index.vue
4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<script lang="ts" setup>
import { Button, Divider } from 'ant-design-vue';
import { nextTick, ref, unref, watch } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { PlusCircleOutlined } from '@ant-design/icons-vue';
import { getExtendDescFormSchemas } from './config';
import { ExtendDescFormFieldsValueType } from '.';
import { BasicModal } from '/@/components/Modal';
import { PlusSquareOutlined, MinusSquareOutlined } from '@ant-design/icons-vue';
import {
ExtendDescOperationTypeEnum,
ExtendDescOperationTypeNameEnum,
OriginalDataTypeNameEnum,
} from '/@/enums/objectModelEnum';
import { EnumList } from '../EnumList';
const show = ref(false);
const props = withDefaults(
defineProps<{
value?: ExtendDescFormFieldsValueType;
disabled?: boolean;
}>(),
{
value: () => ({} as ExtendDescFormFieldsValueType),
}
);
const emit = defineEmits(['update:value', 'change']);
const [registerForm, { setFieldsValue, getFieldsValue, setProps, validate, resetFields }] =
useForm({
schemas: getExtendDescFormSchemas(),
showActionButtonGroup: false,
});
const infoExpandFlag = ref(false);
const enumListRef = ref<InstanceType<typeof EnumList>>();
const handleClick = async () => {
show.value = true;
await nextTick();
resetFields();
setProps({ disabled: props.disabled });
setFieldsValue(props.value);
};
const handleSubmit = async () => {
await validate();
await unref(enumListRef)?.validate();
const value = getFieldsValue() as ExtendDescFormFieldsValueType;
const valueMapping = unref(enumListRef)?.getFieldsValue();
value.valueMapping = valueMapping;
emit('update:value', value);
emit('change', value);
show.value = false;
};
const handleDelete = () => {
emit('update:value', {});
emit('change', {});
};
watch(show, async (value) => {
if (value) {
await nextTick();
setFieldsValue({ ...props.value });
}
});
const getOperationTypeName = (operationType: ExtendDescOperationTypeEnum) => {
const key = Object.keys(ExtendDescOperationTypeEnum).find(
(key) => ExtendDescOperationTypeEnum[key] === operationType
);
return key ? ExtendDescOperationTypeNameEnum[key] : key;
};
</script>
<template>
<section>
<Button v-if="!value.operationType" type="link" @click="handleClick">
<PlusCircleOutlined />
新增扩展描述
</Button>
<main v-if="value.operationType" class="flex">
<div class="flex-auto flex text-gray-400 bg-blue-50 text-xs p-2 border gap-2 border-gray-100">
<div text-base>
<PlusSquareOutlined
v-if="!infoExpandFlag"
class="cursor-pointer"
@click="infoExpandFlag = !infoExpandFlag"
/>
<MinusSquareOutlined
v-else
class="cursor-pointer"
@click="infoExpandFlag = !infoExpandFlag"
/>
</div>
<div>
<div class="mb-2">
<span class="text-gray-400">操作类型</span>
<span class="ml-2">{{ getOperationTypeName(value.operationType) }}</span>
</div>
<section
class="flex flex-col gap-2 overflow-hidden transition"
:class="infoExpandFlag ? '' : 'h-0'"
>
<div>
<span>寄存器地址:</span>
<span class="ml-2">{{ value.registerAddress }}</span>
</div>
<div>
<span>原始数据类型:</span>
<span class="ml-2">{{ OriginalDataTypeNameEnum[value.originalDataType] }}</span>
</div>
<div v-if="value.scaling">
<span>缩放因子:</span>
<span class="ml-2">{{ value.scaling }}</span>
</div>
<div v-if="value.valueRange">
<span>取值范围:</span>
<span class="ml-2">{{ value.valueRange?.min }} ~ {{ value.valueRange?.max }}</span>
</div>
</section>
</div>
</div>
<div class="ml-2">
<Button class="!px-0" @click="handleClick" type="link">
{{ disabled ? '查看' : '编辑' }}
</Button>
<Divider v-if="!disabled" type="vertical" />
<Button class="!px-0" @click="handleDelete" type="link" v-if="!disabled"> 删除 </Button>
</div>
</main>
<BasicModal
title="扩展描述"
v-model:visible="show"
@ok="handleSubmit"
:show-ok-btn="!disabled"
:width="480"
>
<BasicForm class="extension-form" @register="registerForm">
<template #valueMapping="{ model, field }">
<EnumList
ref="enumListRef"
v-model:value="model[field]"
:disabled="disabled"
:required="false"
add-button-name="+添加值映射"
/>
</template>
</BasicForm>
</BasicModal>
</section>
</template>
<style lang="less" scoped>
.extension-form {
:deep(.ant-input-number) {
width: 100%;
}
}
</style>