Commit a06c5fbc303b8116cc3121726bbaadb9667d3f2e
1 parent
c7b8da2a
投放点地图 key 轮换
Showing
3 changed files
with
95 additions
and
6 deletions
trash-ui/src/plugins/cache.js
0 → 100644
| 1 | +const sessionCache = { | ||
| 2 | + set (key, value) { | ||
| 3 | + if (!sessionStorage) { | ||
| 4 | + return | ||
| 5 | + } | ||
| 6 | + if (key != null && value != null) { | ||
| 7 | + sessionStorage.setItem(key, value) | ||
| 8 | + } | ||
| 9 | + }, | ||
| 10 | + get (key) { | ||
| 11 | + if (!sessionStorage) { | ||
| 12 | + return null | ||
| 13 | + } | ||
| 14 | + if (key == null) { | ||
| 15 | + return null | ||
| 16 | + } | ||
| 17 | + return sessionStorage.getItem(key) | ||
| 18 | + }, | ||
| 19 | + setJSON (key, jsonValue) { | ||
| 20 | + if (jsonValue != null) { | ||
| 21 | + this.set(key, JSON.stringify(jsonValue)) | ||
| 22 | + } | ||
| 23 | + }, | ||
| 24 | + getJSON (key) { | ||
| 25 | + const value = this.get(key) | ||
| 26 | + if (value != null) { | ||
| 27 | + return JSON.parse(value) | ||
| 28 | + } | ||
| 29 | + }, | ||
| 30 | + remove (key) { | ||
| 31 | + sessionStorage.removeItem(key); | ||
| 32 | + } | ||
| 33 | +} | ||
| 34 | +const localCache = { | ||
| 35 | + set (key, value) { | ||
| 36 | + if (!localStorage) { | ||
| 37 | + return | ||
| 38 | + } | ||
| 39 | + if (key != null && value != null) { | ||
| 40 | + localStorage.setItem(key, value) | ||
| 41 | + } | ||
| 42 | + }, | ||
| 43 | + get (key) { | ||
| 44 | + if (!localStorage) { | ||
| 45 | + return null | ||
| 46 | + } | ||
| 47 | + if (key == null) { | ||
| 48 | + return null | ||
| 49 | + } | ||
| 50 | + return localStorage.getItem(key) | ||
| 51 | + }, | ||
| 52 | + setJSON (key, jsonValue) { | ||
| 53 | + if (jsonValue != null) { | ||
| 54 | + this.set(key, JSON.stringify(jsonValue)) | ||
| 55 | + } | ||
| 56 | + }, | ||
| 57 | + getJSON (key) { | ||
| 58 | + const value = this.get(key) | ||
| 59 | + if (value != null) { | ||
| 60 | + return JSON.parse(value) | ||
| 61 | + } | ||
| 62 | + }, | ||
| 63 | + remove (key) { | ||
| 64 | + localStorage.removeItem(key); | ||
| 65 | + } | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +export default { | ||
| 69 | + /** | ||
| 70 | + * 会话级缓存 | ||
| 71 | + */ | ||
| 72 | + session: sessionCache, | ||
| 73 | + /** | ||
| 74 | + * 本地缓存 | ||
| 75 | + */ | ||
| 76 | + local: localCache | ||
| 77 | +} |
trash-ui/src/plugins/index.js
trash-ui/src/views/unit/dropPointInfo/index.vue
| @@ -336,10 +336,6 @@ import {getAreaList,getAreasList} from "@/api/dict" | @@ -336,10 +336,6 @@ import {getAreaList,getAreasList} from "@/api/dict" | ||
| 336 | import AMapLoader from "@amap/amap-jsapi-loader"; | 336 | import AMapLoader from "@amap/amap-jsapi-loader"; |
| 337 | import Treeselect from "@riophae/vue-treeselect"; | 337 | import Treeselect from "@riophae/vue-treeselect"; |
| 338 | 338 | ||
| 339 | -// 设置安全密钥 | ||
| 340 | -window._AMapSecurityConfig = { | ||
| 341 | - securityJsCode: 'c82d0bf9ef42c220d3295a712cdd18b8', | ||
| 342 | -} | ||
| 343 | 339 | ||
| 344 | export default { | 340 | export default { |
| 345 | name: "DropPointInfo", | 341 | name: "DropPointInfo", |
| @@ -449,10 +445,18 @@ export default { | @@ -449,10 +445,18 @@ export default { | ||
| 449 | circleMarker: null, | 445 | circleMarker: null, |
| 450 | endTime: null, | 446 | endTime: null, |
| 451 | dropTime: true, | 447 | dropTime: true, |
| 452 | - infoDisable: false | 448 | + infoDisable: false, |
| 449 | + mapKeys:["3865c516a0e83ce0ca5cec3f2087675c","9439896287541d826bbaf6404063c9c2","0a4662cc567d13bdbebf71fa3dc036cc"], | ||
| 450 | + jsCode: ["c82d0bf9ef42c220d3295a712cdd18b8","70c91935d43cc5b7b5f95f1b295ae1d1","e7867b1dbe76542fb23e320b6086506f"], | ||
| 451 | + keyIndex: 0 | ||
| 453 | }; | 452 | }; |
| 454 | }, | 453 | }, |
| 455 | created() { | 454 | created() { |
| 455 | + this.keyIndex = this.$cache.session.get("keyIndex") || 0; | ||
| 456 | + console.log("keyIndex",this.keyIndex) | ||
| 457 | + window._AMapSecurityConfig = { | ||
| 458 | + securityJsCode: this.jsCode[this.keyIndex] | ||
| 459 | + } | ||
| 456 | getAreasList().then(response => { | 460 | getAreasList().then(response => { |
| 457 | if(response==null || response.length===0){ | 461 | if(response==null || response.length===0){ |
| 458 | this.$message.error("获取区域列表失败"); | 462 | this.$message.error("获取区域列表失败"); |
| @@ -543,7 +547,7 @@ export default { | @@ -543,7 +547,7 @@ export default { | ||
| 543 | const _this = this | 547 | const _this = this |
| 544 | // 加载高德地图 | 548 | // 加载高德地图 |
| 545 | AMapLoader.load({ | 549 | AMapLoader.load({ |
| 546 | - key: _this.$aMapKey, //设置高德地图申请的key | 550 | + key: _this.mapKeys[_this.keyIndex], //设置高德地图申请的key |
| 547 | version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15 | 551 | version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15 |
| 548 | plugins: ['AMap.ToolBar','AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Marker','AMap.CircleMarker'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等 | 552 | plugins: ['AMap.ToolBar','AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Marker','AMap.CircleMarker'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等 |
| 549 | AMapUI: { | 553 | AMapUI: { |
| @@ -658,6 +662,11 @@ export default { | @@ -658,6 +662,11 @@ export default { | ||
| 658 | setTimeout(() => { | 662 | setTimeout(() => { |
| 659 | this.loading = false; | 663 | this.loading = false; |
| 660 | this.AutoComplete.search(query, (status, result) => { | 664 | this.AutoComplete.search(query, (status, result) => { |
| 665 | + if(result==="USER_DAILY_QUERY_OVER_LIMIT"){ | ||
| 666 | + this.$message.error("当前 key["+this.mapKeys[this.keyIndex]+"] 今日查询次数上限,请刷新页面!"); | ||
| 667 | + this.keyIndex = (this.keyIndex+1) % this.mapKeys.length; | ||
| 668 | + this.$cache.session.set("keyIndex", this.keyIndex); | ||
| 669 | + } | ||
| 661 | this.mapOptions = result.tips; | 670 | this.mapOptions = result.tips; |
| 662 | }); | 671 | }); |
| 663 | }, 200); | 672 | }, 200); |