Browse Source

修改代码缺陷

zhoutao 1 week ago
parent
commit
3edb338987

+ 69 - 41
ipsomcadmin/src/views/bparam/btstopology.vue

@@ -141,6 +141,7 @@ export default {
     mounted() {
         this.$nextTick(function () {
             const rootDiv = document.querySelector('.btstopology');
+            console.log("初始化的容器大小", rootDiv.offsetWidth, rootDiv.offsetHeight)
             if (rootDiv) {
                 this.mainData.pageWidth = rootDiv.offsetWidth
                 this.mainData.pageHeight = rootDiv.offsetHeight
@@ -226,7 +227,14 @@ export default {
             }
         },
         hGetDataBaseParam() {
-            this.getBtsBaseParamList()
+            this.$nextTick(function () {
+                const rootDiv = document.querySelector('.btstopology');
+                if (rootDiv) {
+                    this.mainData.pageWidth = rootDiv.offsetWidth
+                    this.mainData.pageHeight = rootDiv.offsetHeight
+                }
+                this.getBtsBaseParamList()
+            })
         },
         openAddBaseParamDlg() {
             this.dialogData.editData.isUpdate = false
@@ -237,9 +245,20 @@ export default {
             this.dialogData.editData.show = false
         },
         hGetBaseParam() {
-            this.getBtsBaseParamList()
+            this.$nextTick(function () {
+                const rootDiv = document.querySelector('.btstopology');
+                if (rootDiv) {
+                    this.mainData.pageWidth = rootDiv.offsetWidth
+                    this.mainData.pageHeight = rootDiv.offsetHeight
+                }
+                this.getBtsBaseParamList()
+            })
         },
         getBtsBaseParamList() {//获得基站基本参数数据
+            //重置比例尺
+            this.mainData.coordScaleX = 15;
+            this.mainData.coordScaleY = 15;
+
             let search = {}
             let itemId = 0
 
@@ -262,16 +281,20 @@ export default {
             //查询数据
             this.tableData.listData.loading = true
             getBtsBaseParamList(param).then((res) => {
-                this.tableData.listData.items = res.data
+                this.tableData.listData.items = res.data || []
                 this.tableData.listData.loading = false
-
-                resultData = this.findMinCoordValue(this.tableData.listData.items);
-
-                //重新设置画布大小
-                this.reSetCanvasSize(resultData.gap)
-
-                //画基站散点图
-                this.drawScatterChart(this.tableData.listData.items, resultData.offset)
+                if (this.tableData.listData.items.length > 0) {
+                    resultData = this.findMinCoordValue(this.tableData.listData.items);
+                    //重新设置画布大小
+                    this.reSetCanvasSize(resultData.gap)
+                    //画基站散点图
+                    this.drawScatterChart(this.tableData.listData.items, resultData.offset)
+                } else {
+                    // 清空画布
+                    const canvas = this.$refs.scatterChart
+                    const ctx = canvas.getContext('2d')
+                    ctx.clearRect(0, 0, canvas.width, canvas.height)
+                }
             }).catch(() => {
                 this.tableData.listData.loading = false
             })
@@ -281,54 +304,59 @@ export default {
             let minX = Infinity, maxX = -Infinity
             let minY = Infinity, maxY = -Infinity
 
-            //找出基站坐标的最大最小值
+            // 找出基站坐标的最大最小值
             dataList.forEach(point => {
                 minX = Math.min(minX, point.coord_x)
                 maxX = Math.max(maxX, point.coord_x)
                 minY = Math.min(minY, point.coord_y)
                 maxY = Math.max(maxY, point.coord_y)
             })
-            if (minX > 0) {//修正坐标
-                minX = 0
-            }
-            if (maxX < 0) {//修正坐标
-                maxX = 0
-            }
-            if (minY > 0) {//修正坐标
-                minY = 0
-            }
-            if (maxY < 0) {//修正坐标
-                maxY = 0
-            }
-            this.mainData.btsMaxY = maxY//保存基站最大Y坐标值
 
-            // 偏移量计算,将负坐标上移或者右移
+            // 修正坐标边界
+            minX = minX > 0 ? 0 : minX
+            maxX = maxX < 0 ? 0 : maxX
+            minY = minY > 0 ? 0 : minY
+            maxY = maxY < 0 ? 0 : maxY
+
+            this.mainData.btsMaxY = maxY
+
+            // 局部比例尺变量
+            let coordScaleX = this.mainData.coordScaleX
+            let coordScaleY = this.mainData.coordScaleY
+
+            // 正确计算Y方向偏移量(与X方向逻辑一致)
             let offset = {
-                xOffset: minX < 0 ? (-minX / this.mainData.coordScaleX + 50) : 50,
-                //yOffset: minY < 0 ? (-minY / this.mainData.coordScaleY + 50) : 50
-                yOffset: 50
+                xOffset: minX < 0 ? (-minX / coordScaleX + 50) : 50,
+                yOffset: minY < 0 ? (-minY / coordScaleY + 50) : 50
             }
-            this.mainData.offset = offset//保存偏移值
 
-            // 计算画布在X轴和Y轴的间隔
+            // 计算画布间隔
             let gap = {
-                gapX: ((maxX - minX) / (this.mainData.coordScaleX)) + 2 * offset.xOffset,
-                gapY: ((maxY - minY) / (this.mainData.coordScaleY)) + 2 * offset.yOffset
+                gapX: ((maxX - minX) / coordScaleX) + 2 * offset.xOffset,
+                gapY: ((maxY - minY) / coordScaleY) + 2 * offset.yOffset
             }
 
-            console.log("画布长宽", gap.gapX, gap.gapY)
-
+            // 仅当X方向间隔小于400时才调整X比例尺
             if (gap.gapX < 400) {
-                this.mainData.coordScaleX = 3
-                offset.xOffset = minX < 0 ? (-minX / this.mainData.coordScaleX + 50) : 50
-                gap.gapX = ((maxX - minX) / (this.mainData.coordScaleX)) + 2 * offset.xOffset
+                coordScaleX = 3
+                // 重新计算X偏移
+                offset.xOffset = minX < 0 ? (-minX / coordScaleX + 50) : 50
+                gap.gapX = ((maxX - minX) / coordScaleX) + 2 * offset.xOffset
             }
 
-            if (gap.minY < 200) {
-                this.mainData.coordScaleX = 3
-                gap.gapY = ((maxY - minY) / (this.mainData.coordScaleY)) + 2 * offset.yOffset
+            // 仅当Y方向间隔小于400时才调整Y比例尺
+            if (gap.gapY < 400) {
+                coordScaleY = 3
+                // 重新计算Y偏移
+                offset.yOffset = minY < 0 ? (-minY / coordScaleY + 50) : 50
+                gap.gapY = ((maxY - minY) / coordScaleY) + 2 * offset.yOffset
             }
 
+            // 更新主数据比例尺
+            this.mainData.coordScaleX = coordScaleX
+            this.mainData.coordScaleY = coordScaleY
+            this.mainData.offset = offset
+
             return { offset, gap }
         }
     }

+ 4 - 22
ipsomcadmin/src/views/bparam/component/baseparamdlg.vue

@@ -61,8 +61,8 @@
         <div style="padding-top: 10px;text-align:right">
             <el-button type="success" @click="hSubmit">确定</el-button>
             <el-button type="warning" @click="hClose">取消</el-button>
-            <el-button type="primary" @click="hEnableBts">全部启用</el-button>
-            <el-button type="danger" @click="hDisableBts">全部停用</el-button>
+            <el-button type="primary" @click="hSubmit">全部启用</el-button>
+            <el-button type="danger" @click="hClose">全部停用</el-button>
         </div>
     </div>
 </template>
@@ -212,32 +212,14 @@ export default {
                 this.$message({ message: err, type: 'error' })
             })
         },
-        async hEnableBts() {
-            const res = await this.$confirm("确定要全部启用吗", "提示", { type: "warning" }).catch(err => err)
-            if (res != 'confirm') {
-                return
-            }
-            this.enableBtsBaseParam(1)
-        },
-        async hDisableBts() {
-            const res = await this.$confirm("确定要全部停用吗", "提示", { type: "warning" }).catch(err => err)
-            if (res != 'confirm') {
-                return
-            }
-            this.enableBtsBaseParam(0)
-        },
-        enableBtsBaseParam(enable_flag) {
-
-
-
+        hEnableBtsBaseParam() {
             let paramData = {}
             paramData.id = parseInt(this.dialogData.editData.data.id)
             paramData.bts_type = parseInt(this.dialogData.editData.data.bts_type);
-            paramData.enable_flag = parseInt(enable_flag)
 
             //修改基站基本参数
             enableBtsBaseParam(paramData).then(() => {
-                this.$message.success('修改成功', '提示')
+                this.$message.success('起作用或者基站', '提示')
                 this.getData()
                 this.hClose()
             }).catch((err) => {