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 @@ @@ -27,10 +27,16 @@ -
+ +
{{ count }} s后刷新 +
-
+
+ + +
+
告警列表 @@ -62,6 +68,7 @@ + @@ -69,18 +76,19 @@ - + +
@@ -137,9 +145,14 @@ components: { DeptSelect, SelectTree }, data() { return { + aMapManager, + type: 'cluster', // 加载数据方式:massMarkers或cluster + refreshType: 'clock', // 刷新数据方式:clock或websocket + showAlarm: false, // 是否显示报警 + showAll: true, // 是否显示全部井 listQuery: { keywords: '', // 关键字 - wellType: '', // 井类型 + wellType: '1', // 井类型 deptid: '', // 组织机构 isAlarm: '1' // 是否报警 }, // 筛选条件 @@ -174,19 +187,13 @@ count: 30, showWellType: this.showWellType(), // 是否显示井类型下拉 wellTypeList: [], // 井类型列表 - deptProps: { - parent: 'pid', - value: 'id', - label: 'name', - children: 'children' - }, // 权属单位树形下拉菜单 - deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示权属单位下拉,0不显示,1显示树,2显示平面 commonIcon: 'well-common-green', // 通用图标 绿 commonIconAlarm: 'well-common-red', // 通用图标 红 center: [this.$store.getters.lng, this.$store.getters.lat], // 地图中心 zoom: 12, // 地图缩放比例 markers: [], // 井列表标注marker + markerRefs: [], // markers对象列表 alarmList: [], // 报警列表 alarmWells: [], // 报警井列表 offset: [-10, -10], // 偏移量 @@ -215,18 +222,18 @@ deptShowTop: false, // 是否显示顶级 clock: null, // 计时器 hasAlarm: false, // 是否有报警, - showAll: false, // 是否显示全部井(包含报警和不报警,为false时只显示报警) firstAmount: true, // 是否第一次加载井数据 loading: true, // 加载图标是否显示 - aMapManager, massMarks: null, // 海量点 + mapMarkers: [], + clusters: [], showClearBtn: false // 是否显示清除查询按钮 } }, watch: { showAll(val) { if (val) { // 显示全部 - this.listQuery.isAlarm = '0' + // this.listQuery.isAlarm = '0' // 先清空查询条件 this.listQuery.deptid = '' this.listQuery.keywords = '' @@ -238,7 +245,7 @@ this.filterIcon() } } else { // 仅显示报警 - this.listQuery.isAlarm = '1' + // this.listQuery.isAlarm = '1' this.filterIcon() } } @@ -246,14 +253,19 @@ mounted() { var that = this that.fetchWellType() - setTimeout(function() { - that.getWellList() - that.refreshAlarm() - that.countDown() - }, 1000) + if (this.showAll) { + this.getWellList() + } + if (this.refreshType === 'clock') { + setTimeout(function() { + // that.getWellList() + that.refreshAlarm() + that.countDown() + }, 1000) + } }, methods: { - // 倒计时函数,暂时不用了 + // 倒计时函数 countDown() { this.clock = window.setInterval(() => { this.count-- @@ -306,7 +318,7 @@ const keywords = this.listQuery.keywords const deptid = this.listQuery.deptid const wellType = this.listQuery.wellType - const isAlarm = this.listQuery.isAlarm + // const isAlarm = this.listQuery.isAlarm console.log('markers length:', this.markers.length) let center = [] // 查询全部井,是否匹配 @@ -325,19 +337,19 @@ show = false } // 如果只显示报警,井的状态不是报警 - if (isAlarm === '1') { - const index = this.alarmWells.filter(item => { - if (item.wellCode === marker.wellCode) { - console.log('匹配') - } - return item.wellCode === marker.wellCode - }) - if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false - show = false - } else { - console.log('no hide:', marker.wellCode) - } - } + // if (isAlarm === '1') { + // const index = this.alarmWells.filter(item => { + // if (item.wellCode === marker.wellCode) { + // console.log('匹配') + // } + // return item.wellCode === marker.wellCode + // }) + // if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false + // show = false + // } else { + // console.log('no hide:', marker.wellCode) + // } + // } if (show === false) { hideWellIds.push(marker.wellId) } else { @@ -366,12 +378,15 @@ if (center.length > 0) { this.center = center } - this.resetMassMarker() + if (this.type === 'massMarkers') { + this.resetMassMarker() + } else if (this.type === 'cluster') { + this.clearClusters() + } }, // 加载海量点 mountMassMarker() { const map = aMapManager.getMap() - // 创建样式对象 const style = { url: './static/images/well/pin.svg', @@ -407,78 +422,169 @@ // 将海量点添加至地图实例 this.massMarks.setMap(map) }, + // 加载聚合点 + mountClusters() { + const self = this + // 聚合点数据应该是一组包含经纬度信息的数组。lnglat 为经纬度信息字段,weight 字段为可选数据,表示权重值,以权重高的点为中心进行聚合。 + var points = this.markers + const markers = [] + var icon = new AMap.Icon({ + size: new AMap.Size(20, 20), // 图标尺寸 + image: 'static/images/well/pin.svg', // Icon的图像 + imageSize: new AMap.Size(20, 20) // 根据所设置的大小拉伸或压缩图片 + }) + for (var i = 0; i < points.length; i += 1) { + markers.push(new AMap.Marker({ + position: points[i]['lnglat'], + icon: icon, // 添加 Icon 实例 + offset: new AMap.Pixel(-10, 0) + })) + } + // 添加聚合组件 + const map = aMapManager.getMap() + const cluster = new AMap.MarkerClusterer(map, markers, { + gridSize: 80, + renderCluserMarker: self._renderCluserMarker, + maxZoom: 16 }) + }, + // 清除聚合点 + clearClusters() { + + }, + _renderCluserMarker(context) { + console.log(context) + const count = this.markers.length + const factor = Math.pow(context.count / count, 1 / 18) + const div = document.createElement('div') + const Hue = 180 - factor * 180 + const bgColor = 'hsla(' + Hue + ',100%,50%,0.9)' + const fontColor = '#ffffff' + const borderColor = 'hsla(' + Hue + ',100%,40%,1)' + const shadowColor = 'hsla(' + Hue + ',100%,50%,1)' + div.style.backgroundColor = bgColor + const size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20) + div.style.width = div.style.height = size + 'px' + div.style.border = 'solid 1px ' + borderColor + div.style.borderRadius = size / 2 + 'px' + div.style.boxShadow = '0 0 1px ' + shadowColor + div.innerHTML = context.count + div.style.lineHeight = size + 'px' + div.style.color = fontColor + div.style.fontSize = '14px' + div.style.textAlign = 'center' + context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2)) + context.marker.setContent(div) + }, // 获取井列表 getWellList() { + // const self = this this.loading = true const listQuery = { keywords: '', // 关键字 - wellType: '', // 井类型 - deptid: '', // 组织机构 - isAlarm: this.listQuery.isAlarm + wellType: '1', // 井类型 + deptid: '' // 组织机构 + // isAlarm: this.listQuery.isAlarm } getWellList(listQuery).then(response => { this.loading = false if (response.code === 200) { const wells = response.data + this.firstAmount = false if (wells.length > 0) { - // 查询正在报警的井 - if (listQuery.isAlarm === '1') { - this.markers = [] - // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - id: well.id, - name: well.wellCode, - wellCode: well.wellCode, - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'alarm' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] - } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 - this.firstAmount = false - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - wellCode: well.wellCode, - id: well.id, - name: well.wellCode, - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'normal' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] + this.markers = [] + const centerxs = [] + const centerys = [] + for (const well of wells) { + this.markers.push({ + wellId: well.id, + wellCode: well.wellCode, + id: well.id, + name: well.wellCode, + lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + positionInfo: well.position, + wellType: well.wellType, + deptid: well.deptid, + bfzt: well.bfzt, + icon: this.commonIcon, + visible: true, + wellStatus: 'normal' + // events: { + // init(o) { + // console.log(self) + // self.markerRefs.push(o) + // } + // } + }) + centerxs.push(parseFloat(well.lngGaode)) + centerys.push(parseFloat(well.latGaode)) } - this.mountMassMarker() + centerxs.sort() + centerys.sort() + const index = Math.floor(centerxs.length / 2) + this.center = [centerxs[index], centerys[index]] + // 查询正在报警的井 + // if (listQuery.isAlarm === '1') { + // this.markers = [] + // // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // id: well.id, + // name: well.wellCode, + // wellCode: well.wellCode, + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'alarm' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 + // this.firstAmount = false + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // wellCode: well.wellCode, + // id: well.id, + // name: well.wellCode, + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'normal' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } + if (this.type === 'massMarkers') { + this.mountMassMarker() + } else if (this.type === 'cluster') { + this.mountClusters() + } } } }) @@ -509,8 +615,10 @@ refreshAlarm() { console.log('refreshAlarm') this.count = 60 + this.loading = true getAlarmsNow().then(response => { if (response.code === 200) { + this.loading = false // 获取当前报警列表 this.alarmList = response.data if (this.alarmList.length > 0) { 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 @@ @@ -27,10 +27,16 @@
-
+ +
{{ count }} s后刷新 +
-
+
+ + +
+
告警列表 @@ -62,6 +68,7 @@ + @@ -69,18 +76,19 @@ - + +
@@ -137,9 +145,14 @@ components: { DeptSelect, SelectTree }, data() { return { + aMapManager, + type: 'cluster', // 加载数据方式:massMarkers或cluster + refreshType: 'clock', // 刷新数据方式:clock或websocket + showAlarm: false, // 是否显示报警 + showAll: true, // 是否显示全部井 listQuery: { keywords: '', // 关键字 - wellType: '', // 井类型 + wellType: '1', // 井类型 deptid: '', // 组织机构 isAlarm: '1' // 是否报警 }, // 筛选条件 @@ -174,19 +187,13 @@ count: 30, showWellType: this.showWellType(), // 是否显示井类型下拉 wellTypeList: [], // 井类型列表 - deptProps: { - parent: 'pid', - value: 'id', - label: 'name', - children: 'children' - }, // 权属单位树形下拉菜单 - deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示权属单位下拉,0不显示,1显示树,2显示平面 commonIcon: 'well-common-green', // 通用图标 绿 commonIconAlarm: 'well-common-red', // 通用图标 红 center: [this.$store.getters.lng, this.$store.getters.lat], // 地图中心 zoom: 12, // 地图缩放比例 markers: [], // 井列表标注marker + markerRefs: [], // markers对象列表 alarmList: [], // 报警列表 alarmWells: [], // 报警井列表 offset: [-10, -10], // 偏移量 @@ -215,18 +222,18 @@ deptShowTop: false, // 是否显示顶级 clock: null, // 计时器 hasAlarm: false, // 是否有报警, - showAll: false, // 是否显示全部井(包含报警和不报警,为false时只显示报警) firstAmount: true, // 是否第一次加载井数据 loading: true, // 加载图标是否显示 - aMapManager, massMarks: null, // 海量点 + mapMarkers: [], + clusters: [], showClearBtn: false // 是否显示清除查询按钮 } }, watch: { showAll(val) { if (val) { // 显示全部 - this.listQuery.isAlarm = '0' + // this.listQuery.isAlarm = '0' // 先清空查询条件 this.listQuery.deptid = '' this.listQuery.keywords = '' @@ -238,7 +245,7 @@ this.filterIcon() } } else { // 仅显示报警 - this.listQuery.isAlarm = '1' + // this.listQuery.isAlarm = '1' this.filterIcon() } } @@ -246,14 +253,19 @@ mounted() { var that = this that.fetchWellType() - setTimeout(function() { - that.getWellList() - that.refreshAlarm() - that.countDown() - }, 1000) + if (this.showAll) { + this.getWellList() + } + if (this.refreshType === 'clock') { + setTimeout(function() { + // that.getWellList() + that.refreshAlarm() + that.countDown() + }, 1000) + } }, methods: { - // 倒计时函数,暂时不用了 + // 倒计时函数 countDown() { this.clock = window.setInterval(() => { this.count-- @@ -306,7 +318,7 @@ const keywords = this.listQuery.keywords const deptid = this.listQuery.deptid const wellType = this.listQuery.wellType - const isAlarm = this.listQuery.isAlarm + // const isAlarm = this.listQuery.isAlarm console.log('markers length:', this.markers.length) let center = [] // 查询全部井,是否匹配 @@ -325,19 +337,19 @@ show = false } // 如果只显示报警,井的状态不是报警 - if (isAlarm === '1') { - const index = this.alarmWells.filter(item => { - if (item.wellCode === marker.wellCode) { - console.log('匹配') - } - return item.wellCode === marker.wellCode - }) - if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false - show = false - } else { - console.log('no hide:', marker.wellCode) - } - } + // if (isAlarm === '1') { + // const index = this.alarmWells.filter(item => { + // if (item.wellCode === marker.wellCode) { + // console.log('匹配') + // } + // return item.wellCode === marker.wellCode + // }) + // if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false + // show = false + // } else { + // console.log('no hide:', marker.wellCode) + // } + // } if (show === false) { hideWellIds.push(marker.wellId) } else { @@ -366,12 +378,15 @@ if (center.length > 0) { this.center = center } - this.resetMassMarker() + if (this.type === 'massMarkers') { + this.resetMassMarker() + } else if (this.type === 'cluster') { + this.clearClusters() + } }, // 加载海量点 mountMassMarker() { const map = aMapManager.getMap() - // 创建样式对象 const style = { url: './static/images/well/pin.svg', @@ -407,78 +422,169 @@ // 将海量点添加至地图实例 this.massMarks.setMap(map) }, + // 加载聚合点 + mountClusters() { + const self = this + // 聚合点数据应该是一组包含经纬度信息的数组。lnglat 为经纬度信息字段,weight 字段为可选数据,表示权重值,以权重高的点为中心进行聚合。 + var points = this.markers + const markers = [] + var icon = new AMap.Icon({ + size: new AMap.Size(20, 20), // 图标尺寸 + image: 'static/images/well/pin.svg', // Icon的图像 + imageSize: new AMap.Size(20, 20) // 根据所设置的大小拉伸或压缩图片 + }) + for (var i = 0; i < points.length; i += 1) { + markers.push(new AMap.Marker({ + position: points[i]['lnglat'], + icon: icon, // 添加 Icon 实例 + offset: new AMap.Pixel(-10, 0) + })) + } + // 添加聚合组件 + const map = aMapManager.getMap() + const cluster = new AMap.MarkerClusterer(map, markers, { + gridSize: 80, + renderCluserMarker: self._renderCluserMarker, + maxZoom: 16 }) + }, + // 清除聚合点 + clearClusters() { + + }, + _renderCluserMarker(context) { + console.log(context) + const count = this.markers.length + const factor = Math.pow(context.count / count, 1 / 18) + const div = document.createElement('div') + const Hue = 180 - factor * 180 + const bgColor = 'hsla(' + Hue + ',100%,50%,0.9)' + const fontColor = '#ffffff' + const borderColor = 'hsla(' + Hue + ',100%,40%,1)' + const shadowColor = 'hsla(' + Hue + ',100%,50%,1)' + div.style.backgroundColor = bgColor + const size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20) + div.style.width = div.style.height = size + 'px' + div.style.border = 'solid 1px ' + borderColor + div.style.borderRadius = size / 2 + 'px' + div.style.boxShadow = '0 0 1px ' + shadowColor + div.innerHTML = context.count + div.style.lineHeight = size + 'px' + div.style.color = fontColor + div.style.fontSize = '14px' + div.style.textAlign = 'center' + context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2)) + context.marker.setContent(div) + }, // 获取井列表 getWellList() { + // const self = this this.loading = true const listQuery = { keywords: '', // 关键字 - wellType: '', // 井类型 - deptid: '', // 组织机构 - isAlarm: this.listQuery.isAlarm + wellType: '1', // 井类型 + deptid: '' // 组织机构 + // isAlarm: this.listQuery.isAlarm } getWellList(listQuery).then(response => { this.loading = false if (response.code === 200) { const wells = response.data + this.firstAmount = false if (wells.length > 0) { - // 查询正在报警的井 - if (listQuery.isAlarm === '1') { - this.markers = [] - // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - id: well.id, - name: well.wellCode, - wellCode: well.wellCode, - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'alarm' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] - } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 - this.firstAmount = false - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - wellCode: well.wellCode, - id: well.id, - name: well.wellCode, - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'normal' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] + this.markers = [] + const centerxs = [] + const centerys = [] + for (const well of wells) { + this.markers.push({ + wellId: well.id, + wellCode: well.wellCode, + id: well.id, + name: well.wellCode, + lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + positionInfo: well.position, + wellType: well.wellType, + deptid: well.deptid, + bfzt: well.bfzt, + icon: this.commonIcon, + visible: true, + wellStatus: 'normal' + // events: { + // init(o) { + // console.log(self) + // self.markerRefs.push(o) + // } + // } + }) + centerxs.push(parseFloat(well.lngGaode)) + centerys.push(parseFloat(well.latGaode)) } - this.mountMassMarker() + centerxs.sort() + centerys.sort() + const index = Math.floor(centerxs.length / 2) + this.center = [centerxs[index], centerys[index]] + // 查询正在报警的井 + // if (listQuery.isAlarm === '1') { + // this.markers = [] + // // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // id: well.id, + // name: well.wellCode, + // wellCode: well.wellCode, + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'alarm' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 + // this.firstAmount = false + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // wellCode: well.wellCode, + // id: well.id, + // name: well.wellCode, + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'normal' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } + if (this.type === 'massMarkers') { + this.mountMassMarker() + } else if (this.type === 'cluster') { + this.mountClusters() + } } } }) @@ -509,8 +615,10 @@ refreshAlarm() { console.log('refreshAlarm') this.count = 60 + this.loading = true getAlarmsNow().then(response => { if (response.code === 200) { + this.loading = false // 获取当前报警列表 this.alarmList = response.data if (this.alarmList.length > 0) { diff --git a/src/views/overview/overview_old.vue b/src/views/overview/overview_old.vue new file mode 100644 index 0000000..3137d98 --- /dev/null +++ b/src/views/overview/overview_old.vue @@ -0,0 +1,730 @@ + + + + + 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 @@ @@ -27,10 +27,16 @@
-
+ +
{{ count }} s后刷新 +
-
+
+ + +
+
告警列表 @@ -62,6 +68,7 @@ + @@ -69,18 +76,19 @@ - + +
@@ -137,9 +145,14 @@ components: { DeptSelect, SelectTree }, data() { return { + aMapManager, + type: 'cluster', // 加载数据方式:massMarkers或cluster + refreshType: 'clock', // 刷新数据方式:clock或websocket + showAlarm: false, // 是否显示报警 + showAll: true, // 是否显示全部井 listQuery: { keywords: '', // 关键字 - wellType: '', // 井类型 + wellType: '1', // 井类型 deptid: '', // 组织机构 isAlarm: '1' // 是否报警 }, // 筛选条件 @@ -174,19 +187,13 @@ count: 30, showWellType: this.showWellType(), // 是否显示井类型下拉 wellTypeList: [], // 井类型列表 - deptProps: { - parent: 'pid', - value: 'id', - label: 'name', - children: 'children' - }, // 权属单位树形下拉菜单 - deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示权属单位下拉,0不显示,1显示树,2显示平面 commonIcon: 'well-common-green', // 通用图标 绿 commonIconAlarm: 'well-common-red', // 通用图标 红 center: [this.$store.getters.lng, this.$store.getters.lat], // 地图中心 zoom: 12, // 地图缩放比例 markers: [], // 井列表标注marker + markerRefs: [], // markers对象列表 alarmList: [], // 报警列表 alarmWells: [], // 报警井列表 offset: [-10, -10], // 偏移量 @@ -215,18 +222,18 @@ deptShowTop: false, // 是否显示顶级 clock: null, // 计时器 hasAlarm: false, // 是否有报警, - showAll: false, // 是否显示全部井(包含报警和不报警,为false时只显示报警) firstAmount: true, // 是否第一次加载井数据 loading: true, // 加载图标是否显示 - aMapManager, massMarks: null, // 海量点 + mapMarkers: [], + clusters: [], showClearBtn: false // 是否显示清除查询按钮 } }, watch: { showAll(val) { if (val) { // 显示全部 - this.listQuery.isAlarm = '0' + // this.listQuery.isAlarm = '0' // 先清空查询条件 this.listQuery.deptid = '' this.listQuery.keywords = '' @@ -238,7 +245,7 @@ this.filterIcon() } } else { // 仅显示报警 - this.listQuery.isAlarm = '1' + // this.listQuery.isAlarm = '1' this.filterIcon() } } @@ -246,14 +253,19 @@ mounted() { var that = this that.fetchWellType() - setTimeout(function() { - that.getWellList() - that.refreshAlarm() - that.countDown() - }, 1000) + if (this.showAll) { + this.getWellList() + } + if (this.refreshType === 'clock') { + setTimeout(function() { + // that.getWellList() + that.refreshAlarm() + that.countDown() + }, 1000) + } }, methods: { - // 倒计时函数,暂时不用了 + // 倒计时函数 countDown() { this.clock = window.setInterval(() => { this.count-- @@ -306,7 +318,7 @@ const keywords = this.listQuery.keywords const deptid = this.listQuery.deptid const wellType = this.listQuery.wellType - const isAlarm = this.listQuery.isAlarm + // const isAlarm = this.listQuery.isAlarm console.log('markers length:', this.markers.length) let center = [] // 查询全部井,是否匹配 @@ -325,19 +337,19 @@ show = false } // 如果只显示报警,井的状态不是报警 - if (isAlarm === '1') { - const index = this.alarmWells.filter(item => { - if (item.wellCode === marker.wellCode) { - console.log('匹配') - } - return item.wellCode === marker.wellCode - }) - if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false - show = false - } else { - console.log('no hide:', marker.wellCode) - } - } + // if (isAlarm === '1') { + // const index = this.alarmWells.filter(item => { + // if (item.wellCode === marker.wellCode) { + // console.log('匹配') + // } + // return item.wellCode === marker.wellCode + // }) + // if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false + // show = false + // } else { + // console.log('no hide:', marker.wellCode) + // } + // } if (show === false) { hideWellIds.push(marker.wellId) } else { @@ -366,12 +378,15 @@ if (center.length > 0) { this.center = center } - this.resetMassMarker() + if (this.type === 'massMarkers') { + this.resetMassMarker() + } else if (this.type === 'cluster') { + this.clearClusters() + } }, // 加载海量点 mountMassMarker() { const map = aMapManager.getMap() - // 创建样式对象 const style = { url: './static/images/well/pin.svg', @@ -407,78 +422,169 @@ // 将海量点添加至地图实例 this.massMarks.setMap(map) }, + // 加载聚合点 + mountClusters() { + const self = this + // 聚合点数据应该是一组包含经纬度信息的数组。lnglat 为经纬度信息字段,weight 字段为可选数据,表示权重值,以权重高的点为中心进行聚合。 + var points = this.markers + const markers = [] + var icon = new AMap.Icon({ + size: new AMap.Size(20, 20), // 图标尺寸 + image: 'static/images/well/pin.svg', // Icon的图像 + imageSize: new AMap.Size(20, 20) // 根据所设置的大小拉伸或压缩图片 + }) + for (var i = 0; i < points.length; i += 1) { + markers.push(new AMap.Marker({ + position: points[i]['lnglat'], + icon: icon, // 添加 Icon 实例 + offset: new AMap.Pixel(-10, 0) + })) + } + // 添加聚合组件 + const map = aMapManager.getMap() + const cluster = new AMap.MarkerClusterer(map, markers, { + gridSize: 80, + renderCluserMarker: self._renderCluserMarker, + maxZoom: 16 }) + }, + // 清除聚合点 + clearClusters() { + + }, + _renderCluserMarker(context) { + console.log(context) + const count = this.markers.length + const factor = Math.pow(context.count / count, 1 / 18) + const div = document.createElement('div') + const Hue = 180 - factor * 180 + const bgColor = 'hsla(' + Hue + ',100%,50%,0.9)' + const fontColor = '#ffffff' + const borderColor = 'hsla(' + Hue + ',100%,40%,1)' + const shadowColor = 'hsla(' + Hue + ',100%,50%,1)' + div.style.backgroundColor = bgColor + const size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20) + div.style.width = div.style.height = size + 'px' + div.style.border = 'solid 1px ' + borderColor + div.style.borderRadius = size / 2 + 'px' + div.style.boxShadow = '0 0 1px ' + shadowColor + div.innerHTML = context.count + div.style.lineHeight = size + 'px' + div.style.color = fontColor + div.style.fontSize = '14px' + div.style.textAlign = 'center' + context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2)) + context.marker.setContent(div) + }, // 获取井列表 getWellList() { + // const self = this this.loading = true const listQuery = { keywords: '', // 关键字 - wellType: '', // 井类型 - deptid: '', // 组织机构 - isAlarm: this.listQuery.isAlarm + wellType: '1', // 井类型 + deptid: '' // 组织机构 + // isAlarm: this.listQuery.isAlarm } getWellList(listQuery).then(response => { this.loading = false if (response.code === 200) { const wells = response.data + this.firstAmount = false if (wells.length > 0) { - // 查询正在报警的井 - if (listQuery.isAlarm === '1') { - this.markers = [] - // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - id: well.id, - name: well.wellCode, - wellCode: well.wellCode, - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'alarm' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] - } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 - this.firstAmount = false - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - wellCode: well.wellCode, - id: well.id, - name: well.wellCode, - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'normal' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] + this.markers = [] + const centerxs = [] + const centerys = [] + for (const well of wells) { + this.markers.push({ + wellId: well.id, + wellCode: well.wellCode, + id: well.id, + name: well.wellCode, + lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + positionInfo: well.position, + wellType: well.wellType, + deptid: well.deptid, + bfzt: well.bfzt, + icon: this.commonIcon, + visible: true, + wellStatus: 'normal' + // events: { + // init(o) { + // console.log(self) + // self.markerRefs.push(o) + // } + // } + }) + centerxs.push(parseFloat(well.lngGaode)) + centerys.push(parseFloat(well.latGaode)) } - this.mountMassMarker() + centerxs.sort() + centerys.sort() + const index = Math.floor(centerxs.length / 2) + this.center = [centerxs[index], centerys[index]] + // 查询正在报警的井 + // if (listQuery.isAlarm === '1') { + // this.markers = [] + // // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // id: well.id, + // name: well.wellCode, + // wellCode: well.wellCode, + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'alarm' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 + // this.firstAmount = false + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // wellCode: well.wellCode, + // id: well.id, + // name: well.wellCode, + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'normal' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } + if (this.type === 'massMarkers') { + this.mountMassMarker() + } else if (this.type === 'cluster') { + this.mountClusters() + } } } }) @@ -509,8 +615,10 @@ refreshAlarm() { console.log('refreshAlarm') this.count = 60 + this.loading = true getAlarmsNow().then(response => { if (response.code === 200) { + this.loading = false // 获取当前报警列表 this.alarmList = response.data if (this.alarmList.length > 0) { diff --git a/src/views/overview/overview_old.vue b/src/views/overview/overview_old.vue new file mode 100644 index 0000000..3137d98 --- /dev/null +++ b/src/views/overview/overview_old.vue @@ -0,0 +1,730 @@ + + + + + diff --git a/src/views/systemConfig/responsibleUser/listResponsibleUser.vue b/src/views/systemConfig/responsibleUser/listResponsibleUser.vue index 7cc4654..15cc4de 100644 --- a/src/views/systemConfig/responsibleUser/listResponsibleUser.vue +++ b/src/views/systemConfig/responsibleUser/listResponsibleUser.vue @@ -111,6 +111,7 @@ getDeptList(this.listQuery).then(response => { this.list = toTreeList(response.data.list, '0', false) this.list = this.list[0].children + // this.list = response.data.list this.listLoading = 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/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 @@ @@ -27,10 +27,16 @@
-
+ +
{{ count }} s后刷新 +
-
+
+ + +
+
告警列表 @@ -62,6 +68,7 @@ + @@ -69,18 +76,19 @@ - + +
@@ -137,9 +145,14 @@ components: { DeptSelect, SelectTree }, data() { return { + aMapManager, + type: 'cluster', // 加载数据方式:massMarkers或cluster + refreshType: 'clock', // 刷新数据方式:clock或websocket + showAlarm: false, // 是否显示报警 + showAll: true, // 是否显示全部井 listQuery: { keywords: '', // 关键字 - wellType: '', // 井类型 + wellType: '1', // 井类型 deptid: '', // 组织机构 isAlarm: '1' // 是否报警 }, // 筛选条件 @@ -174,19 +187,13 @@ count: 30, showWellType: this.showWellType(), // 是否显示井类型下拉 wellTypeList: [], // 井类型列表 - deptProps: { - parent: 'pid', - value: 'id', - label: 'name', - children: 'children' - }, // 权属单位树形下拉菜单 - deptTreeList: null, // 组织树列表数据 showDeptTree: 0, // 是否显示权属单位下拉,0不显示,1显示树,2显示平面 commonIcon: 'well-common-green', // 通用图标 绿 commonIconAlarm: 'well-common-red', // 通用图标 红 center: [this.$store.getters.lng, this.$store.getters.lat], // 地图中心 zoom: 12, // 地图缩放比例 markers: [], // 井列表标注marker + markerRefs: [], // markers对象列表 alarmList: [], // 报警列表 alarmWells: [], // 报警井列表 offset: [-10, -10], // 偏移量 @@ -215,18 +222,18 @@ deptShowTop: false, // 是否显示顶级 clock: null, // 计时器 hasAlarm: false, // 是否有报警, - showAll: false, // 是否显示全部井(包含报警和不报警,为false时只显示报警) firstAmount: true, // 是否第一次加载井数据 loading: true, // 加载图标是否显示 - aMapManager, massMarks: null, // 海量点 + mapMarkers: [], + clusters: [], showClearBtn: false // 是否显示清除查询按钮 } }, watch: { showAll(val) { if (val) { // 显示全部 - this.listQuery.isAlarm = '0' + // this.listQuery.isAlarm = '0' // 先清空查询条件 this.listQuery.deptid = '' this.listQuery.keywords = '' @@ -238,7 +245,7 @@ this.filterIcon() } } else { // 仅显示报警 - this.listQuery.isAlarm = '1' + // this.listQuery.isAlarm = '1' this.filterIcon() } } @@ -246,14 +253,19 @@ mounted() { var that = this that.fetchWellType() - setTimeout(function() { - that.getWellList() - that.refreshAlarm() - that.countDown() - }, 1000) + if (this.showAll) { + this.getWellList() + } + if (this.refreshType === 'clock') { + setTimeout(function() { + // that.getWellList() + that.refreshAlarm() + that.countDown() + }, 1000) + } }, methods: { - // 倒计时函数,暂时不用了 + // 倒计时函数 countDown() { this.clock = window.setInterval(() => { this.count-- @@ -306,7 +318,7 @@ const keywords = this.listQuery.keywords const deptid = this.listQuery.deptid const wellType = this.listQuery.wellType - const isAlarm = this.listQuery.isAlarm + // const isAlarm = this.listQuery.isAlarm console.log('markers length:', this.markers.length) let center = [] // 查询全部井,是否匹配 @@ -325,19 +337,19 @@ show = false } // 如果只显示报警,井的状态不是报警 - if (isAlarm === '1') { - const index = this.alarmWells.filter(item => { - if (item.wellCode === marker.wellCode) { - console.log('匹配') - } - return item.wellCode === marker.wellCode - }) - if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false - show = false - } else { - console.log('no hide:', marker.wellCode) - } - } + // if (isAlarm === '1') { + // const index = this.alarmWells.filter(item => { + // if (item.wellCode === marker.wellCode) { + // console.log('匹配') + // } + // return item.wellCode === marker.wellCode + // }) + // if (index.length === 0) { // 如果不在alarmWells中,即index=-1,表示没有匹配成功,show=false + // show = false + // } else { + // console.log('no hide:', marker.wellCode) + // } + // } if (show === false) { hideWellIds.push(marker.wellId) } else { @@ -366,12 +378,15 @@ if (center.length > 0) { this.center = center } - this.resetMassMarker() + if (this.type === 'massMarkers') { + this.resetMassMarker() + } else if (this.type === 'cluster') { + this.clearClusters() + } }, // 加载海量点 mountMassMarker() { const map = aMapManager.getMap() - // 创建样式对象 const style = { url: './static/images/well/pin.svg', @@ -407,78 +422,169 @@ // 将海量点添加至地图实例 this.massMarks.setMap(map) }, + // 加载聚合点 + mountClusters() { + const self = this + // 聚合点数据应该是一组包含经纬度信息的数组。lnglat 为经纬度信息字段,weight 字段为可选数据,表示权重值,以权重高的点为中心进行聚合。 + var points = this.markers + const markers = [] + var icon = new AMap.Icon({ + size: new AMap.Size(20, 20), // 图标尺寸 + image: 'static/images/well/pin.svg', // Icon的图像 + imageSize: new AMap.Size(20, 20) // 根据所设置的大小拉伸或压缩图片 + }) + for (var i = 0; i < points.length; i += 1) { + markers.push(new AMap.Marker({ + position: points[i]['lnglat'], + icon: icon, // 添加 Icon 实例 + offset: new AMap.Pixel(-10, 0) + })) + } + // 添加聚合组件 + const map = aMapManager.getMap() + const cluster = new AMap.MarkerClusterer(map, markers, { + gridSize: 80, + renderCluserMarker: self._renderCluserMarker, + maxZoom: 16 }) + }, + // 清除聚合点 + clearClusters() { + + }, + _renderCluserMarker(context) { + console.log(context) + const count = this.markers.length + const factor = Math.pow(context.count / count, 1 / 18) + const div = document.createElement('div') + const Hue = 180 - factor * 180 + const bgColor = 'hsla(' + Hue + ',100%,50%,0.9)' + const fontColor = '#ffffff' + const borderColor = 'hsla(' + Hue + ',100%,40%,1)' + const shadowColor = 'hsla(' + Hue + ',100%,50%,1)' + div.style.backgroundColor = bgColor + const size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20) + div.style.width = div.style.height = size + 'px' + div.style.border = 'solid 1px ' + borderColor + div.style.borderRadius = size / 2 + 'px' + div.style.boxShadow = '0 0 1px ' + shadowColor + div.innerHTML = context.count + div.style.lineHeight = size + 'px' + div.style.color = fontColor + div.style.fontSize = '14px' + div.style.textAlign = 'center' + context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2)) + context.marker.setContent(div) + }, // 获取井列表 getWellList() { + // const self = this this.loading = true const listQuery = { keywords: '', // 关键字 - wellType: '', // 井类型 - deptid: '', // 组织机构 - isAlarm: this.listQuery.isAlarm + wellType: '1', // 井类型 + deptid: '' // 组织机构 + // isAlarm: this.listQuery.isAlarm } getWellList(listQuery).then(response => { this.loading = false if (response.code === 200) { const wells = response.data + this.firstAmount = false if (wells.length > 0) { - // 查询正在报警的井 - if (listQuery.isAlarm === '1') { - this.markers = [] - // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - id: well.id, - name: well.wellCode, - wellCode: well.wellCode, - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'alarm' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] - } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 - this.firstAmount = false - const centerxs = [] - const centerys = [] - for (const well of wells) { - this.markers.push({ - wellId: well.id, - wellCode: well.wellCode, - id: well.id, - name: well.wellCode, - lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], - positionInfo: well.position, - wellType: well.wellType, - deptid: well.deptid, - bfzt: well.bfzt, - icon: this.commonIcon, - visible: true, - wellStatus: 'normal' - }) - centerxs.push(parseFloat(well.lngGaode)) - centerys.push(parseFloat(well.latGaode)) - } - centerxs.sort() - centerys.sort() - const index = Math.floor(centerxs.length / 2) - this.center = [centerxs[index], centerys[index]] + this.markers = [] + const centerxs = [] + const centerys = [] + for (const well of wells) { + this.markers.push({ + wellId: well.id, + wellCode: well.wellCode, + id: well.id, + name: well.wellCode, + lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + positionInfo: well.position, + wellType: well.wellType, + deptid: well.deptid, + bfzt: well.bfzt, + icon: this.commonIcon, + visible: true, + wellStatus: 'normal' + // events: { + // init(o) { + // console.log(self) + // self.markerRefs.push(o) + // } + // } + }) + centerxs.push(parseFloat(well.lngGaode)) + centerys.push(parseFloat(well.latGaode)) } - this.mountMassMarker() + centerxs.sort() + centerys.sort() + const index = Math.floor(centerxs.length / 2) + this.center = [centerxs[index], centerys[index]] + // 查询正在报警的井 + // if (listQuery.isAlarm === '1') { + // this.markers = [] + // // centerxs和centerys用于获取所有坐标,目的是排序找到中位数 + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // id: well.id, + // name: well.wellCode, + // wellCode: well.wellCode, + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'alarm' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } else if (listQuery.isAlarm === '0') { // 查询状态正常的井 + // this.firstAmount = false + // const centerxs = [] + // const centerys = [] + // for (const well of wells) { + // this.markers.push({ + // wellId: well.id, + // wellCode: well.wellCode, + // id: well.id, + // name: well.wellCode, + // lnglat: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // position: [parseFloat(well.lngGaode), parseFloat(well.latGaode)], + // positionInfo: well.position, + // wellType: well.wellType, + // deptid: well.deptid, + // bfzt: well.bfzt, + // icon: this.commonIcon, + // visible: true, + // wellStatus: 'normal' + // }) + // centerxs.push(parseFloat(well.lngGaode)) + // centerys.push(parseFloat(well.latGaode)) + // } + // centerxs.sort() + // centerys.sort() + // const index = Math.floor(centerxs.length / 2) + // this.center = [centerxs[index], centerys[index]] + // } + if (this.type === 'massMarkers') { + this.mountMassMarker() + } else if (this.type === 'cluster') { + this.mountClusters() + } } } }) @@ -509,8 +615,10 @@ refreshAlarm() { console.log('refreshAlarm') this.count = 60 + this.loading = true getAlarmsNow().then(response => { if (response.code === 200) { + this.loading = false // 获取当前报警列表 this.alarmList = response.data if (this.alarmList.length > 0) { diff --git a/src/views/overview/overview_old.vue b/src/views/overview/overview_old.vue new file mode 100644 index 0000000..3137d98 --- /dev/null +++ b/src/views/overview/overview_old.vue @@ -0,0 +1,730 @@ + + + + + diff --git a/src/views/systemConfig/responsibleUser/listResponsibleUser.vue b/src/views/systemConfig/responsibleUser/listResponsibleUser.vue index 7cc4654..15cc4de 100644 --- a/src/views/systemConfig/responsibleUser/listResponsibleUser.vue +++ b/src/views/systemConfig/responsibleUser/listResponsibleUser.vue @@ -111,6 +111,7 @@ getDeptList(this.listQuery).then(response => { this.list = toTreeList(response.data.list, '0', false) this.list = this.list[0].children + // this.list = response.data.list this.listLoading = false }) }, diff --git a/static/images/well/cluster_yellow.png b/static/images/well/cluster_yellow.png new file mode 100644 index 0000000..b999cbc --- /dev/null +++ b/static/images/well/cluster_yellow.png Binary files differ