Commit 32f48f21 by zhangleyuan

Merge branch 'feature/zhangleyuan/20210321/work-wechat-authorize' into 'master'

Feature/zhangleyuan/20210321/work wechat authorize

See merge request !3
parents 199a611b 11378975
......@@ -26,6 +26,7 @@ const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpack
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
const postcssNormalize = require('postcss-normalize');
const vConsolePlugin = require('vconsole-webpack-plugin');
const appPackageJson = require(paths.appPackageJson);
......@@ -607,6 +608,9 @@ module.exports = function(webpackEnv) {
};
},
}),
new vConsolePlugin({
enable: (process.env.DEPLOY_ENV === 'prod' || process.env.DEPLOY_ENV === 'beta') ? false : true
}),
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
......
......@@ -74,6 +74,7 @@
"typescript": "^4.0.2",
"underscore": "^1.10.2",
"url-loader": "2.3.0",
"vconsole-webpack-plugin": "^1.5.2",
"webpack": "4.42.0",
"webpack-dev-server": "3.11.0",
"webpack-manifest-plugin": "2.2.0",
......
<!--
* @Author: zhangleyuan
* @Date: 2021-04-08 14:56:33
* @LastEditors: zhangleyuan
* @LastEditTime: 2021-04-13 18:09:09
* @Description: 描述一下
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
-->
<!--
* @Author: 吴文洁
* @Date: 2020-08-24 12:20:57
* @LastEditors: wufan
* @LastEditTime: 2021-01-09 11:18:27
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="icon" href="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!-- <link rel="apple-touch-icon" href="../src/common/images/logo.png" /> -->
<link rel="shortcut icon" href="https://image.xiaomaiketang.com/xm/KGSYFEpcHT.png">
<title>小麦企培</title>
<script type="text/javascript" charset="utf-8" src="./jquery.min.js"></script>
<style type="text/css">
.box {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: rgba(244, 246, 250, 1);
}
p {
font-size: 17px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
line-height: 24px;
margin-top: 12px;
}
.desc{
font-size:14px;
color:#999;
}
.hide {
display: none;
text-align: center;
}
</style>
</head>
<body>
<div class="box">
<div id='success' class='hide'>
<img src="https://image.xiaomaiketang.com/xm/iRkcMHPHba.png" style='width:60px' alt="">
<p>
扫码成功
</p>
</div>
<div id="error" class='hide'>
<img src="https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
" style='width:60px' alt="">
<p id='message'>
</p>
</div>
</div>
</body>
<script>
$(document).ready(function () {
var BASIC_HOST_MAP = {
dev: 'https://dev-heimdall.xiaomai5.com/',
dev1: 'https://dev1-heimdall.xiaomai5.com/',
rc: 'https://rc-heimdall.xiaomai5.com/',
gray: 'https://gray-heimdall.xiaomai5.com/',
prod: 'https://gateway.xiaomai5.com/'
};
function getParameterByName(name) {
name = name.replace(/[\\[]/, '\\[').replace(/[\]]/, '\\]')
const regex = new RegExp('[\\?&]' + name + '=([^&#]*)')
const results = regex.exec(window.location.href)
return results === null
? ''
: decodeURIComponent(results[1].replace(/\+/g, ' '))
}
const env = getParameterByName('env');
const code = getParameterByName('code');
const ticket = getParameterByName('ticket');
const storeId = getParameterByName('storeId');
if (!code) {
postJSON('hades/anon/hades/getCorpTrainSuiteId', {}, (res) => {
const url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.result}&redirect_uri=${encodeURIComponent(location.href)}&response_type=code&scope=snsapi_privateinfo&state=STATE#wechat_redirect`
location.href = url
})
return
} else {
postJSON("hades/anon/hades/wXWorkUserTicketLogin", {
appTermEnum: 'XIAOMAI_CLOUD_CLASS_PC_WEB_CUSTOMER',
code: code,
ticket: ticket,
storeId:storeId
}, (res) => {
if (res.code == 200) {
$('#success').show()
} else {
$('#error').show();
var message = res.message.split(',').join('<br />')
if(message === "非当前企业学院"){
$('#message').html("<div><div>非当前企业学院</div><div class='desc'>尝试扫描「企业外部客户」二维码登录</div></div>");
}else{
$('#message').html(message);
}
}
})
}
function postJSON(url, data, callback) {
const ajaxOptions = {
data: JSON.stringify(data),
type: 'POST',
url: BASIC_HOST_MAP[env] + url,
contentType: 'application/json; charset=UTF-8',
timeout: 20000,
dataType: 'json',
success(res, status, xhr) {
callback(res)
},
};
$.ajax(ajaxOptions)
}
});
</script>
</html>
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Date: 2020-04-27 20:35:34
* @LastEditors: zhangleyuan
* @LastEditTime: 2021-01-14 10:48:59
* @LastEditTime: 2021-04-08 14:57:41
* @Description:
*/
......
......@@ -15,6 +15,9 @@ class Authorize extends React.Component {
}
}
componentDidMount() {
// console.log("ticket",window.getParameterByName('ticket'))
// const searchParams = this.props.location.search;
// const {code,ticket} = queryString.parse(searchParams);
const code = window.getParameterByName('code');
const ticket = window.getParameterByName('ticket');
this.setState({
......
import React, { useState, useEffect, useRef } from "react";
import Service from '@/common/js/service';
import './index.less';
function WorkWxAuthorize(props){
const [scanState,setScanState] = useState('');
const [messageText,setMessageText] = useState('');
useEffect(()=>{
const code = window.getParameterByName('code');
console.log('我起作用了');
if(!code){
workWechatAuthorize();
}else{
console.log('我已经重新进来了')
workWechatLogin();
}
},[])
function workWechatLogin(){
const code = window.getParameterByName('code');
const ticket = window.getParameterByName('ticket');
const storeId = window.getParameterByName('storeId');
Service.hades("anon/hades/wXWorkUserTicketLogin", {
appTermEnum: 'XIAOMAI_CLOUD_CLASS_PC_WEB_CUSTOMER',
code,
ticket,
storeId
}).then((res) => {
if (res.code == 200) {
setScanState('success');
} else {
let message = res.message.split(',').join('<br />')
setScanState('error');
setMessageText(message);
}
})
}
function workWechatAuthorize(){
const params = {}
Service.hades('anon/hades/getCorpTrainSuiteId',params).then((res)=>{
let path = window.location.href;
const htmlUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.result}&redirect_uri=${encodeURIComponent(path)}&response_type=code&scope=snsapi_privateinfo&state=STATE#wechat_redirect`
window.location.href = htmlUrl;
})
}
return (
<div className="work-authorize-page">
<div className="box">
{ scanState === 'success' &&
<div className="success">
<img src="https://image.xiaomaiketang.com/xm/iRkcMHPHba.png" alt=""/>
<p>
扫码成功
</p>
</div>
}
{ scanState === 'error' &&
<div className="error">
<img src="https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
" alt="" />
<p className='message'>
{ messageText }
</p>
</div>
}
</div>
</div>
)
}
// class WorkWxAuthorize extends React.Component {
// constructor(props) {
// super(props);
// this.state = {
// scanState:'',
// messageText:''
// }
// }
// componentDidMount() {
// const code = window.getParameterByName('code');
// if(!code){
// this.workWechatAuthorize();
// }else{
// console.log('我已经重新进来了')
// this.workWechatLogin();
// }
// }
// workWechatLogin= ()=>{
// const code = window.getParameterByName('code');
// const ticket = window.getParameterByName('ticket');
// const storeId = window.getParameterByName('storeId');
// Service.hades("anon/hades/wXWorkUserTicketLogin", {
// appTermEnum: 'XIAOMAI_CLOUD_CLASS_PC_WEB_CUSTOMER',
// code,
// ticket,
// storeId
// }).then((res) => {
// if (res.code == 200) {
// this.setState({
// scanState:'success'
// })
// } else {
// let message = res.message.split(',').join('<br />')
// this.setState({
// scanState:'error',
// messageText:message
// })
// }
// })
// }
// workWechatAuthorize = () => {
// const params = {}
// Service.hades('anon/hades/getCorpTrainSuiteId',params).then((res)=>{
// let path = window.location.href;
// const htmlUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${res.result}&redirect_uri=${encodeURIComponent(path)}&response_type=code&scope=snsapi_privateinfo&state=STATE#wechat_redirect`
// window.location.href = htmlUrl;
// })
// }
// render() {
// const { scanState,messageText} = this.state;
// return (
// <div className="work-authorize-page">
// <div className="box">
// { scanState === 'success' &&
// <div className="success">
// <img src="https://image.xiaomaiketang.com/xm/iRkcMHPHba.png" alt=""/>
// <p>
// 扫码成功
// </p>
// </div>
// }
// { scanState === 'error' &&
// <div className="error">
// <img src="https://image.xiaomaiketang.com/xm/6kSAYFMm2r.png
// " alt="" />
// <p className='message'>
// { messageText }
// </p>
// </div>
// }
// </div>
// </div>
// )
// }
// }
export default WorkWxAuthorize;
.work-authorize-page{
.box {
width: 100%;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: rgba(244, 246, 250, 1);
}
img{
width:60px;
}
p {
font-size: 17px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #333333;
line-height: 24px;
margin-top: 12px;
}
.hide {
display: none;
text-align: center;
}
}
......@@ -2,14 +2,14 @@
* @Author: 吴文洁
* @Date: 2020-04-29 10:26:32
* @LastEditors: zhangleyuan
* @LastEditTime: 2021-01-05 10:23:51
* @LastEditTime: 2021-03-31 16:31:55
* @Description: 内容线路由配置
*/
import { MenuConfig } from '@/routes/interface';
import Authorize from '@/modules/authorize';
import WorkWxAuthorize from '@/modules/workWxAuthorize';
const CloudClassConfig: MenuConfig = {
key: 'cloudClass',
name: '云课堂',
......@@ -19,7 +19,13 @@ const CloudClassConfig: MenuConfig = {
name: '授权登录',
path: '/wechat-authorize',
component: Authorize,
}
},
{
key: 'authorize',
name: '授权登录',
path: '/work-wechat-authorize',
component: WorkWxAuthorize,
},
]
};
export default CloudClassConfig;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment