|
|
@@ -74,7 +74,7 @@ const { loading: branchLoading } = useRequest(branchMethod(0, 1, 1)).onSuccess((
|
|
|
branch.value = to(data);
|
|
|
});
|
|
|
|
|
|
-const { loading: submitting, send: submit } = useRequest(addDeviceRegisterMethod, { immediate: false }).onSuccess(({ data }) => {
|
|
|
+const { loading: submitting, send: submit } = useRequest(addDeviceRegisterMethod, { immediate: false }).onSuccess(() => {
|
|
|
emits('submit');
|
|
|
});
|
|
|
// 获取设备类型
|
|
|
@@ -85,11 +85,15 @@ async function getDeviceType() {
|
|
|
deviceTypesLoading.value = true;
|
|
|
const res = await getDictionaryMethod('fdhb_device_type');
|
|
|
if (res && res.length > 0) {
|
|
|
+ console.log(res, 'res==>');
|
|
|
deviceTypes.value = res.map((item: any) => ({
|
|
|
id: item.value,
|
|
|
name: item.label,
|
|
|
}));
|
|
|
}
|
|
|
+ console.log(deviceTypes.value, 'deviceTypes==>');
|
|
|
+ // 设备类型加载后,若当前值是名称则映射成对应的id
|
|
|
+ normalizeDeviceTypeToId();
|
|
|
deviceTypesLoading.value = false;
|
|
|
}
|
|
|
const showDept = ref(false);
|
|
|
@@ -105,17 +109,33 @@ async function getInstitution(orgId: string | number) {
|
|
|
}
|
|
|
watch(
|
|
|
() => model.value.orgId,
|
|
|
- async (newVal) => {
|
|
|
+ async (newVal, oldVal) => {
|
|
|
showDept.value = !!newVal;
|
|
|
if (showDept.value) {
|
|
|
- // 请求获取机构
|
|
|
- getInstitution(newVal ?? '');
|
|
|
+ // 加载机构列表,确保编辑时机构名称可显示
|
|
|
+ await getInstitution(newVal ?? '');
|
|
|
+ } else {
|
|
|
+ insArr.value = [];
|
|
|
}
|
|
|
- if (!newVal || newVal !== model.value.institutionId) {
|
|
|
- model.value.institutionId = ''; // 或者 ''
|
|
|
+ // 仅当组织实际发生切换时清空机构
|
|
|
+ if (oldVal !== undefined && newVal !== oldVal) {
|
|
|
+ model.value.institutionId = '';
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
);
|
|
|
+// 始终以数组形式暴露设备ID,避免模板类型告警
|
|
|
+const deviceIdsSafe = computed<string[]>({
|
|
|
+ get() {
|
|
|
+ if (!Array.isArray(model.value.deviceIds)) {
|
|
|
+ model.value.deviceIds = [''];
|
|
|
+ }
|
|
|
+ return model.value.deviceIds as string[];
|
|
|
+ },
|
|
|
+ set(newVal: string[]) {
|
|
|
+ model.value.deviceIds = newVal;
|
|
|
+ },
|
|
|
+});
|
|
|
const formItems = computed(() => {
|
|
|
const baseItems: any[] = [
|
|
|
{
|
|
|
@@ -129,7 +149,7 @@ const formItems = computed(() => {
|
|
|
loading: deviceTypesLoading.value,
|
|
|
options: computed(() => deviceTypes.value),
|
|
|
optionProps: { value: 'id', label: 'name' },
|
|
|
- optionGroupProps: { options: 'groups' },
|
|
|
+ // optionGroupProps: { options: 'groups' },
|
|
|
clearable: true,
|
|
|
filterable: true,
|
|
|
},
|
|
|
@@ -219,6 +239,8 @@ const formProps = reactive<VxeFormProps>({
|
|
|
|
|
|
const formEmits: VxeFormListeners = {
|
|
|
submit({ data }) {
|
|
|
+ // 提交前确保 deviceType 存为 id
|
|
|
+ normalizeDeviceTypeToId();
|
|
|
// 验证必填字段
|
|
|
if (!data.deviceType) {
|
|
|
notification.error({
|
|
|
@@ -283,6 +305,21 @@ onBeforeMount(async () => {
|
|
|
// 获取设备名称·
|
|
|
getDeviceType();
|
|
|
});
|
|
|
+
|
|
|
+// 若 deviceType 当前为名称,按照选项映射成对应的 id
|
|
|
+function normalizeDeviceTypeToId() {
|
|
|
+ const current = model.value.deviceType;
|
|
|
+ if (!current) return;
|
|
|
+ const options = deviceTypes.value || [];
|
|
|
+ // 已经是有效 id 则不处理
|
|
|
+ const existsById = options.some((opt) => String(opt.id) === String(current));
|
|
|
+ if (existsById) return;
|
|
|
+ // 如果值是名称,回填为对应的 id
|
|
|
+ const byName = options.find((opt) => String(opt.name) === String(current));
|
|
|
+ if (byName) {
|
|
|
+ model.value.deviceType = String(byName.id);
|
|
|
+ }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -303,8 +340,8 @@ onBeforeMount(async () => {
|
|
|
|
|
|
<template #deviceIdSlot>
|
|
|
<div class="device-ids-container">
|
|
|
- <div v-for="(deviceId, index) in model.deviceIds || []" :key="index" class="device-id-item">
|
|
|
- <vxe-input v-model="model.deviceIds[index]" placeholder="请输入" style="width: 200px" />
|
|
|
+ <div v-for="(deviceId, index) in deviceIdsSafe" :key="index" class="device-id-item">
|
|
|
+ <vxe-input v-model="deviceIdsSafe[index]" placeholder="请输入" style="width: 200px" />
|
|
|
<vxe-button v-if="(model.deviceIds || []).length > 1" type="text" style="color: #ff4d4f; margin-left: 8px" @click="removeDeviceId(index)">
|
|
|
<template #default>×</template>
|
|
|
</vxe-button>
|