import { PageListController } from "@queenjs/controllers"; import { ResourceModule } from "."; import { PromotionController } from "./controllers/PromotionController"; import { MaterialController } from "./controllers/MaterialController"; 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}`; }, createPromotinController() { const ctrl= new PromotionController(); ctrl.ListCtrl = new PageListController(this.config?.httpConfig); ctrl.ListCtrl.setCrudPrefix("/h5") ctrl.createPromotion = this.actions.createPromotion; return ctrl; }, createSourceController(isSelectModel:boolean, selectType :string) { 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 } });