bi-element-ui 1.6.21 → 1.6.22-bata.3
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/lib/bi-element-ui-externals.common.js +1 -1
- package/lib/bi-element-ui-externals.common.js.gz +0 -0
- package/lib/bi-element-ui-externals.umd.min.js +1 -1
- package/lib/bi-element-ui-externals.umd.min.js.gz +0 -0
- package/lib/bi-element-ui.common.js +1 -1
- package/lib/bi-element-ui.common.js.gz +0 -0
- package/lib/bi-element-ui.esm.js +1 -1
- package/lib/bi-element-ui.esm.js.gz +0 -0
- package/lib/bi-element-ui.umd.min.js +1 -1
- package/lib/bi-element-ui.umd.min.js.gz +0 -0
- package/package.json +1 -1
- package/packages/TableHeaderPopper/src/popper.js +6 -15
- package/packages/utils/ossUpload.js +102 -69
|
Binary file
|
package/package.json
CHANGED
|
@@ -25,12 +25,9 @@ export default class HeaderPopper {
|
|
|
25
25
|
system: 'zq',
|
|
26
26
|
api: '/common/table_head/list',
|
|
27
27
|
data: {
|
|
28
|
-
module: this.module
|
|
28
|
+
module: this.module,
|
|
29
|
+
system: this.system,
|
|
29
30
|
},
|
|
30
|
-
headers: {
|
|
31
|
-
System: this.system,
|
|
32
|
-
Authkey: ''
|
|
33
|
-
}
|
|
34
31
|
})
|
|
35
32
|
if (res.status_code === 1) {
|
|
36
33
|
this.editEnabled = res.data.super
|
|
@@ -48,7 +45,8 @@ export default class HeaderPopper {
|
|
|
48
45
|
prop: params.prop,
|
|
49
46
|
label: '',
|
|
50
47
|
content: params.content,
|
|
51
|
-
imgs: params.imgs || []
|
|
48
|
+
imgs: params.imgs || [],
|
|
49
|
+
system: this.system,
|
|
52
50
|
}
|
|
53
51
|
if (params.id) {
|
|
54
52
|
obj.id = params.id
|
|
@@ -58,10 +56,6 @@ export default class HeaderPopper {
|
|
|
58
56
|
system: 'zq',
|
|
59
57
|
api: '/common/table_head/save',
|
|
60
58
|
data: obj,
|
|
61
|
-
headers: {
|
|
62
|
-
System: this.system,
|
|
63
|
-
Authkey: ''
|
|
64
|
-
}
|
|
65
59
|
}).then((res) => {
|
|
66
60
|
if (res.status_code === 1) {
|
|
67
61
|
resolve()
|
|
@@ -77,12 +71,9 @@ export default class HeaderPopper {
|
|
|
77
71
|
system: 'zq',
|
|
78
72
|
api: '/common/table_head/del',
|
|
79
73
|
data: {
|
|
80
|
-
id
|
|
74
|
+
id,
|
|
75
|
+
system: this.system,
|
|
81
76
|
},
|
|
82
|
-
headers: {
|
|
83
|
-
System: this.system,
|
|
84
|
-
Authkey: ''
|
|
85
|
-
}
|
|
86
77
|
})
|
|
87
78
|
}
|
|
88
79
|
}
|
|
@@ -2,91 +2,122 @@ import OSS from 'ali-oss'
|
|
|
2
2
|
import { getSystem, getEnv, randomStr } from './tools'
|
|
3
3
|
import request from './request/index.js'
|
|
4
4
|
import moment from 'moment'
|
|
5
|
+
|
|
6
|
+
// 公共访问域名(与后端 endpoint 一致)
|
|
7
|
+
const OSS_BASE_URL = 'https://pigeon-oss.wozhangwan.com'
|
|
8
|
+
const OSS_REGION = 'oss-cn-hangzhou'
|
|
9
|
+
// STS 后端约定 900s 有效,提前 60s 过期
|
|
10
|
+
const STS_TTL_MS = 840 * 1000
|
|
11
|
+
|
|
12
|
+
let stsPromise = null
|
|
13
|
+
let stsFetchedAt = 0
|
|
14
|
+
|
|
15
|
+
function fetchStsToken(env, system) {
|
|
16
|
+
return request({
|
|
17
|
+
env,
|
|
18
|
+
system: 'zq',
|
|
19
|
+
api: '/common/oss/stsToken',
|
|
20
|
+
headers: {
|
|
21
|
+
System: system
|
|
22
|
+
}
|
|
23
|
+
}).then((result) => {
|
|
24
|
+
if (!result || result.status_code !== 1) {
|
|
25
|
+
throw new Error((result && result.msg) || '获取上传凭证失败')
|
|
26
|
+
}
|
|
27
|
+
return result.data || {}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getStsCredentials(env, system) {
|
|
32
|
+
if (stsPromise && Date.now() - stsFetchedAt < STS_TTL_MS) {
|
|
33
|
+
return stsPromise
|
|
34
|
+
}
|
|
35
|
+
stsFetchedAt = Date.now()
|
|
36
|
+
stsPromise = fetchStsToken(env, system).catch((err) => {
|
|
37
|
+
stsPromise = null
|
|
38
|
+
throw err
|
|
39
|
+
})
|
|
40
|
+
return stsPromise
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function clearOssStsCache() {
|
|
44
|
+
stsPromise = null
|
|
45
|
+
stsFetchedAt = 0
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function joinUrl(base, key) {
|
|
49
|
+
const b = String(base || '').replace(/\/+$/, '')
|
|
50
|
+
const k = String(key || '').replace(/^\/+/, '')
|
|
51
|
+
return `${b}/${k}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 仅允许上传到 table_head/*(与收窄后 STS policy 对齐)
|
|
55
|
+
function buildKey(env, dir) {
|
|
56
|
+
const envPart = env === 'production' ? 'production' : 'staging'
|
|
57
|
+
const rawDir = String(dir || '').replace(/^\/+|\/+$/g, '')
|
|
58
|
+
const fileName = randomStr(16)
|
|
59
|
+
return rawDir
|
|
60
|
+
? `table_head/${envPart}/${rawDir}/${fileName}`
|
|
61
|
+
: `table_head/${envPart}/${fileName}`
|
|
62
|
+
}
|
|
63
|
+
|
|
5
64
|
export default function ossUpload(file, config, progressCallback) {
|
|
6
65
|
const system = getSystem()
|
|
7
66
|
const $BiEnv = getEnv()
|
|
8
67
|
|
|
9
|
-
// const baseUrl = getServiceURL('zhangquan', $BiEnv || '')
|
|
10
68
|
const configImg = {
|
|
11
69
|
dir: '',
|
|
12
|
-
region:
|
|
70
|
+
region: OSS_REGION,
|
|
13
71
|
file: null,
|
|
14
72
|
date: moment().format('YYYYMMDD'),
|
|
15
73
|
str: '',
|
|
16
74
|
ext: null,
|
|
17
75
|
secure: true,
|
|
18
|
-
pact: 'https://'
|
|
76
|
+
pact: 'https://'
|
|
19
77
|
}
|
|
20
78
|
const _config = Object.assign({}, configImg, config)
|
|
21
79
|
_config.file = file
|
|
22
80
|
_config.ext = file.name.slice(file.name.lastIndexOf('.') + 1)
|
|
23
81
|
|
|
82
|
+
// 旧实现 key 会拼扩展名;randomStr 已含随机段,这里补上 ext
|
|
83
|
+
const baseKeyWithoutExt = buildKey($BiEnv, _config.dir)
|
|
84
|
+
const objectKey = `${baseKeyWithoutExt}.${_config.ext}`
|
|
85
|
+
|
|
24
86
|
return new Promise(function (resolve, reject) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
accessKeySecret,
|
|
45
|
-
stsToken: securityToken,
|
|
46
|
-
bucket,
|
|
47
|
-
secure: true,
|
|
48
|
-
endpoint,
|
|
49
|
-
cname: true,
|
|
50
|
-
refreshSTSTokenInterval: 300000,
|
|
51
|
-
refreshSTSToken: async () => {
|
|
52
|
-
// request({
|
|
53
|
-
// url: baseUrl + '/common/oss/stsToken',
|
|
54
|
-
// method: 'post',
|
|
55
|
-
// headers: {
|
|
56
|
-
// System: system
|
|
57
|
-
// }
|
|
58
|
-
// })
|
|
59
|
-
const refreshToken = await request({
|
|
60
|
-
env: $BiEnv,
|
|
61
|
-
system: 'zq',
|
|
62
|
-
api: '/common/oss/stsToken',
|
|
63
|
-
headers: {
|
|
64
|
-
System: system
|
|
87
|
+
getStsCredentials($BiEnv, system)
|
|
88
|
+
.then((sts) => {
|
|
89
|
+
const client = new OSS({
|
|
90
|
+
region: _config.region,
|
|
91
|
+
accessKeyId: sts.accessKeyId,
|
|
92
|
+
accessKeySecret: sts.accessKeySecret,
|
|
93
|
+
stsToken: sts.securityToken,
|
|
94
|
+
bucket: sts.bucket,
|
|
95
|
+
secure: true,
|
|
96
|
+
endpoint: sts.endpoint || OSS_BASE_URL,
|
|
97
|
+
cname: true,
|
|
98
|
+
refreshSTSTokenInterval: 300000,
|
|
99
|
+
refreshSTSToken: async () => {
|
|
100
|
+
clearOssStsCache()
|
|
101
|
+
const refreshToken = await getStsCredentials($BiEnv, system)
|
|
102
|
+
return {
|
|
103
|
+
accessKeyId: refreshToken.accessKeyId,
|
|
104
|
+
accessKeySecret: refreshToken.accessKeySecret,
|
|
105
|
+
stsToken: refreshToken.securityToken
|
|
65
106
|
}
|
|
66
|
-
})
|
|
67
|
-
return {
|
|
68
|
-
accessKeyId: refreshToken.data.accessKeyId,
|
|
69
|
-
accessKeySecret: refreshToken.data.accessKeySecret,
|
|
70
|
-
stsToken: refreshToken.data.securityToken
|
|
71
107
|
}
|
|
108
|
+
})
|
|
109
|
+
const options = {
|
|
110
|
+
progress: (p, cpt, res) => {
|
|
111
|
+
progressCallback && progressCallback(p, cpt, res)
|
|
112
|
+
},
|
|
113
|
+
parallel: 4
|
|
72
114
|
}
|
|
73
|
-
|
|
74
|
-
const fileName = randomStr(16) + '.' + _config.ext
|
|
75
|
-
const options = {
|
|
76
|
-
progress: (p, cpt, res) => {
|
|
77
|
-
progressCallback && progressCallback(p, cpt, res)
|
|
78
|
-
},
|
|
79
|
-
parallel: 4
|
|
80
|
-
// partSize: 1024 * 1024 * 100
|
|
81
|
-
}
|
|
82
|
-
client
|
|
83
|
-
.multipartUpload('/table_head' + ($BiEnv === 'production' ? '/production' : '/staging') + _config.dir + fileName, _config.file, options)
|
|
84
|
-
.then((res) => {
|
|
115
|
+
return client.multipartUpload(objectKey, _config.file, options).then((res) => {
|
|
85
116
|
if (res.res.status === 200) {
|
|
86
117
|
resolve({
|
|
87
118
|
status_code: 1,
|
|
88
119
|
msg: '上传成功',
|
|
89
|
-
data: endpoint
|
|
120
|
+
data: joinUrl(sts.endpoint || OSS_BASE_URL, res.name || objectKey),
|
|
90
121
|
config: _config
|
|
91
122
|
})
|
|
92
123
|
} else {
|
|
@@ -98,14 +129,16 @@ export default function ossUpload(file, config, progressCallback) {
|
|
|
98
129
|
})
|
|
99
130
|
}
|
|
100
131
|
})
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
132
|
+
})
|
|
133
|
+
.catch((err) => {
|
|
134
|
+
// 凭证/STS 类失败清缓存,由调用方决定是否重试
|
|
135
|
+
clearOssStsCache()
|
|
136
|
+
reject({
|
|
137
|
+
status_code: -1,
|
|
138
|
+
msg: (err && err.message) || '上传失败',
|
|
139
|
+
data: err,
|
|
140
|
+
config: _config
|
|
108
141
|
})
|
|
109
|
-
|
|
142
|
+
})
|
|
110
143
|
})
|
|
111
144
|
}
|