refactor: 代码生成 字典下拉加载改为每次都重新加载
This commit is contained in:
parent
006370798b
commit
08de1a6f19
@ -4,9 +4,10 @@ import type { Ref } from 'vue';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { GenInfo } from '#/api/tool/gen/model';
|
||||
|
||||
import { inject } from 'vue';
|
||||
import { inject, onMounted, reactive } from 'vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { dictOptionSelectList } from '#/api/system/dict/dict-type';
|
||||
|
||||
import { validRules, vxeTableColumns } from './gen-data';
|
||||
|
||||
@ -15,8 +16,26 @@ import { validRules, vxeTableColumns } from './gen-data';
|
||||
*/
|
||||
const genInfoData = inject('genInfoData') as Ref<GenInfo['info']>;
|
||||
|
||||
const dictOptions = reactive<{ label: string; value: string }[]>([
|
||||
{ label: '未设置', value: '' },
|
||||
]);
|
||||
|
||||
/**
|
||||
* 加载字典下拉数据
|
||||
*/
|
||||
onMounted(async () => {
|
||||
const resp = await dictOptionSelectList();
|
||||
|
||||
const options = resp.map((dict) => ({
|
||||
label: `${dict.dictName} | ${dict.dictType}`,
|
||||
value: dict.dictType,
|
||||
}));
|
||||
|
||||
dictOptions.push(...options);
|
||||
});
|
||||
|
||||
const gridOptions: VxeGridProps = {
|
||||
columns: vxeTableColumns,
|
||||
columns: vxeTableColumns(dictOptions),
|
||||
keepSource: true,
|
||||
editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
|
||||
editRules: validRules,
|
||||
|
@ -2,14 +2,10 @@ import type { Recordable } from '@vben/types';
|
||||
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { reactive } from 'vue';
|
||||
|
||||
import { getPopupContainer } from '@vben/utils';
|
||||
|
||||
import { Checkbox, Input, Select } from 'ant-design-vue';
|
||||
|
||||
import { dictOptionSelectList } from '#/api/system/dict/dict-type';
|
||||
|
||||
const JavaTypes: string[] = [
|
||||
'Long',
|
||||
'String',
|
||||
@ -45,24 +41,6 @@ const componentsOptions = [
|
||||
{ label: '富文本', value: 'editor' },
|
||||
];
|
||||
|
||||
const dictOptions = reactive<{ label: string; value: string }[]>([
|
||||
{ label: '未设置', value: '' },
|
||||
]);
|
||||
/**
|
||||
* 在这里初始化字典下拉框
|
||||
*/
|
||||
(async function init() {
|
||||
const ret = await dictOptionSelectList();
|
||||
|
||||
ret.forEach((dict) => {
|
||||
const option = {
|
||||
label: `${dict.dictName} | ${dict.dictType}`,
|
||||
value: dict.dictType,
|
||||
};
|
||||
dictOptions.push(option);
|
||||
});
|
||||
})();
|
||||
|
||||
function renderBooleanTag(row: Recordable<any>, field: string) {
|
||||
const value = row[field] ? '是' : '否';
|
||||
const className = row[field] ? 'text-green-500' : 'text-red-500';
|
||||
@ -78,7 +56,10 @@ export const validRules: VxeGridProps['editRules'] = {
|
||||
javaField: [{ required: true, message: '请输入' }],
|
||||
};
|
||||
|
||||
export const vxeTableColumns: VxeGridProps['columns'] = [
|
||||
// 内部依赖的字典从外部通过函数传入
|
||||
export const vxeTableColumns: (
|
||||
dictOptions: { label: string; value: string }[],
|
||||
) => VxeGridProps['columns'] = (dictOptions) => [
|
||||
{
|
||||
title: '序号',
|
||||
type: 'seq',
|
||||
|
Loading…
Reference in New Issue
Block a user