123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- import { PageListController } from "@queenjs/controllers";
- import { queenApi } from "queenjs";
- import { ResourceModule } from ".";
- import { ComponentController } from "./controllers/ComponentController";
- 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}`;
- },
- createCompController() {
- const ctrl = new ComponentController();
- ctrl.ListCtrl = new PageListController(this.config?.httpConfig);
- ctrl.ListCtrl.setCrudPrefix("/frame");
- ctrl.createComp = this.actions.createComp;
- ctrl.onMenuClick = async (name, record) => {
- if (name == "delete") {
- await this.actions.deleteComp(record);
- ctrl.ListCtrl.fresh();
- } else if (name == "rename") {
- await this.actions.renameComp(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",
- };
- result.successRow.push(souceObj);
- }
- }
- queenApi.hideLoading();
- return result;
- },
- });
|