feat(iot):优化 IoT 请求的代码风格(thingmodel 界面调整引入)
parent
5182cdbffa
commit
cfb1f8401e
|
|
@ -2,7 +2,7 @@
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
import type { IotProductApi } from '#/api/iot/product/product';
|
import type { IotProductApi } from '#/api/iot/product/product';
|
||||||
import type { ThingModelData } from '#/api/iot/thingmodel';
|
import type { ThingModelApi } from '#/api/iot/thingmodel';
|
||||||
|
|
||||||
import { computed, inject } from 'vue';
|
import { computed, inject } from 'vue';
|
||||||
|
|
||||||
|
|
@ -46,12 +46,12 @@ function handleCreate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 编辑物模型 */
|
/** 编辑物模型 */
|
||||||
function handleEdit(row: ThingModelData) {
|
function handleEdit(row: ThingModelApi.ThingModel) {
|
||||||
formModalApi.setData({ id: row.id }).open();
|
formModalApi.setData({ id: row.id }).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 删除物模型 */
|
/** 删除物模型 */
|
||||||
async function handleDelete(row: ThingModelData) {
|
async function handleDelete(row: ThingModelApi.ThingModel) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||||
duration: 0,
|
duration: 0,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { ThingModelData } from '#/api/iot/thingmodel';
|
import type { ThingModelApi } from '#/api/iot/thingmodel';
|
||||||
|
|
||||||
import { computed } from 'vue';
|
import { computed } from 'vue';
|
||||||
|
|
||||||
|
|
@ -27,7 +27,7 @@ const LIST_TYPES = new Set<string>([
|
||||||
IoTDataSpecsDataTypeEnum.ENUM,
|
IoTDataSpecsDataTypeEnum.ENUM,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const props = defineProps<{ data: ThingModelData }>();
|
const props = defineProps<{ data: ThingModelApi.ThingModel }>();
|
||||||
|
|
||||||
const formattedDataSpecsList = computed(() => {
|
const formattedDataSpecsList = computed(() => {
|
||||||
if (!props.data.property?.dataSpecsList?.length) {
|
if (!props.data.property?.dataSpecsList?.length) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
import type { DataSpecsNumberData } from '#/api/iot/thingmodel';
|
import type { ThingModelApi } from '#/api/iot/thingmodel';
|
||||||
|
|
||||||
import { DICT_TYPE } from '@vben/constants';
|
import { DICT_TYPE } from '@vben/constants';
|
||||||
import { getDictOptions } from '@vben/hooks';
|
import { getDictOptions } from '@vben/hooks';
|
||||||
|
|
@ -16,7 +16,7 @@ const dataSpecs = useVModel(
|
||||||
props,
|
props,
|
||||||
'modelValue',
|
'modelValue',
|
||||||
emits,
|
emits,
|
||||||
) as Ref<DataSpecsNumberData>;
|
) as Ref<ThingModelApi.DataSpecsNumberData>;
|
||||||
|
|
||||||
/** 单位下拉变化时,拆出 unitName 与 unit 回写 */
|
/** 单位下拉变化时,拆出 unitName 与 unit 回写 */
|
||||||
function unitChange(unitSpecs: any) {
|
function unitChange(unitSpecs: any) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
import type { IotProductApi } from '#/api/iot/product/product';
|
import type { IotProductApi } from '#/api/iot/product/product';
|
||||||
import type { ThingModelData } from '#/api/iot/thingmodel';
|
import type { ThingModelApi } from '#/api/iot/thingmodel';
|
||||||
|
|
||||||
import { computed, inject, ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
|
|
||||||
|
|
@ -35,7 +35,7 @@ const emit = defineEmits(['success']);
|
||||||
const product = inject<Ref<IotProductApi.Product>>(IOT_PROVIDE_KEY.PRODUCT);
|
const product = inject<Ref<IotProductApi.Product>>(IOT_PROVIDE_KEY.PRODUCT);
|
||||||
|
|
||||||
const formRef = ref();
|
const formRef = ref();
|
||||||
const formData = ref<ThingModelData>(buildEmptyFormData());
|
const formData = ref<ThingModelApi.ThingModel>(buildEmptyFormData());
|
||||||
|
|
||||||
const getTitle = computed(() =>
|
const getTitle = computed(() =>
|
||||||
formData.value.id
|
formData.value.id
|
||||||
|
|
@ -86,7 +86,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||||
});
|
});
|
||||||
|
|
||||||
/** 构造空白表单数据 */
|
/** 构造空白表单数据 */
|
||||||
function buildEmptyFormData(): ThingModelData {
|
function buildEmptyFormData(): ThingModelApi.ThingModel {
|
||||||
return {
|
return {
|
||||||
type: IoTThingModelTypeEnum.PROPERTY,
|
type: IoTThingModelTypeEnum.PROPERTY,
|
||||||
dataType: IoTDataSpecsDataTypeEnum.INT,
|
dataType: IoTDataSpecsDataTypeEnum.INT,
|
||||||
|
|
@ -107,7 +107,7 @@ function buildEmptyFormData(): ThingModelData {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 回显数据时,规整各分支字段确保子表单可绑定 */
|
/** 回显数据时,规整各分支字段确保子表单可绑定 */
|
||||||
function normalizeFormData(result: ThingModelData): ThingModelData {
|
function normalizeFormData(result: ThingModelApi.ThingModel): ThingModelApi.ThingModel {
|
||||||
const next: any = { ...result, type: Number(result.type) };
|
const next: any = { ...result, type: Number(result.type) };
|
||||||
if (isEmpty(next.property)) {
|
if (isEmpty(next.property)) {
|
||||||
next.dataType = IoTDataSpecsDataTypeEnum.INT;
|
next.dataType = IoTDataSpecsDataTypeEnum.INT;
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { Ref } from 'vue';
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
import type { ThingModelProperty } from '#/api/iot/thingmodel';
|
import type { ThingModelApi } from '#/api/iot/thingmodel';
|
||||||
|
|
||||||
import { computed, watch } from 'vue';
|
import { computed, watch } from 'vue';
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ const property = useVModel(
|
||||||
props,
|
props,
|
||||||
'modelValue',
|
'modelValue',
|
||||||
emits,
|
emits,
|
||||||
) as Ref<ThingModelProperty>;
|
) as Ref<ThingModelApi.Property>;
|
||||||
|
|
||||||
const dataTypeOptions = computed(() =>
|
const dataTypeOptions = computed(() =>
|
||||||
props.isStructDataSpecs ? STRUCT_CHILD_OPTIONS : getDataTypeOptions(),
|
props.isStructDataSpecs ? STRUCT_CHILD_OPTIONS : getDataTypeOptions(),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue