1. 优化了一些交互,中药药品编辑交互

2. dev和生产环境统一鉴别
This commit is contained in:
李琦
2026-05-30 13:52:44 +08:00
parent ad370375a7
commit 6d93314222
15 changed files with 496 additions and 326 deletions

View File

@@ -71,6 +71,8 @@
* @event {Function} on-choose-complete 每次选择图片后触发,只是让外部可以得知每次选择后,内部的文件列表
* @example <u-upload :action="action" :file-list="fileList" ></u-upload>
*/
import { prepareImagePath } from '@/common/js/image-compress.js';
export default {
name: 'd-upload',
props: {
@@ -296,52 +298,57 @@
const {
name = '', maxCount, multiple, maxSize, sizeType, lists, camera, compressed, maxDuration, sourceType
} = this;
let chooseFile = null;
const newMaxCount = maxCount - lists.length;
// 设置为只选择图片的时候使用 chooseImage 来实现
chooseFile = new Promise((resolve, reject) => {
uni.chooseImage({
count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1,
sourceType: sourceType,
sizeType,
success: resolve,
fail: reject
});
});
chooseFile
.then(res => {
let file = null;
let listOldLength = this.lists.length;
res.tempFiles.map((val, index) => {
// 检查文件后缀是否允许如果不在this.limitType内就会返回false
if (!this.checkFileExt(val)) return;
// 如果是非多选index大于等于1或者超出最大限制数量时不处理
if (!multiple && index >= 1) return;
uni.chooseImage({
count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1,
sourceType: sourceType,
sizeType,
success: async (res) => {
const listOldLength = this.lists.length;
for (let index = 0; index < res.tempFiles.length; index++) {
const val = res.tempFiles[index];
if (!this.checkFileExt(val)) continue;
if (!multiple && index >= 1) continue;
if (val.size > maxSize) {
this.$emit('on-oversize', val, this.lists, this.index);
this.showToast('超出允许的文件大小');
} else {
if (maxCount <= lists.length) {
this.$emit('on-exceed', val, this.lists, this.index);
this.showToast('超出最大允许的文件个数');
return;
}
continue;
}
if (maxCount <= lists.length) {
this.$emit('on-exceed', val, this.lists, this.index);
this.showToast('超出最大允许的文件个数');
break;
}
try {
const prepared = await prepareImagePath({
path: val.path,
size: val.size,
});
if (!prepared) continue;
lists.push({
url: val.path,
url: prepared.path,
progress: 0,
error: false,
file: val
file: {
...val,
path: prepared.path,
size: prepared.size,
},
});
} catch (error) {
this.$emit('on-choose-fail', error);
this.showToast('图片处理失败');
}
});
// 每次图片选择完,抛出一个事件,并将当前内部选择的图片数组抛出去
}
this.$emit('on-choose-complete', this.lists, this.index);
if (this.autoUpload) this.uploadFile(listOldLength);
})
.catch(error => {
},
fail: (error) => {
this.$emit('on-choose-fail', error);
});
}
});
},
// 提示用户消息
showToast(message, force = false) {