Browse Source

- 增加 引入高德地图api

feat
JinxChen 2 years ago
parent
commit
b2ba317a10
4 changed files with 99 additions and 32 deletions
  1. +31
    -31
      .eslintrc.js
  2. +49
    -0
      src/config/map/index.js
  3. +13
    -0
      src/config/map/models.js
  4. +6
    -1
      vue.config.js

+ 31
- 31
.eslintrc.js View File

@@ -1,33 +1,33 @@
/*
* @Date: 2022-01-19 10:08:26
* @LastEditors: JinxChen
* @LastEditTime: 2022-01-19 10:29:11
* @FilePath: \alipay-scan-code-front-end\.eslintrc.js
* @description:
*/
module.exports = {
root: true,
env: {
node: true,
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint",
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "off" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "off" : "off",
"prettier/prettier": "off", //关闭 prettier 验证
},
overrides: [
{
files: [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)",
],
env: {
jest: true,
},
root: true,
env: {
node: true,
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint",
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
//关闭prettier
"prettier/prettier": "off",
// 关闭eslint语法检测
"no-unused-vars":0,
},
],
};
globals: {
"AMap": "true",
"AMapUI": "true",
},
overrides: [
{
files: [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)",
],
env: {
jest: true,
},
},
],
};

+ 49
- 0
src/config/map/index.js View File

@@ -0,0 +1,49 @@
/*
* @Date: 2022-01-14 09:15:21
* @LastEditors: JinxChen
* @LastEditTime: 2022-05-10 10:24:06
* @FilePath: \AntpayFrontEnd\src\config\map\index.js
* @description:
*/
import { AMapKey, AMapJsCode } from './models';

/**
* @param isSync 异步加载
* @param plugins 字符串数组格式 [ 'AMap.Geocoder', ... ]
* @returns {Promise}
* @constructor
*/
export default function MapLoader(isSync = false, plugins = []) {
return new Promise((resolve, reject) => {
try {
if (window.AMap && (plugins === null || plugins === undefined || plugins.length === 0)) {
resolve(window.AMap)
} else {
let script = document.createElement('script');
script.type = 'text/javascript';
script.async = !isSync;
script.src = `https://webapi.amap.com/maps?v=1.4.15&callback=initAMap&key=${AMapKey}&plugin=AMap.BezierCurveEditor${plugins ? ',' + plugins.join(',') : ''}`;
script.onerror = reject;
document.head.appendChild(script);

let script1 = document.createElement('script');
script1.type = 'text/javascript';
script1.async = false;
script1.src = 'https://webapi.amap.com/ui/1.0/main.js?v=1.0.11';
script1.onerror = reject;
if (isSync) {
document.head.appendChild(script1);
}
}
window.initAMap = () => resolve(window.AMap);

// JSAPI key搭配静态安全密钥以明文设置, 详情见: https://lbs.amap.com/api/jsapi-v2/guide/abc/load
window._AMapSecurityConfig = {
securityJsCode: `${AMapJsCode}`,
}
} catch (e) {
console.log(e);
}

})
}

+ 13
- 0
src/config/map/models.js View File

@@ -0,0 +1,13 @@
/*
* @Date: 2021-04-12 16:29:30
* @LastEditors: JinxChen
* @LastEditTime: 2022-05-09 14:16:46
* @FilePath: \AntpayFrontEnd\src\config\map\models.js
* @description:
*/
// 高德key
export const AMapKey = /* 'f7bc7e76645d2e84aa6bc62fdc5498a0' */ '6e4a6c39ea6d18b8dd3151baa3a7c0d5';


//高德jscode
export const AMapJsCode = '6a421e1233cd12dd4899e373e11bb641';

+ 6
- 1
vue.config.js View File

@@ -1,7 +1,7 @@
/*
* @Author: your name
* @Date: 2020-04-15 10:00:32
* @LastEditTime: 2022-04-08 15:01:09
* @LastEditTime: 2022-05-10 09:59:17
* @LastEditors: JinxChen
* @Description: In User Settings Edit
* @FilePath: \AntpayFrontEnd\vue.config.js
@@ -41,6 +41,11 @@ module.exports = {
// Enable CSS modules for all css / pre-processor files. // This option does not affect *.vue files.
requireModuleExtension: true
},
configureWebpack: {
externals: {
'AMap': 'AMap'
}
},
chainWebpack: config => {
// 该配置用来配置打包生成的文件是否带hash值后缀,该值默认为true,
// 在模式为production的时候,打包出的js和css文件会自动添加hash值后缀。


Loading…
Cancel
Save