shaogen1995 2 lat temu
rodzic
commit
021a72ebb9

后台/src/components/Z_RicjText/index.module.scss → 后台/src/components/Z_RichText/index.module.scss


+ 5 - 4
后台/src/components/Z_RicjText/index.tsx

@@ -18,20 +18,21 @@ import "braft-editor/dist/index.css";
 
 import classNames from "classnames";
 import { MessageFu } from "@/utils/message";
-import { B2_APIupFile } from "@/store/action/B2Goods";
 import { fileDomInitialFu } from "@/utils/domShow";
 import { baseURL } from "@/utils/http";
 
 import { forwardRef, useImperativeHandle } from "react";
+import { A1_APIupFile } from "@/store/action/A1Plate";
 
 type Props = {
   check: boolean; //表单校验,为fasle表示不校验
   dirCode: string; //文件的code码
   isLook: boolean; //是否是查看进来
   ref: any; //当前自己的ref,给父组件调用
+  myUrl: string; //上传的api地址
 };
 
-function RichText({ check, dirCode, isLook }: Props, ref: any) {
+function RichText({ check, dirCode, isLook, myUrl }: Props, ref: any) {
   // 添加 上传 图片的dom
   useEffect(() => {
     if (!isLook) {
@@ -100,7 +101,7 @@ function RichText({ check, dirCode, isLook }: Props, ref: any) {
         e.target.value = "";
 
         try {
-          const res = await B2_APIupFile(fd);
+          const res = await A1_APIupFile(fd, myUrl);
           if (res.code === 0) {
             MessageFu.success("上传成功!");
             // 在光标位置插入图片
@@ -119,7 +120,7 @@ function RichText({ check, dirCode, isLook }: Props, ref: any) {
         }
       }
     },
-    [dirCode, editorValue]
+    [dirCode, editorValue, myUrl]
   );
 
   // 让父组件调用的 回显 富文本

+ 15 - 7
后台/src/pages/B2Goods/B2Edit/index.tsx

@@ -7,7 +7,7 @@ import { RootState } from "@/store";
 import UpFileOne from "@/components/Z_upFileOne";
 import { B2_APIgetInfo, B2_APIsave } from "@/store/action/B2Goods";
 import { MessageFu } from "@/utils/message";
-import RichText from "@/components/Z_RicjText";
+import RichText from "@/components/Z_RichText";
 import TextArea from "antd/es/input/TextArea";
 
 type Props = {
@@ -26,8 +26,10 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
       FormBoxRef.current?.setFieldsValue(res.data);
       setCover(res.data.thumb);
 
+      setDirCode(res.data.id);
+
       // 调用富文本子组件的函数,回显数据
-      ricjTxtRef.current.ritxtShowFu(res.data.content);
+      richTxtRef.current.ritxtShowFu(res.data.content);
     }
   }, []);
 
@@ -37,6 +39,8 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
   useEffect(() => {
     if (editId > 0) getInfoFu(editId);
     else {
+      setDirCode(Date.now() + "");
+
       FormBoxRef.current?.setFieldsValue({
         type: myType,
       });
@@ -66,7 +70,7 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
       if (!cover) return;
 
       // 富文本 为空
-      const { val, flag } = ricjTxtRef.current.fatherBtnOkFu();
+      const { val, flag } = richTxtRef.current.fatherBtnOkFu();
 
       if (flag) return;
 
@@ -89,7 +93,10 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
   );
 
   // 富文本的ref
-  const ricjTxtRef = useRef<any>(null);
+  const richTxtRef = useRef<any>(null);
+
+  // 文件的code码
+  const [dirCode, setDirCode] = useState("");
 
   return (
     <div className={styles.B2Edit}>
@@ -138,9 +145,10 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
               </div>
               <div className="e_rowR">
                 <RichText
-                  ref={ricjTxtRef}
+                  myUrl="cms/goods/upload"
+                  ref={richTxtRef}
                   check={check}
-                  dirCode="myGoods"
+                  dirCode={dirCode}
                   isLook={isLook}
                 />
               </div>
@@ -158,7 +166,7 @@ function B2Edit({ editId, isLook, closeFu, editFu, addFu, myType }: Props) {
                   isLook={isLook}
                   coverCheck={check}
                   size={5}
-                  dirCode={"myGoods"}
+                  dirCode={dirCode}
                   checkTxt="请上传图片!"
                 />
               </div>

+ 1 - 27
后台/src/store/action/B2Goods.ts

@@ -1,7 +1,5 @@
 import http from "@/utils/http";
-import store, { AppDispatch } from "..";
-import axios from "axios";
-import { domShowFu, progressDomFu } from "@/utils/domShow";
+import { AppDispatch } from "..";
 
 /**
  * 获取赏析-版块列表
@@ -46,27 +44,3 @@ export const B2_APIgetInfo = (id: number) => {
 export const B2_APIsave = (data: any) => {
   return http.post("cms/goods/save", data);
 };
-
-const CancelToken = axios.CancelToken;
-/**
- * 上传封面图和附件
- */
-export const B2_APIupFile = (data: any) => {
-  domShowFu("#UpAsyncLoding", true);
-
-  return http.post("cms/config/upload", data, {
-    timeout: 0,
-    // 显示进度条
-    onUploadProgress: (e: any) => {
-      const complete = (e.loaded / e.total) * 100 || 0;
-      progressDomFu(complete + "%");
-    },
-    // 取消上传
-    cancelToken: new CancelToken(function executor(c) {
-      store.dispatch({
-        type: "layout/closeUpFile",
-        payload: { fu: c, state: true },
-      });
-    }),
-  });
-};