@smart100/spu-web-plugin 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/spu-web-plugin.mjs +14 -0
- package/package.json +51 -0
- package/src/AMapLoader.ts +46 -0
- package/src/axios.ts +144 -0
- package/src/cloudServ.ts +121 -0
- package/src/index.ts +31 -0
- package/src/install.ts +88 -0
- package/src/loadding/img/loading.gif +0 -0
- package/src/loadding/index.ts +83 -0
- package/src/loadding/index.vue +43 -0
- package/src/location.ts +187 -0
- package/src/login.ts +248 -0
- package/src/oss/downloadService.ts +192 -0
- package/src/oss/index.ts +8 -0
- package/src/oss/multiUpload.ts +129 -0
- package/src/oss/servtoken.ts +131 -0
- package/src/oss/uploadService.ts +145 -0
- package/src/package/ali-oss/aliyun-oss-sdk.apaas.js +25198 -0
- package/src/package/ali-oss/aliyun-oss-sdk.apaas.min.js +15 -0
- package/src/package/ali-oss/aliyun-oss-sdk.js +25168 -0
- package/src/package/ali-oss/aliyun-oss-sdk.min.js +14 -0
- package/src/package/ali-oss/package.json +162 -0
- package/src/package/huaweicloud-obs/esdk-obs-browserjs-without-polyfill.3.22.3.min.js +2 -0
- package/src/package/huaweicloud-obs/esdk-obs-browserjs.3.22.3.min.js +2 -0
- package/src/package/huaweicloud-obs/package.json +28 -0
- package/src/storageProxy.ts +47 -0
- package/src/tenantInfo.ts +76 -0
- package/src/types/index.d.ts +84 -0
- package/src/types/shims-lib.d.ts +37 -0
- package/src/urlquery.ts +53 -0
- package/src/utils.ts +20 -0
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smart100/spu-web-plugin",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "rollup -c -w",
|
|
7
|
+
"build": "rollup -c",
|
|
8
|
+
"build1": "rollup -c --environment NODE_ENV:production",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"author": "tarymee",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"browser": "dist/spu-web-plugin.umd.js",
|
|
14
|
+
"main": "dist/spu-web-plugin.cjs",
|
|
15
|
+
"module": "dist/spu-web-plugin.mjs",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/core": "^7.23.2",
|
|
22
|
+
"@babel/preset-env": "^7.23.2",
|
|
23
|
+
"@rollup/plugin-babel": "^6.0.4",
|
|
24
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
25
|
+
"@rollup/plugin-image": "^3.0.3",
|
|
26
|
+
"@rollup/plugin-json": "^6.0.1",
|
|
27
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
28
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
29
|
+
"@rollup/plugin-typescript": "^11.1.5",
|
|
30
|
+
"@types/lodash-es": "^4.17.10",
|
|
31
|
+
"@types/node": "^20.8.10",
|
|
32
|
+
"postcss": "^8.4.31",
|
|
33
|
+
"rollup": "^4.2.0",
|
|
34
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
35
|
+
"rollup-plugin-vue": "^6.0.0",
|
|
36
|
+
"tslib": "^2.6.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@amap/amap-jsapi-loader": "^1.0.1",
|
|
40
|
+
"axios": "^1.6.0",
|
|
41
|
+
"co": "^4.6.0",
|
|
42
|
+
"dayjs": "^1.11.10",
|
|
43
|
+
"jwt-decode": "^3.1.2",
|
|
44
|
+
"lodash-es": "^4.17.21",
|
|
45
|
+
"uuid": "^9.0.1",
|
|
46
|
+
"vconsole": "^3.15.1"
|
|
47
|
+
},
|
|
48
|
+
"peerdependencies": {
|
|
49
|
+
"vue": "^3.2.13"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
2
|
+
|
|
3
|
+
// 高德地图 web端key 和 安全密钥
|
|
4
|
+
const amapKey = {
|
|
5
|
+
// 测试开发环境
|
|
6
|
+
dev: {
|
|
7
|
+
key: '38fa4702d240e1e6ee5cc8ca059b254f',
|
|
8
|
+
securityjscode: '96f2af5670b7a41a56dcd2e8b63c1e06'
|
|
9
|
+
},
|
|
10
|
+
// 生产环境
|
|
11
|
+
production: {
|
|
12
|
+
key: '1993ac213d2f4675ac1bffb1b03ef1f0',
|
|
13
|
+
securityjscode: '816fe46b7b7bce145940b93c1e4818fa'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
// const amapkey = process.env.NODE_ENV !== 'production' ? amapKey.dev.key : amapKey.production.key
|
|
17
|
+
// const amapsecurityjscode = process.env.NODE_ENV !== 'production' ? amapKey.dev.securityjscode : amapKey.production.securityjscode
|
|
18
|
+
|
|
19
|
+
const amapkey = amapKey.production.key
|
|
20
|
+
const amapsecurityjscode = amapKey.production.securityjscode
|
|
21
|
+
|
|
22
|
+
const load = (options?: {
|
|
23
|
+
plugins?: Array<string>
|
|
24
|
+
AMapUI?: {
|
|
25
|
+
plugins?: Array<string>
|
|
26
|
+
}
|
|
27
|
+
}) => {
|
|
28
|
+
if (!window._AMapSecurityConfig) {
|
|
29
|
+
window._AMapSecurityConfig = {
|
|
30
|
+
securityJsCode: amapsecurityjscode
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return AMapLoader.load({
|
|
34
|
+
key: amapkey,
|
|
35
|
+
version: '2.0',
|
|
36
|
+
plugins: options?.plugins || [],
|
|
37
|
+
AMapUI: {
|
|
38
|
+
version: '1.1',
|
|
39
|
+
plugins: options?.AMapUI?.plugins || []
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default {
|
|
45
|
+
load
|
|
46
|
+
}
|
package/src/axios.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import axios from 'axios'
|
|
2
|
+
import type {
|
|
3
|
+
AxiosInstance,
|
|
4
|
+
AxiosError,
|
|
5
|
+
AxiosResponse
|
|
6
|
+
} from 'axios'
|
|
7
|
+
import { get } from 'lodash-es'
|
|
8
|
+
// import { Message } from 'element-ui'
|
|
9
|
+
import loadding from './loadding/index'
|
|
10
|
+
import login from './login'
|
|
11
|
+
|
|
12
|
+
interface Response {
|
|
13
|
+
code: number | string
|
|
14
|
+
data: any
|
|
15
|
+
msg: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const createAxiosInstance = (type: 'spu' | 'apaas' = 'spu', options: SPUWebPluginOptions) => {
|
|
19
|
+
const axiosInstance: AxiosInstance = axios.create({
|
|
20
|
+
baseURL: type === 'spu' ? `/api/${options.modulekey}/${options.moduleversion}` : '',
|
|
21
|
+
// timeout: 36000000
|
|
22
|
+
// withCredentials: true, // 不能开启 影响ali oss
|
|
23
|
+
// headers: {
|
|
24
|
+
// // 'Content-Type': 'application/json;charset=UTF-8',
|
|
25
|
+
// // 'app_id': '100'
|
|
26
|
+
// }
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
axiosInstance.interceptors.request.use((config: any) => {
|
|
30
|
+
// const isShowLoading = typeof config?.isShowLoading !== 'undefined' ? config.isShowLoading : true
|
|
31
|
+
const isShowLoading = get(config, 'isShowLoading', true)
|
|
32
|
+
isShowLoading && loadding.open()
|
|
33
|
+
|
|
34
|
+
const isSendToken = get(config, 'isSendToken', true)
|
|
35
|
+
if (isSendToken) {
|
|
36
|
+
const token = login.getToken()
|
|
37
|
+
if (config?.headers && token) {
|
|
38
|
+
config.headers.token = token
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return config
|
|
42
|
+
}, error => {
|
|
43
|
+
return Promise.reject(error)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
axiosInstance.interceptors.response.use((res: AxiosResponse) => {
|
|
47
|
+
// debugger
|
|
48
|
+
const isShowLoading = get(res, 'config.isShowLoading', true)
|
|
49
|
+
isShowLoading && loadding.close()
|
|
50
|
+
|
|
51
|
+
let realRes: Response = {
|
|
52
|
+
code: 404,
|
|
53
|
+
data: '',
|
|
54
|
+
msg: ''
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (type === 'spu') {
|
|
58
|
+
if (res.data.code === 200) {
|
|
59
|
+
// return res.data
|
|
60
|
+
realRes = {
|
|
61
|
+
code: res.data.code,
|
|
62
|
+
data: res.data.data,
|
|
63
|
+
msg: res.data.msg
|
|
64
|
+
}
|
|
65
|
+
return realRes
|
|
66
|
+
} else {
|
|
67
|
+
const msg = res?.data?.msg || '网络异常,请稍后重试。'
|
|
68
|
+
const isShowErrorMessage = get(res, 'config.isShowErrorMessage', true)
|
|
69
|
+
// isShowErrorMessage && Message.error(msg)
|
|
70
|
+
|
|
71
|
+
realRes = {
|
|
72
|
+
code: res.data.code,
|
|
73
|
+
data: res.data.data,
|
|
74
|
+
msg: res.data.msg
|
|
75
|
+
}
|
|
76
|
+
return Promise.reject(realRes) as any
|
|
77
|
+
}
|
|
78
|
+
} else if (type === 'apaas') {
|
|
79
|
+
realRes = {
|
|
80
|
+
code: res.status || 200,
|
|
81
|
+
data: res.data?.resp_data || res.data,
|
|
82
|
+
msg: res.data?.error_code || ''
|
|
83
|
+
}
|
|
84
|
+
return realRes
|
|
85
|
+
}
|
|
86
|
+
}, (err: AxiosError) => {
|
|
87
|
+
// console.log(err)
|
|
88
|
+
// debugger
|
|
89
|
+
const isShowLoading = get(err, 'config.isShowLoading', true)
|
|
90
|
+
isShowLoading && loadding.close()
|
|
91
|
+
|
|
92
|
+
// console.log(err)
|
|
93
|
+
// debugger
|
|
94
|
+
// 兼容处理接口新方案 通过传参配置区分 默认使用新方案
|
|
95
|
+
// 接口返回非 200 状态码 肯定是报错必须要提示
|
|
96
|
+
const msg = (type === 'spu' ? get(err, 'response.data.msg') : get(err, 'response.data.error_code')) || get(err, 'response.statusText') || get(err, 'message', '网络异常,请稍后重试。')
|
|
97
|
+
|
|
98
|
+
const isShowErrorMessage = get(err, 'config.isShowErrorMessage', true)
|
|
99
|
+
// isShowErrorMessage && Message.error(msg)
|
|
100
|
+
|
|
101
|
+
const isNoLogin = () => {
|
|
102
|
+
if (type === 'spu') {
|
|
103
|
+
if (msg === '未授权' && get(err, 'response.data.code') === 401) {
|
|
104
|
+
return true
|
|
105
|
+
} else {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
} else if (type === 'apaas') {
|
|
109
|
+
if (msg.indexOf('token is invalid(decode).') !== -1 || msg.indexOf('token is invalid(null).') !== -1 || msg === 'token无效,请重新登录' || msg === 'jwt token无效') {
|
|
110
|
+
return true
|
|
111
|
+
} else {
|
|
112
|
+
return false
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const noLoginFn = () => {
|
|
118
|
+
if (isNoLogin()) {
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return Promise.reject(err)
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
return axiosInstance
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// const spuAxios: AxiosInstance = createAxiosInstance('spu')
|
|
130
|
+
// const apaasAxios: AxiosInstance = createAxiosInstance('apaas')
|
|
131
|
+
|
|
132
|
+
let spuAxios: any = null
|
|
133
|
+
let apaasAxios: any = null
|
|
134
|
+
|
|
135
|
+
function initAxios (options: SPUWebPluginOptions) {
|
|
136
|
+
spuAxios = createAxiosInstance('spu', options)
|
|
137
|
+
apaasAxios = createAxiosInstance('apaas', options)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
initAxios,
|
|
142
|
+
spuAxios,
|
|
143
|
+
apaasAxios
|
|
144
|
+
}
|
package/src/cloudServ.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { lsProxy } from './storageProxy'
|
|
2
|
+
|
|
3
|
+
// let cacheStorage: NormalizedCloudServ | null = null
|
|
4
|
+
|
|
5
|
+
// const CLOUDSERVE = 'cloudserv'
|
|
6
|
+
|
|
7
|
+
// const set = (storage: NormalizedCloudServ | string) => {
|
|
8
|
+
// if (typeof storage === 'object') {
|
|
9
|
+
// cacheStorage = storage
|
|
10
|
+
// storage = JSON.stringify(storage)
|
|
11
|
+
// }
|
|
12
|
+
// lsProxy.setItem(CLOUDSERVE, storage)
|
|
13
|
+
// }
|
|
14
|
+
|
|
15
|
+
// const get = (key: StorageType = 'storage'): NormalizedCloudServItem | null => {
|
|
16
|
+
// if (cacheStorage) {
|
|
17
|
+
// return cacheStorage[key as StorageType] || null
|
|
18
|
+
// }
|
|
19
|
+
// const storageStr = lsProxy.getItem(CLOUDSERVE)
|
|
20
|
+
// if (!storageStr) {
|
|
21
|
+
// return null
|
|
22
|
+
// }
|
|
23
|
+
// const storage = JSON.parse(storageStr)
|
|
24
|
+
// cacheStorage = storage
|
|
25
|
+
// return storage[key]
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// const getProvider = (sign: StorageType = 'storage') => {
|
|
29
|
+
// const storage: NormalizedCloudServItem | null = get(sign)
|
|
30
|
+
// if (!storage) {
|
|
31
|
+
// return false
|
|
32
|
+
// }
|
|
33
|
+
// return storage.cloudserv_storage_provider
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// const isAliyun = (sign: StorageType = 'storage') => {
|
|
37
|
+
// return getProvider(sign) === 'aliyun'
|
|
38
|
+
// }
|
|
39
|
+
|
|
40
|
+
// const isAzure = (sign: StorageType = 'storage') => {
|
|
41
|
+
// return getProvider(sign) === 'azure'
|
|
42
|
+
// }
|
|
43
|
+
|
|
44
|
+
// const isAwss3 = (sign: StorageType = 'storage') => {
|
|
45
|
+
// return getProvider(sign) === 'awss3'
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
// const isHuawei = (sign: StorageType = 'storage') => {
|
|
49
|
+
// return getProvider(sign) === 'huawei'
|
|
50
|
+
// }
|
|
51
|
+
|
|
52
|
+
// export default {
|
|
53
|
+
// set,
|
|
54
|
+
// get,
|
|
55
|
+
// isAliyun,
|
|
56
|
+
// isAzure,
|
|
57
|
+
// isAwss3,
|
|
58
|
+
// isHuawei
|
|
59
|
+
// }
|
|
60
|
+
|
|
61
|
+
class CloudServ {
|
|
62
|
+
CLOUD_SERVE_KEY = 'cloudserv'
|
|
63
|
+
|
|
64
|
+
cacheStorage: NormalizedCloudServ | null = null
|
|
65
|
+
|
|
66
|
+
public get (key: StorageType = 'storage'): NormalizedCloudServItem | null {
|
|
67
|
+
if (this.cacheStorage) {
|
|
68
|
+
return this.cacheStorage[key] || null
|
|
69
|
+
}
|
|
70
|
+
const storageStr = lsProxy.getItem(this.CLOUD_SERVE_KEY)
|
|
71
|
+
if (!storageStr) {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
const storage = JSON.parse(storageStr)
|
|
75
|
+
this.cacheStorage = storage
|
|
76
|
+
return storage[key]
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
public set (storage: NormalizedCloudServ | string) {
|
|
80
|
+
if (typeof storage === 'object') {
|
|
81
|
+
this.cacheStorage = storage
|
|
82
|
+
storage = JSON.stringify(storage)
|
|
83
|
+
}
|
|
84
|
+
lsProxy.setItem(this.CLOUD_SERVE_KEY, storage)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private getProvider (sign: StorageType = 'storage') {
|
|
88
|
+
const storage: NormalizedCloudServItem | null = this.get(sign)
|
|
89
|
+
if (!storage) {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
return storage.cloudserv_storage_provider
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
public isAliyun (sign: StorageType = 'storage') {
|
|
97
|
+
return this.getProvider(sign) === 'aliyun'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public isAzure (sign: StorageType = 'storage') {
|
|
101
|
+
return this.getProvider(sign) === 'azure'
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public isAwss3 (sign: StorageType = 'storage') {
|
|
105
|
+
return this.getProvider(sign) === 'awss3'
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public isHuawei (sign: StorageType = 'storage') {
|
|
109
|
+
return this.getProvider(sign) === 'huawei'
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default new CloudServ()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { version } from '../package.json'
|
|
2
|
+
import { install } from './install'
|
|
3
|
+
import { lsProxy, ssProxy } from './storageProxy'
|
|
4
|
+
import { getLocation, getDistance } from './location'
|
|
5
|
+
import { spuAxios, apaasAxios } from './axios'
|
|
6
|
+
import { downloadService, uploadService } from './oss'
|
|
7
|
+
// import { downloadService } from './oss'
|
|
8
|
+
|
|
9
|
+
// class SPUWebPlugin {
|
|
10
|
+
// static install = install
|
|
11
|
+
// static version = version
|
|
12
|
+
// }
|
|
13
|
+
// // SPUWebPlugin.install = install
|
|
14
|
+
// // SPUWebPlugin.version = version
|
|
15
|
+
|
|
16
|
+
const SPUWebPlugin = {
|
|
17
|
+
install,
|
|
18
|
+
version
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
SPUWebPlugin as default,
|
|
23
|
+
lsProxy,
|
|
24
|
+
ssProxy,
|
|
25
|
+
getLocation,
|
|
26
|
+
getDistance,
|
|
27
|
+
spuAxios,
|
|
28
|
+
apaasAxios,
|
|
29
|
+
downloadService,
|
|
30
|
+
uploadService
|
|
31
|
+
}
|
package/src/install.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { initStorageProxy } from './storageProxy'
|
|
2
|
+
import login from './login'
|
|
3
|
+
import { initAxios } from './axios'
|
|
4
|
+
import urlquery from './urlquery'
|
|
5
|
+
// import tenantInfo from './tenantInfo'
|
|
6
|
+
// import { downloadService } from './oss'
|
|
7
|
+
|
|
8
|
+
const install = (app: any, options: SPUWebPluginOptions) => {
|
|
9
|
+
// console.log(app)
|
|
10
|
+
// console.log(app.version)
|
|
11
|
+
console.log(options)
|
|
12
|
+
|
|
13
|
+
// if (install.installed) return
|
|
14
|
+
// install.installed = true
|
|
15
|
+
// debugger
|
|
16
|
+
|
|
17
|
+
const version = Number(app.version.split('.')[0])
|
|
18
|
+
if (version < 3) {
|
|
19
|
+
console.error('This plugin requires Vue 3')
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
initStorageProxy(options)
|
|
24
|
+
initAxios(options)
|
|
25
|
+
urlquery.init()
|
|
26
|
+
login.startRefreshtoken()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// setTimeout(async () => {
|
|
32
|
+
// const a = await downloadService.getUrl({
|
|
33
|
+
// // source: 'a1b9954a-fb39-4bb2-aa0b-501f4af0d99e.jpeg',
|
|
34
|
+
// // datetime: '1698832693257',
|
|
35
|
+
// // source: '2f7dfe47-1827-4db1-9d99-3ddb08bb7e21.jpg',
|
|
36
|
+
// // datetime: '1698832697897',
|
|
37
|
+
// source: 'e3befbe5-8954-46d2-a368-5f812a5530e5.jpg',
|
|
38
|
+
// datetime: '1699527237567',
|
|
39
|
+
// // cope: {
|
|
40
|
+
// // width: 100
|
|
41
|
+
// // }
|
|
42
|
+
// })
|
|
43
|
+
// console.log(a)
|
|
44
|
+
// console.log(71117)
|
|
45
|
+
// }, 1000)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// tenantInfo.getAndSave()
|
|
49
|
+
|
|
50
|
+
if (options.router) {
|
|
51
|
+
options.router.beforeEach(async (to: any, from: any, next: any) => {
|
|
52
|
+
// console.log(from)
|
|
53
|
+
// console.log(to)
|
|
54
|
+
// const isInitVisit = from.path === '/' && from.name === undefined // 路由初始化访问
|
|
55
|
+
// console.log('isInitVisit', isInitVisit)
|
|
56
|
+
|
|
57
|
+
// 自动登录
|
|
58
|
+
if (to.query.token) {
|
|
59
|
+
const singleLoginRes = await login.singleLogin(to.query)
|
|
60
|
+
next({
|
|
61
|
+
path: to.path,
|
|
62
|
+
params: to.params,
|
|
63
|
+
query: singleLoginRes.query
|
|
64
|
+
})
|
|
65
|
+
} else {
|
|
66
|
+
next()
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
} else {
|
|
70
|
+
console.error('请传入 router 实例。')
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Vue.component('xt-engine', components.engine)
|
|
74
|
+
// Vue.prototype.$xtEngine = () => {
|
|
75
|
+
// console.log('$xtEngine')
|
|
76
|
+
// }
|
|
77
|
+
|
|
78
|
+
// const component = options?.component
|
|
79
|
+
// if (component) {
|
|
80
|
+
// for (const x in component) {
|
|
81
|
+
// register(x, component[x])
|
|
82
|
+
// }
|
|
83
|
+
// }
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
install
|
|
88
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createVNode, render } from 'vue'
|
|
2
|
+
import loadding from './index.vue'
|
|
3
|
+
|
|
4
|
+
class Loadding {
|
|
5
|
+
private count = 0
|
|
6
|
+
|
|
7
|
+
private mountNode: HTMLDivElement | null = null
|
|
8
|
+
|
|
9
|
+
open () {
|
|
10
|
+
this.count++
|
|
11
|
+
if (!this.mountNode) {
|
|
12
|
+
const vm = createVNode(loadding, {
|
|
13
|
+
// ...options
|
|
14
|
+
})
|
|
15
|
+
this.mountNode = document.createElement('div')
|
|
16
|
+
render(vm, this.mountNode)
|
|
17
|
+
document.body.appendChild(this.mountNode)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
close () {
|
|
22
|
+
this.count--
|
|
23
|
+
if (this.count <= 0) {
|
|
24
|
+
this.count = 0
|
|
25
|
+
if (this.mountNode) {
|
|
26
|
+
document.body.removeChild(this.mountNode)
|
|
27
|
+
this.mountNode = null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// class Loadding2 {
|
|
34
|
+
// constructor () {
|
|
35
|
+
// this.MyVueElement = defineCustomElement({
|
|
36
|
+
// // 这里是普通的 Vue 组件选项
|
|
37
|
+
// // props: {},
|
|
38
|
+
// // emits: {},
|
|
39
|
+
// template: `
|
|
40
|
+
// 5436546546
|
|
41
|
+
// <div class="aaa">231365135</div>
|
|
42
|
+
// `,
|
|
43
|
+
// styles: [`
|
|
44
|
+
// .aaa {
|
|
45
|
+
// display: block;
|
|
46
|
+
// }
|
|
47
|
+
// `]
|
|
48
|
+
// })
|
|
49
|
+
// this.MyVueElement = defineCustomElement(loadding)
|
|
50
|
+
// customElements.define('my-vue-element', this.MyVueElement)
|
|
51
|
+
// }
|
|
52
|
+
|
|
53
|
+
// public MyVueElement
|
|
54
|
+
// public count = 0
|
|
55
|
+
|
|
56
|
+
// public mountNode: any = null
|
|
57
|
+
|
|
58
|
+
// open () {
|
|
59
|
+
// this.count++
|
|
60
|
+
// if (!this.mountNode) {
|
|
61
|
+
// this.mountNode = new this.MyVueElement({
|
|
62
|
+
// // 初始化的 prop (可选)
|
|
63
|
+
// msg: 'ssssss'
|
|
64
|
+
// })
|
|
65
|
+
// console.log(this.mountNode)
|
|
66
|
+
// document.body.appendChild((this.mountNode as any))
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
|
|
70
|
+
// close () {
|
|
71
|
+
// this.count--
|
|
72
|
+
// if (this.count <= 0) {
|
|
73
|
+
// this.count = 0
|
|
74
|
+
// // wx.hideLoading()
|
|
75
|
+
// if (this.mountNode) {
|
|
76
|
+
// document.body.removeChild(this.mountNode)
|
|
77
|
+
// this.mountNode = null
|
|
78
|
+
// }
|
|
79
|
+
// }
|
|
80
|
+
// }
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
export default new Loadding()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="loadding">
|
|
3
|
+
<div class="loadding-icon">
|
|
4
|
+
<img src="./img/loading.gif" alt="" />
|
|
5
|
+
</div>
|
|
6
|
+
</div>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script lang="ts">
|
|
10
|
+
import { defineComponent, ref } from 'vue'
|
|
11
|
+
|
|
12
|
+
export default defineComponent({
|
|
13
|
+
props: {
|
|
14
|
+
msg: String
|
|
15
|
+
},
|
|
16
|
+
setup () {
|
|
17
|
+
const show = ref(true)
|
|
18
|
+
return { show }
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<style scoped>
|
|
24
|
+
.loadding {
|
|
25
|
+
width: 100%;
|
|
26
|
+
height: 100%;
|
|
27
|
+
position: fixed;
|
|
28
|
+
top: 0;
|
|
29
|
+
left: 0;
|
|
30
|
+
background-color: rgba(255, 255, 255, 0.2);
|
|
31
|
+
}
|
|
32
|
+
.loadding-icon {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
height: 100%;
|
|
37
|
+
}
|
|
38
|
+
.loadding-icon img {
|
|
39
|
+
display: block;
|
|
40
|
+
width: 24px;
|
|
41
|
+
height: 24px;
|
|
42
|
+
}
|
|
43
|
+
</style>
|