【功能新增】IOT: 产品物模型,20%

pull/620/head
puhui999 2024-12-11 13:14:47 +08:00
parent 1ce8233159
commit fdc971dd03
7 changed files with 778 additions and 73 deletions

View File

@ -0,0 +1,98 @@
<template>
<el-select
v-model="formData.property.dataType.type"
:disabled="!!formData.id"
placeholder="请选择数据类型"
>
<el-option key="int" label="int32 (整数型)" value="int" />
<el-option key="float" label="float (单精度浮点型)" value="float" />
<el-option key="double" label="double (双精度浮点型)" value="double" />
<el-option key="enum" label="enum(枚举型)" value="enum" />
<el-option key="bool" label="bool (布尔型)" value="bool" />
<el-option key="text" label="text (文本型)" value="text" />
<el-option key="date" label="date (时间型)" value="date" />
<el-option key="struct" label="struct (结构体)" value="struct" />
<el-option key="array" label="array (数组)" value="array" />
</el-select>
<!-- 情况一数值型 -->
</template>
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
/** 物模型数据类型 */
defineOptions({ name: 'ThingModelDataSpecs' })
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
const formData = useVModel(props, 'modelValue', emits)
// dataTypeINTdataSpecs
//
// {
// "dataSpecs": {
// "custom": true,
// "dataType": "INT",
// "defaultValue": "30",
// "max": "1440",
// "min": "0",
// "step": "10",
// "unit": "min"
// }
// }
// dataTypeTEXTdataSpecs
//
// {
// "dataSpecs": {
// "custom": true,
// "dataType": "TEXT",
// "id": 2412127,
// "length": 2048
// }
// }
// dataTypeARRAYdataSpecs
//
// {
// "dataSpecs": {
// "childDataType": "INT",
// "custom": true,
// "dataType": "ARRAY",
// "size": 1
// }
// }
// dataTypeENUMdataSpecsList
//
// {
// "dataSpecsList": [
// {
// "custom": false,
// "dataType": "ENUM",
// "defaultValue": "true",
// "name": "",
// "value": 1
// },
// {
// "custom": false,
// "dataType": "ENUM",
// "defaultValue": "false",
// "name": "",
// "value": 0
// }
// ]
// }
// dataTypeSTRUCTdataSpecsList
//
// {
// "childDataType": "TEXT",
// "childName": "",
// "dataSpecs": {
// "custom": true,
// "dataType": "TEXT",
// "length": 128
// },
// "dataType": "STRUCT",
// "identifier": "CardNo",
// "name": "NVR"
// }
</script>
<style lang="scss" scoped></style>

View File

@ -0,0 +1,29 @@
<template>
<el-select
v-model="formData.property.dataType.type"
:disabled="!!formData.id"
placeholder="请选择数据类型"
>
<el-option key="int" label="int32 (整数型)" value="int" />
<el-option key="float" label="float (单精度浮点型)" value="float" />
<el-option key="double" label="double (双精度浮点型)" value="double" />
<el-option key="enum" label="enum(枚举型)" value="enum" />
<el-option key="bool" label="bool (布尔型)" value="bool" />
<el-option key="text" label="text (文本型)" value="text" />
<el-option key="date" label="date (时间型)" value="date" />
<el-option key="struct" label="struct (结构体)" value="struct" />
<el-option key="array" label="array (数组)" value="array" />
</el-select>
</template>
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
/** 物模型数据类型 */
defineOptions({ name: 'ThingModelDataType' })
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
const formData = useVModel(props, 'modelValue', emits)
</script>
<style lang="scss" scoped></style>

View File

@ -1,11 +1,11 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<Dialog v-model="dialogVisible" :title="dialogTitle">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="功能类型" prop="type">
<el-radio-group v-model="formData.type">
@ -20,38 +20,14 @@
<el-form-item label="标识符" prop="identifier">
<el-input
v-model="formData.identifier"
placeholder="请输入标识符"
:disabled="formType === 'update'"
placeholder="请输入标识符"
/>
</el-form-item>
<el-form-item label="数据类型" prop="type">
<el-select
v-model="formData.property.dataType.type"
placeholder="请选择数据类型"
:disabled="formType === 'update'"
>
<el-option key="int" label="int32 (整数型)" value="int" />
<el-option key="float" label="float (单精度浮点型)" value="float" />
<el-option key="double" label="double (双精度浮点型)" value="double" />
<!-- <el-option key="text" label="text (文本型)" value="text" />-->
<!-- <el-option key="date" label="date (日期型)" value="date" />-->
<!-- <el-option key="bool" label="bool (布尔型)" value="bool" />-->
<!-- <el-option key="enum" label="enum (枚举型)" value="enum" />-->
<!-- <el-option key="struct" label="struct (结构体)" value="struct" />-->
<!-- <el-option key="array" label="array (数组)" value="array" />-->
</el-select>
</el-form-item>
<el-form-item label="取值范围" prop="max">
<el-input v-model="formData.property.dataType.specs.min" placeholder="请输入最小值" />
<span class="mx-2">~</span>
<el-input v-model="formData.property.dataType.specs.max" placeholder="请输入最大值" />
</el-form-item>
<el-form-item label="步长" prop="step">
<el-input v-model="formData.property.dataType.specs.step" placeholder="请输入步长" />
</el-form-item>
<el-form-item label="单位" prop="unit">
<el-input v-model="formData.property.dataType.specs.unit" placeholder="请输入单位" />
<ThingModelDataType v-model="formData" />
</el-form-item>
<ThingModelNumberTypeDataSpecs v-model="formData" />
<el-form-item label="读写类型" prop="accessMode">
<el-radio-group v-model="formData.property.accessMode">
<el-radio label="rw">读写</el-radio>
@ -60,21 +36,22 @@
</el-form-item>
<el-form-item label="属性描述" prop="property.description">
<el-input
type="textarea"
v-model="formData.property.description"
placeholder="请输入属性描述"
type="textarea"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
<script lang="ts" setup>
import ThingModelNumberTypeDataSpecs from './ThingModelNumberTypeDataSpecs.vue'
import { ProductVO } from '@/api/iot/product/product'
import {
ProductFunctionAccessModeEnum,
@ -82,10 +59,11 @@ import {
ThinkModelFunctionApi,
ThinkModelFunctionVO
} from '@/api/iot/thinkmodelfunction'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
const props = defineProps<{ product: ProductVO }>()
defineOptions({ name: 'IoTProductThingModelForm' })
defineOptions({ name: 'ThinkModelFunctionForm' })
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) //
const { t } = useI18n()
const message = useMessage()
@ -184,8 +162,8 @@ const submitForm = async () => {
formLoading.value = true
try {
const data = formData.value as unknown as ThinkModelFunctionVO
data.productId = props.product.id
data.productKey = props.product.productKey
data.productId = product!.value.id
data.productKey = product!.value.productKey
if (formType.value === 'create') {
await ThinkModelFunctionApi.createThinkModelFunction(data)
message.success(t('common.createSuccess'))

View File

@ -0,0 +1,59 @@
<template>
<el-form-item label="取值范围" prop="max">
<div class="flex items-center justify-between">
<el-input v-model="formData.min" placeholder="请输入最小值" />
<span class="mx-2">~</span>
<el-input v-model="formData.max" placeholder="请输入最大值" />
</div>
</el-form-item>
<el-form-item label="步长" prop="step">
<el-input v-model="formData.step" placeholder="请输入步长" />
</el-form-item>
<el-form-item label="单位" prop="unit">
<el-select
:model-value="formData.unit ? formData.unitName + '-' + formData.unit : ''"
filterable
placeholder="请选择单位"
style="width: 240px"
@change="unitChange"
>
<el-option
v-for="(item, index) in UnifyUnitSpecsDTO"
:key="index"
:label="item.Name + '-' + item.Symbol"
:value="item.Name + '-' + item.Symbol"
/>
</el-select>
</el-form-item>
</template>
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import { UnifyUnitSpecsDTO } from '@/views/iot/utils/constants'
defineOptions({ name: 'ThingModelNumberTypeDataSpecs' })
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
const formData = useVModel(props, 'modelValue', emits) as Ref<DataConfig>
type DataType = 'INT' | 'FLOAT' | 'DOUBLE'
interface DataConfig {
dataType: DataType // INTFLOAT DOUBLE
max: string // dataType STRING
min: string // dataType STRING
step: string // dataType STRING
precise?: string // dataType FLOAT DOUBLE
defaultValue?: string //
unit: string //
unitName: string //
}
/** 单位发生变化时触发 */
const unitChange = (UnitSpecs: string) => {
const [unitName, unit] = UnitSpecs.split('-')
formData.value.unitName = unitName
formData.value.unit = unit
}
</script>
<style lang="scss" scoped></style>

View File

@ -2,18 +2,18 @@
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
:model="queryParams"
class="-mb-15px"
label-width="68px"
>
<el-form-item label="功能类型" prop="name">
<el-select
v-model="queryParams.type"
placeholder="请选择功能类型"
clearable
class="!w-240px"
clearable
placeholder="请选择功能类型"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.IOT_PRODUCT_FUNCTION_TYPE)"
@ -24,46 +24,48 @@
</el-select>
</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:think-model-function:create']"
>
<Icon icon="ep:plus" class="mr-5px" /> 添加功能
<el-button @click="handleQuery">
<Icon class="mr-5px" icon="ep:search" />
搜索
</el-button>
<el-button @click="resetQuery">
<Icon class="mr-5px" icon="ep:refresh" />
重置
</el-button>
<el-button plain type="primary" @click="openForm('create')">
<Icon class="mr-5px" icon="ep:plus" />
添加功能
</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<ContentWrap>
<el-tabs>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="功能类型" align="center" prop="type">
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
<el-table-column align="center" label="功能类型" prop="type">
<template #default="scope">
<dict-tag :type="DICT_TYPE.IOT_PRODUCT_FUNCTION_TYPE" :value="scope.row.type" />
</template>
</el-table-column>
<el-table-column label="功能名称" align="center" prop="name" />
<el-table-column label="标识符" align="center" prop="identifier" />
<el-table-column label="数据类型" align="center" prop="identifier" />
<el-table-column label="数据定义" align="center" prop="identifier" />
<el-table-column label="操作" align="center">
<el-table-column align="center" label="功能名称" prop="name" />
<el-table-column align="center" label="标识符" prop="identifier" />
<el-table-column align="center" label="数据类型" prop="identifier" />
<el-table-column align="center" label="数据定义" prop="identifier" />
<el-table-column align="center" label="操作">
<template #default="scope">
<el-button
v-hasPermi="[`iot:think-model-function:update`]"
link
type="primary"
@click="openForm('update', scope.row.id)"
v-hasPermi="[`iot:think-model-function:update`]"
>
编辑
</el-button>
<el-button
v-hasPermi="['iot:think-model-function:delete']"
link
type="danger"
@click="handleDelete(scope.row.id)"
v-hasPermi="['iot:think-model-function:delete']"
>
删除
</el-button>
@ -72,23 +74,24 @@
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
v-model:page="queryParams.pageNo"
:total="total"
@pagination="getList"
/>
</el-tabs>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<ThinkModelFunctionForm ref="formRef" :product="product" @success="getList" />
<ThingModelForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { ProductVO } from '@/api/iot/product/product'
<script lang="ts" setup>
import { ThinkModelFunctionApi, ThinkModelFunctionVO } from '@/api/iot/thinkmodelfunction'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import ThinkModelFunctionForm from './ThinkModelFunctionForm.vue'
import ThingModelForm from './ThingModelForm.vue'
import { ProductVO } from '@/api/iot/product/product'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
const props = defineProps<{ product: ProductVO }>()
defineOptions({ name: 'IoTProductThingModel' })
const { t } = useI18n() //
const message = useMessage() //
@ -104,12 +107,12 @@ const queryParams = reactive({
})
const queryFormRef = ref() //
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) //
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
queryParams.productId = props.product.id
queryParams.productId = product?.value?.id || -1
const data = await ThinkModelFunctionApi.getThinkModelFunctionPage(queryParams)
list.value = data.list
total.value = data.total

View File

@ -8,8 +8,8 @@
<el-tab-pane label="Topic 类列表" name="topic">
<ProductTopic v-if="activeTab === 'topic'" :product="product" />
</el-tab-pane>
<el-tab-pane label="功能定义" name="function">
<ThinkModelFunction v-if="activeTab === 'function'" :product="product" />
<el-tab-pane label="功能定义" lazy name="function">
<IoTProductThingModel ref="thingModelRef" />
</el-tab-pane>
<el-tab-pane label="消息解析" name="message" />
<el-tab-pane label="服务端订阅" name="subscription" />
@ -22,9 +22,10 @@ import { DeviceApi } from '@/api/iot/device'
import ProductDetailsHeader from './ProductDetailsHeader.vue'
import ProductDetailsInfo from './ProductDetailsInfo.vue'
import ProductTopic from './ProductTopic.vue'
import ThinkModelFunction from './ThinkModelFunction.vue'
import IoTProductThingModel from './ThingModel/index.vue'
import { useTagsViewStore } from '@/store/modules/tagsView'
import { useRouter } from 'vue-router'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
defineOptions({ name: 'IoTProductDetail' })
@ -38,6 +39,8 @@ const loading = ref(true) // 加载中
const product = ref<ProductVO>({} as ProductVO) //
const activeTab = ref('info') //
provide(IOT_PROVIDE_KEY.PRODUCT, product) //
/** 获取详情 */
const getProductData = async (id: number) => {
loading.value = true

View File

@ -0,0 +1,535 @@
/** iot 依赖注入 KEY */
export const IOT_PROVIDE_KEY = {
PRODUCT: 'IOT_PRODUCT'
}
// TODO puhui999: 物模型数字数据类型单位类型,后面改成字典获取
export const UnifyUnitSpecsDTO = [
{
Symbol: 'L/min',
Name: '升每分钟'
},
{
Symbol: 'mg/kg',
Name: '毫克每千克'
},
{
Symbol: 'NTU',
Name: '浊度'
},
{
Symbol: 'pH',
Name: 'PH值'
},
{
Symbol: 'dS/m',
Name: '土壤EC值'
},
{
Symbol: 'W/㎡',
Name: '太阳总辐射'
},
{
Symbol: 'mm/hour',
Name: '降雨量'
},
{
Symbol: 'var',
Name: '乏'
},
{
Symbol: 'cP',
Name: '厘泊'
},
{
Symbol: 'aw',
Name: '饱和度'
},
{
Symbol: 'pcs',
Name: '个'
},
{
Symbol: 'cst',
Name: '厘斯'
},
{
Symbol: 'bar',
Name: '巴'
},
{
Symbol: 'ppt',
Name: '纳克每升'
},
{
Symbol: 'ppb',
Name: '微克每升'
},
{
Symbol: 'uS/cm',
Name: '微西每厘米'
},
{
Symbol: 'N/C',
Name: '牛顿每库仑'
},
{
Symbol: 'V/m',
Name: '伏特每米'
},
{
Symbol: 'ml/min',
Name: '滴速'
},
{
Symbol: 'mmHg',
Name: '毫米汞柱'
},
{
Symbol: 'mmol/L',
Name: '血糖'
},
{
Symbol: 'mm/s',
Name: '毫米每秒'
},
{
Symbol: 'turn/m',
Name: '转每分钟'
},
{
Symbol: 'count',
Name: '次'
},
{
Symbol: 'gear',
Name: '档'
},
{
Symbol: 'stepCount',
Name: '步'
},
{
Symbol: 'Nm3/h',
Name: '标准立方米每小时'
},
{
Symbol: 'kV',
Name: '千伏'
},
{
Symbol: 'kVA',
Name: '千伏安'
},
{
Symbol: 'kVar',
Name: '千乏'
},
{
Symbol: 'uw/cm2',
Name: '微瓦每平方厘米'
},
{
Symbol: '只',
Name: '只'
},
{
Symbol: '%RH',
Name: '相对湿度'
},
{
Symbol: 'm³/s',
Name: '立方米每秒'
},
{
Symbol: 'kg/s',
Name: '公斤每秒'
},
{
Symbol: 'r/min',
Name: '转每分钟'
},
{
Symbol: 't/h',
Name: '吨每小时'
},
{
Symbol: 'KCL/h',
Name: '千卡每小时'
},
{
Symbol: 'L/s',
Name: '升每秒'
},
{
Symbol: 'Mpa',
Name: '兆帕'
},
{
Symbol: 'm³/h',
Name: '立方米每小时'
},
{
Symbol: 'kvarh',
Name: '千乏时'
},
{
Symbol: 'μg/L',
Name: '微克每升'
},
{
Symbol: 'kcal',
Name: '千卡路里'
},
{
Symbol: 'GB',
Name: '吉字节'
},
{
Symbol: 'MB',
Name: '兆字节'
},
{
Symbol: 'KB',
Name: '千字节'
},
{
Symbol: 'B',
Name: '字节'
},
{
Symbol: 'μg/(d㎡·d)',
Name: '微克每平方分米每天'
},
{
Symbol: '',
Name: '无'
},
{
Symbol: 'ppm',
Name: '百万分率'
},
{
Symbol: 'pixel',
Name: '像素'
},
{
Symbol: 'Lux',
Name: '照度'
},
{
Symbol: 'grav',
Name: '重力加速度'
},
{
Symbol: 'dB',
Name: '分贝'
},
{
Symbol: '%',
Name: '百分比'
},
{
Symbol: 'lm',
Name: '流明'
},
{
Symbol: 'bit',
Name: '比特'
},
{
Symbol: 'g/mL',
Name: '克每毫升'
},
{
Symbol: 'g/L',
Name: '克每升'
},
{
Symbol: 'mg/L',
Name: '毫克每升'
},
{
Symbol: 'μg/m³',
Name: '微克每立方米'
},
{
Symbol: 'mg/m³',
Name: '毫克每立方米'
},
{
Symbol: 'g/m³',
Name: '克每立方米'
},
{
Symbol: 'kg/m³',
Name: '千克每立方米'
},
{
Symbol: 'nF',
Name: '纳法'
},
{
Symbol: 'pF',
Name: '皮法'
},
{
Symbol: 'μF',
Name: '微法'
},
{
Symbol: 'F',
Name: '法拉'
},
{
Symbol: 'Ω',
Name: '欧姆'
},
{
Symbol: 'μA',
Name: '微安'
},
{
Symbol: 'mA',
Name: '毫安'
},
{
Symbol: 'kA',
Name: '千安'
},
{
Symbol: 'A',
Name: '安培'
},
{
Symbol: 'mV',
Name: '毫伏'
},
{
Symbol: 'V',
Name: '伏特'
},
{
Symbol: 'ms',
Name: '毫秒'
},
{
Symbol: 's',
Name: '秒'
},
{
Symbol: 'min',
Name: '分钟'
},
{
Symbol: 'h',
Name: '小时'
},
{
Symbol: 'day',
Name: '日'
},
{
Symbol: 'week',
Name: '周'
},
{
Symbol: 'month',
Name: '月'
},
{
Symbol: 'year',
Name: '年'
},
{
Symbol: 'kn',
Name: '节'
},
{
Symbol: 'km/h',
Name: '千米每小时'
},
{
Symbol: 'm/s',
Name: '米每秒'
},
{
Symbol: '″',
Name: '秒'
},
{
Symbol: '',
Name: '分'
},
{
Symbol: '°',
Name: '度'
},
{
Symbol: 'rad',
Name: '弧度'
},
{
Symbol: 'Hz',
Name: '赫兹'
},
{
Symbol: 'μW',
Name: '微瓦'
},
{
Symbol: 'mW',
Name: '毫瓦'
},
{
Symbol: 'kW',
Name: '千瓦特'
},
{
Symbol: 'W',
Name: '瓦特'
},
{
Symbol: 'cal',
Name: '卡路里'
},
{
Symbol: 'kW·h',
Name: '千瓦时'
},
{
Symbol: 'Wh',
Name: '瓦时'
},
{
Symbol: 'eV',
Name: '电子伏'
},
{
Symbol: 'kJ',
Name: '千焦'
},
{
Symbol: 'J',
Name: '焦耳'
},
{
Symbol: '℉',
Name: '华氏度'
},
{
Symbol: 'K',
Name: '开尔文'
},
{
Symbol: 't',
Name: '吨'
},
{
Symbol: '°C',
Name: '摄氏度'
},
{
Symbol: 'mPa',
Name: '毫帕'
},
{
Symbol: 'hPa',
Name: '百帕'
},
{
Symbol: 'kPa',
Name: '千帕'
},
{
Symbol: 'Pa',
Name: '帕斯卡'
},
{
Symbol: 'mg',
Name: '毫克'
},
{
Symbol: 'g',
Name: '克'
},
{
Symbol: 'kg',
Name: '千克'
},
{
Symbol: 'N',
Name: '牛'
},
{
Symbol: 'mL',
Name: '毫升'
},
{
Symbol: 'L',
Name: '升'
},
{
Symbol: 'mm³',
Name: '立方毫米'
},
{
Symbol: 'cm³',
Name: '立方厘米'
},
{
Symbol: 'km³',
Name: '立方千米'
},
{
Symbol: 'm³',
Name: '立方米'
},
{
Symbol: 'h㎡',
Name: '公顷'
},
{
Symbol: 'c㎡',
Name: '平方厘米'
},
{
Symbol: 'm㎡',
Name: '平方毫米'
},
{
Symbol: 'k㎡',
Name: '平方千米'
},
{
Symbol: '㎡',
Name: '平方米'
},
{
Symbol: 'nm',
Name: '纳米'
},
{
Symbol: 'μm',
Name: '微米'
},
{
Symbol: 'mm',
Name: '毫米'
},
{
Symbol: 'cm',
Name: '厘米'
},
{
Symbol: 'dm',
Name: '分米'
},
{
Symbol: 'km',
Name: '千米'
},
{
Symbol: 'm',
Name: '米'
}
]