|
@@ -1,26 +1,24 @@
|
|
|
-import React, { useCallback, useEffect, useState } from 'react'
|
|
|
+import React, { useCallback, useEffect } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
import TopCom from '@/components/TopCom'
|
|
|
import { Button } from 'antd'
|
|
|
-import history, { toHomeFu } from '@/utils/history'
|
|
|
+import history from '@/utils/history'
|
|
|
import { setTokenInfo } from '@/utils/storage'
|
|
|
import { MessageFu } from '@/utils/message'
|
|
|
import { useParams } from 'react-router-dom'
|
|
|
+import { API_login } from '@/store/action/all'
|
|
|
function Z1login() {
|
|
|
// 获取地址栏参数 1:课程 2:展馆
|
|
|
const urlObjTemp: any = useParams()
|
|
|
|
|
|
// 获取用户openID(微信授权)
|
|
|
const getUserCode = useCallback(() => {
|
|
|
- console.log(123, urlObjTemp.key)
|
|
|
-
|
|
|
- // window.location.href = 'http://192.168.20.55:3001/#/login?code=xxxx'
|
|
|
//此处的ID是在文档的开发-基本配置里面
|
|
|
- // let appid = 'wx3d4f2e0cfc3b8e54'
|
|
|
- // let url = `https://sit-hqbooking.4dage.com/web/#/login${urlObjTemp.key}`
|
|
|
- // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
|
|
|
- // url
|
|
|
- // )}&response_type=code&scope=SCOPE&state=STATE#wechat_redirect`
|
|
|
+ let appid = 'wxcf0db4440f05e3a5'
|
|
|
+ let url = `https://sit-hqbooking.4dage.com/web/#/login/${urlObjTemp.key}`
|
|
|
+ window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent(
|
|
|
+ url
|
|
|
+ )}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`
|
|
|
}, [urlObjTemp.key])
|
|
|
|
|
|
// 获取地址栏参数的方法
|
|
@@ -44,21 +42,22 @@ function Z1login() {
|
|
|
return r[2]
|
|
|
}, [])
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- let code = getQueryCode('code')
|
|
|
- console.log('-----------', code)
|
|
|
- if (code) {
|
|
|
- // 发请求,拿token
|
|
|
- // 用户信息存到本地
|
|
|
- setTokenInfo({
|
|
|
- token:
|
|
|
- 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwibG9naW5UeXBlIjoid3giLCJpZCI6MSwidXNlck5hbWUiOiJvakpPdDZBc1MyTUhKSUFLMWtqSV9FTllyRnIwIiwiZXhwIjoxNzM0NjU3NjgyLCJyb2xlS2V5cyI6WyJ3ZWJfdXNlciJdLCJpYXQiOjE3MzQ1NzEyODIsImp0aSI6IjBkOTNlZTBkLTI0NjAtNDliZi1iM2Y2LTdjY2ZjNzMwNjVlMSJ9.01BrenscrgsUxvM6z6GFap0d78qnnmAVQuW1VTA_3mI'
|
|
|
- })
|
|
|
- // 跳到首页
|
|
|
+ const API_loginFu = useCallback(async (code: string) => {
|
|
|
+ const res = await API_login(code)
|
|
|
+ if (res.code === 0) {
|
|
|
+ // console.log(123, res)
|
|
|
+ // // 跳到首页
|
|
|
+ setTokenInfo(res.data)
|
|
|
MessageFu.success('登录成功!')
|
|
|
- history.replace(urlObjTemp.key === '1' ? '/' : '/exhi')
|
|
|
+ history.replace(window.location.href.includes('/login/1') ? '/' : '/exhi')
|
|
|
}
|
|
|
- }, [getQueryCode, urlObjTemp.key])
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ let code = getQueryCode('code')
|
|
|
+ // console.log('-----------', code)
|
|
|
+ if (code) API_loginFu(code)
|
|
|
+ }, [API_loginFu, getQueryCode])
|
|
|
|
|
|
return (
|
|
|
<div className={styles.Z1login}>
|