import { queenApi } from "queenjs"; import { ResourceModule } from "."; export const helper = ResourceModule.helper({ createFileName(fileName: string, dir: string) { const suffix = fileName.substring(fileName.lastIndexOf(".")); if (/[\u4e00-\u9fa5]/.test(fileName) || fileName.length > 10) { fileName = `${this.controls.uploader.randomName(4)}${suffix}`; } return `${dir}/${Date.now()}_${this.controls.uploader.randomName( 6 )}_${fileName}`; }, // createSourceController() { // const { controls, actions } = this; // const ctrl = new MaterialController(); // ctrl.imageCtrl = controls.materialImageListCtrl; // ctrl.vidoeCtrl = controls.materialVideoListCtrl; // ctrl.taskCtrl = controls.renderTaskListCtrl; // ctrl.tplCtrl = controls.matTempListCtrl; // ctrl.onBtnClick = async function (name: string) { // if (name == "upload") { // const uploaded = await actions.uploadMaterial(); // ctrl.switchTab(uploaded.fileType, false); // ctrl.getCurrControl().loadPage(1); // return; // } // ctrl.showDialog(name); // }; // ctrl.onItemClick = function (name, record) { // if (name == "delete") return actions.deleteMaterial(record); // return actions.downloadMaterial(record); // }; // return ctrl; // }, async uploadResource(opts?: { accept?: string; multiple?: boolean }) { const result = []; const blobs = await queenApi.selectFile(opts); queenApi.showLoading("上传中……"); for (const key in blobs) { const blob = blobs[key]; const file = await this.controls.uploader.uploadFile(blob, "queenshow"); const souceObj = { file, fileType: blob.type.split("/")[0], from: "upload", }; result.push(souceObj); } queenApi.hideLoading(); return result; }, async uploadMaterials(opts?: { accept?: string; multiple?: boolean }) { const result: any = { successRow: [], failRow: [], }; const blobs = await queenApi.selectFile(opts); queenApi.showLoading("上传中……"); for (const key in blobs) { const blob = blobs[key]; if (blob.type.indexOf("image") !== -1 && blob.size >= 10 * 1024 * 1024) { result.failRow.push(blob); } else if ( blob.type.indexOf("video") !== -1 && blob.size >= 200 * 1024 * 1024 ) { result.failRow.push(blob); } else { const file = await this.controls.uploader.uploadFile(blob, "queenshow"); const souceObj = { file, fileType: blob.type.split("/")[0], from: "upload", isSvg: blob.name.toLowerCase().lastIndexOf(".svg") == blob.name.length -4 }; result.successRow.push(souceObj); } } queenApi.hideLoading(); return result; }, });