shenwu 5 months ago
parent
commit
06050f910c
2 changed files with 58 additions and 6 deletions
  1. 51 6
      src/pages/MiniApp/AdBack/index.tsx
  2. 7 0
      src/services/miniApp/adBack/index.ts

+ 51 - 6
src/pages/MiniApp/AdBack/index.tsx

@@ -1,8 +1,8 @@
 import { useAjax } from "@/Hook/useAjax"
 import { useAjax } from "@/Hook/useAjax"
-import { appAccountConfig, getAppAccountConfig, tencentAdAccountDoAuth, tencentAdAccountToAuth } from "@/services/miniApp/adBack"
+import { appAccountConfig, doAuthOfBUnit, getAppAccountConfig, tencentAdAccountDoAuth, tencentAdAccountToAuth } from "@/services/miniApp/adBack"
 import { BetaSchemaForm, PageContainer, ProCard, ProForm, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText } from "@ant-design/pro-components"
 import { BetaSchemaForm, PageContainer, ProCard, ProForm, ProFormInstance, ProFormRadio, ProFormSelect, ProFormText } from "@ant-design/pro-components"
 import { history, useModel } from "@umijs/max"
 import { history, useModel } from "@umijs/max"
-import { Button, Divider, message, Space } from "antd"
+import { Button, Divider, List, message, Modal, Radio, Space } from "antd"
 import { useEffect, useRef, useState } from "react"
 import { useEffect, useRef, useState } from "react"
 import formConfig from "./formConfig"
 import formConfig from "./formConfig"
 import { searchToObj } from "@/utils"
 import { searchToObj } from "@/utils"
@@ -14,10 +14,13 @@ function Auth() {
     let [isEdit, setIsEdit] = useState(false)
     let [isEdit, setIsEdit] = useState(false)
     const [readonly, setReadonly] = useState(false);
     const [readonly, setReadonly] = useState(false);
     const formRef = useRef<ProFormInstance>();
     const formRef = useRef<ProFormInstance>();
+    const [accountData, setAccountData] = useState<any>(null)
+    const [accountId, setAccountId] = useState(null)
     let TencentAdAccountToAuth = useAjax((params) => tencentAdAccountToAuth(params))//获取授权地址
     let TencentAdAccountToAuth = useAjax((params) => tencentAdAccountToAuth(params))//获取授权地址
     let TencentAdAccountDoAuth = useAjax((params) => tencentAdAccountDoAuth(params))//开始授权
     let TencentAdAccountDoAuth = useAjax((params) => tencentAdAccountDoAuth(params))//开始授权
     let GetAppAccountConfig = useAjax((params) => getAppAccountConfig(params))//获取回传配置
     let GetAppAccountConfig = useAjax((params) => getAppAccountConfig(params))//获取回传配置
     let AppAccountConfig = useAjax((params) => appAccountConfig(params))//设置配置
     let AppAccountConfig = useAjax((params) => appAccountConfig(params))//设置配置
+    let DoAuthOfBUnit = useAjax((params) => doAuthOfBUnit(params))//广告业务单元授权
     // 获取广告回传列表
     // 获取广告回传列表
     useEffect(() => {
     useEffect(() => {
         // 授权回调
         // 授权回调
@@ -30,11 +33,20 @@ function Auth() {
                     "callbackPage": "https://testdistribution.zanxiangwl.com/miniApp/adBack"
                     "callbackPage": "https://testdistribution.zanxiangwl.com/miniApp/adBack"
                 }).then(res => {
                 }).then(res => {
                     if (res.code === 200) {
                     if (res.code === 200) {
-                        message.success("授权成功")
+                        // 授权失败
+                        if (res.data.authorizationStatus == 1) {
+                            setAccountData(res.data)
+                        } else {
+                            message.success("授权成功")
+                            setTimeout(() => {
+                                history.push("/miniApp/adBack")
+                            }, 1000)
+                        }
+                    } else {
+                        setTimeout(() => {
+                            history.push("/miniApp/adBack")
+                        }, 1000)
                     }
                     }
-                   setTimeout(()=>{
-                    history.push("/miniApp/adBack")
-                   },1000)
                 })
                 })
             }
             }
         }
         }
@@ -109,6 +121,19 @@ function Auth() {
             }, 100)
             }, 100)
         }
         }
     }
     }
+    // 广告单元授权
+    const ad = () => {
+        doAuthOfBUnit({ state: accountData?.state, accountId }).then(res => {
+            if (res.code === 200) {
+                message.success("授权成功")
+                setAccountData(null)
+                setAccountId(null)
+            }
+            setTimeout(() => {
+                history.push("/miniApp/adBack")
+            }, 1000)
+        })
+    }
     return <PageContainer
     return <PageContainer
         tabList={getEnum("ADVERTISING_CHANNEL", "arr")?.map((item: { label: any; key: any }, index: number) => {
         tabList={getEnum("ADVERTISING_CHANNEL", "arr")?.map((item: { label: any; key: any }, index: number) => {
             if (index === 0 && !key) {
             if (index === 0 && !key) {
@@ -212,6 +237,26 @@ function Auth() {
                 destroyOnClose: true
                 destroyOnClose: true
             }}
             }}
         />
         />
+        {/* 业务单元授权 */}
+        <Modal
+            open={!!accountData}
+            title={"选择广告账号"}
+            footer={false}
+            destroyOnClose
+            onCancel={() => { setAccountData(null); setAccountId(null) }}
+            onOk={ad}
+        >
+            <Radio.Group onChange={(e) => {
+                let value = e.target.value
+                setAccountId(value)
+            }} value={accountId} >
+                {
+                    accountData?.accountIdList?.map((id: any) => {
+                        return <Radio key={id} value={id}>{id}</Radio>
+                    })
+                }
+            </Radio.Group>
+        </Modal>
     </PageContainer>
     </PageContainer>
 }
 }
 
 

+ 7 - 0
src/services/miniApp/adBack/index.ts

@@ -26,6 +26,13 @@ export async function tencentAdAccountDoAuth(data: DoAuthData) {
         data
         data
     });
     });
 }
 }
+/**广告账号授权*/
+export async function doAuthOfBUnit(data: {state:any,accountId:any}) {
+    return request(api + '/admin/tencentAdAccount/doAuthOfBUnit', {
+        method: 'POST',
+        params:data
+    });
+}
 /**应用账号广告及回传配置信息*/
 /**应用账号广告及回传配置信息*/
 export async function getAppAccountConfig({ appType, appId }: any) {
 export async function getAppAccountConfig({ appType, appId }: any) {
     return request(api + `/admin/tencentAdAccount/getAppAccountConfig/${appType}/${appId}`, {
     return request(api + `/admin/tencentAdAccount/getAppAccountConfig/${appType}/${appId}`, {