index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
  2. import styles from './index.module.scss'
  3. import { useDispatch, useSelector } from 'react-redux'
  4. import { B4FromDataType } from './data'
  5. import { B4_APIgetlist, B4_APIgetlistAll } from '@/store/action/B4JsonPush'
  6. import { RootState } from '@/store'
  7. import { B4tableType } from '@/types'
  8. import { B1options2, B1options2Obj } from '../B1Plan/data'
  9. import { Button, Cascader, Input, Select, Table, Tooltip } from 'antd'
  10. import { QuestionCircleOutlined } from '@ant-design/icons'
  11. import { MessageFu } from '@/utils/message'
  12. import dayjs from 'dayjs'
  13. import ExportJsonExcel from 'js-export-excel'
  14. import { mapDataAll1 } from '../C1User/AddUser/city'
  15. function B4JsonPush() {
  16. const dispatch = useDispatch()
  17. // 筛选和分页
  18. const [tableSelect, setTableSelect] = useState<B4FromDataType>({
  19. siteArr: undefined,
  20. province: '',
  21. city: '',
  22. region: '',
  23. pmUser: '',
  24. jsonStatus: '',
  25. linkStatus: '',
  26. searchKey: '',
  27. pageSize: 10,
  28. pageNum: 1
  29. })
  30. const tableSelectRef = useRef({} as B4FromDataType)
  31. useEffect(() => {
  32. tableSelectRef.current = { ...tableSelect }
  33. }, [tableSelect])
  34. // 点击搜索的 时间戳
  35. const [timeKey, setTimeKey] = useState(-1)
  36. // 发送接口的函数
  37. const getListFu = useCallback(() => {
  38. const objTemp: any = {}
  39. if (tableSelectRef.current.siteArr) {
  40. const temp = tableSelectRef.current.siteArr
  41. objTemp.province = temp[0] || ''
  42. objTemp.city = temp[1] || ''
  43. objTemp.region = temp[2] || ''
  44. }
  45. const obj = {
  46. ...tableSelectRef.current,
  47. ...objTemp
  48. }
  49. dispatch(B4_APIgetlist(obj))
  50. }, [dispatch])
  51. useEffect(() => {
  52. getListFu()
  53. }, [getListFu, timeKey])
  54. // 输入框的改变
  55. const txtChangeFu = useCallback(
  56. (txt: string, key: 'pmUser' | 'searchKey') => {
  57. setTableSelect({ ...tableSelect, [key]: txt })
  58. },
  59. [tableSelect]
  60. )
  61. // 点击搜索
  62. const clickSearch = useCallback(() => {
  63. setTableSelect({ ...tableSelect, pageNum: 1 })
  64. setTimeout(() => {
  65. setTimeKey(Date.now())
  66. }, 50)
  67. }, [tableSelect])
  68. // 点击重置
  69. const [inputKey, setInputKey] = useState(1)
  70. const resetSelectFu = useCallback(() => {
  71. // 把2个输入框和时间选择器清空
  72. setInputKey(Date.now())
  73. setTableSelect({
  74. siteArr: undefined,
  75. province: '',
  76. city: '',
  77. region: '',
  78. pmUser: '',
  79. jsonStatus: '',
  80. linkStatus: '',
  81. searchKey: '',
  82. pageSize: 10,
  83. pageNum: 1
  84. })
  85. setTimeout(() => {
  86. setTimeKey(Date.now())
  87. }, 50)
  88. }, [])
  89. // 从仓库获取列表
  90. const B4TableList = useSelector((state: RootState) => state.B4JsonPush.B4TableList)
  91. // 页码变化
  92. const paginationChange = useCallback(
  93. () => (pageNum: number, pageSize: number) => {
  94. setTableSelect({ ...tableSelect, pageNum, pageSize })
  95. setTimeout(() => {
  96. setTimeKey(Date.now())
  97. }, 50)
  98. },
  99. [tableSelect]
  100. )
  101. const columns = useMemo(() => {
  102. return [
  103. {
  104. title: '机房编码',
  105. render: (item: B4tableType) => item.roomNum || '(空)'
  106. },
  107. {
  108. title: '站址地区',
  109. render: (item: B4tableType) =>
  110. !item.province && !item.city && !item.region
  111. ? '(空)'
  112. : `${item.province}${item.city ? '-' + item.city : ''}${
  113. item.region ? '-' + item.region : ''
  114. }`
  115. },
  116. {
  117. title: '项目经理',
  118. render: (item: B4tableType) => {
  119. if (item.creatorId === 1) return '管理员'
  120. else {
  121. return item.pmName || '(空)'
  122. }
  123. }
  124. },
  125. {
  126. title: '场景码',
  127. render: (item: B4tableType) => item.sceneCode || '(空)'
  128. },
  129. {
  130. title: '链接推送状态',
  131. render: (item: B4tableType) => (
  132. <>
  133. {Reflect.get(B1options2Obj, item.pushLinkStatus) || '(空)'}
  134. <span style={{ cursor: 'pointer' }} hidden={!item.pushLinkDesc}>
  135. <Tooltip title={item.pushLinkDesc}>
  136. &nbsp;
  137. <QuestionCircleOutlined rev={undefined} />
  138. </Tooltip>
  139. </span>
  140. </>
  141. )
  142. },
  143. {
  144. title: '状态更新时间',
  145. render: (item: B4tableType) => item.pushLinkTime || '(空)'
  146. },
  147. {
  148. title: 'Json推送状态',
  149. render: (item: B4tableType) => (
  150. <>
  151. {Reflect.get(B1options2Obj, item.jsonStatus) || '(空)'}
  152. <span style={{ cursor: 'pointer' }} hidden={!item.jsonDesc}>
  153. <Tooltip title={item.jsonDesc}>
  154. &nbsp;
  155. <QuestionCircleOutlined rev={undefined} />
  156. </Tooltip>
  157. </span>
  158. </>
  159. )
  160. },
  161. {
  162. title: '状态更新时间',
  163. render: (item: B4tableType) => item.jsonUpdateTime || '(空)'
  164. }
  165. ]
  166. }, [])
  167. // 点击导出
  168. const deriveFu = useCallback(async () => {
  169. if (B4TableList.total > 30000)
  170. return MessageFu.warning('只支持导出最多30000条数据。请增加筛选条件,并重新尝试')
  171. if (B4TableList.list.length === 0) return MessageFu.warning('当前搜索条件没有数据!')
  172. const name = 'Json推送' + dayjs(new Date()).format('YYYY-MM-DD HH:mm')
  173. const objTemp: any = {}
  174. if (tableSelectRef.current.siteArr) {
  175. const temp = tableSelectRef.current.siteArr
  176. objTemp.province = temp[0] || ''
  177. objTemp.city = temp[1] || ''
  178. objTemp.region = temp[2] || ''
  179. }
  180. const res = await B4_APIgetlistAll({
  181. ...tableSelect,
  182. ...objTemp,
  183. pageNum: 1,
  184. pageSize: 99999
  185. })
  186. if (res.code === 0) {
  187. if (res.data.records.length <= 0) return MessageFu.warning('当前搜索条件没有数据!')
  188. const option = {
  189. fileName: name,
  190. datas: [
  191. {
  192. sheetData: res.data.records.map((v: B4tableType) => ({
  193. roomNum: v.roomNum || '(空)',
  194. myCity:
  195. !v.province && !v.city && !v.region
  196. ? '(空)'
  197. : `${v.province}${v.city ? '-' + v.city : ''}${v.region ? '-' + v.region : ''}`,
  198. pmName: v.creatorId === 1 ? '管理员' : v.pmName || '(空)',
  199. sceneCode: v.sceneCode || '(空)',
  200. pushLinkStatus: Reflect.get(B1options2Obj, v.pushLinkStatus) || '(空)',
  201. pushLinkDesc: v.pushLinkDesc || '(空)',
  202. pushLinkTime: v.pushLinkTime || '(空)',
  203. jsonStatus: Reflect.get(B1options2Obj, v.jsonStatus) || '(空)',
  204. jsonDesc: v.jsonDesc || '(空)',
  205. jsonUpdateTime: v.jsonUpdateTime || '(空)'
  206. })),
  207. sheetName: name,
  208. sheetFilter: [
  209. 'roomNum',
  210. 'myCity',
  211. 'pmName',
  212. 'sceneCode',
  213. 'pushLinkStatus',
  214. 'pushLinkDesc',
  215. 'pushLinkTime',
  216. 'jsonStatus',
  217. 'jsonDesc',
  218. 'jsonUpdateTime'
  219. ],
  220. sheetHeader: [
  221. '机房编码',
  222. '站址地区',
  223. '项目经理',
  224. '场景码',
  225. '链接推送状态',
  226. '链接推送状态描述',
  227. '状态更新时间',
  228. 'Json推送状态',
  229. 'Json推送状态描述',
  230. '状态更新时间'
  231. ],
  232. columnWidths: [10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
  233. }
  234. ]
  235. }
  236. const toExcel = new ExportJsonExcel(option) //new
  237. toExcel.saveExcel() //保存
  238. }
  239. }, [B4TableList.list.length, B4TableList.total, tableSelect])
  240. return (
  241. <div className={styles.B4JsonPush}>
  242. <div className='pageTitle'>Json推送</div>
  243. {/*顶部筛选 */}
  244. <div className='B4top'>
  245. <div className='B4topSon'>
  246. <div className='B4topRow'>
  247. <span>搜索项:</span>
  248. <Input
  249. key={inputKey}
  250. maxLength={24}
  251. style={{ width: 260 }}
  252. placeholder='请输入机房编码/场景码,最多24字'
  253. allowClear
  254. onChange={e => txtChangeFu(e.target.value, 'searchKey')}
  255. />
  256. </div>
  257. <div className='B4topRow'>
  258. <span>站址地区:</span>
  259. <Cascader
  260. changeOnSelect
  261. value={tableSelect.siteArr}
  262. style={{ width: 200 }}
  263. options={mapDataAll1}
  264. placeholder='全部'
  265. onChange={e => setTableSelect({ ...tableSelect, siteArr: e as string[] })}
  266. />
  267. </div>
  268. <div className='B4topRow'>
  269. <span>项目经理:</span>
  270. <Input
  271. key={inputKey}
  272. maxLength={10}
  273. style={{ width: 200 }}
  274. placeholder='请输入姓名,最多10字'
  275. allowClear
  276. onChange={e => txtChangeFu(e.target.value, 'pmUser')}
  277. />
  278. </div>
  279. </div>
  280. <div className='B4topSon B4topSon2'>
  281. <div>
  282. <div className='B4topRow'>
  283. <span>链接推送状态:</span>
  284. <Select
  285. style={{ width: 194 }}
  286. value={tableSelect.linkStatus}
  287. onChange={e => setTableSelect({ ...tableSelect, linkStatus: e })}
  288. options={B1options2}
  289. />
  290. </div>
  291. <div className='B4topRow'>
  292. <span>Json推送状态:</span>
  293. <Select
  294. style={{ width: 194 }}
  295. value={tableSelect.jsonStatus}
  296. onChange={e => setTableSelect({ ...tableSelect, jsonStatus: e })}
  297. options={B1options2}
  298. />
  299. </div>
  300. </div>
  301. <div>
  302. <Button onClick={resetSelectFu}>重置</Button>&emsp;
  303. <Button type='primary' onClick={clickSearch}>
  304. 查询
  305. </Button>
  306. &emsp;
  307. <Button type='primary' onClick={deriveFu}>
  308. 导出表格
  309. </Button>
  310. </div>
  311. </div>
  312. </div>
  313. {/* 表格主体 */}
  314. <div className='tableMain'>
  315. <Table
  316. scroll={{ y: 578 }}
  317. dataSource={B4TableList.list}
  318. columns={columns}
  319. rowKey='id'
  320. pagination={{
  321. showQuickJumper: true,
  322. position: ['bottomCenter'],
  323. showSizeChanger: true,
  324. current: tableSelect.pageNum,
  325. pageSize: tableSelect.pageSize,
  326. total: B4TableList.total,
  327. onChange: paginationChange()
  328. }}
  329. />
  330. </div>
  331. {/* 右下角的列表数量 */}
  332. <div className='tableNumBox'>
  333. 共 <span>{B4TableList.total}</span> 条数据
  334. </div>
  335. </div>
  336. )
  337. }
  338. const MemoB4JsonPush = React.memo(B4JsonPush)
  339. export default MemoB4JsonPush