feat(iot): 优化代码,尽量使用 ProductStatusEnum 枚举
parent
f26c65c03f
commit
fee633b0c8
|
|
@ -13,7 +13,7 @@
|
|||
<el-button
|
||||
@click="openForm('update', product.id)"
|
||||
v-hasPermi="['iot:product:update']"
|
||||
:disabled="product.status === 1"
|
||||
:disabled="product.status === ProductStatusEnum.PUBLISHED"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
type="primary"
|
||||
@click="confirmPublish(product.id)"
|
||||
v-hasPermi="['iot:product:update']"
|
||||
v-if="product.status === 0"
|
||||
v-if="product.status === ProductStatusEnum.UNPUBLISHED"
|
||||
>
|
||||
发布
|
||||
</el-button>
|
||||
|
|
@ -29,7 +29,7 @@
|
|||
type="danger"
|
||||
@click="confirmUnpublish(product.id)"
|
||||
v-hasPermi="['iot:product:update']"
|
||||
v-if="product.status === 1"
|
||||
v-if="product.status === ProductStatusEnum.PUBLISHED"
|
||||
>
|
||||
撤销发布
|
||||
</el-button>
|
||||
|
|
@ -54,6 +54,7 @@
|
|||
<script setup lang="ts">
|
||||
import ProductForm from '@/views/iot/product/product/ProductForm.vue'
|
||||
import { ProductApi, ProductVO } from '@/api/iot/product/product'
|
||||
import { ProductStatusEnum } from '@/views/iot/utils/constants'
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
|
||||
const message = useMessage()
|
||||
|
|
@ -90,7 +91,7 @@ const openForm = (type: string, id?: number) => {
|
|||
/** 发布操作 */
|
||||
const confirmPublish = async (id: number) => {
|
||||
try {
|
||||
await ProductApi.updateProductStatus(id, 1)
|
||||
await ProductApi.updateProductStatus(id, ProductStatusEnum.PUBLISHED)
|
||||
message.success('发布成功')
|
||||
formRef.value.close() // 关闭弹框
|
||||
emit('refresh')
|
||||
|
|
@ -102,7 +103,7 @@ const confirmPublish = async (id: number) => {
|
|||
/** 撤销发布操作 */
|
||||
const confirmUnpublish = async (id: number) => {
|
||||
try {
|
||||
await ProductApi.updateProductStatus(id, 0)
|
||||
await ProductApi.updateProductStatus(id, ProductStatusEnum.UNPUBLISHED)
|
||||
message.success('撤销发布成功')
|
||||
formRef.value.close() // 关闭弹框
|
||||
emit('refresh')
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@
|
|||
<div class="mx-[10px] h-[20px] w-[1px] bg-[#dcdfe6]"></div>
|
||||
<el-button
|
||||
v-hasPermi="['iot:product:delete']"
|
||||
:disabled="item.status === 1"
|
||||
:disabled="item.status === ProductStatusEnum.PUBLISHED"
|
||||
class="!px-2 !h-[32px] text-[13px]"
|
||||
plain
|
||||
type="danger"
|
||||
|
|
@ -216,7 +216,7 @@
|
|||
</el-button>
|
||||
<el-button
|
||||
v-hasPermi="['iot:product:delete']"
|
||||
:disabled="scope.row.status === 1"
|
||||
:disabled="scope.row.status === ProductStatusEnum.PUBLISHED"
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
|
|
@ -248,6 +248,7 @@ import { DICT_TYPE } from '@/utils/dict'
|
|||
import download from '@/utils/download'
|
||||
import defaultPicUrl from '@/assets/imgs/iot/device.png'
|
||||
import defaultIconUrl from '@/assets/svgs/iot/cube.svg'
|
||||
import { ProductStatusEnum } from '@/views/iot/utils/constants'
|
||||
|
||||
/** iot 产品列表 */
|
||||
defineOptions({ name: 'IoTProduct' })
|
||||
|
|
|
|||
|
|
@ -72,13 +72,12 @@ const getDeviceList = async () => {
|
|||
|
||||
try {
|
||||
deviceLoading.value = true
|
||||
const res = await DeviceApi.getDeviceListByProductId(props.productId)
|
||||
deviceList.value = res || []
|
||||
const data = await DeviceApi.getDeviceListByProductId(props.productId)
|
||||
deviceList.value = [DEVICE_SELECTOR_OPTIONS.ALL_DEVICES, ...(data || [])]
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error)
|
||||
deviceList.value = []
|
||||
deviceList.value = [DEVICE_SELECTOR_OPTIONS.ALL_DEVICES]
|
||||
} finally {
|
||||
deviceList.value.unshift(DEVICE_SELECTOR_OPTIONS.ALL_DEVICES)
|
||||
deviceLoading.value = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,12 @@ export enum DeviceStateEnum {
|
|||
OFFLINE = 2 // 离线
|
||||
}
|
||||
|
||||
/** IoT 产品状态枚举 */
|
||||
export enum ProductStatusEnum {
|
||||
UNPUBLISHED = 0, // 未发布
|
||||
PUBLISHED = 1 // 已发布
|
||||
}
|
||||
|
||||
/** IoT 产品物模型类型枚举类 */
|
||||
export const IoTThingModelTypeEnum = {
|
||||
PROPERTY: 1, // 属性
|
||||
|
|
|
|||
Loading…
Reference in New Issue