使用字典值替换所有枚举对象.

This commit is contained in:
lijiahang
2023-10-27 14:48:50 +08:00
parent d32f21dc91
commit 706492f54a
48 changed files with 395 additions and 360 deletions

View File

@@ -44,24 +44,25 @@
:field="name as string"
:label="name">
<!-- 字符串 -->
<a-input v-if="ValueTypeEnum.STRING.value === type"
<a-input v-if="ValueType.STRING === type"
v-model="extraValue[name]"
:placeholder="`请输入 ${name}`"
allow-clear />
<!-- 数字 -->
<a-input-number v-else-if="ValueTypeEnum.INTEGER.value === type || ValueTypeEnum.DECIMAL.value === type"
<a-input-number v-else-if="ValueType.INTEGER === type || ValueType.DECIMAL === type"
v-model="extraValue[name]"
:placeholder="`请输入 ${name}`"
:precision="ValueType.INTEGER === type ? 0 : 4"
allow-clear
hide-button />
<!-- 布尔值 -->
<a-switch v-else-if="ValueTypeEnum.BOOLEAN.value === type"
<a-switch v-else-if="ValueType.BOOLEAN === type"
type="round"
v-model="extraValue[name]"
checked-text="TRUE"
unchecked-text="FALSE" />
<!-- 颜色 -->
<template v-else-if="ValueTypeEnum.COLOR.value === type">
<template v-else-if="ValueType.COLOR === type">
<a-input v-model="extraValue[name]"
:placeholder="`请输入 ${name}`"
allow-clear
@@ -84,15 +85,14 @@
<script lang="ts" setup>
import type { DictValueUpdateRequest } from '@/api/system/dict-value';
import type { ExtraParamType } from '../../dict-key/types/const';
import { ref } from 'vue';
import useLoading from '@/hooks/loading';
import useVisible from '@/hooks/visible';
import formRules from '../types/form.rules';
import { createDictValue, updateDictValue } from '@/api/system/dict-value';
import { Message } from '@arco-design/web-vue';
import { ExtraParamType, innerKeys } from '../../dict-key/types/const';
import { ValueTypeEnum } from '../../dict-key/types/enum.types';
import {} from '@/utils/enum';
import { ValueType } from '../../dict-key/types/const';
import DictKeySelector from '@/components/system/dict-key/dict-key-selector.vue';
import { DictKeyQueryResponse } from '@/api/system/dict-key';
import { useCacheStore } from '@/store';
@@ -170,7 +170,7 @@
const nameKey = name as string;
const value = extraValue.value[nameKey];
if (value === undefined) {
if (type === ValueTypeEnum.BOOLEAN.value) {
if (type === ValueType.BOOLEAN) {
extraValue.value[nameKey] = false;
continue;
}

View File

@@ -128,7 +128,7 @@
<script lang="ts" setup>
import type { DictValueQueryRequest, DictValueQueryResponse } from '@/api/system/dict-value';
import { reactive, ref } from 'vue';
import { reactive, ref, onMounted } from 'vue';
import { batchDeleteDictValue, deleteDictValue, getDictValuePage } from '@/api/system/dict-value';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
@@ -137,14 +137,15 @@
import useCopy from '@/hooks/copy';
import DictKeySelector from '@/components/system/dict-key/dict-key-selector.vue';
const { copy } = useCopy();
const tableRenderData = ref<DictValueQueryResponse[]>([]);
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate', 'openHistory']);
const pagination = usePagination();
const selectedKeys = ref<number[]>([]);
const tableRenderData = ref<DictValueQueryResponse[]>([]);
const { copy } = useCopy();
const pagination = usePagination();
const rowSelection = useRowSelection();
const { loading, setLoading } = useLoading();
const formModel = reactive<DictValueQueryRequest>({
id: undefined,
@@ -165,7 +166,7 @@
Message.success(`成功删除${selectedKeys.value.length}条数据`);
selectedKeys.value = [];
// 重新加载数据
await fetchTableData();
fetchTableData();
} catch (e) {
} finally {
setLoading(false);
@@ -182,7 +183,7 @@
await deleteDictValue(id);
Message.success('删除成功');
// 重新加载数据
await fetchTableData();
fetchTableData();
} catch (e) {
} finally {
setLoading(false);
@@ -238,7 +239,10 @@
const fetchTableData = (page = 1, limit = pagination.pageSize, form = formModel) => {
doFetchTableData({ page, limit, ...form });
};
fetchTableData();
onMounted(() => {
fetchTableData();
});
</script>

View File

@@ -1,5 +1,5 @@
<template>
<div class="layout-container">
<div class="layout-container" v-if="render">
<!-- 列表-表格 -->
<dict-value-table ref="table"
@openAdd="() => modal.openAdd()"
@@ -21,11 +21,12 @@
import DictValueTable from './components/dict-value-table.vue';
import DictValueFormModal from './components/dict-value-form-modal.vue';
import { onUnmounted, ref } from 'vue';
import { ref, onBeforeMount, onUnmounted } from 'vue';
import { useCacheStore } from '@/store';
import { getDictKeyList } from '@/api/system/dict-key';
import { Message } from '@arco-design/web-vue';
const render = ref(false);
const table = ref();
const modal = ref();
const cacheStore = useCacheStore();
@@ -50,11 +51,16 @@
Message.error('配置项加载失败');
}
};
loadDictKeys();
onBeforeMount(async () => {
// 加载字典值
await loadDictKeys();
render.value = true;
});
// 卸载时清除 cache
onUnmounted(() => {
cacheStore.set('dictKeys', []);
cacheStore.reset('dictKeys');
});
</script>