新增:IOT 产品管理
							parent
							
								
									5ba69ba707
								
							
						
					
					
						commit
						4aea2eaed5
					
				| 
						 | 
				
			
			@ -0,0 +1,50 @@
 | 
			
		|||
import request from '@/config/axios'
 | 
			
		||||
 | 
			
		||||
// iot 产品 VO
 | 
			
		||||
export interface ProductVO {
 | 
			
		||||
  name: string // 产品名称
 | 
			
		||||
  id: number // 产品ID
 | 
			
		||||
  productKey: string // 产品标识
 | 
			
		||||
  protocolId: number // 协议编号(脚本解析 id)
 | 
			
		||||
  categoryId: number // 产品所属品类标识符
 | 
			
		||||
  description: string // 产品描述
 | 
			
		||||
  validateType: number // 数据校验级别, 0: 强校验, 1: 弱校验, 2: 免校验
 | 
			
		||||
  status: number // 产品状态, 0: DEVELOPMENT_STATUS, 1: RELEASE_STATUS
 | 
			
		||||
  deviceType: number // 设备类型, 0: 直连设备, 1: 网关子设备, 2: 网关设备
 | 
			
		||||
  netType: number // 联网方式, 0: Wi-Fi, 1: Cellular, 2: Ethernet, 3: 其他
 | 
			
		||||
  protocolType: number // 接入网关协议, 0: modbus, 1: opc-ua, 2: customize, 3: ble, 4: zigbee
 | 
			
		||||
  dataFormat: number // 数据格式, 0: 透传模式, 1: Alink JSON
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// iot 产品 API
 | 
			
		||||
export const ProductApi = {
 | 
			
		||||
  // 查询iot 产品分页
 | 
			
		||||
  getProductPage: async (params: any) => {
 | 
			
		||||
    return await request.get({ url: `/iot/product/page`, params })
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // 查询iot 产品详情
 | 
			
		||||
  getProduct: async (id: number) => {
 | 
			
		||||
    return await request.get({ url: `/iot/product/get?id=` + id })
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // 新增iot 产品
 | 
			
		||||
  createProduct: async (data: ProductVO) => {
 | 
			
		||||
    return await request.post({ url: `/iot/product/create`, data })
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // 修改iot 产品
 | 
			
		||||
  updateProduct: async (data: ProductVO) => {
 | 
			
		||||
    return await request.put({ url: `/iot/product/update`, data })
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // 删除iot 产品
 | 
			
		||||
  deleteProduct: async (id: number) => {
 | 
			
		||||
    return await request.delete({ url: `/iot/product/delete?id=` + id })
 | 
			
		||||
  },
 | 
			
		||||
 | 
			
		||||
  // 导出iot 产品 Excel
 | 
			
		||||
  exportProduct: async (params) => {
 | 
			
		||||
    return await request.download({ url: `/iot/product/export-excel`, params })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -594,6 +594,27 @@ const remainingRouter: AppRouteRecordRaw[] = [
 | 
			
		|||
        }
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    path: '/iot',
 | 
			
		||||
    component: Layout,
 | 
			
		||||
    name: 'IOT',
 | 
			
		||||
    meta: {
 | 
			
		||||
      hidden: true
 | 
			
		||||
    },
 | 
			
		||||
    children: [
 | 
			
		||||
      {
 | 
			
		||||
        path: 'product/detail/:id',
 | 
			
		||||
        name: 'IotProductDetail',
 | 
			
		||||
        meta: {
 | 
			
		||||
          title: '产品详情',
 | 
			
		||||
          noCache: true,
 | 
			
		||||
          hidden: true,
 | 
			
		||||
          activeMenu: '/iot/product'
 | 
			
		||||
        },
 | 
			
		||||
        component: () => import('@/views/iot/product/detail/index.vue')
 | 
			
		||||
      }
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -226,5 +226,13 @@ export enum DICT_TYPE {
 | 
			
		|||
  AI_WRITE_LENGTH = 'ai_write_length', // AI 写作长度
 | 
			
		||||
  AI_WRITE_FORMAT = 'ai_write_format', // AI 写作格式
 | 
			
		||||
  AI_WRITE_TONE = 'ai_write_tone', // AI 写作语气
 | 
			
		||||
  AI_WRITE_LANGUAGE = 'ai_write_language' // AI 写作语言
 | 
			
		||||
  AI_WRITE_LANGUAGE = 'ai_write_language', // AI 写作语言
 | 
			
		||||
 | 
			
		||||
  // ========== IOT - 物联网模块  ==========
 | 
			
		||||
  IOT_NET_TYPE = 'iot_net_type', // IOT 联网方式
 | 
			
		||||
  IOT_VALIDATE_TYPE = 'iot_validate_type', // IOT 数据校验级别
 | 
			
		||||
  IOT_PRODUCT_STATUS = 'iot_product_status', // IOT 产品状态
 | 
			
		||||
  IOT_PRODUCT_DEVICE_TYPE = 'iot_product_device_type', // IOT 产品设备类型
 | 
			
		||||
  IOT_DATA_FORMAT = 'iot_data_format', // IOT 数据格式
 | 
			
		||||
  IOT_PROTOCOL_TYPE = 'iot_protocol_type' // IOT 接入网关协议
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,203 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <Dialog :title="dialogTitle" v-model="dialogVisible">
 | 
			
		||||
    <el-form
 | 
			
		||||
      ref="formRef"
 | 
			
		||||
      :model="formData"
 | 
			
		||||
      :rules="formRules"
 | 
			
		||||
      label-width="100px"
 | 
			
		||||
      v-loading="formLoading"
 | 
			
		||||
    >
 | 
			
		||||
      <el-form-item label="产品名称" prop="name">
 | 
			
		||||
        <el-input v-model="formData.name" placeholder="请输入产品名称" />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="设备类型" prop="deviceType">
 | 
			
		||||
        <el-radio-group v-model="formData.deviceType">
 | 
			
		||||
          <el-radio
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE)"
 | 
			
		||||
            :key="dict.value"
 | 
			
		||||
            :label="dict.value"
 | 
			
		||||
          >
 | 
			
		||||
            {{ dict.label }}
 | 
			
		||||
          </el-radio>
 | 
			
		||||
        </el-radio-group>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item
 | 
			
		||||
        v-if="formData.deviceType === 0 || formData.deviceType === 2"
 | 
			
		||||
        label="联网方式"
 | 
			
		||||
        prop="netType"
 | 
			
		||||
      >
 | 
			
		||||
        <el-select v-model="formData.netType" placeholder="请选择联网方式">
 | 
			
		||||
          <el-option
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.IOT_NET_TYPE)"
 | 
			
		||||
            :key="dict.value"
 | 
			
		||||
            :label="dict.label"
 | 
			
		||||
            :value="dict.value"
 | 
			
		||||
          />
 | 
			
		||||
        </el-select>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item v-if="formData.deviceType === 1" label="接入网关协议" prop="protocolType">
 | 
			
		||||
        <el-select v-model="formData.protocolType" placeholder="请选择接入网关协议">
 | 
			
		||||
          <el-option
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PROTOCOL_TYPE)"
 | 
			
		||||
            :key="dict.value"
 | 
			
		||||
            :label="dict.label"
 | 
			
		||||
            :value="dict.value"
 | 
			
		||||
          />
 | 
			
		||||
        </el-select>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="数据格式" prop="dataFormat">
 | 
			
		||||
        <el-select v-model="formData.dataFormat" placeholder="请选择接数据格式">
 | 
			
		||||
          <el-option
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.IOT_DATA_FORMAT)"
 | 
			
		||||
            :key="dict.value"
 | 
			
		||||
            :label="dict.label"
 | 
			
		||||
            :value="dict.value"
 | 
			
		||||
          />
 | 
			
		||||
        </el-select>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="数据校验级别" prop="validateType">
 | 
			
		||||
        <el-radio-group v-model="formData.validateType">
 | 
			
		||||
          <el-radio
 | 
			
		||||
            v-for="dict in getIntDictOptions(DICT_TYPE.IOT_VALIDATE_TYPE)"
 | 
			
		||||
            :key="dict.value"
 | 
			
		||||
            :label="dict.value"
 | 
			
		||||
          >
 | 
			
		||||
            {{ dict.label }}
 | 
			
		||||
          </el-radio>
 | 
			
		||||
        </el-radio-group>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="产品描述" prop="description">
 | 
			
		||||
        <el-input type="textarea" v-model="formData.description" placeholder="请输入产品描述" />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
    </el-form>
 | 
			
		||||
    <template #footer>
 | 
			
		||||
      <el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
 | 
			
		||||
      <el-button @click="dialogVisible = false">取 消</el-button>
 | 
			
		||||
    </template>
 | 
			
		||||
  </Dialog>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
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 dialogVisible = ref(false) // 弹窗的是否展示
 | 
			
		||||
const dialogTitle = ref('') // 弹窗的标题
 | 
			
		||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
 | 
			
		||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
 | 
			
		||||
const formData = ref({
 | 
			
		||||
  name: undefined,
 | 
			
		||||
  id: undefined,
 | 
			
		||||
  productKey: undefined,
 | 
			
		||||
  protocolId: undefined,
 | 
			
		||||
  categoryId: undefined,
 | 
			
		||||
  description: undefined,
 | 
			
		||||
  validateType: undefined,
 | 
			
		||||
  status: undefined,
 | 
			
		||||
  deviceType: undefined,
 | 
			
		||||
  netType: undefined,
 | 
			
		||||
  protocolType: undefined,
 | 
			
		||||
  dataFormat: undefined
 | 
			
		||||
})
 | 
			
		||||
const formRules = reactive({
 | 
			
		||||
  name: [{ required: true, message: '产品名称不能为空', trigger: 'blur' }],
 | 
			
		||||
  deviceType: [
 | 
			
		||||
    {
 | 
			
		||||
      required: true,
 | 
			
		||||
      message: '设备类型不能为空',
 | 
			
		||||
      trigger: 'change'
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  netType: [
 | 
			
		||||
    {
 | 
			
		||||
      required: formData.deviceType === 0 || formData.deviceType === 2,
 | 
			
		||||
      message: '联网方式不能为空',
 | 
			
		||||
      trigger: 'change'
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  protocolType: [
 | 
			
		||||
    { required: formData.deviceType === 1, message: '接入网关协议不能为空', trigger: 'change' }
 | 
			
		||||
  ],
 | 
			
		||||
  dataFormat: [
 | 
			
		||||
    {
 | 
			
		||||
      required: true,
 | 
			
		||||
      message: '数据格式不能为空',
 | 
			
		||||
      trigger: 'change'
 | 
			
		||||
    }
 | 
			
		||||
  ],
 | 
			
		||||
  validateType: [
 | 
			
		||||
    {
 | 
			
		||||
      required: true,
 | 
			
		||||
      message: '数据校验级别不能为空',
 | 
			
		||||
      trigger: 'change'
 | 
			
		||||
    }
 | 
			
		||||
  ]
 | 
			
		||||
})
 | 
			
		||||
const formRef = ref() // 表单 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 {
 | 
			
		||||
      formData.value = await ProductApi.getProduct(id)
 | 
			
		||||
    } finally {
 | 
			
		||||
      formLoading.value = false
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
 | 
			
		||||
 | 
			
		||||
/** 提交表单 */
 | 
			
		||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
 | 
			
		||||
const submitForm = async () => {
 | 
			
		||||
  // 校验表单
 | 
			
		||||
  await formRef.value.validate()
 | 
			
		||||
  // 提交请求
 | 
			
		||||
  formLoading.value = true
 | 
			
		||||
  try {
 | 
			
		||||
    const data = formData.value as unknown as ProductVO
 | 
			
		||||
    if (formType.value === 'create') {
 | 
			
		||||
      await ProductApi.createProduct(data)
 | 
			
		||||
      message.success(t('common.createSuccess'))
 | 
			
		||||
    } else {
 | 
			
		||||
      await ProductApi.updateProduct(data)
 | 
			
		||||
      message.success(t('common.updateSuccess'))
 | 
			
		||||
    }
 | 
			
		||||
    dialogVisible.value = false
 | 
			
		||||
    // 发送操作成功的事件
 | 
			
		||||
    emit('success')
 | 
			
		||||
  } finally {
 | 
			
		||||
    formLoading.value = false
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 重置表单 */
 | 
			
		||||
const resetForm = () => {
 | 
			
		||||
  formData.value = {
 | 
			
		||||
    name: undefined,
 | 
			
		||||
    id: undefined,
 | 
			
		||||
    productKey: undefined,
 | 
			
		||||
    protocolId: undefined,
 | 
			
		||||
    categoryId: undefined,
 | 
			
		||||
    description: undefined,
 | 
			
		||||
    validateType: undefined,
 | 
			
		||||
    status: undefined,
 | 
			
		||||
    deviceType: undefined,
 | 
			
		||||
    netType: undefined,
 | 
			
		||||
    protocolType: undefined,
 | 
			
		||||
    dataFormat: undefined
 | 
			
		||||
  }
 | 
			
		||||
  formRef.value?.resetFields()
 | 
			
		||||
}
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,45 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <div>
 | 
			
		||||
    <div class="flex items-start justify-between">
 | 
			
		||||
      <div>
 | 
			
		||||
        <el-col>
 | 
			
		||||
          <el-row>
 | 
			
		||||
            <span class="text-xl font-bold">{{ product.name }}</span>
 | 
			
		||||
          </el-row>
 | 
			
		||||
        </el-col>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div>
 | 
			
		||||
        <!-- 右上:按钮 -->
 | 
			
		||||
        <el-button @click="openForm('update', product.id)" v-hasPermi="['iot:product:update']">
 | 
			
		||||
          编辑
 | 
			
		||||
        </el-button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
  <ContentWrap class="mt-10px">
 | 
			
		||||
    <el-descriptions :column="5" direction="vertical">
 | 
			
		||||
      <el-descriptions-item label="产品名称">{{ product.name }}</el-descriptions-item>
 | 
			
		||||
      <el-descriptions-item label="产品标识">{{ product.identification }}</el-descriptions-item>
 | 
			
		||||
      <el-descriptions-item label="设备类型">
 | 
			
		||||
        <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" />
 | 
			
		||||
      </el-descriptions-item>
 | 
			
		||||
      <el-descriptions-item label="产品状态">
 | 
			
		||||
        <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="product.status" />
 | 
			
		||||
      </el-descriptions-item>
 | 
			
		||||
    </el-descriptions>
 | 
			
		||||
  </ContentWrap>
 | 
			
		||||
  <!-- 表单弹窗:添加/修改 -->
 | 
			
		||||
  <ProductForm ref="formRef" @success="openForm('update', product.id)" />
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import ProductForm from '@/views/iot/product/ProductForm.vue'
 | 
			
		||||
import { DICT_TYPE } from '@/utils/dict'
 | 
			
		||||
import { ProductVO } from '@/api/iot/product'
 | 
			
		||||
 | 
			
		||||
// 操作修改
 | 
			
		||||
const formRef = ref()
 | 
			
		||||
const openForm = (type: string, id?: number) => {
 | 
			
		||||
  formRef.value.open(type, id)
 | 
			
		||||
}
 | 
			
		||||
const { product } = defineProps<{ product: ProductVO }>()
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,37 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <ContentWrap>
 | 
			
		||||
    <el-collapse v-model="activeNames">
 | 
			
		||||
      <el-collapse-item name="basicInfo">
 | 
			
		||||
        <template #title>
 | 
			
		||||
          <span class="text-base font-bold">基本信息</span>
 | 
			
		||||
        </template>
 | 
			
		||||
        <el-descriptions :column="4">
 | 
			
		||||
          <el-descriptions-item label="产品名称">{{ product.name }}</el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="产品标识">{{ product.identification }}</el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="设备类型">
 | 
			
		||||
            <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :value="product.deviceType" />
 | 
			
		||||
          </el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="数据格式">
 | 
			
		||||
            <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DATA_FORMAT" :value="product.dataFormat" />
 | 
			
		||||
          </el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="协议类型">
 | 
			
		||||
            <dict-tag :type="DICT_TYPE.IOT_PRODUCT_PROTOCOL_TYPE" :value="product.protocolType" />
 | 
			
		||||
          </el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="产品状态">
 | 
			
		||||
            <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :value="product.status" />
 | 
			
		||||
          </el-descriptions-item>
 | 
			
		||||
          <el-descriptions-item label="产品描述">{{ product.description }}</el-descriptions-item>
 | 
			
		||||
        </el-descriptions>
 | 
			
		||||
      </el-collapse-item>
 | 
			
		||||
    </el-collapse>
 | 
			
		||||
  </ContentWrap>
 | 
			
		||||
</template>
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { DICT_TYPE } from '@/utils/dict'
 | 
			
		||||
import { ProductVO } from '@/api/iot/product'
 | 
			
		||||
 | 
			
		||||
const { product } = defineProps<{ product: ProductVO }>()
 | 
			
		||||
 | 
			
		||||
// 展示的折叠面板
 | 
			
		||||
const activeNames = ref(['basicInfo'])
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,51 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <ProductDetailsHeader :loading="loading" :product="product" @refresh="getProductData(id)" />
 | 
			
		||||
  <el-col>
 | 
			
		||||
    <el-tabs>
 | 
			
		||||
      <el-tab-pane label="详细资料">
 | 
			
		||||
        <ProductDetailsInfo :product="product" />
 | 
			
		||||
      </el-tab-pane>
 | 
			
		||||
      <el-tab-pane label="物模型">
 | 
			
		||||
        <!--        <ProductDetailsModel :product="product" />-->
 | 
			
		||||
      </el-tab-pane>
 | 
			
		||||
    </el-tabs>
 | 
			
		||||
  </el-col>
 | 
			
		||||
</template>
 | 
			
		||||
<script lang="ts" setup>
 | 
			
		||||
import { useTagsViewStore } from '@/store/modules/tagsView'
 | 
			
		||||
import { ProductApi, ProductVO } from '@/api/iot/product'
 | 
			
		||||
import ProductDetailsHeader from '@/views/iot/product/detail/ProductDetailsHeader.vue'
 | 
			
		||||
import ProductDetailsInfo from '@/views/iot/product/detail/ProductDetailsInfo.vue'
 | 
			
		||||
 | 
			
		||||
defineOptions({ name: 'IotProductDetail' })
 | 
			
		||||
 | 
			
		||||
const route = useRoute()
 | 
			
		||||
const message = useMessage()
 | 
			
		||||
const id = Number(route.params.id) // 编号
 | 
			
		||||
const loading = ref(true) // 加载中
 | 
			
		||||
const product = ref<ProductVO>({} as ProductVO) // 详情
 | 
			
		||||
 | 
			
		||||
/** 获取详情 */
 | 
			
		||||
const getProductData = async (id: number) => {
 | 
			
		||||
  loading.value = true
 | 
			
		||||
  try {
 | 
			
		||||
    product.value = await ProductApi.getProduct(id)
 | 
			
		||||
  } finally {
 | 
			
		||||
    loading.value = false
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 获取物模型 */
 | 
			
		||||
 | 
			
		||||
/** 初始化 */
 | 
			
		||||
const { delView } = useTagsViewStore() // 视图操作
 | 
			
		||||
const { currentRoute } = useRouter() // 路由
 | 
			
		||||
onMounted(async () => {
 | 
			
		||||
  if (!id) {
 | 
			
		||||
    message.warning('参数错误,产品不能为空!')
 | 
			
		||||
    delView(unref(currentRoute))
 | 
			
		||||
    return
 | 
			
		||||
  }
 | 
			
		||||
  await getProductData(id)
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,206 @@
 | 
			
		|||
<template>
 | 
			
		||||
  <ContentWrap>
 | 
			
		||||
    <!-- 搜索工作栏 -->
 | 
			
		||||
    <el-form
 | 
			
		||||
      class="-mb-15px"
 | 
			
		||||
      :model="queryParams"
 | 
			
		||||
      ref="queryFormRef"
 | 
			
		||||
      :inline="true"
 | 
			
		||||
      label-width="68px"
 | 
			
		||||
    >
 | 
			
		||||
      <el-form-item label="产品名称" prop="name">
 | 
			
		||||
        <el-input
 | 
			
		||||
          v-model="queryParams.name"
 | 
			
		||||
          placeholder="请输入产品名称"
 | 
			
		||||
          clearable
 | 
			
		||||
          @keyup.enter="handleQuery"
 | 
			
		||||
          class="!w-240px"
 | 
			
		||||
        />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item label="ProductKey" prop="productKey">
 | 
			
		||||
        <el-input
 | 
			
		||||
          v-model="queryParams.productKey"
 | 
			
		||||
          placeholder="请输入产品标识"
 | 
			
		||||
          clearable
 | 
			
		||||
          @keyup.enter="handleQuery"
 | 
			
		||||
          class="!w-240px"
 | 
			
		||||
        />
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
      <el-form-item>
 | 
			
		||||
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
 | 
			
		||||
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
 | 
			
		||||
        <el-button
 | 
			
		||||
          type="primary"
 | 
			
		||||
          plain
 | 
			
		||||
          @click="openForm('create')"
 | 
			
		||||
          v-hasPermi="['iot:product:create']"
 | 
			
		||||
        >
 | 
			
		||||
          <Icon icon="ep:plus" class="mr-5px" /> 新增
 | 
			
		||||
        </el-button>
 | 
			
		||||
        <el-button
 | 
			
		||||
          type="success"
 | 
			
		||||
          plain
 | 
			
		||||
          @click="handleExport"
 | 
			
		||||
          :loading="exportLoading"
 | 
			
		||||
          v-hasPermi="['iot:product:export']"
 | 
			
		||||
        >
 | 
			
		||||
          <Icon icon="ep:download" class="mr-5px" /> 导出
 | 
			
		||||
        </el-button>
 | 
			
		||||
      </el-form-item>
 | 
			
		||||
    </el-form>
 | 
			
		||||
  </ContentWrap>
 | 
			
		||||
 | 
			
		||||
  <!-- 列表 -->
 | 
			
		||||
  <ContentWrap>
 | 
			
		||||
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
 | 
			
		||||
      <el-table-column label="产品名称" align="center" prop="name" />
 | 
			
		||||
      <el-table-column label="ProductKey" align="center" prop="productKey" />
 | 
			
		||||
      <el-table-column label="设备类型" align="center" prop="deviceType">
 | 
			
		||||
        <template #default="scope">
 | 
			
		||||
          <dict-tag :type="DICT_TYPE.IOT_PRODUCT_DEVICE_TYPE" :code="scope.row.deviceType" />
 | 
			
		||||
        </template>
 | 
			
		||||
      </el-table-column>
 | 
			
		||||
      <el-table-column
 | 
			
		||||
        label="创建时间"
 | 
			
		||||
        align="center"
 | 
			
		||||
        prop="createTime"
 | 
			
		||||
        :formatter="dateFormatter"
 | 
			
		||||
        width="180px"
 | 
			
		||||
      />
 | 
			
		||||
      <el-table-column label="产品状态" align="center" prop="status">
 | 
			
		||||
        <template #default="scope">
 | 
			
		||||
          <dict-tag :type="DICT_TYPE.IOT_PRODUCT_STATUS" :code="scope.row.status" />
 | 
			
		||||
        </template>
 | 
			
		||||
      </el-table-column>
 | 
			
		||||
      <el-table-column label="操作" align="center">
 | 
			
		||||
        <template #default="scope">
 | 
			
		||||
          <el-button
 | 
			
		||||
            link
 | 
			
		||||
            type="primary"
 | 
			
		||||
            @click="openForm('update', scope.row.id)"
 | 
			
		||||
            v-hasPermi="['iot:product:update']"
 | 
			
		||||
          >
 | 
			
		||||
            编辑
 | 
			
		||||
          </el-button>
 | 
			
		||||
          <el-button
 | 
			
		||||
            link
 | 
			
		||||
            type="danger"
 | 
			
		||||
            @click="handleDelete(scope.row.id)"
 | 
			
		||||
            v-hasPermi="['iot:product:delete']"
 | 
			
		||||
          >
 | 
			
		||||
            删除
 | 
			
		||||
          </el-button>
 | 
			
		||||
        </template>
 | 
			
		||||
      </el-table-column>
 | 
			
		||||
    </el-table>
 | 
			
		||||
    <!-- 分页 -->
 | 
			
		||||
    <Pagination
 | 
			
		||||
      :total="total"
 | 
			
		||||
      v-model:page="queryParams.pageNo"
 | 
			
		||||
      v-model:limit="queryParams.pageSize"
 | 
			
		||||
      @pagination="getList"
 | 
			
		||||
    />
 | 
			
		||||
  </ContentWrap>
 | 
			
		||||
 | 
			
		||||
  <!-- 表单弹窗:添加/修改 -->
 | 
			
		||||
  <ProductForm ref="formRef" @success="getList" />
 | 
			
		||||
</template>
 | 
			
		||||
 | 
			
		||||
<script setup lang="ts">
 | 
			
		||||
import { dateFormatter } from '@/utils/formatTime'
 | 
			
		||||
import download from '@/utils/download'
 | 
			
		||||
import { ProductApi, ProductVO } from '@/api/iot/product'
 | 
			
		||||
import ProductForm from './ProductForm.vue'
 | 
			
		||||
import { DICT_TYPE } from '@/utils/dict'
 | 
			
		||||
 | 
			
		||||
/** iot 产品 列表 */
 | 
			
		||||
defineOptions({ name: 'Product' })
 | 
			
		||||
 | 
			
		||||
const message = useMessage() // 消息弹窗
 | 
			
		||||
const { t } = useI18n() // 国际化
 | 
			
		||||
 | 
			
		||||
const loading = ref(true) // 列表的加载中
 | 
			
		||||
const list = ref<ProductVO[]>([]) // 列表的数据
 | 
			
		||||
const total = ref(0) // 列表的总页数
 | 
			
		||||
const queryParams = reactive({
 | 
			
		||||
  pageNo: 1,
 | 
			
		||||
  pageSize: 10,
 | 
			
		||||
  name: undefined,
 | 
			
		||||
  createTime: [],
 | 
			
		||||
  productKey: undefined,
 | 
			
		||||
  protocolId: undefined,
 | 
			
		||||
  categoryId: undefined,
 | 
			
		||||
  description: undefined,
 | 
			
		||||
  validateType: undefined,
 | 
			
		||||
  status: undefined,
 | 
			
		||||
  deviceType: undefined,
 | 
			
		||||
  netType: undefined,
 | 
			
		||||
  protocolType: undefined,
 | 
			
		||||
  dataFormat: undefined
 | 
			
		||||
})
 | 
			
		||||
const queryFormRef = ref() // 搜索的表单
 | 
			
		||||
const exportLoading = ref(false) // 导出的加载中
 | 
			
		||||
 | 
			
		||||
/** 查询列表 */
 | 
			
		||||
const getList = async () => {
 | 
			
		||||
  loading.value = true
 | 
			
		||||
  try {
 | 
			
		||||
    const data = await ProductApi.getProductPage(queryParams)
 | 
			
		||||
    list.value = data.list
 | 
			
		||||
    total.value = data.total
 | 
			
		||||
  } finally {
 | 
			
		||||
    loading.value = false
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 搜索按钮操作 */
 | 
			
		||||
const handleQuery = () => {
 | 
			
		||||
  queryParams.pageNo = 1
 | 
			
		||||
  getList()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 重置按钮操作 */
 | 
			
		||||
const resetQuery = () => {
 | 
			
		||||
  queryFormRef.value.resetFields()
 | 
			
		||||
  handleQuery()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 添加/修改操作 */
 | 
			
		||||
const formRef = ref()
 | 
			
		||||
const openForm = (type: string, id?: number) => {
 | 
			
		||||
  formRef.value.open(type, id)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** 删除按钮操作 */
 | 
			
		||||
const handleDelete = async (id: number) => {
 | 
			
		||||
  try {
 | 
			
		||||
    // 删除的二次确认
 | 
			
		||||
    await message.delConfirm()
 | 
			
		||||
    // 发起删除
 | 
			
		||||
    await ProductApi.deleteProduct(id)
 | 
			
		||||
    message.success(t('common.delSuccess'))
 | 
			
		||||
    // 刷新列表
 | 
			
		||||
    await getList()
 | 
			
		||||
  } 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(() => {
 | 
			
		||||
  getList()
 | 
			
		||||
})
 | 
			
		||||
</script>
 | 
			
		||||
		Loading…
	
		Reference in New Issue