diff --git a/.env.development b/.env.development index 594a0a0..cf41b70 100644 --- a/.env.development +++ b/.env.development @@ -7,4 +7,5 @@ VUE_APP_API_ROOT = /tduck-api VUE_APP_CDN = OFF # 调试工具,可设置 eruda 或 vconsole,如果不需要开启则留空 VUE_APP_DEBUG_TOOL = - +# 高德地图key +VUE_APP_MAP_KEY = f2200337d0d08538e78729572749882d diff --git a/.env.production b/.env.production index 0585e48..3741072 100644 --- a/.env.production +++ b/.env.production @@ -7,3 +7,5 @@ VUE_APP_API_ROOT = /tduck-api VUE_APP_CDN = OFF # 调试工具,可设置 eruda 或 vconsole,如果不需要开启则留空 VUE_APP_DEBUG_TOOL = +# 高德地图key +VUE_APP_MAP_KEY = f2200337d0d08538e78729572749882d diff --git a/src/components/form/InputMap/amap.js b/src/components/form/InputMap/amap.js new file mode 100644 index 0000000..c6deb53 --- /dev/null +++ b/src/components/form/InputMap/amap.js @@ -0,0 +1,26 @@ +let amapKey = process.env.VUE_APP_MAP_KEY +let amapVersion = '2.0' +let _createScript = url => { + let jsapi = document.createElement('script') + jsapi.charset = 'utf-8' + jsapi.src = url + document.head.appendChild(jsapi) +} + +export default () => { + return new Promise((resolve, reject) => { + if (!window.AMap) { // 判断window下有没有AMap对象,再判断是否引入cdn地图 + _createScript(`https://webapi.amap.com/maps?v=${amapVersion}&key=${amapKey}.Key&callback=aMapInitCallback`) + window.aMapInitCallback = () => { + _createScript('//webapi.amap.com/ui/1.1/main.js&callback=amapUiCallback') + // 创建定时器 当AMapUI有值的时候 清除定时器 并resolve + let interval = setInterval(() => { + if (window.AMapUI) { + clearInterval(interval) + resolve(window.AMap) + } + }, 50) + } + } else resolve(window.AMap) + }) +} diff --git a/src/components/form/InputMap/index.vue b/src/components/form/InputMap/index.vue new file mode 100644 index 0000000..8c037f0 --- /dev/null +++ b/src/components/form/InputMap/index.vue @@ -0,0 +1,35 @@ + + + diff --git a/src/components/form/InputMap/index1.vue b/src/components/form/InputMap/index1.vue new file mode 100644 index 0000000..35d140d --- /dev/null +++ b/src/components/form/InputMap/index1.vue @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/router/modules/root.js b/src/router/modules/root.js index 88c635b..80ad859 100644 --- a/src/router/modules/root.js +++ b/src/router/modules/root.js @@ -100,7 +100,7 @@ export default [ // { // path: 'form', // meta: {requireLogin: true}, - // component: () => import(/* webpackChunkName: 'root' */ '@/views/form/index.vue') + // component: () => import(/* webpackChunkName: 'root' */ '@/views/form/index1.vue') // } ] }, { diff --git a/src/views/test.vue b/src/views/test.vue index 221aba6..248d3f4 100644 --- a/src/views/test.vue +++ b/src/views/test.vue @@ -3,6 +3,7 @@ + @@ -10,12 +11,15 @@ import SignPad from '../components/form/SignPad' import pagination from '../components/form/pagination' import ProvinceCity from '@/components/form/ProvinceCity' + +import InputMap from '@/components/form/InputMap' export default { name: 'App', components: { ProvinceCity, SignPad, - pagination + pagination, + InputMap }, data() { return {