diff --git a/src/api/iot/product/index.ts b/src/api/iot/product/index.ts index 4c18426b..1bc45b9e 100644 --- a/src/api/iot/product/index.ts +++ b/src/api/iot/product/index.ts @@ -46,5 +46,10 @@ export const ProductApi = { // 导出iot 产品 Excel exportProduct: async (params) => { return await request.download({ url: `/iot/product/export-excel`, params }) + }, + + // 更新产品状态 + updateProductStatus: async (id: number, status: number) => { + return await request.put({ url: `/iot/product/update-status?id=` + id + `&status=` + status }) } -} \ No newline at end of file +} diff --git a/src/views/iot/product/ProductForm.vue b/src/views/iot/product/ProductForm.vue index f5a33cd4..21cee6c3 100644 --- a/src/views/iot/product/ProductForm.vue +++ b/src/views/iot/product/ProductForm.vue @@ -103,16 +103,15 @@ import { ProductApi, ProductVO } from '@/api/iot/product' import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' -/** iot 产品 表单 */ defineOptions({ name: 'ProductForm' }) -const { t } = useI18n() // 国际化 -const message = useMessage() // 消息弹窗 +const { t } = useI18n() +const message = useMessage() -const dialogVisible = ref(false) // 弹窗的是否展示 -const dialogTitle = ref('') // 弹窗的标题 -const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 -const formType = ref('') // 表单的类型:create - 新增;update - 修改 +const dialogVisible = ref(false) +const dialogTitle = ref('') +const formLoading = ref(false) +const formType = ref('') const formData = ref({ name: undefined, id: undefined, @@ -161,15 +160,13 @@ const formRules = reactive({ } ] }) -const formRef = ref() // 表单 Ref +const formRef = ref() -/** 打开弹窗 */ const open = async (type: string, id?: number) => { dialogVisible.value = true dialogTitle.value = t('action.' + type) formType.value = type resetForm() - // 修改时,设置数据 if (id) { formLoading.value = true try { @@ -179,14 +176,11 @@ const open = async (type: string, id?: number) => { } } } -defineExpose({ open }) // 提供 open 方法,用于打开弹窗 +defineExpose({ open, close: () => (dialogVisible.value = false) }) -/** 提交表单 */ -const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 +const emit = defineEmits(['success']) const submitForm = async () => { - // 校验表单 await formRef.value.validate() - // 提交请求 formLoading.value = true try { const data = formData.value as unknown as ProductVO @@ -197,15 +191,13 @@ const submitForm = async () => { await ProductApi.updateProduct(data) message.success(t('common.updateSuccess')) } - dialogVisible.value = false - // 发送操作成功的事件 + dialogVisible.value = false // 确保关闭弹框 emit('success') } finally { formLoading.value = false } } -/** 重置表单 */ const resetForm = () => { formData.value = { name: undefined, diff --git a/src/views/iot/product/detail/ProductDetailsHeader.vue b/src/views/iot/product/detail/ProductDetailsHeader.vue index 4314652b..b50001e8 100644 --- a/src/views/iot/product/detail/ProductDetailsHeader.vue +++ b/src/views/iot/product/detail/ProductDetailsHeader.vue @@ -10,36 +10,89 @@