1. 新增角色管理后台页面、路由与国际化文案 2. 重构API请求错误处理逻辑,统一拦截业务与HTTP错误 3. 新增确认弹窗组合式函数,区分取消与请求错误场景 4. 完善表格按钮权限与显示控制逻辑 5. 更新API参数规范与文档说明 6. 修复部分页面分页数据解析问题
50 lines
1.7 KiB
JavaScript
50 lines
1.7 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,
|
|
visible: btn.visible || (() => true)
|
|
}))
|
|
|
|
return { toolbarButtons, rowButtons }
|
|
}
|
|
|
|
export default useTableButtons
|