|
@@ -6,13 +6,14 @@ import React, {
|
|
|
useState,
|
|
|
} from "react";
|
|
|
import styles from "./index.module.scss";
|
|
|
+import axios from "axios";
|
|
|
|
|
|
// 引入编辑器组件
|
|
|
|
|
|
// 安装---npm install braft-editor --save --force
|
|
|
// npm install braft-utils --save --force
|
|
|
// @ts-ignore
|
|
|
-// import { ContentUtils } from "braft-utils";
|
|
|
+import { ContentUtils } from "braft-utils";
|
|
|
// @ts-ignore
|
|
|
import BraftEditor from "braft-editor";
|
|
|
// 引入编辑器样式
|
|
@@ -22,6 +23,9 @@ import classNames from "classnames";
|
|
|
|
|
|
import { forwardRef, useImperativeHandle } from "react";
|
|
|
import { message } from "antd";
|
|
|
+import { domShowFu, fileDomInitialFu, progressDomFu } from "@/utils/domShow";
|
|
|
+import store from "@/store";
|
|
|
+import http from "@/utils/http";
|
|
|
|
|
|
type Props = {
|
|
|
check?: boolean; //表单校验,为fasle表示不校验
|
|
@@ -33,6 +37,28 @@ type Props = {
|
|
|
onChange?(v: any): void;
|
|
|
};
|
|
|
|
|
|
+const CancelToken = axios.CancelToken;
|
|
|
+
|
|
|
+export const A1_APIupFile = (data: any, url: string) => {
|
|
|
+ domShowFu("#UpAsyncLoding", true);
|
|
|
+
|
|
|
+ return http.post(url, 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 },
|
|
|
+ });
|
|
|
+ }),
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
function RichText(
|
|
|
{ check, dirCode, isLook, myUrl, onChange }: Props,
|
|
|
ref: any
|
|
@@ -126,24 +152,27 @@ function RichText(
|
|
|
e.target.value = "";
|
|
|
|
|
|
try {
|
|
|
- console.log(fd, myUrl);
|
|
|
- // const res = await A1_APIupFile(fd, myUrl);
|
|
|
- // if (res.code === 0) {
|
|
|
- // messageApi.success("上传成功!");
|
|
|
- // // 在光标位置插入图片
|
|
|
- // const newTxt = ContentUtils.insertMedias(editorValue, [
|
|
|
- // {
|
|
|
- // type: "IMAGE",
|
|
|
- // url: process.env.REACT_APP_API_URL + res.data.filePath,
|
|
|
- // },
|
|
|
- // ]);
|
|
|
-
|
|
|
- // setEditorValue(newTxt);
|
|
|
- // }
|
|
|
- } catch (error) {}
|
|
|
+ const res = await A1_APIupFile(fd, myUrl);
|
|
|
+ // @ts-ignore
|
|
|
+ if (res.code === 0) {
|
|
|
+ messageApi.success("上传成功!");
|
|
|
+ // 在光标位置插入图片
|
|
|
+ const newTxt = ContentUtils.insertMedias(editorValue, [
|
|
|
+ {
|
|
|
+ type: "IMAGE",
|
|
|
+ url: `${process.env.REACT_APP_API_URL}${process.env.REACT_APP_IMG_PUBLIC}${res.data.filePath}`,
|
|
|
+ },
|
|
|
+ ]);
|
|
|
+
|
|
|
+ setEditorValue(newTxt);
|
|
|
+ }
|
|
|
+ fileDomInitialFu();
|
|
|
+ } catch (error) {
|
|
|
+ fileDomInitialFu();
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
- [dirCode, myUrl, messageApi]
|
|
|
+ [dirCode, myUrl, messageApi, editorValue]
|
|
|
);
|
|
|
|
|
|
// 让父组件调用的 回显 富文本
|