Authored by zhangwenxue

feat(finances/invoice): change validate config

... ... @@ -103,9 +103,9 @@ export default {
return callback(new Error('请输入物流单号'));
}
if (!/^[\w\d_-]{5,}$/.test(value)) {
// TODO: refs https://www.cnblogs.com/Jerseyblog/p/10077136.html
return callback(new Error('请输入有效的物流单号')); // TODO: 描述下什么是有效的?
if (!/^[\w\d]{10,20}$/i.test(value)) {
// 10位-20位字符,只能是数字或者字母
return callback(new Error('请输入有效的物流单号:10位~20位数字或字母'));
}
}
... ...
... ... @@ -21,7 +21,7 @@
:show-upload-list="false"
:on-success="handleSuccess"
:format="['pdf']"
:max-size="1024 * 1024 * 5"
:max-size="500"
:on-format-error="handleFormatError"
:on-exceeded-size="handleMaxSize"
:before-upload="handleBeforeUpload"
... ... @@ -114,8 +114,8 @@ export default {
},
handleMaxSize(file) {
this.$Notice.warning({
title: '文件大小错误',
desc: `${file.name}的大小三于5MB`,
title: '文件过大',
desc: `${file.name}文件不能大于500k`,
});
},
handleBeforeUpload() {
... ...
... ... @@ -29,14 +29,18 @@ class FileController extends Context {
}
req.body.files = [];
const bucket = req.body.bucket;
_.each(files, file => {
const types = file.type.split('/');
// add support for pdf
const isPdf = /pdf/i.test(file.type || '');
if (isPdf) {
// 5M
if (file.size > 5 * 1024 * 1024) {
if (bucket === 'invoices') {
// 上传 pdf, pdf大小限制500k
const isPDF = /pdf/i.test(file.type || '');
if (!isPDF) {
errTip = '上传文件格式不正确';
}
if (file.size > 500 * 1024) {
errTip = '上传文件尺寸太大!';
}
} else {
... ... @@ -63,16 +67,16 @@ class FileController extends Context {
});
}
if (req.body.bucket === 'goodsimg' || req.body.bucket === 'invoice') {
if (bucket === 'goodsimg' || bucket === 'invoices') {
this.api
.upload('http://upload.static.yohobuy.com', {
fileData: req.body.files,
project: req.body.bucket,
project: bucket,
})
.then(result => {
if (result.code === 200 && _.get(result, 'data.imagesList.length', 0)) {
result.data.imagesList = _.map(result.data.imagesList, imgUrl => {
return this.fileService.getAbsoluteUrl(imgUrl, req.body.bucket);
return this.fileService.getAbsoluteUrl(imgUrl, bucket);
});
}
res.json(result);
... ... @@ -82,7 +86,7 @@ class FileController extends Context {
this.api
.upload(apiDomain.platform.uploads, {
files: req.body.files,
bucket: req.body.bucket,
bucket,
})
.then(result => {
const newResult = {
... ...