@skyfox2000/webui 1.6.17 → 1.6.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyfox2000/webui",
3
- "version": "1.6.17",
3
+ "version": "1.6.19",
4
4
  "description": "后台前端通用组件定义, 支持国际化",
5
5
  "type": "module",
6
6
  "keywords": [],
@@ -17,6 +17,7 @@ import Switch from '../../form/switch/index.vue';
17
17
  import { AnyData } from '@skyfox2000/fapi';
18
18
  import { ProviderKeys } from '@/index';
19
19
  import { $t } from '@/locales/index';
20
+ import { getPermission } from '@/config/permission';
20
21
 
21
22
  const props = withDefaults(defineProps<{
22
23
  /**
@@ -59,10 +60,13 @@ defineOptions({
59
60
  const attrs = useAttrs(); // 手动获取 $attrs
60
61
 
61
62
  const gridCtrl = props.gridCtrl;
62
-
63
- // 响应式获取当前路由路径
64
63
  const currentPath = computed(() => AppRouter.currentRoute.value.path);
65
64
 
65
+ // 获取启用状态权限角色
66
+ const enabledRole = computed(() => {
67
+ return gridCtrl.permission?.enabled ?? getPermission().enabled ?? ['Super', 'Admin'];
68
+ });
69
+
66
70
  if (gridCtrl) {
67
71
  gridCtrl.pageNo.value = 1;
68
72
  gridCtrl.total.value = 0;
@@ -217,7 +221,7 @@ onMounted(async () => {
217
221
  <slot name="bodyCell" :column="bodyCell?.column" :record="bodyCell?.record"></slot>
218
222
  <template v-if="gridCtrl && bodyCell?.column?.dataIndex === 'enabled'">
219
223
  <Switch v-model:checked="bodyCell.record[gridCtrl.statusKey]"
220
- v-auth:disable="{ url: currentPath, role: ['Super', 'Admin'], permit: ':enabled' }"
224
+ v-auth:disable="{ url: currentPath, role: enabledRole, permit: ':enabled' }"
221
225
  :disabled="statusDisabled ? statusDisabled(bodyCell.record) : false" :data="OPTIONS.EnableDisable"
222
226
  @click="gridStatusUpdate(gridCtrl, bodyCell.record)" :class="[
223
227
  'w-[58px]',
@@ -10,31 +10,28 @@ import { getToolGroup, getToolVisible, getToolStatus, onToolClicked } from '@/ut
10
10
  import { ConfigProvider, Button, Space, DropdownButton, Menu, MenuItem, Popconfirm } from 'ant-design-vue';
11
11
  import { computed } from 'vue';
12
12
  import { $t } from '@/locales/index';
13
+ import { getPermission } from '@/config/permission';
13
14
 
14
15
  const props = defineProps<{
15
- /**
16
- * 数据行记录
17
- */
18
16
  record: Record<string, any>;
19
- /**
20
- * 表格数据控制
21
- */
22
17
  gridCtrl: GridControl<T>;
23
18
  }>();
24
19
 
25
20
  const gridCtrl = props.gridCtrl;
26
-
27
- // 响应式获取当前路由路径
28
21
  const currentPath = computed(() => AppRouter.currentRoute.value.path);
29
22
 
30
- /// 兼容其它按钮操作参数
31
- const defaultOperates: ButtonTool[] = [
23
+ // 获取权限角色:gridCtrl.permission > 全局配置 > 默认值
24
+ const getRole = (key: 'edit' | 'delete') => {
25
+ return gridCtrl.permission?.[key] ?? getPermission()[key] ?? ['Super', 'Admin'];
26
+ };
27
+
28
+ const defaultOperates = computed<ButtonTool[]>(() => [
32
29
  {
33
30
  key: 'Edit',
34
31
  label: $t('webui.common.edit'),
35
32
  type: 'primary',
36
33
  visible: true,
37
- role: ['Super', 'Admin'],
34
+ role: getRole('edit'),
38
35
  permit: ':edit',
39
36
  click: () => onGridRowEdit<T>(gridCtrl, props.record as T),
40
37
  },
@@ -44,15 +41,15 @@ const defaultOperates: ButtonTool[] = [
44
41
  type: 'primary',
45
42
  visible: true,
46
43
  danger: true,
47
- role: ['Super', 'Admin'],
44
+ role: getRole('delete'),
48
45
  permit: ':delete',
49
46
  confirm: true,
50
47
  confirmText: $t('webui.components.content.table.confirmDelete'),
51
48
  click: () => onGridRowDelete<T>(gridCtrl, props.record as T),
52
49
  },
53
- ];
50
+ ]);
54
51
 
55
- const { buttons, menus } = getToolGroup(defaultOperates, 0, gridCtrl.operates);
52
+ const { buttons, menus } = getToolGroup(defaultOperates.value, 0, gridCtrl.operates);
56
53
 
57
54
  const disabled = (item: ButtonTool): boolean => {
58
55
  if (typeof item.disabled == 'boolean') {
@@ -82,8 +79,7 @@ const disabled = (item: ButtonTool): boolean => {
82
79
  <template v-for="item in buttons" :key="item.key">
83
80
  <Popconfirm v-if="getToolVisible(item, props.record)" :disabled="disabled(item) || !item.confirm"
84
81
  :cancelText="$t('webui.common.no')" :okText="$t('webui.common.yes')" :title="item.confirmText"
85
- :okButtonProps="{ size: 'small' }"
86
- :cancelButtonProps="{ size: 'small' }"
82
+ :okButtonProps="{ size: 'small' }" :cancelButtonProps="{ size: 'small' }"
87
83
  @confirm="onToolClicked(item, gridCtrl.page, gridCtrl, props.record, true)">
88
84
  <Button :key="item.key" :type="item.type ?? 'text'" :danger="item.danger"
89
85
  v-if="getToolVisible(item, props.record)" :disabled="disabled(item)"
@@ -12,15 +12,10 @@ import { Button } from '../../common';
12
12
  import IconTool from './icontool.vue';
13
13
  import { ref, watch, computed } from 'vue';
14
14
  import { $t } from '@/locales/index';
15
+ import { getPermission } from '@/config/permission';
15
16
 
16
17
  const props = defineProps<{
17
- /**
18
- * 表格控制器
19
- */
20
18
  gridCtrl: GridControl<T>;
21
- /**
22
- * 表单控制器
23
- */
24
19
  editorCtrl: EditorControl<T>;
25
20
  }>();
26
21
 
@@ -28,23 +23,25 @@ const gridCtrl = props.gridCtrl;
28
23
  const pageCtrl = gridCtrl.page;
29
24
  const editorCtrl = props.editorCtrl;
30
25
 
31
- // 响应式获取当前路由路径
32
26
  const currentPath = computed(() => AppRouter.currentRoute.value.path);
33
27
 
34
- const defaultButtons: ButtonTool[] = [
28
+ // 获取权限角色:gridCtrl.permission > 全局配置 > 默认值
29
+ const newRole = computed(() => {
30
+ return gridCtrl.permission?.new ?? getPermission().new ?? ['Admin'];
31
+ });
32
+
33
+ const defaultButtons = computed<ButtonTool[]>(() => [
35
34
  {
36
35
  key: 'New',
37
36
  label: $t('webui.common.add'),
38
37
  type: 'primary',
39
38
  icon: 'icon-new',
40
39
  danger: true,
41
- role: ['Super', 'Admin'],
42
- permit: ':new', // 默认仅受权限码控制
43
- click: () => {
44
- return openNewForm(editorCtrl);
45
- },
40
+ role: newRole.value,
41
+ permit: ':new',
42
+ click: () => openNewForm(editorCtrl),
46
43
  },
47
- ];
44
+ ]);
48
45
 
49
46
  const MaxButtonCount = 3;
50
47
 
@@ -52,10 +49,10 @@ const ToolbarButtons = ref<ButtonTool[]>([]);
52
49
  const ToolbarMenus = ref<ButtonTool[]>([]);
53
50
 
54
51
  watch(
55
- () => gridCtrl.buttons?.value,
52
+ [() => gridCtrl.buttons?.value, defaultButtons],
56
53
  () => {
57
54
  const { buttons, menus } = getToolGroup(
58
- defaultButtons,
55
+ defaultButtons.value,
59
56
  gridCtrl.flat !== undefined ? gridCtrl.flat : MaxButtonCount,
60
57
  gridCtrl.buttons?.value,
61
58
  );
@@ -71,29 +68,19 @@ watch(
71
68
  <template>
72
69
  <div class="flex justify-between mb-[10px]">
73
70
  <Space>
74
- <Button
75
- v-for="item in ToolbarButtons"
76
- :key="item.key"
77
- :type="item.type"
78
- :danger="item.danger"
79
- :disabled="getToolStatus(item)"
80
- :icon="item.icon"
71
+ <Button v-for="item in ToolbarButtons" :key="item.key" :type="item.type" :danger="item.danger"
72
+ :disabled="getToolStatus(item)" :icon="item.icon"
81
73
  v-auth="{ url: currentPath, role: item.role, permit: item.permit }"
82
- @click="onToolClicked(item, pageCtrl, gridCtrl)"
83
- >
74
+ @click="onToolClicked(item, pageCtrl, gridCtrl)">
84
75
  {{ item.label }}
85
76
  </Button>
86
77
  <Dropdown v-if="ToolbarMenus.length > 0">
87
78
  <template #overlay>
88
79
  <Menu>
89
- <MenuItem
90
- v-for="item in ToolbarMenus"
91
- :key="item.key"
92
- :disabled="getToolStatus(item)"
80
+ <MenuItem v-for="item in ToolbarMenus" :key="item.key" :disabled="getToolStatus(item)"
93
81
  v-auth="{ url: currentPath, role: item.role, permit: item.permit }"
94
- @click="onToolClicked(item, pageCtrl, gridCtrl)"
95
- >
96
- {{ item.label }}
82
+ @click="onToolClicked(item, pageCtrl, gridCtrl)">
83
+ {{ item.label }}
97
84
  </MenuItem>
98
85
  </Menu>
99
86
  </template>
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 用户角色级别
3
+ */
4
+ export type UserRole = 'Super' | 'Admin' | 'User';
5
+
6
+ /**
7
+ * 操作权限配置
8
+ */
9
+ export interface OperatePermission {
10
+ /** 编辑按钮角色 */
11
+ edit?: UserRole[];
12
+ /** 删除按钮角色 */
13
+ delete?: UserRole[];
14
+ /** 启用/禁用切换角色 */
15
+ enabled?: UserRole[];
16
+ /** 新增按钮角色 */
17
+ new?: UserRole[];
18
+ }
19
+
20
+ /**
21
+ * 全局默认权限配置
22
+ */
23
+ export const defaultPermission: OperatePermission = {
24
+ edit: ['Super', 'Admin'],
25
+ delete: ['Super', 'Admin'],
26
+ enabled: ['Super', 'Admin'],
27
+ new: ['Admin'],
28
+ };
29
+
30
+ /**
31
+ * 设置全局默认权限
32
+ * @param config 权限配置
33
+ */
34
+ export const setPermission = (config: Partial<OperatePermission>) => {
35
+ Object.assign(defaultPermission, config);
36
+ };
37
+
38
+ /**
39
+ * 获取全局默认权限
40
+ */
41
+ export const getPermission = () => defaultPermission;
package/src/index.ts CHANGED
@@ -312,4 +312,7 @@ export type {
312
312
 
313
313
  export { uploadTempOpener, uploadTempBtn } from './utils/upload-template';
314
314
 
315
- export { i18n, initLang, $t, getAvailableLanguages, getLang, setLang } from './locales/index';
315
+ export { i18n, initLang, $t, getAvailableLanguages, getLang, setLang } from './locales/index';
316
+
317
+ export { setPermission, getPermission } from './config/permission';
318
+ export type { UserRole, OperatePermission } from './config/permission';
@@ -3,6 +3,7 @@ import { ButtonTools } from './tools';
3
3
  import { PageControl, PrimaryKey } from './page';
4
4
  import { EditorControl } from './form';
5
5
  import { AnyData, IUrlInfo, ReqParams, FindResult } from '@skyfox2000/fapi';
6
+ import { OperatePermission } from '@/config/permission';
6
7
 
7
8
  /**
8
9
  * 表格控制默认设置
@@ -179,4 +180,9 @@ export type GridControl<T> = GridControlOption & {
179
180
  * 表格数据删除后回调
180
181
  */
181
182
  afterDelete?: (record: T) => void;
183
+ /**
184
+ * 操作权限配置
185
+ * - 优先级高于全局配置
186
+ */
187
+ permission?: OperatePermission;
182
188
  };