index.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. import { useAjax } from "@/Hook/useAjax";
  2. import { delCorpWechatApi, getCorpWechatAllApi, getCorpWechatApi, getCorpWechatDetailApi } from "@/services/adqV3/global";
  3. import { PlusOutlined, SearchOutlined } from "@ant-design/icons";
  4. import { Button, Card, Divider, Input, message, Select, Table, Typography } from "antd";
  5. import React, { useEffect, useState } from "react"
  6. import '../../tencentAdPutIn/index.less'
  7. import Modify from "./modify";
  8. import columns from "./tableConfig";
  9. const { Text, Paragraph } = Typography;
  10. /**
  11. * 企业微信
  12. * @returns
  13. */
  14. const CorpWechat: React.FC = () => {
  15. /**********************************/
  16. const [queryForm, setQueryForm] = useState<{ pageNum: number, pageSize: number, wechatName?: string, wechatIdList?: string[] }>({ pageNum: 1, pageSize: 20 })
  17. const [queryFormNew, setQueryFormNew] = useState<{ pageNum: number, pageSize: number, wechatName?: string, wechatIdList?: string[] }>({ pageNum: 1, pageSize: 20 })
  18. const [visible, setVisible] = useState<boolean>(false)
  19. const getCorpWechat = useAjax((params) => getCorpWechatApi(params))
  20. const delCorpWechat = useAjax((params) => delCorpWechatApi(params))
  21. /**********************************/
  22. useEffect(() => {
  23. getCorpWechat.run(queryFormNew)
  24. }, [queryFormNew])
  25. const del = (id: number) => {
  26. delCorpWechat.run(id).then(res => {
  27. if (res) {
  28. message.success('删除成功')
  29. getCorpWechat.refresh()
  30. }
  31. })
  32. }
  33. return <Card
  34. className="cardResetCss"
  35. title={<div className="flexStart" style={{ gap: 8 }}>
  36. <Input style={{ width: 200 }} placeholder="请输入企业微信名称" value={queryForm?.wechatName} allowClear onChange={(e) => setQueryForm({ ...queryForm, wechatName: e.target.value, pageNum: 1 })} />
  37. <Input.TextArea
  38. style={{ width: 300 }}
  39. placeholder="请输入企业微信ID(多个逗号隔开)"
  40. allowClear
  41. rows={1}
  42. onChange={(e) => {
  43. let value = e.target.value
  44. let arr: string[] = []
  45. if (value) {
  46. value = value.replace(/[,,\s]/g, ',')
  47. arr = value.split(',').filter((a: string) => a)
  48. }
  49. setQueryForm({ ...queryForm, wechatIdList: arr, pageNum: 1 })
  50. }}
  51. />
  52. <Button type="primary" icon={<SearchOutlined />} onClick={() => setQueryFormNew({ ...queryForm })}>搜索</Button>
  53. <Button type="primary" icon={<PlusOutlined />} onClick={() => { setVisible(true) }}>新增企业微信</Button>
  54. </div>}
  55. >
  56. <Table
  57. columns={columns(del)}
  58. dataSource={getCorpWechat.data?.records}
  59. size="small"
  60. loading={getCorpWechat?.loading}
  61. scroll={{ y: 600 }}
  62. bordered
  63. rowKey={'id'}
  64. pagination={{
  65. defaultPageSize: 20,
  66. current: getCorpWechat.data?.current || 1,
  67. pageSize: getCorpWechat.data?.size || 10,
  68. total: getCorpWechat.data?.total || 0
  69. }}
  70. onChange={(pagination) => {
  71. const { current, pageSize } = pagination
  72. setQueryForm({ ...queryForm, pageNum: current || 1, pageSize: pageSize || 10 })
  73. setQueryFormNew({ ...queryForm, pageNum: current || 1, pageSize: pageSize || 10 })
  74. }}
  75. />
  76. {/* 新增修改 */}
  77. {visible && <Modify
  78. visible={visible}
  79. onClose={() => {
  80. setVisible(false)
  81. }}
  82. onChange={() => {
  83. setVisible(false)
  84. getCorpWechat.refresh()
  85. }}
  86. />}
  87. </Card>
  88. }
  89. /**
  90. * 选择企微
  91. * @param param0
  92. * @returns
  93. */
  94. export const SelectCorpWechat: React.FC<{ value?: number, onChange?: (value?: number) => void }> = ({ value, onChange }) => {
  95. /*******************************/
  96. const [visible, setVisible] = useState<boolean>(false)
  97. const getCorpWechatAll = useAjax((params) => getCorpWechatAllApi(params))
  98. /*******************************/
  99. // 获取列表
  100. useEffect(() => {
  101. getCorpWechatAll.run({})
  102. }, [])
  103. return <>
  104. <Select
  105. showSearch
  106. allowClear
  107. placeholder="请选择企微"
  108. filterOption={(input: any, option: any) => {
  109. return option!.name?.toString().toLowerCase().includes(input.toLowerCase())
  110. }}
  111. style={{ width: 480 }}
  112. dropdownRender={menu => <>
  113. {menu}
  114. <Divider style={{ margin: '8px 0' }} />
  115. <div>
  116. <Button type="link" onClick={() => {
  117. window.location.href = '/#/launchSystemV3/tencenTasset/corpWechat'
  118. }}>前往管理</Button>
  119. <Button type="link" style={{ paddingLeft: 0, paddingRight: 0 }} onClick={() => {
  120. setVisible(true)
  121. }}>新增</Button>
  122. {/* <Link href="/#/launchSystemV3/tencenTasset/miniProgramWechat" target="_blank">
  123. 前往管理
  124. </Link> */}
  125. </div>
  126. </>}
  127. value={value}
  128. onChange={(e) => onChange?.(e)}
  129. >
  130. {getCorpWechatAll?.data?.map((item: { id: number, wechatId: string, wechatName: string }) => {
  131. return <Select.Option value={item.id} key={item.id} name={item.wechatName + `(${item.wechatId})`}><Text strong>{item.wechatName}</Text><Text type="secondary">{`(${item.wechatId})`}</Text></Select.Option>
  132. })}
  133. </Select>
  134. {/* 新增修改 */}
  135. {visible && <Modify
  136. visible={visible}
  137. onClose={() => {
  138. setVisible(false)
  139. }}
  140. onChange={() => {
  141. setVisible(false)
  142. getCorpWechatAll.refresh()
  143. }}
  144. />}
  145. </>
  146. }
  147. /**
  148. * 选择企微
  149. * @param param0
  150. * @returns
  151. */
  152. export const SelectCorpWechatCorpId: React.FC<{ value?: string[], onChange?: (value?: string[]) => void }> = ({ value, onChange }) => {
  153. /*******************************/
  154. const [visible, setVisible] = useState<boolean>(false)
  155. const getCorpWechatAll = useAjax((params) => getCorpWechatAllApi(params))
  156. /*******************************/
  157. // 获取列表
  158. useEffect(() => {
  159. getCorpWechatAll.run({})
  160. }, [])
  161. return <>
  162. <Select
  163. showSearch
  164. allowClear
  165. placeholder="请选择企微"
  166. filterOption={(input: any, option: any) => {
  167. return option!.name?.toString().toLowerCase().includes(input.toLowerCase())
  168. }}
  169. mode="multiple"
  170. style={{ width: 480 }}
  171. dropdownRender={menu => <>
  172. {menu}
  173. <Divider style={{ margin: '8px 0' }} />
  174. <div>
  175. <Button type="link" onClick={() => {
  176. window.location.href = '/#/launchSystemV3/tencenTasset/corpWechat'
  177. }}>前往管理</Button>
  178. <Button type="link" style={{ paddingLeft: 0, paddingRight: 0 }} onClick={() => {
  179. setVisible(true)
  180. }}>新增</Button>
  181. {/* <Link href="/#/launchSystemV3/tencenTasset/miniProgramWechat" target="_blank">
  182. 前往管理
  183. </Link> */}
  184. </div>
  185. </>}
  186. value={value}
  187. onChange={(e) => onChange?.(e)}
  188. >
  189. {getCorpWechatAll?.data?.map((item: { id: number, wechatId: string, wechatName: string }) => {
  190. return <Select.Option value={item.wechatId} disabled={value && value?.length > 0 && !value.includes(item.wechatId)} key={item.id} name={item.wechatName + `(${item.wechatId})`}><Text strong>{item.wechatName}</Text><Text type="secondary">{`(${item.wechatId})`}</Text></Select.Option>
  191. })}
  192. </Select>
  193. {/* 新增修改 */}
  194. {visible && <Modify
  195. visible={visible}
  196. onClose={() => {
  197. setVisible(false)
  198. }}
  199. onChange={() => {
  200. setVisible(false)
  201. getCorpWechatAll.refresh()
  202. }}
  203. />}
  204. </>
  205. }
  206. /**
  207. * 展示企微
  208. * @param param0
  209. * @returns
  210. */
  211. export const ShowCorpWechatDetail: React.FC<{ id: number }> = ({ id }) => {
  212. /*******************************/
  213. const getCorpWechatDetail = useAjax((params) => getCorpWechatDetailApi(params))
  214. /*******************************/
  215. // 获取列表
  216. useEffect(() => {
  217. if (id) {
  218. getCorpWechatDetail.run(id)
  219. }
  220. }, [id])
  221. return <Paragraph style={{ fontSize: 12, wordBreak: 'break-all', marginBottom: 0 }} ellipsis={{ rows: 2 }}>
  222. {getCorpWechatDetail.data ? <>
  223. <Text strong>企业微信:{getCorpWechatDetail.data?.wechatName}</Text><Text type="secondary">{`(${getCorpWechatDetail.data?.wechatId}})`}</Text>
  224. </> : id}
  225. </Paragraph>
  226. }
  227. export default CorpWechat