From ec90cbd7680a6f927cb1cea43f33ab7df6d0864c Mon Sep 17 00:00:00 2001
From: zhangwei <1504152376@qq.com>
Date: 星期二, 11 十一月 2025 09:23:22 +0800
Subject: [PATCH] -
---
src/components/tem/tem-upload-file.vue | 299 +++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 187 insertions(+), 112 deletions(-)
diff --git a/src/components/tem/tem-upload-file.vue b/src/components/tem/tem-upload-file.vue
index d49b47b..2ae0b56 100644
--- a/src/components/tem/tem-upload-file.vue
+++ b/src/components/tem/tem-upload-file.vue
@@ -33,7 +33,7 @@
:style="{width:width+'rpx',borderRadius:radius+'rpx',borderColor:borderColor,borderStyle:borderSytle}"
v-if="showAdd" @tap.stop="chooseImage">
<slot>
- <u-button type="primary" text="涓婁紶" size="small"></u-button>
+ <u-button type="primary" :text="btnText" size="small"></u-button>
<!-- <fui-icon name="plus" :size="addSize" :color="addColor"></fui-icon> -->
</slot>
</view>
@@ -58,13 +58,17 @@
// fuiIcon
// },
props: {
+ btnText: {
+ type: String,
+ default: '涓婁紶'
+ },
width: {
type: [Number, String],
- default: 200
+ default: 190
},
height: {
type: [Number, String],
- default: 200
+ default: 190
},
fileList: {
type: Array,
@@ -140,6 +144,12 @@
type: Array,
default () {
return ['album', 'camera']
+ }
+ },
+ isSource: {
+ type: Boolean,
+ default () {
+ return false
}
},
//鍥剧墖鍚庣紑鍚嶉檺鍒�
@@ -311,69 +321,134 @@
'success_action_status': "200" //涓婁紶鎴愬姛鍚庡搷搴旂姸鎬佺爜
}
})
- wx.chooseMessageFile({
- count: max === -1 ? 9 : max - this.urls.length,
- type: this.fileType,
- success: (e) => {
- let imageArr = [];
- for (let i = 0; i < e.tempFiles.length; i++) {
- let len = this.urls.length;
- if (len >= max && max !== -1) {
- this.toast(`鏈�澶氬彲涓婁紶${max}涓枃浠禶);
- break;
- }
- //杩囨护鏂囦欢绫诲瀷
- let path = e.tempFiles[i].path;
- if (this.suffix.length > 0) {
- let format = ""
- // #ifdef H5
- let type = e.tempFiles[i].type;
- format = type.split('/')[1]
- console.log(format, 'eeeeeeeeeeeeee鈥�');
- // #endif
+ if (this.isSource) {
+ uni.chooseImage({
+ count: max === -1 ? 9 : max - this.urls.length,
+ sizeType: this.sizeType,
+ sourceType: this.sourceType,
+ success: (e) => {
+ let imageArr = [];
+ for (let i = 0; i < e.tempFiles.length; i++) {
+ let len = this.urls.length;
+ if (len >= max && max !== -1) {
+ this.toast(`鏈�澶氬彲涓婁紶${max}寮犲浘鐗嘸);
+ break;
+ }
+ //杩囨护鍥剧墖绫诲瀷
+ let path = e.tempFiles[i].path;
- // #ifndef H5
- format = path.split(".")[(path.split(".")).length - 1];
- // #endif
- console.log(format);
- if (this.suffix.indexOf(format) == -1) {
- // let text = `鍙兘涓婁紶 ${this.suffix.join(',')} 鏍煎紡锛乣
- let text = `鍙兘涓婁紶 doc锛宒ocx锛宲df 鏍煎紡锛乣
- this.toast(text);
+ if (this.suffix.length > 0) {
+ let format = ""
+ // #ifdef H5
+ let type = e.tempFiles[i].type;
+ format = type.split('/')[1]
+ // #endif
+
+ // #ifndef H5
+ format = path.split(".")[(path.split(".")).length - 1];
+ // #endif
+
+ if (this.suffix.indexOf(format) == -1) {
+ let text = `鍙兘涓婁紶 ${this.suffix.join(',')} 鏍煎紡鍥剧墖锛乣
+ this.toast(text);
+ continue;
+ }
+ }
+
+ //杩囨护瓒呭嚭澶у皬闄愬埗鍥剧墖
+ let size = e.tempFiles[i].size;
+
+ if (Number(this.size) * 1024 * 1024 < size) {
+ let err = `鍗曞紶鍥剧墖澶у皬涓嶈兘瓒呰繃锛�${this.size}MB`
+ this.toast(err);
continue;
}
+ imageArr.push(path)
+ this.urls.push(path)
+ this.tempFiles.push(e.tempFiles[i])
+ this.status.push(this.immediate ? 'uploading' : 'preupload')
}
-
- //杩囨护瓒呭嚭澶у皬闄愬埗鍥剧墖
- let size = e.tempFiles[i].size;
-
- if (Number(this.size) * 1024 * 1024 < size) {
- let err = `鏂囦欢澶у皬涓嶈兘瓒呰繃锛�${this.size}MB`
- this.toast(err);
- continue;
- }
- imageArr.push(path)
- this.urls.push(path)
- this.tempFiles.push(e.tempFiles[i])
- this.status.push(this.immediate ? 'uploading' : 'preupload')
- }
- this.onComplete('choose')
- let start = this.urls.length - imageArr.length
- if (this.immediate) {
- for (let j = 0; j < imageArr.length; j++) {
- let index = start + j
- let obj = JSON.parse(JSON.stringify(this.formDataNew))
- obj.key = this.$util.generateTimestampWithRandom(imageArr[j])
- this.uploadImage(index, imageArr[j], null, obj).then((res) => {
- this._success(res)
- }).catch((res) => {
- this._error(res)
- })
+ this.onComplete('choose')
+ let start = this.urls.length - imageArr.length
+ if (this.immediate) {
+ for (let j = 0; j < imageArr.length; j++) {
+ let index = start + j
+ let obj = JSON.parse(JSON.stringify(this.formDataNew))
+ obj.key = this.$util.generateTimestampWithRandom(imageArr[j])
+ this.uploadImage(index, imageArr[j], null, obj).then((res) => {
+ this._success(res)
+ }).catch((res) => {
+ this._error(res)
+ })
+ }
}
}
- },
- fail: () => {}
- })
+ })
+ } else {
+ wx.chooseMessageFile({
+ count: max === -1 ? 9 : max - this.urls.length,
+ type: this.fileType,
+ success: (e) => {
+ let imageArr = [];
+ for (let i = 0; i < e.tempFiles.length; i++) {
+ let len = this.urls.length;
+ if (len >= max && max !== -1) {
+ this.toast(`鏈�澶氬彲涓婁紶${max}涓枃浠禶);
+ break;
+ }
+ //杩囨护鏂囦欢绫诲瀷
+ let path = e.tempFiles[i].path;
+ if (this.suffix.length > 0) {
+ let format = ""
+ // #ifdef H5
+ let type = e.tempFiles[i].type;
+ format = type.split('/')[1]
+ console.log(format, 'eeeeeeeeeeeeee鈥�');
+ // #endif
+
+ // #ifndef H5
+ format = path.split(".")[(path.split(".")).length - 1];
+ // #endif
+ console.log(format);
+ if (this.suffix.indexOf(format) == -1) {
+ let text = `鍙兘涓婁紶 ${this.suffix.join(',')} 鏍煎紡锛乣
+ this.toast(text);
+ continue;
+ }
+ }
+
+ //杩囨护瓒呭嚭澶у皬闄愬埗鍥剧墖
+ let size = e.tempFiles[i].size;
+
+ if (Number(this.size) * 1024 * 1024 < size) {
+ let err = `鏂囦欢澶у皬涓嶈兘瓒呰繃锛�${this.size}MB`
+ this.toast(err);
+ continue;
+ }
+ imageArr.push(path)
+ this.urls.push(path)
+ this.tempFiles.push(e.tempFiles[i])
+ this.status.push(this.immediate ? 'uploading' : 'preupload')
+ }
+ this.onComplete('choose')
+ let start = this.urls.length - imageArr.length
+ if (this.immediate) {
+ for (let j = 0; j < imageArr.length; j++) {
+ let index = start + j
+ let obj = JSON.parse(JSON.stringify(this.formDataNew))
+ obj.key = this.$util.generateTimestampWithRandom(imageArr[j])
+ this.uploadImage(index, imageArr[j], null, obj).then((res) => {
+ this._success(res)
+ }).catch((res) => {
+ this._error(res)
+ })
+ }
+ }
+ },
+ fail: () => {}
+ })
+ }
+
// uni.chooseFile({
// count: max === -1 ? 9 : max - this.urls.length,
// extension: ['.doc', '.pdf', '.docx'],
@@ -437,66 +512,66 @@
},
// chooseImage() {
// let max = Number(this.max)
- // uni.chooseImage({
- // count: max === -1 ? 9 : max - this.urls.length,
- // sizeType: this.sizeType,
- // sourceType: this.sourceType,
- // success: (e) => {
- // let imageArr = [];
- // for (let i = 0; i < e.tempFiles.length; i++) {
- // let len = this.urls.length;
- // if (len >= max && max !== -1) {
- // this.toast(`鏈�澶氬彲涓婁紶${max}寮犲浘鐗嘸);
- // break;
- // }
- // //杩囨护鍥剧墖绫诲瀷
- // let path = e.tempFiles[i].path;
+ // uni.chooseImage({
+ // count: max === -1 ? 9 : max - this.urls.length,
+ // sizeType: this.sizeType,
+ // sourceType: this.sourceType,
+ // success: (e) => {
+ // let imageArr = [];
+ // for (let i = 0; i < e.tempFiles.length; i++) {
+ // let len = this.urls.length;
+ // if (len >= max && max !== -1) {
+ // this.toast(`鏈�澶氬彲涓婁紶${max}寮犲浘鐗嘸);
+ // break;
+ // }
+ // //杩囨护鍥剧墖绫诲瀷
+ // let path = e.tempFiles[i].path;
- // if (this.suffix.length > 0) {
- // let format = ""
- // // #ifdef H5
- // let type = e.tempFiles[i].type;
- // format = type.split('/')[1]
- // // #endif
+ // if (this.suffix.length > 0) {
+ // let format = ""
+ // // #ifdef H5
+ // let type = e.tempFiles[i].type;
+ // format = type.split('/')[1]
+ // // #endif
- // // #ifndef H5
- // format = path.split(".")[(path.split(".")).length - 1];
- // // #endif
+ // // #ifndef H5
+ // format = path.split(".")[(path.split(".")).length - 1];
+ // // #endif
- // if (this.suffix.indexOf(format) == -1) {
- // let text = `鍙兘涓婁紶 ${this.suffix.join(',')} 鏍煎紡鍥剧墖锛乣
- // this.toast(text);
- // continue;
- // }
- // }
-
- // //杩囨护瓒呭嚭澶у皬闄愬埗鍥剧墖
- // let size = e.tempFiles[i].size;
-
- // if (Number(this.size) * 1024 * 1024 < size) {
- // let err = `鍗曞紶鍥剧墖澶у皬涓嶈兘瓒呰繃锛�${this.size}MB`
- // this.toast(err);
+ // if (this.suffix.indexOf(format) == -1) {
+ // let text = `鍙兘涓婁紶 ${this.suffix.join(',')} 鏍煎紡鍥剧墖锛乣
+ // this.toast(text);
// continue;
// }
- // imageArr.push(path)
- // this.urls.push(path)
- // this.tempFiles.push(e.tempFiles[i])
- // this.status.push(this.immediate ? 'uploading' : 'preupload')
// }
- // this.onComplete('choose')
- // let start = this.urls.length - imageArr.length
- // if (this.immediate) {
- // for (let j = 0; j < imageArr.length; j++) {
- // let index = start + j
- // this.uploadImage(index, imageArr[j]).then((res) => {
- // this._success(res)
- // }).catch((res) => {
- // this._error(res)
- // })
- // }
+
+ // //杩囨护瓒呭嚭澶у皬闄愬埗鍥剧墖
+ // let size = e.tempFiles[i].size;
+
+ // if (Number(this.size) * 1024 * 1024 < size) {
+ // let err = `鍗曞紶鍥剧墖澶у皬涓嶈兘瓒呰繃锛�${this.size}MB`
+ // this.toast(err);
+ // continue;
+ // }
+ // imageArr.push(path)
+ // this.urls.push(path)
+ // this.tempFiles.push(e.tempFiles[i])
+ // this.status.push(this.immediate ? 'uploading' : 'preupload')
+ // }
+ // this.onComplete('choose')
+ // let start = this.urls.length - imageArr.length
+ // if (this.immediate) {
+ // for (let j = 0; j < imageArr.length; j++) {
+ // let index = start + j
+ // this.uploadImage(index, imageArr[j]).then((res) => {
+ // this._success(res)
+ // }).catch((res) => {
+ // this._error(res)
+ // })
// }
// }
- // })
+ // }
+ // })
// },
uploadImage(index, imgUrl, url, formDataNew) {
return new Promise((resolve, reject) => {
--
Gitblit v1.9.1