|
|
|
@ -102,12 +102,221 @@ link type="primary" @click="openForm('update', scope.row.id)"
|
|
|
|
</ContentWrap>
|
|
|
|
</ContentWrap>
|
|
|
|
|
|
|
|
|
|
|
|
<ContentWrap>
|
|
|
|
<ContentWrap>
|
|
|
|
|
|
|
|
<template v-if="attributeModelId">
|
|
|
|
|
|
|
|
<div class="mb-10px text-sm text-gray-500">
|
|
|
|
|
|
|
|
当前模型:<span class="font-medium text-gray-700">{{ attributeModelName || '-' }}</span>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<el-tabs model-value="modelAttribute">
|
|
|
|
<el-tabs model-value="modelAttribute">
|
|
|
|
<el-tab-pane :label="modelAttributeTabLabel" name="modelAttribute">
|
|
|
|
<el-tab-pane :label="modelAttributeTabLabel" name="modelAttribute">
|
|
|
|
<ModelAttributeList v-if="attributeModelId" :id="attributeModelId" />
|
|
|
|
<ModelAttributeList :id="attributeModelId" />
|
|
|
|
<el-empty v-else description="请点击设备模型列表的“点位”查看采集点" />
|
|
|
|
</el-tab-pane>
|
|
|
|
|
|
|
|
<el-tab-pane :label="modelRuleTabLabel" name="modelRule">
|
|
|
|
|
|
|
|
<el-form class="-mb-15px" :model="ruleQueryParams" ref="ruleQueryFormRef" :inline="true" label-width="80px">
|
|
|
|
|
|
|
|
<el-form-item label="标识符" prop="identifier">
|
|
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
|
|
v-model="ruleQueryParams.identifier"
|
|
|
|
|
|
|
|
placeholder="请输入标识符"
|
|
|
|
|
|
|
|
clearable
|
|
|
|
|
|
|
|
@keyup.enter="handleRuleQuery"
|
|
|
|
|
|
|
|
class="!w-200px"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="名称" prop="fieldName">
|
|
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
|
|
v-model="ruleQueryParams.fieldName"
|
|
|
|
|
|
|
|
placeholder="请输入名称"
|
|
|
|
|
|
|
|
clearable
|
|
|
|
|
|
|
|
@keyup.enter="handleRuleQuery"
|
|
|
|
|
|
|
|
class="!w-200px"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="默认值" prop="defaultValue">
|
|
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
|
|
v-model="ruleQueryParams.defaultValue"
|
|
|
|
|
|
|
|
placeholder="请输入默认值"
|
|
|
|
|
|
|
|
clearable
|
|
|
|
|
|
|
|
@keyup.enter="handleRuleQuery"
|
|
|
|
|
|
|
|
class="!w-200px"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item>
|
|
|
|
|
|
|
|
<el-button @click="handleRuleQuery">
|
|
|
|
|
|
|
|
<Icon icon="ep:search" class="mr-5px" /> 搜索
|
|
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
<el-button @click="resetRuleQuery">
|
|
|
|
|
|
|
|
<Icon icon="ep:refresh" class="mr-5px" /> 重置
|
|
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-table
|
|
|
|
|
|
|
|
v-loading="ruleLoading"
|
|
|
|
|
|
|
|
:data="ruleList"
|
|
|
|
|
|
|
|
:stripe="true"
|
|
|
|
|
|
|
|
:show-overflow-tooltip="true"
|
|
|
|
|
|
|
|
row-key="id"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-table-column label="标识符" align="center" prop="identifier" />
|
|
|
|
|
|
|
|
<el-table-column label="名称" align="center" prop="fieldName" />
|
|
|
|
|
|
|
|
<el-table-column label="规则" align="center" prop="fieldRule" />
|
|
|
|
|
|
|
|
<el-table-column label="默认值" align="center" prop="defaultValue" />
|
|
|
|
|
|
|
|
<el-table-column label="创建时间" align="center" prop="createTime" :formatter="dateFormatter" width="180px" />
|
|
|
|
|
|
|
|
<el-table-column label="操作" align="center" width="120px">
|
|
|
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
|
|
|
<el-button link type="primary" @click="openRuleForm(scope.row)">
|
|
|
|
|
|
|
|
编辑
|
|
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
<Pagination
|
|
|
|
|
|
|
|
:total="ruleTotal"
|
|
|
|
|
|
|
|
v-model:page="ruleQueryParams.pageNo"
|
|
|
|
|
|
|
|
v-model:limit="ruleQueryParams.pageSize"
|
|
|
|
|
|
|
|
@pagination="getRuleList"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-dialog v-model="ruleDialogVisible" title="编辑点位规则" width="880px" draggable>
|
|
|
|
|
|
|
|
<el-form :model="ruleForm" ref="ruleFormRef" label-width="90px">
|
|
|
|
|
|
|
|
<el-form-item label="标识符">
|
|
|
|
|
|
|
|
<el-input v-model="ruleForm.identifier" disabled />
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="名称">
|
|
|
|
|
|
|
|
<el-input v-model="ruleForm.fieldName" disabled />
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="默认值">
|
|
|
|
|
|
|
|
<el-input v-model="ruleForm.defaultValue" disabled />
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="flex flex-col w-full">
|
|
|
|
|
|
|
|
<div class="border border-gray-200 dark:border-gray-600 rounded-md px-16px py-12px">
|
|
|
|
|
|
|
|
<el-form-item label="点位规则">
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="ruleForm.fieldRule"
|
|
|
|
|
|
|
|
placeholder="请选择点位规则"
|
|
|
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
|
|
|
:disabled="!currentRuleOptions.length"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="item in currentRuleOptions"
|
|
|
|
|
|
|
|
:key="item.value"
|
|
|
|
|
|
|
|
:label="item.label"
|
|
|
|
|
|
|
|
:value="item.value"
|
|
|
|
|
|
|
|
:disabled="isRuleDisabled(item.value, ruleForm.fieldRule)"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="规则">
|
|
|
|
|
|
|
|
<div class="flex items-center gap-8px">
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="ruleForm.ruleAttributeId"
|
|
|
|
|
|
|
|
placeholder="请选择点位"
|
|
|
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="item in ruleAttributeOptions"
|
|
|
|
|
|
|
|
:key="item.id"
|
|
|
|
|
|
|
|
:label="item.attributeName || item.attributeCode"
|
|
|
|
|
|
|
|
:value="item.id"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="ruleForm.ruleOperator"
|
|
|
|
|
|
|
|
placeholder="请选择条件"
|
|
|
|
|
|
|
|
class="!w-160px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="item in ruleOperatorOptions"
|
|
|
|
|
|
|
|
:key="item.value"
|
|
|
|
|
|
|
|
:label="item.label"
|
|
|
|
|
|
|
|
:value="item.value"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
|
|
v-model="ruleForm.ruleValue"
|
|
|
|
|
|
|
|
placeholder="请输入符号值"
|
|
|
|
|
|
|
|
class="!w-200px"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
|
|
|
v-for="(item, index) in extraPointRules"
|
|
|
|
|
|
|
|
:key="index"
|
|
|
|
|
|
|
|
class="border border-gray-200 dark:border-gray-600 rounded-md px-16px py-12px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-form-item label="点位规则">
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="item.rule"
|
|
|
|
|
|
|
|
placeholder="请选择点位规则"
|
|
|
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="opt in currentRuleOptions"
|
|
|
|
|
|
|
|
:key="opt.value"
|
|
|
|
|
|
|
|
:label="opt.label"
|
|
|
|
|
|
|
|
:value="opt.value"
|
|
|
|
|
|
|
|
:disabled="isRuleDisabled(opt.value, item.rule)"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
<el-form-item label="规则">
|
|
|
|
|
|
|
|
<div class="flex items-center gap-8px">
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="item.id"
|
|
|
|
|
|
|
|
placeholder="请选择点位"
|
|
|
|
|
|
|
|
class="!w-240px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="attr in ruleAttributeOptions"
|
|
|
|
|
|
|
|
:key="attr.id"
|
|
|
|
|
|
|
|
:label="attr.attributeName || attr.attributeCode"
|
|
|
|
|
|
|
|
:value="attr.id"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
<el-select
|
|
|
|
|
|
|
|
v-model="item.operator"
|
|
|
|
|
|
|
|
placeholder="请选择条件"
|
|
|
|
|
|
|
|
class="!w-160px"
|
|
|
|
|
|
|
|
>
|
|
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
|
|
v-for="opt in ruleOperatorOptions"
|
|
|
|
|
|
|
|
:key="opt.value"
|
|
|
|
|
|
|
|
:label="opt.label"
|
|
|
|
|
|
|
|
:value="opt.value"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
|
|
v-model="item.operatorRule"
|
|
|
|
|
|
|
|
placeholder="请输入符号值"
|
|
|
|
|
|
|
|
class="!w-200px"
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
<el-button type="danger" link @click="handleRemovePointRule(index)">
|
|
|
|
|
|
|
|
删除
|
|
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<el-form-item v-if="isRunningIdentifier" label=" ">
|
|
|
|
|
|
|
|
<el-button type="primary" link @click="handleAddPointRule">
|
|
|
|
|
|
|
|
+ 添加规则
|
|
|
|
|
|
|
|
</el-button>
|
|
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
|
|
<span class="dialog-footer">
|
|
|
|
|
|
|
|
<el-button @click="ruleDialogVisible = false">取 消</el-button>
|
|
|
|
|
|
|
|
<el-button type="primary" :loading="ruleFormLoading" @click="handleRuleSubmit">保 存</el-button>
|
|
|
|
|
|
|
|
</span>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
</el-dialog>
|
|
|
|
</el-tab-pane>
|
|
|
|
</el-tab-pane>
|
|
|
|
</el-tabs>
|
|
|
|
</el-tabs>
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<el-empty v-else description="请点击设备模型列表的“点位”查看采集点和点位规则" />
|
|
|
|
</ContentWrap>
|
|
|
|
</ContentWrap>
|
|
|
|
<!-- 表单弹窗:添加/修改 -->
|
|
|
|
<!-- 表单弹窗:添加/修改 -->
|
|
|
|
<DeviceModelForm ref="formRef" @success="getList" />
|
|
|
|
<DeviceModelForm ref="formRef" @success="getList" />
|
|
|
|
@ -117,7 +326,9 @@ link type="primary" @click="openForm('update', scope.row.id)"
|
|
|
|
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
|
|
|
|
import { getStrDictOptions, DICT_TYPE } from '@/utils/dict'
|
|
|
|
import { dateFormatter } from '@/utils/formatTime'
|
|
|
|
import { dateFormatter } from '@/utils/formatTime'
|
|
|
|
import download from '@/utils/download'
|
|
|
|
import download from '@/utils/download'
|
|
|
|
|
|
|
|
import request from '@/config/axios'
|
|
|
|
import { DeviceModelApi, DeviceModelVO } from '@/api/iot/devicemodel'
|
|
|
|
import { DeviceModelApi, DeviceModelVO } from '@/api/iot/devicemodel'
|
|
|
|
|
|
|
|
import { DeviceModelAttributeApi, DeviceModelAttributeVO } from '@/api/iot/devicemodelattribute'
|
|
|
|
import DeviceModelForm from './DeviceModelForm.vue'
|
|
|
|
import DeviceModelForm from './DeviceModelForm.vue'
|
|
|
|
import ModelAttributeList from './components/ModelAttributeList.vue'
|
|
|
|
import ModelAttributeList from './components/ModelAttributeList.vue'
|
|
|
|
|
|
|
|
|
|
|
|
@ -208,16 +419,16 @@ const handleBatchDelete = async () => {
|
|
|
|
|
|
|
|
|
|
|
|
/** 导出按钮操作 */
|
|
|
|
/** 导出按钮操作 */
|
|
|
|
const handleExport = async () => {
|
|
|
|
const handleExport = async () => {
|
|
|
|
if (!selectedIds.value.length) {
|
|
|
|
|
|
|
|
message.error('请选择需要导出的数据')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// 导出的二次确认
|
|
|
|
// 导出的二次确认
|
|
|
|
await message.exportConfirm()
|
|
|
|
await message.exportConfirm()
|
|
|
|
// 发起导出
|
|
|
|
// 发起导出
|
|
|
|
exportLoading.value = true
|
|
|
|
exportLoading.value = true
|
|
|
|
const data = await DeviceModelApi.exportDeviceModel({ ids: selectedIds.value.join(',') })
|
|
|
|
const params: any = {
|
|
|
|
|
|
|
|
...queryParams,
|
|
|
|
|
|
|
|
ids: selectedIds.value.length ? selectedIds.value.join(',') : undefined
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const data = await DeviceModelApi.exportDeviceModel(params)
|
|
|
|
download.excel(data, '采集设备模型.xls')
|
|
|
|
download.excel(data, '采集设备模型.xls')
|
|
|
|
} catch {
|
|
|
|
} catch {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
@ -229,12 +440,274 @@ const attributeModelId = ref<number | undefined>(undefined)
|
|
|
|
const attributeModelName = ref('')
|
|
|
|
const attributeModelName = ref('')
|
|
|
|
|
|
|
|
|
|
|
|
const modelAttributeTabLabel = computed(() => {
|
|
|
|
const modelAttributeTabLabel = computed(() => {
|
|
|
|
if (!attributeModelId.value) {
|
|
|
|
|
|
|
|
return '采集点'
|
|
|
|
return '采集点'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const modelRuleTabLabel = computed(() => {
|
|
|
|
|
|
|
|
return '点位规则'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface DeviceModelRuleVO {
|
|
|
|
|
|
|
|
id: number
|
|
|
|
|
|
|
|
identifier: string
|
|
|
|
|
|
|
|
fieldName: string
|
|
|
|
|
|
|
|
fieldRule: string
|
|
|
|
|
|
|
|
defaultValue: string
|
|
|
|
|
|
|
|
modelId: number
|
|
|
|
|
|
|
|
createTime?: string | number | Date
|
|
|
|
|
|
|
|
ruleAttributeId?: number
|
|
|
|
|
|
|
|
ruleOperator?: string
|
|
|
|
|
|
|
|
ruleValue?: string | number
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ruleLoading = ref(false)
|
|
|
|
|
|
|
|
const ruleList = ref<DeviceModelRuleVO[]>([])
|
|
|
|
|
|
|
|
const ruleTotal = ref(0)
|
|
|
|
|
|
|
|
const ruleQueryParams = reactive({
|
|
|
|
|
|
|
|
pageNo: 1,
|
|
|
|
|
|
|
|
pageSize: 10,
|
|
|
|
|
|
|
|
identifier: undefined as string | undefined,
|
|
|
|
|
|
|
|
fieldName: undefined as string | undefined,
|
|
|
|
|
|
|
|
fieldRule: undefined as string | undefined,
|
|
|
|
|
|
|
|
defaultValue: undefined as string | undefined,
|
|
|
|
|
|
|
|
modelId: undefined as number | undefined,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
const ruleQueryFormRef = ref()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ruleAttributeOptions = ref<DeviceModelAttributeVO[]>([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getRuleList = async () => {
|
|
|
|
|
|
|
|
if (!attributeModelId.value) return
|
|
|
|
|
|
|
|
ruleLoading.value = true
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const params = {
|
|
|
|
|
|
|
|
...ruleQueryParams,
|
|
|
|
|
|
|
|
modelId: attributeModelId.value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return attributeModelName.value ? `采集点:${attributeModelName.value}` : '采集点'
|
|
|
|
const data = await request.get({ url: '/iot/device-model-rules/page', params })
|
|
|
|
|
|
|
|
const listData = Array.isArray((data as any)?.list) ? (data as any).list : (Array.isArray(data) ? data : [])
|
|
|
|
|
|
|
|
const totalData = (data as any)?.total ?? listData.length
|
|
|
|
|
|
|
|
ruleList.value = listData as DeviceModelRuleVO[]
|
|
|
|
|
|
|
|
ruleTotal.value = totalData
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ruleLoading.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleRuleQuery = () => {
|
|
|
|
|
|
|
|
if (!attributeModelId.value) return
|
|
|
|
|
|
|
|
ruleQueryParams.pageNo = 1
|
|
|
|
|
|
|
|
getRuleList()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const resetRuleQuery = () => {
|
|
|
|
|
|
|
|
if (!attributeModelId.value) return
|
|
|
|
|
|
|
|
ruleQueryFormRef.value?.resetFields?.()
|
|
|
|
|
|
|
|
handleRuleQuery()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const loadRuleAttributeOptions = async (modelId: number) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const res = await DeviceModelAttributeApi.getDeviceModelAttributeList(modelId)
|
|
|
|
|
|
|
|
const data = Array.isArray(res) ? res : (res as any)?.list ?? []
|
|
|
|
|
|
|
|
ruleAttributeOptions.value = data as DeviceModelAttributeVO[]
|
|
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
|
|
ruleAttributeOptions.value = []
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
|
|
() => attributeModelId.value,
|
|
|
|
|
|
|
|
async (val) => {
|
|
|
|
|
|
|
|
ruleQueryParams.modelId = val ?? undefined
|
|
|
|
|
|
|
|
if (!val) {
|
|
|
|
|
|
|
|
ruleList.value = []
|
|
|
|
|
|
|
|
ruleTotal.value = 0
|
|
|
|
|
|
|
|
ruleAttributeOptions.value = []
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleQueryParams.pageNo = 1
|
|
|
|
|
|
|
|
await Promise.all([getRuleList(), loadRuleAttributeOptions(val)])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ruleDialogVisible = ref(false)
|
|
|
|
|
|
|
|
const ruleFormLoading = ref(false)
|
|
|
|
|
|
|
|
const ruleFormRef = ref()
|
|
|
|
|
|
|
|
const ruleForm = reactive<Partial<DeviceModelRuleVO>>({
|
|
|
|
|
|
|
|
id: undefined,
|
|
|
|
|
|
|
|
identifier: '',
|
|
|
|
|
|
|
|
fieldName: '',
|
|
|
|
|
|
|
|
fieldRule: '',
|
|
|
|
|
|
|
|
defaultValue: '',
|
|
|
|
|
|
|
|
modelId: undefined,
|
|
|
|
|
|
|
|
ruleAttributeId: undefined,
|
|
|
|
|
|
|
|
ruleOperator: undefined,
|
|
|
|
|
|
|
|
ruleValue: undefined,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const extraPointRules = ref<
|
|
|
|
|
|
|
|
Array<{
|
|
|
|
|
|
|
|
id?: number
|
|
|
|
|
|
|
|
rule?: string
|
|
|
|
|
|
|
|
operator?: string
|
|
|
|
|
|
|
|
operatorRule?: string | number
|
|
|
|
|
|
|
|
}>
|
|
|
|
|
|
|
|
>([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const runningRuleOptions = [
|
|
|
|
|
|
|
|
{ value: '1', label: '运行' },
|
|
|
|
|
|
|
|
{ value: '2', label: '待机中(不运行、没故障)' },
|
|
|
|
|
|
|
|
{ value: '3', label: '故障中(故障且待机)' },
|
|
|
|
|
|
|
|
{ value: '4', label: '报警中(故障且运行)' },
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const alarmRuleOptions = [
|
|
|
|
|
|
|
|
{ value: 'ALARM', label: '报警' },
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const currentRuleOptions = computed(() => {
|
|
|
|
|
|
|
|
const id = (ruleForm.identifier || '').toString().toUpperCase()
|
|
|
|
|
|
|
|
if (id === 'RUNNING') return runningRuleOptions
|
|
|
|
|
|
|
|
if (id === 'ALARM') return alarmRuleOptions
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isRuleDisabled = (value: string, selfRule?: string | number) => {
|
|
|
|
|
|
|
|
if (!value) return false
|
|
|
|
|
|
|
|
const v = String(value)
|
|
|
|
|
|
|
|
const self = selfRule != null ? String(selfRule) : undefined
|
|
|
|
|
|
|
|
if (self === v) return false
|
|
|
|
|
|
|
|
if (ruleForm.fieldRule && String(ruleForm.fieldRule) === v && self !== v) return true
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
|
|
|
extraPointRules.value.some(
|
|
|
|
|
|
|
|
(item) => item.rule != null && String(item.rule) === v && String(item.rule) !== self
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ruleOperatorOptions = [
|
|
|
|
|
|
|
|
{ value: 'TRUE', label: '为真' },
|
|
|
|
|
|
|
|
{ value: 'FALSE', label: '为假' },
|
|
|
|
|
|
|
|
{ value: 'EQ', label: '等于' },
|
|
|
|
|
|
|
|
{ value: 'LE', label: '小于等于' },
|
|
|
|
|
|
|
|
{ value: 'GE', label: '大于等于' },
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isRunningIdentifier = computed(() => {
|
|
|
|
|
|
|
|
return (ruleForm.identifier || '').toString().toUpperCase() === 'RUNNING'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const openRuleForm = (row: DeviceModelRuleVO & { pointRulesVOList?: any[] }) => {
|
|
|
|
|
|
|
|
ruleForm.id = row.id
|
|
|
|
|
|
|
|
ruleForm.identifier = row.identifier
|
|
|
|
|
|
|
|
ruleForm.fieldName = row.fieldName
|
|
|
|
|
|
|
|
ruleForm.defaultValue = row.defaultValue
|
|
|
|
|
|
|
|
ruleForm.modelId = row.modelId
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extraPointRules.value = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const list = Array.isArray(row.pointRulesVOList) ? row.pointRulesVOList : []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (list.length) {
|
|
|
|
|
|
|
|
const first = list[0] as any
|
|
|
|
|
|
|
|
ruleForm.fieldRule = (first.rule ?? row.fieldRule) as any
|
|
|
|
|
|
|
|
ruleForm.ruleAttributeId = first.id as any
|
|
|
|
|
|
|
|
ruleForm.ruleOperator = first.operator as any
|
|
|
|
|
|
|
|
ruleForm.ruleValue = first.operatorRule as any
|
|
|
|
|
|
|
|
extraPointRules.value = list.slice(1).map((item: any) => ({
|
|
|
|
|
|
|
|
id: item.id,
|
|
|
|
|
|
|
|
rule: item.rule,
|
|
|
|
|
|
|
|
operator: item.operator,
|
|
|
|
|
|
|
|
operatorRule: item.operatorRule,
|
|
|
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ruleForm.fieldRule = row.fieldRule
|
|
|
|
|
|
|
|
ruleForm.ruleAttributeId = row.ruleAttributeId
|
|
|
|
|
|
|
|
ruleForm.ruleOperator = row.ruleOperator
|
|
|
|
|
|
|
|
ruleForm.ruleValue = row.ruleValue as any
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const options = currentRuleOptions.value
|
|
|
|
|
|
|
|
if (options.length && !options.some((item) => item.value === ruleForm.fieldRule)) {
|
|
|
|
|
|
|
|
ruleForm.fieldRule = options[0].value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ruleDialogVisible.value = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleRuleSubmit = async () => {
|
|
|
|
|
|
|
|
if (!ruleForm.id) return
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
ruleFormLoading.value = true
|
|
|
|
|
|
|
|
const pointRulesVOList: any[] = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ruleForm.ruleAttributeId && ruleForm.ruleOperator) {
|
|
|
|
|
|
|
|
pointRulesVOList.push({
|
|
|
|
|
|
|
|
id: ruleForm.ruleAttributeId,
|
|
|
|
|
|
|
|
rule: ruleForm.fieldRule,
|
|
|
|
|
|
|
|
operator: ruleForm.ruleOperator,
|
|
|
|
|
|
|
|
operatorRule: ruleForm.ruleValue,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
extraPointRules.value.forEach((item) => {
|
|
|
|
|
|
|
|
if (!item.id || !item.operator) return
|
|
|
|
|
|
|
|
pointRulesVOList.push({
|
|
|
|
|
|
|
|
id: item.id,
|
|
|
|
|
|
|
|
rule: item.rule ?? ruleForm.fieldRule,
|
|
|
|
|
|
|
|
operator: item.operator,
|
|
|
|
|
|
|
|
operatorRule: item.operatorRule,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
|
|
id: ruleForm.id,
|
|
|
|
|
|
|
|
identifier: ruleForm.identifier,
|
|
|
|
|
|
|
|
fieldName: ruleForm.fieldName,
|
|
|
|
|
|
|
|
fieldRule: ruleForm.fieldRule,
|
|
|
|
|
|
|
|
defaultValue: ruleForm.defaultValue,
|
|
|
|
|
|
|
|
modelId: ruleForm.modelId,
|
|
|
|
|
|
|
|
pointRulesVOList,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await request.put({ url: '/iot/device-model-rules/update', data: payload })
|
|
|
|
|
|
|
|
message.success('保存成功')
|
|
|
|
|
|
|
|
ruleDialogVisible.value = false
|
|
|
|
|
|
|
|
await getRuleList()
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
ruleFormLoading.value = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleAddPointRule = () => {
|
|
|
|
|
|
|
|
if (!isRunningIdentifier.value) return
|
|
|
|
|
|
|
|
const allOptions = currentRuleOptions.value || []
|
|
|
|
|
|
|
|
const used = new Set<string>()
|
|
|
|
|
|
|
|
if (ruleForm.fieldRule) used.add(String(ruleForm.fieldRule))
|
|
|
|
|
|
|
|
extraPointRules.value.forEach((item) => {
|
|
|
|
|
|
|
|
if (item.rule != null) used.add(String(item.rule))
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
const next = allOptions.find((opt) => !used.has(String(opt.value)))
|
|
|
|
|
|
|
|
if (!next) {
|
|
|
|
|
|
|
|
message.warning('已没有可用的点位规则可选')
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extraPointRules.value.push({
|
|
|
|
|
|
|
|
rule: next.value as any,
|
|
|
|
|
|
|
|
id: undefined,
|
|
|
|
|
|
|
|
operator: undefined,
|
|
|
|
|
|
|
|
operatorRule: undefined,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemovePointRule = (index: number) => {
|
|
|
|
|
|
|
|
if (index < 0 || index >= extraPointRules.value.length) return
|
|
|
|
|
|
|
|
extraPointRules.value.splice(index, 1)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const handleShowAttribute = (row: any) => {
|
|
|
|
const handleShowAttribute = (row: any) => {
|
|
|
|
attributeModelId.value = row?.id
|
|
|
|
attributeModelId.value = row?.id
|
|
|
|
attributeModelName.value = row?.name ?? ''
|
|
|
|
attributeModelName.value = row?.name ?? ''
|
|
|
|
|