mirror of
https://gitee.com/JavaLionLi/plus-ui.git
synced 2026-09-15 08:25:10 +08:00
feat(dict): 添加字典生成枚举类功能
This commit is contained in:
parent
e9653ebcbc
commit
1e1dc1e89d
@ -12,6 +12,7 @@ export interface DictDataVO extends BaseEntity {
|
|||||||
listClass: ElTagType;
|
listClass: ElTagType;
|
||||||
dictSort: number;
|
dictSort: number;
|
||||||
remark: string;
|
remark: string;
|
||||||
|
enumName: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DictDataForm {
|
export interface DictDataForm {
|
||||||
@ -23,4 +24,5 @@ export interface DictDataForm {
|
|||||||
listClass: ElTagType;
|
listClass: ElTagType;
|
||||||
dictSort: number;
|
dictSort: number;
|
||||||
remark: string;
|
remark: string;
|
||||||
|
enumName: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
import type { PageResult } from '@/api/types';
|
import type { PageResult } from '@/api/types';
|
||||||
import type { AxiosPromise } from '@/utils/api-types';
|
import errorCode from '@/utils/errorCode';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
|
import type { AxiosPromise } from '@/utils/api-types';
|
||||||
|
import { blobValidate } from '@/utils/ruoyi';
|
||||||
|
import { saveBlob } from '@/utils/save';
|
||||||
import type { DictTypeForm, DictTypeQuery, DictTypeVO } from './types';
|
import type { DictTypeForm, DictTypeQuery, DictTypeVO } from './types';
|
||||||
|
|
||||||
// 查询字典类型列表
|
// 查询字典类型列表
|
||||||
@ -61,3 +64,29 @@ export function optionselect(): AxiosPromise<DictTypeVO[]> {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 生成字典枚举类压缩包
|
||||||
|
export function genEnum(dictTypes: string[]) {
|
||||||
|
const loading = ElLoading.service({
|
||||||
|
text: '正在下载数据,请稍候',
|
||||||
|
background: 'rgba(0, 0, 0, 0.7)'
|
||||||
|
});
|
||||||
|
return request({
|
||||||
|
url: '/system/dict/type/genEnum',
|
||||||
|
method: 'post',
|
||||||
|
data: dictTypes,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
.then(async (data: any) => {
|
||||||
|
if (blobValidate(data)) {
|
||||||
|
const blob = new Blob([data], { type: 'application/zip' });
|
||||||
|
saveBlob(blob, 'dict_enum.zip');
|
||||||
|
} else {
|
||||||
|
const resText = await new Blob([data]).text();
|
||||||
|
const rspObj = JSON.parse(resText);
|
||||||
|
const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'];
|
||||||
|
ElMessage.error(errMsg);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.finally(() => loading.close());
|
||||||
|
}
|
||||||
|
|||||||
@ -81,6 +81,17 @@
|
|||||||
>
|
>
|
||||||
导出
|
导出
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-if="isDev"
|
||||||
|
v-hasPermi="['system:dict:list']"
|
||||||
|
type="primary"
|
||||||
|
plain
|
||||||
|
icon="Download"
|
||||||
|
:disabled="typeMultiple"
|
||||||
|
@click="handleGenEnum"
|
||||||
|
>
|
||||||
|
生成枚举
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-hasPermi="['system:dict:remove']"
|
v-hasPermi="['system:dict:remove']"
|
||||||
type="danger"
|
type="danger"
|
||||||
@ -280,6 +291,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="字典键值" align="center" prop="dictValue" width="100" />
|
<el-table-column label="字典键值" align="center" prop="dictValue" width="100" />
|
||||||
|
<el-table-column label="枚举名称" align="center" prop="enumName" width="100" />
|
||||||
<el-table-column label="字典排序" align="center" prop="dictSort" width="80" />
|
<el-table-column label="字典排序" align="center" prop="dictSort" width="80" />
|
||||||
<el-table-column label="备注" align="center" prop="remark" width="100" />
|
<el-table-column label="备注" align="center" prop="remark" width="100" />
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||||
@ -386,6 +398,9 @@
|
|||||||
></el-option>
|
></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="枚举名称" prop="enumName">
|
||||||
|
<el-input v-model="dataForm.enumName" placeholder="请输入枚举名称(如: yes)" />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="备注" prop="remark">
|
<el-form-item label="备注" prop="remark">
|
||||||
<el-input v-model="dataForm.remark" type="textarea" placeholder="请输入内容"></el-input>
|
<el-input v-model="dataForm.remark" type="textarea" placeholder="请输入内容"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
@ -403,17 +418,21 @@
|
|||||||
<script setup name="Dict" lang="ts">
|
<script setup name="Dict" lang="ts">
|
||||||
import { listData, getData, delData, addData, updateData } from '@/api/system/dict/data';
|
import { listData, getData, delData, addData, updateData } from '@/api/system/dict/data';
|
||||||
import { DictDataForm, DictDataQuery, DictDataVO } from '@/api/system/dict/data/types';
|
import { DictDataForm, DictDataQuery, DictDataVO } from '@/api/system/dict/data/types';
|
||||||
import { listType, getType, delType, addType, updateType, refreshCache } from '@/api/system/dict/type';
|
import { listType, getType, delType, addType, updateType, refreshCache, genEnum } from '@/api/system/dict/type';
|
||||||
import { DictTypeForm, DictTypeQuery, DictTypeVO } from '@/api/system/dict/type/types';
|
import { DictTypeForm, DictTypeQuery, DictTypeVO } from '@/api/system/dict/type/types';
|
||||||
import modal from '@/plugins/modal';
|
import modal from '@/plugins/modal';
|
||||||
import { useDictStore } from '@/store/modules/dict';
|
import { useDictStore } from '@/store/modules/dict';
|
||||||
import { download as requestDownload } from '@/utils/request';
|
import { download as requestDownload } from '@/utils/request';
|
||||||
import { parseTime } from '@/utils/ruoyi';
|
import { parseTime } from '@/utils/ruoyi';
|
||||||
|
|
||||||
|
/** 是否开发环境(仅开发环境显示生成枚举按钮) */
|
||||||
|
const isDev = import.meta.env.DEV;
|
||||||
|
|
||||||
const typeList = ref<DictTypeVO[]>([]);
|
const typeList = ref<DictTypeVO[]>([]);
|
||||||
const typeLoading = ref(true);
|
const typeLoading = ref(true);
|
||||||
const showTypeSearch = ref(true);
|
const showTypeSearch = ref(true);
|
||||||
const typeIds = ref<Array<number | string>>([]);
|
const typeIds = ref<Array<number | string>>([]);
|
||||||
|
const typeSelections = ref<DictTypeVO[]>([]);
|
||||||
const typeSingle = ref(true);
|
const typeSingle = ref(true);
|
||||||
const typeMultiple = ref(true);
|
const typeMultiple = ref(true);
|
||||||
const typeTotal = ref(0);
|
const typeTotal = ref(0);
|
||||||
@ -489,7 +508,8 @@ const dataInitFormData: DictDataForm = {
|
|||||||
cssClass: '',
|
cssClass: '',
|
||||||
listClass: 'primary',
|
listClass: 'primary',
|
||||||
dictSort: 0,
|
dictSort: 0,
|
||||||
remark: ''
|
remark: '',
|
||||||
|
enumName: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
const dataState = reactive<PageData<DictDataForm, DictDataQuery>>({
|
const dataState = reactive<PageData<DictDataForm, DictDataQuery>>({
|
||||||
@ -504,7 +524,8 @@ const dataState = reactive<PageData<DictDataForm, DictDataQuery>>({
|
|||||||
rules: {
|
rules: {
|
||||||
dictLabel: [{ required: true, message: '数据标签不能为空', trigger: 'blur' }],
|
dictLabel: [{ required: true, message: '数据标签不能为空', trigger: 'blur' }],
|
||||||
dictValue: [{ required: true, message: '数据键值不能为空', trigger: 'blur' }],
|
dictValue: [{ required: true, message: '数据键值不能为空', trigger: 'blur' }],
|
||||||
dictSort: [{ required: true, message: '数据顺序不能为空', trigger: 'blur' }]
|
dictSort: [{ required: true, message: '数据顺序不能为空', trigger: 'blur' }],
|
||||||
|
enumName: [{ pattern: /^[A-Za-z_]+$/, message: '枚举名称只能包含英文字母和下划线', trigger: 'blur' }]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -574,6 +595,7 @@ const handleTypeAdd = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleTypeSelectionChange = (selection: DictTypeVO[]) => {
|
const handleTypeSelectionChange = (selection: DictTypeVO[]) => {
|
||||||
|
typeSelections.value = selection;
|
||||||
typeIds.value = selection.map(item => item.dictId);
|
typeIds.value = selection.map(item => item.dictId);
|
||||||
typeSingle.value = selection.length != 1;
|
typeSingle.value = selection.length != 1;
|
||||||
typeMultiple.value = !selection.length;
|
typeMultiple.value = !selection.length;
|
||||||
@ -617,6 +639,16 @@ const handleTypeExport = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 生成枚举类 */
|
||||||
|
const handleGenEnum = () => {
|
||||||
|
const dictTypes = typeSelections.value.map(item => item.dictType);
|
||||||
|
if (!dictTypes.length) {
|
||||||
|
modal.msgWarning('请选择要生成枚举的字典');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
genEnum(dictTypes);
|
||||||
|
};
|
||||||
|
|
||||||
const handleRefreshCache = async () => {
|
const handleRefreshCache = async () => {
|
||||||
await refreshCache();
|
await refreshCache();
|
||||||
modal.msgSuccess('刷新成功');
|
modal.msgSuccess('刷新成功');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user