first commit

This commit is contained in:
编码猿
2024-09-27 02:06:13 +08:00
commit 852d94fbb9
36760 changed files with 3274413 additions and 0 deletions

View File

@@ -0,0 +1,226 @@
'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');
component_1.VantComponent({
props: __assign(
__assign(
{
disabled: Boolean,
multiple: Boolean,
uploadText: String,
useBeforeRead: Boolean,
afterRead: null,
beforeRead: null,
previewSize: {
type: null,
value: 80,
},
name: {
type: [Number, String],
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,
},
imageFit: {
type: String,
value: 'scaleToFill',
},
uploadIcon: {
type: String,
value: 'photograph',
},
},
shared_1.chooseImageProps
),
shared_1.chooseVideoProps
),
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:
typeof item.isImage === 'undefined'
? utils_1.isImageFile(item)
: item.isImage,
deletable:
typeof item.deletable === 'undefined' ? true : item.deletable,
});
});
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,
accept = _a.accept,
lists = _a.lists,
disabled = _a.disabled;
if (disabled) return;
utils_1
.chooseFile(
__assign(__assign({}, this.data), {
maxCount: maxCount - lists.length,
})
)
.then(function (res) {
var file = null;
if (utils_1.isVideo(res, accept)) {
file = __assign({ path: res.tempFilePath }, res);
} else {
file = multiple ? res.tempFiles : res.tempFiles[0];
}
_this.onBeforeRead(file);
})
.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 (utils_1.isPromise(res)) {
res.then(function (data) {
return _this.onAfterRead(data || file);
});
} else {
this.onAfterRead(file);
}
},
onAfterRead: function (file) {
var maxSize = this.data.maxSize;
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 this.data.afterRead === 'function') {
this.data.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 lists = this.data.lists;
var item = lists[index];
wx.previewImage({
urls: lists
.filter(function (item) {
return item.isImage;
})
.map(function (item) {
return item.url || item.path;
}),
current: item.url || item.path,
fail: function () {
wx.showToast({ title: '预览图片失败', icon: 'none' });
},
});
},
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))
);
},
},
});

View File

@@ -0,0 +1,7 @@
{
"component": true,
"usingComponents": {
"van-icon": "../icon/index",
"van-loading": "../loading/index"
}
}

View File

@@ -0,0 +1,68 @@
<wxs src="../wxs/utils.wxs" module="utils" />
<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.url || item.path }}"
alt="{{ item.name || ('图片' + index) }}"
class="van-uploader__preview-image"
style="width: {{ utils.addUnit(previewSize) }}; height: {{ utils.addUnit(previewSize) }};"
data-index="{{ index }}"
bind:tap="onPreviewImage"
/>
<view
wx:else
class="van-uploader__file"
style="width: {{ utils.addUnit(previewSize) }}; height: {{ utils.addUnit(previewSize) }};"
>
<van-icon name="description" class="van-uploader__file-icon" />
<view class="van-uploader__file-name van-ellipsis">{{ item.name || item.url || item.path }}</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" bind:tap="startUpload">
<slot />
</view>
<!-- 默认上传样式 -->
<view
wx:if="{{ showUpload }}"
class="van-uploader__upload {{ disabled ? 'van-uploader__upload--disabled': ''}}"
style="width: {{ utils.addUnit(previewSize) }}; height: {{ utils.addUnit(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>

View File

@@ -0,0 +1 @@
@import '../common/index.wxss';.van-uploader{position:relative;display:inline-block}.van-uploader__wrapper{display:-webkit-flex;display:flex;-webkit-flex-wrap:wrap;flex-wrap:wrap}.van-uploader__slot:empty{display:none}.van-uploader__slot:not(:empty)+.van-uploader__upload{display:none!important}.van-uploader__upload{position:relative;display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;box-sizing:border-box;width:80px;height:80px;margin:0 8px 8px 0;background-color:#f7f8fa}.van-uploader__upload:active{background-color:#f2f3f5}.van-uploader__upload-icon{color:#dcdee0;font-size:24px}.van-uploader__upload-text{margin-top:8px;color:#969799;font-size:12px}.van-uploader__upload--disabled{opacity:.5;opacity:var(--uploader-disabled-opacity,.5)}.van-uploader__preview{position:relative;margin:0 8px 8px 0;cursor:pointer}.van-uploader__preview-image{display:block;width:80px;height:80px;overflow:hidden}.van-uploader__preview-delete{position:absolute;top:0;right:0;width:14px;height:14px;background-color:rgba(0,0,0,.7);border-radius:0 0 0 12px}.van-uploader__preview-delete-icon{position:absolute;top:-2px;right:-2px;color:#fff;font-size:16px;-webkit-transform:scale(.5);transform:scale(.5)}.van-uploader__file{display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;width:80px;height:80px;background-color:#f7f8fa}.van-uploader__file-icon{color:#646566;font-size:20px}.van-uploader__file-name{box-sizing:border-box;width:100%;margin-top:8px;padding:0 4px;color:#646566;font-size:12px;text-align:center}.van-uploader__mask{position:absolute;top:0;right:0;bottom:0;left:0;display:-webkit-flex;display:flex;-webkit-flex-direction:column;flex-direction:column;-webkit-align-items:center;align-items:center;-webkit-justify-content:center;justify-content:center;color:#fff;background-color:rgba(50,50,51,.88)}.van-uploader__mask-icon{font-size:22px}.van-uploader__mask-message{margin-top:6px;padding:0 4px;font-size:12px;line-height:14px}.van-uploader__loading{width:22px;height:22px;color:#fff!important}

View File

@@ -0,0 +1,33 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
exports.chooseVideoProps = exports.chooseImageProps = void 0;
// props for choose image
exports.chooseImageProps = {
sizeType: {
type: Array,
value: ['original', 'compressed'],
},
capture: {
type: Array,
value: ['album', 'camera'],
},
};
// props for choose video
exports.chooseVideoProps = {
capture: {
type: Array,
value: ['album', 'camera'],
},
compressed: {
type: Boolean,
value: true,
},
maxDuration: {
type: Number,
value: 60,
},
camera: {
type: String,
value: 'back',
},
};

View File

@@ -0,0 +1,91 @@
'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,
multiple = _a.multiple,
capture = _a.capture,
compressed = _a.compressed,
maxDuration = _a.maxDuration,
sizeType = _a.sizeType,
camera = _a.camera,
maxCount = _a.maxCount;
switch (accept) {
case 'image':
return new Promise(function (resolve, reject) {
wx.chooseImage({
count: multiple ? Math.min(maxCount, 9) : 1,
sourceType: capture,
sizeType: sizeType,
success: resolve,
fail: reject,
});
});
case 'media':
return new Promise(function (resolve, reject) {
wx.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) {
wx.chooseVideo({
sourceType: capture,
compressed: compressed,
maxDuration: maxDuration,
camera: camera,
success: resolve,
fail: reject,
});
});
default:
return new Promise(function (resolve, reject) {
wx.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;