xianniu-ui 0.8.51 → 0.8.53
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/xianniu-ui.common.js +163 -90
- package/lib/xianniu-ui.umd.js +163 -90
- package/lib/xianniu-ui.umd.min.js +7 -7
- package/package.json +1 -1
- package/packages/city/main.vue +17 -20
- package/packages/upload/main.vue +36 -12
- package/src/oss/index.js +90 -99
package/package.json
CHANGED
package/packages/city/main.vue
CHANGED
|
@@ -120,7 +120,6 @@ export default {
|
|
|
120
120
|
const res = this.findParent(_value, this.flattenResult).map(
|
|
121
121
|
(item) => item.cityCode
|
|
122
122
|
);
|
|
123
|
-
console.log("123", res);
|
|
124
123
|
return res;
|
|
125
124
|
}
|
|
126
125
|
},
|
|
@@ -246,28 +245,26 @@ export default {
|
|
|
246
245
|
// });
|
|
247
246
|
// },
|
|
248
247
|
handleChange(code) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
: this.getRes(code);
|
|
248
|
+
// 判断是否是多选
|
|
249
|
+
const isMultiple = Array.isArray(code) && Array.isArray(code[0]);
|
|
252
250
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
this.$emit("on-change", value);
|
|
251
|
+
// 获取变更结果
|
|
252
|
+
const changeResults = (isMultiple ? code : [code]).map(this.getRes);
|
|
258
253
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
city,
|
|
263
|
-
|
|
264
|
-
cityName,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
254
|
+
// 生成 value 和 cityResults
|
|
255
|
+
const [value, cityResults] = changeResults.reduce(
|
|
256
|
+
(acc, res) => {
|
|
257
|
+
const { city, cityCode, cityName, cityCodeLast, cityNameLast } = res;
|
|
258
|
+
acc[0].push(this.valueKey ? code : cityCodeLast);
|
|
259
|
+
acc[1].push({ city, cityCode, cityName, cityCodeLast, cityNameLast });
|
|
260
|
+
return acc;
|
|
261
|
+
},
|
|
262
|
+
[[], []]
|
|
263
|
+
);
|
|
269
264
|
|
|
270
|
-
|
|
265
|
+
// 触发事件
|
|
266
|
+
this.$emit("on-change", isMultiple ? value : value[0]);
|
|
267
|
+
this.$emit("on-city", isMultiple ? cityResults : cityResults[0]);
|
|
271
268
|
},
|
|
272
269
|
// 获取结果
|
|
273
270
|
getRes(cityCode) {
|
package/packages/upload/main.vue
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
v-bind="$attrs"
|
|
14
14
|
:file-list.sync="fileList"
|
|
15
15
|
:http-request="onHttpUpload"
|
|
16
|
-
:on-error="onError"
|
|
17
16
|
:before-upload="onBeforeUpload"
|
|
18
17
|
:style="{ ...styles, ...idCardSizeData }"
|
|
19
18
|
:on-exceed="onExceed"
|
|
@@ -38,7 +37,13 @@
|
|
|
38
37
|
</slot>
|
|
39
38
|
</template>
|
|
40
39
|
|
|
41
|
-
<div
|
|
40
|
+
<div
|
|
41
|
+
slot="file"
|
|
42
|
+
slot-scope="{ file }"
|
|
43
|
+
:class="{
|
|
44
|
+
'xn-upload--slot': ['picture-card', 'idcard'].includes(listType),
|
|
45
|
+
}"
|
|
46
|
+
>
|
|
42
47
|
<template v-if="['list'].includes(listType)">
|
|
43
48
|
<a
|
|
44
49
|
class="el-upload-list__item-name"
|
|
@@ -89,6 +94,7 @@
|
|
|
89
94
|
</template>
|
|
90
95
|
<template v-if="['picture-card', 'idcard'].includes(listType)">
|
|
91
96
|
<uploadPop :file="file" @on-download="handleDownload(file)"></uploadPop>
|
|
97
|
+
<div v-if="file.status === 'fail'">失败</div>
|
|
92
98
|
<template v-if="$utils.isImg(file)">
|
|
93
99
|
<el-image
|
|
94
100
|
class="el-upload-list__item-thumbnail"
|
|
@@ -245,7 +251,6 @@ export default {
|
|
|
245
251
|
imageView: "",
|
|
246
252
|
isHidden: false,
|
|
247
253
|
viewList: [],
|
|
248
|
-
files: [],
|
|
249
254
|
successFiles: [],
|
|
250
255
|
isUploading: false,
|
|
251
256
|
file: {},
|
|
@@ -254,6 +259,8 @@ export default {
|
|
|
254
259
|
idCardSizeData: {},
|
|
255
260
|
isShowAV: false,
|
|
256
261
|
avUrl: "",
|
|
262
|
+
realFileList: [],
|
|
263
|
+
reUploadFile: {},
|
|
257
264
|
};
|
|
258
265
|
},
|
|
259
266
|
computed: {
|
|
@@ -265,11 +272,14 @@ export default {
|
|
|
265
272
|
fileSize() {
|
|
266
273
|
return this.$format.bytesToSize(this.file.size);
|
|
267
274
|
},
|
|
275
|
+
isMultiple() {
|
|
276
|
+
return this.$attrs.multiple;
|
|
277
|
+
},
|
|
268
278
|
},
|
|
269
279
|
watch: {
|
|
270
280
|
fileList: {
|
|
271
281
|
handler(n) {
|
|
272
|
-
this.successFiles = n;
|
|
282
|
+
// this.successFiles = n;
|
|
273
283
|
this.isHidden = this.limit === n.length;
|
|
274
284
|
},
|
|
275
285
|
immediate: true,
|
|
@@ -344,29 +354,43 @@ export default {
|
|
|
344
354
|
});
|
|
345
355
|
},
|
|
346
356
|
onChange(file, fileList) {
|
|
347
|
-
this.
|
|
357
|
+
this.realFileList = fileList;
|
|
348
358
|
},
|
|
349
359
|
async onHttpUpload(file) {
|
|
360
|
+
this.handleUpload(file);
|
|
361
|
+
},
|
|
362
|
+
handleUpload(file) {
|
|
350
363
|
this.isUploading = true;
|
|
351
364
|
this.$emit("on-uploaded", false);
|
|
352
365
|
this.oss
|
|
353
366
|
.upload(file)
|
|
354
367
|
.then((res) => {
|
|
355
368
|
this.successFiles.push(res);
|
|
356
|
-
|
|
369
|
+
|
|
370
|
+
this.realFileList.forEach((item, idx) => {
|
|
371
|
+
if (item.uid === res.file.uid) {
|
|
372
|
+
delete res.file;
|
|
373
|
+
this.$set(this.realFileList, idx, res);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
this.$emit("update:fileList", this.realFileList);
|
|
357
378
|
this.$emit("on-file", this.res);
|
|
358
379
|
this.$emit("on-success", this.successFiles);
|
|
359
380
|
this.$emit("on-uploaded", true);
|
|
360
381
|
this.isUploading = false;
|
|
361
382
|
})
|
|
362
|
-
.catch(() => {
|
|
363
|
-
this.$
|
|
383
|
+
.catch(({ fileName }) => {
|
|
384
|
+
this.$notify.error({
|
|
385
|
+
title: "上传失败",
|
|
386
|
+
dangerouslyUseHTMLString: true,
|
|
387
|
+
message:`<div><p>文件名:</p>${fileName}</div>`,
|
|
388
|
+
});
|
|
364
389
|
});
|
|
365
390
|
},
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
},
|
|
391
|
+
// onError() {
|
|
392
|
+
// this.$message.error("上传失败,请重试");
|
|
393
|
+
// },
|
|
370
394
|
onSubmitUpload() {
|
|
371
395
|
this.$refs.upload.submit();
|
|
372
396
|
},
|
package/src/oss/index.js
CHANGED
|
@@ -1,130 +1,121 @@
|
|
|
1
|
-
const OSS = require('ali-oss')
|
|
2
|
-
import $dayjs from '@/utils/dayjs'
|
|
1
|
+
const OSS = require('ali-oss');
|
|
2
|
+
import $dayjs from '@/utils/dayjs';
|
|
3
3
|
const { v4: uuidv4 } = require('uuid');
|
|
4
|
+
|
|
4
5
|
class Client {
|
|
5
6
|
constructor(params = {}) {
|
|
6
|
-
this.uploadHost = null
|
|
7
|
-
this.stsUrl = params.stsUrl || ''
|
|
8
|
-
this.setFileIdUrl = params.setFileIdUrl || ''
|
|
9
|
-
this.oss = null
|
|
7
|
+
this.uploadHost = null;
|
|
8
|
+
this.stsUrl = params.stsUrl || '';
|
|
9
|
+
this.setFileIdUrl = params.setFileIdUrl || '';
|
|
10
|
+
this.oss = null;
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
getToken() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
token = _token
|
|
19
|
-
}
|
|
14
|
+
try {
|
|
15
|
+
const _token = localStorage.getItem('xnToken');
|
|
16
|
+
return _token ? JSON.parse(_token) : '';
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error('Failed to parse token:', error);
|
|
19
|
+
return '';
|
|
20
20
|
}
|
|
21
|
-
return token
|
|
22
21
|
}
|
|
22
|
+
|
|
23
23
|
getExt(file) {
|
|
24
|
-
|
|
25
|
-
// 判断上传格式
|
|
26
|
-
return `${fileExt}`.toLowerCase();
|
|
24
|
+
return file.name.split('.').pop().toLowerCase();
|
|
27
25
|
}
|
|
26
|
+
|
|
28
27
|
isImg(file) {
|
|
29
|
-
return file.type.
|
|
28
|
+
return file.type.startsWith('image');
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
|
|
31
|
+
isAV(file) {
|
|
32
|
+
return file.type.startsWith('audio') || file.type.startsWith('video');
|
|
33
33
|
}
|
|
34
|
+
|
|
34
35
|
getFileNameUUID() {
|
|
35
|
-
|
|
36
|
-
return uuid
|
|
36
|
+
return uuidv4();
|
|
37
37
|
}
|
|
38
|
-
getStsToken(file) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
if (!this.stsUrl) {
|
|
41
|
-
console.error('获取临时凭证地址不能为空');
|
|
42
|
-
file.onError()
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
38
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
uploadHost,
|
|
53
|
-
bucket,
|
|
54
|
-
region
|
|
55
|
-
}
|
|
56
|
-
this.uploadHost = uploadHost
|
|
57
|
-
this.oss = new OSS({
|
|
58
|
-
...obj,
|
|
59
|
-
})
|
|
60
|
-
resolve(this)
|
|
61
|
-
}).catch((err) => {
|
|
62
|
-
reject(err)
|
|
63
|
-
})
|
|
39
|
+
async getStsToken(file) {
|
|
40
|
+
if (!this.stsUrl) {
|
|
41
|
+
console.error('获取临时凭证地址不能为空');
|
|
42
|
+
file.onError();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
64
45
|
|
|
65
|
-
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(this.stsUrl + '?xnToken=' + this.getToken());
|
|
48
|
+
const res = await response.json();
|
|
49
|
+
const { accessKeyId, accessKeySecret, securityToken: stsToken, uploadHost, bucket, region } = res.data;
|
|
50
|
+
this.uploadHost = uploadHost;
|
|
51
|
+
this.oss = new OSS({
|
|
52
|
+
accessKeyId,
|
|
53
|
+
accessKeySecret,
|
|
54
|
+
stsToken,
|
|
55
|
+
bucket,
|
|
56
|
+
region
|
|
57
|
+
});
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error('获取临时凭证失败:', err);
|
|
60
|
+
throw err;
|
|
61
|
+
}
|
|
66
62
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
|
|
64
|
+
async setFileId(params) {
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(this.setFileIdUrl, {
|
|
70
67
|
method: 'POST',
|
|
71
68
|
headers: {
|
|
72
69
|
'Content-Type': 'application/json',
|
|
73
70
|
'xnToken': this.getToken()
|
|
74
71
|
},
|
|
75
72
|
body: JSON.stringify(params)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.then(({ data }) => {
|
|
84
|
-
resolve(data)
|
|
85
|
-
}).catch((err) => {
|
|
86
|
-
reject(err)
|
|
87
|
-
});
|
|
88
|
-
})
|
|
73
|
+
});
|
|
74
|
+
const { data } = await response.json();
|
|
75
|
+
return data;
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error('设置文件ID失败:', err);
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
89
80
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
|
|
82
|
+
async upload(file, headers = {}) {
|
|
83
|
+
const currentFile = file.file;
|
|
84
|
+
const fileName = currentFile.name;
|
|
85
|
+
const newFileName = this.getFileNameUUID() + '.' + this.getExt(currentFile);
|
|
86
|
+
const path = `accessory/${$dayjs().format('YYYY/MM/DD')}/`;
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
await this.getStsToken(file);
|
|
90
|
+
|
|
91
|
+
const res = await this.oss.multipartUpload(path + newFileName, currentFile, {
|
|
97
92
|
...headers,
|
|
98
|
-
progress(p) {
|
|
99
|
-
const _progress = parseFloat(p * 100)
|
|
93
|
+
progress: (p) => {
|
|
94
|
+
const _progress = parseFloat(p * 100);
|
|
100
95
|
file.onProgress({ percent: _progress });
|
|
101
96
|
}
|
|
102
|
-
})
|
|
103
|
-
file.onSuccess()
|
|
104
|
-
const obj = {
|
|
105
|
-
name: fileName,
|
|
106
|
-
size: currentFile.size,
|
|
107
|
-
ext: this.getExt(currentFile),
|
|
108
|
-
imgFlag: ~~this.isImg(currentFile),
|
|
109
|
-
isAV: ~~this.isAV(currentFile),
|
|
110
|
-
url: this.uploadHost + res.name,
|
|
111
|
-
accessoryName: fileName,
|
|
112
|
-
accessorySize: currentFile.size
|
|
113
|
-
}
|
|
114
|
-
this.setFileId(obj).then((res) => {
|
|
115
|
-
resolve({ ...obj, fileId: res.fileId })
|
|
116
|
-
}).catch((err) => {
|
|
117
|
-
file.onError();
|
|
118
|
-
reject(err)
|
|
119
|
-
})
|
|
97
|
+
});
|
|
120
98
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
99
|
+
const obj = {
|
|
100
|
+
name: fileName,
|
|
101
|
+
size: currentFile.size,
|
|
102
|
+
ext: this.getExt(currentFile),
|
|
103
|
+
imgFlag: Number(this.isImg(currentFile)),
|
|
104
|
+
isAV: Number(this.isAV(currentFile)),
|
|
105
|
+
url: this.uploadHost + res.name,
|
|
106
|
+
accessoryName: fileName,
|
|
107
|
+
accessorySize: currentFile.size
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const fileIdResponse = await this.setFileId(obj);
|
|
111
|
+
file.onSuccess();
|
|
112
|
+
return { ...obj, fileId: fileIdResponse.fileId, file: currentFile };
|
|
113
|
+
} catch (err) {
|
|
114
|
+
file.onError();
|
|
115
|
+
console.error('上传文件失败:', err);
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
126
118
|
}
|
|
127
119
|
}
|
|
128
120
|
|
|
129
|
-
|
|
130
|
-
export default Client
|
|
121
|
+
export default Client;
|