上传图片组件删除修正

This commit is contained in:
Wang Kejun 2022-09-09 19:21:35 +08:00
parent 0406f86a94
commit 354ee30e2a
39 changed files with 155 additions and 105 deletions

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -11,9 +11,9 @@ exports.default = OakComponent({
isList: true,
formData: function (_a) {
var _b, _c;
var files = _a.data, features = _a.features;
var originalFiles = _a.data, features = _a.features;
return tslib_1.__awaiter(this, void 0, void 0, function () {
var application, number2, files2;
var application, number2, files;
var _this = this;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
@ -21,25 +21,27 @@ exports.default = OakComponent({
case 1:
application = _d.sent();
number2 = this.props.maxNumber;
files2 = files;
files = originalFiles;
if (this.props.tag1) {
files2 = files2.filter(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.tag1) === _this.props.tag1; });
files = files === null || files === void 0 ? void 0 : files.filter(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.tag1) === _this.props.tag1; });
}
if (this.props.tag2) {
files2 = files2.filter(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.tag2) === _this.props.tag2; });
files = files === null || files === void 0 ? void 0 : files.filter(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.tag2) === _this.props.tag2; });
}
if (typeof number2 === 'number' &&
(number2 === 0 || (files === null || files === void 0 ? void 0 : files.length) >= number2)) {
return [2 /*return*/, {
files: files2,
files: files,
disableInsert: true,
systemConfig: (_b = application === null || application === void 0 ? void 0 : application.system) === null || _b === void 0 ? void 0 : _b.config,
originalFiles: originalFiles,
}];
}
return [2 /*return*/, {
files: files2,
files: files,
disableInsert: false,
systemConfig: (_c = application === null || application === void 0 ? void 0 : application.system) === null || _c === void 0 ? void 0 : _c.config,
originalFiles: originalFiles,
}];
}
});
@ -276,7 +278,6 @@ exports.default = OakComponent({
if (callback) {
callback(updateData);
}
;
ele = {
updateData: updateData,
};
@ -316,18 +317,6 @@ exports.default = OakComponent({
});
});
},
setNewUploadFiles: function (file) {
var filename = file.filename, size = file.size, id = file.id;
var newUploadFiles = this.state.newUploadFiles;
var file2 = newUploadFiles.find(function (ele) { return ele.filename = filename && ele.size === size; });
Object.assign(file2, {
status: 'success',
id: id,
});
this.setState({
newUploadFiles: tslib_1.__spreadArray([], tslib_1.__read(newUploadFiles), false),
});
},
onItemTapped: function (event) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, files, systemConfig, index, imageUrl, urls, detail, result;
@ -361,14 +350,16 @@ exports.default = OakComponent({
},
onDelete: function (event) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var _a, value, index, id, result, confirm_1;
var originalFiles, _a, value, index, id, findIndex, result, confirm_1;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
originalFiles = this.state.originalFiles;
_a = event.currentTarget.dataset, value = _a.value, index = _a.index;
id = value.id;
findIndex = originalFiles === null || originalFiles === void 0 ? void 0 : originalFiles.findIndex(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.id) === id; });
if (!(0, mockId_1.isMockId)(id)) return [3 /*break*/, 1];
this.removeNode('', "".concat(index));
this.removeNode('', "".concat(findIndex));
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, wx.showModal({
title: '确认删除吗',
@ -378,7 +369,7 @@ exports.default = OakComponent({
result = _b.sent();
confirm_1 = result.confirm;
if (confirm_1) {
this.removeNode('', "".concat(index));
this.removeNode('', "".concat(findIndex));
}
_b.label = 3;
case 3: return [2 /*return*/];
@ -386,28 +377,16 @@ exports.default = OakComponent({
});
});
},
customDelete: function (index) {
onWebDelete: function (value) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var newUploadFiles, arr;
return tslib_1.__generator(this, function (_a) {
newUploadFiles = this.state.newUploadFiles;
arr = tslib_1.__spreadArray([], tslib_1.__read(newUploadFiles), false);
arr.splice(index, 1);
this.setState({
newUploadFiles: arr,
});
return [2 /*return*/];
});
});
},
onWebDelete: function (value, index) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var id, confirm_2;
var originalFiles, id, findIndex, confirm_2;
var _this = this;
return tslib_1.__generator(this, function (_a) {
originalFiles = this.state.originalFiles;
id = value.id;
findIndex = originalFiles === null || originalFiles === void 0 ? void 0 : originalFiles.findIndex(function (ele) { return (ele === null || ele === void 0 ? void 0 : ele.id) === id; });
if ((0, mockId_1.isMockId)(id)) {
this.removeNode('', "".concat(index));
this.removeNode('', "".concat(findIndex));
}
else {
confirm_2 = index_1.default.confirm({
@ -418,7 +397,7 @@ exports.default = OakComponent({
cancelBtn: '取消',
confirmBtn: '确定',
onConfirm: function () {
_this.removeNode('', "".concat(index));
_this.removeNode('', "".concat(findIndex));
confirm_2.hide();
},
onCancel: function () {
@ -459,7 +438,7 @@ exports.default = OakComponent({
types_1.OakUnloggedInException.name) {
this.navigateTo({
url: '/login',
});
}, undefined, true);
return [2 /*return*/];
}
throw error_2;
@ -468,6 +447,32 @@ exports.default = OakComponent({
});
});
},
setNewUploadFiles: function (file) {
var filename = file.filename, size = file.size, id = file.id;
var newUploadFiles = this.state.newUploadFiles;
var file2 = newUploadFiles.findIndex(function (ele) { return (ele.filename = filename && ele.size === size); });
Object.assign(file2, {
status: 'success',
id: id,
});
this.setState({
newUploadFiles: tslib_1.__spreadArray([], tslib_1.__read(newUploadFiles), false),
});
},
customDelete: function (index) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var newUploadFiles, arr;
return tslib_1.__generator(this, function (_a) {
newUploadFiles = this.state.newUploadFiles;
arr = tslib_1.__spreadArray([], tslib_1.__read(newUploadFiles), false);
arr.splice(index, 1);
this.setState({
newUploadFiles: arr,
});
return [2 /*return*/];
});
});
},
},
observers: {
maxNumber: function () {

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -43,7 +43,6 @@ declare type AttrFilter = {
code: Q_StringValue;
visitorId: Q_StringValue;
reason: Q_StringValue;
env: Object;
expired: Q_BooleanValue;
expiresAt: Q_DateValue;
iState: Q_EnumValue<IState>;

View File

@ -45,9 +45,6 @@ declare type AttrFilter = {
entity: Q_StringValue;
entityId: Q_StringValue;
action: Q_StringValue;
data: Object;
filter: Object;
extra: Object;
iState: Q_EnumValue<IState>;
};
export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;

View File

@ -38,9 +38,6 @@ declare type AttrFilter = {
$$createAt$$: Q_DateValue;
$$updateAt$$: Q_DateValue;
action: Q_StringValue;
data: Object;
filter: Object;
extra: Object;
operatorId: Q_StringValue | SubQuery.UserIdSubQuery;
operator: User.Filter;
};

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1,2 +1,3 @@
/// <reference types="react" />
import '@wangeditor/editor/dist/css/style.css';
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -1 +1,2 @@
/// <reference types="react" />
export default function render(this: any): JSX.Element;

View File

@ -8,34 +8,32 @@ import { composeFileUrl } from '../../../utils/extraFile';
export default OakComponent({
entity: 'extraFile',
isList: true,
async formData({ data: files, features }) {
async formData({ data: originalFiles, features }) {
const application = await features.application.getApplication();
const number2 = this.props.maxNumber;
let files2 = files;
let files = originalFiles as Array<EntityDict['extraFile']['OpSchema']>;
if (this.props.tag1) {
files2 = files2.filter(
ele => ele?.tag1 === this.props.tag1
);
files = files?.filter((ele) => ele?.tag1 === this.props.tag1);
}
if (this.props.tag2) {
files2 = files2.filter(
ele => ele?.tag2 === this.props.tag2
);
files = files?.filter((ele) => ele?.tag2 === this.props.tag2);
}
if (
typeof number2 === 'number' &&
(number2 === 0 || files?.length >= number2)
) {
return {
files: files2,
files,
disableInsert: true,
systemConfig: application?.system?.config,
originalFiles,
};
}
return {
files: files2,
files,
disableInsert: false,
systemConfig: application?.system?.config,
originalFiles,
};
},
data: {
@ -171,22 +169,29 @@ export default OakComponent({
await Promise.all(
uploadFiles.map(async (uploadFile) => {
const { name, type: fileType, size, raw } = uploadFile;
this.pushExtraFile({
name,
fileType,
size,
extra1: raw,
}, callback);
this.pushExtraFile(
{
name,
fileType,
size,
extra1: raw,
},
callback
);
})
);
},
async pushExtraFile(options: {
name: string;
extra1: any;
fileType: string;
size: number;
}, callback?: (file:any) => void) {
const { type, origin, tag1, tag2, entity, entityId, autoUpload } = this.props;
async pushExtraFile(
options: {
name: string;
extra1: any;
fileType: string;
size: number;
},
callback?: (file: any) => void
) {
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('.'));
@ -208,8 +213,9 @@ export default OakComponent({
// autoUpload为true, 选择直接上传七牛再提交extraFile
if (autoUpload) {
try {
const { bucket } =
await this.features.extraFile.upload(updateData);
const { bucket } = await this.features.extraFile.upload(
updateData
);
try {
Object.assign(updateData, {
bucket,
@ -220,7 +226,7 @@ export default OakComponent({
await this.addExtraFile(updateData);
if (callback) {
callback(updateData);
};
}
const ele: Parameters<typeof this['pushNode']>[1] = {
updateData,
};
@ -235,8 +241,9 @@ export default OakComponent({
const ele: Parameters<typeof this['pushNode']>[1] = {
updateData,
beforeExecute: async (updateData) => {
const { bucket } =
await this.features.extraFile.upload(updateData);
const { bucket } = await this.features.extraFile.upload(
updateData
);
Object.assign(updateData, {
bucket,
extra1: null,
@ -247,18 +254,6 @@ export default OakComponent({
this.pushNode(undefined, ele);
}
},
setNewUploadFiles(file: any) {
const { filename, size, id } = file;
const { newUploadFiles } = this.state;
const file2 = newUploadFiles.find((ele: any) => ele.filename = filename && ele.size === size) as any;
Object.assign(file2, {
status: 'success',
id,
})
this.setState({
newUploadFiles: [...newUploadFiles],
})
},
async onItemTapped(event: WechatMiniprogram.Touch) {
const { files, systemConfig } = this.state;
const { index } = event.currentTarget.dataset;
@ -284,10 +279,13 @@ export default OakComponent({
}
},
async onDelete(event: WechatMiniprogram.Touch) {
const { originalFiles } = this.state;
const { value, index } = event.currentTarget.dataset;
const { id } = value;
const findIndex = originalFiles?.findIndex((ele) => ele?.id === id);
if (isMockId(id)) {
this.removeNode('', `${index}`);
this.removeNode('', `${findIndex}`);
} else {
const result = await wx.showModal({
title: '确认删除吗',
@ -295,22 +293,16 @@ export default OakComponent({
});
const { confirm } = result;
if (confirm) {
this.removeNode('', `${index}`);
this.removeNode('', `${findIndex}`);
}
}
},
async customDelete(index: number) {
const { newUploadFiles } = this.state;
const arr = [...newUploadFiles];
arr.splice(index, 1);
this.setState({
newUploadFiles: arr,
})
},
async onWebDelete(value: any, index: number) {
async onWebDelete(value: any) {
const { originalFiles } = this.state;
const { id } = value;
const findIndex = originalFiles?.findIndex((ele) => ele?.id === id);
if (isMockId(id)) {
this.removeNode('', `${index}`);
this.removeNode('', `${findIndex}`);
} else {
const confirm = Dialog.confirm({
header: '确认删除当前文件?',
@ -320,7 +312,7 @@ export default OakComponent({
cancelBtn: '取消',
confirmBtn: '确定',
onConfirm: () => {
this.removeNode('', `${index}`);
this.removeNode('', `${findIndex}`);
confirm.hide();
},
onCancel: () => {
@ -349,14 +341,40 @@ export default OakComponent({
(<OakException>error).constructor.name ===
OakUnloggedInException.name
) {
this.navigateTo({
url: '/login',
});
this.navigateTo(
{
url: '/login',
},
undefined,
true
);
return;
}
throw error;
}
},
setNewUploadFiles(file: any) {
const { filename, size, id } = file;
const { newUploadFiles } = this.state;
const file2 = newUploadFiles.findIndex(
(ele: any) => (ele.filename = filename && ele.size === size)
) as any;
Object.assign(file2, {
status: 'success',
id,
});
this.setState({
newUploadFiles: [...newUploadFiles],
});
},
async customDelete(index: number) {
const { newUploadFiles } = this.state;
const arr = [...newUploadFiles];
arr.splice(index, 1);
this.setState({
newUploadFiles: arr,
});
},
},
observers: {