tableConfig.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. import { ProColumns } from '@ant-design/pro-components';
  2. import { Badge, Button, Col, Image, Popconfirm, Row, Space, Tag } from 'antd';
  3. import { createStyles } from 'antd-style';
  4. const useStyles = createStyles(({ token }) => {
  5. return {
  6. bookLabel: {
  7. color: token.colorTextTertiary,
  8. },
  9. del: {
  10. textDecoration: 'line-through',
  11. color: token.colorTextDisabled,
  12. },
  13. color: {
  14. color: token.colorWarningActive,
  15. },
  16. };
  17. });
  18. const brightColors = [
  19. '#FF6347', // 番茄红
  20. '#FF4500', // 橙红色
  21. '#FFD700', // 金黄色
  22. '#32CD32', // 鲜绿色
  23. '#00FF7F', // 麦绿色
  24. '#00CED1', // 暗青色
  25. '#4682B4', // 钢蓝色
  26. '#6A5ACD', // 鲜紫色
  27. '#FF69B4', // 热粉红色
  28. '#FF1493', // 深粉红色
  29. ];
  30. export const columns = (props: {
  31. authList?: any[];
  32. labelList?: any[];
  33. enumList?: { [key: string]: any };
  34. categoryList?: any[];
  35. lookBook: (data: any) => void;
  36. closeForm: (b: boolean, d: any) => void;
  37. setEditValues: (v: any) => void;
  38. setWorkDirection: (w: any) => void;
  39. del: (id: any) => void;
  40. setParagraphEdit: (data: any) => void;
  41. }): ProColumns<any>[] => {
  42. let {
  43. authList,
  44. labelList,
  45. categoryList,
  46. enumList,
  47. lookBook,
  48. closeForm,
  49. setWorkDirection,
  50. del,
  51. setEditValues,
  52. setParagraphEdit
  53. } = props;
  54. let { styles } = useStyles();
  55. console.log(
  56. enumList
  57. )
  58. return enumList?.BOOK_STATUS
  59. ? [
  60. {
  61. title: '封面',
  62. dataIndex: 'picUrl',
  63. key: 'picUrl',
  64. width: 90,
  65. ellipsis: true,
  66. align: 'center',
  67. hideInSearch: true,
  68. render: (a: any, b: any) => {
  69. return (
  70. <div style={{ position: 'relative' }}>
  71. <Image
  72. src={b?.picUrl}
  73. style={{ width: 50 }}
  74. onError={(e: any) => {
  75. e.target.src = localStorage.getItem('nocover');
  76. }}
  77. />
  78. </div>
  79. );
  80. },
  81. },
  82. {
  83. title: '作品详情',
  84. dataIndex: 'authorId',
  85. key: 'authorId',
  86. ellipsis: true,
  87. hideInSearch: true,
  88. width: 500,
  89. render: (a, b) => {
  90. let { bookName, wordCount, labels, bookStatus, categoryName, authorName, score } = b;
  91. let arr = enumList?.BOOK_STATUS?.values;
  92. return (
  93. <Row>
  94. <Col span={24}>
  95. <Space size={[5, 0]} wrap>
  96. <a
  97. style={{ fontSize: 14, color: '#337ab7', cursor: 'pointer' }}
  98. onClick={() => {
  99. lookBook?.({ ...b, pageNum: 1, pageSize: 2 });
  100. }}
  101. >
  102. [{categoryName}]{bookName}
  103. </a>
  104. <span style={{ fontSize: 11 }} className={styles.bookLabel}>
  105. [{arr[bookStatus]?.description}]
  106. </span>
  107. <Space size={[0, 0]}>
  108. {labels?.map((tags: { id: string; name: string }, index: number) => {
  109. return (
  110. <Tag key={tags?.id} color={brightColors[index]}>
  111. {tags?.name}
  112. </Tag>
  113. );
  114. })}
  115. </Space>
  116. </Space>
  117. </Col>
  118. <Col span={24} className={styles.bookLabel}>
  119. <span>
  120. <span>作者</span>:
  121. </span>
  122. {authorName}
  123. </Col>
  124. <Col span={24} className={styles.bookLabel}>
  125. <span>总字数:</span>
  126. {wordCount || 0}
  127. </Col>
  128. <Col span={24} className={styles.bookLabel}>
  129. <span>评分:</span>
  130. {score || 0}
  131. </Col>
  132. </Row>
  133. );
  134. },
  135. },
  136. {
  137. title: '所属频道',
  138. dataIndex: 'workDirection',
  139. key: 'workDirection',
  140. align: 'center',
  141. width: 80,
  142. ellipsis: true,
  143. hideInSearch: true,
  144. render: (a: any, b: any) => {
  145. return enumList?.WORK_DIRECTION?.values[b.workDirection]?.description;
  146. },
  147. },
  148. {
  149. title: '点击量',
  150. dataIndex: 'visitCount',
  151. key: 'visitCount',
  152. width: 90,
  153. ellipsis: true,
  154. align: 'center',
  155. hideInSearch: true,
  156. render: (a, b) => {
  157. let { visitCount } = b;
  158. return visitCount;
  159. },
  160. },
  161. {
  162. title: '上架状态',
  163. dataIndex: 'shelveStatus',
  164. key: 'shelveStatus',
  165. width: 90,
  166. ellipsis: true,
  167. align: 'center',
  168. hideInSearch: true,
  169. render: (a: any, b) => {
  170. let arr: any = enumList?.SHELVE_STATUS?.values;
  171. let { shelveStatus } = b;
  172. return (
  173. arr[shelveStatus]?.description && (
  174. <Badge
  175. text={arr[shelveStatus]?.description}
  176. status={shelveStatus == 0 ? 'processing' : 'default'}
  177. />
  178. )
  179. );
  180. },
  181. },
  182. {
  183. title: '来源',
  184. dataIndex: 'source',
  185. key: 'source',
  186. width: 90,
  187. ellipsis: true,
  188. align: 'center',
  189. hideInSearch: true,
  190. render: (a: any, b) => {
  191. let { source } = b;
  192. let arr: any = new Map(
  193. enumList?.SOURCE?.values?.map(({ value, description }: any) => [value, description]),
  194. );
  195. return arr.get(source);
  196. },
  197. },
  198. {
  199. title: '操作',
  200. dataIndex: 'cz',
  201. key: 'cz',
  202. width: 90,
  203. ellipsis: true,
  204. align: 'center',
  205. hideInSearch: true,
  206. render: (a: any, b: any) => {
  207. return (
  208. <Space size={[0, 0]}>
  209. <Button
  210. type="link"
  211. size="small"
  212. className={styles.color}
  213. onClick={() => {
  214. setParagraphEdit(b);
  215. }}
  216. >
  217. 段落管理
  218. </Button>
  219. <Button
  220. type="link"
  221. size="small"
  222. onClick={() => {
  223. closeForm(true, b)
  224. }}
  225. >
  226. 编辑
  227. </Button>
  228. <Popconfirm
  229. title={
  230. <div>
  231. 确定要删除<span style={{ color: 'red' }}>{b.bookName}</span>此书籍?
  232. </div>
  233. }
  234. onConfirm={() => {
  235. del(b.id);
  236. }}
  237. >
  238. <Button type="link" size="small" danger>
  239. 删除
  240. </Button>
  241. </Popconfirm>
  242. </Space>
  243. );
  244. },
  245. },
  246. // 搜索条件
  247. {
  248. title: '小说名称',
  249. dataIndex: 'bookName',
  250. valueType: 'text',
  251. hideInTable: true,
  252. fieldProps: { placeholder: '请输入小说名称' },
  253. colSize: 1,
  254. },
  255. {
  256. title: '作者',
  257. dataIndex: 'authorId',
  258. valueType: 'select',
  259. hideInTable: true,
  260. fieldProps: { showSearch: true, placeholder: '请选择作者' },
  261. colSize: 1,
  262. valueEnum: new Map(authList?.map(({ id, authorName }) => [id, authorName])),
  263. },
  264. {
  265. title: '频道',
  266. dataIndex: 'workDirection',
  267. valueType: 'segmented',
  268. hideInTable: true,
  269. fieldProps: {
  270. type: 'primary',
  271. style: { width: 'auto' },
  272. onChange: (value) => {
  273. setWorkDirection(value);
  274. },
  275. },
  276. colSize: 3,
  277. initialValue: '',
  278. valueEnum: () => {
  279. let arr = enumList?.WORK_DIRECTION?.values;
  280. return arr
  281. ? new Map(
  282. [{ value: '', description: '全部' }, ...arr]?.map(
  283. ({ value, description }: any) => [value, description],
  284. ),
  285. )
  286. : {};
  287. },
  288. },
  289. {
  290. title: '分类',
  291. dataIndex: 'categoryId',
  292. valueType: 'segmented',
  293. hideInTable: true,
  294. hideInSearch: !labelList,
  295. fieldProps: { type: 'primary', style: { width: 'auto' } },
  296. colSize: 3,
  297. initialValue: '',
  298. valueEnum: () => {
  299. let arr = categoryList || [];
  300. return new Map([{ id: '', name: '全部' }, ...arr]?.map((item) => [item.id, item.name]));
  301. },
  302. },
  303. {
  304. title: '标签',
  305. dataIndex: 'labelIds',
  306. valueType: 'segmented',
  307. hideInTable: true,
  308. hideInSearch: !labelList,
  309. fieldProps: { type: 'primary', style: { width: 'auto' } },
  310. colSize: 3,
  311. initialValue: '',
  312. valueEnum: () => {
  313. let arr = labelList || [];
  314. return new Map([{ id: '', name: '全部' }, ...arr]?.map((item) => [item.id, item.name]));
  315. },
  316. },
  317. {
  318. title: '来源',
  319. dataIndex: 'source',
  320. valueType: 'segmented',
  321. hideInTable: true,
  322. fieldProps: { type: 'primary', style: { width: 'auto' } },
  323. colSize: 3,
  324. initialValue: '',
  325. valueEnum: () => {
  326. let arr = enumList?.SOURCE?.values;
  327. return arr
  328. ? new Map(
  329. [{ value: '', description: '全部' }, ...arr]?.map(
  330. ({ value, description }: any) => [value, description],
  331. ),
  332. )
  333. : {};
  334. },
  335. },
  336. {
  337. title: '连载',
  338. dataIndex: 'bookStatus',
  339. valueType: 'segmented',
  340. hideInTable: true,
  341. fieldProps: { type: 'primary', style: { width: 'auto' } },
  342. colSize: 3,
  343. initialValue: '',
  344. valueEnum: () => {
  345. let arr = enumList?.BOOK_STATUS?.values;
  346. return arr
  347. ? new Map(
  348. [{ value: '', description: '全部' }, ...arr]?.map(
  349. ({ value, description }: any) => [value, description],
  350. ),
  351. )
  352. : {};
  353. },
  354. },
  355. {
  356. title: '上架',
  357. dataIndex: 'shelveStatus',
  358. valueType: 'segmented',
  359. hideInTable: true,
  360. fieldProps: { type: 'primary', style: { width: 'auto' } },
  361. colSize: 3,
  362. initialValue: '',
  363. valueEnum: () => {
  364. let arr = enumList?.SHELVE_STATUS?.values;
  365. return arr
  366. ? new Map(
  367. [{ value: '', description: '全部' }, ...arr]?.map(
  368. ({ value, description }: any) => [value, description],
  369. ),
  370. )
  371. : {};
  372. },
  373. },
  374. {
  375. title: '字数',
  376. dataIndex: 'wordCount',
  377. valueType: 'segmented',
  378. hideInTable: true,
  379. fieldProps: { type: 'primary', style: { width: 'auto' }, block: true },
  380. colSize: 3,
  381. initialValue: '',
  382. valueEnum: {
  383. '': '全部',
  384. '0-2': '2万内',
  385. '2-5': '2-5万',
  386. '5-10': '5-10万',
  387. '10-20': '10-20万',
  388. '20-40': '20-40万',
  389. '40-100': '40-100万',
  390. '100-150': '100-150万',
  391. '150-200': '150-200万',
  392. '200-300': '200-300万',
  393. '300-0': '300万以上',
  394. },
  395. },
  396. ]
  397. : [];
  398. };
  399. export const childrenColumns = (props: {
  400. del: (id: any) => void;
  401. closeForm: (b: boolean, v: any) => void;
  402. }): ProColumns<any>[] => {
  403. let { del, closeForm } = props;
  404. return [
  405. {
  406. title: 'ID',
  407. dataIndex: 'id',
  408. key: 'id',
  409. align: 'center',
  410. width: 50,
  411. ellipsis: true,
  412. hideInSearch: true,
  413. },
  414. {
  415. title: '段落号',
  416. dataIndex: 'paragraphNo',
  417. key: 'paragraphNo',
  418. align: 'center',
  419. width: 70,
  420. ellipsis: true,
  421. hideInSearch: true,
  422. },
  423. {
  424. title: '段落字数',
  425. dataIndex: 'wordCount',
  426. key: 'wordCount',
  427. align: 'center',
  428. width: 70,
  429. ellipsis: true,
  430. hideInSearch: true,
  431. },
  432. {
  433. title: '创建时间',
  434. dataIndex: 'createTime',
  435. key: 'createTime',
  436. align: 'center',
  437. width: 150,
  438. ellipsis: true,
  439. hideInSearch: true,
  440. },
  441. {
  442. title: '更新时间',
  443. dataIndex: 'updateTime',
  444. key: 'updateTime',
  445. align: 'center',
  446. width: 150,
  447. ellipsis: true,
  448. hideInSearch: true,
  449. },
  450. {
  451. title: '操作',
  452. dataIndex: 'cz',
  453. key: 'cz',
  454. width: 90,
  455. ellipsis: true,
  456. align: 'center',
  457. hideInSearch: true,
  458. render: (a, b) => {
  459. return (
  460. <Space>
  461. <Button
  462. type="link"
  463. size="small"
  464. onClick={() => {
  465. closeForm(true, b);
  466. }}
  467. >
  468. 编辑
  469. </Button>
  470. <Popconfirm
  471. title={
  472. <div>
  473. 确定要删除<span style={{ color: 'red' }}>{b.paragraphNo}</span>号段落?
  474. </div>
  475. }
  476. onConfirm={() => {
  477. del(b.id);
  478. }}
  479. >
  480. <a style={{ color: 'red' }}>删除</a>
  481. </Popconfirm>
  482. </Space>
  483. );
  484. },
  485. },
  486. ];
  487. };