Files
mgm-daylight-mcrm-mobile-ios/pages/login/login.vue
T
2026-09-08 17:20:27 +08:00

409 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view>
<view class="hz-text-center" style="padding-top:200rpx;">
<image src="../../static/images/logo.png" style="width:138rpx;height:140rpx;"></image>
</view>
<view class="hz-font-bolder hz-font-xl hz-text-center hz-font-color-primary">
{{$t('common.appName')}}
</view>
<view class="hz-font-bolder hz-font-xl hz-text-center hz-font-color-dark" style="margin-top:160rpx;">
{{$t('common.userLogin')}}
</view>
<view style="margin-top:30rpx;margin-right:60rpx;margin-left:60rpx;">
<view @click="goLogin" class="hz-btn hz-font-color-white hz-font-lg hz-font-bold hz-text-center" >{{$t("common.loginsso")}}</view>
<button type="primary" v-show="false" @click="checkVPNOpen">testVPNFunc</button>
<button type="primary" v-show="false" @click="checkInMacau">testLocationFunc</button>
<button type="primary" v-show="false" @click="testCfgDecrypt">testCfgDecrypt</button>
</view>
<view class="hz-font-sm hz-text-center" style="margin-top:30rpx;color:#999;">
<u-row>
<u-col span="6" customStyle="text-align:center;">
{{siteData.version}}
</u-col>
<u-col span="6" customStyle="text-align:center;">
<view v-if="showConnected" style="display:flex;flex-direction:row;align-items: center;justify-content:center;">
<view style="width:6px;height:6px;background-color: #009933;border-radius: 50%;"></view>
<view style="margin-left:3px;">{{$t('common.connected')}}</view>
</view>
<view v-if="!showConnected" style="display:flex;flex-direction:row;align-items: center;justify-content:center;">
<view style="width:6px;height:6px;background-color: #ff0000;border-radius: 50%;"></view>
<view style="margin-left:3px;">{{$t('common.disconnected')}}</view>
</view>
</u-col>
</u-row>
</view>
<!--<view style="margin-top:30rpx;margin-right:60rpx;margin-left:60rpx;">
<view @click="logout" class="hz-btn hz-font-color-white hz-font-lg hz-font-bold hz-text-center" >testlogout</view>
</view>-->
<!-- <u-modal :show="showCommitment" :customStyle="{height:contentHeight + 'px;overflow:auto;'}" :confirmText="confirmText" :showCancelButton="false" closeOnClickOverlay @confirm="checkInMacau" confirmColor="#C39A4B" @close="showCommitment=false">
<scroll-view scroll-y style="max-height: 400rpx; margin: 20rpx 0;">
<view class="hz-font-lg commit-content">{{commitmentText1 }}<p style="margin-top:20px;">{{commitmentText2}}</p></view>
</scroll-view>
</u-modal> -->
<view style="width: 100%;">
<u-popup :show="showCommitment" :round="10" mode="center" customStyle="margin:0rpx 40rpx;">
<view style="padding: 20px 22px 32px 22px;">
<h4 style="font-size: 18px; display: flex; justify-content: center; padding: 7px;">{{commitTitle}}</h4>
<view style="height:490px;font-size:13px;color:#333;">
<view style="margin-bottom: 24rpx;line-height: 1.7;">{{commitmentText1}}</view>
<view >{{commitmentText2}}</view>
</view>
<view >
<view @click="handleConfirm()" class="hz-btn hz-font-color-white hz-font-lg hz-font-bold hz-text-center" >{{confirmText}}</view>
</view>
</view>
</u-popup>
</view>
</view>
</template>
<script>
import {getSettings} from '../../api/commonApi.js'
import {getSSOTokenByCode,userSSOlogin,userOpenIdlogin} from '../../api/ssoApi.js'
import { userConfirm } from '../../api/todoApi.js';
import { getCfgSettingByKey } from '../../api/configApi.js';
import config from '../../common/config.js';
import { decryptCfgSettingValue } from '../../common/cfgSettingCrypto.js';
import dayjs from '../../uni_modules/uview-ui/libs/util/dayjs.js';
export default {
data() {
return {
// 数据变量
playerIdStr: this.$t("common.playerId"),
searchPlayerId: '',
userData:null,
deviceData:null,
siteData:null,
// 界面变量
title: '',
userName:'',
code:'',
commitTitle:this.$t("region.commitTitle"),
commitmentText1:this.$t("region.commitment1"),
commitmentText2:this.$t("region.commitment2"),
confirmText:this.$t("common.confirm"),
showConnected:false,
showCommitment:false,
contentHeight:600,
}
},
async onLoad(opt) {
await this.$onLaunched; // 必须等App.vue中的initCfg执行完才执行onload
// 初始化界面
//uni.setLocale("en") //測試切換語言en or zh-Hant
await this.initUI();
this.siteData = uni.getStorageSync("siteData");
if(opt!=undefined && opt!=null && opt.code!=undefined && opt.code!=''){
this.code = opt.code;
this.goLogin();
}else{
this.code = '';
}
await this.getSetting();
uni.onNetworkStatusChange(res => {
console.log("是否联网:", res.isConnected);
console.log("网络类型:", res.networkType);
this.getSetting();
});
},
onShow() {
this.siteData = uni.getStorageSync("siteData");
var userData = uni.getStorageSync("userData");
if(userData==undefined || userData==null || userData==""){
this.code='';
}
/*let idToken = uni.getStorageSync("idToken");
console.log("onshow idToken="+idToken);*/
},
methods: {
/** 调试:拉取配置并 GCM 解密 keyValues,结果见控制台(需把按钮 v-show 改为 true 或在控制台调用) */
async testCfgDecrypt(){
try{
console.log('[testCfgDecrypt] crypto.subtle:', !!(globalThis.crypto && globalThis.crypto.subtle));
const params = { keyName: 'MACAU_IP' };
const res = await getCfgSettingByKey(params);
const cfg = new config();
const cipher = res && res.data ? res.data.keyValues : '';
const plain = await decryptCfgSettingValue(cipher, cfg.allowKey);
console.log('[testCfgDecrypt] cipher:', cipher);
console.log('[testCfgDecrypt] plain:', plain);
}catch(e){
console.error('[testCfgDecrypt]', e);
}
},
async handleConfirm(){
const userData = uni.getStorageSync("userData");
const params = {
userId : userData.userId,
userName : userData.userName
};
const res = await userConfirm(params);
this.checkInMacau();
},
checkInMacau(){
this.showCommitment = false;
//用户commit之后 将userData传到后端写log
// #ifdef APP-PLUS
let siteData = uni.getStorageSync("siteData");
if(siteData.internalTag===true){
let userData= uni.getStorageSync("userData");
this.redirectByPermission(userData,true);
}
//只有外网才检查
if(siteData!==undefined && siteData!==null && siteData.internalTag===false)
{
this.checkLocationAndVPN(false);
}
// #endif
// #ifdef H5
let userData= uni.getStorageSync("userData");
this.redirectByPermission(userData,true);
// #endif
},
// 数据方法
async getSetting(){
uni.showLoading({
title: this.$t("common.loading")
});
let that = this;
// 获取是否mockSSO配置
await getSettings({}).then((res) => {
try{
if(res!=null && res.success == true){
if(res.data!=null){
const settings = res.data;
//console.log('SETTING');
//console.log(settings);
for(let i=0;i<settings.length;i++){
const setting = settings[i];
if(setting.settingKey == 'APP_MOCK_SSO'){
if(setting.settingValue == "1")
that.siteData.mockSSO = true;
else
that.siteData.mockSSO = false;
if(setting.internalNetwork == true)
that.siteData.internalTag = true;
else
that.siteData.internalTag = false;
}
else if(setting.settingKey == 'APP_MOCK_TPD'){
if(setting.settingValue == "1")
that.siteData.mockTPD = true;
else
that.siteData.mockTPD = false;
}
}
//that.siteData.mockSSO = true;
//that.siteData.internalTag = true;
that.showConnected = true;
}else{
that.showConnected = false;
}
uni.setStorageSync('siteData', that.siteData);
that.$isResolve();
}else{
that.showConnected = false;
}
}catch(e){
console.error(e);
uni.$u.toast(e.errMsg,5000);
that.writeLog("","login","","[APP][login.vue][getSetting][Parse Exception]"+e.errMsg,"","",1,false);
uni.hideLoading();
}
finally{
uni.hideLoading();
}
})
.catch(error => {
console.log(error)
if(error.errMsg.indexOf('-1')>0){
that.showConnected = false;
}
uni.$u.toast(error.errMsg,5000);
var request = error.config!=undefined?JSON.stringify(error.config):"";
var response = error.data!=undefined?JSON.stringify(error.data):"";
that.writeLog("","login","","[APP][login.vue][getSetting][Catch Exception]"+error.errMsg,request,response,1,false);
uni.hideLoading();
});
},
logout(){
uni.redirectTo({
url:'/pages/azureLogout/azureLogout'
//url:'/pages/adfs/adfs'
});
},
async getTokenByCodeMock(code){
uni.showLoading({
title: this.$t("common.loading")
});
try{
let params = {
code:code,
mockSSO:this.siteData.mockSSO,
};
let that = this;
const res = await getSSOTokenByCode(params);
if(res.success === true){
if(res !== null){
uni.setStorageSync("token",res.accessToken);
uni.setStorageSync("userData",res.userData);
uni.setStorageSync("clientId",res.clientId);
uni.setStorageSync("timeOut",dayjs().add(30,'day').unix());
uni.setStorageSync("tokenTime",dayjs().unix());
uni.setStorageSync("refreshToken",res.refreshToken);
// uni.setStorageSync("timeOut",dayjs().add(1,'day').unix());//For test
// uni.setStorageSync("timeOut",dayjs().add(30, 'minutes').unix());
//this.navTo('/pages/dashboard/dashboard',1,false);
// that.redirectByPermission(res.data.userData,true);
that.showCommitment = true;
}else{
uni.$u.toast(res.message,5000);
this.writeLog("","getTokenByCodeMock","","[APP][login.vue][getTokenByCodeMock]data is null;"+res.message,"","",1,false);
}
}else{
uni.$u.toast(res.message,5000);
this.writeLog("","getTokenByCodeMock","","[APP][login.vue][getTokenByCodeMock]return false;"+res.message,"","",1,false);
}
}catch(e){
// write exception log
console.error(e);
uni.$u.toast(e.errMsg,5000);
this.writeLog("","getTokenByCodeMock","","[APP][login.vue][getTokenByCodeMock][Catch Exception]"+e.errMsg,"","",1,false);
}finally{
uni.hideLoading();
}
},
async getTokenByCode(code){
uni.showLoading({
title: this.$t("common.loading")
});
try{
code = code.replaceAll(" ", "+");
let params = {};
params = {
SAMLResponse:code,
};
let that = this;
const res = await userSSOlogin(params);
if(res.success === true){
if(res !== null){
uni.setStorageSync("idToken",res.idToken);
uni.setStorageSync("token",res.token);
uni.setStorageSync("userData",res.userData);
uni.setStorageSync("clientId",res.clientId);
uni.setStorageSync("timeOut",dayjs().add(30,'day').unix());
uni.setStorageSync("tokenTime",dayjs().unix());
uni.setStorageSync("refreshToken",res.refreshToken);
that.showCommitment = true;
// uni.setStorageSync("timeOut",dayjs().add(30, 'minutes').unix());
// uni.setStorageSync("timeOut",dayjs().add(1,'day').unix());//For test
//根据权限进行页面跳转
//that.redirectByPermission(res.data.userData,true);
//this.navTo('/pages/dashboard/dashboard',1,false);
}else{
// write log正常不会没有返回
uni.$u.toast(res.message+" No response data.",5000);
}
}else{
// write error log
uni.$u.toast(res.message +" Server return false.",5000);
}
}catch(e){
// write exception log
console.error(e);
uni.$u.toast(e.errMsg,5000);
this.writeLog("","getTokenByCode","","[APP][login.vue][getTokenByCode][Catch Exception]"+e.errMsg,code,"",1,false);
}finally{
uni.hideLoading();
}
},
// 界面方法
async goLogin(){
await this.$onLaunched;
await this.getSetting();
const userData = uni.getStorageSync("userData");
let loginTag = false;
uni.setStorageSync("todoSwitch","true");
if(userData!==undefined && userData!==null && userData!==''){
loginTag = userData.loginTag;
}
//uni.$u.toast("LoginTag="+loginTag + ";mockSSO="+this.siteData.mockSSO);
if(loginTag===true){
this.redirectByPermission(userData);
}
// 模拟开启,没有code,默认进来的情况
if(this.siteData.mockSSO==true && this.code=='' && loginTag===false){
// 模拟SSO
uni.redirectTo({
url:'/pages/ssoLogin/ssoLogin'
})
}
// 模拟开启,有code,SSO返回code的情况
else if(this.siteData.mockSSO==true && this.code!==''){
this.getTokenByCodeMock(this.code);
}
// 真实SSO环境,没有code,默认进来的情况
else if(this.siteData.mockSSO==false && this.code=='' && loginTag===false)
{
if(this.siteData.internalTag==true)
{
console.log('INTERNAL LOGIN');
uni.redirectTo({
url:'/pages/idpLogin/idpLogin'
});
}
else
{
console.log('AZURE LOGIN');
uni.redirectTo({
url:'/pages/azureLogin/azureLogin'
});
}
}
// 真实SSO环境,有code,SSO返回code的情况
else if(this.siteData.mockSSO==false && this.code!=='')
{
this.getTokenByCode(this.code);
}
},
clearSearchInput(){
this.searchPlayerId = '';
uni.removeStorageSync("playerData");
},
initUI() {
this.deviceData = uni.getStorageSync("deviceData");
this.contentHeight = this.deviceData.windowHeight - 60;
},
},
}
</script>
<style>
.commit-content{
line-height: 1.5; /* 增加行间距提升可读性 */
color: #333; /* 深灰提升阅读舒适度 */
max-height: 500px;
overflow-y: auto!important;
}
.custom-scrollbar::-webkit-scrollbar {
width: 6px;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: #c1c1c1;
border-radius: 3px;
}
</style>