ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<script lang="ts" setup>
import type { ActionItem, BasicColumn } from '@jnpf/ui/vxeTable';
 
import { computed, onMounted, reactive, ref, toRefs, unref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicLeftTree } from '@jnpf/ui';
import { useModal } from '@jnpf/ui/modal';
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { DownOutlined } from '@ant-design/icons-vue';
 
import { del as delButtonAuthorize, getButtonAuthorizeList, selectActions } from '#/api/system/buttonAuthorize';
import { del as delColumnAuthorize, getColumnAuthorizeList } from '#/api/system/columnAuthorize';
import { create, del as delDataAuthorize, getDataAuthorizeList } from '#/api/system/dataAuthorize';
import { del as delFormAuthorize, getFormAuthorizeList } from '#/api/system/formAuthorize';
import { getMenuList } from '#/api/system/menu';
import { $t } from '#/locales';
 
import ActionAuthForm from './actionAuthorize/Form.vue';
import ColumnAuthForm from './columnAuthorize/Form.vue';
import ActionModal from './components/ActionModal.vue';
import DataAuthForm from './dataAuthorize/Form.vue';
import BatchForm from './formAuthorize/BatchForm.vue';
import FormAuthForm from './formAuthorize/Form.vue';
 
defineOptions({ name: 'PermissionResource' });
 
const props = defineProps({
  isSystem: {
    type: Boolean,
    default: true,
  },
});
 
interface State {
  treeData: any[];
  treeLoading: boolean;
  tabActiveKey: string;
  activeKey: number;
  tableKey: number;
  searchInfo: any;
  menuType: any;
  webType: number;
  hasPermission: boolean;
}
 
const state = reactive<State>({
  treeData: [],
  treeLoading: false,
  tabActiveKey: 'Web',
  activeKey: 0,
  tableKey: 0,
  searchInfo: {
    menuId: '',
  },
  menuType: undefined,
  webType: 0,
  hasPermission: false,
});
const { treeData, treeLoading, tabActiveKey, activeKey } = toRefs(state);
const { createMessage } = useMessage();
const leftTreeRef = ref<Nullable<any>>(null);
const tabList = [
  { fullName: '动作', id: 0 },
  { fullName: '表单字段', id: 1 },
  { fullName: '列表字段', id: 2 },
  { fullName: '数据权限', id: 3 },
];
const noPermissionConfigList = new Set([4, 5, 6, 7, 8, 10]); // 4字典、5报表(原)、6大屏、7门户、8外链、9报表
const actionColumns: BasicColumn[] = [
  { title: '动作名称', dataIndex: 'fullName', minWidth: 200 },
  { title: '动作编码', dataIndex: 'enCode', width: 150 },
  { title: '状态', dataIndex: 'enabledMark', width: 70, align: 'center', slots: { default: 'enabledMark' } },
];
const formColumns: BasicColumn[] = [
  { title: '数据库表', dataIndex: 'bindTable', width: 180 },
  { title: '字段名称', dataIndex: 'enCode', width: 180 },
  { title: '字段说明', dataIndex: 'fullName', minWidth: 200 },
  { title: '排序', dataIndex: 'sortCode', width: 70, align: 'center' },
  { title: '状态', dataIndex: 'enabledMark', width: 70, align: 'center', slots: { default: 'enabledMark' } },
];
const dataColumns: BasicColumn[] = [
  { title: '方案编码', dataIndex: 'enCode', width: 160 },
  { title: '方案名称', dataIndex: 'fullName', width: 160 },
  { title: '过滤条件', dataIndex: 'conditionText', minWidth: 200 },
];
const [registerActionTable, { reload: reloadActionTable }] = useVxeTable({ api: getButtonAuthorizeList, columns: actionColumns });
const [registerFormTable, { reload: reloadFormTable }] = useVxeTable({ api: getFormAuthorizeList, columns: formColumns });
const [registerColumnTable, { reload: reloadColumnTable }] = useVxeTable({ api: getColumnAuthorizeList, columns: formColumns });
const [registerDataTable, { reload: reloadDataTable }] = useVxeTable({ api: getDataAuthorizeList, columns: dataColumns });
const [registerActionAuthForm, { openModal: openActionAuthFormModal }] = useModal();
const [registerFormAuthForm, { openModal: openFormAuthFormModal }] = useModal();
const [registerColumnAuthForm, { openModal: openColumnAuthFormModal }] = useModal();
const [registerDataAuthForm, { openModal: openDataAuthFormModal }] = useModal();
const [registerBatchForm, { openModal: openBatchFormModal }] = useModal();
const [registerAction, { openModal: openActionModal }] = useModal();
 
const getAlertMessage = computed(() => {
  if (state.menuType == 1) return '请选择右侧的菜单资源';
  if (state.menuType == 3 && state.webType === 4) return '视图菜单无权限配置,默认查看该菜单的全部数据和全部字段。';
  if (!state.hasPermission && !noPermissionConfigList.has(state.menuType))
    return '该菜单未开启资源的权限控制,默认查看该菜单的全部数据和全部字段。若需要开启,请在表单的“列表设计”中开启!';
  return '该菜单无可配置的权限资源(报表、大屏、门户、字典、外链类型的菜单无权限资源配置)';
});
const getTableBindValue = computed(() => ({
  searchInfo: state.searchInfo,
  immediate: false,
  actionColumn: {
    width: 100,
    title: '操作',
    dataIndex: 'action',
  },
  tableKey: state.tableKey,
}));
const getShowAlertStatus = computed(
  () => noPermissionConfigList.has(state.menuType) || (state.menuType == 3 && (!state.hasPermission || state.webType == 4)) || state.menuType == 1,
);
const getTabList = computed(() => {
  if (props.isSystem) return tabList.filter((o) => o.id === 0);
  if (state.menuType == 9) return tabList.filter((o) => o.id !== 1);
  return tabList;
});
 
function initTreeData() {
  state.treeLoading = true;
  getMenuList({ category: state.tabActiveKey })
    .then((res) => {
      state.treeData = res.data.list || [];
      state.treeLoading = false;
      if (!state.treeData.length) return;
      state.searchInfo.menuId = state.treeData[0]?.id;
      state.hasPermission = state.treeData[0]?.hasPermission || false;
      state.menuType = state.treeData[0]?.type;
      state.webType = state.treeData[0]?.webType;
      unref(leftTreeRef)?.setSelectedKeys([state.treeData[0]?.id]);
      setTimeout(() => {
        reload();
      }, 100);
    })
    .catch(() => {
      state.treeLoading = false;
    });
}
function handleTreeSelect(id, item) {
  if (id == state.searchInfo.menuId) return;
  state.searchInfo.menuId = id;
  state.menuType = item.type;
  state.webType = item.webType;
  state.hasPermission = !!item.hasPermission;
  state.tableKey = Date.now();
  state.activeKey = 0;
  onTabChange();
}
function onTabChange() {
  setTimeout(() => {
    reload();
  }, 10);
}
function handleAddAction({ key }) {
  if (key === 0) addOrUpdateHandle();
  if (key == 1) openActionModal(true, {});
}
function reload() {
  if (unref(getShowAlertStatus)) return;
  if (state.activeKey === 0) reloadActionTable();
  if (state.activeKey === 1) reloadFormTable();
  if (state.activeKey === 2) reloadColumnTable();
  if (state.activeKey === 3) reloadDataTable();
}
function getTableActions(record): ActionItem[] {
  return [
    {
      label: $t('common.editText'),
      disabled: record.enCode === 'jnpf_alldata' && state.activeKey == 3,
      onClick: addOrUpdateHandle.bind(null, record.id),
    },
    {
      label: $t('common.delText'),
      color: 'error',
      disabled: record.isMain == 1,
      modelConfirm: {
        onOk: handleDelete.bind(null, record.id),
      },
    },
  ];
}
function addOrUpdateHandle(id?) {
  let openFormModal = openActionAuthFormModal;
  if (state.activeKey === 1) openFormModal = openFormAuthFormModal;
  if (state.activeKey === 2) openFormModal = openColumnAuthFormModal;
  if (state.activeKey === 3) openFormModal = openDataAuthFormModal;
  openFormModal(true, { id, menuId: state.searchInfo.menuId, type: state.menuType, dataType: 2 });
}
function handleBatchAdd() {
  if (state.activeKey !== 1 && state.activeKey !== 2) return;
  const type = state.activeKey === 1 ? 'form' : 'column';
  openBatchFormModal(true, { menuId: state.searchInfo.menuId, type });
}
function handleDelete(id) {
  let del = delButtonAuthorize;
  if (state.activeKey === 1) del = delFormAuthorize;
  if (state.activeKey === 2) del = delColumnAuthorize;
  if (state.activeKey === 3) del = delDataAuthorize;
  del(id).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function onActionChange(ids) {
  selectActions({ ids, menuId: state.searchInfo.menuId }).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function handleAdd() {
  const data = {
    moduleId: state.searchInfo.menuId,
    enCode: 'jnpf_alldata',
    fullName: '全部数据',
    allData: 1,
  };
  create(data).then((res) => {
    createMessage.success(res.msg);
    reload();
  });
}
function onTabActiveKeyChange() {
  unref(leftTreeRef)?.clearSearchValue();
  initTreeData();
}
 
onMounted(() => {
  initTreeData();
});
</script>
<template>
  <div class="jnpf-content-wrapper">
    <div class="jnpf-content-wrapper-left !w-[260px]" :class="{ 'resource-content-wrapper-left': !isSystem }">
      <BasicLeftTree
        :title="isSystem ? '系统菜单' : '应用菜单'"
        ref="leftTreeRef"
        :tree-data="treeData"
        :loading="treeLoading"
        @select="handleTreeSelect"
        @reload="onTabActiveKeyChange">
        <template #headerTitle v-if="!isSystem">
          <a-tabs v-model:active-key="tabActiveKey" class="jnpf-content-wrapper-tabs" :tab-bar-gutter="10" @change="onTabActiveKeyChange">
            <a-tab-pane key="Web" tab="Web菜单" />
            <a-tab-pane key="App" tab="App菜单" />
          </a-tabs>
        </template>
      </BasicLeftTree>
    </div>
    <div class="jnpf-content-wrapper-center">
      <div class="jnpf-content-wrapper-content relative bg-white" v-loading="treeLoading">
        <div class="flex h-full w-full flex-col" v-if="!treeLoading">
          <template v-if="treeData.length">
            <a-alert :message="getAlertMessage" class="m-[10px]" type="warning" show-icon v-if="getShowAlertStatus" />
            <template v-else>
              <a-tabs v-model:active-key="activeKey" class="jnpf-content-wrapper-tabs" @change="onTabChange">
                <a-tab-pane :key="item.id" :tab="item.fullName" v-for="item in getTabList" />
              </a-tabs>
              <BasicVxeTable @register="registerActionTable" v-bind="getTableBindValue" v-if="activeKey === 0">
                <template #tableTitle>
                  <a-dropdown>
                    <template #overlay>
                      <a-menu @click="handleAddAction">
                        <a-menu-item :key="0"><i class="icon-ym icon-ym-btn-add pr-[5px]"></i>新建动作</a-menu-item>
                        <a-menu-item :key="1"> <i class="icon-ym icon-ym icon-ym-generator-user pr-[5px]"></i>选择动作</a-menu-item>
                      </a-menu>
                    </template>
                    <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add">添加动作<DownOutlined /></a-button>
                  </a-dropdown>
                </template>
                <template #enabledMark="{ record }">
                  <a-tag :color="record.enabledMark == 1 ? 'success' : 'error'">{{ record.enabledMark == 1 ? '启用' : '禁用' }}</a-tag>
                </template>
                <template #action="{ record }">
                  <TableAction :actions="getTableActions(record)" />
                </template>
              </BasicVxeTable>
              <BasicVxeTable @register="registerFormTable" v-bind="getTableBindValue" v-else-if="activeKey === 1">
                <template #tableTitle>
                  <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">新建</a-button>
                  <a-button type="link" pre-icon="ym-custom ym-custom-content-copy" @click="handleBatchAdd()">批量新增</a-button>
                </template>
                <template #enabledMark="{ record }">
                  <a-tag :color="record.enabledMark == 1 ? 'success' : 'error'">{{ record.enabledMark == 1 ? '启用' : '禁用' }}</a-tag>
                </template>
                <template #action="{ record }">
                  <TableAction :actions="getTableActions(record)" />
                </template>
              </BasicVxeTable>
              <BasicVxeTable @register="registerColumnTable" v-bind="getTableBindValue" v-else-if="activeKey === 2">
                <template #tableTitle>
                  <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">新建</a-button>
                  <a-button type="link" pre-icon="ym-custom ym-custom-content-copy" @click="handleBatchAdd()">批量新增</a-button>
                </template>
                <template #enabledMark="{ record }">
                  <a-tag :color="record.enabledMark == 1 ? 'success' : 'error'">{{ record.enabledMark == 1 ? '启用' : '禁用' }}</a-tag>
                </template>
                <template #action="{ record }">
                  <TableAction :actions="getTableActions(record)" />
                </template>
              </BasicVxeTable>
              <BasicVxeTable @register="registerDataTable" v-bind="getTableBindValue" v-else-if="activeKey === 3">
                <template #tableTitle>
                  <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">新建</a-button>
                  <a-dropdown>
                    <template #overlay>
                      <a-menu>
                        <a-menu-item @click="handleAdd">全部数据</a-menu-item>
                      </a-menu>
                    </template>
                    <a-button type="link" pre-icon="icon-ym icon-ym-btn-add">常用方案<DownOutlined /></a-button>
                  </a-dropdown>
                </template>
                <template #enabledMark="{ record }">
                  <a-tag :color="record.enabledMark == 1 ? 'success' : 'error'">{{ record.enabledMark == 1 ? '启用' : '禁用' }}</a-tag>
                </template>
                <template #action="{ record }">
                  <TableAction :actions="getTableActions(record)" />
                </template>
              </BasicVxeTable>
            </template>
          </template>
          <jnpf-empty class="mt-[150px]" v-else />
        </div>
      </div>
    </div>
    <ActionAuthForm @register="registerActionAuthForm" @reload="reload" />
    <FormAuthForm @register="registerFormAuthForm" @reload="reload" />
    <ColumnAuthForm @register="registerColumnAuthForm" @reload="reload" />
    <DataAuthForm @register="registerDataAuthForm" @reload="reload" />
    <BatchForm @register="registerBatchForm" @reload="reload" />
    <ActionModal @register="registerAction" @change="onActionChange" />
  </div>
</template>