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

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

@@ -27,7 +27,7 @@
<!-- 配置值类型 -->
<a-form-item field="valueType" label="配置值类型">
<a-select v-model="formModel.valueType"
:options="toOptions(ValueTypeEnum)"
:options="toOptions(dictValueTypeKey)"
placeholder="请选择配置值类型" />
</a-form-item>
<!-- 配置描述 -->
@@ -43,7 +43,7 @@
<a-input-group>
<!-- 参数类型 -->
<a-select v-model="schema.type"
:options="toOptions(ValueTypeEnum)"
:options="toOptions(dictValueTypeKey)"
placeholder="类型"
:style="{ width: '110px' }" />
<!-- 参数值 -->
@@ -100,12 +100,12 @@
import formRules from '../types/form.rules';
import { Message } from '@arco-design/web-vue';
import { createDictKey, updateDictKey } from '@/api/system/dict-key';
import { definedExtraKeys, innerKeys } from '../types/const';
import { ValueTypeEnum } from '../types/enum.types';
import { toOptions } from '@/utils/enum';
import { definedExtraKeys, innerKeys, dictValueTypeKey, ValueType } from '../types/const';
import { useDictStore } from '@/store';
const { visible, setVisible } = useVisible();
const { loading, setLoading } = useLoading();
const { toOptions } = useDictStore();
const title = ref<string>();
const isAddHandle = ref<boolean>(true);
@@ -114,7 +114,7 @@
return {
id: undefined,
keyName: undefined,
valueType: ValueTypeEnum.INTEGER.value,
valueType: ValueType.INTEGER,
extraSchema: undefined,
description: undefined,
};
@@ -161,7 +161,7 @@
}
extraSchemaArr.value.push({
name: name,
type: type || ValueTypeEnum.STRING.value
type: type || ValueType.STRING
});
};

View File

@@ -62,8 +62,8 @@
</template>
<!-- 配置值类型 -->
<template #valueType="{ record }">
<a-tag :color="getEnumValue(record.valueType, ValueTypeEnum, 'color')">
{{ getEnumValue(record.valueType, ValueTypeEnum) }}
<a-tag :color="getDictValue(dictValueTypeKey, record.valueType, 'color')">
{{ getDictValue(dictValueTypeKey, record.valueType) }}
</a-tag>
</template>
<!-- 额外参数 -->
@@ -71,7 +71,7 @@
<template v-if="record.extraSchema">
<a-space>
<template v-for="item in JSON.parse(record.extraSchema)" :key="item.name">
<a-tag :color="getEnumValue(item.type, ValueTypeEnum, 'color')">
<a-tag :color="getDictValue(dictValueTypeKey, item.type, 'color')">
{{ item.name }}
</a-tag>
</template>
@@ -123,23 +123,23 @@
<script lang="ts" setup>
import type { DictKeyQueryRequest, DictKeyQueryResponse } from '@/api/system/dict-key';
import { reactive, ref } from 'vue';
import { reactive, ref, onMounted } from 'vue';
import { batchDeleteDictKey, deleteDictKey, getDictKeyPage } from '@/api/system/dict-key';
import { Message } from '@arco-design/web-vue';
import useLoading from '@/hooks/loading';
import columns from '../types/table.columns';
import { usePagination } from '@/types/table';
import {} from '../types/const';
import { ValueTypeEnum } from '../types/enum.types';
import { getEnumValue } from '@/utils/enum';
import { dictValueTypeKey } from '../types/const';
import useCopy from '@/hooks/copy';
import { useDictStore } from '@/store';
const tableRenderData = ref<DictKeyQueryResponse[]>([]);
const { loading, setLoading } = useLoading();
const emits = defineEmits(['openAdd', 'openUpdate', 'openView']);
const { copy } = useCopy();
const pagination = usePagination();
const { copy } = useCopy();
const { loading, setLoading } = useLoading();
const { toOptions, getDictValue } = useDictStore();
const formModel = reactive<DictKeyQueryRequest>({
id: undefined,
@@ -157,7 +157,7 @@
await deleteDictKey(id);
Message.success('删除成功');
// 重新加载数据
await fetchTableData();
fetchTableData();
} catch (e) {
} finally {
setLoading(false);
@@ -197,7 +197,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-key-table ref="table"
@openAdd="() => modal.openAdd()"
@@ -21,19 +21,18 @@
</script>
<script lang="ts" setup>
import { ref } from 'vue';
import { ref, onBeforeMount } from 'vue';
import DictKeyTable from './components/dict-key-table.vue';
import DictKeyFormModal from './components/dict-key-form-modal.vue';
import DictKeyViewModal from './components/dict-key-view-modal.vue';
import { useDictStore } from '@/store';
import { dictKeys } from './types/const';
const render = ref(false);
const table = ref();
const modal = ref();
const view = ref();
useDictStore().loadKeys(dictKeys);
// 添加回调
const modalAddCallback = () => {
table.value.addedCallback();
@@ -44,6 +43,12 @@
table.value.updatedCallback();
};
onBeforeMount(async () => {
const dictStore = useDictStore();
await dictStore.loadKeys(dictKeys);
render.value = true;
});
</script>
<style lang="less" scoped>

View File

@@ -1,9 +1,14 @@
// 配置值类型定义
export const ValueType = {
// 字符串
STRING: 'STRING',
// 整数
INTEGER: 'INTEGER',
// 小数
DECIMAL: 'DECIMAL',
// 布尔值
BOOLEAN: 'BOOLEAN',
// 颜色
COLOR: 'COLOR',
};

View File

@@ -1,31 +0,0 @@
/**
* 配置值定义
*/
export const ValueTypeEnum = {
STRING: {
label: '字符串',
value: 'STRING',
color: 'blue',
},
INTEGER: {
label: '整数',
value: 'INTEGER',
color: 'arcoblue',
},
DECIMAL: {
label: '小数',
value: 'DECIMAL',
color: 'purple',
},
BOOLEAN: {
label: '布尔值',
value: 'BOOLEAN',
color: 'pinkpurple',
},
COLOR: {
label: '颜色',
value: 'COLOR',
color: 'magenta',
},
};

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>

View File

@@ -182,7 +182,7 @@
<script lang="ts" setup>
import type { MenuQueryRequest, MenuQueryResponse } from '@/api/system/menu';
import { onMounted, reactive, ref } from 'vue';
import { reactive, ref, onMounted } from 'vue';
import useLoading from '@/hooks/loading';
import { getMenuList, deleteMenu, updateMenuStatus, initCache } from '@/api/system/menu';
import { menuStatusKey, menuVisibleKey, menuTypeKey, MenuType } from '../types/const';

View File

@@ -20,16 +20,14 @@
<script lang="ts" setup>
import MenuTable from '@/views/system/menu/components/menu-table.vue';
import MenuFormModal from '@/views/system/menu/components/menu-form-modal.vue';
import { onBeforeMount, onUnmounted, ref } from 'vue';
import { ref, onBeforeMount, onUnmounted } from 'vue';
import { useCacheStore, useDictStore } from '@/store';
import { dictKeys } from './types/const';
const table = ref();
const modal = ref();
// FIXME
const render = ref(false);
// FIXME
// 加载字典项
onBeforeMount(async () => {
const dictStore = useDictStore();
@@ -37,10 +35,10 @@
render.value = true;
});
// 卸载时清除 menu cache
// 卸载时清除 cache
onUnmounted(() => {
const cacheStore = useCacheStore();
cacheStore.set('menus', []);
cacheStore.reset('menus');
});
</script>