3131
3232<script >
3333import jx3boxData from " @jx3box/jx3box-common/data/jx3box.json" ;
34- import mapScales from " ../data/map_scales.json " ;
34+ import { getMapScales } from " ../service/data " ;
3535
3636export default {
3737 name: " Jx3boxMap" ,
3838 props: {
39+ // 地图ID
3940 mapId: {
4041 type: Number ,
4142 default: 1 ,
4243 },
44+ // 点位数据
4345 datas: {
4446 type: Array ,
4547 default : () => [],
@@ -52,13 +54,20 @@ export default {
5254 type: Number ,
5355 default: undefined ,
5456 },
57+ hiddenBoarder: {
58+ type: Boolean ,
59+ default: false ,
60+ },
61+ draggable: {
62+ type: Boolean ,
63+ default: true ,
64+ },
5565 },
56- data () {
57- return {
58- outerWidth: 0 ,
59- outerHeight: 0 ,
60- };
61- },
66+ data : () => ({
67+ outerWidth: 0 ,
68+ outerHeight: 0 ,
69+ mapScales: {},
70+ }),
6271 computed: {
6372 // 内层容器宽高
6473 innerWidth () {
@@ -120,7 +129,7 @@ export default {
120129 },
121130 // 地图ID、名称、尺寸、图片等
122131 subId () {
123- let scales = mapScales[this .mapId ];
132+ let scales = this . mapScales [this .mapId ];
124133 if (! scales || Object .keys (scales) <= 1 ) return 0 ;
125134 let _sub = 0 ;
126135 let _subScale = 0 ;
@@ -139,16 +148,19 @@ export default {
139148 return _sub;
140149 },
141150 mapName () {
142- return mapScales[this .mapId ][this .subId ].Name ;
151+ return this . mapScales [this .mapId ]? . [this .subId ]? .Name ;
143152 },
144153 mapScale () {
145- return mapScales[this .mapId ][this .subId ];
154+ return this . mapScales [this .mapId ]? . [this .subId ];
146155 },
147156 mapImg () {
148157 return ` ${ jx3boxData .__imgPath } map/maps/map_${ this .mapId } _${ this .subId } .png` ;
149158 },
150159 },
151160 mounted () {
161+ getMapScales ().then ((data ) => {
162+ this .mapScales = data;
163+ });
152164 this .$nextTick (function () {
153165 this .updateSize ();
154166 window .addEventListener (" resize" , this .updateSize );
@@ -160,6 +172,7 @@ export default {
160172 methods: {
161173 pointPosition (item ) {
162174 const scale = this .mapScale ;
175+ if (! scale) return { left: 0 , bottom: 0 };
163176 const Width = scale .Width / scale .Scale ;
164177 const Height = scale .Height / scale .Scale ;
165178 const left = ((item .x - scale .StartX ) / Width) * this .innerWidth ;
0 commit comments