index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import Tables from '@/components/Tables'
  2. import { useAjax } from '@/Hook/useAjax'
  3. import { exportAutoLinkExcle, importLinkExcle, selectLinks } from '@/services/operating/link'
  4. import { downloadFile } from '@/utils/downloadFile'
  5. import { DownloadOutlined, UploadOutlined } from '@ant-design/icons'
  6. import { Button, Card, Drawer, message, Popover, Select, Space, Tooltip, Upload } from 'antd'
  7. import { RcCustomRequestOptions } from 'antd/lib/upload/interface'
  8. import React, { useCallback, useEffect, useMemo, useState } from 'react'
  9. import columns from './tableConfig'
  10. import detailsColumns from './detailsTableConfig'
  11. import platformText from './platformText'
  12. import style from './index.less'
  13. enum LinkType {
  14. '数据',
  15. '推广链接',
  16. '自定义活动',
  17. '赠币活动',
  18. '常规活动链接',
  19. '模板充值活动链接',
  20. '模板直赠活动链接',
  21. '模板消耗活动连接'
  22. }
  23. enum Platform {
  24. '花生' = '花生',
  25. '阅文' = '阅文',
  26. '阳光' = '阳光',
  27. '文鼎' = '文鼎',
  28. '掌中云' = '掌中云',
  29. }
  30. enum PlatformName {
  31. '花生推广链接' = '花生Link',
  32. '花生活动链接' = '花生Active',
  33. '阳光推广链接' = '阳光Link',
  34. '阳光活动链接' = '阳光Active',
  35. '阅文推广链接' = '阅文Link',
  36. '阅文活动链接' = '阅文Active'
  37. }
  38. const name = {
  39. '花生': '花生自动建链接导入模板 .xlsx',
  40. '阅文': '阅文自动建链接导入模板.xlsx',
  41. '阳光': '阳光自动建链接导入模板.xlsx',
  42. '文鼎': '文鼎自动建链接导入模板.xlsx',
  43. '掌中云': '掌中云自动建链接导入模板.xlsx'
  44. }
  45. function Automation() {
  46. const [platformName, setPlatformName] = useState<string>('花生')
  47. const [btnUploadLoding, setBtnUploadLoding] = useState<boolean>(false)//按钮loding
  48. const downLoad = useAjax((params) => exportAutoLinkExcle(params), { formatResult: true })//模板下载
  49. const upLoad = useAjax((params) => importLinkExcle(params), { formatResult: true })//模板下载
  50. const list = useAjax((params) => selectLinks(params), { formatResult: true })//模板下载
  51. const [visible, setVisible] = useState<boolean>(false)//详情弹窗
  52. const [data, setData] = useState<any>([])//详情数据
  53. const [bfData, setBfData] = useState<any>([])//备份详情数据用在筛选
  54. //导出
  55. const onExportLinkExcle = useCallback((platformName: string) => {
  56. downLoad.run({ platformName }).then((res) => {
  57. downloadFile(res, 'vnd.openxmlformats-officedocument.spreadsheetml.sheet', `${platformName}自动建链接导入模板.xlsx`)
  58. })
  59. }, [])
  60. //平台数组
  61. const tabList = useMemo(() => {
  62. let arr: any = []
  63. Object.keys(Platform).map((item) => {
  64. arr.push({ key: item, tab: Platform[item] })
  65. })
  66. return arr
  67. }, [Platform])
  68. //获取列表
  69. const getList = useCallback((props: { pageSize?: number, pageNum?: number, createStatus?: any }) => {
  70. let { pageSize = 20, pageNum = 1, createStatus } = props
  71. let obj = { platformName, pageSize, pageNum }
  72. if (createStatus) {
  73. obj['createStatus'] = createStatus
  74. }
  75. list.run(obj)
  76. }, [platformName])
  77. //查询
  78. const pageChange = useCallback((props: any) => {
  79. const { pageSize = 20, current = 1, createStatus } = props
  80. getList({ pageNum: current, pageSize, createStatus })
  81. }, [])
  82. //查询详情状态
  83. const statusChange = useCallback((value) => {
  84. let newData = JSON.parse(JSON.stringify(data))
  85. if (value) {
  86. newData['autoLinkReocrds'] = data?.autoLinkReocrds?.filter((item: { createStatus: any }) => item.createStatus == value)
  87. } else {
  88. newData['autoLinkReocrds'] = data?.autoLinkReocrds
  89. }
  90. setBfData(newData)
  91. }, [data, bfData])
  92. //查看详情
  93. const see = useCallback((props) => {
  94. setVisible(true)
  95. setData(props)
  96. setBfData(props)
  97. console.log(props)
  98. }, [])
  99. //首次或切换tab获取列表
  100. useEffect(() => {
  101. getList({})
  102. }, [platformName])
  103. console.log(platformText[platformName])
  104. return <div>
  105. <Card
  106. style={{ width: '100%' }}
  107. title={'自动化任务'}
  108. tabList={tabList}
  109. onTabChange={key => {
  110. setPlatformName(key)//设置平台id
  111. // setCreatLinkType(`${Platform[key]}Link`)
  112. }}
  113. size='small'
  114. tabProps={{ size: 'small', type: "card" }}
  115. tabBarExtraContent={
  116. <Space>
  117. <Popover
  118. content={
  119. <div className={style.platformText}>
  120. {platformText[platformName]}
  121. </div>
  122. }
  123. title={<h1 style={{ textAlign: 'center' }}>{platformName}字段描述</h1>}
  124. placement='bottom'
  125. >
  126. <Button type='dashed' danger>平台导入注意项</Button>
  127. </Popover>
  128. <Select
  129. showSearch
  130. placeholder='状态查询'
  131. filterOption={(input, option) =>
  132. option?.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
  133. }
  134. style={{ width: 130 }}
  135. onChange={(value) => { value && pageChange({ createStatus: value }) }}
  136. allowClear
  137. >
  138. <Select.Option value='0'>导入excel成功</Select.Option>
  139. <Select.Option value='1'>创建中</Select.Option>
  140. <Select.Option value='2'>部分成功</Select.Option>
  141. <Select.Option value='3'>全部成功</Select.Option>
  142. <Select.Option value='-1'>创建失败</Select.Option>
  143. <Select.Option value='-2'>全部失败</Select.Option>
  144. </Select>
  145. <Button onClick={() => { getList({}) }} type='primary' loading={list?.loading}>刷新</Button>
  146. {/* <Button onClick={() => onExportLinkExcle(platformName)} type='dashed'><DownloadOutlined />下载自动化模板</Button> */}
  147. <Button type='dashed'><DownloadOutlined />
  148. <a href={`http://oss.zanxiangnet.com/zx-system/file/excel/${name[platformName]}`}>下载自动化模板</a>
  149. </Button>
  150. <Upload
  151. accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
  152. action=""
  153. listType="text"
  154. onChange={() => { }}
  155. multiple={true}
  156. showUploadList={false}
  157. customRequest={(options: RcCustomRequestOptions) => {
  158. setBtnUploadLoding(true)
  159. let formData = new FormData();
  160. formData.append("file", options.file);
  161. upLoad.run({ data: formData, platformName }).then(res => {
  162. setBtnUploadLoding(false)
  163. if (res) {
  164. message.success('导入成功')
  165. list.refresh()
  166. }
  167. }).catch(() => {
  168. setBtnUploadLoding(false)
  169. })
  170. }}
  171. ><Button type='primary' icon={<UploadOutlined />} loading={btnUploadLoding}>导入模板批量创建</Button></Upload>
  172. </Space>
  173. }
  174. >
  175. <Tables
  176. dataSource={list?.data?.data?.records}
  177. columns={columns(platformName, see)}
  178. bordered
  179. size='small'
  180. rowClassName={(data: any) => {
  181. if (data['createStatus'] === -2 || data['createStatus'] === -1) {
  182. return 'table_row_red'
  183. }
  184. if (data['createStatus'] === 2) {
  185. return 'table_row_yellow'
  186. }
  187. return ''
  188. }}
  189. // pageChange={pageChange}
  190. // sizeChange={pageChange}
  191. total={list?.data?.data?.total}
  192. onChange={pageChange}
  193. />
  194. </Card>
  195. {/* 详情弹窗 */ }
  196. <Drawer
  197. title={<div style={{ display: 'flex', justifyContent: 'space-between' }}>
  198. <Space>
  199. <span>{data?.fileName}</span>
  200. <a href={data?.excelLink}>导出Excel</a>
  201. </Space>
  202. <Select
  203. showSearch
  204. placeholder='状态查询'
  205. filterOption={(input, option) =>
  206. option?.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
  207. }
  208. style={{ width: 130 }}
  209. onChange={(value) => { statusChange(value) }}
  210. allowClear
  211. >
  212. <Select.Option value={'0'}>创建</Select.Option>
  213. <Select.Option value={'1'}>创建中</Select.Option>
  214. <Select.Option value={'2'}>创建成功</Select.Option>
  215. <Select.Option value={'-1'}>创建链接失败</Select.Option>
  216. <Select.Option value={'-2'}>创建客服消息失败</Select.Option>
  217. </Select>
  218. </div>}
  219. placement={'top'}
  220. closable={false}
  221. onClose={() => { setVisible(false) }}
  222. visible={visible}
  223. height={500}
  224. >
  225. <Tables
  226. dataSource={bfData?.autoLinkReocrds}
  227. columns={detailsColumns(platformName)}
  228. bordered
  229. size='small'
  230. scroll={{ x: 3000 }}
  231. rowClassName={(data: any) => {
  232. console.log(data['createStatus'])
  233. if (data['createStatus'] === -1 || data['createStatus'] === -2) {
  234. return 'table_row_red'
  235. }
  236. return ''
  237. }}
  238. />
  239. </Drawer>
  240. </div >
  241. }
  242. export default Automation