wxMpnews.tsx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import { Button, Card, Modal, Pagination, Tabs, Tag } from 'antd'
  2. import React, { useCallback, useEffect, useRef, useState } from 'react'
  3. import DrawerPage from "@/components/FileBox/components/newsModal"
  4. import { useModel } from 'umi'
  5. import style from './mpnews.less'
  6. import FileBox from '../FileBox'
  7. /**
  8. *
  9. * 图文素材
  10. *
  11. * 编辑图文内容 素材库导入
  12. */
  13. type Props = {
  14. visible: boolean,
  15. onCancel: () => void,
  16. onOK: (props: any, type?: number) => void,
  17. defaultData: any,
  18. wx?: any,
  19. isNews?: boolean
  20. }
  21. /**微信图文弹窗 */
  22. const WxMpnews = React.memo((props: Props) => {
  23. const { visible, onCancel, onOK, wx } = props
  24. const [action, setAction] = useState<any>('')
  25. const { getData, update } = useModel('useOperating.useMaterialContent', model => ({ getData: model.getWeData, update: model.update }))
  26. const { actionWX } = useModel('useOperating.useWxGroupList', model => ({ actionWX: model.state.actionWX }))
  27. let refD: { current: { showDrawer: (props?: any) => void } } | any = useRef()//DrawerPage获取实例方法
  28. const { state, set, getList } = useModel('useOperating.useBdMedia')
  29. const [isWx, setIsWx] = useState<boolean>(false)
  30. const { fileType, belongUser, parentId, selectItem } = state
  31. /**加载组件或数据更新执行请求列表 */
  32. useEffect(() => {
  33. set({ fileType: 'news' })//设置获取图文列表
  34. if (belongUser === '1' || belongUser === '0') {
  35. getList()//获取列表
  36. }
  37. }, [fileType, belongUser, parentId])
  38. let pageSizeChange = useCallback((pageNum: number, pageSize: number) => {
  39. getData.run({
  40. pageNum: pageNum,
  41. pageSize: pageSize,
  42. mpId: actionWX?.id,
  43. mediaType: 'news'
  44. })
  45. }, [actionWX?.id])
  46. //同步更新
  47. let sync = useCallback(() => {
  48. update.run({ mpId: actionWX?.id, mediaType: 'news' })
  49. }, [actionWX?.id])
  50. //选中图片
  51. let handleClick = useCallback((data: any) => {
  52. setAction(data)
  53. }, [])
  54. //ok
  55. let ok = useCallback(() => {
  56. if (isWx) {
  57. onOK(action)
  58. } else {
  59. onOK(selectItem)
  60. }
  61. }, [action, isWx, selectItem])
  62. useEffect(() => {
  63. if (actionWX?.id) {
  64. getData.run({ mpId: actionWX?.id, mediaType: 'news', pageSize: 9, pageNum: 1 })
  65. }
  66. }, [actionWX?.id])
  67. useEffect(() => {
  68. if (props.defaultData) {
  69. setAction(props.defaultData)
  70. }
  71. }, [props.defaultData])
  72. //tabs切换
  73. const change = useCallback((s: string) => {
  74. setIsWx(s === '1' ? false : true)
  75. }, [])
  76. return <div >
  77. <Modal
  78. open={visible}
  79. title='图文素材'
  80. onCancel={onCancel}
  81. onOk={ok}
  82. width={1200}
  83. destroyOnClose
  84. maskClosable={false}
  85. >
  86. <Tabs defaultActiveKey="1" onChange={change} type='card'>
  87. <Tabs.TabPane tab="本地素材" key="1">
  88. <Tabs
  89. onChange={(activeKey: any) => { set({ belongUser: activeKey }) }}
  90. activeKey={belongUser}
  91. items={[
  92. { label: '个人本地', key: '1' },
  93. { label: '公共本地', key: '0' },
  94. ]}
  95. />
  96. <FileBox isAll={false} noFile={true} height={450} showDrawer={refD?.current?.showDrawer} isBd={true} />
  97. </Tabs.TabPane>
  98. <Tabs.TabPane tab="微信素材" key="2">
  99. <div className={style.btn}>
  100. <Button type='primary' onClick={() => { refD?.current.showDrawer() }} loading={getData?.loading} style={{ marginRight: 10 }}>新建微信素材</Button>
  101. <Button type='primary' onClick={sync} loading={update?.loading}>更新公众号下素材</Button>
  102. </div>
  103. <div className={style.box}>
  104. {
  105. [0, 1, 2].map((n) => {
  106. return <ul className={style.ul} key={n}>
  107. {
  108. getData?.data?.records?.map((item: any, index: number) => {
  109. if (index % 3 === n) {
  110. return <li key={item.mediaId} className={action?.mediaId === item.mediaId ? style.action : ""} onClick={() => handleClick(item)}>
  111. <Card
  112. hoverable
  113. className={style.box_card}
  114. cover={
  115. item?.news?.map((list: any, index: number) => {
  116. return <div className={style.img_ScwxBox} key={index}>
  117. <span>{list.title}</span>
  118. <img src={list.thumbMediaUrl} />
  119. </div>
  120. })
  121. }
  122. />
  123. </li>
  124. }
  125. return null
  126. })
  127. }
  128. </ul>
  129. })
  130. }
  131. </div>
  132. <div className={style.footer}>
  133. <Pagination
  134. onChange={pageSizeChange}
  135. size={'small'}
  136. defaultCurrent={1}
  137. defaultPageSize={9}
  138. total={getData?.data?.total}
  139. style={{ float: 'right' }}
  140. showTotal={(total) => <Tag color="cyan">总共{total}数据</Tag>}
  141. />
  142. </div>
  143. </Tabs.TabPane>
  144. </Tabs>
  145. <DrawerPage ref={refD} syncNews={false} isWx={isWx} isAll={false} />
  146. </Modal>
  147. </div >
  148. }, (a, b) => {
  149. if (JSON.stringify(a) === JSON.stringify(b)) {
  150. return true
  151. }
  152. return false
  153. })
  154. export default WxMpnews