@smart100/spu-web-plugin 1.0.0 → 1.0.4
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/README.md +1 -0
- package/dist/index.d.ts +13 -15
- package/dist/spu-web-plugin.mjs +19354 -19345
- package/package.json +2 -2
- package/src/apaasSpuTrack.ts +42 -72
- package/src/axios.ts +136 -132
- package/src/cloudServ.ts +4 -4
- package/src/components/expandexp/index.ts +260 -205
- package/src/core.js +120 -59
- package/src/globalConfig.ts +5 -7
- package/src/index.ts +48 -111
- package/src/location.ts +20 -23
- package/src/login.ts +534 -428
- package/src/nativeApi.ts +7 -10
- package/src/oss/OSSClient.ts +20 -0
- package/src/oss/downloadService.ts +73 -73
- package/src/oss/index.ts +1 -5
- package/src/oss/multiUpload.ts +7 -4
- package/src/oss/servtoken.ts +2 -52
- package/src/oss/uploadService.ts +64 -78
- package/src/spuConfig.ts +7 -10
- package/src/storageProxy.ts +11 -13
- package/src/test.ts +3 -17
- package/src/types/global.d.ts +1 -1
- package/src/types/index.d.ts +13 -15
- package/src/types/shims-lib.d.ts +4 -10
- package/src/urlquery.ts +37 -5
- package/src/utils.ts +15 -31
- package/src/wxworksuitePlugin.ts +25 -0
package/src/spuConfig.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spuAxios } from './
|
|
1
|
+
import { spuAxios } from './axios'
|
|
2
2
|
import { cloneDeep } from 'lodash-es'
|
|
3
3
|
|
|
4
4
|
let modulekey = ''
|
|
@@ -8,7 +8,7 @@ class SpuConfig {
|
|
|
8
8
|
|
|
9
9
|
cache: any[] = []
|
|
10
10
|
|
|
11
|
-
public async getFun
|
|
11
|
+
public async getFun(): Promise<any> {
|
|
12
12
|
if (!this.isload) {
|
|
13
13
|
try {
|
|
14
14
|
const res = await spuAxios.post('/lifecycle/getconfigdata', {
|
|
@@ -29,7 +29,7 @@ class SpuConfig {
|
|
|
29
29
|
|
|
30
30
|
private getPro: any = null
|
|
31
31
|
|
|
32
|
-
public async get
|
|
32
|
+
public async get(dataid?: string | string[]): Promise<any> {
|
|
33
33
|
if (!this.isload) {
|
|
34
34
|
// 兼容同时间发起多个
|
|
35
35
|
if (!this.getPro) {
|
|
@@ -40,7 +40,7 @@ class SpuConfig {
|
|
|
40
40
|
|
|
41
41
|
if (dataid) {
|
|
42
42
|
if (Array.isArray(dataid)) {
|
|
43
|
-
return cloneDeep(this.cache.filter((item: any) =>
|
|
43
|
+
return cloneDeep(this.cache.filter((item: any) => dataid.some((item2) => item2 === item.dataid)))
|
|
44
44
|
} else {
|
|
45
45
|
return cloneDeep(this.cache.find((item: any) => item.dataid === dataid))
|
|
46
46
|
}
|
|
@@ -97,13 +97,10 @@ class SpuConfig {
|
|
|
97
97
|
// }
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
function
|
|
100
|
+
function installSpuConfig(options: any) {
|
|
101
101
|
modulekey = options.modulekey
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const spuConfig =
|
|
104
|
+
const spuConfig = new SpuConfig()
|
|
105
105
|
|
|
106
|
-
export {
|
|
107
|
-
initSpuConfig,
|
|
108
|
-
spuConfig
|
|
109
|
-
}
|
|
106
|
+
export { installSpuConfig, spuConfig }
|
package/src/storageProxy.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
let STORAGENAMESPACE = ''
|
|
2
2
|
|
|
3
3
|
class StorageProxy {
|
|
4
|
-
constructor
|
|
4
|
+
constructor(StorageType: 'local' | 'session' = 'local') {
|
|
5
5
|
this.provider = window[`${StorageType}Storage`]
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
provider
|
|
9
9
|
|
|
10
|
-
getItem
|
|
10
|
+
getItem(key: string) {
|
|
11
11
|
return this.provider.getItem(`${STORAGENAMESPACE ? STORAGENAMESPACE + '-' + key : key}`)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
setItem
|
|
14
|
+
setItem(key: string, value: string) {
|
|
15
15
|
return this.provider.setItem(`${STORAGENAMESPACE ? STORAGENAMESPACE + '-' + key : key}`, value)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
removeItem
|
|
18
|
+
removeItem(key: string) {
|
|
19
19
|
return this.provider.removeItem(`${STORAGENAMESPACE ? STORAGENAMESPACE + '-' + key : key}`)
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
clear
|
|
22
|
+
clear() {
|
|
23
23
|
const namespaceKeys = []
|
|
24
24
|
for (let i = 0, len = this.provider.length; i < len; i++) {
|
|
25
25
|
const item: string | null = this.provider.key(i)
|
|
@@ -33,15 +33,13 @@ class StorageProxy {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
let lsProxy!: StorageProxy
|
|
37
|
+
let ssProxy!: StorageProxy
|
|
38
38
|
|
|
39
|
-
function
|
|
39
|
+
function installStorageProxy(options: any) {
|
|
40
40
|
STORAGENAMESPACE = options.storageproxyprefix || options.modulekey
|
|
41
|
+
lsProxy = new StorageProxy('local')
|
|
42
|
+
ssProxy = new StorageProxy('session')
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
export {
|
|
44
|
-
initStorageProxy,
|
|
45
|
-
lsProxy,
|
|
46
|
-
ssProxy
|
|
47
|
-
}
|
|
45
|
+
export { installStorageProxy, lsProxy, ssProxy }
|
package/src/test.ts
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
3
|
-
// import core, { Module } from './core'
|
|
4
|
-
import { globalOptions, axios, getUser, getToken, getRefreshToken, getTokenExpires, Module } from './index'
|
|
5
|
-
import { get, cloneDeep } from 'lodash-es'
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
async function initTest (options: any) {
|
|
9
|
-
// console.log('initTest')
|
|
1
|
+
async function installTest(options: any) {
|
|
2
|
+
// console.log('installTest')
|
|
10
3
|
// loadding.open()
|
|
11
|
-
|
|
12
|
-
// const envname = await login.getEnvname()
|
|
13
4
|
// console.log(envname)
|
|
14
|
-
|
|
15
5
|
// const coreData = await core.getData()
|
|
16
6
|
// console.log(coreData)
|
|
17
|
-
|
|
18
|
-
|
|
19
7
|
// const apiOrigin = await core.getApiOrigin('expandexp')
|
|
20
8
|
// console.log(apiOrigin)
|
|
21
9
|
}
|
|
22
10
|
|
|
23
|
-
export {
|
|
24
|
-
initTest
|
|
25
|
-
}
|
|
11
|
+
export { installTest }
|
package/src/types/global.d.ts
CHANGED
package/src/types/index.d.ts
CHANGED
|
@@ -12,15 +12,15 @@ interface IAMapLoader {
|
|
|
12
12
|
|
|
13
13
|
type StorageType = 'storage' | 'storage-1d' | 'storage-3m' | 'storage-1y'
|
|
14
14
|
|
|
15
|
-
type Cope = { width?: number
|
|
15
|
+
type Cope = { width?: number; height?: number } | string | boolean
|
|
16
16
|
|
|
17
17
|
interface IDownload {
|
|
18
|
-
type?: 'att' | 'img'
|
|
19
|
-
source: string
|
|
20
|
-
datetime: string | number
|
|
21
|
-
storagetype?: StorageType
|
|
22
|
-
cope?: Cope
|
|
23
|
-
filename?: string
|
|
18
|
+
type?: 'att' | 'img'
|
|
19
|
+
source: string
|
|
20
|
+
datetime: string | number
|
|
21
|
+
storagetype?: StorageType
|
|
22
|
+
cope?: Cope
|
|
23
|
+
filename?: string // 下载文件名
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
interface IDownloadService {
|
|
@@ -29,11 +29,11 @@ interface IDownloadService {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
interface IUpload {
|
|
32
|
-
type?: 'att' | 'img'
|
|
33
|
-
file: File
|
|
34
|
-
source?: string
|
|
35
|
-
datetime?: string | number
|
|
36
|
-
storagetype?: StorageType
|
|
32
|
+
type?: 'att' | 'img'
|
|
33
|
+
file: File
|
|
34
|
+
source?: string
|
|
35
|
+
datetime?: string | number
|
|
36
|
+
storagetype?: StorageType
|
|
37
37
|
onprogress?: (p: number, _checkpoint?: any) => void
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -49,10 +49,9 @@ interface IUploadService {
|
|
|
49
49
|
// router?: any
|
|
50
50
|
// }
|
|
51
51
|
|
|
52
|
-
|
|
53
52
|
interface ISPUWebPlugin {
|
|
54
53
|
// install (app: App, option: ISPUWebPluginOptions): void
|
|
55
|
-
install
|
|
54
|
+
install(app: any, option: any): void
|
|
56
55
|
// install: any
|
|
57
56
|
version: string
|
|
58
57
|
}
|
|
@@ -61,7 +60,6 @@ declare const SPUWebPlugin: ISPUWebPlugin
|
|
|
61
60
|
|
|
62
61
|
export default SPUWebPlugin
|
|
63
62
|
|
|
64
|
-
|
|
65
63
|
export const globalOptions: any
|
|
66
64
|
export const lsProxy: any
|
|
67
65
|
export const ssProxy: any
|
package/src/types/shims-lib.d.ts
CHANGED
|
@@ -6,18 +6,12 @@ declare module '*.vue' {
|
|
|
6
6
|
|
|
7
7
|
declare module 'co'
|
|
8
8
|
declare module 'uuid'
|
|
9
|
-
|
|
10
|
-
|
|
11
9
|
declare module '*.js'
|
|
12
10
|
declare module '*.svg'
|
|
13
11
|
declare module '*.png'
|
|
14
12
|
declare module '*.jpg'
|
|
15
13
|
declare module '*.jpeg'
|
|
16
14
|
declare module '*.gif'
|
|
17
|
-
// declare module '*.bmp'
|
|
18
|
-
// declare module '*.tiff'
|
|
19
|
-
|
|
20
|
-
// declare module 'the-answer'
|
|
21
15
|
|
|
22
16
|
interface Window {
|
|
23
17
|
_AMapSecurityConfig: {
|
|
@@ -25,11 +19,11 @@ interface Window {
|
|
|
25
19
|
}
|
|
26
20
|
// Native Module aPaaS 为 G3 SPU 容器注入的 Native-API
|
|
27
21
|
Native: any
|
|
28
|
-
Module: any
|
|
29
|
-
aPaaS: any
|
|
22
|
+
Module: any
|
|
23
|
+
aPaaS: any
|
|
30
24
|
// 日志插件 和 日志实例
|
|
31
|
-
ApaasSpuTrack: any
|
|
32
|
-
apaasSpuTrack: any
|
|
25
|
+
ApaasSpuTrack: any
|
|
26
|
+
apaasSpuTrack: any
|
|
33
27
|
// wx: IAny;
|
|
34
28
|
// AMapUI: IAny;
|
|
35
29
|
// lsProxy: any;
|
package/src/urlquery.ts
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import VConsole from 'vconsole'
|
|
2
2
|
import { ssProxy } from './storageProxy'
|
|
3
|
+
import { isMobile } from './utils'
|
|
4
|
+
import { getUser } from './login'
|
|
3
5
|
|
|
4
6
|
class Urlquery {
|
|
5
7
|
private isinit = false
|
|
6
8
|
|
|
7
|
-
get isvirtuallocation
|
|
9
|
+
get isvirtuallocation(): boolean {
|
|
8
10
|
return ssProxy.getItem('isvirtuallocation') === '1'
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
get isdebugger
|
|
13
|
+
get isdebugger(): boolean {
|
|
12
14
|
return ssProxy.getItem('isdebugger') === '1'
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
// 获取 web 端引擎是否开了开发者模式
|
|
18
|
+
private getWebDevmodel() {
|
|
19
|
+
let flag = false
|
|
20
|
+
let webSetting: any = window.localStorage.getItem('setting')
|
|
21
|
+
if (webSetting) {
|
|
22
|
+
try {
|
|
23
|
+
webSetting = JSON.parse(webSetting)
|
|
24
|
+
if (webSetting[getUser('tenantcode')]?.devmodel) {
|
|
25
|
+
flag = true
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {
|
|
28
|
+
// console.error(err)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return flag
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 单点登录后 获取 web 开发者模式 如果是则设置 isdebugger
|
|
35
|
+
public dealWebDebugger() {
|
|
36
|
+
if (!this.isdebugger && !isMobile() && this.getWebDevmodel()) {
|
|
37
|
+
ssProxy.setItem('isdebugger', '1')
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public init() {
|
|
16
42
|
if (this.isinit) return false
|
|
17
43
|
|
|
18
44
|
this.isinit = true
|
|
@@ -20,7 +46,9 @@ class Urlquery {
|
|
|
20
46
|
// 调试
|
|
21
47
|
if (location.href.indexOf('isdebugger=1') >= 0 || ssProxy.getItem('isdebugger') === '1') {
|
|
22
48
|
ssProxy.setItem('isdebugger', '1')
|
|
23
|
-
|
|
49
|
+
if (isMobile()) {
|
|
50
|
+
new VConsole({ theme: 'dark' }) /* eslint-disable-line no-new */
|
|
51
|
+
}
|
|
24
52
|
} else {
|
|
25
53
|
ssProxy.setItem('isdebugger', '0')
|
|
26
54
|
}
|
|
@@ -56,4 +84,8 @@ class Urlquery {
|
|
|
56
84
|
|
|
57
85
|
const urlquery = new Urlquery()
|
|
58
86
|
|
|
59
|
-
|
|
87
|
+
function installUrlquery() {
|
|
88
|
+
urlquery.init()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { installUrlquery, urlquery }
|
package/src/utils.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import { getUser } from './
|
|
2
|
-
import urlquery from './urlquery'
|
|
1
|
+
import { getUser } from './login'
|
|
2
|
+
import { urlquery } from './urlquery'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
function isIOS() {
|
|
5
5
|
const ua = navigator.userAgent
|
|
6
6
|
return /(iPhone|iPad|iPod|IOS)/i.test(ua)
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
function isMobile() {
|
|
10
|
+
const ua = navigator.userAgent
|
|
11
|
+
return ua.includes('Mobile')
|
|
12
|
+
}
|
|
13
|
+
|
|
9
14
|
// 生成唯一id
|
|
10
|
-
|
|
15
|
+
function getUniqueid() {
|
|
11
16
|
const random = Math.ceil(Math.random() * 100000)
|
|
12
17
|
// TODO:生成的id不能以0开头,在数据库存储转换长整型会被消除,导致唯一编码错误存储
|
|
13
18
|
// TODO: 不能与服务端返回的idarray在未来产生重叠,用9开头(应该够用许多年了?)
|
|
14
19
|
return `9${Date.now()}${random}`
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
const functionCheck = (functioncode?: string): boolean => {
|
|
22
|
+
function functionCheck(functioncode?: string): boolean {
|
|
19
23
|
if (!functioncode) return false
|
|
20
24
|
const functioncodes = getUser('functioncodes') || []
|
|
21
25
|
// console.log(functioncodes)
|
|
@@ -24,7 +28,7 @@ const functionCheck = (functioncode?: string): boolean => {
|
|
|
24
28
|
return !!check
|
|
25
29
|
}
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
function setTitle(pagetitle?: string) {
|
|
28
32
|
pagetitle = pagetitle || ''
|
|
29
33
|
|
|
30
34
|
// 设置本身
|
|
@@ -43,18 +47,7 @@ const setTitle = (pagetitle?: string) => {
|
|
|
43
47
|
window?.Native?.setNavigationBarTitle && window.Native.setNavigationBarTitle(pagetitle)
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
|
|
47
|
-
// 只有app端才提供原生拍照能力
|
|
48
|
-
if (window?.aPaaS?.getPhoto) {
|
|
49
|
-
return 'app'
|
|
50
|
-
} else if (window?.Module?.spuContainerType) {
|
|
51
|
-
return window.Module.spuContainerType
|
|
52
|
-
} else {
|
|
53
|
-
return ''
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const isInApp = (): boolean => {
|
|
50
|
+
function isInApp(): boolean {
|
|
58
51
|
if (window?.aPaaS?.getPhoto || window?.top?.aPaaS?.getPhoto) {
|
|
59
52
|
return true
|
|
60
53
|
} else {
|
|
@@ -62,21 +55,12 @@ const isInApp = (): boolean => {
|
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
function isdebugger(): boolean {
|
|
66
59
|
return urlquery.isdebugger
|
|
67
60
|
}
|
|
68
61
|
|
|
69
|
-
|
|
62
|
+
function isvirtuallocation(): boolean {
|
|
70
63
|
return urlquery.isvirtuallocation
|
|
71
64
|
}
|
|
72
65
|
|
|
73
|
-
export {
|
|
74
|
-
isIOS,
|
|
75
|
-
getUniqueid,
|
|
76
|
-
functionCheck,
|
|
77
|
-
setTitle,
|
|
78
|
-
getSpuContainerType,
|
|
79
|
-
isInApp,
|
|
80
|
-
isdebugger,
|
|
81
|
-
isvirtuallocation
|
|
82
|
-
}
|
|
66
|
+
export { isIOS, isMobile, getUniqueid, functionCheck, setTitle, isInApp, isdebugger, isvirtuallocation }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WxworksuitePluginInstall,
|
|
3
|
+
jssdk,
|
|
4
|
+
isWxworkSuiteTenant,
|
|
5
|
+
isWxwork,
|
|
6
|
+
isWxworkPc,
|
|
7
|
+
isWxworkApp
|
|
8
|
+
} from '@smart100/wxworksuite-plugin'
|
|
9
|
+
import { getToken } from './login'
|
|
10
|
+
|
|
11
|
+
function installWxworksuitePlugin() {
|
|
12
|
+
WxworksuitePluginInstall({
|
|
13
|
+
getToken: getToken
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const wxworkSuite = {
|
|
18
|
+
JSSDK: jssdk,
|
|
19
|
+
isWxworkSuiteTenant,
|
|
20
|
+
isWxwork,
|
|
21
|
+
isWxworkPc,
|
|
22
|
+
isWxworkApp
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { installWxworksuitePlugin, wxworkSuite }
|