From 3744069aa22a108607ae9bb6ff41022578a3ef53 Mon Sep 17 00:00:00 2001 From: haohao <1036606149@qq.com> Date: Mon, 15 Dec 2025 22:48:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E3=80=90antd=E3=80=91=E3=80=90iot?= =?UTF-8?q?=E3=80=91=E4=BA=A7=E5=93=81=E8=AF=A6=E6=83=85=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=88=B0=20detail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web-antd/src/router/routes/modules/iot.ts | 2 +- .../src/views/iot/product/product/data.ts | 40 ++++------ .../product/{modules => }/detail/index.vue | 2 +- .../{modules => }/detail/modules/header.vue | 2 +- .../{modules => }/detail/modules/info.vue | 0 .../iot/product/product/modules/form.vue | 78 +++++++++---------- 6 files changed, 55 insertions(+), 69 deletions(-) rename apps/web-antd/src/views/iot/product/product/{modules => }/detail/index.vue (93%) rename apps/web-antd/src/views/iot/product/product/{modules => }/detail/modules/header.vue (98%) rename apps/web-antd/src/views/iot/product/product/{modules => }/detail/modules/info.vue (100%) diff --git a/apps/web-antd/src/router/routes/modules/iot.ts b/apps/web-antd/src/router/routes/modules/iot.ts index 3e7f87caf..1c885a4c6 100644 --- a/apps/web-antd/src/router/routes/modules/iot.ts +++ b/apps/web-antd/src/router/routes/modules/iot.ts @@ -19,7 +19,7 @@ const routes: RouteRecordRaw[] = [ activePath: '/iot/device/product', }, component: () => - import('#/views/iot/product/product/modules/detail/index.vue'), + import('#/views/iot/product/product/detail/index.vue'), }, { path: 'device/detail/:id', diff --git a/apps/web-antd/src/views/iot/product/product/data.ts b/apps/web-antd/src/views/iot/product/product/data.ts index e9e7809bf..6d21d05b2 100644 --- a/apps/web-antd/src/views/iot/product/product/data.ts +++ b/apps/web-antd/src/views/iot/product/product/data.ts @@ -14,18 +14,13 @@ import { getSimpleProductCategoryList } from '#/api/iot/product/category'; /** 产品分类列表缓存 */ let categoryList: IotProductCategoryApi.ProductCategory[] = []; - -/** 加载产品分类数据 */ -async function loadCategoryData() { - categoryList = await getSimpleProductCategoryList(); -} - -// 初始化加载分类数据 -// TODO @haohao:可以参考 /Users/yunai/Java/yudao-ui-admin-vben-v5/apps/web-antd/src/views/system/tenant/data.ts 简洁一点。 -loadCategoryData(); +getSimpleProductCategoryList().then((data) => (categoryList = data)); /** 新增/修改产品的表单 */ -export function useFormSchema(formApi?: any): VbenFormSchema[] { +export function useFormSchema( + formApi?: any, + generateProductKey?: () => string, +): VbenFormSchema[] { return [ { component: 'Input', @@ -59,7 +54,9 @@ export function useFormSchema(formApi?: any): VbenFormSchema[] { { type: 'default', onClick: () => { - formApi?.setFieldValue('productKey', generateProductKey()); + if (generateProductKey) { + formApi?.setFieldValue('productKey', generateProductKey()); + } }, }, { default: () => '重新生成' }, @@ -175,7 +172,10 @@ export function useFormSchema(formApi?: any): VbenFormSchema[] { } /** 基础表单字段(不含图标、图片、描述) */ -export function useBasicFormSchema(formApi?: any): VbenFormSchema[] { +export function useBasicFormSchema( + formApi?: any, + generateProductKey?: () => string, +): VbenFormSchema[] { return [ { component: 'Input', @@ -208,7 +208,9 @@ export function useBasicFormSchema(formApi?: any): VbenFormSchema[] { { type: 'default', onClick: () => { - formApi?.setFieldValue('productKey', generateProductKey()); + if (generateProductKey) { + formApi?.setFieldValue('productKey', generateProductKey()); + } }, }, { default: () => '重新生成' }, @@ -299,6 +301,7 @@ export function useBasicFormSchema(formApi?: any): VbenFormSchema[] { buttonStyle: 'solid', optionType: 'button', }, + defaultValue: 0, rules: 'required', }, { @@ -339,7 +342,6 @@ export function useAdvancedFormSchema(): VbenFormSchema[] { placeholder: '请输入产品描述', rows: 3, }, - formItemClass: 'col-span-2', // 让描述占满两列 }, ]; } @@ -404,13 +406,3 @@ export function useGridColumns(): VxeTableGridOptions['columns'] { ]; } -/** 生成 ProductKey(包含大小写字母和数字) */ -export function generateProductKey(): string { - const chars = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - let result = ''; - for (let i = 0; i < 16; i++) { - result += chars.charAt(Math.floor(Math.random() * chars.length)); - } - return result; -} diff --git a/apps/web-antd/src/views/iot/product/product/modules/detail/index.vue b/apps/web-antd/src/views/iot/product/product/detail/index.vue similarity index 93% rename from apps/web-antd/src/views/iot/product/product/modules/detail/index.vue rename to apps/web-antd/src/views/iot/product/product/detail/index.vue index 1769c8017..3ca0daee1 100644 --- a/apps/web-antd/src/views/iot/product/product/modules/detail/index.vue +++ b/apps/web-antd/src/views/iot/product/product/detail/index.vue @@ -28,7 +28,6 @@ const activeTab = ref('info'); provide('product', product); // 提供产品信息给子组件 /** 获取产品详情 */ -// TODO @haohao:因为 detail 是独立界面,所以不放在 modules 里,应该放在 web-antd/src/views/iot/product/product/detail/index.vue 里,更合理一些哈。 async function getProductData(productId: number) { loading.value = true; try { @@ -91,3 +90,4 @@ onMounted(async () => { + diff --git a/apps/web-antd/src/views/iot/product/product/modules/detail/modules/header.vue b/apps/web-antd/src/views/iot/product/product/detail/modules/header.vue similarity index 98% rename from apps/web-antd/src/views/iot/product/product/modules/detail/modules/header.vue rename to apps/web-antd/src/views/iot/product/product/detail/modules/header.vue index e298afe1d..52ae5ee85 100644 --- a/apps/web-antd/src/views/iot/product/product/modules/detail/modules/header.vue +++ b/apps/web-antd/src/views/iot/product/product/detail/modules/header.vue @@ -10,7 +10,7 @@ import { Button, Card, Descriptions, message, Modal } from 'ant-design-vue'; import { updateProductStatus } from '#/api/iot/product/product'; -import Form from '../../form.vue'; +import Form from '../../modules/form.vue'; interface Props { product: IotProductApi.Product; diff --git a/apps/web-antd/src/views/iot/product/product/modules/detail/modules/info.vue b/apps/web-antd/src/views/iot/product/product/detail/modules/info.vue similarity index 100% rename from apps/web-antd/src/views/iot/product/product/modules/detail/modules/info.vue rename to apps/web-antd/src/views/iot/product/product/detail/modules/info.vue diff --git a/apps/web-antd/src/views/iot/product/product/modules/form.vue b/apps/web-antd/src/views/iot/product/product/modules/form.vue index 1ead43b64..6f7fdb26f 100644 --- a/apps/web-antd/src/views/iot/product/product/modules/form.vue +++ b/apps/web-antd/src/views/iot/product/product/modules/form.vue @@ -1,7 +1,7 @@