1
0

feat(web): 增加一些amis结构的工具函数

This commit is contained in:
2024-12-01 11:17:44 +08:00
parent 4dcc10f2f7
commit b072b83f80
6 changed files with 224 additions and 268 deletions

View File

@@ -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 tpl = ignoreLength === 0 ? `\${${field}}` : `\${TRUNCATE(${field}, ${ignoreLength})}`
let content = extra let content = extra
? { ? {
@@ -121,6 +128,7 @@ export function copyField(field, tips = '复制', ignoreLength = 0, extra = unde
tpl: tpl, tpl: tpl,
} }
return { return {
name: field,
type: 'wrapper', type: 'wrapper',
size: 'none', size: 'none',
body: [ 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 = { let mapData = {
'*': `<span class='label bg-gray-300'>\${${field}}</span>`, '*': `<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>` mapData[item['value']] = `<span class='label ${item['color']}'>${item['label']}</span>`
}) })
return { return {
label: label,
type: 'mapping', type: 'mapping',
width: width,
value: `\${${field}}`, value: `\${${field}}`,
align: 'center',
map: mapData, map: mapData,
} }
} }

View File

@@ -16,22 +16,8 @@ const dialogBody = [
{ {
type: 'group', type: 'group',
body: [ body: [
{ mappingField('role', '角色', userRoleMapping),
type: 'control', mappingField('state', '账号状态', userStateMapping),
name: 'role',
label: '角色',
body: [
mappingField('role', userRoleMapping),
]
},
{
type: 'control',
name: 'state',
label: '账号状态',
body: [
mappingField('state', userStateMapping)
]
},
] ]
}, },
...formCreatedUserAndModifiedUser(), ...formCreatedUserAndModifiedUser(),

View File

@@ -4,7 +4,8 @@ import {
checkOverMapping, checkOverMapping,
checkTypeMapping, checkTypeMapping,
crudCommonOptions, crudCommonOptions,
mappingField mappingField,
operationField
} from "../../components/constants.js"; } from "../../components/constants.js";
import {permissionDetailDialog} from "../../components/permission/dialog-permission.js"; import {permissionDetailDialog} from "../../components/permission/dialog-permission.js";
@@ -27,25 +28,9 @@ export function tabCheck() {
name: 'description', name: 'description',
label: '描述', label: '描述',
}, },
{ mappingField('type', '类型', checkTypeMapping),
label: '类型', mappingField('over', '状态', checkOverMapping),
width: 80, operationField('操作', undefined, [
align: 'center',
...mappingField('type', checkTypeMapping)
},
{
label: '状态',
width: 80,
align: 'center',
...mappingField('over', checkOverMapping)
},
{
label: '操作',
width: 100,
type: 'operation',
fixed: 'right',
className: 'nowrap',
buttons: [
{ {
visibleOn: '${!over}', visibleOn: '${!over}',
type: 'action', type: 'action',
@@ -69,8 +54,7 @@ export function tabCheck() {
] ]
), ),
}, },
] ]),
}
] ]
} }
] ]

View File

@@ -11,6 +11,8 @@ import {
confirmationStateMapping, confirmationStateMapping,
crudCommonOptions, crudCommonOptions,
mappingField, mappingField,
operationField,
timeField,
userOnly userOnly
} from "../../components/constants.js"; } from "../../components/constants.js";
@@ -38,26 +40,9 @@ export function resourceList() {
label: '描述', label: '描述',
name: 'description', name: 'description',
}, },
{ mappingField('confirmationState', '确权状态', confirmationStateMapping),
label: '确权状态', timeField('createdTime', '创建时间'),
width: 80, operationField('操作', undefined, [
align: 'center',
...mappingField('confirmationState', confirmationStateMapping)
},
{
label: '创建时间',
width: 150,
align: 'center',
type: 'tpl',
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
},
{
label: '操作',
width: 100,
type: 'operation',
fixed: 'right',
className: 'nowrap',
buttons: [
{ {
type: 'action', type: 'action',
label: '详情', label: '详情',
@@ -93,8 +78,7 @@ export function resourceList() {
}, },
] ]
}, },
] ]),
},
] ]
} }
} }

View File

@@ -3,7 +3,9 @@ import {
confirmationStateMapping, confirmationStateMapping,
crudCommonOptions, crudCommonOptions,
mappingField, mappingField,
operationField,
providerOnly, providerOnly,
timeField,
userOnly userOnly
} from "../../components/constants.js"; } from "../../components/constants.js";
import { import {
@@ -49,26 +51,9 @@ export function tabPermissions() {
label: '描述', label: '描述',
name: 'description', name: 'description',
}, },
{ mappingField('state', '状态', confirmationStateMapping),
label: '状态', timeField('createdTime', '创建时间'),
width: 80, operationField('操作', undefined, [
align: 'center',
...mappingField('state', confirmationStateMapping)
},
{
label: '创建时间',
width: 150,
align: 'center',
type: 'tpl',
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
},
{
label: '操作',
width: 100,
type: 'operation',
fixed: 'right',
className: 'nowrap',
buttons: [
{ {
type: 'action', type: 'action',
label: '查看', label: '查看',
@@ -103,7 +88,7 @@ export function tabPermissions() {
trigger: 'hover', trigger: 'hover',
buttons: [ buttons: [
{ {
disabledOn: "${state === 'CHECKING'}", disabledOn: "${state !== 'DRAFT'}",
type: 'action', type: 'action',
label: '编辑', label: '编辑',
level: 'link', level: 'link',
@@ -114,14 +99,13 @@ export function tabPermissions() {
type: 'action', type: 'action',
label: "删除", label: "删除",
confirmTitle: '确认删除', confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的确权申请吗?', confirmText: '确认删除名称为「${name}」的确权申请吗?删除后对应的数据资源处于未确权状态。',
actionType: 'ajax', actionType: 'ajax',
api: apiGet('${base}/confirmation/remove/${id}'), api: apiGet('${base}/confirmation/remove/${id}'),
}, },
] ]
}, },
] ]),
},
] ]
} }
}, },

View File

@@ -4,6 +4,8 @@ import {
copyField, copyField,
crudCommonOptions, crudCommonOptions,
mappingField, mappingField,
operationField,
timeField,
userRoleMapping, userRoleMapping,
userStateMapping userStateMapping
} from '../../components/constants.js' } from '../../components/constants.js'
@@ -31,49 +33,18 @@ export function tabUser() {
}, },
], ],
columns: [ columns: [
{ copyField(
name: 'username',
label: '邮箱',
...copyField(
'username', 'username',
'邮箱',
undefined, undefined,
undefined, undefined,
userDetailDialog(), userDetailDialog(),
) ),
}, mappingField('role', '角色', userRoleMapping, 120),
{ mappingField('state', '账号状态', userStateMapping),
label: '角色', timeField('createdTime', '创建时间'),
width: 120, timeField('lastLoginTime', '上次登陆时间'),
align: 'center', operationField('操作', undefined, [
...mappingField('role', userRoleMapping)
},
{
label: '账号状态',
width: 80,
align: 'center',
...mappingField('state', userStateMapping)
},
{
label: '创建时间',
width: 150,
align: 'center',
type: 'tpl',
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
},
{
label: '上次登陆时间',
width: 150,
align: 'center',
type: 'tpl',
tpl: "${IF(lastLoginTime, DATETOSTR(lastLoginTime), '-')}"
},
{
label: '操作',
width: 100,
type: 'operation',
fixed: 'right',
className: 'nowrap',
buttons: [
{ {
visibleOn: "${state === 'CHECKING'}", visibleOn: "${state === 'CHECKING'}",
label: '审核', label: '审核',
@@ -104,8 +75,7 @@ export function tabUser() {
actionType: 'ajax', actionType: 'ajax',
api: apiGet('${base}/user_management/enable/${username}'), api: apiGet('${base}/user_management/enable/${username}'),
} }
] ]),
},
] ]
} }
] ]