index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { appAccountConfig, getAppAccountConfig, tencentAdAccountDoAuth, tencentAdAccountToAuth } from "@/services/miniApp/adBack"
  3. import { BetaSchemaForm, PageContainer, ProCard, ProForm, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText } from "@ant-design/pro-components"
  4. import { history, useModel } from "@umijs/max"
  5. import { Button, Divider, message, Space } from "antd"
  6. import { useEffect, useRef, useState } from "react"
  7. import formConfig from "./formConfig"
  8. import { searchToObj } from "@/utils"
  9. function Auth() {
  10. let { getEnum } = useModel('global')
  11. let { initialState } = useModel("@@initialState")
  12. let [key, setKey] = useState<any>()
  13. let [isEdit, setIsEdit] = useState(false)
  14. const [readonly, setReadonly] = useState(false);
  15. const formRef = useRef<ProFormInstance>();
  16. let TencentAdAccountToAuth = useAjax((params) => tencentAdAccountToAuth(params))//获取授权地址
  17. let TencentAdAccountDoAuth = useAjax((params) => tencentAdAccountDoAuth(params))//开始授权
  18. let GetAppAccountConfig = useAjax((params) => getAppAccountConfig(params))//获取回传配置
  19. let AppAccountConfig = useAjax((params) => appAccountConfig(params))//设置配置
  20. // 获取广告回传列表
  21. useEffect(() => {
  22. // 授权回调
  23. if (history.location.search) {
  24. let obj = searchToObj(history.location.search)
  25. if (obj?.state && obj?.authorization_code) {
  26. TencentAdAccountDoAuth.run({
  27. "state": obj.state,
  28. "authorizationCode": obj.authorization_code,
  29. "callbackPage": "https://testdistribution.zanxiangwl.com/miniApp/adBack"
  30. }).then(res => {
  31. if (res.code === 200) {
  32. message.success("授权成功")
  33. }
  34. setTimeout(()=>{
  35. history.push("/miniApp/adBack")
  36. },1000)
  37. })
  38. }
  39. }
  40. getConfig()
  41. }, [])
  42. //获取回传配置
  43. const getConfig = () => {
  44. GetAppAccountConfig.run({ appType: initialState?.selectApp?.appType, appId: initialState?.selectApp?.id })
  45. }
  46. // 授权
  47. const auth = () => {
  48. TencentAdAccountToAuth.run({
  49. appType: initialState?.selectApp?.appType,
  50. appId: initialState?.selectApp?.id,
  51. advertisingChannel: key,
  52. callbackPage: "https://testdistribution.zanxiangwl.com/miniApp/adBack"
  53. }).then(res => {
  54. if (res.code === 200) {
  55. window.open(res.data)
  56. }
  57. })
  58. }
  59. // submit
  60. const submit = async (values: any) => {
  61. // 遍历 firstBackRate 数组,并将 backRate 转换为字符串
  62. if (values.firstBackRate) {
  63. values.firstBackRate = values.firstBackRate.map((item: any) => {
  64. if (Array.isArray(item.backRate)) {
  65. item.backRate = item.backRate.join(":"); // 转换数组为 'min:max' 字符串
  66. }
  67. return item;
  68. });
  69. }
  70. if (values.otherBackRate) {
  71. values.otherBackRate = values.otherBackRate.map((item: any) => {
  72. if (Array.isArray(item.backRate)) {
  73. item.backRate = item.backRate.join(":"); // 转换数组为 'min:max' 字符串
  74. }
  75. return item;
  76. });
  77. }
  78. if (values.markUpBackRate) {
  79. values.markUpBackRate = values.markUpBackRate.map((item: any) => {
  80. if (Array.isArray(item.backRate)) {
  81. item.backRate = item.backRate.join(":"); // 转换数组为 'min:max' 字符串
  82. }
  83. return item;
  84. });
  85. }
  86. // 打印转换后的数据
  87. console.log("处理后的表单数据: ", values);
  88. AppAccountConfig.run({
  89. appType: initialState?.selectApp?.appType,
  90. appId: initialState?.selectApp?.id,
  91. advertisingChannel: key,
  92. policyType: 1,
  93. policyContentOfDefault: values
  94. }).then(res => {
  95. if (res.code === 200) {
  96. message.success("配置成功!")
  97. GetAppAccountConfig.refresh()
  98. setIsEdit(false)
  99. }
  100. })
  101. }
  102. // lock or edit
  103. const edit = () => {
  104. setIsEdit(true)
  105. if (GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault) {
  106. setTimeout(() => {
  107. formRef?.current?.setFieldsValue(GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault)
  108. }, 100)
  109. }
  110. }
  111. return <PageContainer
  112. tabList={getEnum("ADVERTISING_CHANNEL", "arr")?.map((item: { label: any; key: any }, index: number) => {
  113. if (index === 0 && !key) {
  114. setKey(item.key)
  115. }
  116. return { tab: item.label, key: item.key }
  117. })}
  118. tabProps={{
  119. type: 'card',
  120. hideAdd: true,
  121. onChange: (e) => setKey(e),
  122. }}
  123. >
  124. <ProCard direction="column" ghost gutter={8} loading={GetAppAccountConfig?.loading} >
  125. <ProCard
  126. bordered
  127. title="归因设置"
  128. actions={
  129. !GetAppAccountConfig?.data?.data[key]?.tencentAdAccount && <Space style={{ margin: 20 }}> <Button type="primary" onClick={auth}>授权</Button></Space>
  130. }
  131. >
  132. <div>
  133. <div style={{ marginBottom: 5 }}>
  134. <span style={{ width: 100, display: 'inline-block', textAlign: 'right' }}>归因方式:</span>
  135. <span style={{ color: "#999" }}>数据源ID</span>
  136. </div>
  137. <div style={{ marginBottom: 5 }}>
  138. <span style={{ width: 100, display: 'inline-block', textAlign: 'right' }}>数据源类型:</span>
  139. <span style={{ color: "#999" }}>{getEnum("TENCENT_USER_ACTION_TYPE", 'map').get(GetAppAccountConfig?.data?.data[key]?.tencentAdAccount?.userActionSets?.type) || "-"}</span>
  140. </div>
  141. <div style={{ marginBottom: 5 }}>
  142. <span style={{ width: 100, display: 'inline-block', textAlign: 'right' }}>数据源ID:</span>
  143. <span style={{ color: "#999" }}>{GetAppAccountConfig?.data?.data[key]?.tencentAdAccount?.userActionSets?.userActionSetId || "-"}</span>
  144. </div>
  145. <div style={{ marginBottom: 5 }}>
  146. <span style={{ width: 100, display: 'inline-block', textAlign: 'right' }}>已授权账号ID:</span>
  147. <span style={{ color: "#999" }}> {GetAppAccountConfig?.data?.data[key]?.tencentAdAccount?.userActionSets?.accountId || "-"}</span>
  148. </div>
  149. {GetAppAccountConfig?.data?.data[key]?.tencentAdAccount && <div style={{ marginBottom: 5 }}>
  150. <span style={{ width: 100, display: 'inline-block', textAlign: 'right' }}>授权:</span>
  151. <span style={{ color: "#999" }}> <Button type="primary" onClick={auth} size="small" danger>更换授权</Button></span>
  152. </div>}
  153. </div>
  154. </ProCard>
  155. <ProCard
  156. bordered
  157. title="回传设置"
  158. tooltip="回传“下单”“付费”两个行为事件,直投小程序链路额外支持“注册”(纯新+染色回流用户进入小程序)事件回传。"
  159. actions={<Space style={{ margin: 20 }}>
  160. <Button type="primary" onClick={edit}>编辑</Button>
  161. </Space>}
  162. >
  163. <div>
  164. <div style={{ marginBottom: 5 }}>
  165. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>回传类型:</span>
  166. <span style={{ color: "#999" }}> {getEnum("CALLBACK_TYPE", "map")?.get(GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.backUnit) || "-"}</span>
  167. </div>
  168. <div style={{ marginBottom: 5 }}>
  169. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>VIP回传策略:</span>
  170. <span style={{ color: "#999" }}>{getEnum("VIP_CALLBACK", "map")?.get(GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.vipOrderBackType) || "-"}</span>
  171. </div>
  172. <div style={{ marginBottom: 5 }}>
  173. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>是否补单:</span>
  174. <span style={{ color: "#999" }}>{new Map([true, false].map(key => [key, key ? "是" : "否"])).get(GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.markUpOrder) || "-"}</span>
  175. </div>
  176. <div style={{ marginBottom: 5 }}>
  177. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>单用户最大回传订单数:</span>
  178. <span style={{ color: "#999" }}> {GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.maxBackCountOfUser || "-"}</span>
  179. </div>
  180. <div style={{ marginBottom: 5 }}>
  181. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>注册充值回传的最大间隔时间:</span>
  182. <span style={{ color: "#999" }}> {GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.regPayIntervalTime ? GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault?.regPayIntervalTime + "分钟" : "-"}</span>
  183. </div>
  184. {GetAppAccountConfig?.data?.data[key]?.distributorAppAdBackPolicy?.policyContentOfDefault && <div style={{ marginBottom: 5 }}>
  185. <span style={{ width: 200, display: 'inline-block', textAlign: 'right' }}>更多内容:</span>
  186. <span style={{ color: "#999" }}><Button size='small' type='link' onClick={() => { setReadonly(true); edit() }}>查看</Button></span>
  187. </div>}
  188. </div>
  189. </ProCard>
  190. </ProCard>
  191. {/* 回传配置 */}
  192. <BetaSchemaForm<any>
  193. title={"回传策略配置"}
  194. formRef={formRef}
  195. open={isEdit}
  196. onOpenChange={(b) => {
  197. if (!b) {
  198. setIsEdit(b)
  199. setReadonly(false)
  200. }
  201. }}
  202. layoutType={"ModalForm"}
  203. labelCol={{ span: 24 }}
  204. colProps={{ span: 8 }}
  205. grid={true}
  206. layout="vertical"
  207. onFinish={submit}
  208. columns={formConfig()}
  209. submitter={readonly ? false : { render: (props, dom) => [...dom] }}
  210. modalProps={{
  211. destroyOnClose: true
  212. }}
  213. />
  214. </PageContainer>
  215. }
  216. export default Auth