mali-applet-ui 1.1.83 → 1.1.85
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/components/ml-upload/ml-upload.vue +9 -0
- package/package.json +1 -1
- package/tongji/index.js +5 -2
- package/utils/file.js +69 -2
|
@@ -216,6 +216,7 @@ export default {
|
|
|
216
216
|
getThumbnailFileUrl: Function,
|
|
217
217
|
uploadFile: Function,
|
|
218
218
|
removeFile: Function,
|
|
219
|
+
previewFile: Function,
|
|
219
220
|
downloadFile: Function
|
|
220
221
|
},
|
|
221
222
|
inject: {
|
|
@@ -435,6 +436,14 @@ export default {
|
|
|
435
436
|
})
|
|
436
437
|
},
|
|
437
438
|
previewDocs (item) {
|
|
439
|
+
const previewMethod = this.previewFile ? this.previewFile : (globalStore.upload ? globalStore.upload.previewFile : null)
|
|
440
|
+
if (previewMethod) {
|
|
441
|
+
previewMethod({
|
|
442
|
+
item,
|
|
443
|
+
params: this.params
|
|
444
|
+
})
|
|
445
|
+
return
|
|
446
|
+
}
|
|
438
447
|
// 仅支持文档和图片
|
|
439
448
|
if (this.previewTypes.includes(item[this.typeField])) {
|
|
440
449
|
uni.downloadFile({
|
package/package.json
CHANGED
package/tongji/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
if (process.env.
|
|
2
|
-
|
|
1
|
+
if (process.env.NODE_ENV === 'production') {
|
|
2
|
+
if (process.env.VUE_APP_BAIDU_TONGJI_APP_KEY) {
|
|
3
|
+
require('./baidu/mtj-wx-sdk')
|
|
4
|
+
console.log('--- tongji ---', process.env.VUE_APP_BAIDU_TONGJI_APP_KEY)
|
|
5
|
+
}
|
|
3
6
|
}
|
|
4
7
|
|
|
5
8
|
const MaliTongJi = {}
|
package/utils/file.js
CHANGED
|
@@ -14,19 +14,86 @@ export function getFileName (url) {
|
|
|
14
14
|
return urlRest.pathname.split('/').slice(-1)[0] || ''
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export function getAllPreviewTypes () {
|
|
18
|
+
return getFilePreviewTypes().concat(getImagePreviewTypes())
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getFilePreviewTypes () {
|
|
22
|
+
return ['doc', 'xls', 'ppt', 'pdf', 'docx', 'xlsx', 'pptx']
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function getImagePreviewTypes () {
|
|
26
|
+
return ['png', 'jpg', 'gif']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 附件预览
|
|
31
|
+
* @param {*} fileUrl
|
|
32
|
+
* @param {*} name
|
|
33
|
+
* @param {*} options
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export function openFileByUrl (fileUrl, fileName, options) {
|
|
37
|
+
const opts = Object.assign({ type: '' }, options)
|
|
38
|
+
const url = decodeURIComponent(fileUrl)
|
|
39
|
+
const name = fileName || getFileName(url)
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const fileType = opts.type || getFileSuffix(name || getFileName(url)).toLowerCase()
|
|
42
|
+
uni.downloadFile({
|
|
43
|
+
url,
|
|
44
|
+
filePath: name ? `${uni.env.USER_DATA_PATH}/${name.indexOf('.') === -1 ? `${name}.${fileType}` : name}` : '',
|
|
45
|
+
success: (downRes) => {
|
|
46
|
+
if (getFilePreviewTypes().includes(fileType)) {
|
|
47
|
+
uni.openDocument({
|
|
48
|
+
filePath: downRes.filePath || downRes.tempFilePath,
|
|
49
|
+
showMenu: true,
|
|
50
|
+
success () {
|
|
51
|
+
resolve({
|
|
52
|
+
savedFilePath: downRes.filePath || downRes.tempFilePath
|
|
53
|
+
})
|
|
54
|
+
},
|
|
55
|
+
fail (e) {
|
|
56
|
+
reject(e)
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
} else if (getImagePreviewTypes().includes(fileType)) {
|
|
60
|
+
uni.previewImage({
|
|
61
|
+
urls: [
|
|
62
|
+
downRes.filePath || downRes.tempFilePath
|
|
63
|
+
],
|
|
64
|
+
longPressActions: {
|
|
65
|
+
itemList: ['保存图片']
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
} else {
|
|
69
|
+
const e = {}
|
|
70
|
+
reject(e)
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
fail (e) {
|
|
74
|
+
reject(e)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
17
80
|
/**
|
|
18
81
|
* 下载文件
|
|
19
82
|
* @param {*} url
|
|
20
83
|
* @param {*} name
|
|
21
84
|
*/
|
|
22
|
-
export function saveFileByUrl (
|
|
85
|
+
export function saveFileByUrl (fileUrl, fileName, options) {
|
|
23
86
|
const opts = Object.assign({ showMsg: true }, options)
|
|
87
|
+
const url = decodeURIComponent(fileUrl)
|
|
88
|
+
const name = fileName || getFileName(url)
|
|
24
89
|
return new Promise((resolve, reject) => {
|
|
90
|
+
const fileType = opts.type || getFileSuffix(name || getFileName(url)).toLowerCase()
|
|
25
91
|
uni.downloadFile({
|
|
26
92
|
url,
|
|
93
|
+
filePath: name ? `${uni.env.USER_DATA_PATH}/${name.indexOf('.') === -1 ? `${name}.${fileType}` : name}` : '',
|
|
27
94
|
success: (downRes) => {
|
|
28
95
|
uni.saveFile({
|
|
29
|
-
tempFilePath: downRes.tempFilePath,
|
|
96
|
+
tempFilePath: downRes.filePath || downRes.tempFilePath,
|
|
30
97
|
success (res) {
|
|
31
98
|
if (opts.showMsg) {
|
|
32
99
|
uni.showToast({
|