feat: 字典
This commit is contained in:
parent
fdd1d19c8e
commit
d7d8784bb4
@ -1,6 +1,6 @@
|
||||
import type { DictType } from './dict-type-model';
|
||||
|
||||
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||
import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
|
||||
|
||||
import { commonExport } from '#/api/helper';
|
||||
import { requestClient } from '#/api/request';
|
||||
@ -18,8 +18,8 @@ enum Api {
|
||||
* @param params 请求参数
|
||||
* @returns list
|
||||
*/
|
||||
export function dictList(params?: PageQuery) {
|
||||
return requestClient.get<DictType[]>(Api.dictTypeList, { params });
|
||||
export function dictTypeList(params?: PageQuery) {
|
||||
return requestClient.get<PageResult<DictType>>(Api.dictTypeList, { params });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ export function dictList(params?: PageQuery) {
|
||||
* @param data 表单参数
|
||||
* @returns blob
|
||||
*/
|
||||
export function dictExport(data: any) {
|
||||
export function dictTypeExport(data: any) {
|
||||
return commonExport(Api.dictTypeExport, data);
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,14 @@
|
||||
import type { FormSchemaGetter } from '#/adapter';
|
||||
import type { FormSchemaGetter, VxeGridProps } from '#/adapter';
|
||||
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { renderDictTag } from '#/utils/render';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: 'TODO: 字典类型',
|
||||
getPopupContainer,
|
||||
},
|
||||
fieldName: 'dictType',
|
||||
@ -18,6 +21,43 @@ export const querySchema: FormSchemaGetter = () => [
|
||||
},
|
||||
];
|
||||
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{
|
||||
title: '字典标签',
|
||||
field: 'cssClass',
|
||||
slots: {
|
||||
default: ({ row }) => {
|
||||
const { dictValue } = row;
|
||||
return renderDictTag(dictValue, [row as any]);
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '字典键值',
|
||||
field: 'dictValue',
|
||||
},
|
||||
{
|
||||
title: '字典排序',
|
||||
field: 'dictSort',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
field: 'remark',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
field: 'createTime',
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
export const drawerSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
|
@ -1,63 +1,203 @@
|
||||
<script setup lang="ts">
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenDrawer } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
|
||||
|
||||
import { Card } from 'ant-design-vue';
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
||||
import {
|
||||
dictDataExport,
|
||||
dictDataList,
|
||||
dictDataRemove,
|
||||
} from '#/api/system/dict/dict-data';
|
||||
import { downloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { emitter } from '../mitt';
|
||||
import { querySchema } from './data';
|
||||
import { columns, querySchema } from './data';
|
||||
import dictDataDrawer from './dict-data-drawer.vue';
|
||||
|
||||
const dictType = ref('');
|
||||
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 80,
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
},
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
// 区间选择器处理
|
||||
if (formValues?.createTime) {
|
||||
formValues.params = {
|
||||
beginTime: dayjs(formValues.createTime[0]).format(
|
||||
'YYYY-MM-DD 00:00:00',
|
||||
),
|
||||
endTime: dayjs(formValues.createTime[1]).format(
|
||||
'YYYY-MM-DD 23:59:59',
|
||||
),
|
||||
};
|
||||
Reflect.deleteProperty(formValues, 'createTime');
|
||||
} else {
|
||||
Reflect.deleteProperty(formValues, 'params');
|
||||
}
|
||||
|
||||
const params: any = {
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
};
|
||||
if (dictType.value) {
|
||||
params.dictType = dictType.value;
|
||||
}
|
||||
|
||||
return await dictDataList(params);
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
keyField: 'dictCode',
|
||||
},
|
||||
round: true,
|
||||
align: 'center',
|
||||
showOverflow: true,
|
||||
};
|
||||
|
||||
const checked = ref(false);
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents: {
|
||||
checkboxChange: (e: any) => {
|
||||
checked.value = e.records.length > 0;
|
||||
},
|
||||
checkboxAll: (e: any) => {
|
||||
checked.value = e.records.length > 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const [DictDataDrawer, drawerApi] = useVbenDrawer({
|
||||
connectedComponent: dictDataDrawer,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
drawerApi.setData({ dictType: 'aa_bb_cc' });
|
||||
drawerApi.setData({ dictType: dictType.value });
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
const [QueryForm] = useVbenForm({
|
||||
// 默认展开
|
||||
collapsed: false,
|
||||
// 所有表单项共用,可单独在表单内覆盖
|
||||
commonConfig: {
|
||||
// 所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
async function handleEdit(record: Recordable<any>) {
|
||||
drawerApi.setData({
|
||||
dictType: dictType.value,
|
||||
dictCode: record.dictCode,
|
||||
});
|
||||
drawerApi.open();
|
||||
}
|
||||
|
||||
async function handleDelete(row: Recordable<any>) {
|
||||
await dictDataRemove(row.dictCode);
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: any) => row.dictCode);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await dictDataRemove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
// 是否可展开
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
text: '查询',
|
||||
},
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2',
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const testValue = ref('');
|
||||
|
||||
emitter.on('rowClick', (dictType) => {
|
||||
testValue.value = dictType;
|
||||
emitter.on('rowClick', async (value) => {
|
||||
dictType.value = value;
|
||||
await tableApi.query();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Card>
|
||||
<QueryForm />
|
||||
</Card>
|
||||
<Card>
|
||||
<a-button type="primary" @click="handleAdd">
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Card>
|
||||
{{ testValue }}
|
||||
<DictDataDrawer />
|
||||
</div>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable>
|
||||
<template #toolbar-actions>
|
||||
<span class="pl-[7px] text-[16px]">字典数据列表</span>
|
||||
</template>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button
|
||||
v-access:code="['system:dict:export']"
|
||||
@click="downloadExcel(dictDataExport, '字典数据', {})"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!checked"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['system:dict:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="dictType === ''"
|
||||
type="primary"
|
||||
v-access:code="['system:dict:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<a-button
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:dict:edit']"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</a-button>
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<a-button
|
||||
danger
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:dict:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
</Popconfirm>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<DictDataDrawer @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
@ -6,8 +6,17 @@ import DictTypePanel from './type/index.vue';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page content-class="flex flex-col gap-[16px] lg:flex-row">
|
||||
<DictTypePanel class="flex-1" />
|
||||
<DictDataPanel class="flex-1" />
|
||||
<Page :auto-content-height="true" content-class="flex flex-col lg:flex-row">
|
||||
<DictTypePanel class="flex-1 overflow-hidden" />
|
||||
<DictDataPanel class="flex-1 overflow-hidden" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/**
|
||||
TODO: ugly code
|
||||
*/
|
||||
:deep(.p-4) {
|
||||
padding: 6px;
|
||||
}
|
||||
</style>
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { type FormSchemaGetter, z } from '#/adapter';
|
||||
import { type FormSchemaGetter, type VxeGridProps, z } from '#/adapter';
|
||||
|
||||
export const querySchema: FormSchemaGetter = () => [
|
||||
{
|
||||
@ -13,6 +13,33 @@ export const querySchema: FormSchemaGetter = () => [
|
||||
},
|
||||
];
|
||||
|
||||
export const columns: VxeGridProps['columns'] = [
|
||||
{ type: 'checkbox', width: 60 },
|
||||
{
|
||||
title: '字典名称',
|
||||
field: 'dictName',
|
||||
},
|
||||
{
|
||||
title: '字典类型',
|
||||
field: 'dictType',
|
||||
},
|
||||
{
|
||||
title: '备注',
|
||||
field: 'remark',
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
field: 'createTime',
|
||||
},
|
||||
{
|
||||
field: 'action',
|
||||
fixed: 'right',
|
||||
slots: { default: 'action' },
|
||||
title: '操作',
|
||||
width: 180,
|
||||
},
|
||||
];
|
||||
|
||||
export const modalSchema: FormSchemaGetter = () => [
|
||||
{
|
||||
component: 'Input',
|
||||
|
@ -1,65 +1,197 @@
|
||||
<script setup lang="ts">
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { $t } from '@vben/locales';
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
import { Card } from 'ant-design-vue';
|
||||
import { uniqueId } from 'lodash-es';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter';
|
||||
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
|
||||
|
||||
import { Modal, Popconfirm, Space } from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import { useVbenVxeGrid, type VxeGridProps } from '#/adapter';
|
||||
import {
|
||||
dictTypeExport,
|
||||
dictTypeList,
|
||||
dictTypeRemove,
|
||||
} from '#/api/system/dict/dict-type';
|
||||
import { downloadExcel } from '#/utils/file/download';
|
||||
|
||||
import { emitter } from '../mitt';
|
||||
import { querySchema } from './data';
|
||||
import dictTypeModel from './dict-type-model.vue';
|
||||
import { columns, querySchema } from './data';
|
||||
import dictTypeModal from './dict-type-modal.vue';
|
||||
|
||||
defineOptions({ name: 'DictTypePanel' });
|
||||
const formOptions: VbenFormProps = {
|
||||
commonConfig: {
|
||||
labelWidth: 70,
|
||||
},
|
||||
schema: querySchema(),
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
|
||||
};
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
checkboxConfig: {
|
||||
// 高亮
|
||||
highlight: true,
|
||||
// 翻页时保留选中状态
|
||||
reserve: true,
|
||||
// 点击行选中
|
||||
// trigger: 'row',
|
||||
},
|
||||
columns,
|
||||
height: 'auto',
|
||||
keepSource: true,
|
||||
pagerConfig: {},
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }, formValues = {}) => {
|
||||
// 区间选择器处理
|
||||
if (formValues?.createTime) {
|
||||
formValues.params = {
|
||||
beginTime: dayjs(formValues.createTime[0]).format(
|
||||
'YYYY-MM-DD 00:00:00',
|
||||
),
|
||||
endTime: dayjs(formValues.createTime[1]).format(
|
||||
'YYYY-MM-DD 23:59:59',
|
||||
),
|
||||
};
|
||||
Reflect.deleteProperty(formValues, 'createTime');
|
||||
} else {
|
||||
Reflect.deleteProperty(formValues, 'params');
|
||||
}
|
||||
|
||||
return await dictTypeList({
|
||||
pageNum: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
...formValues,
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
rowConfig: {
|
||||
isHover: true,
|
||||
keyField: 'dictId',
|
||||
},
|
||||
round: true,
|
||||
align: 'center',
|
||||
showOverflow: true,
|
||||
};
|
||||
|
||||
const checked = ref(false);
|
||||
const lastDictType = ref('');
|
||||
|
||||
const [BasicTable, tableApi] = useVbenVxeGrid({
|
||||
formOptions,
|
||||
gridOptions,
|
||||
gridEvents: {
|
||||
cellClick: (e: any) => {
|
||||
const { row } = e;
|
||||
if (lastDictType.value === row.dictType) {
|
||||
return;
|
||||
}
|
||||
emitter.emit('rowClick', row.dictType);
|
||||
lastDictType.value = row.dictType;
|
||||
},
|
||||
checkboxChange: (e: any) => {
|
||||
checked.value = e.records.length > 0;
|
||||
},
|
||||
checkboxAll: (e: any) => {
|
||||
checked.value = e.records.length > 0;
|
||||
},
|
||||
},
|
||||
});
|
||||
const [DictTypeModal, modalApi] = useVbenModal({
|
||||
connectedComponent: dictTypeModel,
|
||||
connectedComponent: dictTypeModal,
|
||||
});
|
||||
|
||||
function handleAdd() {
|
||||
modalApi.setData({ update: false });
|
||||
modalApi.setData({});
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
const [QueryForm] = useVbenForm({
|
||||
// 默认展开
|
||||
collapsed: false,
|
||||
// 所有表单项共用,可单独在表单内覆盖
|
||||
commonConfig: {
|
||||
// 所有表单项
|
||||
componentProps: {
|
||||
class: 'w-full',
|
||||
},
|
||||
},
|
||||
schema: querySchema(),
|
||||
// 是否可展开
|
||||
showCollapseButton: true,
|
||||
submitButtonOptions: {
|
||||
text: '查询',
|
||||
},
|
||||
wrapperClass: 'grid-cols-1 md:grid-cols-2',
|
||||
});
|
||||
async function handleEdit(record: Recordable<any>) {
|
||||
modalApi.setData({ id: record.dictId });
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
function handleRowClickTest() {
|
||||
emitter.emit('rowClick', uniqueId('mitt-'));
|
||||
async function handleDelete(row: Recordable<any>) {
|
||||
await dictTypeRemove(row.dictId);
|
||||
await tableApi.query();
|
||||
}
|
||||
|
||||
function handleMultiDelete() {
|
||||
const rows = tableApi.grid.getCheckboxRecords();
|
||||
const ids = rows.map((row: any) => row.dictId);
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
okType: 'danger',
|
||||
content: `确认删除选中的${ids.length}条记录吗?`,
|
||||
onOk: async () => {
|
||||
await dictTypeRemove(ids);
|
||||
await tableApi.query();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<Card>
|
||||
<QueryForm />
|
||||
</Card>
|
||||
<Card>
|
||||
<a-button type="primary" @click="handleAdd">
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Card>
|
||||
<Card>
|
||||
<a-button @click="handleRowClickTest">测试mitt</a-button>
|
||||
左侧向右侧传值
|
||||
</Card>
|
||||
<DictTypeModal />
|
||||
</div>
|
||||
<Page :auto-content-height="true">
|
||||
<BasicTable>
|
||||
<template #toolbar-actions>
|
||||
<span class="pl-[7px] text-[16px]">字典类型列表</span>
|
||||
</template>
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<a-button danger type="primary">缓存(TODO)</a-button>
|
||||
<a-button
|
||||
v-access:code="['system:dict:export']"
|
||||
@click="downloadExcel(dictTypeExport, '字典类型数据', {})"
|
||||
>
|
||||
{{ $t('pages.common.export') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
:disabled="!checked"
|
||||
danger
|
||||
type="primary"
|
||||
v-access:code="['system:dict:remove']"
|
||||
@click="handleMultiDelete"
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="primary"
|
||||
v-access:code="['system:dict:add']"
|
||||
@click="handleAdd"
|
||||
>
|
||||
{{ $t('pages.common.add') }}
|
||||
</a-button>
|
||||
</Space>
|
||||
</template>
|
||||
<template #action="{ row }">
|
||||
<a-button
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:dict:edit']"
|
||||
@click="handleEdit(row)"
|
||||
>
|
||||
{{ $t('pages.common.edit') }}
|
||||
</a-button>
|
||||
<Popconfirm
|
||||
placement="left"
|
||||
title="确认删除?"
|
||||
@confirm="handleDelete(row)"
|
||||
>
|
||||
<a-button
|
||||
danger
|
||||
size="small"
|
||||
type="link"
|
||||
v-access:code="['system:dict:remove']"
|
||||
@click.stop=""
|
||||
>
|
||||
{{ $t('pages.common.delete') }}
|
||||
</a-button>
|
||||
</Popconfirm>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<DictTypeModal @reload="tableApi.query()" />
|
||||
</Page>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user