Просмотр исходного кода

Merge branch 'master' of http://git.zanxiangnet.com/wjx/h5-sdk-react

shenwu 8 месяцев назад
Родитель
Сommit
430082712e
5 измененных файлов с 53 добавлено и 16 удалено
  1. 19 7
      src/App.tsx
  2. 13 0
      src/api/index.ts
  3. 1 1
      src/components/floatingWindow.tsx
  4. 19 5
      src/pages/loginSucc/index.tsx
  5. 1 3
      src/pages/payPop/index.tsx

+ 19 - 7
src/App.tsx

@@ -1,7 +1,7 @@
 import { useEffect, useMemo, useState } from 'react'
 import './App.less'
 import LoginPop from './pages/loginPop'
-import { getInitAppletApi, tokenExpireTimeCheckApi, weChatLoginApi } from './api'
+import { getInitAppletApi, setVisitLogPushApi, tokenExpireTimeCheckApi, weChatLoginApi } from './api'
 import { useAjax } from './hooks/useAjax'
 import { removeGameId, removeToken, setGameId, setToken } from './utils/auth'
 import { Spin, App as AntdApp, Result } from 'antd'
@@ -24,6 +24,7 @@ function App() {
 	const searchParams = new URLSearchParams(new URL(url).search);
 	const gameId = searchParams.get('game_id')
 	const isSw = searchParams.get('isSw')
+	const vt = searchParams.get('vt')
 	const { state, dispatch, getDetails } = useConfig()
 	const { typeSwitch, token } = state
 	// const [isInit, setIsInit] = useState<boolean>(false)
@@ -33,13 +34,14 @@ function App() {
 
 	const getInitApplet = useAjax(() => getInitAppletApi())
 	const weChatLogin = useAjax((params) => weChatLoginApi(params))
+	const setVisitLogPush = useAjax((params) => setVisitLogPushApi(params))
 	const tokenExpireTimeCheck = useAjax(() => tokenExpireTimeCheckApi())
 	/**************************************/
 
 	useEffect(() => {
 		// sw
-		if(isSw){
-			localStorage.setItem("isSw",isSw)
+		if (isSw) {
+			localStorage.setItem("isSw", isSw)
 		}
 		function handleOrientationChange() {
 			let orientationType = 'VERTICAL'
@@ -77,6 +79,12 @@ function App() {
 		}
 	}, [gameId])
 
+	useEffect(() => {
+		if (vt === '1' && gameId) {
+			setVisitLogPush.run({ url: window.location.href })
+		}
+	}, [vt, gameId])
+
 	// 监听token 获取用户信息
 	useEffect(() => {
 		if (token) {
@@ -117,13 +125,17 @@ function App() {
 		getInitApplet.run().then(res => {
 			setIsLoding(false)
 			if (res?.data) {
-				let h5WeChatControl = res?.data?.h5GameConfigDTO?.h5WeChatControl || 'UN_CONTROL'
+				let h5WeChatControl = res?.data?.h5GameConfigMap?.h5WeChatControl || 'UN_CONTROL'
+				if (h5WeChatControl === 'ONLY_WE_CHAT' && !isWeChat()) {
+					window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=888"
+					return
+				}
 				dispatch({ type: 'setIsPut', params: { isPut: (res.data.isPut && res.data.appId) || false } })
 				document.title = (res.data?.gameName || '游戏-登录')
-				dispatch({ type: 'setInitData', params: { initData: { ...res.data, ...res.data?.h5GameConfigDTO } } })
-				if (res.data?.h5GameConfigDTO?.h5SignLogo) {
+				dispatch({ type: 'setInitData', params: { initData: { ...res.data, ...res.data?.h5GameConfigMap } } })
+				if (res.data?.h5GameConfigMap?.h5SignLogo) {
 					let iconLink: any = document.querySelector('link[rel="icon"]');
-					iconLink.href = res.data?.h5GameConfigDTO?.h5SignLogo
+					iconLink.href = res.data?.h5GameConfigMap?.h5SignLogo
 				}
 				if (isWx() && ['ios', 'android'].includes(isOs()) && h5WeChatControl === 'UN_WE_CHAT') {
 					setIsPhoneWxShow(false)

+ 13 - 0
src/api/index.ts

@@ -1,6 +1,19 @@
 import request from "../utils/request";
 
 
+/**
+ * 渠道打开调用
+ * @param data 
+ * @returns 
+ */
+export async function setVisitLogPushApi(data: { url: string }) {
+    return request({
+        url: "/api/visit/log/push",
+        method: 'POST',
+        data
+    })
+}
+
 /**
  * 初始化接口
  * @returns 

+ 1 - 1
src/components/floatingWindow.tsx

@@ -13,7 +13,7 @@ interface Props {
  * @returns 
  */
 const FloatingWindow: React.FC<Props> = ({ isVer, onClick }) => {
-
+    console.log('isVer--->', isVer)
     /**********************************/
     const { state: { initData: { h5SignLogo } } } = useContext(DispatchContext)!;
     const [isDragging, setIsDragging] = useState(false);

+ 19 - 5
src/pages/loginSucc/index.tsx

@@ -24,7 +24,7 @@ import showModal from "../../components/showModal"
 const LoginSucc: React.FC = () => {
 
     /*************************************/
-    const { dispatch, state: { initData: { h5GameUrl, h5SignShow }, userData, isBind, isAuth, orientation }, getDetails } = useContext(DispatchContext)!;
+    const { dispatch, state: { initData: { h5GameUrl, h5SignShow, orientation: isOrientationServer }, userData, isBind, isAuth, orientation }, getDetails } = useContext(DispatchContext)!;
     const { userId, authentication, checkSwitch, bindPhone } = userData
     const [open, setOpen] = useState<boolean>(false)
     const [openPhone, setOpenPhone] = useState<boolean>(false)
@@ -58,7 +58,7 @@ const LoginSucc: React.FC = () => {
 
     useEffect(() => {
         let os = isOs()
-        if (['ios', 'android'].includes(os) && orientation === 'VERTICAL') {
+        if (['ios', 'android'].includes(os) && orientation === 'VERTICAL' && !isOrientationServer) {
             setIsVer(true)
         } else {
             setIsVer(false)
@@ -90,7 +90,7 @@ const LoginSucc: React.FC = () => {
     const startTimer = () => {
         if (!timer) {
             activeEscalationHandle()
-            let t:any = setInterval(() => {
+            let t: any = setInterval(() => {
                 activeEscalationHandle()
             }, 1000 * 60 * 10)
             setTimer(t)
@@ -139,7 +139,11 @@ const LoginSucc: React.FC = () => {
                     })
                     break
                 case 'member.pay'://支付
-                    setPayConfig({ open: true, data: data.data })
+                    if (data?.data) {
+                        setPayConfig({ open: true, data: data.data || {} })
+                    } else {
+                        message.error('支付失败:格式错误')
+                    }
                     break
                 case 'member.uprole': // 上报
                     escalation(data.data)
@@ -339,7 +343,17 @@ const LoginSucc: React.FC = () => {
             {openModify && <Modify open={openModify} onClose={() => setOpenModify(false)} onChange={() => { getDetails(); setOpenModify(false) }} />}
             {/* 悬浮球 */}
             {h5SignShow !== 'SIGN_SHOW_NONE' && <>
-                {(h5SignShow === 'SIGN_SHOW_ALL' || ((h5SignShow === 'SIGN_SHOW_WX_NONE' && !isWx()) || (isOs() === 'windows' || isOs() === 'mac')) || (h5SignShow === 'SIGN_SHOW_H5_NONE' && (isOs() === 'windows' || isOs() === 'mac'))) && <FloatingWindow isVer={isVer} onClick={() => setOpen(true)} />}
+                {(
+                    h5SignShow === 'SIGN_SHOW_ALL' ||
+                    (
+                        (h5SignShow === 'SIGN_SHOW_WX_NONE' && !isWx())
+                        // || (isOs() === 'windows' || isOs() === 'mac')
+                    )
+                    || (
+                        h5SignShow === 'SIGN_SHOW_H5_NONE' &&
+                        (isOs() === 'windows' || isOs() === 'mac')
+                    )
+                ) && <FloatingWindow isVer={isVer} onClick={() => setOpen(true)} />}
             </>}
             {/* 支付选择组件 */}
             {payConfig.open && <PayPop isVer={isVer} {...payConfig} onClose={() => setPayConfig({ open: false, data: {} })} onChange={preOrderSucc} />}

+ 1 - 3
src/pages/payPop/index.tsx

@@ -64,15 +64,13 @@ const PayPop: React.FC<Props> = ({ open, data, onClose, onChange, isVer }) => {
         })
     }
 
-
-
     return <>
         {payPostReady.loading && <LoadingPop />}
 
         {isVer ? <div className="pop">
             <div className="pop_body" style={{ transform: 'rotate(90deg)' }}>
                 <div className="payment_head">
-                    <span className="payment_amount">支付金额:<b>{data.amount + '元'}</b></span>
+                    <span className="payment_amount">支付金额:<b>{data?.amount + '元'}</b></span>
                     <a className="payment_close icon_close" onClick={() => onClose?.()}></a>
                 </div>
                 <div className="payment_type">