feat(web): 增加一些amis结构的工具函数
This commit is contained in:
@@ -104,7 +104,14 @@ export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB)
|
||||
}
|
||||
}
|
||||
|
||||
export function copyField(field, tips = '复制', ignoreLength = 0, extra = undefined) {
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {string} tips
|
||||
* @param {number} ignoreLength
|
||||
* @param {{}} extra
|
||||
*/
|
||||
export function copyField(field, label, tips = '复制', ignoreLength = 0, extra = undefined) {
|
||||
let tpl = ignoreLength === 0 ? `\${${field}}` : `\${TRUNCATE(${field}, ${ignoreLength})}`
|
||||
let content = extra
|
||||
? {
|
||||
@@ -121,6 +128,7 @@ export function copyField(field, tips = '复制', ignoreLength = 0, extra = unde
|
||||
tpl: tpl,
|
||||
}
|
||||
return {
|
||||
name: field,
|
||||
type: 'wrapper',
|
||||
size: 'none',
|
||||
body: [
|
||||
@@ -139,7 +147,44 @@ export function copyField(field, tips = '复制', ignoreLength = 0, extra = unde
|
||||
}
|
||||
}
|
||||
|
||||
export function mappingField(field, mapping) {
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {number} width
|
||||
* @param {Array} buttons
|
||||
*/
|
||||
export function operationField(label, width = 100, buttons = []) {
|
||||
return {
|
||||
label: label,
|
||||
width: width,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: buttons,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {number} width
|
||||
*/
|
||||
export function timeField(field, label, width = 150) {
|
||||
return {
|
||||
label: label,
|
||||
width: width,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: `\${IF(${field}, DATETOSTR(${field}), '-')}`
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {[{label: *, value: *, color: string}]} mapping
|
||||
* @param {number} width
|
||||
*/
|
||||
export function mappingField(field, label, mapping, width = 80) {
|
||||
let mapData = {
|
||||
'*': `<span class='label bg-gray-300'>\${${field}}</span>`,
|
||||
}
|
||||
@@ -147,8 +192,11 @@ export function mappingField(field, mapping) {
|
||||
mapData[item['value']] = `<span class='label ${item['color']}'>${item['label']}</span>`
|
||||
})
|
||||
return {
|
||||
label: label,
|
||||
type: 'mapping',
|
||||
width: width,
|
||||
value: `\${${field}}`,
|
||||
align: 'center',
|
||||
map: mapData,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,8 @@ const dialogBody = [
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'control',
|
||||
name: 'role',
|
||||
label: '角色',
|
||||
body: [
|
||||
mappingField('role', userRoleMapping),
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'control',
|
||||
name: 'state',
|
||||
label: '账号状态',
|
||||
body: [
|
||||
mappingField('state', userStateMapping)
|
||||
]
|
||||
},
|
||||
mappingField('role', '角色', userRoleMapping),
|
||||
mappingField('state', '账号状态', userStateMapping),
|
||||
]
|
||||
},
|
||||
...formCreatedUserAndModifiedUser(),
|
||||
|
||||
Reference in New Issue
Block a user