Quellcode durchsuchen

控制器下沉到module里面去创建

liwei vor 1 Jahr
Ursprung
Commit
9fbe63675f

+ 4 - 1
src/modules/resource/actions/promotion.ts

@@ -1,5 +1,7 @@
 import { queenApi } from "queenjs";
 import { ResourceModule } from "..";
+import { PromotionController } from "../controllers/PromotionController";
+import { PageListController } from "@queenjs/controllers";
 
 export const promotionAction = ResourceModule.action({
   async renamePromotion(record: any) {
@@ -30,5 +32,6 @@ export const promotionAction = ResourceModule.action({
     const res = await this.https.createPromotion({ title });
     const url = `${location.origin}/editor.html#/?id=${res.result}`;
     location.href = url;
-  },
+  }
+
 });

+ 15 - 1
src/pages/website/Material2/components/MaterialController.ts → src/modules/resource/controllers/MaterialController.ts

@@ -6,13 +6,23 @@ export class MaterialController  {
     imageCtrl = new PageListController<any, any>();
     vidoeCtrl = new PageListController<any, any>();
     taskCtrl = new PageListController<any, any>();
+    tplCtrl = new PageListController<any, any>();
 
+    async showDialog(type:string) {
+        const ctrl = this.tplCtrl;
+        ctrl.state.query = type == "video" ? { hasVideo: true } : {}
+        ctrl.loadPage(1);
+        const record:any = await this.onShowDialog(ctrl, type);
+        if (record && record._id) {
+            const url = `${location.origin}/index.html#/create/${record._id}`;
+            location.href = url;
+        }
+    }
     switchTab(name: string, fresh = true) {
         this.state.currTab = name;
         const ctrol = this.getCurrControl();
         if(fresh)  ctrol.fresh();
     }
-
     getCurrControl() : PageListController<any, any> {
         switch (this.state.currTab) {
             case "image": return this.imageCtrl;
@@ -21,12 +31,16 @@ export class MaterialController  {
         }
     }
 
+
     onBtnClick(name:string) {
         console.log("onBtnClick", name)
     }
     onItemClick(name: "delete" | "download", record:any) {
         console.log("onItemClick", name, record)
     }
+    async onShowDialog(listCtrl: PageListController<any, any>, type:string) {
+        console.log("onShowDialog", type)
+    }
 }
 
 export const TabNames = {

+ 0 - 0
src/pages/website/Promotion2/components/PromotionController.ts → src/modules/resource/controllers/PromotionController.ts


+ 37 - 0
src/modules/resource/helper.ts

@@ -1,4 +1,7 @@
+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) {
@@ -10,4 +13,38 @@ export const helper = ResourceModule.helper({
       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
+  }
 });

+ 1 - 1
src/modules/resource/index.ts

@@ -18,7 +18,7 @@ export class ResourceModule extends ModuleRoot {
   components = this.useComponents(compoents);
   store = this.createStore([store]);
   https = this.createHttps(http);
-  helpers = this.createHelper(helper);
+  helper = this.createHelper(helper);
 
   controls = {
     uploader: new UploadController({

+ 2 - 2
src/pages/website/Material/index.tsx

@@ -1,10 +1,10 @@
-import { useResource } from "@/modules/resource";
+import { initResource, useResource } from "@/modules/resource";
 import { defineComponent } from "vue";
 
 export default defineComponent({
   setup() {
     const resource = useResource();
-
+    
     return () => {
       return (
         <div>

+ 1 - 1
src/pages/website/Material2/components/Material.tsx

@@ -5,8 +5,8 @@ import { Button } from "ant-design-vue";
 import AssetsList from "@/components/AssetsList";
 import { any } from "vue-types";
 import MaterialItem from "./MaterialItem";
-import {MaterialController } from "./MaterialController";
 import { onMounted } from "vue";
+import { MaterialController } from "@/modules/resource/controllers/MaterialController";
 
 
 export default defineUI({

+ 1 - 1
src/pages/website/Material2/components/MaterialToolbar.tsx

@@ -2,7 +2,7 @@ import { Button } from "ant-design-vue";
 import { defineComponent } from "vue";
 import { css, cx } from "@linaria/core";
 import { any } from "vue-types";
-import { BtnNames, MaterialController, TabNames } from "./MaterialController";
+import { BtnNames, MaterialController, TabNames } from "../../../../modules/resource/controllers/MaterialController";
 import { defineUI } from "queenjs";
 
 const materialType = [

+ 1 - 1
src/pages/website/Material2/controller.tsx

@@ -1,5 +1,5 @@
 import SelectListItemModal from "./components/SelectListItemModal";
-import { MaterialController } from "./components/MaterialController";
+import { MaterialController } from "../../../modules/resource/controllers/MaterialController";
 
 export default function createController(resource:any, isSelectModel:boolean, selectType :string) {
     const {controls, actions} = resource;

+ 1 - 1
src/pages/website/Promotion2/components/index.tsx

@@ -5,7 +5,7 @@ import Header from "./Header";
 import PromotionItem from "./PromotionItem"
 import { defineUI } from "queenjs";
 import { any } from "vue-types";
-import { PromotionController } from "./PromotionController";
+import { PromotionController } from "@/modules/resource/controllers/PromotionController";
 
 
 export default defineUI({

+ 2 - 9
src/pages/website/Promotion2/index.tsx

@@ -1,18 +1,11 @@
 import { useResource } from "@/modules/resource";
 import { defineComponent } from "vue";
-import PromotionUI from "./components";
-import { PromotionController } from "./components/PromotionController";
-import { PageListController } from "@queenjs/controllers";
 
+import PromotionUI from "./components";
 export default defineComponent({
   setup() {
-    
     const resource = useResource();
-    const ctrl= new PromotionController();
-    ctrl.ListCtrl = new PageListController(resource.config?.httpConfig);
-    ctrl.ListCtrl.setCrudPrefix("/h5")
-    ctrl.createPromotion = resource.actions.createPromotion;
-    
+    const ctrl = resource.helper.createPromotinController();
     return () => (
       <PromotionUI
         Controller={ctrl}