index.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. import AuthButton from "@/components/AuthButton";
  2. import BreadTit from "@/components/BreadTit";
  3. import history, { urlParameter } from "@/utils/history";
  4. import { Input, message, Select, Table, Popconfirm } from "antd";
  5. import TextArea from "antd/es/input/TextArea";
  6. import React, { useEffect, useMemo, useRef, useState } from "react";
  7. import { useLocation } from "react-router-dom";
  8. import styles from "./index.module.scss";
  9. import ObjectAdd from "@/components/ObjectAdd";
  10. import ImageLazy from "@/components/ImageLazy/index";
  11. import { useSelector } from "react-redux";
  12. import { RootState } from "@/store";
  13. function AddObject1() {
  14. // 从仓库中获取藏品来源下拉数据
  15. const options = useSelector(
  16. (state: RootState) => state.loginStore.selectAll["文物来源"]
  17. );
  18. // 获取地址栏参数
  19. const location = useLocation();
  20. const [urlParam, setUrlParam] = useState<any>({});
  21. useEffect(() => {
  22. setUrlParam(urlParameter(location.search));
  23. }, [location]);
  24. // 顶部数据
  25. const [addInfoTop, setAddInfoTop] = useState({
  26. num: "DJ20221212009",
  27. user: "admin",
  28. laiyuan: options[0].name?options[0].name:'',
  29. txt: "",
  30. });
  31. // 藏品来源下拉框
  32. const handleChange = (value: string) => {
  33. setAddInfoTop({ ...addInfoTop, laiyuan: value });
  34. };
  35. // const tabList = useMemo(() => {
  36. // return [
  37. // { id: 1, value: "img", label: "高清图片" },
  38. // { id: 2, value: "video", label: "视频文件" },
  39. // { id: 3, value: "audio", label: "音频文件" },
  40. // { id: 4, value: "model", label: "三维模型" },
  41. // { id: 5, value: "file", label: "文档资料" },
  42. // ];
  43. // }, []);
  44. // 表格数据
  45. // 选中的表格数据
  46. const [tableSelectList, setTableSelectList] = useState([]);
  47. // 点击删除
  48. const delTableListFu = () => {
  49. console.log("多个删除", tableSelectList);
  50. };
  51. const delOne = (id: number) => {
  52. console.log("单个删除", id);
  53. };
  54. const rowSelection = {
  55. onChange: (selectedRowKeys: any, selectedRows: any) => {
  56. setTableSelectList(selectedRows);
  57. },
  58. };
  59. const results = useMemo(() => {
  60. return [
  61. {
  62. id: 1,
  63. name: "图片1",
  64. img: "https://ts1.cn.mm.bing.net/th/id/R-C.6d2d3fecd79a96e43d1a410640d7199b?rik=B7RCgF82Vb7P0A&riu=http%3a%2f%2f5b0988e595225.cdn.sohucs.com%2fimages%2f20190831%2f3e03e9c2473c40b180aa99a37c0589fa.jpeg&ehk=JXdgMrjnolHlMkdX9N0K7%2fzBc9wi7FSFDjSGclreQbI%3d&risl=&pid=ImgRaw&r=0",
  65. },
  66. { id: 2, name: "图片2", img: "https://ts1.cn.mm" },
  67. {
  68. id: 3,
  69. name: "图片3",
  70. img: "http://project.4dage.com:8016/content/1_1001/img/20220810_1553241331042.JPG",
  71. },
  72. { id: 4, name: "图片4", img: "3" },
  73. { id: 5, name: "图片4", img: "4" },
  74. { id: 6, name: "图片4", img: "5" },
  75. { id: 7, name: "图片4", img: "6" },
  76. { id: 8, name: "图片4", img: "7" },
  77. { id: 9, name: "图片4", img: "8" },
  78. { id: 10, name: "图片4", img: "9" },
  79. {
  80. id: 11,
  81. name: "图片4",
  82. img: "https://ts1.cn.mm.bing.net/th/id/R-C.3745122e5760fe2283195293d76bc1e0?rik=YBMOcCcn7CX6Ig&riu=http%3a%2f%2fup.deskcity.org%2fpic%2f20%2fe4%2f4d%2f20e44dce0fe116832ba890edaf2ede32.jpg&ehk=vldj1pqTKyKgirU8ck%2f%2bJWEhtPm22Owe5VEmGNMeLpA%3d&risl=&pid=ImgRaw&r=0",
  83. },
  84. ];
  85. }, []);
  86. const columns = useMemo(() => {
  87. return [
  88. {
  89. title: "缩略图",
  90. render: (item: any) => (
  91. <div className="tableImg">
  92. <ImageLazy width={120} height={70} src={item.img} />
  93. </div>
  94. ),
  95. },
  96. {
  97. title: "标题",
  98. dataIndex: "name",
  99. },
  100. {
  101. title: "操作",
  102. render: (item: any) => (
  103. <>
  104. <AuthButton type="text" danger onClick={() => addPageFu(item.id)}>
  105. 编辑
  106. </AuthButton>
  107. <Popconfirm
  108. title="确定删除吗?"
  109. okText="确定"
  110. cancelText="取消"
  111. onConfirm={() => delOne(item.id)}
  112. >
  113. <AuthButton type="text" danger>
  114. 删除
  115. </AuthButton>
  116. </Popconfirm>
  117. </>
  118. ),
  119. },
  120. ];
  121. }, []);
  122. // 点击返回
  123. const cancelFu = () => {
  124. history.push({
  125. pathname: `/object`,
  126. state: { k: urlParam.k ? urlParam.k : "1" },
  127. });
  128. };
  129. // 点击提交
  130. const submitFu = (val: number) => {
  131. if (results.length === 0)
  132. return message.warning("至少需要添加一条藏品信息!");
  133. // cancelFu()
  134. };
  135. // 点击添加或者编辑出来页面
  136. const [addPage, setAddPage] = useState(true);
  137. // 点击添加或者编辑
  138. const addId = useRef<any>(null);
  139. const addPageFu = (id?: any) => {
  140. addId.current = id;
  141. setAddPage(true);
  142. };
  143. return (
  144. <div className={styles.AddObject1}>
  145. <div className="breadTit">
  146. <BreadTit>
  147. <div className="breadTitRow">藏品登记</div>
  148. <div className="splitStr">/</div>
  149. <div className="breadTitRow active">
  150. {urlParam.id ? "编辑" : "新增"}
  151. </div>
  152. </BreadTit>
  153. </div>
  154. <div className="objectSonMain">
  155. {/* 上面的信息展示 */}
  156. <div className="addInfoTop">
  157. <div className="row">
  158. <div>
  159. <span className="bs">登记编号:</span>
  160. <Input style={{ width: 400 }} value={addInfoTop.num} disabled />
  161. </div>
  162. <div>
  163. <span className="bs">登记人员:</span>
  164. <Input style={{ width: 400 }} value={addInfoTop.user} disabled />
  165. </div>
  166. </div>
  167. <div className="row">
  168. <div>
  169. <span className="bs">藏品来源:</span>
  170. <Select
  171. placeholder="请选择"
  172. style={{ width: 400 }}
  173. value={addInfoTop.laiyuan}
  174. onChange={handleChange}
  175. options={options.map((v: any) => ({
  176. label: v.name,
  177. value: v.name,
  178. }))}
  179. />
  180. </div>
  181. </div>
  182. <div className="rowAll">
  183. <span>登记说明:</span>
  184. <TextArea
  185. value={addInfoTop.txt}
  186. onChange={(e) =>
  187. setAddInfoTop({ ...addInfoTop, txt: e.target.value })
  188. }
  189. rows={3}
  190. placeholder="请输入"
  191. showCount
  192. maxLength={255}
  193. />
  194. </div>
  195. </div>
  196. {/* 下面的表格 */}
  197. <div className="addTableBox">
  198. <div className="addTableBox_Tit">
  199. <div className="addTableBox_TitL">藏品信息</div>
  200. <div className="addTableBox_TitR">
  201. <AuthButton onClick={() => addPageFu(null)}>添加</AuthButton>
  202. &emsp;
  203. <Popconfirm
  204. title="确定删除吗?"
  205. okText="确定"
  206. cancelText="取消"
  207. onConfirm={delTableListFu}
  208. >
  209. <AuthButton disabled={tableSelectList.length === 0}>
  210. 删除
  211. </AuthButton>
  212. </Popconfirm>
  213. </div>
  214. </div>
  215. {/* 表格主体 */}
  216. <div className="addTableBox_table">
  217. <Table
  218. scroll={{ y: 280 }}
  219. rowSelection={{
  220. type: "checkbox",
  221. ...rowSelection,
  222. }}
  223. dataSource={results}
  224. columns={columns}
  225. rowKey="id"
  226. pagination={false}
  227. />
  228. </div>
  229. <div className="addTableBox_btn">
  230. <AuthButton onClick={() => submitFu(1)}>存入草稿</AuthButton>
  231. &emsp;
  232. <AuthButton type="primary" onClick={() => submitFu(1)}>
  233. 提交
  234. </AuthButton>
  235. &emsp;
  236. <AuthButton onClick={cancelFu}>返回</AuthButton>
  237. </div>
  238. </div>
  239. </div>
  240. {/* 点击添加或者编辑出来的页面 */}
  241. {addPage ? (
  242. <ObjectAdd id={addId.current} colsePage={() => setAddPage(false)} />
  243. ) : null}
  244. </div>
  245. );
  246. }
  247. const MemoAddObject1 = React.memo(AddObject1);
  248. export default MemoAddObject1;