|
|
@@ -0,0 +1,183 @@
|
|
|
+<template>
|
|
|
+ <a-row justify="end">
|
|
|
+ <a-col >
|
|
|
+ <a-space>
|
|
|
+ <a-button type="primary" @click="openModel('attrVisible', 'add')" >新增属性</a-button>
|
|
|
+ </a-space>
|
|
|
+ </a-col>
|
|
|
+ </a-row>
|
|
|
+ <a-table
|
|
|
+ style="margin-top: 10px;"
|
|
|
+ :columns="columns"
|
|
|
+ :dataSource="state.dataSource"
|
|
|
+ :loading="state.loading"
|
|
|
+ :pagination="state.queryParams"
|
|
|
+ >
|
|
|
+ <template #bodyCell="{column, record}">
|
|
|
+ <template v-if="column.key === 'action'">
|
|
|
+ </template>
|
|
|
+ <a-space>
|
|
|
+ <a href="#">修改</a>
|
|
|
+ <a-popconfirm
|
|
|
+ title="确实要删除吗?"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ @confirm="confirmDel('attr', record.id)"
|
|
|
+ >
|
|
|
+ <a href="#">删除</a>
|
|
|
+ </a-popconfirm>
|
|
|
+ </a-space>
|
|
|
+ </template>
|
|
|
+ </a-table>
|
|
|
+
|
|
|
+ <a-modal
|
|
|
+ :title="modalTitle"
|
|
|
+ :visible="state.attrVisible"
|
|
|
+ @cancel="state.attrVisible = false"
|
|
|
+ @ok="ok('attr')"
|
|
|
+ ok-text="确定"
|
|
|
+ cancel-text="取消"
|
|
|
+ >
|
|
|
+ <a-form :label-col="{span: 4}" :wrapper-col="{span: 14}" >
|
|
|
+ <a-form-item label="属性名称" v-bind="validateInfos.attributeLabel" >
|
|
|
+ <a-input v-model:value="attrRef.attributeLabel" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="数据类型" v-bind="validateInfos.dataType" >
|
|
|
+ <a-select v-model:value="attrRef.dataType" >
|
|
|
+ <a-select-option :value="item" v-for="item in dataTypes" :key="item" >{{item}}</a-select-option>
|
|
|
+ </a-select>
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="访问权限" v-bind="validateInfos.scope" >
|
|
|
+ <a-checkbox-group v-model:value="attrRef.scope" name="checkboxgroup" :options="[{label: '读', value: 'R'}, {label: '写', value: 'W'}]" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="单位" >
|
|
|
+ <a-input v-model:value="attrRef.dataUnit" />
|
|
|
+ </a-form-item>
|
|
|
+ <a-form-item label="计算表达式" >
|
|
|
+ <a-input v-model:value="attrRef.expr" />
|
|
|
+ </a-form-item>
|
|
|
+ </a-form>
|
|
|
+ </a-modal>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script lang="ts" setup >
|
|
|
+import { ModelAttrController } from '@/controller/iot/modelAttr'
|
|
|
+import { computed } from '@vue/reactivity'
|
|
|
+import { ColumnProps } from 'ant-design-vue/lib/table'
|
|
|
+import { onMounted, reactive } from 'vue'
|
|
|
+import { Form } from 'ant-design-vue'
|
|
|
+import { useRoute } from 'vue-router'
|
|
|
+
|
|
|
+const columns: ColumnProps = [
|
|
|
+ {
|
|
|
+ title: '属性',
|
|
|
+ key: 'attributeKey'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '属性名称',
|
|
|
+ key: 'attributeLabel'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '数据类型',
|
|
|
+ key: 'dataType'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '数据单位',
|
|
|
+ key: 'dataUnit'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '权限',
|
|
|
+ key: 'scope'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '表达式',
|
|
|
+ key: 'expr'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '操作',
|
|
|
+ key: 'action'
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+const route = useRoute()
|
|
|
+
|
|
|
+const modelId = route.query.id! as string
|
|
|
+
|
|
|
+const useForm = Form.useForm
|
|
|
+
|
|
|
+const dataTypes = ['string(字符串)', 'long(整数)', 'boolean(布尔值)', 'double(浮点数)', 'json(JSON)']
|
|
|
+
|
|
|
+const state = reactive<{
|
|
|
+ dataSource: IOT.API.MODELATTR.ModelAttr[],
|
|
|
+ [key: string]: any
|
|
|
+}>({
|
|
|
+ dataSource: [],
|
|
|
+ loading: false,
|
|
|
+ opraState: 'add',
|
|
|
+ queryParams: {
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ modelId: '',
|
|
|
+ total: 0
|
|
|
+ },
|
|
|
+ attrVisible: false,
|
|
|
+ commandVisible: false
|
|
|
+})
|
|
|
+
|
|
|
+const attrRef = reactive({
|
|
|
+ attributeLabel: '',
|
|
|
+ dataType: '',
|
|
|
+ dataUnit: '',
|
|
|
+ scope: [],
|
|
|
+ key: 'tem',
|
|
|
+ expr: '',
|
|
|
+ attributeKey: 'tem',
|
|
|
+ modelId: ''
|
|
|
+})
|
|
|
+
|
|
|
+const { resetFields, validate: validateAttr, validateInfos } = useForm(attrRef, reactive({
|
|
|
+ attributeLabel: [{ required: true, message: '请填写属性名称' }],
|
|
|
+ dataType: [{ required: true, message: '请选择数据类型' }],
|
|
|
+ dataUnit: [{ required: true, message: '请填写数据单位' }]
|
|
|
+}))
|
|
|
+
|
|
|
+const confirmDel = async (modalName: 'attr' | 'command', id: string) => {
|
|
|
+ modalName === 'attr' ? await ModelAttrController.del(id) : await ModelAttrController.del(id)
|
|
|
+ getModelAttr()
|
|
|
+}
|
|
|
+
|
|
|
+const ok = (modalName: 'attr' | 'command') => {
|
|
|
+ if (modalName === 'attr') {
|
|
|
+ validateAttr().then(() => {
|
|
|
+ ModelAttrController.post({ ...attrRef, scope: attrRef.scope.join(''), modelId })
|
|
|
+ })
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const openModel = (key: string, opraState: 'add' | 'update') => {
|
|
|
+ state[key] = true
|
|
|
+ state.opraState = opraState
|
|
|
+}
|
|
|
+
|
|
|
+const getModelAttr = async () => {
|
|
|
+ state.loading = true
|
|
|
+ const { data, sum } = await ModelAttrController.page(state.queryParams)
|
|
|
+ state.loading = false
|
|
|
+ state.dataSource = data
|
|
|
+ state.queryParams.total = sum
|
|
|
+}
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ state.queryParams.modelId = route.query.id
|
|
|
+ getModelAttr()
|
|
|
+})
|
|
|
+
|
|
|
+const modalTitle = computed(() => {
|
|
|
+ const t1 = state.opraState === 'add' ? '新增' : '编辑'
|
|
|
+ const t2 = state.attrVisible ? '属性' : '命令'
|
|
|
+ return t1 + t2
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+<style>
|
|
|
+</style>
|