extrafile filetype 获取file自带的type , 上传图片组件支持entityid

This commit is contained in:
Wang Kejun 2022-09-01 13:52:20 +08:00
parent 5cb09870f4
commit a52addc20a
10 changed files with 113 additions and 67 deletions

View File

@ -92,6 +92,7 @@ exports.default = OakComponent({
tag1: String,
tag2: String,
entity: String,
entityId: String,
},
methods: {
/**
@ -211,19 +212,19 @@ exports.default = OakComponent({
},
pushExtraFile: function (options) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, type, origin, tag1, tag2, entity, autoUpload, name, extra1, fileType, size, extension, filename, updateData, _b, url, bucket, _c, _d, _e, ele, error_1, ele;
var _f, _g;
var _a, type, origin, tag1, tag2, entity, entityId, autoUpload, name, extra1, fileType, size, extension, filename, updateData, bucket, _b, _c, _d, ele, error_1, err_2, ele;
var _e, _f;
var _this = this;
return tslib_1.__generator(this, function (_h) {
switch (_h.label) {
return tslib_1.__generator(this, function (_g) {
switch (_g.label) {
case 0:
_a = this.props, type = _a.type, origin = _a.origin, tag1 = _a.tag1, tag2 = _a.tag2, entity = _a.entity, autoUpload = _a.autoUpload;
_a = this.props, type = _a.type, origin = _a.origin, tag1 = _a.tag1, tag2 = _a.tag2, entity = _a.entity, entityId = _a.entityId, autoUpload = _a.autoUpload;
name = options.name, extra1 = options.extra1, fileType = options.fileType, size = options.size;
extension = name.substring(name.lastIndexOf('.') + 1);
filename = name.substring(0, name.lastIndexOf('.'));
(0, assert_1.default)(entity, '必须传入entity');
(0, assert_1.default)(origin === 'qiniu', '目前只支持七牛上传'); // 目前只支持七牛上传
_f = {
_e = {
extra1: extra1,
origin: origin,
type: type || 'file',
@ -232,51 +233,60 @@ exports.default = OakComponent({
};
return [4 /*yield*/, generateNewId()];
case 1:
updateData = (_f.objectId = _h.sent(),
_f.entity = entity,
_f.filename = filename,
_f.size = size,
_f.extension = extension,
_f);
if (!autoUpload) return [3 /*break*/, 8];
_h.label = 2;
updateData = (_e.objectId = _g.sent(),
_e.entity = entity,
_e.filename = filename,
_e.size = size,
_e.extension = extension,
_e.fileType = fileType,
_e);
if (!autoUpload) return [3 /*break*/, 11];
_g.label = 2;
case 2:
_h.trys.push([2, 6, , 7]);
_g.trys.push([2, 9, , 10]);
return [4 /*yield*/, this.features.extraFile.upload(updateData)];
case 3:
_b = _h.sent(), url = _b.url, bucket = _b.bucket;
_d = (_c = Object).assign;
_e = [updateData];
_g = {
bucket = (_g.sent()).bucket;
_g.label = 4;
case 4:
_g.trys.push([4, 7, , 8]);
_c = (_b = Object).assign;
_d = [updateData];
_f = {
bucket: bucket,
extra1: null
};
return [4 /*yield*/, generateNewId()];
case 4:
_d.apply(_c, _e.concat([(_g.id = _h.sent(),
_g)]));
return [4 /*yield*/, this.addExtraFile(updateData)];
case 5:
_h.sent();
_c.apply(_b, _d.concat([(_f.id = _g.sent(),
_f.entityId = entityId,
_f)]));
return [4 /*yield*/, this.addExtraFile(updateData)];
case 6:
_g.sent();
ele = {
updateData: updateData,
};
this.pushNode(undefined, ele);
return [3 /*break*/, 7];
case 6:
error_1 = _h.sent();
return [3 /*break*/, 7];
case 7: return [3 /*break*/, 9];
case 8:
return [3 /*break*/, 8];
case 7:
error_1 = _g.sent();
return [3 /*break*/, 8];
case 8: return [3 /*break*/, 10];
case 9:
err_2 = _g.sent();
return [3 /*break*/, 10];
case 10: return [3 /*break*/, 12];
case 11:
ele = {
updateData: updateData,
beforeExecute: function (updateData) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var _a, url, bucket;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
var bucket;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.features.extraFile.upload(updateData)];
case 1:
_a = _b.sent(), url = _a.url, bucket = _a.bucket;
bucket = (_a.sent()).bucket;
Object.assign(updateData, {
bucket: bucket,
extra1: null,
@ -287,8 +297,8 @@ exports.default = OakComponent({
}); },
};
this.pushNode(undefined, ele);
_h.label = 9;
case 9: return [2 /*return*/];
_g.label = 12;
case 12: return [2 /*return*/];
}
});
});

View File

@ -11,9 +11,9 @@ function extraFileToUploadFile(extraFile, systemConfig) {
}
function render() {
var _this = this;
var _a = this.props, mediaType = _a.mediaType, _b = _a.maxNumber, maxNumber = _b === void 0 ? 100 : _b, _c = _a.multiple, multiple = _c === void 0 ? true : _c, _d = _a.useMockProgress, useMockProgress = _d === void 0 ? false : _d, _e = _a.draggable, draggable = _e === void 0 ? false : _e, _f = _a.showUploadProgress, showUploadProgress = _f === void 0 ? false : _f, _g = _a.theme, theme = _g === void 0 ? 'image' : _g;
var _a = this.props, mediaType = _a.mediaType, _b = _a.maxNumber, maxNumber = _b === void 0 ? 100 : _b, _c = _a.multiple, multiple = _c === void 0 ? true : _c, _d = _a.useMockProgress, useMockProgress = _d === void 0 ? false : _d, _e = _a.draggable, draggable = _e === void 0 ? false : _e, _f = _a.showUploadProgress, showUploadProgress = _f === void 0 ? false : _f, _g = _a.theme, theme = _g === void 0 ? 'image' : _g, tips = _a.tips, placeholder = _a.placeholder, beforeUpload = _a.beforeUpload, disabled = _a.disabled, style = _a.style, className = _a.className, sizeLimit = _a.sizeLimit;
var _h = this.state, files = _h.files, systemConfig = _h.systemConfig;
return ((0, jsx_runtime_1.jsx)(tdesign_react_1.Upload, { multiple: multiple, autoUpload: false, draggable: draggable, useMockProgress: useMockProgress, max: maxNumber, accept: mediaType, showUploadProgress: showUploadProgress, theme: theme, files: (files || []).map(function (ele) {
return ((0, jsx_runtime_1.jsx)(tdesign_react_1.Upload, { sizeLimit: sizeLimit, className: className, style: style, disabled: disabled, beforeUpload: beforeUpload, placeholder: placeholder, tips: tips, multiple: multiple, autoUpload: false, draggable: draggable, useMockProgress: useMockProgress, max: maxNumber, accept: mediaType, showUploadProgress: showUploadProgress, theme: theme, files: (files || []).map(function (ele) {
return extraFileToUploadFile(ele, systemConfig);
}), onChange: function (uploadFiles) {
var newUploadFiles = (uploadFiles === null || uploadFiles === void 0 ? void 0 : uploadFiles.filter(function (ele) { return !ele.id; })) || [];
@ -23,7 +23,6 @@ function render() {
_this.onWebDelete(file, index);
}, onPreview: function (_a) {
var file = _a.file, e = _a.e;
// this.onWebDelete(file, e);
} }));
}
exports.default = render;

View File

@ -2,7 +2,7 @@ import { String, Int, Text } from 'oak-domain/lib/types/DataType';
import { FileCarrierEntityShape } from 'oak-domain/lib/types/Entity';
export interface Schema extends FileCarrierEntityShape {
origin: 'qiniu' | 'unknown';
type: 'image' | 'pdf' | 'video' | 'audio' | 'file';
type: 'image' | 'video' | 'audio' | 'file' | 'pdf';
bucket: String<16>;
objectId: String<64>;
tag1: String<16>;
@ -15,4 +15,5 @@ export interface Schema extends FileCarrierEntityShape {
extension: String<16>;
size?: Int<4>;
sort?: Int<4>;
fileType: String<16>;
}

View File

@ -18,6 +18,7 @@ var locale = {
extension: '后缀名',
size: '文件大小',
sort: '排序',
fileType: '文件类型',
},
v: {
origin: {
@ -26,10 +27,10 @@ var locale = {
},
type: {
image: '图像',
pdf: 'pdf',
video: '视频',
audio: '音频',
file: '文件',
pdf: 'pdf',
},
},
},

View File

@ -12,7 +12,7 @@ export declare type OpSchema = {
$$updateAt$$: Datetime;
$$deleteAt$$?: Datetime | null;
origin: 'qiniu' | 'unknown';
type: 'image' | 'pdf' | 'video' | 'audio' | 'file';
type: 'image' | 'video' | 'audio' | 'file' | 'pdf';
bucket: String<16>;
objectId: String<64>;
tag1: String<16>;
@ -25,6 +25,7 @@ export declare type OpSchema = {
extension: String<16>;
size?: Int<4> | null;
sort?: Int<4> | null;
fileType: String<16>;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = {
@ -33,7 +34,7 @@ export declare type Schema = {
$$updateAt$$: Datetime;
$$deleteAt$$?: Datetime | null;
origin: 'qiniu' | 'unknown';
type: 'image' | 'pdf' | 'video' | 'audio' | 'file';
type: 'image' | 'video' | 'audio' | 'file' | 'pdf';
bucket: String<16>;
objectId: String<64>;
tag1: String<16>;
@ -46,6 +47,7 @@ export declare type Schema = {
extension: String<16>;
size?: Int<4> | null;
sort?: Int<4> | null;
fileType: String<16>;
article?: Article.Schema;
user?: User.Schema;
} & {
@ -56,7 +58,7 @@ declare type AttrFilter<E> = {
$$createAt$$: Q_DateValue;
$$updateAt$$: Q_DateValue;
origin: Q_EnumValue<'qiniu' | 'unknown'>;
type: Q_EnumValue<'image' | 'pdf' | 'video' | 'audio' | 'file'>;
type: Q_EnumValue<'image' | 'video' | 'audio' | 'file' | 'pdf'>;
bucket: Q_StringValue;
objectId: Q_StringValue;
tag1: Q_StringValue;
@ -69,6 +71,7 @@ declare type AttrFilter<E> = {
extension: Q_StringValue;
size: Q_NumberValue;
sort: Q_NumberValue;
fileType: Q_StringValue;
article: Article.Filter;
user: User.Filter;
};
@ -93,6 +96,7 @@ export declare type Projection = {
extension?: 1;
size?: 1;
sort?: 1;
fileType?: 1;
article?: Article.Projection;
user?: User.Projection;
} & Partial<ExprOp<OpAttr | string>>;
@ -116,6 +120,7 @@ export declare type ExportProjection = {
extension?: string;
size?: string;
sort?: string;
fileType?: string;
article?: Article.ExportProjection;
user?: User.ExportProjection;
} & Partial<ExprOp<OpAttr | string>>;
@ -162,6 +167,8 @@ export declare type SortAttr = {
size: 1;
} | {
sort: 1;
} | {
fileType: 1;
} | {
article: Article.SortAttr;
} | {

View File

@ -83,6 +83,12 @@ exports.desc = {
width: 4,
signed: true
}
},
fileType: {
type: "varchar",
params: {
length: 16
}
}
},
actionType: "crud",

View File

@ -1 +1 @@
{ "attr": { "origin": "源", "type": "类型", "bucket": "桶", "objectId": "对象编号", "tag1": "标签一", "tag2": "标签二", "filename": "文件名", "md5": "md5", "entity": "关联对象", "entityId": "关联对象id", "extra1": "额外信息", "extension": "后缀名", "size": "文件大小", "sort": "排序" }, "v": { "origin": { "qiniu": "七牛云", "unknown": "未知" }, "type": { "image": "图像", "pdf": "pdf", "video": "视频", "audio": "音频", "file": "文件" } } }
{ "attr": { "origin": "源", "type": "类型", "bucket": "桶", "objectId": "对象编号", "tag1": "标签一", "tag2": "标签二", "filename": "文件名", "md5": "md5", "entity": "关联对象", "entityId": "关联对象id", "extra1": "额外信息", "extension": "后缀名", "size": "文件大小", "sort": "排序", "fileType": "文件类型" }, "v": { "origin": { "qiniu": "七牛云", "unknown": "未知" }, "type": { "image": "图像", "video": "视频", "audio": "音频", "file": "文件", "pdf": "pdf" } } }

View File

@ -82,6 +82,7 @@ export default OakComponent({
tag1: String,
tag2: String,
entity: String,
entityId: String,
},
methods: {
@ -173,7 +174,7 @@ export default OakComponent({
fileType: string;
size: number;
}) {
const { type, origin, tag1, tag2, entity, autoUpload } = this.props;
const { type, origin, tag1, tag2, entity, entityId, autoUpload } = this.props;
const { name, extra1, fileType, size } = options;
const extension = name.substring(name.lastIndexOf('.') + 1);
const filename = name.substring(0, name.lastIndexOf('.'));
@ -190,30 +191,36 @@ export default OakComponent({
filename,
size,
extension,
fileType,
} as DeduceCreateOperationData<EntityDict['extraFile']['Schema']>;
// autoUpload为true, 选择直接上传七牛再提交extraFile
if (autoUpload) {
try {
const { url, bucket } =
const { bucket } =
await this.features.extraFile.upload(updateData);
Object.assign(updateData, {
bucket,
extra1: null,
id: await generateNewId(),
});
await this.addExtraFile(updateData);
const ele: Parameters<typeof this['pushNode']>[1] = {
updateData: updateData,
};
this.pushNode(undefined, ele);
} catch (error) {
//上传七牛失败或保存extraFile失败 需要remove
try {
Object.assign(updateData, {
bucket,
extra1: null,
id: await generateNewId(),
entityId,
});
await this.addExtraFile(updateData);
const ele: Parameters<typeof this['pushNode']>[1] = {
updateData,
};
this.pushNode(undefined, ele);
} catch (error) {
//todo 保存extraFile失败 需要remove七牛图片
}
} catch (err) {
//上传七牛失败
}
} else {
const ele: Parameters<typeof this['pushNode']>[1] = {
updateData: updateData,
updateData,
beforeExecute: async (updateData) => {
const { url, bucket } =
const { bucket } =
await this.features.extraFile.upload(updateData);
Object.assign(updateData, {
bucket,

View File

@ -22,11 +22,25 @@ export default function render(this: any) {
draggable = false,
showUploadProgress = false,
theme = 'image',
tips,
placeholder,
beforeUpload,
disabled,
style,
className,
sizeLimit,
} = this.props;
const { files, systemConfig } = this.state;
return (
<Upload
sizeLimit={sizeLimit}
className={className}
style={style}
disabled={disabled}
beforeUpload={beforeUpload}
placeholder={placeholder}
tips={tips}
multiple={multiple}
autoUpload={false}
draggable={draggable}
@ -39,15 +53,14 @@ export default function render(this: any) {
extraFileToUploadFile(ele, systemConfig)
)}
onChange={(uploadFiles) => {
const newUploadFiles = uploadFiles?.filter((ele: ExtraFile) => !ele.id) || [];
const newUploadFiles =
uploadFiles?.filter((ele: ExtraFile) => !ele.id) || [];
this.onWebPick(newUploadFiles);
}}
onRemove={({ file, index, e }) => {
this.onWebDelete(file, index);
}}
onPreview={({ file, e }) => {
// this.onWebDelete(file, e);
}}
onPreview={({ file, e }) => {}}
/>
);
}

View File

@ -4,7 +4,7 @@ import { LocaleDef } from 'oak-domain/lib/types/Locale';
export interface Schema extends FileCarrierEntityShape {
origin: 'qiniu' | 'unknown';
type: 'image' | 'pdf' | 'video' | 'audio' | 'file';
type: 'image' | 'video' | 'audio' | 'file' | 'pdf';
bucket: String<16>;
objectId: String<64>;
tag1: String<16>;
@ -17,6 +17,7 @@ export interface Schema extends FileCarrierEntityShape {
extension: String<16>;
size?: Int<4>;
sort?: Int<4>;
fileType: String<16>;
};
const locale: LocaleDef<
@ -44,6 +45,7 @@ const locale: LocaleDef<
extension: '后缀名',
size: '文件大小',
sort: '排序',
fileType: '文件类型',
},
v: {
origin: {
@ -52,10 +54,10 @@ const locale: LocaleDef<
},
type: {
image: '图像',
pdf: 'pdf',
video: '视频',
audio: '音频',
file: '文件',
pdf: 'pdf',
},
},
},