wxHistorBD.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import useIndexDB from '@/Hook/useIndexDB';
  2. import { Modal, Row, Pagination, Card, Input, Button, Space } from 'antd'
  3. import React, { useCallback, useEffect, useState } from 'react'
  4. import { useModel } from 'umi';
  5. import style from './db.less'
  6. import filePng from '../../../public/file.png'
  7. /**
  8. * @param historyType //历史图文type 0: 智能互动消息历史 1:客服消息历史
  9. */
  10. type props = {
  11. visible: boolean,
  12. onCancel: () => void,
  13. onOK: (props: any, type?: number) => void,
  14. wx?: any,
  15. }
  16. const WxHistoryMpnews: React.FC<props> = (props) => {
  17. const { visible, onCancel, onOK, } = props
  18. const [action, setAction] = useState<number>(0)
  19. const [actionData, setActionData] = useState()
  20. let { state: { data, total } } = useModel('useOperating.useDB')
  21. const { query, del } = useIndexDB()
  22. //ok
  23. const pageSize = 10 // 每页请求多少数据
  24. let ok = useCallback(() => {
  25. onOK(actionData)
  26. }, [actionData])
  27. let pageSizeChange = useCallback((pageNum, pageSize) => {
  28. console.log(pageNum, pageSize)
  29. query({ start: pageNum, end: pageSize })
  30. }, [query])
  31. //选中图片
  32. let handleClick = useCallback((data) => {
  33. setAction(data?.id)
  34. setActionData(data?.data)
  35. }, [])
  36. useEffect(() => {
  37. query()
  38. }, [query])
  39. return <Modal
  40. open={visible}
  41. title={<span>浏览器本地素材库<span style={{ color: 'red' }}>不需要的数据请手动删除避免太多数据会很卡,存放上限跟个人浏览器浏览器性能相关!</span></span>}
  42. onCancel={onCancel}
  43. onOk={ok}
  44. width={1000}
  45. >
  46. {/* <Row justify='space-between'>
  47. <Col>
  48. <Search placeholder="请输入" enterButton="搜索" loading={false} />
  49. </Col>
  50. <Col><Button>一键清空</Button></Col>
  51. </Row> */}
  52. <div className={style.content}>
  53. <div style={{ borderBottom: '1px solid #efefef', paddingBottom: 10 }}>
  54. <Space>
  55. <Input.Search placeholder="模糊查询(支持链接,内容,标题)" onSearch={(value: string) => { query({ str: value }) }} style={{ width: 300 }} />
  56. <Button onClick={() => del(action)} type='primary' disabled={!action}>删除</Button>
  57. </Space>
  58. </div>
  59. <div className={style.box}>
  60. {
  61. [0, 1, 2].map((n) => {
  62. return <ul className={style.ul} key={n}>
  63. {
  64. data.length > 0 && data?.map((item: any, index: number) => {
  65. if (index % 3 === n) {
  66. return <li key={item?.id} className={action === item?.id ? style.action : ""} onClick={() => handleClick(item)}>
  67. <Card
  68. hoverable
  69. className={style.box_card}
  70. cover={
  71. item?.data?.map((a: any, eq: number) => {
  72. return <div className={style.img_ScwxBox} key={eq}>
  73. <span>{a?.title || a?.newsTitle}</span>
  74. {/* <img src={(a?.knewsThumbInfo?.folder ? filePng : a?.knewsThumbInfo?.id ? a?.knewsThumbInfo?.url : a?.knewsThumbUrl) || ('https://s.weituibao.com/static/1552098829922/bigfm.png')} /> */}
  75. {Object.keys(a)?.includes('newsPicUrl') ? <img src={a?.newsPicUrl} /> : <img src={a?.knewsThumbUrl || (a?.knewsThumbId ? filePng : 'https://s.weituibao.com/static/1552098829922/bigfm.png')} />}
  76. </div>
  77. })
  78. }
  79. />
  80. </li>
  81. }
  82. return null
  83. })
  84. }
  85. </ul>
  86. })
  87. }
  88. </div>
  89. </div>
  90. <Row justify='center' style={{ paddingTop: 10, borderTop: '1px solid #efefef' }}>
  91. <Pagination size="small" total={total} showQuickJumper pageSize={pageSize} onChange={pageSizeChange} />
  92. </Row>
  93. </Modal>
  94. }
  95. export default WxHistoryMpnews