index.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. import { useRef, useEffect, useState } from 'react';
  2. import PageContent from '@/components/PageContent';
  3. import {
  4. queryCadDirList,
  5. queryCadList,
  6. queryCreateCad,
  7. queryProject,
  8. } from '@/services/cad';
  9. import { useRequest, useNavigate } from '@umijs/max';
  10. import { Table, Button, message, Space, Select, Input } from 'antd';
  11. import CreateModal from './components/CreateModal';
  12. import { createAduit } from '@/services/boom';
  13. import CreateChildrenModal from './components/CreateChildrenModal';
  14. import { queryCreateCadVer } from '../../services/cad';
  15. const CadDemo = () => {
  16. let navigate = useNavigate();
  17. const [createLoading, setCreateLoading] = useState(false);
  18. const [visible, setVisible] = useState(false);
  19. const [childrenVisible, setChildrenVisible] = useState(false);
  20. const [parentId, setParentId] = useState();
  21. const [params, setParams] = useState({
  22. // project_name: '',
  23. // name: '',
  24. page: 1,
  25. page_size: 20,
  26. });
  27. const auditListRef = useRef();
  28. const columns = [
  29. {
  30. title: '名称',
  31. dataIndex: 'name',
  32. key: 'name',
  33. width: 160,
  34. },
  35. {
  36. title: '所属项目',
  37. dataIndex: 'project_name',
  38. key: 'project_name',
  39. width: 120,
  40. },
  41. {
  42. title: '状态',
  43. // dataIndex: 'cad_status',
  44. // key: 'cad_status',
  45. width: 100,
  46. render: (record) => {
  47. let str = '';
  48. let color = 'black';
  49. switch (record.cad_status) {
  50. case 1:
  51. str = '已归档';
  52. color = 'green';
  53. break;
  54. case 2:
  55. str = '审核拒绝';
  56. color = 'red';
  57. break;
  58. case 0:
  59. str = '待审核';
  60. color = 'blue';
  61. }
  62. return record.parent_id ? <div style={{ color }}>{str}</div> : '';
  63. },
  64. },
  65. {
  66. title: '操作',
  67. width: '10%',
  68. render: (record) => {
  69. return (
  70. <Space>
  71. {record.canShow && (
  72. <a
  73. onClick={() =>
  74. navigate('/cad/detail', {
  75. state: {
  76. path: record.path,
  77. },
  78. })
  79. }
  80. >
  81. 查看
  82. </a>
  83. )}
  84. {record.showCreate && (
  85. <a
  86. onClick={() => {
  87. setParentId(record.id);
  88. setChildrenVisible(true);
  89. }}
  90. >
  91. 新建
  92. </a>
  93. )}
  94. </Space>
  95. );
  96. },
  97. },
  98. ];
  99. const { data: projectList } = useRequest(queryProject, {
  100. formatResult: (res) => {
  101. return res?.data?.list?.map((item) => {
  102. return { label: item.Name, value: item.ID };
  103. });
  104. },
  105. });
  106. //请求归档目录
  107. const { data: dirList } = useRequest(queryCadDirList, {
  108. formatResult: (res) => {
  109. return res.data;
  110. },
  111. });
  112. //请求列表
  113. const { data, run, loading } = useRequest(queryCadList, {
  114. defaultParams: [params],
  115. formatResult: (res) => {
  116. res.data?.list?.forEach((item) => {
  117. item.children?.forEach((cur) => {
  118. cur.name = item.name + cur.version;
  119. item.showCreate = cur.cad_status == 2 ? true : false;
  120. if (cur.cad_path) {
  121. const pathList = cur.cad_path.split(',');
  122. cur.children = pathList.map((item) => {
  123. const names = item.split('/');
  124. const name = names?.length > 1 ? names[1] : names[0];
  125. return {
  126. name: name,
  127. path: item,
  128. canShow: true,
  129. parent_id: cur.parent_id,
  130. };
  131. });
  132. }
  133. });
  134. });
  135. return res.data?.list;
  136. },
  137. });
  138. //创建审批
  139. const { run: runCreate } = useRequest(queryCreateCad, {
  140. manual: true,
  141. onSuccess: (data) => {
  142. createOARun({
  143. ...auditListRef.current,
  144. extend_code: data.cad_id + '',
  145. extend_type: 2, //2图纸
  146. });
  147. },
  148. });
  149. //创建子审批
  150. const { run: runCreateVer, loading: loadingCreateVer } = useRequest(
  151. queryCreateCadVer,
  152. {
  153. manual: true,
  154. onSuccess: (data) => {
  155. message.success('新建成功');
  156. setChildrenVisible(false);
  157. // createOARun({
  158. // ...auditListRef.current,
  159. // extend_code: data.cad_id + '',
  160. // extend_type: 2, //2图纸
  161. // });
  162. },
  163. },
  164. );
  165. //发起OA审批
  166. const { run: createOARun } = useRequest(
  167. (data) => createAduit({ ...data, flow_id: 67, files: '' }),
  168. {
  169. manual: true,
  170. onSuccess: () => {
  171. run();
  172. message.success('新建成功');
  173. setVisible(false);
  174. setCreateLoading(false);
  175. },
  176. },
  177. );
  178. useEffect(() => {
  179. ZwCloud2D.ZwDataProcessor.ZwSetConnectUrl(
  180. 'http://47.111.24.13:5121', //47.111.24.13
  181. 'ws://47.111.24.13:5121',
  182. 'http://47.111.24.13:5121',
  183. );
  184. }, []);
  185. const handleCreate = (values, audit_list) => {
  186. setCreateLoading(true);
  187. auditListRef.current = audit_list;
  188. runCreate(values);
  189. };
  190. return (
  191. <PageContent>
  192. <Space>
  193. <Button type="primary" onClick={() => setVisible(true)}>
  194. 新建图纸
  195. </Button>
  196. <div>
  197. 项目名称:
  198. <Select
  199. style={{ width: 130 }}
  200. allowClear
  201. options={projectList}
  202. onChange={(value) => {
  203. const project_name = projectList?.find(
  204. (item) => item.value == value,
  205. )?.label;
  206. setParams({ ...params, project_name });
  207. }}
  208. />
  209. </div>
  210. <div>
  211. 图纸名称:
  212. <Input
  213. allowClear
  214. style={{ width: '200px' }}
  215. onChange={(e) => {
  216. setParams({ ...params, name: e.target.value });
  217. }}
  218. />
  219. </div>
  220. <Button type="primary" onClick={() => run(params)}>
  221. 查询
  222. </Button>
  223. </Space>
  224. <Table
  225. rowKey="id"
  226. loading={loading}
  227. columns={columns}
  228. dataSource={data}
  229. indentSize={70}
  230. />
  231. <CreateModal
  232. loading={createLoading}
  233. dirList={dirList}
  234. projectList={projectList}
  235. open={visible}
  236. onOk={handleCreate}
  237. handleCancel={() => setVisible(false)}
  238. />
  239. <CreateChildrenModal
  240. parentId={parentId}
  241. loading={loadingCreateVer}
  242. open={childrenVisible}
  243. onOk={runCreateVer}
  244. handleCancel={() => setChildrenVisible(false)}
  245. />
  246. </PageContent>
  247. );
  248. };
  249. export default CadDemo;