|
@@ -1,11 +1,10 @@
|
|
|
<template>
|
|
|
- <el-dialog class="api-edit" v-model="showDialog" :title="`${formData.id ? '编辑设备档案' : '新增设备档案'}`" width="800px" :close-on-click-modal="false" :close-on-press-escape="false">
|
|
|
+ <el-dialog class="api-edit" v-model="showDialog" :title="formData.id ? t('message.property.dossier.dialog.editTitle') : t('message.property.dossier.dialog.addTitle')" width="800px" :close-on-click-modal="false" :close-on-press-escape="false">
|
|
|
<el-form class="inline-form" ref="formRef" :model="formData" :rules="ruleForm" label-width="120px">
|
|
|
-
|
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="选择产品" prop="productKey">
|
|
|
- <el-select v-model="formData.productKey" placeholder="请选择产品" class="w100" disabled>
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.productKey')" prop="productKey">
|
|
|
+ <el-select v-model="formData.productKey" :placeholder="t('message.property.dossier.form.productPlaceholder')" class="w100" disabled>
|
|
|
<el-option v-for="item in productData" :key="item.key" :label="item.name" :value="item.key">
|
|
|
<span style="float: left">{{ item.name }}</span>
|
|
|
<span style="float: right; font-size: 13px">{{ item.key }}</span>
|
|
@@ -15,8 +14,8 @@
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="选择设备" prop="deviceKey">
|
|
|
- <el-select v-model="formData.deviceKey" placeholder="请选择设备" class="w100" filterable clearable @change="handleSelectionChange">
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.deviceKey')" prop="deviceKey">
|
|
|
+ <el-select v-model="formData.deviceKey" :placeholder="t('message.property.dossier.form.devicePlaceholder')" class="w100" filterable clearable @change="handleSelectionChange">
|
|
|
<el-option v-for="item in deviceList" :key="item.key" :label="item.name" :value="item.key">
|
|
|
<span style="float: left">{{ item.name }}</span>
|
|
|
<span style="float: right; font-size: 13px">{{ item.key }}</span>
|
|
@@ -28,22 +27,22 @@
|
|
|
|
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="设备名称" prop="deviceName">
|
|
|
- <el-input v-model.trim="formData.deviceName" placeholder="请输入设备名称" disabled />
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.deviceName')" prop="deviceName">
|
|
|
+ <el-input v-model.trim="formData.deviceName" :placeholder="t('message.property.dossier.form.deviceNamePlaceholder')" disabled />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="设备编码" prop="deviceNumber">
|
|
|
- <el-input v-model.trim="formData.deviceNumber" placeholder="请输入设备编码" />
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.deviceNumber')" prop="deviceNumber">
|
|
|
+ <el-input v-model.trim="formData.deviceNumber" :placeholder="t('message.property.dossier.form.deviceNumberPlaceholder')" />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="所属部门" prop="deptId">
|
|
|
- <el-cascader :options="deptData" :props="{ checkStrictly: true, emitPath: false, value: 'deptId', label: 'deptName' }" placeholder="请选择所属部门" clearable class="w100" v-model="formData.deptId">
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.deptId')" prop="deptId">
|
|
|
+ <el-cascader :options="deptData" :props="{ checkStrictly: true, emitPath: false, value: 'deptId', label: 'deptName' }" :placeholder="t('message.property.dossier.form.deptPlaceholder')" clearable class="w100" v-model="formData.deptId">
|
|
|
<template #default="{ node, data }">
|
|
|
<span>{{ data.deptName }}</span>
|
|
|
<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
|
|
@@ -53,101 +52,102 @@
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="设备类型">
|
|
|
- <el-input v-model.trim="formData.deviceCategory" placeholder="请输入设备类型" />
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.deviceCategory')">
|
|
|
+ <el-input v-model.trim="formData.deviceCategory" :placeholder="t('message.property.dossier.form.deviceCategoryPlaceholder')" />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
|
- <el-form-item label="安装时间">
|
|
|
- <el-date-picker v-model="formData.installTime" type="date" value-format="YYYY-MM-DD" placeholder="请选择时间" class="w100" clearable />
|
|
|
+ <el-form-item :label="t('message.property.dossier.form.installTime')">
|
|
|
+ <el-date-picker v-model="formData.installTime" type="date" value-format="YYYY-MM-DD" :placeholder="t('message.property.dossier.form.datePlaceholder')" class="w100" clearable />
|
|
|
</el-form-item>
|
|
|
</el-col>
|
|
|
</el-row>
|
|
|
|
|
|
- <el-divider content-position="left" v-if="Datalist">自定义属性</el-divider>
|
|
|
+ <el-divider content-position="left" v-if="Datalist">{{ t("message.property.dossier.form.dividerCustom") }}</el-divider>
|
|
|
<FromData :DataList="Datalist" @SetSaveData="SetSaveData" v-if="Datalist && Datalist.length > 0"></FromData>
|
|
|
-
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
|
- <el-button @click="showDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="onSubmit">确定</el-button>
|
|
|
+ <el-button @click="showDialog = false">{{ t("message.property.dossier.messages.cancel") }}</el-button>
|
|
|
+ <el-button type="primary" @click="onSubmit">{{ t("message.property.dossier.messages.confirm") }}</el-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
</el-dialog>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { ref, reactive, nextTick } from 'vue';
|
|
|
-import api from '/@/api/device'
|
|
|
-import system from '/@/api/system';
|
|
|
-import FromData from './component/from.vue';
|
|
|
+import { ref, reactive, nextTick, computed } from "vue";
|
|
|
+import api from "/@/api/device";
|
|
|
+import system from "/@/api/system";
|
|
|
+import FromData from "./component/from.vue";
|
|
|
|
|
|
-import { ruleRequired } from '/@/utils/validator';
|
|
|
-import { ElMessage } from 'element-plus';
|
|
|
+import { ruleRequired } from "/@/utils/validator";
|
|
|
+import { ElMessage } from "element-plus";
|
|
|
+import { useI18n } from "vue-i18n";
|
|
|
|
|
|
-const emit = defineEmits(['getList']);
|
|
|
+const emit = defineEmits(["getList"]);
|
|
|
+const { t } = useI18n();
|
|
|
|
|
|
const showDialog = ref(false);
|
|
|
const formRef = ref();
|
|
|
-const orgData = ref();
|
|
|
-const deviceList = ref();
|
|
|
-const productData = ref();
|
|
|
-const deptData = ref();
|
|
|
-const Datalist = ref();
|
|
|
-const newData = ref([]);
|
|
|
+const orgData = ref<any[]>([]);
|
|
|
+const deviceList = ref<Array<{ key: string; name: string }>>([]);
|
|
|
+const productData = ref<any[]>([]);
|
|
|
+const deptData = ref<any[]>([]);
|
|
|
+const Datalist = ref<any[]>([]);
|
|
|
const baseForm = {
|
|
|
id: undefined,
|
|
|
- productKey: '',
|
|
|
- deviceKey: '',
|
|
|
- deviceName: '',
|
|
|
+ productKey: "",
|
|
|
+ deviceKey: "",
|
|
|
+ deviceName: "",
|
|
|
area: "",
|
|
|
- deviceNumber: '',
|
|
|
- deviceCategory: '',
|
|
|
- installTime: '',
|
|
|
- deptId: '',
|
|
|
+ deviceNumber: "",
|
|
|
+ deviceCategory: "",
|
|
|
+ installTime: "",
|
|
|
+ deptId: "",
|
|
|
data: [],
|
|
|
-
|
|
|
};
|
|
|
|
|
|
-
|
|
|
const SetSaveData = (data: any) => {
|
|
|
formData.data = data;
|
|
|
-}
|
|
|
+};
|
|
|
const formData = reactive({
|
|
|
...baseForm,
|
|
|
});
|
|
|
|
|
|
-const ruleForm = {
|
|
|
- productKey: [ruleRequired('所属产品不能为空')],
|
|
|
- deviceName: [ruleRequired('设备名称不能为空')],
|
|
|
- deviceKey: [ruleRequired('设备不能为空')],
|
|
|
-};
|
|
|
-const handleSelectionChange = (value: any) => {
|
|
|
- const selectedOption = deviceList.value.find(option => option.key === value);
|
|
|
+const ruleForm = computed(() => {
|
|
|
+ return {
|
|
|
+ productKey: [ruleRequired(t("message.property.dossier.valid.productRequired"))],
|
|
|
+ deviceName: [ruleRequired(t("message.property.dossier.valid.deviceNameRequired"))],
|
|
|
+ deviceKey: [ruleRequired(t("message.property.dossier.valid.deviceRequired"))],
|
|
|
+ };
|
|
|
+});
|
|
|
+
|
|
|
+const handleSelectionChange = (value: string) => {
|
|
|
+ const selectedOption = deviceList.value.find((option: { key: string; name: string }) => option.key === value);
|
|
|
if (selectedOption) {
|
|
|
formData.deviceName = selectedOption.name;
|
|
|
} else {
|
|
|
- formData.deviceName = '';
|
|
|
+ formData.deviceName = "";
|
|
|
}
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
const onSubmit = async () => {
|
|
|
await formRef.value.validate();
|
|
|
- const theApi = !formData.id || formData.id === '0' ? api.dev_asset.add : api.dev_asset.edit;
|
|
|
+ const theApi = !formData.id || formData.id === "0" ? api.dev_asset.add : api.dev_asset.edit;
|
|
|
await theApi(formData);
|
|
|
- ElMessage.success('操作成功');
|
|
|
+ ElMessage.success(t("message.property.dossier.messages.saveSuccess"));
|
|
|
resetForm();
|
|
|
showDialog.value = false;
|
|
|
- emit('getList');
|
|
|
+ emit("getList");
|
|
|
};
|
|
|
|
|
|
const resetForm = async () => {
|
|
|
Object.assign(formData, { ...baseForm });
|
|
|
- Datalist.value = ''
|
|
|
+ Datalist.value = [];
|
|
|
formRef.value && formRef.value.resetFields();
|
|
|
};
|
|
|
|
|
@@ -158,7 +158,7 @@ const getIdByKey = (key: string) => {
|
|
|
}
|
|
|
}
|
|
|
return null; // 如果没有找到匹配的key,则返回null(或者其他合适的值)
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
const open = async (row: any, productInfo: any) => {
|
|
|
resetForm();
|
|
@@ -178,13 +178,13 @@ const open = async (row: any, productInfo: any) => {
|
|
|
productInfo = {
|
|
|
id: getIdByKey(row.productKey),
|
|
|
key: row.productKey,
|
|
|
- }
|
|
|
+ };
|
|
|
}
|
|
|
//根据产品ID获取设备列表
|
|
|
api.device.allList({ productKey: productInfo.key }).then((resd: any) => {
|
|
|
- deviceList.value = resd.device || [];
|
|
|
+ deviceList.value = (resd.device || []) as Array<{ key: string; name: string }>;
|
|
|
});
|
|
|
- })
|
|
|
+ });
|
|
|
|
|
|
//获取部门
|
|
|
api.dept.getList({ status: -1 }).then((res: any) => {
|
|
@@ -195,26 +195,24 @@ const open = async (row: any, productInfo: any) => {
|
|
|
});
|
|
|
|
|
|
if (row.id) {
|
|
|
-
|
|
|
api.dev_asset.detail({ deviceKey: row.deviceKey }).then((resde: any) => {
|
|
|
Object.assign(formData, { ...resde });
|
|
|
- formData.productKey = row.productKey
|
|
|
- const newArray = resde.data.map(obj => {
|
|
|
+ formData.productKey = row.productKey;
|
|
|
+ const newArray = (resde.data as any[]).map((obj: any) => {
|
|
|
const { name, value, ...rest } = obj;
|
|
|
const newObj = { name, value, ...rest };
|
|
|
- newObj[name] = value ? value : '';
|
|
|
+ newObj[name] = value ? value : "";
|
|
|
return newObj;
|
|
|
});
|
|
|
- Datalist.value = newArray
|
|
|
+ Datalist.value = newArray;
|
|
|
});
|
|
|
} else {
|
|
|
//获取档案属性
|
|
|
- api.dev_asset_metadata.detail({ productKey: productInfo.key }).then((res: any) => {
|
|
|
- const sortedArray = res.sort((a, b) => a.id - b.id);
|
|
|
+ api.dev_asset_metadata.detail({ productKey: productInfo.key }).then((res: any[]) => {
|
|
|
+ const sortedArray = res.sort((a: any, b: any) => a.id - b.id);
|
|
|
Datalist.value = sortedArray || [];
|
|
|
});
|
|
|
- formData.productKey = productInfo.key
|
|
|
-
|
|
|
+ formData.productKey = productInfo.key;
|
|
|
}
|
|
|
});
|
|
|
};
|
|
@@ -225,4 +223,4 @@ defineExpose({ open });
|
|
|
.demo-form-inline .el-input {
|
|
|
--el-input-width: 320px;
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|