review:【antd】【iot】物模型的管理

pull/268/head^2
YunaiV 2025-11-21 11:20:27 +08:00
parent 543e48504b
commit f650d44194
6 changed files with 70 additions and 71 deletions

View File

@ -23,16 +23,65 @@ const props = defineProps<{
productId: number;
}>();
//
const product = ref<IotProductApi.Product>({} as IotProductApi.Product);
const product = ref<IotProductApi.Product>({} as IotProductApi.Product); //
//
provide(IOT_PROVIDE_KEY.PRODUCT, product);
provide(IOT_PROVIDE_KEY.PRODUCT, product); //
//
// TODO @haohaoform web-antd/src/views/system/user/index.vue open
const thingModelFormRef = ref();
// TODO @haohaothingModelTSLRef modal
const thingModelTSLRef = ref();
// TODO @haohao
//
function handleCreate() {
thingModelFormRef.value?.open('create');
}
//
function handleEdit(row: any) {
thingModelFormRef.value?.open('update', row.id);
}
//
async function handleDelete(row: any) {
// TODO @haohao loading
try {
await deleteThingModel(row.id);
message.success('删除成功');
gridApi.reload();
} catch (error) {
console.error('删除失败:', error);
}
}
// TSL
function handleOpenTSL() {
thingModelTSLRef.value?.open();
}
//
// TODO @haohao data.ts
function getDataTypeLabel(row: any) {
return getDataTypeOptionsLabel(row.property?.dataType) || '-';
}
//
function handleRefresh() {
gridApi.reload();
}
//
async function getProductData() {
try {
product.value = await getProduct(props.productId);
} catch (error) {
console.error('获取产品信息失败:', error);
}
}
// TODO @haohao
const [Grid, gridApi] = useVbenVxeGrid({
gridOptions: {
columns: useGridColumns(),
@ -64,51 +113,6 @@ const [Grid, gridApi] = useVbenVxeGrid({
},
});
//
function handleCreate() {
thingModelFormRef.value?.open('create');
}
//
function handleEdit(row: any) {
thingModelFormRef.value?.open('update', row.id);
}
//
async function handleDelete(row: any) {
try {
await deleteThingModel(row.id);
message.success('删除成功');
gridApi.reload();
} catch (error) {
console.error('删除失败:', error);
}
}
// TSL
function handleOpenTSL() {
thingModelTSLRef.value?.open();
}
//
function getDataTypeLabel(row: any) {
return getDataTypeOptionsLabel(row.property?.dataType) || '-';
}
//
function handleRefresh() {
gridApi.reload();
}
//
async function getProductData() {
try {
product.value = await getProduct(props.productId);
} catch (error) {
console.error('获取产品信息失败:', error);
}
}
//
onMounted(async () => {
await getProductData();
@ -116,11 +120,7 @@ onMounted(async () => {
</script>
<template>
<Page
auto-content-height
description="管理产品的物模型定义,包括属性、服务和事件"
title="物模型管理"
>
<Page auto-content-height>
<Grid>
<template #toolbar-tools>
<TableAction
@ -134,23 +134,21 @@ onMounted(async () => {
{
label: 'TSL',
type: 'default',
color: 'success',
color: 'success', // TODO @haohao color ps icon
onClick: handleOpenTSL,
},
]"
/>
</template>
<!-- 数据类型列 -->
<template #dataType="{ row }">
<span>{{ getDataTypeLabel(row) }}</span>
</template>
<!-- 数据定义列 -->
<!-- TODO @haohao可以在 data.ts 就写掉这个逻辑 -->
<template #dataDefinition="{ row }">
<DataDefinition :data="row" />
</template>
<!-- 操作列 -->
<template #actions="{ row }">
<TableAction
@ -178,8 +176,7 @@ onMounted(async () => {
<!-- 物模型表单 -->
<ThingModelForm ref="thingModelFormRef" @success="handleRefresh" />
<!-- TSL 弹窗 -->
<ThingModelTsl ref="thingModelTSLRef"/>
<ThingModelTsl ref="thingModelTSLRef" />
</Page>
</template>

View File

@ -1,3 +1,4 @@
<!-- TODO @haohao如果是模块内用的就用 modules 等后面点在看优先级 -->
<script lang="ts" setup>
import type { ThingModelData } from '#/api/iot/thingmodel';
@ -17,7 +18,6 @@ defineOptions({ name: 'DataDefinition' });
const props = defineProps<{ data: ThingModelData }>();
//
const formattedDataSpecsList = computed(() => {
if (
!props.data.property?.dataSpecsList ||
@ -28,9 +28,8 @@ const formattedDataSpecsList = computed(() => {
return props.data.property.dataSpecsList
.map((item) => `${item.value}-${item.name}`)
.join('、');
});
}); //
//
const shortText = computed(() => {
if (
!props.data.property?.dataSpecsList ||
@ -43,7 +42,7 @@ const shortText = computed(() => {
return count > 1
? `${first.value}-${first.name}${count}`
: `${first.value}-${first.name}`;
});
}); //
</script>
<template>
@ -100,9 +99,8 @@ const shortText = computed(() => {
</template>
<!-- 服务 -->
<div v-if="Number(data.type) === IoTThingModelTypeEnum.SERVICE">
调用方式{{
getThingModelServiceCallTypeLabel(data.service?.callType as any)
}}
调用方式
{{ getThingModelServiceCallTypeLabel(data.service?.callType as any) }}
</div>
<!-- 事件 -->
<div v-if="Number(data.type) === IoTThingModelTypeEnum.EVENT">
@ -111,6 +109,7 @@ const shortText = computed(() => {
</template>
<style lang="scss" scoped>
/** TODO @haohaotindwind */
.data-specs-text {
cursor: help;
border-bottom: 1px dashed #d9d9d9;

View File

@ -1 +1 @@
export {default as DataDefinition} from './data-definition.vue';
export { default as DataDefinition } from './data-definition.vue';

View File

@ -23,7 +23,7 @@ const props = defineProps<{ isStructDataSpecs?: boolean; modelValue: any }>();
const emits = defineEmits(['update:modelValue']);
const thingModelEvent = useVModel(props, 'modelValue', emits) as Ref<any>;
// INFO
/** 默认选中INFO 信息 */
watch(
() => thingModelEvent.value.type,
(val: string | undefined) =>

View File

@ -2,6 +2,7 @@
<script lang="ts" setup>
import type { Ref } from 'vue';
// TODO @haohao使 form.vue
import type { IotProductApi } from '#/api/iot/product/product';
import type { ThingModelData } from '#/api/iot/thingmodel';
@ -61,6 +62,7 @@ const formData = ref<any>({
const formRef = ref(); // Ref
/** 打开弹窗 */
// TODO @haohaoModal
async function open(type: string, id?: number) {
dialogVisible.value = true;
// create -> update ->
@ -244,6 +246,7 @@ function resetForm() {
:confirm-loading="formLoading"
@ok="submitForm"
>
<!-- TODO @haohao这个可以改造成 data.ts schema 形式么可能是有一定成本后续迁移 ele 版本会容易很多 -->
<Form
ref="formRef"
:model="formData"

View File

@ -10,7 +10,7 @@ import { Modal, Radio, Textarea } from 'ant-design-vue';
import { getThingModelTSL } from '#/api/iot/thingmodel';
import { IOT_PROVIDE_KEY } from '#/views/iot/utils/constants';
defineOptions({name: 'ThingModelTsl'});
defineOptions({ name: 'ThingModelTsl' });
const dialogVisible = ref(false); //
const dialogTitle = ref('物模型 TSL'); //