mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
15ea958b4f
commit
7afb5795bf
@ -12,6 +12,7 @@
|
|||||||
<van-uploader
|
<van-uploader
|
||||||
name="2"
|
name="2"
|
||||||
file-list="{{ fileList2 }}"
|
file-list="{{ fileList2 }}"
|
||||||
|
multiple
|
||||||
bind:after-read="afterRead"
|
bind:after-read="afterRead"
|
||||||
bind:delete="delete"
|
bind:delete="delete"
|
||||||
bind:click-preview="clickPreview"
|
bind:click-preview="clickPreview"
|
||||||
@ -22,6 +23,7 @@
|
|||||||
<van-uploader
|
<van-uploader
|
||||||
name="3"
|
name="3"
|
||||||
file-list="{{ fileList3 }}"
|
file-list="{{ fileList3 }}"
|
||||||
|
multiple
|
||||||
max-count="{{ 2 }}"
|
max-count="{{ 2 }}"
|
||||||
bind:after-read="afterRead"
|
bind:after-read="afterRead"
|
||||||
bind:delete="delete"
|
bind:delete="delete"
|
||||||
|
@ -2,19 +2,10 @@ import { VantComponent } from '../common/component';
|
|||||||
import { isImageFile } from './utils';
|
import { isImageFile } from './utils';
|
||||||
import { addUnit } from '../common/utils';
|
import { addUnit } from '../common/utils';
|
||||||
|
|
||||||
interface File {
|
|
||||||
path: string; // 上传临时地址
|
|
||||||
url: string; // 上传临时地址
|
|
||||||
size: number; // 上传大小
|
|
||||||
name: string; // 上传文件名称,accept="image" 不存在
|
|
||||||
type: string; // 上传类型,accept="image" 不存在
|
|
||||||
time: number; // 上传时间,accept="image" 不存在
|
|
||||||
image: boolean; // 是否为图片
|
|
||||||
}
|
|
||||||
|
|
||||||
VantComponent({
|
VantComponent({
|
||||||
props: {
|
props: {
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
|
multiple: Boolean,
|
||||||
uploadText: String,
|
uploadText: String,
|
||||||
previewSize: {
|
previewSize: {
|
||||||
type: null,
|
type: null,
|
||||||
@ -104,12 +95,8 @@ VantComponent({
|
|||||||
wx.chooseImage({
|
wx.chooseImage({
|
||||||
count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1, // 最多可以选择的数量,如果不支持多选则数量为1
|
count: multiple ? (newMaxCount > 9 ? 9 : newMaxCount) : 1, // 最多可以选择的数量,如果不支持多选则数量为1
|
||||||
sourceType: capture, // 选择图片的来源,相册还是相机
|
sourceType: capture, // 选择图片的来源,相册还是相机
|
||||||
success: res => {
|
success: resolve,
|
||||||
resolve(res);
|
fail: reject
|
||||||
},
|
|
||||||
fail: err => {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -117,18 +104,17 @@ VantComponent({
|
|||||||
wx.chooseMessageFile({
|
wx.chooseMessageFile({
|
||||||
count: multiple ? newMaxCount : 1, // 最多可以选择的数量,如果不支持多选则数量为1
|
count: multiple ? newMaxCount : 1, // 最多可以选择的数量,如果不支持多选则数量为1
|
||||||
type: 'file',
|
type: 'file',
|
||||||
success(res) {
|
success: resolve,
|
||||||
resolve(res);
|
fail: reject
|
||||||
},
|
|
||||||
fail: err => {
|
|
||||||
reject(err);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
chooseFile.then(res => {
|
chooseFile.then((res:
|
||||||
const file: File | File[] = multiple ? res.tempFiles : res.tempFiles[0];
|
WechatMiniprogram.ChooseImageSuccessCallbackResult |
|
||||||
|
WechatMiniprogram.ChooseMessageFileSuccessCallbackResult
|
||||||
|
) => {
|
||||||
|
const file = multiple ? res.tempFiles : res.tempFiles[0];
|
||||||
|
|
||||||
// 检查文件大小
|
// 检查文件大小
|
||||||
if (file instanceof Array) {
|
if (file instanceof Array) {
|
||||||
@ -147,7 +133,7 @@ VantComponent({
|
|||||||
this.$emit('before-read', {
|
this.$emit('before-read', {
|
||||||
file,
|
file,
|
||||||
name,
|
name,
|
||||||
callback: result => {
|
callback: (result: boolean) => {
|
||||||
if (result) {
|
if (result) {
|
||||||
// 开始上传
|
// 开始上传
|
||||||
this.$emit('after-read', { file, name });
|
this.$emit('after-read', { file, name });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user