Переглянути джерело

Squashed commit of the following:
merge dev
commit 393b45345da22613f2f0076318717629f59417d6
Merge: 3c3c2a6 8976c53
Author: Renxy <18510891294@163.com>
Date: Wed Jan 3 10:44:52 2024 +0800

Merge branch 'develop' of http://120.55.44.4:10080/xujunjie/GtDigManageWeb into develop

commit 3c3c2a6478e4ba555ff190751e4e428bc559f1d3
Author: Renxy <18510891294@163.com>
Date: Wed Jan 3 10:44:43 2024 +0800

隔离cad代码改为iframe

Renxy 1 рік тому
батько
коміт
4127bb5c09
5 змінених файлів з 167 додано та 205 видалено
  1. 5 5
      .umirc.ts
  2. 119 0
      public/cad.html
  3. 20 20
      src/pages/Cad/components/CreateChildrenModal.js
  4. 23 172
      src/pages/Cad/detail.js
  5. 0 8
      src/pages/Cad/index.js

+ 5 - 5
.umirc.ts

@@ -39,11 +39,11 @@ export default defineConfig({
   //   { src: '/ZwCloud2DSDK/ZwWasmJs.js' },
   //   { src: '/ZwCloud2DSDK/ZwCloud2DAPI.js' },
   // ],
-  headScripts: [
-    `${publicPath}ZwCloud2DSDK/ZwCloud2D.js`,
-    `${publicPath}ZwCloud2DSDK/ZwWasmJs.js`,
-    `${publicPath}ZwCloud2DSDK/ZwCloud2DPrivateAPI.js`,
-  ],
+  // headScripts: [
+  //   `${publicPath}ZwCloud2DSDK/ZwCloud2D.js`,
+  //   `${publicPath}ZwCloud2DSDK/ZwWasmJs.js`,
+  //   `${publicPath}ZwCloud2DSDK/ZwCloud2DPrivateAPI.js`,
+  // ],
   proxy: {
     '/api': {
       // target: 'http://192.168.20.232:1007/',

+ 119 - 0
public/cad.html

@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="UTF-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+    <title>Document</title>
+    <script src="/gt-dig/ZwCloud2DSDK/ZwCloud2D.js"></script>
+    <script src="/gt-dig/ZwCloud2DSDK/ZwWasmJs.js"></script>
+    <script src="/gt-dig/ZwCloud2DSDK/ZwCloud2DPrivateAPI.js"></script>
+
+    <script src="/ZwCloud2DSDK/ZwCloud2D.js"></script>
+    <script src="/ZwCloud2DSDK/ZwWasmJs.js"></script>
+    <script src="/ZwCloud2DSDK/ZwCloud2DPrivateAPI.js"></script>
+  </head>
+
+  <body>
+    <div
+      id="container"
+      style="
+        margin: 0px;
+        padding: 0px;
+        position: absolute;
+        width: 100%;
+        height: 100%;
+        left: 0px;
+        top: 0px;
+      "
+    ></div>
+  </body>
+  <script>
+    window.initData = ({ path, user, project_id, doc_id, runAdd, runDel }) => {
+      const content = document.getElementById('container');
+      ZwCloud2D.ZwEditor.ZwInit(content);
+      ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
+        'https://cad.greentech.com.cn',
+        'wss://cad.greentech.com.cn:5121',
+        'https://cad.greentech.com.cn',
+      );
+      //加载图纸
+      ZwCloud2D.ZwDataProcessor.ZwSetLoadDwg(path);
+      ZwCloud2D.ZwDataProcessor.ZwLoad();
+
+      //拦截cad评论面板方法,调用后端接口处理
+      ZwCloud2D.ZwMessageCallback.ZwEvtUpdateCommentData = function (data) {
+        console.log('------------------', data);
+        switch (data.type) {
+          case 'create':
+            // 补充data.data中缺失的参数,保存新增的评论数据\
+            const paramsAdd = {
+              id: 0,
+              project_id,
+              user_name: user.CName,
+              content: data.data.content,
+              doc_id,
+              parent_id: 0,
+              with_mark: data.data.withMark || '',
+              mark: data.data.mark || '',
+            };
+            runAdd(paramsAdd);
+            break;
+          case 'reply':
+            const paramsReply = {
+              id: 0,
+              project_id,
+              user_name: user.CName,
+              content: data.data.content,
+              doc_id,
+              parent_id: data.data.parentId,
+              with_mark: data.data.withMark || '',
+              mark: data.data.mark || '',
+            };
+            runAdd(paramsReply);
+            break;
+          case 'delete':
+            // 删除评论数据
+            const paramsDel = {
+              project_id,
+              id: data.data.id,
+            };
+            runDel(paramsDel);
+            break;
+          case 'edit':
+            // 编辑评论数据
+            const paramsEdit = {
+              project_id,
+              id: data.data.id,
+              user_name: user.CName,
+              content: data.data.content,
+              doc_id,
+              parent_id: 0,
+              with_mark: data.data.withMark || '',
+              mark: data.data.mark || '',
+            };
+            runAdd(paramsEdit);
+            break;
+          default:
+            break;
+        }
+      };
+    };
+    window.setCommitList = (resultData, currentUser) => {
+      let memberList = {
+        msg: '操作成功',
+        code: 0,
+        data: {
+          total: 2,
+          rows: [],
+        },
+      };
+      //注入评论列表、用户列表(目前为空), 个人信息
+      ZwCloud2D.ZwDataManager.ZwSetCommentData({
+        commentList: { msg: '操作成功', code: 0, data: resultData },
+        memberList,
+        user: currentUser,
+      });
+    };
+  </script>
+</html>

+ 20 - 20
src/pages/Cad/components/CreateChildrenModal.js

@@ -24,27 +24,27 @@ const CreateChildrenModal = ({
     form.resetFields();
   }, [open]);
 
-  function dwgUpload() {
-    let uploadDwg = document.getElementById('uploadDwg');
-    uploadDwg.click();
-  }
+  // function dwgUpload() {
+  //   let uploadDwg = document.getElementById('uploadDwg');
+  //   uploadDwg.click();
+  // }
 
-  function uploadDwg(event) {
-    const selectedFile = event.target.files[0];
-    if (selectedFile) {
-      setUpLoading(true);
-      ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
-        if (res.code == 200) {
-          const oldPath = form.getFieldValue('cad_path');
-          const cad_path = oldPath
-            ? oldPath + ',' + res.data.path
-            : res.data.path;
-          form.setFieldsValue({ cad_path });
-        }
-        setUpLoading(false);
-      });
-    }
-  }
+  // function uploadDwg(event) {
+  //   const selectedFile = event.target.files[0];
+  //   if (selectedFile) {
+  //     setUpLoading(true);
+  //     ZwCloud2D.ZwDataProcessor.uploadDwg(selectedFile).then((res) => {
+  //       if (res.code == 200) {
+  //         const oldPath = form.getFieldValue('cad_path');
+  //         const cad_path = oldPath
+  //           ? oldPath + ',' + res.data.path
+  //           : res.data.path;
+  //         form.setFieldsValue({ cad_path });
+  //       }
+  //       setUpLoading(false);
+  //     });
+  //   }
+  // }
   const UploadProps = {
     action: `https://cad.greentech.com.cn/sdk/doc/upload`,
     multiple: true,

+ 23 - 172
src/pages/Cad/detail.js

@@ -12,12 +12,12 @@ import moment from 'moment';
 
 const CadDeTail = () => {
   const navigate = useNavigate();
-  const cadRef = useRef();
   const location = useLocation();
   const {
     state: { path, user = {}, project_id },
   } = location;
   console.log('---------------------------', path, user, project_id);
+  const iframeRef = useRef();
 
   //当前登录的用户信息
   let currentUser = {
@@ -31,18 +31,15 @@ const CadDeTail = () => {
   const doc_id = useMemo(() => md5(path), [path]);
 
   //添加、编辑评论
-  const { run: runAdd, loading: loadingAdd } = useRequest(
-    queryCadCommitCreate,
-    {
-      manual: true,
-      onSuccess: (data) => {
-        message.success('新建成功');
-        setCommitList(data);
-      },
+  const { run: runAdd } = useRequest(queryCadCommitCreate, {
+    manual: true,
+    onSuccess: (data) => {
+      message.success('新建成功');
+      setCommitList(data);
     },
-  );
+  });
   //删除评论
-  const { run: runDel, loading: loadingDel } = useRequest(queryCadCommitDel, {
+  const { run: runDel } = useRequest(queryCadCommitDel, {
     manual: true,
     onSuccess: (data) => {
       message.success('删除成功');
@@ -50,162 +47,20 @@ const CadDeTail = () => {
     },
   });
   //请求评论列表
-  const { run: run, loading } = useRequest(
-    () => queryCadCommitList({ doc_id }),
-    {
-      manual: true,
-      onSuccess: (data) => {
-        setCommitList(data);
-      },
-    },
-  );
-
-  // let commentList = {
-  //   msg: '操作成功',
-  //   code: 0,
-  //   data: {
-  //     total: 2,
-  //     rows: [
-  //       {
-  //         createBy: 1317,
-  //         creator: '皮卡丘',
-  //         createTime: 1672040045000,
-  //         id: '1737299871415943168',
-  //         docId: '1703039467897',
-  //         handleId: '34',
-  //         parentId: '0',
-  //         level: 0,
-  //         withAt: 'NO',
-  //         withMark: 'NO',
-  //         content: '###梵蒂冈梵蒂冈发的',
-  //         mark: '',
-  //         replyList: [],
-  //       },
-  //       {
-  //         createBy: 1317,
-  //         creator: '柯南',
-  //         createTime: 1672040002000,
-  //         id: '1737299871415943169',
-  //         docId: '1703039467897',
-  //         handleId: '34',
-  //         parentId: '1737299871415943168',
-  //         level: 0,
-  //         withAt: 'NO',
-  //         withMark: 'YES',
-  //         content: '对符合法规和法国###',
-  //         mark: '[{"id":"7a4f4b9f-992d-15ef-9b17-7ca8abe833df","pt":[532.2265851288126,664.973293757502,0],"color":"red","type":0},{"id":"8bac4935-2e0b-444c-212e-bfca607c4f8e","points":[614.8609930415427,634.9244181528729,0,813.1835720320946,678.495287779585,0,834.217784955335,418.5725137995435,0,811.6811282518631,329.9283307658877,0],"color":"red","type":3},{"id":"a664f1ab-359b-87a0-7db9-f758e0e9e958","center":[294.8404678522429,338.9429934472764,0],"endPt":[365.45532552312125,275.84035467755535,0],"color":"cyan","type":1}]',
-  //         replyList: [],
-  //       },
-  //     ],
-  //   },
-  // };
-  //设置群组成员列表,作为@用户列表供用户选择
-  let memberList = {
-    msg: '操作成功',
-    code: 0,
-    data: {
-      total: 2,
-      rows: [
-        // {
-        //   memberId: '2138',
-        //   phone: '',
-        //   email: '',
-        //   memberName: '何为',
-        //   memberType: 'USER',
-        //   lastTime: 1672039449000,
-        //   roleId: '1607272382833942531',
-        //   roleName: '查看者',
-        //   color: '#87CEFA',
-        // },
-        // {
-        //   memberId: '1317',
-        //   phone: '',
-        //   email: '',
-        //   memberName: '柯南',
-        //   memberType: 'PROJECT_ADMIN',
-        //   lastTime: 1672038572000,
-        //   roleId: '1607272382833942528',
-        //   roleName: '管理员',
-        //   color: '#87CEFA',
-        // },
-      ],
+  const { run: run } = useRequest(() => queryCadCommitList({ doc_id }), {
+    manual: true,
+    onSuccess: (data) => {
+      setCommitList(data);
     },
-  };
+  });
 
-  useEffect(() => {
-    const content = document.getElementById('container');
-    ZwCloud2D.ZwEditor.ZwInit(content);
-    ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
-      'https://cad.greentech.com.cn',
-      'wss://cad.greentech.com.cn:5121',
-      'https://cad.greentech.com.cn',
-    );
-    //加载图纸
-    ZwCloud2D.ZwDataProcessor.ZwSetLoadDwg(path);
-    ZwCloud2D.ZwDataProcessor.ZwLoad();
-    //请求评论内容并注入cad评论列表
+  const handlerLoad = () => {
+    const contentWindow = iframeRef.current.contentWindow;
+    contentWindow.initData({ path, user, project_id, doc_id, runAdd, runDel });
     setTimeout(() => {
       run();
     }, 1000);
-
-    //拦截cad评论面板方法,调用后端接口处理
-    ZwCloud2D.ZwMessageCallback.ZwEvtUpdateCommentData = function (data) {
-      console.log('------------------', data);
-      switch (data.type) {
-        case 'create':
-          // 补充data.data中缺失的参数,保存新增的评论数据\
-          const paramsAdd = {
-            id: 0,
-            project_id,
-            user_name: user.CName,
-            content: data.data.content,
-            doc_id,
-            parent_id: 0,
-            with_mark: data.data.withMark || '',
-            mark: data.data.mark || '',
-          };
-          runAdd(paramsAdd);
-          break;
-        case 'reply':
-          const paramsReply = {
-            id: 0,
-            project_id,
-            user_name: user.CName,
-            content: data.data.content,
-            doc_id,
-            parent_id: data.data.parentId,
-            with_mark: data.data.withMark || '',
-            mark: data.data.mark || '',
-          };
-          runAdd(paramsReply);
-          break;
-        case 'delete':
-          // 删除评论数据
-          const paramsDel = {
-            project_id,
-            id: data.data.id,
-          };
-          runDel(paramsDel);
-          break;
-        case 'edit':
-          // 编辑评论数据
-          const paramsEdit = {
-            project_id,
-            id: data.data.id,
-            user_name: user.CName,
-            content: data.data.content,
-            doc_id,
-            parent_id: 0,
-            with_mark: data.data.withMark || '',
-            mark: data.data.mark || '',
-          };
-          runAdd(paramsEdit);
-          break;
-        default:
-          break;
-      }
-    };
-  }, []);
+  };
 
   const getRows = (list) => {
     if (!list || list?.length == 0) return [];
@@ -246,12 +101,8 @@ const CadDeTail = () => {
       rows: [],
     };
     resultData.rows = getRows(data.list);
-    //注入评论列表、用户列表(目前为空), 个人信息
-    ZwCloud2D.ZwDataManager.ZwSetCommentData({
-      commentList: { msg: '操作成功', code: 0, data: resultData },
-      memberList: memberList,
-      user: currentUser,
-    });
+    const contentWindow = iframeRef.current.contentWindow;
+    contentWindow.setCommitList(resultData, currentUser);
   };
 
   const handleBackClick = () => {
@@ -270,11 +121,11 @@ const CadDeTail = () => {
           返回
         </Button>
       </div>
-
-      <div
-        id="container"
+      <iframe
         style={{ width: '100%', height: '80vh' }}
-        ref={cadRef}
+        ref={iframeRef}
+        onLoad={handlerLoad}
+        src="/cad.html"
       />
     </PageContent>
   );

+ 0 - 8
src/pages/Cad/index.js

@@ -194,14 +194,6 @@ const CadDemo = () => {
     },
   );
 
-  useEffect(() => {
-    ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
-      'https://cad.greentech.com.cn', //47.111.24.13
-      'wss://cad.greentech.com.cn:5121',
-      'https://cad.greentech.com.cn',
-    );
-  }, []);
-
   const handleCreate = (values, audit_list) => {
     setCreateLoading(true);
     auditListRef.current = audit_list;