123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.isPromise = exports.isObject = exports.isFunction = exports.chooseFile = exports.isVideo = exports.isImageFile = void 0;
- var IMAGE_REGEXP = /\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg)/i;
- function isImageUrl(url) {
- return IMAGE_REGEXP.test(url);
- }
- function isImageFile(item) {
- if (item.type) {
- return item.type.indexOf('image') === 0;
- }
- if (item.path) {
- return isImageUrl(item.path);
- }
- if (item.url) {
- return isImageUrl(item.url);
- }
- return false;
- }
- exports.isImageFile = isImageFile;
- function isVideo(res, accept) {
- return accept === 'video';
- }
- exports.isVideo = isVideo;
- function chooseFile(_a) {
- var accept = _a.accept;
- var multiple = _a.multiple;
- var capture = _a.capture;
- var compressed = _a.compressed;
- var maxDuration = _a.maxDuration;
- var sizeType = _a.sizeType;
- var camera = _a.camera;
- var maxCount = _a.maxCount;
- switch (accept) {
- case 'image':
- return new Promise(function (resolve, reject) {
- uni.chooseImage({
- count: multiple ? Math.min(maxCount, 9) : 1,
- sourceType: capture,
- sizeType: sizeType,
- success: resolve,
- fail: reject
- });
- });
- case 'media':
- return new Promise(function (resolve, reject) {
- uni.chooseMedia({
- count: multiple ? Math.min(maxCount, 9) : 1,
- sourceType: capture,
- maxDuration: maxDuration,
- sizeType: sizeType,
- camera: camera,
- success: resolve,
- fail: reject
- });
- });
- case 'video':
- return new Promise(function (resolve, reject) {
- uni.chooseVideo({
- sourceType: capture,
- compressed: compressed,
- maxDuration: maxDuration,
- camera: camera,
- success: resolve,
- fail: reject
- });
- });
- default:
- return new Promise(function (resolve, reject) {
- uni.chooseMessageFile({
- count: multiple ? maxCount : 1,
- type: 'file',
- success: resolve,
- fail: reject
- });
- });
- }
- }
- exports.chooseFile = chooseFile;
- function isFunction(val) {
- return typeof val === 'function';
- }
- exports.isFunction = isFunction;
- function isObject(val) {
- return val !== null && typeof val === 'object';
- }
- exports.isObject = isObject;
- function isPromise(val) {
- return isObject(val) && isFunction(val.then) && isFunction(val.catch);
- }
- exports.isPromise = isPromise;
|