wjx 1 rok pred
rodič
commit
a293f3e84f
2 zmenil súbory, kde vykonal 11 pridanie a 4 odobranie
  1. 3 4
      src/App.tsx
  2. 8 0
      src/utils/index.ts

+ 3 - 4
src/App.tsx

@@ -11,7 +11,7 @@ import PwdPop from './pages/pwdPop'
 import useConfig, { Action, State } from './models/useConfig'
 import LoginSucc from './pages/loginSucc'
 import React from 'react'
-import { getRedirectUrl, isWx } from './utils'
+import { getRedirectUrl, isWeChat } from './utils'
 
 
 export const DispatchContext = React.createContext<{ dispatch: React.Dispatch<Action>, state: State, getDetails: () => void } | null>(null);
@@ -89,9 +89,8 @@ function App() {
 		} else {
 			console.log(gameId)
 			if (gameId) {
-				if (searchParams.get('code') && isWx()) {
+				if (searchParams.get('code') && isWeChat()) {
 					weChatLogin.run({ code: searchParams.get('code') }).then(res => {
-						console.log('1111', res)
 						if (+res.code === 200) {
 							dispatch({ type: 'setToken', params: { token: res?.data?.token } })
 							setToken(res?.data?.token)
@@ -118,7 +117,7 @@ function App() {
 					let iconLink: any = document.querySelector('link[rel="icon"]');
 					iconLink.href = res.data?.h5GameConfigDTO?.h5SignLogo
 				}
-				if (!searchParams.get('code') && res.data.isPut && res.data.appId && isWx()) {
+				if (!searchParams.get('code') && res.data.isPut && res.data.appId && isWeChat()) {
 					setIsShowLogin(false)
 					window.location.replace(`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.data.appId}&redirect_uri=${encodeURIComponent(location.href)}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`)
 				} else {

+ 8 - 0
src/utils/index.ts

@@ -143,4 +143,12 @@ export const getOrientation = () => {
     orientationType = 'VERTICAL'
   }
   return orientationType
+}
+
+/**
+ * 判断是否是必须在微信打开
+ * @returns 
+ */
+export const isWeChat = () => {
+  return isWx() || window.location.href.includes('/wechat/');
 }