|
@@ -1,16 +1,18 @@
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
-import { type PropType, watch } from 'vue';
|
|
|
|
|
|
|
+import type { PropType } from 'vue';
|
|
|
|
|
+
|
|
|
|
|
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
|
|
|
|
|
+
|
|
|
|
|
+import { watch } from 'vue';
|
|
|
|
|
|
|
|
-import { useAccess } from '@vben/access';
|
|
|
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
import { useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
|
|
-import { Button, message, Modal } from 'ant-design-vue';
|
|
|
|
|
|
|
+import { Button, message } from 'ant-design-vue';
|
|
|
|
|
|
|
|
-import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
|
|
|
|
+import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
|
|
|
import { DictionaryApi } from '#/api';
|
|
import { DictionaryApi } from '#/api';
|
|
|
-import { TableAction } from '#/components/table-action';
|
|
|
|
|
|
|
|
|
|
-import { gridOptions, searchFormOptions } from './data.config';
|
|
|
|
|
|
|
+import { useColumns, useSearchSchema } from './data.config';
|
|
|
import FormEdit from './edit.vue';
|
|
import FormEdit from './edit.vue';
|
|
|
|
|
|
|
|
defineOptions({
|
|
defineOptions({
|
|
@@ -24,52 +26,18 @@ const props = defineProps({
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-const { hasAccessByCodes } = useAccess();
|
|
|
|
|
-
|
|
|
|
|
-const [Grid, { reload }] = useVbenVxeGrid({
|
|
|
|
|
- formOptions: searchFormOptions,
|
|
|
|
|
- gridOptions: {
|
|
|
|
|
- ...gridOptions,
|
|
|
|
|
-
|
|
|
|
|
- proxyConfig: {
|
|
|
|
|
- autoLoad: false,
|
|
|
|
|
- ajax: {
|
|
|
|
|
- query: async (_: any, formValues: any) => {
|
|
|
|
|
- const postData = { ...formValues };
|
|
|
|
|
- postData.type = props.type;
|
|
|
|
|
- return await DictionaryApi.getItemTree({
|
|
|
|
|
- ...postData,
|
|
|
|
|
- });
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
-});
|
|
|
|
|
-
|
|
|
|
|
const [FormEditModal, formEditApi] = useVbenModal({
|
|
const [FormEditModal, formEditApi] = useVbenModal({
|
|
|
connectedComponent: FormEdit,
|
|
connectedComponent: FormEdit,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-watch(
|
|
|
|
|
- () => props.type,
|
|
|
|
|
- () => {
|
|
|
|
|
- reload();
|
|
|
|
|
- },
|
|
|
|
|
- { deep: true },
|
|
|
|
|
-);
|
|
|
|
|
|
|
+const handelSuccess = () => {
|
|
|
|
|
+ reload();
|
|
|
|
|
+};
|
|
|
|
|
|
|
|
-const handleDelete = (id: number) => {
|
|
|
|
|
- Modal.confirm({
|
|
|
|
|
- iconType: 'info',
|
|
|
|
|
- title: '删除提示',
|
|
|
|
|
- content: `确定要删除选择的记录吗?`,
|
|
|
|
|
- cancelText: `关闭`,
|
|
|
|
|
- onOk: async () => {
|
|
|
|
|
- await DictionaryApi.deleteItemDetail(id);
|
|
|
|
|
- message.success('数据删除成功');
|
|
|
|
|
- reload();
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
|
|
+const handleDelete = async (id: number) => {
|
|
|
|
|
+ await DictionaryApi.deleteItemDetail(id);
|
|
|
|
|
+ message.success('数据删除成功');
|
|
|
|
|
+ reload();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const handleEdit = (record: any, isUpdate: boolean) => {
|
|
const handleEdit = (record: any, isUpdate: boolean) => {
|
|
@@ -77,17 +45,71 @@ const handleEdit = (record: any, isUpdate: boolean) => {
|
|
|
message.warning('请先选择字典类型');
|
|
message.warning('请先选择字典类型');
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- formEditApi.setData({
|
|
|
|
|
- isUpdate,
|
|
|
|
|
- baseData: { ...record, dictionaryCode: props.type },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- formEditApi.open();
|
|
|
|
|
|
|
+ formEditApi
|
|
|
|
|
+ .setData({
|
|
|
|
|
+ isUpdate,
|
|
|
|
|
+ baseData: { ...record, dictionaryCode: props.type },
|
|
|
|
|
+ })
|
|
|
|
|
+ .open();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-const handelSuccess = () => {
|
|
|
|
|
- reload();
|
|
|
|
|
|
|
+const handleActionClick = async ({
|
|
|
|
|
+ code,
|
|
|
|
|
+ row,
|
|
|
|
|
+}: OnActionClickParams<DictionaryApi.RecordItem>) => {
|
|
|
|
|
+ switch (code) {
|
|
|
|
|
+ case 'append': {
|
|
|
|
|
+ handleEdit({ parentId: row.id }, false);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'delete': {
|
|
|
|
|
+ await handleDelete(row.id);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 'edit': {
|
|
|
|
|
+ handleEdit({ id: row.id }, true);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+const [Grid, { reload }] = useVbenVxeGrid(
|
|
|
|
|
+ useTableGridOptions({
|
|
|
|
|
+ formOptions: {
|
|
|
|
|
+ schema: useSearchSchema(),
|
|
|
|
|
+ },
|
|
|
|
|
+ gridOptions: {
|
|
|
|
|
+ pagerConfig: {
|
|
|
|
|
+ enabled: false,
|
|
|
|
|
+ },
|
|
|
|
|
+ treeConfig: {
|
|
|
|
|
+ rowField: 'id',
|
|
|
|
|
+ childrenField: 'children',
|
|
|
|
|
+ },
|
|
|
|
|
+ columns: useColumns(handleActionClick),
|
|
|
|
|
+ proxyConfig: {
|
|
|
|
|
+ autoLoad: false,
|
|
|
|
|
+ ajax: {
|
|
|
|
|
+ query: async (_: any, formValues: any) => {
|
|
|
|
|
+ const postData = { ...formValues };
|
|
|
|
|
+ postData.type = props.type;
|
|
|
|
|
+ return await DictionaryApi.getItemTree({
|
|
|
|
|
+ ...postData,
|
|
|
|
|
+ });
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ } as VxeTableGridOptions,
|
|
|
|
|
+ }),
|
|
|
|
|
+);
|
|
|
|
|
+
|
|
|
|
|
+watch(
|
|
|
|
|
+ () => props.type,
|
|
|
|
|
+ () => {
|
|
|
|
|
+ reload();
|
|
|
|
|
+ },
|
|
|
|
|
+ { deep: true },
|
|
|
|
|
+);
|
|
|
</script>
|
|
</script>
|
|
|
<template>
|
|
<template>
|
|
|
<div class="h-full">
|
|
<div class="h-full">
|
|
@@ -103,32 +125,6 @@ const handelSuccess = () => {
|
|
|
新增字典项
|
|
新增字典项
|
|
|
</Button>
|
|
</Button>
|
|
|
</template>
|
|
</template>
|
|
|
- <template #action="{ row }">
|
|
|
|
|
- <TableAction
|
|
|
|
|
- :actions="[
|
|
|
|
|
- {
|
|
|
|
|
- label: '添加子项',
|
|
|
|
|
- type: 'text',
|
|
|
|
|
- disabled: !hasAccessByCodes(['dict-detail:add']),
|
|
|
|
|
- onClick: handleEdit.bind(null, { parentId: row.id }, false),
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- label: '编辑',
|
|
|
|
|
- type: 'text',
|
|
|
|
|
- disabled: !hasAccessByCodes(['dict-detail:edit']),
|
|
|
|
|
- onClick: handleEdit.bind(null, { id: row.id }, true),
|
|
|
|
|
- },
|
|
|
|
|
- ]"
|
|
|
|
|
- :drop-down-actions="[
|
|
|
|
|
- {
|
|
|
|
|
- label: '删除',
|
|
|
|
|
- type: 'text',
|
|
|
|
|
- disabled: !hasAccessByCodes(['dict-detail:delete']),
|
|
|
|
|
- onClick: handleDelete.bind(null, row.id),
|
|
|
|
|
- },
|
|
|
|
|
- ]"
|
|
|
|
|
- />
|
|
|
|
|
- </template>
|
|
|
|
|
</Grid>
|
|
</Grid>
|
|
|
</div>
|
|
</div>
|
|
|
</template>
|
|
</template>
|