Commit add200cd authored by 郭铭瑶's avatar 郭铭瑶 🤘

添加token获取方式

parent 51ea3341
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="/lz-string.min.js"></script>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
</body> </body>
......
...@@ -20,8 +20,10 @@ ...@@ -20,8 +20,10 @@
"esri-loader": "^3.2.0", "esri-loader": "^3.2.0",
"exceljs": "^4.3.0", "exceljs": "^4.3.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"lz-string": "^1.4.4",
"md5": "^2.3.0", "md5": "^2.3.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"parse-domain": "^4.1.0",
"qs": "^6.10.1", "qs": "^6.10.1",
"vite-plugin-svgicon": "^1.0.0", "vite-plugin-svgicon": "^1.0.0",
"vue": "^3.2.6", "vue": "^3.2.6",
...@@ -4092,6 +4094,14 @@ ...@@ -4092,6 +4094,14 @@
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=" "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
}, },
"node_modules/ip-regex": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz",
"integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q==",
"engines": {
"node": ">=8"
}
},
"node_modules/is-arrayish": { "node_modules/is-arrayish": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
...@@ -4218,6 +4228,17 @@ ...@@ -4218,6 +4228,17 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/is-ip": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/is-ip/-/is-ip-3.1.0.tgz",
"integrity": "sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==",
"dependencies": {
"ip-regex": "^4.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/is-negative-zero": { "node_modules/is-negative-zero": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz",
...@@ -4790,6 +4811,14 @@ ...@@ -4790,6 +4811,14 @@
"yallist": "^3.0.2" "yallist": "^3.0.2"
} }
}, },
"node_modules/lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY=",
"bin": {
"lz-string": "bin/bin.js"
}
},
"node_modules/magic-string": { "node_modules/magic-string": {
"version": "0.25.7", "version": "0.25.7",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
...@@ -4992,6 +5021,14 @@ ...@@ -4992,6 +5021,14 @@
"node": ">= 0.4.0" "node": ">= 0.4.0"
} }
}, },
"node_modules/node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA==",
"engines": {
"node": "4.x || >=6.0.0"
}
},
"node_modules/node-releases": { "node_modules/node-releases": {
"version": "1.1.75", "version": "1.1.75",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.75.tgz", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.75.tgz",
...@@ -5249,6 +5286,19 @@ ...@@ -5249,6 +5286,19 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/parse-domain": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/parse-domain/-/parse-domain-4.1.0.tgz",
"integrity": "sha512-zas79foMEsbMbIcJoPx26+NISWa3jTzZykOW9mXfRzvgadHvAHGd7qcCc1FbSWbD1I4qP71UWAxlTgu7Uq6IQg==",
"dependencies": {
"is-ip": "^3.1.0",
"node-fetch": "^2.6.1",
"punycode": "^2.1.1"
},
"bin": {
"parse-domain-update": "bin/update.js"
}
},
"node_modules/parse-json": { "node_modules/parse-json": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz",
...@@ -5749,7 +5799,6 @@ ...@@ -5749,7 +5799,6 @@
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true,
"engines": { "engines": {
"node": ">=6" "node": ">=6"
} }
...@@ -10691,6 +10740,11 @@ ...@@ -10691,6 +10740,11 @@
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz", "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo=" "integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
}, },
"ip-regex": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz",
"integrity": "sha512-B9ZWJxHHOHUhUjCPrMpLD4xEq35bUTClHM1S6CBU5ixQnkZmwipwgc96vAd7AAGM9TGHvJR+Uss+/Ak6UphK+Q=="
},
"is-arrayish": { "is-arrayish": {
"version": "0.2.1", "version": "0.2.1",
"resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz",
...@@ -10781,6 +10835,14 @@ ...@@ -10781,6 +10835,14 @@
"is-extglob": "^2.1.1" "is-extglob": "^2.1.1"
} }
}, },
"is-ip": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/is-ip/-/is-ip-3.1.0.tgz",
"integrity": "sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==",
"requires": {
"ip-regex": "^4.0.0"
}
},
"is-negative-zero": { "is-negative-zero": {
"version": "2.0.1", "version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.1.tgz",
...@@ -11265,6 +11327,11 @@ ...@@ -11265,6 +11327,11 @@
"yallist": "^3.0.2" "yallist": "^3.0.2"
} }
}, },
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
},
"magic-string": { "magic-string": {
"version": "0.25.7", "version": "0.25.7",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
...@@ -11432,6 +11499,11 @@ ...@@ -11432,6 +11499,11 @@
"resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz", "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz",
"integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==" "integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg=="
}, },
"node-fetch": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"node-releases": { "node-releases": {
"version": "1.1.75", "version": "1.1.75",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.75.tgz", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.75.tgz",
...@@ -11625,6 +11697,16 @@ ...@@ -11625,6 +11697,16 @@
"callsites": "^3.0.0" "callsites": "^3.0.0"
} }
}, },
"parse-domain": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/parse-domain/-/parse-domain-4.1.0.tgz",
"integrity": "sha512-zas79foMEsbMbIcJoPx26+NISWa3jTzZykOW9mXfRzvgadHvAHGd7qcCc1FbSWbD1I4qP71UWAxlTgu7Uq6IQg==",
"requires": {
"is-ip": "^3.1.0",
"node-fetch": "^2.6.1",
"punycode": "^2.1.1"
}
},
"parse-json": { "parse-json": {
"version": "4.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz",
...@@ -12024,8 +12106,7 @@ ...@@ -12024,8 +12106,7 @@
"punycode": { "punycode": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
"dev": true
}, },
"q": { "q": {
"version": "1.5.1", "version": "1.5.1",
......
...@@ -24,8 +24,10 @@ ...@@ -24,8 +24,10 @@
"esri-loader": "^3.2.0", "esri-loader": "^3.2.0",
"exceljs": "^4.3.0", "exceljs": "^4.3.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"lz-string": "^1.4.4",
"md5": "^2.3.0", "md5": "^2.3.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"parse-domain": "^4.1.0",
"qs": "^6.10.1", "qs": "^6.10.1",
"vite-plugin-svgicon": "^1.0.0", "vite-plugin-svgicon": "^1.0.0",
"vue": "^3.2.6", "vue": "^3.2.6",
......
var LZString = (function () {
function o(o, r) {
if (!t[o]) {
t[o] = {}
for (var n = 0; n < o.length; n++) t[o][o.charAt(n)] = n
}
return t[o][r]
}
var r = String.fromCharCode,
n = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=',
e = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$',
t = {},
i = {
compressToBase64: function (o) {
if (null == o) return ''
var r = i._compress(o, 6, function (o) {
return n.charAt(o)
})
switch (r.length % 4) {
default:
case 0:
return r
case 1:
return r + '==='
case 2:
return r + '=='
case 3:
return r + '='
}
},
decompressFromBase64: function (r) {
return null == r
? ''
: '' == r
? null
: i._decompress(r.length, 32, function (e) {
return o(n, r.charAt(e))
})
},
compressToUTF16: function (o) {
return null == o
? ''
: i._compress(o, 15, function (o) {
return r(o + 32)
}) + ' '
},
decompressFromUTF16: function (o) {
return null == o
? ''
: '' == o
? null
: i._decompress(o.length, 16384, function (r) {
return o.charCodeAt(r) - 32
})
},
compressToUint8Array: function (o) {
for (
var r = i.compress(o),
n = new Uint8Array(2 * r.length),
e = 0,
t = r.length;
t > e;
e++
) {
var s = r.charCodeAt(e)
;(n[2 * e] = s >>> 8), (n[2 * e + 1] = s % 256)
}
return n
},
decompressFromUint8Array: function (o) {
if (null === o || void 0 === o) return i.decompress(o)
for (var n = new Array(o.length / 2), e = 0, t = n.length; t > e; e++)
n[e] = 256 * o[2 * e] + o[2 * e + 1]
var s = []
return (
n.forEach(function (o) {
s.push(r(o))
}),
i.decompress(s.join(''))
)
},
compressToEncodedURIComponent: function (o) {
return null == o
? ''
: i._compress(o, 6, function (o) {
return e.charAt(o)
})
},
decompressFromEncodedURIComponent: function (r) {
return null == r
? ''
: '' == r
? null
: ((r = r.replace(/ /g, '+')),
i._decompress(r.length, 32, function (n) {
return o(e, r.charAt(n))
}))
},
compress: function (o) {
return i._compress(o, 16, function (o) {
return r(o)
})
},
_compress: function (o, r, n) {
if (null == o) return ''
var e,
t,
i,
s = {},
p = {},
u = '',
c = '',
a = '',
l = 2,
f = 3,
h = 2,
d = [],
m = 0,
v = 0
for (i = 0; i < o.length; i += 1)
if (
((u = o.charAt(i)),
Object.prototype.hasOwnProperty.call(s, u) ||
((s[u] = f++), (p[u] = !0)),
(c = a + u),
Object.prototype.hasOwnProperty.call(s, c))
)
a = c
else {
if (Object.prototype.hasOwnProperty.call(p, a)) {
if (a.charCodeAt(0) < 256) {
for (e = 0; h > e; e++)
(m <<= 1), v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++
for (t = a.charCodeAt(0), e = 0; 8 > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
} else {
for (t = 1, e = 0; h > e; e++)
(m = (m << 1) | t),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t = 0)
for (t = a.charCodeAt(0), e = 0; 16 > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
}
l--, 0 == l && ((l = Math.pow(2, h)), h++), delete p[a]
} else
for (t = s[a], e = 0; h > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
l--,
0 == l && ((l = Math.pow(2, h)), h++),
(s[c] = f++),
(a = String(u))
}
if ('' !== a) {
if (Object.prototype.hasOwnProperty.call(p, a)) {
if (a.charCodeAt(0) < 256) {
for (e = 0; h > e; e++)
(m <<= 1), v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++
for (t = a.charCodeAt(0), e = 0; 8 > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
} else {
for (t = 1, e = 0; h > e; e++)
(m = (m << 1) | t),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t = 0)
for (t = a.charCodeAt(0), e = 0; 16 > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
}
l--, 0 == l && ((l = Math.pow(2, h)), h++), delete p[a]
} else
for (t = s[a], e = 0; h > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
l--, 0 == l && ((l = Math.pow(2, h)), h++)
}
for (t = 2, e = 0; h > e; e++)
(m = (m << 1) | (1 & t)),
v == r - 1 ? ((v = 0), d.push(n(m)), (m = 0)) : v++,
(t >>= 1)
for (;;) {
if (((m <<= 1), v == r - 1)) {
d.push(n(m))
break
}
v++
}
return d.join('')
},
decompress: function (o) {
return null == o
? ''
: '' == o
? null
: i._decompress(o.length, 32768, function (r) {
return o.charCodeAt(r)
})
},
_decompress: function (o, n, e) {
var t,
i,
s,
p,
u,
c,
a,
l,
f = [],
h = 4,
d = 4,
m = 3,
v = '',
w = [],
A = { val: e(0), position: n, index: 1 }
for (i = 0; 3 > i; i += 1) f[i] = i
for (p = 0, c = Math.pow(2, 2), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
switch ((t = p)) {
case 0:
for (p = 0, c = Math.pow(2, 8), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
l = r(p)
break
case 1:
for (p = 0, c = Math.pow(2, 16), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
l = r(p)
break
case 2:
return ''
}
for (f[3] = l, s = l, w.push(l); ; ) {
if (A.index > o) return ''
for (p = 0, c = Math.pow(2, m), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
switch ((l = p)) {
case 0:
for (p = 0, c = Math.pow(2, 8), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
;(f[d++] = r(p)), (l = d - 1), h--
break
case 1:
for (p = 0, c = Math.pow(2, 16), a = 1; a != c; )
(u = A.val & A.position),
(A.position >>= 1),
0 == A.position && ((A.position = n), (A.val = e(A.index++))),
(p |= (u > 0 ? 1 : 0) * a),
(a <<= 1)
;(f[d++] = r(p)), (l = d - 1), h--
break
case 2:
return w.join('')
}
if ((0 == h && ((h = Math.pow(2, m)), m++), f[l])) v = f[l]
else {
if (l !== d) return null
v = s + s.charAt(0)
}
w.push(v),
(f[d++] = s + v.charAt(0)),
h--,
(s = v),
0 == h && ((h = Math.pow(2, m)), m++)
}
},
}
return i
})()
'function' == typeof define && define.amd
? define(function () {
return LZString
})
: 'undefined' != typeof module &&
null != module &&
(module.exports = LZString)
import { tokenIns } from '@/util/tokenUtil'
let BASE_URL: string = '' let BASE_URL: string = ''
let TOKEN: string = '' let TOKEN: string = ''
let MAP_CONFIG: { jsApiUrl: string; cssUrl: string } = { let MAP_CONFIG: { jsApiUrl: string; cssUrl: string } = {
...@@ -5,20 +7,18 @@ let MAP_CONFIG: { jsApiUrl: string; cssUrl: string } = { ...@@ -5,20 +7,18 @@ let MAP_CONFIG: { jsApiUrl: string; cssUrl: string } = {
cssUrl: '', cssUrl: '',
} }
const getCookie = (name: string): string | null => { function getToken() {
const reg: RegExp = new RegExp(`(^| )${name}=([^;]*)(;|$)`) const header = window.__DM_GLOBE_UTIL
const arr: RegExpMatchArray | null = document.cookie.match(reg) ? window.__DM_GLOBE_UTIL.getHeader()
if (arr) return unescape(arr[2]) : null
return null return header ? header.authorization : tokenIns.get()
} }
switch (process.env.NODE_ENV) { switch (process.env.NODE_ENV) {
case 'production': case 'production':
BASE_URL = 'https://www.maicedata.com/collector/data/' // 生产环境 BASE_URL = 'https://www.maicedata.com/collector/data/' // 生产环境
// TODO 获取token TOKEN = getToken()
TOKEN = LZString.decompressFromEncodedURIComponent(
getCookie('__DM_TOKEN__') || window.localStorage.getItem('dm_token_'),
)
// TODO 生产环境地图链接?? // TODO 生产环境地图链接??
MAP_CONFIG = { MAP_CONFIG = {
jsApiUrl: 'http://10.108.3.41/arcgis_js_api/library/4.18/init.js', jsApiUrl: 'http://10.108.3.41/arcgis_js_api/library/4.18/init.js',
...@@ -26,8 +26,7 @@ switch (process.env.NODE_ENV) { ...@@ -26,8 +26,7 @@ switch (process.env.NODE_ENV) {
} }
break break
default: default:
// vite.config 代理 https://survey.maicedata.com/api/data/ BASE_URL = '/api' // vite.config 代理 https://survey.maicedata.com/api/data/
BASE_URL = '/api'
TOKEN = '91e315a9-b2a8-4950-97fa-9dbf84a230d6' TOKEN = '91e315a9-b2a8-4950-97fa-9dbf84a230d6'
MAP_CONFIG = { MAP_CONFIG = {
jsApiUrl: 'http://10.108.3.41/arcgis_js_api/library/4.18/init.js', jsApiUrl: 'http://10.108.3.41/arcgis_js_api/library/4.18/init.js',
......
...@@ -16,12 +16,8 @@ declare module '*.jpeg' ...@@ -16,12 +16,8 @@ declare module '*.jpeg'
declare module '*.gif' declare module '*.gif'
declare module '*.svg' declare module '*.svg'
declare const LZString: {
decompressFromEncodedURIComponent: any
}
declare interface Window { declare interface Window {
__DM_GLOBE_UTIL: any
_global_datamap_emit: any _global_datamap_emit: any
dojoConfig: any dojoConfig: any
apiRoot: any apiRoot: any
......
...@@ -19,7 +19,7 @@ export default { ...@@ -19,7 +19,7 @@ export default {
/** 获取权限编码 */ /** 获取权限编码 */
async getAuth({ commit }: Method) { async getAuth({ commit }: Method) {
if (process.env.NODE_ENV !== 'production') { if (process.env.NODE_ENV !== 'production') {
// 开发环境 /* 开发环境 测试用 */
commit('SET_AUTH', { commit('SET_AUTH', {
userid: 91541, userid: 91541,
orgid: '000001', orgid: '000001',
......
export const setCookie = (
name: string,
value: string,
domain?: string,
path?: string,
expires?: string,
): void => {
const days: number = 1
const exp: Date = new Date()
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000)
let ck = `${name}=${escape(value)};`
if (domain) {
ck += `domain=${domain};`
}
if (path) {
ck += `path=${path};`
}
ck += `expires=${expires || exp.toUTCString()}`
document.cookie = ck
}
export const getCookie = (name: string): string | null => {
const reg: RegExp = new RegExp(`(^| )${name}=([^;]*)(;|$)`)
// eslint-disable-next-line no-undef
const arr: RegExpMatchArray | null = document.cookie.match(reg)
if (arr) {
return unescape(arr[2])
}
return null
}
export const deleteCookie = (
name: string,
domain: string,
path: string,
): void => {
const exp = new Date()
exp.setTime(exp.getTime() - 1)
const cval = getCookie(name)
// tslint:disable-next-line: strict-comparisons
if (cval !== null) {
let ck = `${name}=;expires=${exp.toUTCString()};`
if (domain) {
ck += `domain=${domain};`
}
if (path) {
ck += `path=${path};`
}
document.cookie = ck
}
}
import * as LZString from 'lz-string'
import { parseDomain, ParseResultType } from 'parse-domain'
import { getCookie, setCookie } from './cookieUtil'
// import { emitObj } from './eventEmit';
// export const TOKEN_SET_EVENT = 'TOKEN_SET_EVENT';
/**
* 获取domain主域名
*/
function getDomainName(hostName: string): string {
// const hostName = host.split(':')[0];
const parseResult = parseDomain(
// This should be a string with basic latin characters only.
// More information below.
hostName,
)
if (parseResult.type === ParseResultType.Listed) {
const { domain: dm, topLevelDomains } = parseResult
return [dm].concat(topLevelDomains).join('.')
}
if (hostName.indexOf('localhost') !== -1) {
return 'localhost'
}
return ''
}
const domain =
window.location && window.location.host && getDomainName(window.location.host)
const DM_TOKEN = '__DM_TOKEN__' // 当前用户token | 被模拟用户
const DM_IMPER_TOKEN = '__DM_IMPER_TOKEN__' // 当前模拟操作用户token
const DM_MDT_USER = '__DM_MDT_USER__' // 当前用户mdt-user: '$user_id:$app_id' | 被模拟用户
const DM_IMPER_MDT_USER = '__DM_IMPER_MDT_USER__' // 当前模拟操作用户mdt-user: '$user_id:$app_id'
const parseFromCookie = (key: string) => {
let cookieToken = getCookie(key)
console.log(cookieToken)
if (!cookieToken || cookieToken.length !== 47) {
cookieToken = localStorage.getItem('dm_token_')
console.log(cookieToken)
}
const p12Asn1 = cookieToken
? LZString.decompressFromEncodedURIComponent(cookieToken)
: ''
return p12Asn1
}
const setToCookie = (key: string, val: string) => {
const days: number = 1
const exp: Date = new Date()
exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000)
const p12Asn1 = LZString.compressToEncodedURIComponent(val)
setCookie(key, p12Asn1, domain, '/', exp.toUTCString())
}
/**
* Token
*/
export class Token {
private path: string = ''
private token: string = ''
private imperToken: string = ''
private mdtUser: string = ''
private imperMdtUser: string = ''
public constructor(path: string = '') {
this.setPath(path)
}
/**
* Sets path
* @param path string
*/
public setPath(path: string): void {
this.path = path
this.token = parseFromCookie(DM_TOKEN + this.path) || ''
this.imperToken = parseFromCookie(DM_IMPER_TOKEN + this.path) || ''
this.mdtUser = parseFromCookie(DM_MDT_USER + this.path) || ''
this.imperMdtUser = parseFromCookie(DM_IMPER_MDT_USER + this.path) || ''
}
/**
* Gets token
* @returns get
*/
public get(): string {
return this.token
}
/**
* Gets impersonate token
* @returns impersonate token
*/
public getImperToken(): string {
return this.imperToken
}
/**
* Gets mdt user
* @returns mdt user
*/
public getMdtUser(): string {
return this.mdtUser
}
/**
* Gets impersonate mdt user
* @returns impersonate mdt user
*/
public getImperMdtUser(): string {
return this.imperMdtUser
}
/**
* Sets token
* @param token string
* @param [saveCookie] boolean
*/
public set(token: string, saveCookie: boolean = true): void {
this.token = token
if (saveCookie) {
setToCookie(DM_TOKEN + this.path, token)
}
// emitObj.emit(TOKEN_SET_EVENT, this.token);
}
/**
* Sets token
* @param token string
* @param [saveCookie] boolean
*/
public setImperToken(token: string, saveCookie: boolean = true): void {
this.imperToken = token
if (saveCookie) {
setToCookie(DM_IMPER_TOKEN + this.path, token)
}
}
/**
* Sets mdt user
* @param mdtUser string
*/
public setMdtUser(mdtUser: string): void {
this.mdtUser = mdtUser
setToCookie(DM_MDT_USER + this.path, mdtUser)
}
/**
* Sets mdt user
* @param mdtUser string
*/
public setImperMdtUser(mdtUser: string): void {
this.imperMdtUser = mdtUser
setToCookie(DM_IMPER_MDT_USER + this.path, mdtUser)
}
/**
* get headers
*/
public getHeaders(): {
'X-Impersonate-Token'?: string
'Mdt-User'?: string
Authorization?: string
} {
const headers: {
'X-Impersonate-Token'?: string
'Mdt-User'?: string
Authorization?: string
} = {}
if (this.token) {
headers.Authorization = this.token
}
if (this.mdtUser) {
headers['Mdt-User'] = this.mdtUser
}
if (this.imperToken) {
headers['X-Impersonate-Token'] = this.imperToken
}
return headers
}
/**
* Logouts token
*/
public logout(): void {
this.set('')
this.setImperToken('')
this.setMdtUser('')
this.setImperMdtUser('')
}
/**
* Logouts mock
*/
public logoutMock(): void {
this.set(this.imperToken)
this.setImperToken('')
this.setMdtUser(this.imperMdtUser)
this.setImperMdtUser('')
}
}
export const tokenIns = new Token()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment