From e6d83c1bd066bd4f9ec2a2185c8a3ecb1ec22dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=B5=A9=E6=B5=A9?= <1036606149@qq.com> Date: Sat, 7 Sep 2024 19:40:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9AIOT=20=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E7=AE=A1=E7=90=86=20=E5=8F=91=E5=B8=83=E4=BA=A7?= =?UTF-8?q?=E5=93=81=E5=92=8C=E4=BA=A7=E5=93=81=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/product/index.ts | 7 +- src/components/DictTag/src/DictTag.vue | 14 ++-- src/utils/formatTime.ts | 12 +-- src/views/iot/product/ProductForm.vue | 28 +++---- .../product/detail/ProductDetailsHeader.vue | 75 ++++++++++++++++--- .../iot/product/detail/ProductDetailsInfo.vue | 51 +++++++------ src/views/iot/product/detail/index.vue | 6 +- src/views/iot/product/index.vue | 26 +++---- 8 files changed, 139 insertions(+), 80 deletions(-) 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/components/DictTag/src/DictTag.vue b/src/components/DictTag/src/DictTag.vue index f84a47cb..8835774f 100644 --- a/src/components/DictTag/src/DictTag.vue +++ b/src/components/DictTag/src/DictTag.vue @@ -3,7 +3,7 @@ import { defineComponent, PropType, computed } from 'vue' import { isHexColor } from '@/utils/color' import { ElTag } from 'element-plus' import { DictDataType, getDictOptions } from '@/utils/dict' -import { isArray, isString, isNumber } from '@/utils/is' +import { isArray, isString, isNumber, isBoolean } from '@/utils/is' export default defineComponent({ name: 'DictTag', @@ -29,15 +29,15 @@ export default defineComponent({ }, setup(props) { const valueArr: any = computed(() => { - // 1.是Number类型的情况 - if (isNumber(props.value)) { + // 1. 是 Number 类型和 Boolean 类型的情况 + if (isNumber(props.value) || isBoolean(props.value)) { return [String(props.value)] } - // 2.是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol ) + // 2. 是字符串(进一步判断是否有包含分隔符号 -> props.sepSymbol ) else if (isString(props.value)) { return props.value.split(props.separator) } - // 3.数组 + // 3. 数组 else if (isArray(props.value)) { return props.value.map(String) } @@ -57,7 +57,7 @@ export default defineComponent({
diff --git a/src/utils/formatTime.ts b/src/utils/formatTime.ts index 134a986e..99eb428c 100644 --- a/src/utils/formatTime.ts +++ b/src/utils/formatTime.ts @@ -56,11 +56,11 @@ export const defaultShortcuts = [ * 时间日期转换 * @param date 当前时间,new Date() 格式 * @param format 需要转换的时间格式字符串 - * @description format 字符串随意,如 `YYYY-mm、YYYY-mm-dd` - * @description format 季度:"YYYY-mm-dd HH:MM:SS QQQQ" - * @description format 星期:"YYYY-mm-dd HH:MM:SS WWW" - * @description format 几周:"YYYY-mm-dd HH:MM:SS ZZZ" - * @description format 季度 + 星期 + 几周:"YYYY-mm-dd HH:MM:SS WWW QQQQ ZZZ" + * @description format 字符串随意,如 `YYYY-MM、YYYY-MM-DD` + * @description format 季度:"YYYY-MM-DD HH:mm:ss QQQQ" + * @description format 星期:"YYYY-MM-DD HH:mm:ss WWW" + * @description format 几周:"YYYY-MM-DD HH:mm:ss ZZZ" + * @description format 季度 + 星期 + 几周:"YYYY-MM-DD HH:mm:ss WWW QQQQ ZZZ" * @returns 返回拼接后的时间字符串 */ export function formatDate(date: Date, format?: string): string { @@ -110,7 +110,7 @@ export function getWeek(dateTime: Date): number { * @description param 3天: 60 * 60* 24 * 1000 * 3 * @returns 返回拼接后的时间字符串 */ -export function formatPast(param: string | Date, format = 'YYYY-mm-dd HH:MM:SS'): string { +export function formatPast(param: string | Date, format = 'YYYY-MM-DD HH:mm:ss'): string { // 传入格式处理、存储转换值 let t: any, s: number // 获取js 时间戳 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 @@
- + 编辑 + + 发布 + + + 撤销发布 +
- - {{ product.name }} - {{ product.identification }} - - + + + {{ product.productKey }} + 复制 - - + + + + 0 + 前往管理 - + diff --git a/src/views/iot/product/detail/ProductDetailsInfo.vue b/src/views/iot/product/detail/ProductDetailsInfo.vue index ced4a98e..e3b5483a 100644 --- a/src/views/iot/product/detail/ProductDetailsInfo.vue +++ b/src/views/iot/product/detail/ProductDetailsInfo.vue @@ -1,34 +1,41 @@