【代码评审】IoT:产品、设备、物模型的代码

pull/542/head
YunaiV 2024-10-01 19:29:24 +08:00
parent 4b2800f723
commit 6d641177b8
15 changed files with 114 additions and 149 deletions

View File

@ -1,16 +1,16 @@
import request from '@/config/axios' import request from '@/config/axios'
// 设备 VO // IoT 设备 VO
export interface DeviceVO { export interface DeviceVO {
id: number // 设备 ID主键自增 id: number // 设备 ID主键自增
deviceKey: string // 设备唯一标识符,全局唯一,用于识别设备 deviceKey: string // 设备唯一标识符
deviceName: string // 设备名称,在产品内唯一,用于标识设备 deviceName: string // 设备名称
productId: number // 产品 ID关联 iot_product 表的 id productId: number // 产品编号
productKey: string // 产品 Key关联 iot_product 表的 product_key productKey: string // 产品标识
deviceType: number // 设备类型0 - 直连设备1 - 网关子设备2 - 网关设备 deviceType: number // 设备类型
nickname: string // 设备备注名称,供用户自定义备注 nickname: string // 设备备注名称
gatewayId: number // 网关设备 ID,子设备需要关联的网关设备 ID gatewayId: number // 网关设备 ID
status: number // 设备状态0 - 未激活1 - 在线2 - 离线3 - 已禁用 status: number // 设备状态
statusLastUpdateTime: Date // 设备状态最后更新时间 statusLastUpdateTime: Date // 设备状态最后更新时间
lastOnlineTime: Date // 最后上线时间 lastOnlineTime: Date // 最后上线时间
lastOfflineTime: Date // 最后离线时间 lastOfflineTime: Date // 最后离线时间
@ -22,17 +22,17 @@ export interface DeviceVO {
mqttClientId: string // MQTT 客户端 ID mqttClientId: string // MQTT 客户端 ID
mqttUsername: string // MQTT 用户名 mqttUsername: string // MQTT 用户名
mqttPassword: string // MQTT 密码 mqttPassword: string // MQTT 密码
authType: string // 认证类型(如一机一密、动态注册) authType: string // 认证类型
latitude: number // 设备位置的纬度,范围 -90.000000 ~ 90.000000 latitude: number // 设备位置的纬度
longitude: number // 设备位置的经度,范围 -180.000000 ~ 180.000000 longitude: number // 设备位置的经度
areaId: number // 地区编码,符合国家地区编码标准,关联地区表 areaId: number // 地区编码
address: string // 设备详细地址 address: string // 设备详细地址
serialNumber: string // 设备序列号 serialNumber: string // 设备序列号
} }
export interface DeviceUpdateStatusVO { export interface DeviceUpdateStatusVO {
id: number // 设备 ID主键自增 id: number // 设备 ID主键自增
status: number // 设备状态0 - 未激活1 - 在线2 - 离线3 - 已禁用 status: number // 设备状态
} }
// 设备 API // 设备 API

View File

@ -1,50 +1,51 @@
import request from '@/config/axios' import request from '@/config/axios'
// iot 产品 VO // IoT 产品 VO
export interface ProductVO { export interface ProductVO {
id: number // 产品编号
name: string // 产品名称 name: string // 产品名称
id: number // 产品ID
productKey: string // 产品标识 productKey: string // 产品标识
protocolId: number // 协议编号(脚本解析 id protocolId: number // 协议编号
categoryId: number // 产品所属品类标识符 categoryId: number // 产品所属品类标识符
description: string // 产品描述 description: string // 产品描述
validateType: number // 数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验 validateType: number // 数据校验级别
status: number // 产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS status: number // 产品状态
deviceType: number // 设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备 deviceType: number // 设备类型
netType: number // 联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他 netType: number // 联网方式
protocolType: number // 接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee protocolType: number // 接入网关协议
dataFormat: number // 数据格式, 0: 透传模式, 1: Alink JSON dataFormat: number // 数据格式
deviceCount: number // 设备数量 deviceCount: number // 设备数量
createTime: Date // 创建时间
} }
// iot 产品 API // IoT 产品 API
export const ProductApi = { export const ProductApi = {
// 查询iot 产品分页 // 查询产品分页
getProductPage: async (params: any) => { getProductPage: async (params: any) => {
return await request.get({ url: `/iot/product/page`, params }) return await request.get({ url: `/iot/product/page`, params })
}, },
// 查询iot 产品详情 // 查询产品详情
getProduct: async (id: number) => { getProduct: async (id: number) => {
return await request.get({ url: `/iot/product/get?id=` + id }) return await request.get({ url: `/iot/product/get?id=` + id })
}, },
// 新增iot 产品 // 新增产品
createProduct: async (data: ProductVO) => { createProduct: async (data: ProductVO) => {
return await request.post({ url: `/iot/product/create`, data }) return await request.post({ url: `/iot/product/create`, data })
}, },
// 修改iot 产品 // 修改产品
updateProduct: async (data: ProductVO) => { updateProduct: async (data: ProductVO) => {
return await request.put({ url: `/iot/product/update`, data }) return await request.put({ url: `/iot/product/update`, data })
}, },
// 删除iot 产品 // 删除产品
deleteProduct: async (id: number) => { deleteProduct: async (id: number) => {
return await request.delete({ url: `/iot/product/delete?id=` + id }) return await request.delete({ url: `/iot/product/delete?id=` + id })
}, },
// 导出iot 产品 Excel // 导出产品 Excel
exportProduct: async (params) => { exportProduct: async (params) => {
return await request.download({ url: `/iot/product/export-excel`, params }) return await request.download({ url: `/iot/product/export-excel`, params })
}, },
@ -54,7 +55,7 @@ export const ProductApi = {
return await request.put({ url: `/iot/product/update-status?id=` + id + `&status=` + status }) return await request.put({ url: `/iot/product/update-status?id=` + id + `&status=` + status })
}, },
// 查询产品(精简)列表 // 查询产品(精简列表
getSimpleProductList() { getSimpleProductList() {
return request.get({ url: '/iot/product/list-all-simple' }) return request.get({ url: '/iot/product/list-all-simple' })
} }

View File

@ -6,21 +6,21 @@ export interface ThinkModelFunctionVO {
identifier: string // 功能标识 identifier: string // 功能标识
name: string // 功能名称 name: string // 功能名称
description: string // 功能描述 description: string // 功能描述
productId: number // 产品ID关联 IotProductDO 的 id productId: number // 产品编号
productKey: string // 产品Key关联 IotProductDO 的 productKey productKey: string // 产品标识
type: number // 功能类型1 - 属性2 - 服务3 - 事件) type: number // 功能类型
property: string // 属性(存储 ThingModelProperty 的 JSON 数据) property: string // 属性
event: string // 事件(存储 ThingModelEvent 的 JSON 数据) event: string // 事件
service: string // 服务(存储服务的 JSON 数据) service: string // 服务
} }
// IoT 产品物模型 API // IoT 产品物模型 API
export const ThinkModelFunctionApi = { export const ThinkModelFunctionApi = {
// 查询IoT 产品物模型分页 // 查询产品物模型分页
getThinkModelFunctionPage: async (params: any) => { getThinkModelFunctionPage: async (params: any) => {
return await request.get({ url: `/iot/think-model-function/page`, params }) return await request.get({ url: `/iot/think-model-function/page`, params })
}, },
// 获得IoT 产品物模型 // 获得产品物模型
getThinkModelFunctionListByProductId: async (params: any) => { getThinkModelFunctionListByProductId: async (params: any) => {
return await request.get({ return await request.get({
url: `/iot/think-model-function/list-by-product-id`, url: `/iot/think-model-function/list-by-product-id`,
@ -28,27 +28,27 @@ export const ThinkModelFunctionApi = {
}) })
}, },
// 查询IoT 产品物模型详情 // 查询产品物模型详情
getThinkModelFunction: async (id: number) => { getThinkModelFunction: async (id: number) => {
return await request.get({ url: `/iot/think-model-function/get?id=` + id }) return await request.get({ url: `/iot/think-model-function/get?id=` + id })
}, },
// 新增IoT 产品物模型 // 新增产品物模型
createThinkModelFunction: async (data: ThinkModelFunctionVO) => { createThinkModelFunction: async (data: ThinkModelFunctionVO) => {
return await request.post({ url: `/iot/think-model-function/create`, data }) return await request.post({ url: `/iot/think-model-function/create`, data })
}, },
// 修改IoT 产品物模型 // 修改产品物模型
updateThinkModelFunction: async (data: ThinkModelFunctionVO) => { updateThinkModelFunction: async (data: ThinkModelFunctionVO) => {
return await request.put({ url: `/iot/think-model-function/update`, data }) return await request.put({ url: `/iot/think-model-function/update`, data })
}, },
// 删除IoT 产品物模型 // 删除产品物模型
deleteThinkModelFunction: async (id: number) => { deleteThinkModelFunction: async (id: number) => {
return await request.delete({ url: `/iot/think-model-function/delete?id=` + id }) return await request.delete({ url: `/iot/think-model-function/delete?id=` + id })
}, },
// 导出IoT 产品物模型 Excel // 导出产品物模型 Excel
exportThinkModelFunction: async (params) => { exportThinkModelFunction: async (params) => {
return await request.download({ url: `/iot/think-model-function/export-excel`, params }) return await request.download({ url: `/iot/think-model-function/export-excel`, params })
} }

View File

@ -57,8 +57,7 @@ const formData = ref({
id: undefined, id: undefined,
productId: undefined, productId: undefined,
deviceName: undefined, deviceName: undefined,
nickname: undefined, nickname: undefined
serialNumber: undefined
}) })
const formRules = reactive({ const formRules = reactive({
productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }], productId: [{ required: true, message: '产品不能为空', trigger: 'blur' }],
@ -66,7 +65,7 @@ const formRules = reactive({
{ {
pattern: /^[a-zA-Z0-9_.\-:@]{4,32}$/, pattern: /^[a-zA-Z0-9_.\-:@]{4,32}$/,
message: message:
'支持英文字母、数字、下划线_、中划线-)、点号(.)、半角冒号(:)和特殊字符@,长度限制为4~32个字符', '支持英文字母、数字、下划线_、中划线-)、点号(.)、半角冒号(:)和特殊字符@,长度限制为 4~32 个字符',
trigger: 'blur' trigger: 'blur'
} }
], ],
@ -79,7 +78,7 @@ const formRules = reactive({
} }
const length = value.replace(/[\u4e00-\u9fa5\u3040-\u30ff]/g, 'aa').length const length = value.replace(/[\u4e00-\u9fa5\u3040-\u30ff]/g, 'aa').length
if (length < 4 || length > 64) { if (length < 4 || length > 64) {
callback(new Error('备注名称长度限制为4~64个字符中文及日文算2个字符')) callback(new Error('备注名称长度限制为 4~64 个字符,中文及日文算 2 个字符'))
} else if (!/^[\u4e00-\u9fa5\u3040-\u30ff_a-zA-Z0-9]+$/.test(value)) { } else if (!/^[\u4e00-\u9fa5\u3040-\u30ff_a-zA-Z0-9]+$/.test(value)) {
callback(new Error('备注名称只能包含中文、英文字母、日文、数字和下划线_')) callback(new Error('备注名称只能包含中文、英文字母、日文、数字和下划线_'))
} else { } else {

View File

@ -59,6 +59,7 @@ const emit = defineEmits(['refresh'])
* @param text 需要复制的文本 * @param text 需要复制的文本
*/ */
const copyToClipboard = (text: string) => { const copyToClipboard = (text: string) => {
// TODO @haohao await
navigator.clipboard.writeText(text).then(() => { navigator.clipboard.writeText(text).then(() => {
message.success('复制成功') message.success('复制成功')
}) })

View File

@ -3,33 +3,33 @@
<el-collapse v-model="activeNames"> <el-collapse v-model="activeNames">
<el-descriptions :column="3" title="设备信息"> <el-descriptions :column="3" title="设备信息">
<el-descriptions-item label="产品名称">{{ product.name }}</el-descriptions-item> <el-descriptions-item label="产品名称">{{ product.name }}</el-descriptions-item>
<el-descriptions-item label="ProductKey" <el-descriptions-item label="ProductKey">
>{{ product.productKey }} {{ product.productKey }}
<el-button @click="copyToClipboard(product.productKey)"></el-button> <el-button @click="copyToClipboard(product.productKey)"></el-button>
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="设备类型"> <el-descriptions-item label="设备类型">
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" /> <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" />
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="DeviceName" <el-descriptions-item label="DeviceName">
>{{ device.deviceName }} {{ device.deviceName }}
<el-button @click="copyToClipboard(device.deviceName)"></el-button> <el-button @click="copyToClipboard(device.deviceName)"></el-button>
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="备注名称">{{ device.nickname }}</el-descriptions-item> <el-descriptions-item label="备注名称">{{ device.nickname }}</el-descriptions-item>
<el-descriptions-item label="创建时间">{{ <el-descriptions-item label="创建时间">
formatDate(device.createTime) {{ formatDate(device.createTime) }}
}}</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="激活时间">{{ <el-descriptions-item label="激活时间">
formatDate(device.activeTime) {{ formatDate(device.activeTime) }}
}}</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="最后上线时间">{{ <el-descriptions-item label="最后上线时间">
formatDate(device.lastOnlineTime) {{ formatDate(device.lastOnlineTime) }}
}}</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="当前状态"> <el-descriptions-item label="当前状态">
<dict-tag :type="DICT_TYPE.IOT_DEVICE_STATUS" :value="device.status" /> <dict-tag :type="DICT_TYPE.IOT_DEVICE_STATUS" :value="device.status" />
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="最后离线时间" :span="3">{{ <el-descriptions-item label="最后离线时间" :span="3">
formatDate(device.lastOfflineTime) {{ formatDate(device.lastOfflineTime) }}
}}</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="MQTT 连接参数"> <el-descriptions-item label="MQTT 连接参数">
<el-button type="primary" @click="openMqttParams"></el-button> <el-button type="primary" @click="openMqttParams"></el-button>
</el-descriptions-item> </el-descriptions-item>
@ -53,7 +53,6 @@
</template> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="username"> <el-form-item label="username">
<el-input v-model="mqttParams.mqttUsername" readonly> <el-input v-model="mqttParams.mqttUsername" readonly>
<template #append> <template #append>
@ -63,7 +62,6 @@
</template> </template>
</el-input> </el-input>
</el-form-item> </el-form-item>
<el-form-item label="passwd"> <el-form-item label="passwd">
<el-input v-model="mqttParams.mqttPassword" readonly type="password"> <el-input v-model="mqttParams.mqttPassword" readonly type="password">
<template #append> <template #append>
@ -87,39 +85,28 @@ import { ProductVO } from '@/api/iot/product'
import { formatDate } from '@/utils/formatTime' import { formatDate } from '@/utils/formatTime'
import { DeviceVO } from '@/api/iot/device' import { DeviceVO } from '@/api/iot/device'
// const message = useMessage() //
const message = useMessage()
// const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>() // Props
const router = useRouter()
// Props const emit = defineEmits(['refresh']) // Emits
const { product, device } = defineProps<{ product: ProductVO; device: DeviceVO }>()
// Emits const activeNames = ref(['basicInfo']) //
const emit = defineEmits(['refresh']) const mqttDialogVisible = ref(false) // MQTT
const mqttParams = ref({
mqttClientId: '',
mqttUsername: '',
mqttPassword: ''
}) // MQTT
// /** 复制到剪贴板方法 */
const activeNames = ref(['basicInfo'])
//
const copyToClipboard = (text: string) => { const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text).then(() => { navigator.clipboard.writeText(text).then(() => {
message.success('复制成功') message.success('复制成功')
}) })
} }
// MQTT /** 打开 MQTT 参数弹框的方法 */
const mqttDialogVisible = ref(false)
// MQTT
const mqttParams = ref({
mqttClientId: '',
mqttUsername: '',
mqttPassword: ''
})
// MQTT
const openMqttParams = () => { const openMqttParams = () => {
mqttParams.value = { mqttParams.value = {
mqttClientId: device.mqttClientId || 'N/A', mqttClientId: device.mqttClientId || 'N/A',
@ -129,7 +116,7 @@ const openMqttParams = () => {
mqttDialogVisible.value = true mqttDialogVisible.value = true
} }
// MQTT /** 关闭 MQTT 弹框的方法 */
const handleCloseMqttDialog = () => { const handleCloseMqttDialog = () => {
mqttDialogVisible.value = false mqttDialogVisible.value = false
} }

View File

@ -192,9 +192,8 @@ const queryParams = reactive({
status: undefined status: undefined
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 产品ID到名称的映射 */ /** 产品标号和名称的映射 */
const productMap = reactive({}) const productMap = reactive({})
/** 查询列表 */ /** 查询列表 */
@ -207,6 +206,7 @@ const getList = async () => {
// ID // ID
const productIds = [...new Set(data.list.map((device) => device.productId))] const productIds = [...new Set(data.list.map((device) => device.productId))]
// //
// TODO @haohao
const products = await Promise.all(productIds.map((id) => ProductApi.getProduct(id))) const products = await Promise.all(productIds.map((id) => ProductApi.getProduct(id)))
products.forEach((product) => { products.forEach((product) => {
productMap[product.id] = product.name productMap[product.id] = product.name
@ -235,7 +235,7 @@ const openForm = (type: string, id?: number) => {
} }
/** 打开详情 */ /** 打开详情 */
const { currentRoute, push } = useRouter() const { push } = useRouter()
const openDetail = (id: number) => { const openDetail = (id: number) => {
push({ name: 'IoTDeviceDetail', params: { id } }) push({ name: 'IoTDeviceDetail', params: { id } })
} }
@ -252,6 +252,7 @@ const handleDelete = async (id: number) => {
await getList() await getList()
} catch {} } catch {}
} }
/** 查询字典下拉列表 */ /** 查询字典下拉列表 */
const products = ref() const products = ref()
const getProducts = async () => { const getProducts = async () => {

View File

@ -128,15 +128,10 @@ const formData = ref({
}) })
const formRules = reactive({ const formRules = reactive({
name: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }], name: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
deviceType: [ deviceType: [{ required: true, message: '设备类型不能为空', trigger: 'change' }],
{
required: true,
message: '设备类型不能为空',
trigger: 'change'
}
],
netType: [ netType: [
{ {
// TODO @haohao01/2 required true v-if
required: formData.deviceType === 0 || formData.deviceType === 2, required: formData.deviceType === 0 || formData.deviceType === 2,
message: '联网方式不能为空', message: '联网方式不能为空',
trigger: 'change' trigger: 'change'
@ -145,23 +140,12 @@ const formRules = reactive({
protocolType: [ protocolType: [
{ required: formData.deviceType === 1, message: '接入网关协议不能为空', trigger: 'change' } { required: formData.deviceType === 1, message: '接入网关协议不能为空', trigger: 'change' }
], ],
dataFormat: [ dataFormat: [{ required: true, message: '数据格式不能为空', trigger: 'change' }],
{ validateType: [{ required: true, message: '数据校验级别不能为空', trigger: 'change' }]
required: true,
message: '数据格式不能为空',
trigger: 'change'
}
],
validateType: [
{
required: true,
message: '数据校验级别不能为空',
trigger: 'change'
}
]
}) })
const formRef = ref() const formRef = ref()
/** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
@ -178,6 +162,7 @@ const open = async (type: string, id?: number) => {
} }
defineExpose({ open, close: () => (dialogVisible.value = false) }) defineExpose({ open, close: () => (dialogVisible.value = false) })
/** 提交表单 */
const emit = defineEmits(['success']) const emit = defineEmits(['success'])
const submitForm = async () => { const submitForm = async () => {
await formRef.value.validate() await formRef.value.validate()
@ -198,6 +183,7 @@ const submitForm = async () => {
} }
} }
/** 重置表单 */
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
name: undefined, name: undefined,

View File

@ -58,19 +58,24 @@ import ProductForm from '@/views/iot/product/ProductForm.vue'
import { ProductApi, ProductVO } from '@/api/iot/product' import { ProductApi, ProductVO } from '@/api/iot/product'
const message = useMessage() const message = useMessage()
const { product } = defineProps<{ product: ProductVO }>() // Props
/** 处理复制 */
const copyToClipboard = (text: string) => { const copyToClipboard = (text: string) => {
navigator.clipboard.writeText(text).then(() => { navigator.clipboard.writeText(text).then(() => {
message.success('复制成功') message.success('复制成功')
}) })
} }
// /** 路由跳转到设备管理 */
const { currentRoute, push } = useRouter() const { push } = useRouter()
const goToManagement = (productId: string) => { const goToManagement = (productId: string) => {
push({ name: 'IoTDevice', query: { productId } }) push({ name: 'IoTDevice', query: { productId } })
} }
// /** 操作修改 */
const emit = defineEmits(['refresh']) // Emits
const formRef = ref() const formRef = ref()
const openForm = (type: string, id?: number) => { const openForm = (type: string, id?: number) => {
formRef.value.open(type, id) formRef.value.open(type, id)
@ -95,10 +100,4 @@ const confirmUnpublish = async (id: number) => {
message.error('撤销发布失败') message.error('撤销发布失败')
} }
} }
// Props
const { product } = defineProps<{ product: ProductVO }>()
// Emits
const emit = defineEmits(['refresh'])
</script> </script>

View File

@ -6,9 +6,9 @@
<el-descriptions-item label="设备类型"> <el-descriptions-item label="设备类型">
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" /> <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" />
</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="创建时间">{{ <el-descriptions-item label="创建时间">
formatDate(product.createTime) {{ formatDate(product.createTime) }}
}}</el-descriptions-item> </el-descriptions-item>
<el-descriptions-item label="数据格式"> <el-descriptions-item label="数据格式">
<dict-tag :type="DICT_TYPE.IOT_DATA_FORMAT" :value="product.dataFormat" /> <dict-tag :type="DICT_TYPE.IOT_DATA_FORMAT" :value="product.dataFormat" />
</el-descriptions-item> </el-descriptions-item>

View File

@ -44,6 +44,7 @@ const columns2 = reactive([
{ label: '描述', field: 'description' } { label: '描述', field: 'description' }
]) ])
// TODO @haohao便 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/ai/utils/constants.ts
const data1 = computed(() => { const data1 = computed(() => {
if (!props.product || !props.product.productKey) return [] if (!props.product || !props.product.productKey) return []
return [ return [

View File

@ -88,6 +88,7 @@ import ThinkModelFunctionForm from '@/views/iot/product/detail/ThinkModelFunctio
const props = defineProps<{ product: ProductVO }>() const props = defineProps<{ product: ProductVO }>()
const { t } = useI18n() //
const message = useMessage() // const message = useMessage() //
const loading = ref(true) // const loading = ref(true) //
@ -97,7 +98,7 @@ const queryParams = reactive({
pageNo: 1, pageNo: 1,
pageSize: 10, pageSize: 10,
type: undefined, type: undefined,
productId: undefined productId: -1
}) })
const queryFormRef = ref() // const queryFormRef = ref() //

View File

@ -46,7 +46,6 @@
<span class="mx-2">~</span> <span class="mx-2">~</span>
<el-input v-model="formData.property.dataType.specs.max" placeholder="请输入最大值" /> <el-input v-model="formData.property.dataType.specs.max" placeholder="请输入最大值" />
</el-form-item> </el-form-item>
<el-form-item label="步长" prop="step"> <el-form-item label="步长" prop="step">
<el-input v-model="formData.property.dataType.specs.step" placeholder="请输入步长" /> <el-input v-model="formData.property.dataType.specs.step" placeholder="请输入步长" />
</el-form-item> </el-form-item>
@ -77,7 +76,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { ProductVO } from '@/api/iot/product' import { ProductVO } from '@/api/iot/product'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { ThinkModelFunctionApi, ThinkModelFunctionVO } from '@/api/iot/thinkmodelfunction' import { ThinkModelFunctionApi, ThinkModelFunctionVO } from '@/api/iot/thinkmodelfunction'
const props = defineProps<{ product: ProductVO }>() const props = defineProps<{ product: ProductVO }>()
@ -159,6 +157,7 @@ const formRules = reactive({
}) })
const formRef = ref() const formRef = ref()
/** 打开弹窗 */
const open = async (type: string, id?: number) => { const open = async (type: string, id?: number) => {
dialogVisible.value = true dialogVisible.value = true
dialogTitle.value = t('action.' + type) dialogTitle.value = t('action.' + type)
@ -175,6 +174,7 @@ const open = async (type: string, id?: number) => {
} }
defineExpose({ open, close: () => (dialogVisible.value = false) }) defineExpose({ open, close: () => (dialogVisible.value = false) })
/** 提交表单 */
const emit = defineEmits(['success']) const emit = defineEmits(['success'])
const submitForm = async () => { const submitForm = async () => {
await formRef.value.validate() await formRef.value.validate()
@ -197,6 +197,7 @@ const submitForm = async () => {
} }
} }
/** 重置表单 */
const resetForm = () => { const resetForm = () => {
formData.value = { formData.value = {
id: undefined, id: undefined,
@ -205,7 +206,7 @@ const resetForm = () => {
identifier: undefined, identifier: undefined,
name: undefined, name: undefined,
description: undefined, description: undefined,
type: '1', type: '1', // todo @HAOHAO
property: { property: {
identifier: undefined, identifier: undefined,
name: undefined, name: undefined,

View File

@ -23,9 +23,14 @@ import ProductDetailsHeader from '@/views/iot/product/detail/ProductDetailsHeade
import ProductDetailsInfo from '@/views/iot/product/detail/ProductDetailsInfo.vue' import ProductDetailsInfo from '@/views/iot/product/detail/ProductDetailsInfo.vue'
import ProductTopic from '@/views/iot/product/detail/ProductTopic.vue' import ProductTopic from '@/views/iot/product/detail/ProductTopic.vue'
import ThinkModelFunction from '@/views/iot/product/detail/ThinkModelFunction.vue' import ThinkModelFunction from '@/views/iot/product/detail/ThinkModelFunction.vue'
import { useTagsViewStore } from '@/store/modules/tagsView'
import { useRouter } from 'vue-router'
defineOptions({ name: 'IoTProductDetail' }) defineOptions({ name: 'IoTProductDetail' })
const { delView } = useTagsViewStore() //
const { currentRoute } = useRouter()
const route = useRoute() const route = useRoute()
const message = useMessage() const message = useMessage()
const id = Number(route.params.id) // const id = Number(route.params.id) //
@ -45,7 +50,7 @@ const getProductData = async (id: number) => {
} }
// //
const getDeviceCount = async (productId: string) => { const getDeviceCount = async (productId: number) => {
try { try {
const count = await DeviceApi.getDeviceCount(productId) const count = await DeviceApi.getDeviceCount(productId)
console.log('Device count response:', count) console.log('Device count response:', count)

View File

@ -104,7 +104,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime' import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { ProductApi, ProductVO } from '@/api/iot/product' import { ProductApi, ProductVO } from '@/api/iot/product'
import ProductForm from './ProductForm.vue' import ProductForm from './ProductForm.vue'
import { DICT_TYPE } from '@/utils/dict' import { DICT_TYPE } from '@/utils/dict'
@ -135,7 +134,6 @@ const queryParams = reactive({
dataFormat: undefined dataFormat: undefined
}) })
const queryFormRef = ref() // const queryFormRef = ref() //
const exportLoading = ref(false) //
/** 查询列表 */ /** 查询列表 */
const getList = async () => { const getList = async () => {
@ -168,7 +166,7 @@ const openForm = (type: string, id?: number) => {
} }
/** 打开详情 */ /** 打开详情 */
const { currentRoute, push } = useRouter() const { push } = useRouter()
const openDetail = (id: number) => { const openDetail = (id: number) => {
push({ name: 'IoTProductDetail', params: { id } }) push({ name: 'IoTProductDetail', params: { id } })
} }
@ -186,21 +184,6 @@ const handleDelete = async (id: number) => {
} catch {} } catch {}
} }
/** 导出按钮操作 */
const handleExport = async () => {
try {
//
await message.exportConfirm()
//
exportLoading.value = true
const data = await ProductApi.exportProduct(queryParams)
download.excel(data, 'iot 产品.xls')
} catch {
} finally {
exportLoading.value = false
}
}
/** 初始化 **/ /** 初始化 **/
onMounted(() => { onMounted(() => {
getList() getList()