Skip to content

Commit

Permalink
fix: uni-forms 优化 兼容nvue页面
Browse files Browse the repository at this point in the history
fix: uni-easyinput 优化 兼容nvue页面
fix: uni-group 优化 兼容nvue页面
feat:  uni-file-picker 新增 文件选择上传组件
  • Loading branch information
mehaotian committed Jan 30, 2021
1 parent 876541b commit 2b19998
Show file tree
Hide file tree
Showing 30 changed files with 2,207 additions and 140 deletions.
Empty file modified components/uni-easyinput/common.js
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions components/uni-easyinput/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"id": "3455",
"name": "Easyinput",
"desc": "增强输入框",
"edition": "0.0.7",
"edition": "0.0.8",
"url": "easyinput",
"type": "表单组件",
"suffix": "vue",
"path": "https://ext.dcloud.net.cn/plugin?id=3455",
"update_log": ["- 优化 trim 属性,兼容 start 和 end"]
"update_log": ["- 优化 兼容 nvue 页面"]
}
2 changes: 1 addition & 1 deletion components/uni-easyinput/uni-easyinput.vue
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<view class="uni-easyinput" :class="{'uni-easyinput-error':msg}" :style="{color:inputBorder && msg?'#dd524d':styles.color}">
<view class="uni-easyinput__content" :class="{'is-input-border':inputBorder ,'is-input-error-border':inputBorder && msg,'is-textarea':type==='textarea','is-disabled':disabled}"
:style="{'border-color':inputBorder && msg?'#dd524d':styles.borderColor,'background-color':disabled?styles.disableColor:'#fff'}">
:style="{'border-color':inputBorder && msg?'#dd524d':styles.borderColor,'background-color':disabled?styles.disableColor:''}">
<uni-icons v-if="prefixIcon" class="content-clear-icon" :type="prefixIcon" color="#c0c4cc" @click="onClickIcon('prefix')"></uni-icons>
<textarea v-if="type === 'textarea'" class="uni-easyinput__content-textarea" :class="{'input-padding':inputBorder}"
:name="name" :value="val" :placeholder="placeholder" :placeholderStyle="placeholderStyle" :disabled="disabled"
Expand Down
2 changes: 1 addition & 1 deletion components/uni-fab/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"type": "基础组件",
"edition": "1.0.6",
"path": "https://ext.dcloud.net.cn/plugin?id=144",
"update_log": "- 新增 支持 PC 端"
"update_log": ["- 优化 按钮背景色调整","- 优化 兼容pc端"]
}
Binary file added components/uni-file-picker.zip
Binary file not shown.
186 changes: 186 additions & 0 deletions components/uni-file-picker/choose-and-upload-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const ERR_MSG_OK = 'chooseAndUploadFile:ok';
const ERR_MSG_FAIL = 'chooseAndUploadFile:fail';
function chooseImage(opts) {
const { count, sizeType, sourceType, extension } = opts;
return new Promise((resolve, reject) => {
uni.chooseImage({
count,
sizeType,
sourceType,
extension,
success(res) {
resolve(normalizeChooseAndUploadFileRes(res, 'image'));
},
fail(res) {
reject({
errMsg: res.errMsg.replace('chooseImage:fail', ERR_MSG_FAIL),
});
},
});
});
}
function chooseVideo(opts) {
const { camera, compressed, maxDuration, sourceType, extension } = opts;
return new Promise((resolve, reject) => {
uni.chooseVideo({
camera,
compressed,
maxDuration,
sourceType,
extension,
success(res) {
const { tempFilePath, duration, size, height, width } = res;
resolve(normalizeChooseAndUploadFileRes({
errMsg: 'chooseVideo:ok',
tempFilePaths: [tempFilePath],
tempFiles: [
{
name: (res.tempFile && res.tempFile.name) || '',
path: tempFilePath,
size,
type: (res.tempFile && res.tempFile.type) || '',
width,
height,
duration,
fileType: 'video',
cloudPath: '',
},
],
}, 'video'));
},
fail(res) {
reject({
errMsg: res.errMsg.replace('chooseVideo:fail', ERR_MSG_FAIL),
});
},
});
});
}
function chooseAll(opts) {
const { count, extension } = opts;
return new Promise((resolve, reject) => {
let chooseFile = uni.chooseFile;
if (typeof wx !== 'undefined' &&
typeof wx.chooseMessageFile === 'function') {
chooseFile = wx.chooseMessageFile;
}
if (typeof chooseFile !== 'function') {
return reject({
errMsg: ERR_MSG_FAIL + ' 请指定 type 类型,该平台仅支持选择 image 或 video。',
});
}
chooseFile({
type: 'all',
count,
extension,
success(res) {
resolve(normalizeChooseAndUploadFileRes(res));
},
fail(res) {
reject({
errMsg: res.errMsg.replace('chooseFile:fail', ERR_MSG_FAIL),
});
},
});
});
}
function normalizeChooseAndUploadFileRes(res, fileType) {
res.tempFiles.forEach((item, index) => {
if (!item.name) {
item.name = item.path.substring(item.path.lastIndexOf('/') + 1);
}
if (fileType) {
item.fileType = fileType;
}
item.cloudPath =
Date.now() + '_' + index + item.name.substring(item.name.lastIndexOf('.'));
});
// wx.chooseMessageFile
if (!res.tempFilePaths) {
res.tempFilePaths = res.tempFiles.map((file) => file.path);
}
return res;
}
function uploadCloudFiles(res, max = 5, onUploadProgress) {
res = Object.assign({}, res);
res.errMsg = ERR_MSG_OK;
const files = res.tempFiles;
const len = files.length;
let count = 0;
return new Promise((resolve) => {
while (count < max) {
next();
}
function next() {
let cur = count++;
if (cur >= len) {
!files.find((item) => !item.url && !item.errMsg) && resolve(res);
return;
}
const fileItem = files[cur];
uniCloud
.uploadFile({
filePath: fileItem.path,
cloudPath: fileItem.cloudPath,
fileType: fileItem.fileType,
onUploadProgress(res) {
res.index = cur;
res.tempFile = fileItem;
res.tempFilePath = fileItem.path;
onUploadProgress &&
onUploadProgress(res);
},
})
.then((res) => {
fileItem.url = res.fileID;
if (cur < len) {
next();
}
})
.catch((res) => {
// fileItem.errMsg = res.message;
fileItem.errMsg = res.errMsg || res.message;
if (cur < len) {
next();
}
});
}
});
}
function uploadFiles(choosePromise, { onChooseFile, onUploadProgress }) {
return choosePromise
.then((res) => {
if (onChooseFile) {
const customChooseRes = onChooseFile(res);
if (typeof customChooseRes !== 'undefined') {
return Promise.resolve(customChooseRes).then((chooseRes) => typeof chooseRes === 'undefined' ? res : chooseRes);
}
}
return res;
})
.then((res) => {
if (res === false) {
return {
errMsg: ERR_MSG_OK,
tempFilePaths: [],
tempFiles: [],
};
}
return uploadCloudFiles(res, 5, onUploadProgress);
});
}
function chooseAndUploadFile(opts = { type: 'all' }) {
if (opts.type === 'image') {
return uploadFiles(chooseImage(opts), opts);
}
else if (opts.type === 'video') {
return uploadFiles(chooseVideo(opts), opts);
}
return uploadFiles(chooseAll(opts), opts);
}

exports.chooseAndUploadFile = chooseAndUploadFile;
12 changes: 12 additions & 0 deletions components/uni-file-picker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "-1",
"name": "Forms",
"desc": "表单",
"edition": "0.0.1",
"url": "forms",
"type": "表单组件",
"suffix": "vue",
"module": ["uni-file-picker"],
"path": "https://ext.dcloud.net.cn/plugin?id=-1",
"update_log": ["- 新增 uni-file-picker 文件上传组件"]
}
Loading

0 comments on commit 2b19998

Please sign in to comment.