Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-admin
Project
Project
Details
Activity
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
shenshaokai
jinfa-admin
Commits
6a6fdcc4
Commit
6a6fdcc4
authored
Jan 07, 2021
by
XieZhiXiong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: 调整 Upload 组件数据结构
parent
126d2fcc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
379 additions
and
381 deletions
+379
-381
index.tsx
src/components/NiceForm/components/AntUpload/index.tsx
+1
-1
index.tsx
...turnManage/components/RefundModal/UploadVoucher/index.tsx
+1
-1
index.ts
src/utils/index.ts
+377
-379
No files found.
src/components/NiceForm/components/AntUpload/index.tsx
View file @
6a6fdcc4
...
...
@@ -111,7 +111,7 @@ const normalizeFileList = fileList => {
status
:
file
.
status
,
name
:
file
.
name
,
url
:
file
.
downloadURL
||
file
.
imgURL
||
file
.
url
,
...
file
.
response
,
...
file
.
response
.
data
,
thumbUrl
:
file
.
imgURL
||
getImageByUrl
(
file
.
downloadURL
||
file
.
url
,
{
exclude
:
[
'.png'
,
'.jpg'
,
'.jpeg'
,
'.gif'
]
})
...
...
src/pages/returnManage/components/RefundModal/UploadVoucher/index.tsx
View file @
6a6fdcc4
...
...
@@ -100,7 +100,7 @@ const UploadVoucher: React.FC<UploadVoucherProps> = ({
...
rest
,
fileList
:
fileList
.
map
(
item
=>
item
.
status
===
'done'
&&
({
name
:
item
.
name
,
proveUrl
:
item
.
data
.
url
,
proveUrl
:
item
.
url
,
})).
filter
(
Boolean
),
},
},
'uploadVoucher'
);
...
...
src/utils/index.ts
View file @
6a6fdcc4
import
deepClone
from
'clone'
import
moment
from
'moment'
;
import
{
ISchema
}
from
'@formily/antd'
;
function
isArray
(
arr
:
any
)
{
return
Array
.
isArray
(
arr
)
}
export
const
findArrayItem
=
(
arr
:
Array
<
any
>
,
flag
:
any
)
=>
{
const
result
=
arr
.
find
(
v
=>
v
.
value
===
flag
)
return
result
?
result
:
{}
}
/**
* 找到最后一个可用的工作流状态的索引
* @param {array} data 数据
* @param {string} customKey 自定义 key
*/
export
const
findLastIndexFlowState
=
(
data
:
any
[],
customKey
=
'isExecute'
):
number
=>
{
let
index
=
0
;
if
(
!
Array
.
isArray
(
data
))
{
return
index
;
}
// 循环数据,找到状态值,一直覆盖
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
data
[
i
][
customKey
])
{
index
=
i
;
}
}
return
index
;
};
export
function
formatTimeString
(
date
,
format
:
string
=
'YYYY-MM-DD HH:mm:ss'
)
{
return
date
?
moment
(
date
).
format
(
format
)
:
''
}
export
function
isObject
(
obj
:
any
)
{
return
Object
.
prototype
.
toString
.
call
(
obj
)
===
'[object Object]'
}
function
transformDataPre
(
data
:
object
,
key
:
string
):
object
{
const
trans
=
{}
Object
.
getOwnPropertyNames
(
data
).
forEach
(
k
=>
{
trans
[
`
${
key
}
.
${
k
}
`
]
=
data
[
k
]
})
return
trans
}
const
reg
=
/
(((
^https
?
:
(?:\/\/)?)(?:[
-;:&=
\+\$
,
\w]
+@
)?[
A-Za-z0-9.-
]
+
(?:
:
\d
+
)?
|
(?:
www.|
[
-;:&=
\+\$
,
\w]
+@
)[
A-Za-z0-9.-
]
+
)((?:\/[\+
~%
\/
.
\w
-_
]
*
)?\??(?:[
-
\+
=&;%@.
\w
_
]
*
)
#
?(?:[\w]
*
))?)
$/
;
export
function
timeRange
(
val
:
number
)
{
let
st
,
et
;
switch
(
val
)
{
case
0
:
st
=
et
=
''
;
break
;
case
1
:
st
=
moment
(
moment
()
.
startOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
2
:
st
=
moment
(
moment
()
.
subtract
(
7
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
3
:
st
=
moment
(
moment
()
.
subtract
(
29
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
4
:
st
=
moment
(
moment
()
.
subtract
(
89
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
5
:
st
=
moment
(
moment
()
.
subtract
(
179
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
6
:
st
=
moment
(
moment
()
.
subtract
(
364
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
7
:
st
=
moment
(
moment
()
.
year
(
moment
().
year
()
-
1
)
.
startOf
(
'year'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
et
=
moment
(
moment
()
.
year
(
moment
().
year
()
-
1
)
.
endOf
(
'year'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
}
return
{
st
,
et
}
}
export
const
isUrl
=
(
path
:
string
):
boolean
=>
reg
.
test
(
path
);
/**
* @description 用于将传入的接口,并行请求,并组装成Select组件可识别的形式返回
* @param asyncList {Array} 异步函数数组
*/
export
const
getAsyncSelectList
=
async
(
asyncList
:
any
[])
=>
{
try
{
const
result
=
await
Promise
.
all
(
asyncList
)
return
result
.
map
(
v
=>
v
.
data
.
map
(
j
=>
{
return
{
label
:
j
.
name
,
value
:
j
.
id
}
}))
}
catch
(
error
)
{
return
error
}
}
// 抽离对象中的某些属性, 并返回一个新对象
export
const
omit
=
(
obj
:
any
,
arr
:
string
[]):
any
=>
{
const
newObj
=
deepClone
(
obj
)
for
(
let
item
=
0
;
item
<
arr
.
length
;
item
++
)
{
if
(
obj
[
arr
[
item
]]
!==
undefined
)
{
delete
newObj
[
arr
[
item
]]
}
}
return
newObj
}
/**
* @param { Object[] } arr 源数据
* @param { any } target 目标值 通常是id等主键
* @param { string } customKey 可选 自定义主键 默认'id'
*/
export
const
findItemAndDelete
=
(
arr
:
any
[],
target
:
any
,
customKey
?:
string
)
=>
{
const
newArr
=
[...
arr
]
if
(
newArr
.
length
>
0
&&
isObject
(
newArr
[
0
]))
{
return
newArr
.
filter
(
v
=>
v
[
customKey
||
'id'
]
!==
target
)
}
const
targetIndex
=
arr
.
indexOf
(
target
)
if
(
targetIndex
===
-
1
)
{
return
newArr
}
else
{
newArr
.
splice
(
targetIndex
,
1
)
return
newArr
}
}
// 遍历树拿到所有key的集合
export
const
findTreeKeys
=
(
arr
:
any
[],
keyword
?:
string
)
=>
{
const
copyArr
:
any
[]
=
deepClone
(
arr
)
const
results
:
any
[]
=
[]
while
(
copyArr
.
length
>
0
)
{
const
item
=
copyArr
.
shift
()
results
.
push
(
keyword
?
item
[
keyword
]
:
item
.
key
)
if
(
item
.
children
)
{
copyArr
.
push
(...
item
.
children
)
}
}
return
results
}
// 树形结构降为一维对象处理
export
const
treeReduction
=
(
data
:
any
[])
=>
{
const
hashMaps
=
{}
const
selfData
:
any
[]
=
deepClone
(
data
)
while
(
selfData
.
length
>
0
)
{
const
useItem
=
selfData
.
shift
()
// 存在子集
if
(
useItem
.
children
&&
useItem
.
children
.
length
>
0
)
{
useItem
.
children
=
useItem
.
children
.
map
(
v
=>
{
v
.
parentId
=
useItem
.
id
return
v
})
selfData
.
push
(...
useItem
.
children
)
}
hashMaps
[
useItem
.
id
]
=
useItem
}
return
hashMaps
}
// 获取某一节点的title路径
export
const
getParentTreeTitles
=
(
dataSouce
,
key
)
=>
{
const
hashMaps
=
treeReduction
(
dataSouce
)
let
targetKey
=
key
let
targetPath
=
''
while
(
targetKey
!==
''
)
{
if
(
!
hashMaps
[
targetKey
])
{
break
}
const
title
=
hashMaps
[
targetKey
].
title
targetPath
=
targetPath
===
''
?
title
:
`
${
title
}
-
${
targetPath
}
`
targetKey
=
hashMaps
[
targetKey
].
parentId
||
''
}
return
targetPath
}
// 数组通过某个key进行去重合并, 并返回一个新数组
export
const
mergeArrByKey
=
(
preArr
:
any
[],
nextArr
:
any
[],
target
?:
string
)
=>
{
const
mergeArr
=
preArr
.
concat
(
nextArr
)
if
(
target
)
{
const
result
:
any
[]
=
[]
mergeArr
.
forEach
(
v
=>
{
const
s
=
result
.
find
(
j
=>
j
[
target
]
===
v
[
target
])
if
(
!
s
)
{
result
.
push
(
v
)
}
})
return
result
}
else
{
return
Array
.
from
(
new
Set
(
mergeArr
))
}
}
// 数组去重
export
const
dupliArr
=
(
arr
:
any
[])
=>
{
return
Array
.
from
(
new
Set
(
arr
))
}
// 填充必填的schema message提示
export
const
padRequiredMessage
=
(
originSchema
:
ISchema
)
=>
{
const
messageSwich
=
(
type
)
=>
{
return
type
?
'请选择'
:
'请输入'
}
const
todoFn
=
(
targetSchema
)
=>
{
}
Object
.
entries
(
originSchema
.
properties
).
map
(([
key
,
value
])
=>
{
if
(
value
.
required
)
{
const
isSelect
=
value
.
enum
const
message
=
messageSwich
(
isSelect
)
+
(
value
.
title
||
''
)
value
[
'x-rules'
]
=
Array
.
isArray
(
value
[
'x-rules'
])
?
value
[
'x-rules'
].
concat
([{
message
,
required
:
true
}])
:
[{
message
,
required
:
true
}]
}
if
(
value
.
properties
)
{
padRequiredMessage
(
value
)
}
return
value
})
return
originSchema
}
export
interface
FileData
{
uid
:
string
;
name
:
string
;
status
:
'uploading'
|
'done'
|
'error'
|
'removed'
;
url
:
string
;
};
/**
* 初始化 Upload 数据
*/
export
function
normalizeFiledata
(
url
:
string
):
FileData
export
function
normalizeFiledata
(
url
:
any
):
any
{
if
(
!
url
)
{
return
url
;
}
const
splited
=
url
.
split
(
'/'
);
const
fileName
=
splited
&&
splited
.
length
?
splited
[
splited
.
length
-
1
]
:
''
;
return
{
uid
:
Math
.
random
().
toFixed
(
16
).
slice
(
2
,
10
),
name
:
fileName
,
status
:
'done'
,
url
,
data
:
{
url
,
},
// formily Upload value 需要这个字段
};
};
/**
* 检查是否还有更多
* @param {Number} curPage 当前页码
* @param {Number} curSize 当前页数
* @param {Number} dataLen 当前数据长度
* @param {Number} dataTotal 数据总长度
*/
export
const
checkMore
=
(
curPage
:
number
,
curSize
:
number
,
dataLen
:
number
,
dataTotal
:
number
)
=>
{
let
hasMore
=
true
;
if
(
!
dataLen
||
dataLen
+
(
curPage
-
1
)
*
curSize
>=
+
dataTotal
)
{
hasMore
=
false
;
}
return
hasMore
;
};
/**
*
* @param {string} str 需要判断是否是 JSON字符串的 字符串
*/
export
const
isJSONStr
=
str
=>
{
if
(
typeof
str
===
'string'
)
{
try
{
const
complete
=
JSON
.
parse
(
str
);
return
complete
;
}
catch
(
e
)
{
return
null
;
}
}
return
str
;
}
/**
* 给 Table columns 的 filters 赋值
* @param {array} data 需要赋值的数组
* @param {string} dataIndex 索引
* @param {array} item 需要赋值的值
*/
export
const
coverColFiltersItem
=
(
data
:
Array
<
{[
key
:
string
]:
any
}
>
,
dataIndex
:
string
,
item
:
{[
key
:
string
]:
any
}
)
=>
{
const
index
=
data
.
findIndex
(
i
=>
i
.
dataIndex
===
dataIndex
);
if
(
index
!==
-
1
)
{
data
.
splice
(
index
,
1
,
{
...
data
[
index
],
filters
:
item
,
});
}
};
export
default
{
isArray
,
isObject
,
transformDataPre
import
deepClone
from
'clone'
import
moment
from
'moment'
;
import
{
ISchema
}
from
'@formily/antd'
;
function
isArray
(
arr
:
any
)
{
return
Array
.
isArray
(
arr
)
}
export
const
findArrayItem
=
(
arr
:
Array
<
any
>
,
flag
:
any
)
=>
{
const
result
=
arr
.
find
(
v
=>
v
.
value
===
flag
)
return
result
?
result
:
{}
}
/**
* 找到最后一个可用的工作流状态的索引
* @param {array} data 数据
* @param {string} customKey 自定义 key
*/
export
const
findLastIndexFlowState
=
(
data
:
any
[],
customKey
=
'isExecute'
):
number
=>
{
let
index
=
0
;
if
(
!
Array
.
isArray
(
data
))
{
return
index
;
}
// 循环数据,找到状态值,一直覆盖
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
data
[
i
][
customKey
])
{
index
=
i
;
}
}
return
index
;
};
export
function
formatTimeString
(
date
,
format
:
string
=
'YYYY-MM-DD HH:mm:ss'
)
{
return
date
?
moment
(
date
).
format
(
format
)
:
''
}
export
function
isObject
(
obj
:
any
)
{
return
Object
.
prototype
.
toString
.
call
(
obj
)
===
'[object Object]'
}
function
transformDataPre
(
data
:
object
,
key
:
string
):
object
{
const
trans
=
{}
Object
.
getOwnPropertyNames
(
data
).
forEach
(
k
=>
{
trans
[
`
${
key
}
.
${
k
}
`
]
=
data
[
k
]
})
return
trans
}
const
reg
=
/
(((
^https
?
:
(?:\/\/)?)(?:[
-;:&=
\+\$
,
\w]
+@
)?[
A-Za-z0-9.-
]
+
(?:
:
\d
+
)?
|
(?:
www.|
[
-;:&=
\+\$
,
\w]
+@
)[
A-Za-z0-9.-
]
+
)((?:\/[\+
~%
\/
.
\w
-_
]
*
)?\??(?:[
-
\+
=&;%@.
\w
_
]
*
)
#
?(?:[\w]
*
))?)
$/
;
export
function
timeRange
(
val
:
number
)
{
let
st
,
et
;
switch
(
val
)
{
case
0
:
st
=
et
=
''
;
break
;
case
1
:
st
=
moment
(
moment
()
.
startOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
2
:
st
=
moment
(
moment
()
.
subtract
(
7
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
3
:
st
=
moment
(
moment
()
.
subtract
(
29
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
4
:
st
=
moment
(
moment
()
.
subtract
(
89
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
5
:
st
=
moment
(
moment
()
.
subtract
(
179
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
6
:
st
=
moment
(
moment
()
.
subtract
(
364
,
'days'
)
.
format
(
'YYYY-MM-DD'
)
+
' 00:00:00'
,
).
unix
();
et
=
moment
(
moment
()
.
endOf
(
'days'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
case
7
:
st
=
moment
(
moment
()
.
year
(
moment
().
year
()
-
1
)
.
startOf
(
'year'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
et
=
moment
(
moment
()
.
year
(
moment
().
year
()
-
1
)
.
endOf
(
'year'
)
.
format
(
'YYYY-MM-DD HH:mm:ss'
),
).
unix
();
break
;
}
return
{
st
,
et
}
}
export
const
isUrl
=
(
path
:
string
):
boolean
=>
reg
.
test
(
path
);
/**
* @description 用于将传入的接口,并行请求,并组装成Select组件可识别的形式返回
* @param asyncList {Array} 异步函数数组
*/
export
const
getAsyncSelectList
=
async
(
asyncList
:
any
[])
=>
{
try
{
const
result
=
await
Promise
.
all
(
asyncList
)
return
result
.
map
(
v
=>
v
.
data
.
map
(
j
=>
{
return
{
label
:
j
.
name
,
value
:
j
.
id
}
}))
}
catch
(
error
)
{
return
error
}
}
// 抽离对象中的某些属性, 并返回一个新对象
export
const
omit
=
(
obj
:
any
,
arr
:
string
[]):
any
=>
{
const
newObj
=
deepClone
(
obj
)
for
(
let
item
=
0
;
item
<
arr
.
length
;
item
++
)
{
if
(
obj
[
arr
[
item
]]
!==
undefined
)
{
delete
newObj
[
arr
[
item
]]
}
}
return
newObj
}
/**
* @param { Object[] } arr 源数据
* @param { any } target 目标值 通常是id等主键
* @param { string } customKey 可选 自定义主键 默认'id'
*/
export
const
findItemAndDelete
=
(
arr
:
any
[],
target
:
any
,
customKey
?:
string
)
=>
{
const
newArr
=
[...
arr
]
if
(
newArr
.
length
>
0
&&
isObject
(
newArr
[
0
]))
{
return
newArr
.
filter
(
v
=>
v
[
customKey
||
'id'
]
!==
target
)
}
const
targetIndex
=
arr
.
indexOf
(
target
)
if
(
targetIndex
===
-
1
)
{
return
newArr
}
else
{
newArr
.
splice
(
targetIndex
,
1
)
return
newArr
}
}
// 遍历树拿到所有key的集合
export
const
findTreeKeys
=
(
arr
:
any
[],
keyword
?:
string
)
=>
{
const
copyArr
:
any
[]
=
deepClone
(
arr
)
const
results
:
any
[]
=
[]
while
(
copyArr
.
length
>
0
)
{
const
item
=
copyArr
.
shift
()
results
.
push
(
keyword
?
item
[
keyword
]
:
item
.
key
)
if
(
item
.
children
)
{
copyArr
.
push
(...
item
.
children
)
}
}
return
results
}
// 树形结构降为一维对象处理
export
const
treeReduction
=
(
data
:
any
[])
=>
{
const
hashMaps
=
{}
const
selfData
:
any
[]
=
deepClone
(
data
)
while
(
selfData
.
length
>
0
)
{
const
useItem
=
selfData
.
shift
()
// 存在子集
if
(
useItem
.
children
&&
useItem
.
children
.
length
>
0
)
{
useItem
.
children
=
useItem
.
children
.
map
(
v
=>
{
v
.
parentId
=
useItem
.
id
return
v
})
selfData
.
push
(...
useItem
.
children
)
}
hashMaps
[
useItem
.
id
]
=
useItem
}
return
hashMaps
}
// 获取某一节点的title路径
export
const
getParentTreeTitles
=
(
dataSouce
,
key
)
=>
{
const
hashMaps
=
treeReduction
(
dataSouce
)
let
targetKey
=
key
let
targetPath
=
''
while
(
targetKey
!==
''
)
{
if
(
!
hashMaps
[
targetKey
])
{
break
}
const
title
=
hashMaps
[
targetKey
].
title
targetPath
=
targetPath
===
''
?
title
:
`
${
title
}
-
${
targetPath
}
`
targetKey
=
hashMaps
[
targetKey
].
parentId
||
''
}
return
targetPath
}
// 数组通过某个key进行去重合并, 并返回一个新数组
export
const
mergeArrByKey
=
(
preArr
:
any
[],
nextArr
:
any
[],
target
?:
string
)
=>
{
const
mergeArr
=
preArr
.
concat
(
nextArr
)
if
(
target
)
{
const
result
:
any
[]
=
[]
mergeArr
.
forEach
(
v
=>
{
const
s
=
result
.
find
(
j
=>
j
[
target
]
===
v
[
target
])
if
(
!
s
)
{
result
.
push
(
v
)
}
})
return
result
}
else
{
return
Array
.
from
(
new
Set
(
mergeArr
))
}
}
// 数组去重
export
const
dupliArr
=
(
arr
:
any
[])
=>
{
return
Array
.
from
(
new
Set
(
arr
))
}
// 填充必填的schema message提示
export
const
padRequiredMessage
=
(
originSchema
:
ISchema
)
=>
{
const
messageSwich
=
(
type
)
=>
{
return
type
?
'请选择'
:
'请输入'
}
const
todoFn
=
(
targetSchema
)
=>
{
}
Object
.
entries
(
originSchema
.
properties
).
map
(([
key
,
value
])
=>
{
if
(
value
.
required
)
{
const
isSelect
=
value
.
enum
const
message
=
messageSwich
(
isSelect
)
+
(
value
.
title
||
''
)
value
[
'x-rules'
]
=
Array
.
isArray
(
value
[
'x-rules'
])
?
value
[
'x-rules'
].
concat
([{
message
,
required
:
true
}])
:
[{
message
,
required
:
true
}]
}
if
(
value
.
properties
)
{
padRequiredMessage
(
value
)
}
return
value
})
return
originSchema
}
export
interface
FileData
{
uid
:
string
;
name
:
string
;
status
:
'uploading'
|
'done'
|
'error'
|
'removed'
;
url
:
string
;
};
/**
* 初始化 Upload 数据
*/
export
function
normalizeFiledata
(
url
:
string
):
FileData
export
function
normalizeFiledata
(
url
:
any
):
any
{
if
(
!
url
)
{
return
url
;
}
const
splited
=
url
.
split
(
'/'
);
const
fileName
=
splited
&&
splited
.
length
?
splited
[
splited
.
length
-
1
]
:
''
;
return
{
uid
:
Math
.
random
().
toFixed
(
16
).
slice
(
2
,
10
),
name
:
fileName
,
status
:
'done'
,
url
,
};
};
/**
* 检查是否还有更多
* @param {Number} curPage 当前页码
* @param {Number} curSize 当前页数
* @param {Number} dataLen 当前数据长度
* @param {Number} dataTotal 数据总长度
*/
export
const
checkMore
=
(
curPage
:
number
,
curSize
:
number
,
dataLen
:
number
,
dataTotal
:
number
)
=>
{
let
hasMore
=
true
;
if
(
!
dataLen
||
dataLen
+
(
curPage
-
1
)
*
curSize
>=
+
dataTotal
)
{
hasMore
=
false
;
}
return
hasMore
;
};
/**
*
* @param {string} str 需要判断是否是 JSON字符串的 字符串
*/
export
const
isJSONStr
=
str
=>
{
if
(
typeof
str
===
'string'
)
{
try
{
const
complete
=
JSON
.
parse
(
str
);
return
complete
;
}
catch
(
e
)
{
return
null
;
}
}
return
str
;
}
/**
* 给 Table columns 的 filters 赋值
* @param {array} data 需要赋值的数组
* @param {string} dataIndex 索引
* @param {array} item 需要赋值的值
*/
export
const
coverColFiltersItem
=
(
data
:
Array
<
{[
key
:
string
]:
any
}
>
,
dataIndex
:
string
,
item
:
{[
key
:
string
]:
any
}
)
=>
{
const
index
=
data
.
findIndex
(
i
=>
i
.
dataIndex
===
dataIndex
);
if
(
index
!==
-
1
)
{
data
.
splice
(
index
,
1
,
{
...
data
[
index
],
filters
:
item
,
});
}
};
export
default
{
isArray
,
isObject
,
transformDataPre
}
\ No newline at end of file
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