bianjiang 1 year ago
parent
commit
5378e6ff18

+ 8 - 2
src/modules/resource/actions/promotion.tsx

@@ -44,7 +44,7 @@ export const promotionAction = ResourceModule.action({
     if (!res) return;
     await this.https.deleteComp(record._id);
   },
-  async editSource(record: any, sourceType: string) {
+  async editSource(record: any, sourceType: string, editCategory = true) {
     // const itemRes = await this.https.detailComp(record._id);
     // if (itemRes.errorNo != 200) {
     //   queenApi.messageWarn("未查询到数据!");
@@ -52,7 +52,11 @@ export const promotionAction = ResourceModule.action({
     // }
     let type = sourceType.toLowerCase();
     const res = await this.showModal(
-      <this.components.SouceModal item={record} sourceType={type} />,
+      <this.components.SouceModal
+        item={record}
+        sourceType={type}
+        editCategory={editCategory}
+      />,
       {
         width: "360px",
         title: "编辑",
@@ -62,6 +66,8 @@ export const promotionAction = ResourceModule.action({
 
     if (type == "image" || type == "video") {
       await this.https.updateResouce(res);
+    } else if (type == "template") {
+      await this.https.updatePromotion(res);
     } else {
       await this.https.updateComp(res);
     }

+ 44 - 27
src/modules/resource/components/SouceModal.tsx

@@ -3,12 +3,14 @@ import { Image } from "@queenjs/ui";
 import { Button, Form, Input, TreeSelect } from "ant-design-vue";
 import { useModal } from "queenjs";
 import { defineComponent, nextTick, onMounted, reactive, ref } from "vue";
-import { any, string } from "vue-types";
+import { any, bool, string } from "vue-types";
 import { useResource } from "..";
+import { SelectOneImage } from "@/pages/website/Material2/modal";
 export default defineComponent({
   props: {
     item: any(),
     sourceType: string().isRequired,
+    editCategory: bool(),
   },
   setup(props) {
     const { controls } = useResource();
@@ -22,7 +24,7 @@ export default defineComponent({
       data.categories = [];
     }
     const formState: { [name: string]: any } = reactive({ ...data });
-    const sourceTitle = ["comp", "shape", "text"];
+    const sourceTitle = ["comp", "shape", "text", "template", "v"];
     const state = reactive({
       categoriesVal: {} as any,
       categoryList: [] as any,
@@ -78,10 +80,16 @@ export default defineComponent({
     const rules = ref({
       title: [
         {
-          required: sourceTitle.includes(props.sourceType) ? true : false,
+          required: props.sourceType != "image" ? true : false,
           message: "名称不能为空!",
         },
       ],
+      thumbnail: [
+        {
+          required: props.sourceType != "image" ? true : false,
+          message: "封面图不能为空",
+        },
+      ],
     });
 
     const { validate, validateInfos } = Form.useForm(formState, rules);
@@ -98,6 +106,14 @@ export default defineComponent({
         modal.submit(formState);
       });
     };
+    const changeThumbnail = async () => {
+      if (props.sourceType == "image") {
+        return;
+      }
+      const url = await SelectOneImage();
+      if (!url) return;
+      formState.thumbnail = url;
+    };
 
     return () => {
       const thumbnail =
@@ -106,8 +122,8 @@ export default defineComponent({
         <div class={configFormStyle}>
           <div class="modal_form">
             <Form name="basic">
-              <Form.Item name="thumbnail">
-                <div class={"h-180px bg-light-50"}>
+              <Form.Item name="thumbnail" {...validateInfos.thumbnail}>
+                <div class={"h-180px bg-light-50"} onClick={changeThumbnail}>
                   <Image
                     class="w-1/1 h-1/1 !object-contain"
                     src={thumbnail}
@@ -121,28 +137,29 @@ export default defineComponent({
                   <Input v-model={[formState.title, "value"]} />
                 </Form.Item>
               )}
-              {state.categoryList.map((item: any, index: number) => {
-                return (
-                  <Form.Item key={index} name={`categories.${index}`}>
-                    <TreeSelect
-                      value={state.categoriesVal[item.id]}
-                      allowClear
-                      treeCheckable
-                      dropdownStyle={{ maxHeight: "500px", overflow: "auto" }}
-                      placeholder={`请选择${item.name}`}
-                      treeData={item?.children}
-                      replaceFields={{
-                        children: "children",
-                        label: "name",
-                        value: "id",
-                      }}
-                      onChange={(v) => {
-                        state.categoriesVal[item.id] = v;
-                      }}
-                    />
-                  </Form.Item>
-                );
-              })}
+              {props.editCategory &&
+                state.categoryList.map((item: any, index: number) => {
+                  return (
+                    <Form.Item key={index} name={`categories.${index}`}>
+                      <TreeSelect
+                        value={state.categoriesVal[item.id]}
+                        allowClear
+                        treeCheckable
+                        dropdownStyle={{ maxHeight: "500px", overflow: "auto" }}
+                        placeholder={`请选择${item.name}`}
+                        treeData={item?.children}
+                        replaceFields={{
+                          children: "children",
+                          label: "name",
+                          value: "id",
+                        }}
+                        onChange={(v) => {
+                          state.categoriesVal[item.id] = v;
+                        }}
+                      />
+                    </Form.Item>
+                  );
+                })}
             </Form>
           </div>
           <div class="modal_footer">

+ 2 - 2
src/modules/resource/controllers/PromotionController.ts

@@ -5,8 +5,8 @@ export class PromotionController {
   createPromotion() {
     console.log("createPromotion");
   }
-  onMenuClick(menu: string, item: any) {
-    console.log("onMenuClick", menu, item);
+  onMenuClick(menu: string, item: any, isSys: boolean) {
+    console.log("onMenuClick", menu, item, isSys);
   }
   onEdit(item: any) {
     const _params = new URLSearchParams(decodeURIComponent(location.search));

+ 6 - 3
src/pages/website/Promotion2/components/PromotionItem.tsx

@@ -110,8 +110,11 @@ export default defineUI({
                     <div onClick={() => emit("menu", "stat")}>统计分析</div>
                   </Menu.Item>
                   <Menu.Item>
-                    <div onClick={() => emit("menu", "rename")}>重命名</div>
+                    <div onClick={() => emit("menu", "edit")}>编辑</div>
                   </Menu.Item>
+                  {/* <Menu.Item>
+                    <div onClick={() => emit("menu", "rename")}>重命名</div>
+                  </Menu.Item> */}
                   <Menu.Item>
                     <div onClick={() => emit("menu", "delete")}>删除</div>
                   </Menu.Item>
@@ -132,13 +135,13 @@ export default defineUI({
                     </Menu.Item>
                   )}
 
-                  {isSys && (
+                  {/* {isSys && (
                     <Menu.Item>
                       <div onClick={() => emit("menu", "thumbnail")}>
                         替换封面
                       </div>
                     </Menu.Item>
-                  )}
+                  )} */}
                 </Menu>
               }
             >

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

@@ -5,6 +5,7 @@ import { onMounted } from "vue";
 import { any } from "vue-types";
 import Header from "./Header";
 import PromotionItem from "./PromotionItem";
+import { useAuth } from "@queenjs-modules/auth";
 
 export default defineUI({
   props: {
@@ -16,11 +17,15 @@ export default defineUI({
     List,
   },
   setup(props, { slots }) {
+    const auth = useAuth();
+
     onMounted(() => {
       props.Controller.ListCtrl.loadPage(1);
     });
 
     return () => {
+      //@ts-ignore
+      const isSys = (auth.store.userInfo.roles || []).indexOf("system") > -1;
       return (
         <div>
           <slots.Header onAdd={props.Controller.createPromotion} />
@@ -33,7 +38,7 @@ export default defineUI({
               <PromotionItem
                 record={record}
                 onMenu={(name) => {
-                  props.Controller.onMenuClick(name, record);
+                  props.Controller.onMenuClick(name, record, isSys);
                 }}
                 onEdit={(record) => props.Controller.onEdit(record)}
               />

+ 5 - 1
src/pages/website/Promotion2/controller.tsx

@@ -44,7 +44,7 @@ export function createPromotinController(
     });
   }
   let url = "";
-  ctrl.onMenuClick = async (name, record) => {
+  ctrl.onMenuClick = async (name, record, isSys) => {
     switch (name) {
       case "stat":
         window.open("https://show.3dqueen.cloud/stat/#/count?id=" + record._id);
@@ -70,6 +70,10 @@ export function createPromotinController(
         await resource.actions.publishPromotion(record, false);
         break;
 
+      case "edit":
+        await resource.actions.editSource(record, "template", isSys);
+        ctrl.ListCtrl.fresh();
+        break;
       case "thumbnail":
         url = (await SelectOneImage()) as string;
         if (!url) return;