Commit 3e9ddc52 by 李伟康

fix(sdk): 修复地图SDK配置获取和脚本加载问题

- 移除环境对象变量,直接在请求URL中使用环境参数
- 为动态加载的脚本添加ignore属性以避免冲突
- 优化可选链操作符的使用方式以提高兼容性
- 更新版本号至0.1.6并重新构建dist文件
1 parent 383e1322
{ {
"name": "glsk-mapapi-sdk", "name": "glsk-mapapi-sdk",
"version": "0.1.4", "version": "0.1.6",
"type": "module", "type": "module",
"description": "glsk-mapapi-sdk", "description": "glsk-mapapi-sdk",
"main": "src/index.js", "main": "src/index.js",
......
const envObject = {
1: 'develop',
2: 'test',
3: 'production',
4: 'beta'
}
class GlMapSdk { class GlMapSdk {
constructor() { constructor() {
let mapConfig = { let mapConfig = {
...@@ -14,17 +8,18 @@ class GlMapSdk { ...@@ -14,17 +8,18 @@ class GlMapSdk {
if (arguments.length > 1) { if (arguments.length > 1) {
mapConfig = typeof arguments[0] == 'object' ? arguments[0] : mapConfig mapConfig = typeof arguments[0] == 'object' ? arguments[0] : mapConfig
_callBack = arguments[1] _callBack = arguments[1]
if (!mapConfig?.env) mapConfig.env = 3 if (!mapConfig.env) mapConfig.env = 3
if (!mapConfig?.version) mapConfig.version = 3 if (!mapConfig.version) mapConfig.version = 3
} }
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
const fetchConfig = async () => { const fetchConfig = async () => {
try { try {
const response = await fetch(`https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js&env=${envObject[mapConfig.env]}`); const response = await fetch(`https://config-center-backend.glsx.com.cn/glsxAdmin/config?moduleUrl=map-api-js`);
const res = await response.json(), const res = await response.json(),
scriptExists = Array.from(document.head.getElementsByTagName('script')).some(script => script.src === res.apiUrl); scriptExists = Array.from(document.head.getElementsByTagName('script')).some(script => script.src === res.apiUrl);
if (!scriptExists) { if (!scriptExists) {
const script = document.createElement('script'); const script = document.createElement('script');
script.setAttribute('ignore', '')
script.src = res.apiUrl; script.src = res.apiUrl;
document.head.appendChild(script) document.head.appendChild(script)
script.onload = () => { script.onload = () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!