Files
mes-ui-d2/src/composables/useTableButtons.js
sheng 3eaea3116d
Some checks failed
Release pipeline / publish (push) Has been cancelled
Release pipeline / Always run job (push) Has been cancelled
feat: 新增工厂区域管理页面,修复Sass废弃警告
1. 新增生产配置-工厂模型-工厂区域完整CRUD页面
2. 新增通用表格、弹窗表单、i18n工具组件
3. 升级sass-loader并修复Sass废弃警告
4. 添加文档记录Sass迁移修复细节
2026-05-26 18:32:57 +08:00

49 lines
1.6 KiB
JavaScript

/**
* 按钮定义工具:消除 buttonList / tableButtonList 重复定义
*
* @param {Object} options
* @param {Array} options.toolbar 顶部工具栏按钮
* @param {Array} options.row 行内操作按钮
* @param {Function} permissionCheck 权限校验函数,默认 $permission
* @returns {{ toolbarButtons: Array, rowButtons: Array }}
*
* @example
* import useTableButtons from '@/composables/useTableButtons'
* // 在组件 data() 或 created() 中调用
* const { toolbarButtons, rowButtons } = useTableButtons({
* toolbar: [{ key: 'add', label: '新建', type: 'primary', auth: '/xxx/create', onClick: this.openDialog }],
* row: [{ key: 'edit', label: '编辑', auth: '/xxx/edit', onClick: this.handleEdit }],
* }, this.$permission)
*/
export function useTableButtons (options = {}, permissionCheck) {
const check = permissionCheck || (() => true)
const toolbarButtons = (options.toolbar || []).map(btn => ({
key: btn.key || btn.label,
label: btn.label,
icon: btn.icon,
type: btn.type || '',
size: btn.size || 'mini',
auth: btn.auth,
cssStyle: btn.cssStyle || {},
onClick: btn.onClick,
hasPermission: btn.auth ? check(btn.auth) : true
}))
const rowButtons = (options.row || []).map(btn => ({
key: btn.key || btn.label,
label: btn.label,
icon: btn.icon,
color: btn.color || '',
cssStyle: btn.cssStyle || { marginRight: '10px', cursor: 'pointer' },
auth: btn.auth,
confirm: btn.confirm || false,
onClick: btn.onClick,
hasPermission: btn.auth ? check(btn.auth) : true
}))
return { toolbarButtons, rowButtons }
}
export default useTableButtons