Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
airtable
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
web_component
airtable
Commits
5f14696a
Commit
5f14696a
authored
Mar 25, 2020
by
zhangwenshuai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finish input textarea select date number
parent
cdafc0f7
Changes
20
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
327 additions
and
189 deletions
+327
-189
Cell.less
src/apollo-table/component/Cell.less
+1
-0
Cell.tsx
src/apollo-table/component/Cell.tsx
+38
-20
Table.tsx
src/apollo-table/component/Table.tsx
+1
-1
setFormatter.tsx
src/apollo-table/component/base/_utils/setFormatter.tsx
+5
-4
config.tsx
src/apollo-table/component/base/config.tsx
+11
-2
index.tsx
src/apollo-table/component/base/edit/date/index.tsx
+34
-7
styles.less
src/apollo-table/component/base/edit/date/styles.less
+14
-11
editInterface.tsx
src/apollo-table/component/base/edit/editInterface.tsx
+8
-22
index.tsx
src/apollo-table/component/base/edit/input/index.tsx
+45
-9
styles.less
src/apollo-table/component/base/edit/input/styles.less
+4
-5
index.tsx
src/apollo-table/component/base/edit/number/index.tsx
+32
-78
styles.less
src/apollo-table/component/base/edit/number/styles.less
+12
-1
index.tsx
src/apollo-table/component/base/edit/select/index.tsx
+46
-13
styles.less
src/apollo-table/component/base/edit/select/styles.less
+17
-0
index.tsx
src/apollo-table/component/base/edit/textarea/index.tsx
+9
-6
styles.less
src/apollo-table/component/base/edit/textarea/styles.less
+0
-3
index.tsx
src/apollo-table/component/base/index.tsx
+2
-2
interface.tsx
src/apollo-table/component/interface.tsx
+1
-1
demo1.less
src/test/demo1.less
+4
-1
demo1.tsx
src/test/demo1.tsx
+43
-3
No files found.
src/apollo-table/component/Cell.less
View file @
5f14696a
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
position: absolute;
position: absolute;
z-index: 1;
z-index: 1;
width: 100%;
width: 100%;
height: 100%;
top: 0;
top: 0;
left: 0;
left: 0;
}
}
src/apollo-table/component/Cell.tsx
View file @
5f14696a
import
React
,
{
useState
}
from
'react'
;
import
React
,
{
use
Effect
,
use
State
}
from
'react'
;
import
{
message
}
from
'antd'
;
import
{
message
}
from
'antd'
;
import
{
config
}
from
'./config'
;
import
{
config
}
from
'./config'
;
import
s
from
'./Cell.less'
;
import
s
from
'./Cell.less'
;
...
@@ -11,7 +11,7 @@ interface CellData {
...
@@ -11,7 +11,7 @@ interface CellData {
}
}
const
Cell
=
(
props
:
CellProps
)
=>
{
const
Cell
=
(
props
:
CellProps
)
=>
{
const
{
columnConfig
,
cellClassName
,
cellStyle
,
rowData
,
cellData
,
emitChangeCell
}
=
props
;
const
{
columnConfig
,
cellClassName
,
cellStyle
,
rowData
,
cellData
,
emitChangeCell
}
=
props
;
const
{
width
,
columnType
,
columnName
,
requiredFlag
}
=
columnConfig
||
{};
const
{
width
,
columnType
,
columnName
,
requiredFlag
,
renderDetailCell
,
renderEditCell
}
=
columnConfig
||
{};
if
(
config
[
String
(
columnType
)]
===
undefined
)
{
if
(
config
[
String
(
columnType
)]
===
undefined
)
{
return
null
;
return
null
;
...
@@ -19,6 +19,10 @@ const Cell = (props: CellProps) => {
...
@@ -19,6 +19,10 @@ const Cell = (props: CellProps) => {
const
Comp
=
config
[
String
(
columnType
)].
component
;
const
Comp
=
config
[
String
(
columnType
)].
component
;
const
[
status
,
setStatus
]
=
useState
(
'detail'
);
const
[
status
,
setStatus
]
=
useState
(
'detail'
);
useEffect
(()
=>
{
setStatus
(
'detail'
);
},
[
cellData
]);
const
changeCellData
=
(
changedValue
)
=>
{
const
changeCellData
=
(
changedValue
)
=>
{
console
.
log
(
'onChange'
,
changedValue
);
console
.
log
(
'onChange'
,
changedValue
);
};
};
...
@@ -29,6 +33,7 @@ const Cell = (props: CellProps) => {
...
@@ -29,6 +33,7 @@ const Cell = (props: CellProps) => {
temp
.
push
({
text
:
item
.
text
,
value
:
item
.
value
});
temp
.
push
({
text
:
item
.
text
,
value
:
item
.
value
});
});
});
if
(
_
.
isEqual
(
temp
,
changedValue
))
{
if
(
_
.
isEqual
(
temp
,
changedValue
))
{
setStatus
(
'detail'
);
return
;
return
;
}
}
changeValue
(
changedValue
,
optionValue
);
changeValue
(
changedValue
,
optionValue
);
...
@@ -67,7 +72,11 @@ const Cell = (props: CellProps) => {
...
@@ -67,7 +72,11 @@ const Cell = (props: CellProps) => {
}
}
};
};
const
renderDetailCell
=
()
=>
{
const
selfRenderDetailCell
=
()
=>
{
let
detailCell
=
null
;
if
(
typeof
renderDetailCell
===
'function'
)
{
detailCell
=
renderDetailCell
({
cellData
,
rowData
,
columnConfig
});
}
return
(
return
(
<
div
<
div
className=
{
s
.
detailCell
}
className=
{
s
.
detailCell
}
...
@@ -75,37 +84,46 @@ const Cell = (props: CellProps) => {
...
@@ -75,37 +84,46 @@ const Cell = (props: CellProps) => {
setStatus
(
'edit'
);
setStatus
(
'edit'
);
}
}
}
}
>
>
<
Comp
.
Detail
value=
{
cellData
}
columnConfig=
{
columnConfig
}
/>
{
detailCell
}
{
!
detailCell
&&
<
Comp
.
Detail
value=
{
cellData
}
columnConfig=
{
columnConfig
}
/>
}
</
div
>
</
div
>
);
);
};
};
const
renderEditCell
=
()
=>
{
const
selfRenderEditCell
=
()
=>
{
let
editCell
=
null
;
if
(
typeof
renderEditCell
===
'function'
)
{
editCell
=
renderEditCell
({
cellData
,
rowData
,
columnConfig
});
}
return
(
return
(
<
div
<
div
className=
{
s
.
editCell
}
className=
{
s
.
editCell
}
onBlur=
{
()
=>
{
//
onBlur={() => {
setStatus
(
'detail'
);
//
setStatus('detail');
}
}
//
}}
>
>
<
Comp
{
editCell
}
value=
{
cellData
}
{
!
editCell
&&
(
columnConfig=
{
columnConfig
}
<
Comp
onChange=
{
changeCellData
}
value=
{
cellData
}
onEmitChange=
{
emitChangeCellData
}
columnConfig=
{
columnConfig
}
style=
{
{
onChange=
{
changeCellData
}
minHeight
:
cellStyle
.
height
,
onEmitChange=
{
emitChangeCellData
}
borderRadius
:
0
,
style=
{
{
}
}
minHeight
:
cellStyle
.
height
,
/>
borderRadius
:
0
,
}
}
/>
)
}
</
div
>
</
div
>
);
);
};
};
return
(
return
(
<
div
className=
{
cellClassName
}
style=
{
{
...
cellStyle
,
width
:
width
||
200
}
}
>
<
div
className=
{
cellClassName
}
style=
{
{
...
cellStyle
,
width
:
width
||
200
}
}
>
{
status
===
'detail'
&&
r
enderDetailCell
()
}
{
status
===
'detail'
&&
selfR
enderDetailCell
()
}
{
status
===
'edit'
&&
r
enderEditCell
()
}
{
status
===
'edit'
&&
selfR
enderEditCell
()
}
</
div
>
</
div
>
);
);
};
};
...
...
src/apollo-table/component/Table.tsx
View file @
5f14696a
...
@@ -105,7 +105,7 @@ export default class AirTable extends Component<TableProps, TableState> {
...
@@ -105,7 +105,7 @@ export default class AirTable extends Component<TableProps, TableState> {
onScroll
=
({
clientHeight
,
scrollHeight
,
scrollTop
}:
any
)
=>
{
onScroll
=
({
clientHeight
,
scrollHeight
,
scrollTop
}:
any
)
=>
{
const
height
=
clientHeight
+
scrollTop
||
0
;
const
height
=
clientHeight
+
scrollTop
||
0
;
const
{
onScroll
,
distanceToLoad
=
100
}
=
this
.
props
;
const
{
onScroll
,
distanceToLoad
=
100
}
=
this
.
props
;
if
(
height
+
distanceToLoad
>=
scrollHeight
&&
typeof
onScroll
===
'function'
)
{
if
(
scrollTop
>
0
&&
height
+
distanceToLoad
>=
scrollHeight
&&
typeof
onScroll
===
'function'
)
{
onScroll
();
onScroll
();
}
}
};
};
...
...
src/apollo-table/component/base/_utils/setFormatter.tsx
View file @
5f14696a
export
const
formatStr
=
'YYYY-MM-DD HH:mm:ss'
;
export
const
formatStr
=
'YYYY-MM-DD HH:mm:ss'
;
export
const
emptyModel
=
[{
text
:
''
,
value
:
''
}];
export
const
emptyModel
=
[{
text
:
''
,
value
:
''
}];
const
emptyFormat
=
(
value
)
=>
{};
export
const
SetFormatter
=
{
export
const
SetFormatter
=
{
INPUT
:
(
event
)
=>
{
INPUT
:
(
value
)
=>
{
const
node
=
event
.
currentTarget
||
{};
if
(
!
value
)
{
return
[{
value
:
node
.
value
,
text
:
node
.
value
}];
return
emptyModel
;
}
return
[{
value
:
value
,
text
:
value
}];
},
},
SEARCH
:
(
val
)
=>
{
SEARCH
:
(
val
)
=>
{
if
(
!
val
||
typeof
val
!==
'object'
)
return
val
;
if
(
!
val
||
typeof
val
!==
'object'
)
return
val
;
...
...
src/apollo-table/component/base/config.tsx
View file @
5f14696a
...
@@ -9,8 +9,11 @@ export const config: any = {
...
@@ -9,8 +9,11 @@ export const config: any = {
component
:
require
(
'./edit/input'
).
default
,
component
:
require
(
'./edit/input'
).
default
,
setFormatter
:
SetFormatter
[
'INPUT'
],
setFormatter
:
SetFormatter
[
'INPUT'
],
getFormatter
:
GetFormatter
[
'INPUT'
],
getFormatter
:
GetFormatter
[
'INPUT'
],
componentAttr
:
{
autoFocus
:
true
,
emitTrigger
:
'onBlur'
,
},
detail
:
require
(
'./detail/input'
).
default
,
detail
:
require
(
'./detail/input'
).
default
,
icon
:
require
(
'../../assets/type/text.png'
),
},
},
'2'
:
{
'2'
:
{
name
:
'超链接'
,
name
:
'超链接'
,
...
@@ -25,7 +28,7 @@ export const config: any = {
...
@@ -25,7 +28,7 @@ export const config: any = {
getFormatter
:
GetFormatter
[
'TEXTAREA'
],
getFormatter
:
GetFormatter
[
'TEXTAREA'
],
setFormatter
:
SetFormatter
[
'TEXTAREA'
],
setFormatter
:
SetFormatter
[
'TEXTAREA'
],
componentAttr
:
{
componentAttr
:
{
auto
Size
:
true
,
auto
Focus
:
true
,
emitTrigger
:
'onBlur'
,
emitTrigger
:
'onBlur'
,
},
},
detail
:
require
(
'./detail/textarea'
).
default
,
detail
:
require
(
'./detail/textarea'
).
default
,
...
@@ -50,6 +53,8 @@ export const config: any = {
...
@@ -50,6 +53,8 @@ export const config: any = {
componentAttr
:
{
componentAttr
:
{
labelInValue
:
true
,
labelInValue
:
true
,
allowClear
:
true
,
allowClear
:
true
,
autoFocus
:
true
,
emitTrigger
:
'onBlur'
,
},
},
getFormatter
:
GetFormatter
[
'SELECT'
],
getFormatter
:
GetFormatter
[
'SELECT'
],
setFormatter
:
SetFormatter
[
'SELECT'
],
setFormatter
:
SetFormatter
[
'SELECT'
],
...
@@ -62,6 +67,8 @@ export const config: any = {
...
@@ -62,6 +67,8 @@ export const config: any = {
labelInValue
:
true
,
labelInValue
:
true
,
mode
:
'tags'
,
mode
:
'tags'
,
maxTagCount
:
3
,
maxTagCount
:
3
,
autoFocus
:
true
,
emitTrigger
:
'onBlur'
,
},
},
getFormatter
:
GetFormatter
[
'MULTIPLE_SELECT'
],
getFormatter
:
GetFormatter
[
'MULTIPLE_SELECT'
],
setFormatter
:
SetFormatter
[
'MULTIPLE_SELECT'
],
setFormatter
:
SetFormatter
[
'MULTIPLE_SELECT'
],
...
@@ -82,6 +89,8 @@ export const config: any = {
...
@@ -82,6 +89,8 @@ export const config: any = {
name
:
'数字输入'
,
name
:
'数字输入'
,
component
:
require
(
'./edit/number'
).
default
,
component
:
require
(
'./edit/number'
).
default
,
componentAttr
:
{
componentAttr
:
{
autoFocus
:
true
,
emitTrigger
:
'onBlur'
,
precision
:
2
,
precision
:
2
,
},
},
setFormatter
:
SetFormatter
[
'NUMBER'
],
setFormatter
:
SetFormatter
[
'NUMBER'
],
...
...
src/apollo-table/component/base/edit/date/index.tsx
View file @
5f14696a
import
React
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
{
DatePicker
}
from
'antd'
;
import
{
DatePicker
}
from
'antd'
;
import
styles
from
'./styles.less'
;
import
styles
from
'./styles.less'
;
import
{
DateProps
}
from
'../editInterface'
;
import
{
ApolloDateProps
}
from
'../editInterface'
;
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
export
default
function
(
props
:
DateProps
)
{
const
ApolloDate
=
(
props
:
ApolloDateProps
)
=>
{
const
{
value
,
placeholder
,
allowClear
,
disabled
,
format
,
showTime
,
onChange
}
=
props
;
const
{
onChange
,
emitTrigger
,
onEmitChange
,
showTime
}
=
props
;
const
selfProps
=
antiAssign
(
props
,
[
'columnConfig'
,
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
]);
let
trigger
=
emitTrigger
;
if
(
showTime
)
{
trigger
=
'onOk'
;
}
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
const
changeValue
=
(
value
,
dateString
)
=>
{
setValue
(
value
);
if
(
typeof
onChange
===
'function'
)
{
onChange
(
value
,
dateString
);
}
if
(
!
trigger
||
trigger
===
'onChange'
)
{
emitChange
(
value
);
}
};
const
selfProps
=
{
value
,
placeholder
,
allowClear
,
disabled
,
format
,
showTime
,
onChange
};
const
emitChange
=
(
value
)
=>
{
if
(
typeof
onEmitChange
===
'function'
)
{
onEmitChange
(
value
);
}
};
const
onOk
=
(
value
)
=>
{
emitChange
(
value
);
};
if
(
trigger
===
'onOk'
)
{
selfProps
.
onOk
=
onOk
;
}
return
(
return
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
container
}
>
<
DatePicker
{
...
selfProps
}
/>
<
DatePicker
className=
{
styles
.
date
}
{
...
selfProps
}
value=
{
value
}
onChange=
{
changeValue
}
/>
</
div
>
</
div
>
);
);
}
};
export
default
ApolloDate
;
src/apollo-table/component/base/edit/date/styles.less
View file @
5f14696a
...
@@ -2,16 +2,19 @@
...
@@ -2,16 +2,19 @@
position: relative;
position: relative;
top: 0;
top: 0;
left: 0;
left: 0;
width: 100%;
.input {
height: 100%;
padding-right: 100px;
font-size: 0;
}
.date {
width: 100%;
.wordNumber {
height: 100%;
position: absolute;
border-radius: 0;
color: #E1E1E1FF;
div {
font-size: 12px;
height: 100%;
right: 7px;
}
top: 7px;
:global(.ant-calendar-picker-input.ant-input) {
height: 100%;
border-radius: 0;
}
}
}
}
}
src/apollo-table/component/base/edit/editInterface.tsx
View file @
5f14696a
import
{
DatePickerProps
}
from
'antd/es/date-picker/interface'
;
import
{
DatePickerProps
}
from
'antd/es/date-picker/interface'
;
import
{
TextAreaProps
}
from
'antd/es/input'
;
import
{
TextAreaProps
,
InputProps
}
from
'antd/es/input'
;
import
{
InputNumberProps
}
from
'antd/es/input-number'
;
import
{
SelectProps
}
from
'antd/es/select'
;
export
interface
CommonProps
{
export
interface
CommonProps
{
onEmitChange
?:
Function
;
onEmitChange
?:
Function
;
emitTrigger
?:
string
;
emitTrigger
?:
string
;
}
}
export
interface
InputProps
extends
CommonProps
{
export
interface
ApolloInputProps
extends
InputProps
,
CommonProps
{
maxLength
:
number
;
value
:
string
|
undefined
;
}
}
export
interface
LinkProps
extends
CommonProps
{
export
interface
LinkProps
extends
CommonProps
{
value
:
any
[];
value
:
any
[];
...
@@ -26,12 +28,9 @@ export interface SearchProps extends CommonProps {
...
@@ -26,12 +28,9 @@ export interface SearchProps extends CommonProps {
tableId
?:
number
;
tableId
?:
number
;
paramsJson
?:
any
;
paramsJson
?:
any
;
}
}
export
interface
SelectProps
extends
CommonProps
{
export
interface
ApolloSelectProps
extends
SelectProps
,
CommonProps
{
isMultiple
?:
boolean
;
isMultiple
?:
boolean
;
maxCount
?:
number
;
tableId
?:
number
;
options
?:
any
[];
options
?:
any
[];
allowClear
?:
boolean
;
}
}
export
interface
RateProps
{
export
interface
RateProps
{
value
:
number
;
value
:
number
;
...
@@ -41,21 +40,8 @@ export interface RateProps {
...
@@ -41,21 +40,8 @@ export interface RateProps {
onChange
:
any
;
onChange
:
any
;
disabled
?:
boolean
;
disabled
?:
boolean
;
}
}
export
interface
Number
Props
{
export
interface
ApolloNumberProps
extends
InputNumberProps
,
Common
Props
{
value
:
number
|
undefined
;
value
:
number
|
undefined
;
onChange
:
Function
;
cellData
?:
any
[];
floatRange
?:
number
;
floatRange
?:
number
;
rowId
?:
number
;
columnConfig
?:
any
;
precision
:
number
;
min
:
number
;
max
:
number
;
step
?:
number
|
string
;
}
export
interface
NumberState
{
prevProps
:
NumberProps
;
value
:
number
|
undefined
;
cellData
?:
any
[];
}
}
export
interface
DateProps
extends
DatePicker
Props
{}
export
interface
ApolloDateProps
extends
DatePickerProps
,
Common
Props
{}
src/apollo-table/component/base/edit/input/index.tsx
View file @
5f14696a
import
React
from
'react'
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
Input
}
from
'antd'
;
import
{
Input
}
from
'antd'
;
import
styles
from
'./styles.less'
;
import
styles
from
'./styles.less'
;
import
{
InputProps
}
from
'../editInterface'
;
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
import
{
ApolloInputProps
}
from
'../editInterface'
;
export
default
function
(
props
:
InputProps
)
{
const
ApolloInput
=
(
props
:
ApolloInputProps
)
=>
{
const
{
value
,
maxLength
,
placeholder
,
onChange
}
=
props
;
const
{
maxLength
,
onChange
,
emitTrigger
,
onEmitChange
,
style
}
=
props
;
const
selfProps
=
{
value
,
maxLength
,
placeholder
,
onChange
};
const
selfProps
=
antiAssign
(
props
,
[
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
,
'style'
]);
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
useEffect
(()
=>
{
setValue
(
props
.
value
);
},
[
props
.
value
]);
const
changeValue
=
(
e
)
=>
{
setValue
(
e
.
target
.
value
);
if
(
typeof
onChange
===
'function'
)
{
onChange
(
e
.
target
.
value
);
}
if
(
!
emitTrigger
||
emitTrigger
===
'onChange'
)
{
emitChange
(
e
);
}
};
const
emitChange
=
(
e
)
=>
{
if
(
typeof
onEmitChange
===
'function'
)
{
onEmitChange
(
e
.
target
.
value
);
}
};
if
(
emitTrigger
===
'onBlur'
)
{
selfProps
.
onBlur
=
emitChange
;
}
const
newStyle
:
any
=
{
...
style
};
if
(
maxLength
&&
style
)
{
newStyle
.
minHeight
=
Number
(
style
.
minHeight
)
+
10
;
newStyle
.
paddingBottom
=
18
;
}
return
(
return
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
container
}
>
<
Input
className=
{
styles
.
input
}
{
...
selfProps
}
/>
<
Input
{
maxLength
&&
(
className=
{
styles
.
input
}
style=
{
newStyle
}
{
...
selfProps
}
value=
{
value
}
onChange=
{
changeValue
}
/>
{
!!
maxLength
&&
(
<
span
className=
{
styles
.
wordNumber
}
>
<
span
className=
{
styles
.
wordNumber
}
>
已输入
{
(
value
||
''
).
length
||
0
}
/
{
maxLength
}
已输入
{
(
value
||
''
).
length
}
/
{
maxLength
}
</
span
>
</
span
>
)
}
)
}
</
div
>
</
div
>
);
);
}
};
export
default
ApolloInput
;
src/apollo-table/component/base/edit/input/styles.less
View file @
5f14696a
...
@@ -2,16 +2,15 @@
...
@@ -2,16 +2,15 @@
position: relative;
position: relative;
top: 0;
top: 0;
left: 0;
left: 0;
.input {
.input {
padding-right: 100
px;
//padding-bottom: 18
px;
}
}
.wordNumber {
.wordNumber {
position: absolute;
position: absolute;
color: #E1E1E1FF;
right: 12px;
bottom: 2px;
color: #e1e1e1ff;
font-size: 12px;
font-size: 12px;
right: 7px;
top: 7px;
}
}
}
}
src/apollo-table/component/base/edit/number/index.tsx
View file @
5f14696a
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
InputNumber
,
Modal
}
from
'antd'
;
import
{
InputNumber
}
from
'antd'
;
import
styles
from
'./styles.less'
;
import
styles
from
'./styles.less'
;
import
{
NumberProps
,
NumberState
}
from
'../editInterface'
;
import
{
ApolloNumberProps
}
from
'../editInterface'
;
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
export
default
class
extends
Component
<
NumberProps
,
NumberState
>
{
const
ApolloNumber
=
(
props
:
ApolloNumberProps
)
=
>
{
static
getDerivedStateFromProps
(
nextProps
:
NumberProps
,
prevState
:
NumberState
)
{
const
{
onChange
,
emitTrigger
,
onEmitChange
}
=
props
;
const
{
prevProps
}
=
prevState
;
const
selfProps
=
antiAssign
(
props
,
[
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
])
;
let
nextState
:
NumberState
=
{
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
...
prevState
,
useEffect
(()
=>
{
prevProps
:
nextProps
,
setValue
(
props
.
value
);
value
:
nextProps
.
value
,
},
[
props
.
value
]);
cellData
:
nextProps
.
cellData
,
const
changeValue
=
(
value
)
=>
{
}
;
setValue
(
value
)
;
if
(
JSON
.
stringify
(
prevProps
.
value
)
!==
JSON
.
stringify
(
nextProps
.
value
)
)
{
if
(
typeof
onChange
===
'function'
)
{
nextState
.
value
=
nextProps
.
value
;
onChange
(
value
)
;
}
}
if
(
JSON
.
stringify
(
prevProps
.
cellData
)
!==
JSON
.
stringify
(
nextProps
.
cellData
)
)
{
if
(
!
emitTrigger
||
emitTrigger
===
'onChange'
)
{
nextState
.
cellData
=
nextProps
.
cellData
;
emitChange
(
value
)
;
}
}
return
nextState
;
}
constructor
(
props
:
NumberProps
)
{
super
(
props
);
const
{
value
,
cellData
}
=
props
;
this
.
state
=
{
prevProps
:
props
,
value
,
cellData
,
};
}
onChange
=
(
changedValue
:
number
|
undefined
)
=>
{
this
.
setState
({
value
:
changedValue
,
});
};
};
resetValue
=
()
=>
{
const
onBlur
=
(
e
)
=>
{
const
{
cellData
}
=
this
.
state
;
emitChange
(
e
.
target
.
value
);
this
.
setState
({
value
:
cellData
&&
cellData
.
length
>
0
?
cellData
[
0
].
value
:
undefined
,
cellData
,
});
};
};
onBlur
=
(
e
:
any
)
=>
{
const
emitChange
=
(
value
)
=>
{
const
{
if
(
typeof
onEmitChange
===
'function'
)
{
onChange
,
onEmitChange
(
value
);
floatRange
,
columnConfig
:
{
columnChsName
},
rowId
,
}
=
this
.
props
;
const
{
cellData
}
=
this
.
state
;
const
originValue
=
Array
.
isArray
(
cellData
)
&&
cellData
.
length
>
0
?
cellData
[
0
].
value
:
undefined
;
// 检测浮动条件:编辑时,有浮动标记,原值不为0
if
(
rowId
&&
floatRange
&&
originValue
&&
Number
(
originValue
)
!==
0
)
{
// 新值默认取0只用于计算,对应清空操作
const
changedValue
=
e
.
target
.
value
||
0
;
const
range
=
Math
.
abs
(
Number
(
changedValue
)
-
Number
(
originValue
))
/
Number
(
originValue
);
if
(
Number
(
range
)
>
Number
(
floatRange
))
{
const
confirm
=
Modal
.
confirm
({
title
:
'确认提示'
,
content
:
`
${
columnChsName
}
变更浮动较大,是否确认提交?`
,
onOk
:
()
=>
{
onChange
({
changedValue
:
e
.
target
.
value
,
isBlur
:
true
});
},
onCancel
:
()
=>
{
this
.
resetValue
();
confirm
.
destroy
();
},
});
return
;
}
}
}
onChange
({
changedValue
:
e
.
target
.
value
,
isBlur
:
true
});
};
};
if
(
emitTrigger
===
'onBlur'
)
{
render
()
{
selfProps
.
onBlur
=
onBlur
;
const
{
value
}
=
this
.
state
;
const
{
precision
,
min
,
max
}
=
this
.
props
;
const
selfProps
=
{
value
,
precision
,
min
,
max
};
return
(
<
div
className=
{
styles
.
container
}
>
<
InputNumber
{
...
selfProps
}
onChange=
{
this
.
onChange
}
onBlur=
{
this
.
onBlur
}
value=
{
value
}
/>
</
div
>
);
}
}
}
return
(
<
div
className=
{
styles
.
container
}
>
<
InputNumber
className=
{
styles
.
number
}
{
...
selfProps
}
value=
{
value
}
onChange=
{
changeValue
}
/>
</
div
>
);
};
export
default
ApolloNumber
;
src/apollo-table/component/base/edit/number/styles.less
View file @
5f14696a
.container {
.container {
position: relative;
top: 0;
left: 0;
.number {
width: 100%;
:global(.ant-input-number-input-wrap){
height: 100%;
input {
height: 100%;
}
}
}
}
}
src/apollo-table/component/base/edit/select/index.tsx
View file @
5f14696a
import
React
from
'react'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
import
{
Select
}
from
'antd'
;
import
{
Select
}
from
'antd'
;
import
{
SelectProps
}
from
'../editInterface'
;
import
{
ApolloSelectProps
}
from
'../editInterface'
;
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
import
styles
from
'./styles.less'
;
export
default
function
(
props
:
SelectProps
)
{
const
ApolloSelect
=
(
props
:
ApolloSelectProps
)
=>
{
const
{
options
=
[],
allowClear
,
disabled
,
placeholder
,
value
,
onChange
,
isMultiple
}
=
props
;
const
{
options
=
[],
onChange
,
emitTrigger
,
onEmitChange
,
isMultiple
}
=
props
;
const
selfProps
:
any
=
{
allowClear
,
disabled
,
placeholder
,
value
,
onChange
};
const
selfProps
=
antiAssign
(
props
,
[
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
,
'isMultiple'
,
'options'
]);
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
const
[
option
,
setOption
]
=
useState
(
undefined
);
useEffect
(()
=>
{
setValue
(
props
.
value
);
setOption
(
undefined
);
},
[
props
.
value
]);
const
changeValue
=
(
value
,
option
)
=>
{
setValue
(
value
);
setOption
(
option
);
if
(
typeof
onChange
===
'function'
)
{
onChange
(
value
,
option
);
}
if
(
!
emitTrigger
||
emitTrigger
===
'onChange'
)
{
emitChange
(
value
,
option
);
}
};
const
emitChange
=
(
value
,
option
)
=>
{
if
(
typeof
onEmitChange
===
'function'
)
{
onEmitChange
(
value
,
option
);
}
};
const
onBlur
=
()
=>
{
emitChange
(
value
,
option
);
};
if
(
emitTrigger
===
'onBlur'
)
{
selfProps
.
onBlur
=
onBlur
;
}
if
(
isMultiple
)
{
if
(
isMultiple
)
{
selfProps
.
mode
=
'multiple'
;
selfProps
.
mode
=
'multiple'
;
}
}
return
(
return
(
<
Select
{
...
selfProps
}
>
<
div
className=
{
styles
.
container
}
onBlur=
{
onBlur
}
>
{
options
.
map
((
item
)
=>
(
<
Select
className=
{
styles
.
select
}
{
...
selfProps
}
value=
{
value
}
onChange=
{
changeValue
}
>
<
Select
.
Option
key=
{
item
.
id
}
value=
{
item
.
id
}
>
{
options
.
map
((
item
)
=>
(
{
item
.
name
}
<
Select
.
Option
key=
{
item
.
id
}
value=
{
item
.
id
}
>
</
Select
.
Option
>
{
item
.
name
}
))
}
</
Select
.
Option
>
</
Select
>
))
}
</
Select
>
</
div
>
);
);
}
};
export
default
ApolloSelect
;
src/apollo-table/component/base/edit/select/styles.less
0 → 100644
View file @
5f14696a
.container {
position: relative;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 0;
.select {
width: 100%;
height: 100%;
border-radius: 0;
:global(.ant-select-selection--single) {
height: 100%;
border-radius: 0;
}
}
}
src/apollo-table/component/base/edit/textarea/index.tsx
View file @
5f14696a
...
@@ -4,7 +4,7 @@ import styles from './styles.less';
...
@@ -4,7 +4,7 @@ import styles from './styles.less';
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
import
{
antiAssign
}
from
'@/apollo-table/utils/utils'
;
import
{
ApolloTextAreaProps
}
from
'../editInterface'
;
import
{
ApolloTextAreaProps
}
from
'../editInterface'
;
const
TextArea
=
(
props
:
ApolloTextAreaProps
)
=>
{
const
Apollo
TextArea
=
(
props
:
ApolloTextAreaProps
)
=>
{
const
{
maxLength
,
onChange
,
emitTrigger
,
onEmitChange
}
=
props
;
const
{
maxLength
,
onChange
,
emitTrigger
,
onEmitChange
}
=
props
;
const
selfProps
=
antiAssign
(
props
,
[
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
]);
const
selfProps
=
antiAssign
(
props
,
[
'value'
,
'onChange'
,
'emitTrigger'
,
'onEmitChange'
]);
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
const
[
value
,
setValue
]
=
useState
(
props
.
value
);
...
@@ -31,11 +31,14 @@ const TextArea = (props: ApolloTextAreaProps) => {
...
@@ -31,11 +31,14 @@ const TextArea = (props: ApolloTextAreaProps) => {
}
}
return
(
return
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
container
}
>
<
Input
.
TextArea
className=
{
styles
.
input
}
{
...
selfProps
}
value=
{
value
}
onChange=
{
changeValue
}
/>
<
Input
.
TextArea
{
maxLength
&&
(
className=
{
styles
.
input
}
<
span
className=
{
styles
.
wordNumber
}
>
{
`已输入${(value || '').length}/${maxLength}`
}
</
span
>
{
...
selfProps
}
)
}
value=
{
value
}
onChange=
{
changeValue
}
/>
{
!!
maxLength
&&
<
span
className=
{
styles
.
wordNumber
}
>
{
`已输入${(value || '').length}/${maxLength}`
}
</
span
>
}
</
div
>
</
div
>
);
);
};
};
export
default
TextArea
;
export
default
Apollo
TextArea
;
src/apollo-table/component/base/edit/textarea/styles.less
View file @
5f14696a
...
@@ -5,9 +5,6 @@
...
@@ -5,9 +5,6 @@
.input {
.input {
padding-bottom: 18px;
padding-bottom: 18px;
}
}
textarea {
padding-bottom: 18px;
}
.wordNumber {
.wordNumber {
position: absolute;
position: absolute;
right: 12px;
right: 12px;
...
...
src/apollo-table/component/base/index.tsx
View file @
5f14696a
...
@@ -68,12 +68,12 @@ export const getComponent = (type: string) => {
...
@@ -68,12 +68,12 @@ export const getComponent = (type: string) => {
}
}
};
};
// 触发修改回调
// 触发修改回调
onEmitChange
=
(
changedValue
:
any
)
=>
{
onEmitChange
=
(
changedValue
:
any
,
option
:
any
)
=>
{
const
{
columnConfig
}
=
this
.
state
;
const
{
columnConfig
}
=
this
.
state
;
const
{
onEmitChange
}
=
this
.
props
;
const
{
onEmitChange
}
=
this
.
props
;
let
value
=
setFormat
(
columnConfig
,
changedValue
);
let
value
=
setFormat
(
columnConfig
,
changedValue
);
if
(
typeof
onEmitChange
===
'function'
)
{
if
(
typeof
onEmitChange
===
'function'
)
{
onEmitChange
(
value
,
changedValue
);
onEmitChange
(
value
,
option
);
}
}
};
};
...
...
src/apollo-table/component/interface.tsx
View file @
5f14696a
...
@@ -80,7 +80,7 @@ export interface CellProps {
...
@@ -80,7 +80,7 @@ export interface CellProps {
cellData
:
any
;
cellData
:
any
;
emitChangeCell
:
Function
;
emitChangeCell
:
Function
;
cellClassName
?:
string
;
cellClassName
?:
string
;
cellStyle
:
object
;
cellStyle
:
any
;
}
}
export
interface
CellState
{
export
interface
CellState
{
status
:
string
;
status
:
string
;
...
...
src/test/demo1.less
View file @
5f14696a
.row{
.row
{
color: green;
color: green;
}
}
.xxx {
color: blue;
}
src/test/demo1.tsx
View file @
5f14696a
...
@@ -2,7 +2,8 @@ import React, { useState, useEffect, useCallback } from 'react';
...
@@ -2,7 +2,8 @@ import React, { useState, useEffect, useCallback } from 'react';
import
_
from
'lodash'
;
import
_
from
'lodash'
;
import
ApolloTable
from
'../apollo-table'
;
import
ApolloTable
from
'../apollo-table'
;
import
{
getColumnConfig
,
getDataSource
,
addOrUpdateDataSource
}
from
'./serives'
;
import
{
getColumnConfig
,
getDataSource
,
addOrUpdateDataSource
}
from
'./serives'
;
import
{
message
}
from
'antd'
;
import
{
Input
,
message
,
DatePicker
}
from
'antd'
;
import
moment
from
'moment'
;
import
s
from
'./demo1.less'
;
import
s
from
'./demo1.less'
;
const
rowStyle
=
({
rowIndex
})
=>
{
const
rowStyle
=
({
rowIndex
})
=>
{
...
@@ -31,7 +32,7 @@ const Demo1 = (props) => {
...
@@ -31,7 +32,7 @@ const Demo1 = (props) => {
const
res
=
await
getColumnConfig
({
tableId
});
const
res
=
await
getColumnConfig
({
tableId
});
if
(
res
&&
res
.
success
&&
res
.
data
)
{
if
(
res
&&
res
.
success
&&
res
.
data
)
{
const
arr
=
Array
.
isArray
(
res
.
data
)
?
res
.
data
:
[];
const
arr
=
Array
.
isArray
(
res
.
data
)
?
res
.
data
:
[];
setColumns
(
arr
);
setColumns
(
formatColumns
(
arr
)
);
}
}
};
};
getColumnsList
();
getColumnsList
();
...
@@ -43,7 +44,7 @@ const Demo1 = (props) => {
...
@@ -43,7 +44,7 @@ const Demo1 = (props) => {
hasNextPage
:
false
,
hasNextPage
:
false
,
nextPage
:
1
,
nextPage
:
1
,
});
});
const
[
flush
,
setFlush
]
=
useState
(
false
);
const
[
flush
,
setFlush
]
=
useState
(
false
);
useEffect
(()
=>
{
useEffect
(()
=>
{
const
getDataList
=
async
()
=>
{
const
getDataList
=
async
()
=>
{
const
data
=
{
const
data
=
{
...
@@ -85,6 +86,45 @@ const Demo1 = (props) => {
...
@@ -85,6 +86,45 @@ const Demo1 = (props) => {
fetchData
(
true
);
fetchData
(
true
);
}
}
};
};
const
renderDetailCell
=
(
data
)
=>
{
const
{
columnConfig
,
cellData
}
=
data
;
const
record
=
data
.
rowData
;
const
{
id
,
rowData
}
=
record
;
const
{
columnName
}
=
columnConfig
;
if
(
columnName
===
'customerNameInput'
)
{
return
<
div
className=
{
s
.
xxx
}
>
{
cellData
[
0
]
&&
cellData
[
0
].
text
}
</
div
>;
}
};
const
renderEditCell
=
(
data
)
=>
{
const
{
columnConfig
,
cellData
}
=
data
;
const
record
=
data
.
rowData
;
const
{
id
,
rowData
}
=
record
;
const
{
columnName
}
=
columnConfig
;
if
(
columnName
===
'followUpDate'
)
{
const
value
=
moment
(
cellData
[
0
]
&&
cellData
[
0
].
value
);
return
(
<
div
className=
{
s
.
xxx
}
>
<
DatePicker
value=
{
value
}
getPopupContainer=
{
(
trigger
)
=>
{
return
trigger
.
parentElement
;
}
}
/>
</
div
>
);
}
};
const
formatColumns
=
(
columns
)
=>
{
columns
.
map
((
item
)
=>
{
if
(
item
.
columnName
===
'followUpDate'
)
{
item
.
renderDetailCell
=
renderDetailCell
;
// item.renderEditCell = renderEditCell;
}
return
item
;
});
return
columns
;
};
return
(
return
(
<
ApolloTable
<
ApolloTable
rowStyle=
{
rowStyle
}
rowStyle=
{
rowStyle
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment