From 233e4fc4f35bd00a36ee34a7fbf5e47b41db26db Mon Sep 17 00:00:00 2001
From: chenyao <1219716595@qq.com>
Date: Mon, 17 Nov 2025 09:54:44 +0800
Subject: [PATCH] feat:更新初始化地形
---
src/views/device/addDevice.vue | 342 ++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 255 insertions(+), 87 deletions(-)
diff --git a/src/views/device/addDevice.vue b/src/views/device/addDevice.vue
index f556b04..a8a95d0 100644
--- a/src/views/device/addDevice.vue
+++ b/src/views/device/addDevice.vue
@@ -24,6 +24,9 @@
getDetail,
} from '@/api/device/workspaces'
+import { getList as getSystemNames } from '@/api/system/sysConfig'
+import { getRegionTreeAll } from '@/api/job/task';
+
import { getLazyTree } from '@/api/base/region'
import { mapGetters } from 'vuex'
@@ -36,6 +39,8 @@
data () {
return {
+ xzqhData: [],
+ systemNamesList: [],
// 用于记录已经创建的websocket,防止重复创建
webSocketIdSet: new Set(),
// 用于保存多组websocket
@@ -60,20 +65,26 @@
},
selectionList: [],
option: {
+ addTitle: '设备注册',
menuWidth: 300,
lazy: true,
tree: true,
- // dialogWidth: 1050,
+ dialogWidth: 1050,
+ searchGutter: 30,
+ searchMenuPosition: 'left',
+ searchMenuSpan: 4,
tip: false,
searchShow: true,
- searchMenuSpan: 6,
border: true,
index: true,
+ indexLabel: '序号',
+ indexWidth: 60,
viewBtn: true,
selection: false,
excelBtn: false,
addBtn: true,
+ addBtnText: '设备注册',
dialogClickModal: false,
grid: false,
@@ -83,11 +94,11 @@
{
label: '设备名称',// '工作空间名称',
prop: 'workspace_name',
- editDisabled: true,
- searchLabelWidth: 130,
- search: true,
- // searchSpan: 4,
+ // editDisabled: true,
+ editDisplay: false,
labelWidth: 130,
+ search: true,
+ searchSpan: 4,
rules: [
{
required: true,
@@ -100,7 +111,11 @@
label: '系统名称',// '平台名称',
prop: 'platform_name',
labelWidth: 130,
- editDisabled: true,
+ width: 180,
+ // editDisabled: true,
+ editDisplay: false,
+ type: 'select',
+ dicData: this.systemNamesDicData,
rules: [
{
required: false,
@@ -110,29 +125,49 @@
],
},
{
- label: '所属单位',
+ label: '所属部门',
+ prop: 'dept_name',
+ addDisplay: false,
+ editDisplay: false,
+ viewDisplay: false,
+ labelWidth: 130,
+ width: 180,
+ rules: [
+ {
+ required: true,
+ message: '请输入所属部门',
+ trigger: 'blur',
+ },
+ ],
+ },
+ {
+ label: '所属部门',
prop: 'dept_id',
+ hide: true,
type: 'tree',
defaultExpandAll: true,
+ search: true,
+ searchSpan: 4,
labelWidth: 130,
dicUrl: '/blade-system/dept/getTree',
props: {
- label: 'name',
- value: 'id',
+ label: 'name',
+ value: 'id',
},
rules: [
- {
- required: true,
- message: '请输入所属单位',
- trigger: 'blur',
- },
+ {
+ required: true,
+ message: '请输入所属部门',
+ trigger: 'blur',
+ },
],
},
{
label: '绑定编号',
prop: 'bind_code',
labelWidth: 130,
- editDisabled: true,
+ // editDisabled: true,
+ editDisplay: false,
rules: [
{
required: false,
@@ -143,17 +178,18 @@
},
{
label: '设备类型',
+ editDisplay: false,
prop: 'type',
- type: 'radio',
labelWidth: 130,
value: 0,
+ type: 'select',
dicData: [
{
- label: '机场',
+ label: '机巢',
value: 0
},
{
- label: '遥控器',
+ label: '控制器',
value: 1
}
],
@@ -166,21 +202,44 @@
],
},
{
- label: '设备描述',// '工作空间描述',
- prop: 'workspace_desc',
+ label: '设备位置',// '行政区划',
+ prop: 'area_name',
+ // hide: true,
+ overHidden: true,
+ addDisplay: false, //新增显示
+ editDisplay: false, //编辑显示
+ viewDisplay: true, //查看显示
labelWidth: 130,
- // search: true,
- searchSpan: 4,
- // editDisabled: true,
- rules: [
- {
- required: true,
- message: '请输入设备描述',
- trigger: 'blur',
- },
- ],
+ width: 200,
},
-
+ {
+ label: '设备位置',
+ prop: 'area_code',
+ // type: 'cascader',
+ type: 'tree',
+ labelWidth: 130,
+ searchSpan: 4,
+ hide: true,
+ search: true,
+ // overHidden: true,
+ editDisplay: true,
+ viewDisplay: true,
+ checkStrictly: true,
+ defaultExpandAll: true,
+ dicData: [],
+ props: {
+ label: 'name',
+ value: 'id',
+ children: 'childrens',
+ },
+ rules: [
+ {
+ required: true,
+ message: '请选择设备位置',
+ trigger: 'change',
+ },
+ ],
+ },
{
label: '创建时间',
prop: 'create_time',
@@ -194,63 +253,44 @@
},
{
- label: '设备位置',// '行政区划',
- prop: 'area_code',
- type: 'cascader',
+ label: '设备描述', // '工作空间描述',
+ prop: 'workspace_desc',
+ type: 'textarea',
labelWidth: 130,
- hide: true,
- editDisplay: true,
- viewDisplay: false,
- props: {
- label: 'title',
- value: 'value',
- emitPath: false,
- checkStrictly: true,
- multiple: false,
- expandTrigger: 'hover',
- },
- dataType: 'string',
+ searchSpan: 4,
+ overHidden: true,
+ minRows: 3,
+ maxRows: 5,
+ maxlength: 250,
+ span: 24,
+ showWordLimit: true,
rules: [
- {
- required: true,
- message: '请选择设备位置',
- trigger: 'change',
- },
+ {
+ required: true,
+ message: '请输入设备描述不能超过250个字',
+ trigger: 'blur',
+ },
+ {
+ max: 250,
+ message: '设备描述不能超过250个字',
+ trigger: 'blur',
+ },
+ // 如果需要更严格的校验(如中文字符计算),可以使用 validator
+ {
+ validator: (rule, value, callback) => {
+ if (value && value.length > 250) {
+ callback(new Error('设备描述不能超过250个字'));
+ } else {
+ callback();
+ }
+ },
+ trigger: 'blur',
+ },
],
- lazy: true,
- lazyLoad (node, resolve) {
- let level = node.level
- let list = []
- let callback = () => {
- resolve(
- (list || []).map(ele => ({
- ...ele,
- value: ele.value,
- leaf: level >= 2,
- }))
- )
- }
-
- if (level === 0) {
- getLazyTree('000000000000').then(res => {
- list = res.data.data
- callback()
- })
- } else if (level === 1) {
- getLazyTree(node.value).then(res => {
- list = res.data.data
- callback()
- })
- } else if (level === 2) {
- getLazyTree(node.value).then(res => {
- list = res.data.data
- callback()
- })
- } else {
- callback()
- }
- },
},
+
+
+
],
},
@@ -275,6 +315,12 @@
})
return ids.join(',')
},
+ systemNamesDicData() {
+ return this.systemNamesList.map(item => ({
+ label: item.name,
+ value: item.id,
+ }));
+ },
},
destroyed () {
this.websocketMap.forEach((k, v) => {
@@ -285,7 +331,105 @@
}
})
},
+ async created() {
+ await this.getRegionTreeList();
+ await this.getSystemNamesList();
+ },
+ mounted() {
+ getRegionTreeAll({ parentCode: this.userInfo.detail.areaCode }).then(res => {
+ const column = this.findObject(this.option.column, 'area_code');
+ column.dicData = res.data.data ? [res.data.data] : [];
+ });
+ },
methods: {
+ async getRegionTreeList(code) {
+ try {
+ const res = await getRegionTreeAll({ parentCode: code });
+ return res.data.data; // 返回数据而不是赋值给 this.xzqhData
+ } catch (error) {
+ console.error('获取区域树数据失败:', error);
+ return null;
+ }
+ },
+ async getSystemNamesList() {
+ try {
+ const res = await getSystemNames(1, 99);
+ if (res?.data?.data?.records) {
+ this.systemNamesList = res.data.data.records;
+ // 找到平台名称列的索引
+ const columnIndex = this.option.column.findIndex(col => col.prop === 'platform_name');
+ if (columnIndex !== -1) {
+ // 直接更新 dicData
+ this.option.column[columnIndex].dicData = this.systemNamesList.map(item => ({
+ label: item.name,
+ value: item.id
+ }));
+ }
+ }
+ } catch (error) {
+ console.error('获取系统名称失败:', error);
+ this.systemNamesList = [];
+ }
+ },
+ // beforeOpen (type, row, index) {
+ // if (type === 'add') {
+ // this.form = {
+ // workspace_name: '',
+ // platform_name: '',
+ // dept_name: '',
+ // bind_code: '',
+ // type: 0,
+ // workspace_desc: '',
+ // area_name: '',
+ // area_code: '',
+ // }
+ // }
+ // },
+ async getXZQHList(area_code) {
+ try {
+ const res = await getLazyTree(area_code);
+ return res.data.data; // 返回数据,而不是直接修改 this.xzqhData
+ } catch (error) {
+ console.error('获取行政区划数据失败:', error);
+ return [];
+ }
+ },
+ findNodeById(tree, id) {
+ if (tree.id === id) {
+ return tree;
+ }
+ if (tree.childrens && tree.childrens.length > 0) {
+ for (const child of tree.childrens) {
+ const found = this.findNodeById(child, id);
+ if (found) return found;
+ }
+ }
+ return null;
+ },
+ async fetchAreaName(areaCode) {
+ if (!areaCode) return '/';
+ try {
+ const response = await this.getFullAreaCode(areaCode);
+ const codes = response.split(',');
+
+ // 获取区域树数据
+ const xzqhData = await this.getRegionTreeList(codes[0]);
+ if (!xzqhData) return '/';
+
+ const names = [];
+ for (const code of codes) {
+ const node = this.findNodeById(xzqhData, code);
+ if (node) {
+ names.push(node.name);
+ }
+ }
+
+ return names.join('');
+ } catch (error) {
+ console.error('获取区域名称失败:', error);
+ return '/';
+ }
+ },
copyInfo (row, index) {
const ipAddress = import.meta.env.VITE_APP_DEVICE_IP
@@ -433,12 +577,24 @@
}
},
beforeOpen (done, type) {
+ if (type === 'add') {
+ this.form = {
+ workspace_name: '',
+ platform_name: '',
+ dept_name: '',
+ bind_code: '',
+ type: 0,
+ workspace_desc: '',
+ area_name: '',
+ area_code: '',
+ }
+ }
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(async res => {
const data = res.data.data
this.form = {
...data,
- area_code: await this.getFullAreaCode(data.area_code),
+ // area_code: await this.getFullAreaCode(data.area_code),
}
})
}
@@ -454,6 +610,7 @@
this.onLoad(this.page, this.query)
},
onLoad (page, params = {}) {
+
const { releaseTimeRange } = this.query
let values = {
...params,
@@ -467,9 +624,14 @@
}
values.releaseTimeRange = null
}
+ console.log(values.area_code,this.query)
values['type'] = 1
+ if (values.area_code) {
+ values['area_code'] = values.area_code.split(',').pop()
+ }
+
this.loading = true
- getList(page.currentPage, page.pageSize, values).then(res => {
+ getList(page.currentPage, page.pageSize, values).then(async res => {
const data = res.data.data
this.page.total = data.total
// data.records.forEach(e => {
@@ -479,9 +641,15 @@
// }
// });
this.data = data.records
+ for (const row of this.data) {
+ if (row.area_code) {
+ row.area_name = await this.fetchAreaName(row.area_code);
+ }
+ }
this.loading = false
this.selectionClear()
})
+
},
treeLoad (tree, treeNode, resolve) {
var params = {
--
Gitblit v1.9.3