@smart100/spu-web-plugin 1.0.25-beta.5 → 1.0.25-beta.7
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/index.d.ts +15 -8
- package/dist/spu-web-plugin.mjs +4192 -403
- package/package.json +2 -2
- package/src/axios.ts +126 -106
- package/src/axiosCache.ts +290 -0
- package/src/components/expandexp/index.ts +6 -6
- package/src/core.js +29 -6
- package/src/envService.ts +2 -2
- package/src/globalConfig.ts +24 -4
- package/src/index.ts +18 -5
- package/src/login.ts +18 -8
- package/src/map/index.ts +3 -3
- package/src/oss/cache.ts +178 -0
- package/src/oss/downloadService.ts +115 -53
- package/src/oss/servtoken.ts +4 -2
- package/src/oss/uploadService.ts +72 -81
- package/src/spuConfig.ts +30 -7
- package/src/tenantSetting.ts +2 -2
- package/src/types/index.d.ts +15 -8
- package/src/utils.ts +38 -3
package/src/oss/uploadService.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { getUser } from '../login'
|
|
|
6
6
|
import cloudServ from './cloudServ'
|
|
7
7
|
import { getServToken } from './servtoken'
|
|
8
8
|
import { obsMultiUpload } from './multiUpload'
|
|
9
|
+
import { globalOptions } from '../index'
|
|
10
|
+
import { defaultCachetime, generateCacheobj, setCache, setCacheByFile } from './cache'
|
|
9
11
|
|
|
10
12
|
interface IUpload {
|
|
11
13
|
type?: 'att' | 'img'
|
|
@@ -45,6 +47,8 @@ const upload = async ({
|
|
|
45
47
|
// console.log(storageConfig)
|
|
46
48
|
// debugger
|
|
47
49
|
const promise = new Promise(async (resolve, reject) => {
|
|
50
|
+
let uploadflag = false
|
|
51
|
+
let rejectV: any = null
|
|
48
52
|
if (provider?.isAliyun) {
|
|
49
53
|
const ossClient = new AliClient({
|
|
50
54
|
// region: storageConfig.cloudserv_storage_storageendpoint,
|
|
@@ -64,22 +68,13 @@ const upload = async ({
|
|
|
64
68
|
// console.log('httpUploadProgress', p)
|
|
65
69
|
onprogress && onprogress(p, _checkpoint)
|
|
66
70
|
if (p === 1) {
|
|
67
|
-
|
|
68
|
-
key: osskey,
|
|
69
|
-
source,
|
|
70
|
-
filename: file.name,
|
|
71
|
-
type: type,
|
|
72
|
-
date: date,
|
|
73
|
-
datetime: datetime,
|
|
74
|
-
storage: storagetype,
|
|
75
|
-
file
|
|
76
|
-
})
|
|
71
|
+
uploadflag = true
|
|
77
72
|
}
|
|
78
73
|
}
|
|
79
74
|
})
|
|
80
75
|
}).catch((error: any) => {
|
|
81
76
|
console.error(error)
|
|
82
|
-
|
|
77
|
+
rejectV = error
|
|
83
78
|
})
|
|
84
79
|
} else if (provider?.isHuawei) {
|
|
85
80
|
const obs = new ObsClient({
|
|
@@ -104,31 +99,12 @@ const upload = async ({
|
|
|
104
99
|
}
|
|
105
100
|
})
|
|
106
101
|
if (uploadRes) {
|
|
107
|
-
|
|
108
|
-
key: osskey,
|
|
109
|
-
source,
|
|
110
|
-
filename: file.name,
|
|
111
|
-
type: type,
|
|
112
|
-
date: date,
|
|
113
|
-
datetime: datetime,
|
|
114
|
-
storage: storagetype,
|
|
115
|
-
file
|
|
116
|
-
})
|
|
102
|
+
uploadflag = true
|
|
117
103
|
}
|
|
118
104
|
} catch (e) {
|
|
119
105
|
console.error(e)
|
|
120
|
-
|
|
106
|
+
rejectV = e
|
|
121
107
|
}
|
|
122
|
-
// obs.putObject({
|
|
123
|
-
// Bucket: cloudServ.cloudserv_storage_storagebucket,
|
|
124
|
-
// Key: osskey,
|
|
125
|
-
// SourceFile: file
|
|
126
|
-
// }, (err, result) => {
|
|
127
|
-
// result.CommonMsg.Status
|
|
128
|
-
// console.error(err)
|
|
129
|
-
// console.log(result)
|
|
130
|
-
// debugger
|
|
131
|
-
// })
|
|
132
108
|
} else if (provider?.isMinio || provider?.isAwss3) {
|
|
133
109
|
// debugger
|
|
134
110
|
// debugger
|
|
@@ -156,29 +132,43 @@ const upload = async ({
|
|
|
156
132
|
upload.send((err: any, data: any) => {
|
|
157
133
|
if (err) {
|
|
158
134
|
console.error(err)
|
|
159
|
-
|
|
135
|
+
rejectV = err
|
|
160
136
|
} else {
|
|
161
|
-
|
|
162
|
-
key: osskey,
|
|
163
|
-
source,
|
|
164
|
-
filename: file.name,
|
|
165
|
-
type: type,
|
|
166
|
-
date: date,
|
|
167
|
-
datetime: datetime,
|
|
168
|
-
storage: storagetype,
|
|
169
|
-
file
|
|
170
|
-
})
|
|
137
|
+
uploadflag = true
|
|
171
138
|
}
|
|
172
139
|
})
|
|
173
140
|
} else {
|
|
174
|
-
|
|
141
|
+
rejectV = new Error(`暂不支持${provider?.name}存储类型`)
|
|
142
|
+
// throw Error(`暂不支持${provider?.name}存储类型`)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (uploadflag) {
|
|
146
|
+
resolve({
|
|
147
|
+
key: osskey,
|
|
148
|
+
source,
|
|
149
|
+
filename: file.name,
|
|
150
|
+
type: type,
|
|
151
|
+
date: date,
|
|
152
|
+
datetime: datetime,
|
|
153
|
+
storage: storagetype,
|
|
154
|
+
file
|
|
155
|
+
})
|
|
156
|
+
// 暂时只作用于图片
|
|
157
|
+
setCacheByFile({
|
|
158
|
+
type,
|
|
159
|
+
source,
|
|
160
|
+
datetime,
|
|
161
|
+
storagetype,
|
|
162
|
+
file
|
|
163
|
+
})
|
|
164
|
+
} else {
|
|
165
|
+
reject(rejectV)
|
|
175
166
|
}
|
|
176
167
|
})
|
|
177
168
|
|
|
178
169
|
return promise
|
|
179
170
|
}
|
|
180
171
|
|
|
181
|
-
|
|
182
172
|
const createTargetObj = (copykey: string, storagetype: StorageType = 'storage') => {
|
|
183
173
|
const uuid = uuidv4()
|
|
184
174
|
const datetime = Date.now().toString()
|
|
@@ -195,14 +185,11 @@ const createTargetObj = (copykey: string, storagetype: StorageType = 'storage')
|
|
|
195
185
|
datetime,
|
|
196
186
|
date,
|
|
197
187
|
type: arr[1],
|
|
198
|
-
storage: storagetype
|
|
188
|
+
storage: storagetype
|
|
199
189
|
}
|
|
200
190
|
}
|
|
201
191
|
|
|
202
|
-
const copy = async ({
|
|
203
|
-
copykey = '',
|
|
204
|
-
storagetype = 'storage'
|
|
205
|
-
}: any) => {
|
|
192
|
+
const copy = async ({ copykey = '', storagetype = 'storage' }: any) => {
|
|
206
193
|
const storageConfig = cloudServ.get(storagetype)
|
|
207
194
|
if (!storageConfig) throw Error('无可用存储设置')
|
|
208
195
|
const servToken = await getServToken()
|
|
@@ -247,23 +234,24 @@ const copy = async ({
|
|
|
247
234
|
server: storageConfig.cloudserv_storage_storageendpoint,
|
|
248
235
|
security_token: servToken.securitytoken
|
|
249
236
|
})
|
|
250
|
-
obs
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
237
|
+
obs
|
|
238
|
+
.copyObject({
|
|
239
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
240
|
+
Key: targetObj.key,
|
|
241
|
+
CopySource: `${storageConfig.cloudserv_storage_storagebucket}/${copykey}`
|
|
242
|
+
})
|
|
243
|
+
.then((res: any) => {
|
|
244
|
+
if (res?.CommonMsg?.Status === 200 && res?.InterfaceResult) {
|
|
245
|
+
resolve(targetObj)
|
|
246
|
+
} else {
|
|
247
|
+
console.error(res)
|
|
248
|
+
reject(res)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
.catch((e: any) => {
|
|
252
|
+
console.error(e)
|
|
253
|
+
reject(e)
|
|
254
|
+
})
|
|
267
255
|
} else if (provider?.isMinio || provider?.isAwss3) {
|
|
268
256
|
// debugger
|
|
269
257
|
// debugger
|
|
@@ -278,28 +266,31 @@ const copy = async ({
|
|
|
278
266
|
})
|
|
279
267
|
// console.log(s3)
|
|
280
268
|
// debugger
|
|
281
|
-
s3.copyObject(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
269
|
+
s3.copyObject(
|
|
270
|
+
{
|
|
271
|
+
Bucket: storageConfig.cloudserv_storage_storagebucket,
|
|
272
|
+
CopySource: `${storageConfig.cloudserv_storage_storagebucket}/${copykey}`,
|
|
273
|
+
Key: targetObj.key
|
|
274
|
+
},
|
|
275
|
+
(err: any, data: any) => {
|
|
276
|
+
if (err) {
|
|
277
|
+
console.error(err)
|
|
278
|
+
reject(err)
|
|
279
|
+
} else {
|
|
280
|
+
// console.log(data)
|
|
281
|
+
resolve(targetObj)
|
|
282
|
+
}
|
|
292
283
|
}
|
|
293
|
-
|
|
284
|
+
)
|
|
294
285
|
} else {
|
|
295
286
|
throw Error(`暂不支持${provider?.name}存储类型`)
|
|
296
287
|
}
|
|
297
288
|
})
|
|
298
289
|
}
|
|
299
290
|
|
|
300
|
-
|
|
301
|
-
|
|
302
291
|
export default {
|
|
303
292
|
upload,
|
|
304
293
|
copy
|
|
305
294
|
}
|
|
295
|
+
|
|
296
|
+
export type { IUpload }
|
package/src/spuConfig.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spuAxios } from './axios'
|
|
2
|
+
import { axiosCache } from './axiosCache'
|
|
2
3
|
import { cloneDeep } from 'lodash-es'
|
|
3
4
|
|
|
4
5
|
let modulekey = ''
|
|
@@ -13,12 +14,32 @@ class SpuConfig {
|
|
|
13
14
|
public async getFun(): Promise<any> {
|
|
14
15
|
if (!this.isload) {
|
|
15
16
|
try {
|
|
16
|
-
const res = await spuAxios.post('/lifecycle/getconfigdata', {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
17
|
+
// const res = await spuAxios.post('/lifecycle/getconfigdata', {
|
|
18
|
+
// // modulekey: 'litheformspu'
|
|
19
|
+
// modulekey: modulekey,
|
|
20
|
+
// customerid: customerid,
|
|
21
|
+
// customertype: customertype
|
|
22
|
+
// })
|
|
23
|
+
|
|
24
|
+
const res = await axiosCache(
|
|
25
|
+
{
|
|
26
|
+
strategy: 'default',
|
|
27
|
+
async checkcachesave(res: any) {
|
|
28
|
+
return !!(res.code === 200 && res?.data?.configs)
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
spuAxios,
|
|
32
|
+
{
|
|
33
|
+
url: '/lifecycle/getconfigdata',
|
|
34
|
+
method: 'post',
|
|
35
|
+
data: {
|
|
36
|
+
// modulekey: 'litheformspu'
|
|
37
|
+
modulekey: modulekey,
|
|
38
|
+
customerid: customerid,
|
|
39
|
+
customertype: customertype
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
)
|
|
22
43
|
|
|
23
44
|
// TODO 9.3.3后 res.data中增加extend字段记录额外的数据,也需要返回,这里需要做一个兼容的数据格式
|
|
24
45
|
if (!res?.data?.configs) {
|
|
@@ -57,7 +78,9 @@ class SpuConfig {
|
|
|
57
78
|
|
|
58
79
|
if (dataid) {
|
|
59
80
|
if (Array.isArray(dataid)) {
|
|
60
|
-
return cloneDeep(
|
|
81
|
+
return cloneDeep(
|
|
82
|
+
this.cache.filter((item: any) => dataid.some((item2) => item2 === item.dataid))
|
|
83
|
+
)
|
|
61
84
|
} else {
|
|
62
85
|
return cloneDeep(this.cache.find((item: any) => item.dataid === dataid))
|
|
63
86
|
}
|
package/src/tenantSetting.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { apaasAxios } from './axios'
|
|
2
2
|
import { decrypt } from './crypt'
|
|
3
3
|
import { lsProxy } from './storageProxy'
|
|
4
4
|
|
|
5
5
|
class TenantSetting {
|
|
6
6
|
async requestAndSetTenantSetting(tenantcode?: string) {
|
|
7
7
|
try {
|
|
8
|
-
const res = await
|
|
8
|
+
const res = await apaasAxios.post(
|
|
9
9
|
'/api/auth/tenantsettings',
|
|
10
10
|
{
|
|
11
11
|
tenantcode: tenantcode || ''
|
package/src/types/index.d.ts
CHANGED
|
@@ -53,6 +53,8 @@ interface IDownload {
|
|
|
53
53
|
|
|
54
54
|
interface IDownloadService {
|
|
55
55
|
getUrl: (options: IDownload) => Promise<any>
|
|
56
|
+
getBlob: (options: IDownload) => Promise<any>
|
|
57
|
+
getObjectURL: (options: IDownload) => Promise<string>
|
|
56
58
|
downloadFile: (options: IDownload) => Promise<any>
|
|
57
59
|
}
|
|
58
60
|
|
|
@@ -75,14 +77,16 @@ interface IUploadService {
|
|
|
75
77
|
copy: (options: ICopy) => Promise<any>
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
//
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
export interface IAxiosCacheConfig {
|
|
81
|
+
// 缓存策略 cachestrategy:
|
|
82
|
+
// network-only: 不缓存:仅使用联网数据
|
|
83
|
+
// network-first: 网络优先,缓存数据后,下次请求优先使用联网数据,离线才使用缓存数据
|
|
84
|
+
// cache-first: 缓存优先,缓存数据后,下次请求优先使用缓存数据,使用缓存后如果有联网则依然请求最新数据替换旧缓存【比如剑哥需求文档中的表单协议缓存,则属于此策略】【这个策略下需第二次请求接口才能拿到最新数据】
|
|
85
|
+
// d.如果是 b c,支持配置缓存过期时间
|
|
86
|
+
strategy: 'network-only' | 'cache-first' | 'network-first' | 'default'
|
|
87
|
+
checkcachesave?: any
|
|
88
|
+
cachetime?: number
|
|
89
|
+
}
|
|
86
90
|
|
|
87
91
|
interface ISPUWebPlugin {
|
|
88
92
|
// install (app: App, option: ISPUWebPluginOptions): void
|
|
@@ -110,11 +114,13 @@ export const getAddress: (location: {
|
|
|
110
114
|
latitude: string
|
|
111
115
|
[propName: string]: any
|
|
112
116
|
}) => Promise<string>
|
|
117
|
+
export const normalAxios: any
|
|
113
118
|
export const spuAxios: any
|
|
114
119
|
export const apaasAxios: any
|
|
115
120
|
export const axios: any
|
|
116
121
|
export const decryptAxiosResponseData: any
|
|
117
122
|
export const spuConfig: any
|
|
123
|
+
export const axiosCache: any
|
|
118
124
|
export const globalConfig: any
|
|
119
125
|
export const downloadService: IDownloadService
|
|
120
126
|
export const uploadService: IUploadService
|
|
@@ -129,6 +135,7 @@ export const getUniqueid: () => string
|
|
|
129
135
|
export const getUuid: () => string
|
|
130
136
|
export const functionCheck: (functioncode?: string) => boolean
|
|
131
137
|
export const getServerTime: () => Promise<string>
|
|
138
|
+
export const isOnline: (pingUrl?: string) => Promise<boolean>
|
|
132
139
|
export const encrypt: (str: string) => string
|
|
133
140
|
export const decrypt: (str: string) => string
|
|
134
141
|
export const setTitle: (pagetitle?: string) => void
|
package/src/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getUser } from './login'
|
|
2
2
|
import { urlquery } from './urlquery'
|
|
3
3
|
import { get } from 'lodash-es'
|
|
4
|
-
import {
|
|
4
|
+
import { apaasAxios } from './axios'
|
|
5
5
|
|
|
6
6
|
function isIOS() {
|
|
7
7
|
const ua = navigator.userAgent
|
|
@@ -140,7 +140,7 @@ const getServerTime = () => {
|
|
|
140
140
|
}
|
|
141
141
|
})
|
|
142
142
|
} else {
|
|
143
|
-
|
|
143
|
+
apaasAxios
|
|
144
144
|
.get(
|
|
145
145
|
'/api/teapi/offline/servertime',
|
|
146
146
|
{},
|
|
@@ -162,6 +162,40 @@ const getServerTime = () => {
|
|
|
162
162
|
})
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// 精准判断是否能访问业务服务器(结合 navigator.onLine + 接口请求)
|
|
166
|
+
const isOnline = async (pingUrl = './') => {
|
|
167
|
+
return navigator.onLine
|
|
168
|
+
// // 先判断基础状态,离线则直接返回 false
|
|
169
|
+
// console.log('navigator.onLine', navigator.onLine)
|
|
170
|
+
// if (!navigator.onLine) {
|
|
171
|
+
// return false
|
|
172
|
+
// }
|
|
173
|
+
|
|
174
|
+
// try {
|
|
175
|
+
// // 发送轻量 GET 请求
|
|
176
|
+
// const response = await fetch(pingUrl, {
|
|
177
|
+
// method: 'GET',
|
|
178
|
+
// credentials: 'omit', // 不携带cookies
|
|
179
|
+
// mode: 'cors', // 允许跨域请求,需后端配置 CORS 头部
|
|
180
|
+
// cache: 'no-store' // 禁用缓存,保证实时性
|
|
181
|
+
// // cache: 'default'
|
|
182
|
+
// // signal: AbortSignal.timeout(3000) // 超时取消
|
|
183
|
+
// })
|
|
184
|
+
// console.log('fetch.onLine', response.ok)
|
|
185
|
+
// // console.log(response)
|
|
186
|
+
// // debugger
|
|
187
|
+
// // 只要响应成功(状态码 200-299),则认为在线
|
|
188
|
+
// return response.ok
|
|
189
|
+
// } catch (error) {
|
|
190
|
+
// // 网络错误/超时,认为离线
|
|
191
|
+
// return false
|
|
192
|
+
// }
|
|
193
|
+
}
|
|
194
|
+
// setInterval(async () => {
|
|
195
|
+
// // const a = await isOnline('https://www.baidu.com/')
|
|
196
|
+
// const a = await isOnline()
|
|
197
|
+
// console.log(a)
|
|
198
|
+
// }, 2000)
|
|
165
199
|
|
|
166
200
|
export {
|
|
167
201
|
isIOS,
|
|
@@ -175,5 +209,6 @@ export {
|
|
|
175
209
|
toggleHttpOrHttps,
|
|
176
210
|
importJS,
|
|
177
211
|
delay,
|
|
178
|
-
getServerTime
|
|
212
|
+
getServerTime,
|
|
213
|
+
isOnline
|
|
179
214
|
}
|