xianniu-ui 0.6.1 → 0.6.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/lib/xianniu-ui.common.js +305 -88
- package/lib/xianniu-ui.umd.js +305 -88
- package/lib/xianniu-ui.umd.min.js +3 -3
- package/package.json +1 -1
- package/packages/city/main.vue +13 -8
- package/packages/upload/main.vue +2 -15
- package/src/oss/index.js +39 -5
- package/src/utils/utils.js +16 -20
package/package.json
CHANGED
package/packages/city/main.vue
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
19
|
<script>
|
|
20
|
-
const ZXCITY = [
|
|
20
|
+
const ZXCITY = ["北京市", "天津市", "上海市", "重庆市"];
|
|
21
21
|
import citys from "xn-ui/src/area/index.js";
|
|
22
22
|
export default {
|
|
23
23
|
name: "XnCity",
|
|
@@ -251,19 +251,24 @@ export default {
|
|
|
251
251
|
getCity(data, nameList) {
|
|
252
252
|
if (nameList.length === 0) return [];
|
|
253
253
|
const [cityName, ...rest] = nameList;
|
|
254
|
-
const item =
|
|
255
|
-
|
|
254
|
+
const item =
|
|
255
|
+
data &&
|
|
256
|
+
data.find((i) => i.cityName === cityName || cityName.indexOf(i.cityName) > -1);
|
|
257
|
+
if (item) {
|
|
256
258
|
return [item.cityCode, ...this.getCity(item.subCitys, rest)];
|
|
257
|
-
}else{
|
|
258
|
-
return [...this.getCity([], rest)]
|
|
259
|
+
} else {
|
|
260
|
+
return [...this.getCity([], rest)];
|
|
259
261
|
}
|
|
260
262
|
},
|
|
261
263
|
str2Code(val) {
|
|
262
264
|
if (!val) return;
|
|
265
|
+
val = val.replace(/[^\u4e00-\u9fa5]/g, "");
|
|
263
266
|
const cityArr = val.match(this.$reg.getCity) || [];
|
|
264
|
-
const newarr =
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
const newarr =
|
|
268
|
+
cityArr.length &&
|
|
269
|
+
cityArr.map((item, idx, arr) => {
|
|
270
|
+
return ZXCITY.includes(item) && idx === 0 ? [item, ...arr] : arr;
|
|
271
|
+
})[0];
|
|
267
272
|
const arr = this.getCity(this.cityList, newarr);
|
|
268
273
|
return arr[arr.length - 1];
|
|
269
274
|
},
|
package/packages/upload/main.vue
CHANGED
|
@@ -178,6 +178,7 @@ export default {
|
|
|
178
178
|
created() {
|
|
179
179
|
this.client = new Client({
|
|
180
180
|
stsUrl: this.$XN.stsUrl || "",
|
|
181
|
+
setFileIdUrl: this.$XN.setFileIdUrl || "",
|
|
181
182
|
});
|
|
182
183
|
},
|
|
183
184
|
beforeDestroy() {
|
|
@@ -276,21 +277,7 @@ export default {
|
|
|
276
277
|
},
|
|
277
278
|
async handleDownload(file) {
|
|
278
279
|
const { url, name } = file;
|
|
279
|
-
|
|
280
|
-
x.open("GET", url, true);
|
|
281
|
-
x.responseType = "blob";
|
|
282
|
-
x.onload = function () {
|
|
283
|
-
const _url = window.URL.createObjectURL(x.response);
|
|
284
|
-
const elt = document.createElement("a");
|
|
285
|
-
elt.setAttribute("href", _url);
|
|
286
|
-
elt.setAttribute("download", name);
|
|
287
|
-
elt.style.display = "none";
|
|
288
|
-
elt.target = "_blank";
|
|
289
|
-
document.body.appendChild(elt);
|
|
290
|
-
elt.click();
|
|
291
|
-
document.body.removeChild(elt);
|
|
292
|
-
};
|
|
293
|
-
x.send();
|
|
280
|
+
return this.$utils.download({url, name})
|
|
294
281
|
},
|
|
295
282
|
handleRemove(file, fileList) {
|
|
296
283
|
fileList.forEach((item, idx) => {
|
package/src/oss/index.js
CHANGED
|
@@ -6,6 +6,7 @@ class Client {
|
|
|
6
6
|
constructor(params = {}) {
|
|
7
7
|
this.uploadHost = null
|
|
8
8
|
this.stsUrl = params.stsUrl || ''
|
|
9
|
+
this.setFileIdUrl = params.setFileIdUrl || ''
|
|
9
10
|
this.oss = null
|
|
10
11
|
}
|
|
11
12
|
getToken() {
|
|
@@ -26,7 +27,7 @@ class Client {
|
|
|
26
27
|
return `${fileExt}`.toLowerCase();
|
|
27
28
|
}
|
|
28
29
|
isImg(file) {
|
|
29
|
-
return
|
|
30
|
+
return file.type.indexOf('image') > -1
|
|
30
31
|
}
|
|
31
32
|
getFileNameUUID() {
|
|
32
33
|
const uuid = uuidv4()
|
|
@@ -37,6 +38,7 @@ class Client {
|
|
|
37
38
|
if (!this.stsUrl) {
|
|
38
39
|
return console.error('获取临时凭证地址不能为空')
|
|
39
40
|
}
|
|
41
|
+
|
|
40
42
|
fetch(this.stsUrl + '?xnToken=' + this.getToken()).then(response => response.json()).then((res) => {
|
|
41
43
|
const { data: { accessKeyId, accessKeySecret, securityToken: stsToken, uploadHost, bucket, region } } = res
|
|
42
44
|
const obj = {
|
|
@@ -47,7 +49,7 @@ class Client {
|
|
|
47
49
|
bucket,
|
|
48
50
|
region
|
|
49
51
|
}
|
|
50
|
-
|
|
52
|
+
this.uploadHost = uploadHost
|
|
51
53
|
this.oss = new OSS({
|
|
52
54
|
...obj,
|
|
53
55
|
})
|
|
@@ -58,6 +60,29 @@ class Client {
|
|
|
58
60
|
|
|
59
61
|
})
|
|
60
62
|
}
|
|
63
|
+
setFileId(params) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
fetch(this.setFileIdUrl, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json',
|
|
69
|
+
'xnToken': this.getToken()
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(params)
|
|
72
|
+
})
|
|
73
|
+
.then(response => {
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
76
|
+
}
|
|
77
|
+
return response.json()
|
|
78
|
+
})
|
|
79
|
+
.then(({ data }) => {
|
|
80
|
+
resolve(data)
|
|
81
|
+
}).catch((err) => {
|
|
82
|
+
reject(err)
|
|
83
|
+
});
|
|
84
|
+
})
|
|
85
|
+
}
|
|
61
86
|
upload(file, headers = {}) {
|
|
62
87
|
const currentFile = file.file
|
|
63
88
|
const fileName = currentFile.name
|
|
@@ -70,16 +95,25 @@ class Client {
|
|
|
70
95
|
const _progress = parseFloat(p * 100)
|
|
71
96
|
file.onProgress({ percent: _progress });
|
|
72
97
|
}
|
|
73
|
-
}).then(res => {
|
|
98
|
+
}).then(async res => {
|
|
74
99
|
file.onSuccess()
|
|
75
100
|
const obj = {
|
|
76
101
|
name: fileName,
|
|
77
102
|
size: currentFile.size,
|
|
78
103
|
ext: this.getExt(currentFile),
|
|
79
|
-
imgFlag: this.isImg(currentFile),
|
|
104
|
+
imgFlag: ~~this.isImg(currentFile),
|
|
80
105
|
url: this.uploadHost + res.name,
|
|
106
|
+
accessoryName: fileName,
|
|
107
|
+
accessorySize: currentFile.size
|
|
81
108
|
}
|
|
82
|
-
|
|
109
|
+
this.setFileId(obj).then((res) => {
|
|
110
|
+
resolve({ ...obj, fileId: res.fileId })
|
|
111
|
+
}).catch((err) => {
|
|
112
|
+
console.log('err: ', err);
|
|
113
|
+
file.onError();
|
|
114
|
+
reject(err)
|
|
115
|
+
})
|
|
116
|
+
|
|
83
117
|
}).catch(err => {
|
|
84
118
|
file.onError();
|
|
85
119
|
reject(err)
|
package/src/utils/utils.js
CHANGED
|
@@ -65,27 +65,23 @@ const download = (params = { name: '', url: '' }) => {
|
|
|
65
65
|
name: '下载模板'
|
|
66
66
|
}
|
|
67
67
|
const _params = Object.assign(defaultParams, params)
|
|
68
|
+
console.log('_params: ', _params);
|
|
68
69
|
const { url, name } = _params
|
|
69
|
-
|
|
70
|
-
x.open(
|
|
71
|
-
|
|
72
|
-
// x.responseType = 'blob'
|
|
73
|
-
x.onprogress = function () {
|
|
74
|
-
}
|
|
70
|
+
const x = new XMLHttpRequest();
|
|
71
|
+
x.open("GET", url, true);
|
|
72
|
+
x.responseType = "blob";
|
|
75
73
|
x.onload = function () {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
x.send()
|
|
74
|
+
const _url = window.URL.createObjectURL(x.response);
|
|
75
|
+
const elt = document.createElement("a");
|
|
76
|
+
elt.setAttribute("href", _url);
|
|
77
|
+
elt.setAttribute("download", name);
|
|
78
|
+
elt.style.display = "none";
|
|
79
|
+
elt.target = "_blank";
|
|
80
|
+
document.body.appendChild(elt);
|
|
81
|
+
elt.click();
|
|
82
|
+
document.body.removeChild(elt);
|
|
83
|
+
};
|
|
84
|
+
x.send();
|
|
89
85
|
}
|
|
90
86
|
/**
|
|
91
87
|
* 根据某个key 对数组去重合并
|
|
@@ -97,7 +93,7 @@ const arrMerge = (arr = [], key = '') => {
|
|
|
97
93
|
if (!key) {
|
|
98
94
|
throw new Error('error arguments: key is required')
|
|
99
95
|
}
|
|
100
|
-
if(!arr.length) return
|
|
96
|
+
if (!arr.length) return
|
|
101
97
|
var map = {}; var result = []
|
|
102
98
|
|
|
103
99
|
for (var i = 0; i < arr.length; i++) {
|