diff --git a/src/main.js b/src/main.js
index 91f9c7d..f1c60a8 100644
--- a/src/main.js
+++ b/src/main.js
@@ -43,8 +43,8 @@
Vue.use(VueAMap)
VueAMap.initAMapApiLoader({
key: 'b6c27a2051691fcb386543c800356e05', // key
- plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'Geolocation'], // 插件
- uiVersion: '1.0.11', // ui组件库版本号
+ plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'MarkerClusterer'], // 插件
+ // uiVersion: '1.1', // ui组件库版本号
v: '1.4.4' // sdk版本
})
Vue.config.productionTip = false
diff --git a/src/main.js b/src/main.js
index 91f9c7d..f1c60a8 100644
--- a/src/main.js
+++ b/src/main.js
@@ -43,8 +43,8 @@
Vue.use(VueAMap)
VueAMap.initAMapApiLoader({
key: 'b6c27a2051691fcb386543c800356e05', // key
- plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'Geolocation'], // 插件
- uiVersion: '1.0.11', // ui组件库版本号
+ plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'MarkerClusterer'], // 插件
+ // uiVersion: '1.1', // ui组件库版本号
v: '1.4.4' // sdk版本
})
Vue.config.productionTip = false
diff --git a/src/utils/structure.js b/src/utils/structure.js
index b325ab0..34a6672 100644
--- a/src/utils/structure.js
+++ b/src/utils/structure.js
@@ -1,53 +1,135 @@
-import store from '../store'
+// 数据结构转换工具
+
/**
- * 判断是否有权限
+ * 判断是否有转树的必要
+ * @param plainList 平行数据列表
+ * @param id 祖宗id
+ * @returns {boolean} 有返回true,无返回false
*/
-export function hasPermission(permission) {
- const btns = store.getters.btns
- return btns.some(btn => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return btn.url === permission
- })
-}
-// 根据用户权限判断是否要显示井类型下拉框
-export function showWellType() {
- console.log('是否显示井类型下拉')
- const wellTypes = store.getters.wellTypes
- if (wellTypes.length > 1) return true
- else return false
+export function judgeTree(plainList, id = '0') {
+ if (plainList && plainList.length > 0) {
+ let flag = false // 是否需要转成树结构
+ const pid = plainList[0].pid
+ for (const item of plainList) {
+ if (item.pid !== pid) {
+ flag = true
+ break
+ }
+ }
+ return flag
+ } else { return false }
}
-// 根据用户权限判断是否要显示设备类型下拉框
-export function showDeviceType() {
- const deviceTypes = store.getters.deviceTypes
- if (deviceTypes.length > 1) return true
- else return false
+/**
+ * 平面数据数据转树结构
+ * @param plainList 平行数据列表
+ * @param id 祖宗id
+ * @param isSelect 是否是下拉需要顶级的树
+ * @returns {*}
+ */
+export function toTreeList(plainList, id = '0', isSelect = false) {
+ const pid = findPid(plainList)
+ if (pid.length > 1) {
+ return plainList
+ } else {
+ const tree = cleanChildren(buildTree(plainList, pid[0], isSelect))
+ return tree
+ }
}
-// 根据用户权限判断是否要显示IP配置项,集中器不显示ip
-export function showIpConfig() {
- const communications = store.getters.communications
- return communications.some(communication => { // 遍历通讯方式,只要没有1(集中器)就是返回true
- return communication !== '1'
- })
+// 构建树
+function buildTree(plainList, id = '0', isSelect) {
+ // 递归函数
+ const fa = (parentId) => {
+ const temp = []
+ for (let i = 0; i < plainList.length; i++) {
+ const n = plainList[i]
+ const id = '' + n.id
+ const pid = '' + n.pid
+ if (pid === parentId) {
+ n.children = fa(id)
+ temp.push(n)
+ }
+ }
+ return temp
+ }
+ // 如果是下拉框需要使用的树,首先寻找顶级,将顶级也放入列表
+ if (isSelect) {
+ let flag = 1
+ const list = []
+ for (const n of plainList) {
+ const nid = '' + n.id
+ if (nid === id) {
+ n.children = fa(id)
+ flag = 0
+ list.push(n)
+ return list
+ }
+ } if (flag === 1) { // 没有找到父级,按原流程走
+ return fa(id)
+ }
+ } else {
+ return fa(id)
+ }
}
-export function notContainConcentrator() {
- const communications = store.getters.communications
- return communications.some(communication => { // 遍历通讯方式,只要有1(集中器)就是返回true
- return communication === '1'
- })
+
+// 清除空 children项
+function cleanChildren(data) {
+ const fa = (list) => {
+ list.map((e) => {
+ if (e && e.children && e.children.length) {
+ fa(e.children)
+ } else {
+ delete e.children
+ }
+ return e
+ })
+ return list
+ }
+ return fa(data)
}
-// 判断用户是否为运维人员或其他管理员
-export function isOperation() {
- const roleTips = store.getters.roleTips
- console.log(roleTips)
- return roleTips.some(tip => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return (tip === 'operation' || tip === 'administrator')
- })
+
+function findPid(plainList) {
+ const pidList = new Set()
+ for (const item of plainList) {
+ pidList.add(item.pid)
+ }
+ for (const item of plainList) {
+ if (pidList.has(item.id)) {
+ pidList.delete(item.id)
+ }
+ }
+ var arr = [...pidList]
+ return arr
}
-// 判断是不是超级管理员
-export function isAdministrator() {
- const roleTips = store.getters.roleTips
- console.log(roleTips)
- return roleTips.some(tip => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return (tip === 'administrator')
- })
+
+// 平面数据数据转树结构
+export function getShowItem(plainList, id = '0') {
+ const expandList = []
+ const openedList = []
+ for (let i = 0; i < plainList.length; i++) {
+ if (plainList[i].open === 'true' || plainList[i].open === true) {
+ expandList.push(plainList[i].id)
+ }
+ if (plainList[i].checked === 'true' || plainList[i].checked === true) {
+ openedList.push(plainList[i].id)
+ }
+ }
+ return [expandList, openedList]
+}
+
+// 从树列表中删除指定元素
+export function deleteItem(list, des) {
+ const del = (list, item) => {
+ for (const i in list) {
+ if (list[i].id === des.id) {
+ list.splice(i, 1)
+ return
+ } else {
+ if (list[i].children && list[i].children.length > 0) {
+ del(list[i].children, des)
+ }
+ }
+ }
+ }
+ del(list, des)
}
diff --git a/src/main.js b/src/main.js
index 91f9c7d..f1c60a8 100644
--- a/src/main.js
+++ b/src/main.js
@@ -43,8 +43,8 @@
Vue.use(VueAMap)
VueAMap.initAMapApiLoader({
key: 'b6c27a2051691fcb386543c800356e05', // key
- plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'Geolocation'], // 插件
- uiVersion: '1.0.11', // ui组件库版本号
+ plugin: ['Autocomplete', 'PlaceSearch', 'Scale', 'OverView', 'ToolBar', 'MapType', 'PolyEditor', 'AMap.CircleEditor', 'MarkerClusterer'], // 插件
+ // uiVersion: '1.1', // ui组件库版本号
v: '1.4.4' // sdk版本
})
Vue.config.productionTip = false
diff --git a/src/utils/structure.js b/src/utils/structure.js
index b325ab0..34a6672 100644
--- a/src/utils/structure.js
+++ b/src/utils/structure.js
@@ -1,53 +1,135 @@
-import store from '../store'
+// 数据结构转换工具
+
/**
- * 判断是否有权限
+ * 判断是否有转树的必要
+ * @param plainList 平行数据列表
+ * @param id 祖宗id
+ * @returns {boolean} 有返回true,无返回false
*/
-export function hasPermission(permission) {
- const btns = store.getters.btns
- return btns.some(btn => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return btn.url === permission
- })
-}
-// 根据用户权限判断是否要显示井类型下拉框
-export function showWellType() {
- console.log('是否显示井类型下拉')
- const wellTypes = store.getters.wellTypes
- if (wellTypes.length > 1) return true
- else return false
+export function judgeTree(plainList, id = '0') {
+ if (plainList && plainList.length > 0) {
+ let flag = false // 是否需要转成树结构
+ const pid = plainList[0].pid
+ for (const item of plainList) {
+ if (item.pid !== pid) {
+ flag = true
+ break
+ }
+ }
+ return flag
+ } else { return false }
}
-// 根据用户权限判断是否要显示设备类型下拉框
-export function showDeviceType() {
- const deviceTypes = store.getters.deviceTypes
- if (deviceTypes.length > 1) return true
- else return false
+/**
+ * 平面数据数据转树结构
+ * @param plainList 平行数据列表
+ * @param id 祖宗id
+ * @param isSelect 是否是下拉需要顶级的树
+ * @returns {*}
+ */
+export function toTreeList(plainList, id = '0', isSelect = false) {
+ const pid = findPid(plainList)
+ if (pid.length > 1) {
+ return plainList
+ } else {
+ const tree = cleanChildren(buildTree(plainList, pid[0], isSelect))
+ return tree
+ }
}
-// 根据用户权限判断是否要显示IP配置项,集中器不显示ip
-export function showIpConfig() {
- const communications = store.getters.communications
- return communications.some(communication => { // 遍历通讯方式,只要没有1(集中器)就是返回true
- return communication !== '1'
- })
+// 构建树
+function buildTree(plainList, id = '0', isSelect) {
+ // 递归函数
+ const fa = (parentId) => {
+ const temp = []
+ for (let i = 0; i < plainList.length; i++) {
+ const n = plainList[i]
+ const id = '' + n.id
+ const pid = '' + n.pid
+ if (pid === parentId) {
+ n.children = fa(id)
+ temp.push(n)
+ }
+ }
+ return temp
+ }
+ // 如果是下拉框需要使用的树,首先寻找顶级,将顶级也放入列表
+ if (isSelect) {
+ let flag = 1
+ const list = []
+ for (const n of plainList) {
+ const nid = '' + n.id
+ if (nid === id) {
+ n.children = fa(id)
+ flag = 0
+ list.push(n)
+ return list
+ }
+ } if (flag === 1) { // 没有找到父级,按原流程走
+ return fa(id)
+ }
+ } else {
+ return fa(id)
+ }
}
-export function notContainConcentrator() {
- const communications = store.getters.communications
- return communications.some(communication => { // 遍历通讯方式,只要有1(集中器)就是返回true
- return communication === '1'
- })
+
+// 清除空 children项
+function cleanChildren(data) {
+ const fa = (list) => {
+ list.map((e) => {
+ if (e && e.children && e.children.length) {
+ fa(e.children)
+ } else {
+ delete e.children
+ }
+ return e
+ })
+ return list
+ }
+ return fa(data)
}
-// 判断用户是否为运维人员或其他管理员
-export function isOperation() {
- const roleTips = store.getters.roleTips
- console.log(roleTips)
- return roleTips.some(tip => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return (tip === 'operation' || tip === 'administrator')
- })
+
+function findPid(plainList) {
+ const pidList = new Set()
+ for (const item of plainList) {
+ pidList.add(item.pid)
+ }
+ for (const item of plainList) {
+ if (pidList.has(item.id)) {
+ pidList.delete(item.id)
+ }
+ }
+ var arr = [...pidList]
+ return arr
}
-// 判断是不是超级管理员
-export function isAdministrator() {
- const roleTips = store.getters.roleTips
- console.log(roleTips)
- return roleTips.some(tip => { // 遍历btns,查找btn.url是否有匹配的permission,有则返回true,否则返回false
- return (tip === 'administrator')
- })
+
+// 平面数据数据转树结构
+export function getShowItem(plainList, id = '0') {
+ const expandList = []
+ const openedList = []
+ for (let i = 0; i < plainList.length; i++) {
+ if (plainList[i].open === 'true' || plainList[i].open === true) {
+ expandList.push(plainList[i].id)
+ }
+ if (plainList[i].checked === 'true' || plainList[i].checked === true) {
+ openedList.push(plainList[i].id)
+ }
+ }
+ return [expandList, openedList]
+}
+
+// 从树列表中删除指定元素
+export function deleteItem(list, des) {
+ const del = (list, item) => {
+ for (const i in list) {
+ if (list[i].id === des.id) {
+ list.splice(i, 1)
+ return
+ } else {
+ if (list[i].children && list[i].children.length > 0) {
+ del(list[i].children, des)
+ }
+ }
+ }
+ }
+ del(list, des)
}
diff --git a/src/views/overview/overview.vue b/src/views/overview/overview.vue
index 88921aa..e6b7993 100644
--- a/src/views/overview/overview.vue
+++ b/src/views/overview/overview.vue
@@ -11,7 +11,7 @@