开始做登录
This commit is contained in:
1
miniprogram_npm/@vant/weapp/uploader/index.d.ts
vendored
Normal file
1
miniprogram_npm/@vant/weapp/uploader/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
183
miniprogram_npm/@vant/weapp/uploader/index.js
Normal file
183
miniprogram_npm/@vant/weapp/uploader/index.js
Normal file
@@ -0,0 +1,183 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var component_1 = require("../common/component");
|
||||
var utils_1 = require("./utils");
|
||||
var shared_1 = require("./shared");
|
||||
var validator_1 = require("../common/validator");
|
||||
(0, component_1.VantComponent)({
|
||||
props: __assign(__assign(__assign(__assign({ disabled: Boolean, multiple: Boolean, uploadText: String, useBeforeRead: Boolean, afterRead: null, beforeRead: null, previewSize: {
|
||||
type: null,
|
||||
value: 80,
|
||||
}, name: {
|
||||
type: null,
|
||||
value: '',
|
||||
}, accept: {
|
||||
type: String,
|
||||
value: 'image',
|
||||
}, fileList: {
|
||||
type: Array,
|
||||
value: [],
|
||||
observer: 'formatFileList',
|
||||
}, maxSize: {
|
||||
type: Number,
|
||||
value: Number.MAX_VALUE,
|
||||
}, maxCount: {
|
||||
type: Number,
|
||||
value: 100,
|
||||
}, deletable: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
}, showUpload: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
}, previewImage: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
}, previewFullImage: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
}, videoFit: {
|
||||
type: String,
|
||||
value: 'contain',
|
||||
}, imageFit: {
|
||||
type: String,
|
||||
value: 'scaleToFill',
|
||||
}, uploadIcon: {
|
||||
type: String,
|
||||
value: 'photograph',
|
||||
} }, shared_1.imageProps), shared_1.videoProps), shared_1.mediaProps), shared_1.messageFileProps),
|
||||
data: {
|
||||
lists: [],
|
||||
isInCount: true,
|
||||
},
|
||||
methods: {
|
||||
formatFileList: function () {
|
||||
var _a = this.data, _b = _a.fileList, fileList = _b === void 0 ? [] : _b, maxCount = _a.maxCount;
|
||||
var lists = fileList.map(function (item) { return (__assign(__assign({}, item), { isImage: (0, utils_1.isImageFile)(item), isVideo: (0, utils_1.isVideoFile)(item), deletable: (0, validator_1.isBoolean)(item.deletable) ? item.deletable : true })); });
|
||||
this.setData({ lists: lists, isInCount: lists.length < maxCount });
|
||||
},
|
||||
getDetail: function (index) {
|
||||
return {
|
||||
name: this.data.name,
|
||||
index: index == null ? this.data.fileList.length : index,
|
||||
};
|
||||
},
|
||||
startUpload: function () {
|
||||
var _this = this;
|
||||
var _a = this.data, maxCount = _a.maxCount, multiple = _a.multiple, lists = _a.lists, disabled = _a.disabled;
|
||||
if (disabled)
|
||||
return;
|
||||
(0, utils_1.chooseFile)(__assign(__assign({}, this.data), { maxCount: maxCount - lists.length }))
|
||||
.then(function (res) {
|
||||
_this.onBeforeRead(multiple ? res : res[0]);
|
||||
})
|
||||
.catch(function (error) {
|
||||
_this.$emit('error', error);
|
||||
});
|
||||
},
|
||||
onBeforeRead: function (file) {
|
||||
var _this = this;
|
||||
var _a = this.data, beforeRead = _a.beforeRead, useBeforeRead = _a.useBeforeRead;
|
||||
var res = true;
|
||||
if (typeof beforeRead === 'function') {
|
||||
res = beforeRead(file, this.getDetail());
|
||||
}
|
||||
if (useBeforeRead) {
|
||||
res = new Promise(function (resolve, reject) {
|
||||
_this.$emit('before-read', __assign(__assign({ file: file }, _this.getDetail()), { callback: function (ok) {
|
||||
ok ? resolve() : reject();
|
||||
} }));
|
||||
});
|
||||
}
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
if ((0, validator_1.isPromise)(res)) {
|
||||
res.then(function (data) { return _this.onAfterRead(data || file); });
|
||||
}
|
||||
else {
|
||||
this.onAfterRead(file);
|
||||
}
|
||||
},
|
||||
onAfterRead: function (file) {
|
||||
var _a = this.data, maxSize = _a.maxSize, afterRead = _a.afterRead;
|
||||
var oversize = Array.isArray(file)
|
||||
? file.some(function (item) { return item.size > maxSize; })
|
||||
: file.size > maxSize;
|
||||
if (oversize) {
|
||||
this.$emit('oversize', __assign({ file: file }, this.getDetail()));
|
||||
return;
|
||||
}
|
||||
if (typeof afterRead === 'function') {
|
||||
afterRead(file, this.getDetail());
|
||||
}
|
||||
this.$emit('after-read', __assign({ file: file }, this.getDetail()));
|
||||
},
|
||||
deleteItem: function (event) {
|
||||
var index = event.currentTarget.dataset.index;
|
||||
this.$emit('delete', __assign(__assign({}, this.getDetail(index)), { file: this.data.fileList[index] }));
|
||||
},
|
||||
onPreviewImage: function (event) {
|
||||
if (!this.data.previewFullImage)
|
||||
return;
|
||||
var index = event.currentTarget.dataset.index;
|
||||
var _a = this.data, lists = _a.lists, showmenu = _a.showmenu;
|
||||
var item = lists[index];
|
||||
wx.previewImage({
|
||||
urls: lists.filter(function (item) { return (0, utils_1.isImageFile)(item); }).map(function (item) { return item.url; }),
|
||||
current: item.url,
|
||||
showmenu: showmenu,
|
||||
fail: function () {
|
||||
wx.showToast({ title: '预览图片失败', icon: 'none' });
|
||||
},
|
||||
});
|
||||
},
|
||||
onPreviewVideo: function (event) {
|
||||
if (!this.data.previewFullImage)
|
||||
return;
|
||||
var index = event.currentTarget.dataset.index;
|
||||
var lists = this.data.lists;
|
||||
var sources = [];
|
||||
var current = lists.reduce(function (sum, cur, curIndex) {
|
||||
if (!(0, utils_1.isVideoFile)(cur)) {
|
||||
return sum;
|
||||
}
|
||||
sources.push(__assign(__assign({}, cur), { type: 'video' }));
|
||||
if (curIndex < index) {
|
||||
sum++;
|
||||
}
|
||||
return sum;
|
||||
}, 0);
|
||||
wx.previewMedia({
|
||||
sources: sources,
|
||||
current: current,
|
||||
fail: function () {
|
||||
wx.showToast({ title: '预览视频失败', icon: 'none' });
|
||||
},
|
||||
});
|
||||
},
|
||||
onPreviewFile: function (event) {
|
||||
var index = event.currentTarget.dataset.index;
|
||||
wx.openDocument({
|
||||
filePath: this.data.lists[index].url,
|
||||
showMenu: true,
|
||||
});
|
||||
},
|
||||
onClickPreview: function (event) {
|
||||
var index = event.currentTarget.dataset.index;
|
||||
var item = this.data.lists[index];
|
||||
this.$emit('click-preview', __assign(__assign({}, item), this.getDetail(index)));
|
||||
},
|
||||
},
|
||||
});
|
7
miniprogram_npm/@vant/weapp/uploader/index.json
Normal file
7
miniprogram_npm/@vant/weapp/uploader/index.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"van-icon": "../icon/index",
|
||||
"van-loading": "../loading/index"
|
||||
}
|
||||
}
|
84
miniprogram_npm/@vant/weapp/uploader/index.wxml
Normal file
84
miniprogram_npm/@vant/weapp/uploader/index.wxml
Normal file
@@ -0,0 +1,84 @@
|
||||
<wxs src="../wxs/utils.wxs" module="utils" />
|
||||
<wxs src="./index.wxs" module="computed" />
|
||||
|
||||
<view class="van-uploader">
|
||||
<view class="van-uploader__wrapper">
|
||||
<!-- 预览样式 -->
|
||||
<view
|
||||
wx:if="{{ previewImage }}"
|
||||
wx:for="{{ lists }}"
|
||||
wx:key="index"
|
||||
class="van-uploader__preview"
|
||||
data-index="{{ index }}"
|
||||
bindtap="onClickPreview"
|
||||
>
|
||||
<image
|
||||
wx:if="{{ item.isImage }}"
|
||||
mode="{{ imageFit }}"
|
||||
src="{{ item.thumb || item.url }}"
|
||||
alt="{{ item.name || ('图片' + index) }}"
|
||||
class="van-uploader__preview-image"
|
||||
style="{{ computed.sizeStyle({ previewSize }) }}"
|
||||
data-index="{{ index }}"
|
||||
bindtap="onPreviewImage"
|
||||
/>
|
||||
<video
|
||||
wx:elif="{{ item.isVideo }}"
|
||||
src="{{ item.url }}"
|
||||
title="{{ item.name || ('视频' + index) }}"
|
||||
poster="{{ item.thumb }}"
|
||||
autoplay="{{ item.autoplay }}"
|
||||
object-fit="{{videoFit}}"
|
||||
class="van-uploader__preview-image"
|
||||
style="{{ computed.sizeStyle({ previewSize }) }}"
|
||||
data-index="{{ index }}"
|
||||
bindtap="onPreviewVideo"
|
||||
>
|
||||
</video>
|
||||
<view
|
||||
wx:else
|
||||
class="van-uploader__file"
|
||||
style="{{ computed.sizeStyle({ previewSize }) }}"
|
||||
data-index="{{ index }}"
|
||||
bindtap="onPreviewFile"
|
||||
>
|
||||
<van-icon name="description" class="van-uploader__file-icon" />
|
||||
<view class="van-uploader__file-name van-ellipsis">{{ item.name || item.url }}</view>
|
||||
</view>
|
||||
<view
|
||||
wx:if="{{ item.status === 'uploading' || item.status === 'failed' }}"
|
||||
class="van-uploader__mask"
|
||||
>
|
||||
<van-icon wx:if="{{ item.status === 'failed' }}" name="close" class="van-uploader__mask-icon" />
|
||||
<van-loading wx:else custom-class="van-uploader__loading" />
|
||||
<text wx:if="{{ item.message }}" class="van-uploader__mask-message">{{ item.message }}</text>
|
||||
</view>
|
||||
<view
|
||||
wx:if="{{ deletable && item.deletable }}"
|
||||
data-index="{{ index }}"
|
||||
class="van-uploader__preview-delete"
|
||||
catch:tap="deleteItem"
|
||||
>
|
||||
<van-icon name="cross" class="van-uploader__preview-delete-icon" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 上传样式 -->
|
||||
<block wx:if="{{ isInCount }}">
|
||||
<view class="van-uploader__slot" bindtap="startUpload">
|
||||
<slot />
|
||||
</view>
|
||||
|
||||
<!-- 默认上传样式 -->
|
||||
<view
|
||||
wx:if="{{ showUpload }}"
|
||||
class="van-uploader__upload {{ disabled ? 'van-uploader__upload--disabled': ''}}"
|
||||
style="{{ computed.sizeStyle({ previewSize }) }}"
|
||||
bindtap="startUpload"
|
||||
>
|
||||
<van-icon name="{{ uploadIcon }}" class="van-uploader__upload-icon" />
|
||||
<text wx:if="{{ uploadText }}" class="van-uploader__upload-text">{{ uploadText }}</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
17
miniprogram_npm/@vant/weapp/uploader/index.wxs
Normal file
17
miniprogram_npm/@vant/weapp/uploader/index.wxs
Normal file
@@ -0,0 +1,17 @@
|
||||
/* eslint-disable */
|
||||
var style = require('../wxs/style.wxs');
|
||||
var addUnit = require('../wxs/add-unit.wxs');
|
||||
|
||||
function sizeStyle(data) {
|
||||
return "Array" === data.previewSize.constructor ? style({
|
||||
width: addUnit(data.previewSize[0]),
|
||||
height: addUnit(data.previewSize[1]),
|
||||
}) : style({
|
||||
width: addUnit(data.previewSize),
|
||||
height: addUnit(data.previewSize),
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
sizeStyle: sizeStyle,
|
||||
};
|
1
miniprogram_npm/@vant/weapp/uploader/index.wxss
Normal file
1
miniprogram_npm/@vant/weapp/uploader/index.wxss
Normal file
@@ -0,0 +1 @@
|
||||
@import '../common/index.wxss';.van-uploader{display:inline-block;position:relative}.van-uploader__wrapper{display:flex;flex-wrap:wrap}.van-uploader__slot:empty{display:none}.van-uploader__slot:not(:empty)+.van-uploader__upload{display:none!important}.van-uploader__upload{align-items:center;background-color:var(--uploader-upload-background-color,#f7f8fa);box-sizing:border-box;display:flex;flex-direction:column;height:var(--uploader-size,80px);justify-content:center;margin:0 8px 8px 0;position:relative;width:var(--uploader-size,80px)}.van-uploader__upload:active{background-color:var(--uploader-upload-active-color,#f2f3f5)}.van-uploader__upload-icon{color:var(--uploader-icon-color,#dcdee0);font-size:var(--uploader-icon-size,24px)}.van-uploader__upload-text{color:var(--uploader-text-color,#969799);font-size:var(--uploader-text-font-size,12px);margin-top:var(--padding-xs,8px)}.van-uploader__upload--disabled{opacity:var(--uploader-disabled-opacity,.5)}.van-uploader__preview{cursor:pointer;margin:0 8px 8px 0;position:relative}.van-uploader__preview-image{display:block;height:var(--uploader-size,80px);overflow:hidden;width:var(--uploader-size,80px)}.van-uploader__preview-delete,.van-uploader__preview-delete:after{height:var(--uploader-delete-icon-size,14px);position:absolute;right:0;top:0;width:var(--uploader-delete-icon-size,14px)}.van-uploader__preview-delete:after{background-color:var(--uploader-delete-background-color,rgba(0,0,0,.7));border-radius:0 0 0 12px;content:""}.van-uploader__preview-delete-icon{color:var(--uploader-delete-color,#fff);font-size:var(--uploader-delete-icon-size,14px);position:absolute;right:0;top:0;transform:scale(.7) translate(10%,-10%);z-index:1}.van-uploader__file{align-items:center;background-color:var(--uploader-file-background-color,#f7f8fa);display:flex;flex-direction:column;height:var(--uploader-size,80px);justify-content:center;width:var(--uploader-size,80px)}.van-uploader__file-icon{color:var(--uploader-file-icon-color,#646566);font-size:var(--uploader-file-icon-size,20px)}.van-uploader__file-name{box-sizing:border-box;color:var(--uploader-file-name-text-color,#646566);font-size:var(--uploader-file-name-font-size,12px);margin-top:var(--uploader-file-name-margin-top,8px);padding:var(--uploader-file-name-padding,0 4px);text-align:center;width:100%}.van-uploader__mask{align-items:center;background-color:var(--uploader-mask-background-color,rgba(50,50,51,.88));bottom:0;color:#fff;display:flex;flex-direction:column;justify-content:center;left:0;position:absolute;right:0;top:0}.van-uploader__mask-icon{font-size:var(--uploader-mask-icon-size,22px)}.van-uploader__mask-message{font-size:var(--uploader-mask-message-font-size,12px);line-height:var(--uploader-mask-message-line-height,14px);margin-top:6px;padding:0 var(--padding-base,4px)}.van-uploader__loading{color:var(--uploader-loading-icon-color,#fff)!important;height:var(--uploader-loading-icon-size,22px);width:var(--uploader-loading-icon-size,22px)}
|
53
miniprogram_npm/@vant/weapp/uploader/shared.d.ts
vendored
Normal file
53
miniprogram_npm/@vant/weapp/uploader/shared.d.ts
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
export declare const imageProps: {
|
||||
sizeType: {
|
||||
type: ArrayConstructor;
|
||||
value: string[];
|
||||
};
|
||||
capture: {
|
||||
type: ArrayConstructor;
|
||||
value: string[];
|
||||
};
|
||||
showmenu: {
|
||||
type: BooleanConstructor;
|
||||
value: boolean;
|
||||
};
|
||||
};
|
||||
export declare const videoProps: {
|
||||
capture: {
|
||||
type: ArrayConstructor;
|
||||
value: string[];
|
||||
};
|
||||
compressed: {
|
||||
type: BooleanConstructor;
|
||||
value: boolean;
|
||||
};
|
||||
maxDuration: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
camera: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
};
|
||||
export declare const mediaProps: {
|
||||
capture: {
|
||||
type: ArrayConstructor;
|
||||
value: string[];
|
||||
};
|
||||
mediaType: {
|
||||
type: ArrayConstructor;
|
||||
value: string[];
|
||||
};
|
||||
maxDuration: {
|
||||
type: NumberConstructor;
|
||||
value: number;
|
||||
};
|
||||
camera: {
|
||||
type: StringConstructor;
|
||||
value: string;
|
||||
};
|
||||
};
|
||||
export declare const messageFileProps: {
|
||||
extension: null;
|
||||
};
|
60
miniprogram_npm/@vant/weapp/uploader/shared.js
Normal file
60
miniprogram_npm/@vant/weapp/uploader/shared.js
Normal file
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.messageFileProps = exports.mediaProps = exports.videoProps = exports.imageProps = void 0;
|
||||
// props for image
|
||||
exports.imageProps = {
|
||||
sizeType: {
|
||||
type: Array,
|
||||
value: ['original', 'compressed'],
|
||||
},
|
||||
capture: {
|
||||
type: Array,
|
||||
value: ['album', 'camera'],
|
||||
},
|
||||
showmenu: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
};
|
||||
// props for video
|
||||
exports.videoProps = {
|
||||
capture: {
|
||||
type: Array,
|
||||
value: ['album', 'camera'],
|
||||
},
|
||||
compressed: {
|
||||
type: Boolean,
|
||||
value: true,
|
||||
},
|
||||
maxDuration: {
|
||||
type: Number,
|
||||
value: 60,
|
||||
},
|
||||
camera: {
|
||||
type: String,
|
||||
value: 'back',
|
||||
},
|
||||
};
|
||||
// props for media
|
||||
exports.mediaProps = {
|
||||
capture: {
|
||||
type: Array,
|
||||
value: ['album', 'camera'],
|
||||
},
|
||||
mediaType: {
|
||||
type: Array,
|
||||
value: ['image', 'video', 'mix'],
|
||||
},
|
||||
maxDuration: {
|
||||
type: Number,
|
||||
value: 60,
|
||||
},
|
||||
camera: {
|
||||
type: String,
|
||||
value: 'back',
|
||||
},
|
||||
};
|
||||
// props for file
|
||||
exports.messageFileProps = {
|
||||
extension: null,
|
||||
};
|
24
miniprogram_npm/@vant/weapp/uploader/utils.d.ts
vendored
Normal file
24
miniprogram_npm/@vant/weapp/uploader/utils.d.ts
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
export interface File {
|
||||
url: string;
|
||||
size?: number;
|
||||
name?: string;
|
||||
type: string;
|
||||
duration?: number;
|
||||
time?: number;
|
||||
isImage?: boolean;
|
||||
isVideo?: boolean;
|
||||
}
|
||||
export declare function isImageFile(item: File): boolean;
|
||||
export declare function isVideoFile(item: File): boolean;
|
||||
export declare function chooseFile({ accept, multiple, capture, compressed, maxDuration, sizeType, camera, maxCount, mediaType, extension, }: {
|
||||
accept: any;
|
||||
multiple: any;
|
||||
capture: any;
|
||||
compressed: any;
|
||||
maxDuration: any;
|
||||
sizeType: any;
|
||||
camera: any;
|
||||
maxCount: any;
|
||||
mediaType: any;
|
||||
extension: any;
|
||||
}): Promise<File | File[]>;
|
112
miniprogram_npm/@vant/weapp/uploader/utils.js
Normal file
112
miniprogram_npm/@vant/weapp/uploader/utils.js
Normal file
@@ -0,0 +1,112 @@
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.chooseFile = exports.isVideoFile = exports.isImageFile = void 0;
|
||||
var utils_1 = require("../common/utils");
|
||||
var validator_1 = require("../common/validator");
|
||||
function isImageFile(item) {
|
||||
if (item.isImage != null) {
|
||||
return item.isImage;
|
||||
}
|
||||
if (item.type) {
|
||||
return item.type === 'image';
|
||||
}
|
||||
if (item.url) {
|
||||
return (0, validator_1.isImageUrl)(item.url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isImageFile = isImageFile;
|
||||
function isVideoFile(item) {
|
||||
if (item.isVideo != null) {
|
||||
return item.isVideo;
|
||||
}
|
||||
if (item.type) {
|
||||
return item.type === 'video';
|
||||
}
|
||||
if (item.url) {
|
||||
return (0, validator_1.isVideoUrl)(item.url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isVideoFile = isVideoFile;
|
||||
function formatImage(res) {
|
||||
return res.tempFiles.map(function (item) { return (__assign(__assign({}, (0, utils_1.pickExclude)(item, ['path'])), { type: 'image', url: item.tempFilePath || item.path, thumb: item.tempFilePath || item.path })); });
|
||||
}
|
||||
function formatVideo(res) {
|
||||
return [
|
||||
__assign(__assign({}, (0, utils_1.pickExclude)(res, ['tempFilePath', 'thumbTempFilePath', 'errMsg'])), { type: 'video', url: res.tempFilePath, thumb: res.thumbTempFilePath }),
|
||||
];
|
||||
}
|
||||
function formatMedia(res) {
|
||||
return res.tempFiles.map(function (item) { return (__assign(__assign({}, (0, utils_1.pickExclude)(item, ['fileType', 'thumbTempFilePath', 'tempFilePath'])), { type: item.fileType, url: item.tempFilePath, thumb: item.fileType === 'video' ? item.thumbTempFilePath : item.tempFilePath })); });
|
||||
}
|
||||
function formatFile(res) {
|
||||
return res.tempFiles.map(function (item) { return (__assign(__assign({}, (0, utils_1.pickExclude)(item, ['path'])), { url: item.path })); });
|
||||
}
|
||||
function chooseFile(_a) {
|
||||
var accept = _a.accept, multiple = _a.multiple, capture = _a.capture, compressed = _a.compressed, maxDuration = _a.maxDuration, sizeType = _a.sizeType, camera = _a.camera, maxCount = _a.maxCount, mediaType = _a.mediaType, extension = _a.extension;
|
||||
return new Promise(function (resolve, reject) {
|
||||
switch (accept) {
|
||||
case 'image':
|
||||
if (utils_1.isPC || utils_1.isWxWork) {
|
||||
wx.chooseImage({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
sourceType: capture,
|
||||
sizeType: sizeType,
|
||||
success: function (res) { return resolve(formatImage(res)); },
|
||||
fail: reject,
|
||||
});
|
||||
}
|
||||
else {
|
||||
wx.chooseMedia({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
mediaType: ['image'],
|
||||
sourceType: capture,
|
||||
maxDuration: maxDuration,
|
||||
sizeType: sizeType,
|
||||
camera: camera,
|
||||
success: function (res) { return resolve(formatImage(res)); },
|
||||
fail: reject,
|
||||
});
|
||||
}
|
||||
break;
|
||||
case 'media':
|
||||
wx.chooseMedia({
|
||||
count: multiple ? Math.min(maxCount, 9) : 1,
|
||||
mediaType: mediaType,
|
||||
sourceType: capture,
|
||||
maxDuration: maxDuration,
|
||||
sizeType: sizeType,
|
||||
camera: camera,
|
||||
success: function (res) { return resolve(formatMedia(res)); },
|
||||
fail: reject,
|
||||
});
|
||||
break;
|
||||
case 'video':
|
||||
wx.chooseVideo({
|
||||
sourceType: capture,
|
||||
compressed: compressed,
|
||||
maxDuration: maxDuration,
|
||||
camera: camera,
|
||||
success: function (res) { return resolve(formatVideo(res)); },
|
||||
fail: reject,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
wx.chooseMessageFile(__assign(__assign({ count: multiple ? maxCount : 1, type: accept }, (extension ? { extension: extension } : {})), { success: function (res) { return resolve(formatFile(res)); }, fail: reject }));
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.chooseFile = chooseFile;
|
Reference in New Issue
Block a user