refactor: 破坏性更新 dict 抽离

This commit is contained in:
xingyu4j
2025-09-05 12:00:24 +08:00
parent b79bebab18
commit 5ef57590e0
112 changed files with 397 additions and 518 deletions

View File

@@ -2,11 +2,12 @@ import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MallCategoryApi } from '#/api/mall/product/category';
import { CommonStatusEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { handleTree } from '@vben/utils';
import { z } from '#/adapter/form';
import { getCategoryList } from '#/api/mall/product/category';
import { CommonStatusEnum, DICT_TYPE, getDictOptions } from '#/utils';
/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {

View File

@@ -1,13 +1,13 @@
<script lang="ts" setup>
import { watch } from 'vue';
import { DeliveryTypeEnum } from '@vben/constants';
import { DeliveryTypeEnum, DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { ElMessage } from 'element-plus';
import { useVbenForm } from '#/adapter/form';
import * as ExpressTemplateApi from '#/api/mall/trade/delivery/expressTemplate';
import { DICT_TYPE, getIntDictOptions } from '#/utils';
const props = defineProps<{
propFormData: Object;
@@ -57,7 +57,7 @@ const [Form, formApi] = useVbenForm({
label: '配送方式',
component: 'CheckboxGroup',
componentProps: {
options: getIntDictOptions(DICT_TYPE.TRADE_DELIVERY_TYPE),
options: getDictOptions(DICT_TYPE.TRADE_DELIVERY_TYPE, 'number'),
},
rules: 'required',
},

View File

@@ -1,10 +1,14 @@
<script lang="ts" setup>
import type { DictDataType } from '@vben/hooks';
import type { MallSpuApi } from '#/api/mall/product/spu';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Page } from '@vben/common-ui';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { IconifyIcon } from '@vben/icons';
import { floatToFixed2 } from '@vben/utils';
@@ -25,7 +29,6 @@ import {
import * as ProductBrandApi from '#/api/mall/product/brand';
import * as ProductCategoryApi from '#/api/mall/product/category';
import * as ProductSpuApi from '#/api/mall/product/spu';
import { DICT_TYPE, getIntDictOptions } from '#/utils/dict';
interface Category {
id: number;
@@ -38,13 +41,6 @@ interface Brand {
name: string;
}
interface DictData {
value: number | string;
label: string;
colorType?: string;
cssClass?: string;
}
const { push } = useRouter(); // 路由
const { params } = useRoute(); // 查询参数
@@ -52,7 +48,7 @@ const formLoading = ref(false); // 表单的加载中1修改时的数据
const activeTab = ref('basic'); // 当前激活的标签页
const categoryList = ref<Category[]>([]); // 商品分类列表
const brandList = ref<Brand[]>([]); // 商品品牌列表
const deliveryTypeDict = ref<DictData[]>([]); // 配送方式字典
const deliveryTypeDict = ref<DictDataType[]>([]); // 配送方式字典
// SPU 表单数据
const formData = ref<MallSpuApi.Spu>({
@@ -90,8 +86,13 @@ const formData = ref<MallSpuApi.Spu>({
/** 获取配送方式字典 */
const getDeliveryTypeDict = async () => {
try {
deliveryTypeDict.value = await getIntDictOptions(
deliveryTypeDict.value = await getDictOptions(
DICT_TYPE.TRADE_DELIVERY_TYPE,
'number',
);
deliveryTypeDict.value = await getDictOptions(
DICT_TYPE.TRADE_DELIVERY_TYPE,
'number',
);
} catch (error) {
console.error('获取配送方式字典失败', error);