feat: 端点登录

This commit is contained in:
caijun
2026-01-25 20:22:58 +08:00
parent f9e1a0cc18
commit f43f2ff3c2
12 changed files with 551 additions and 444 deletions

View File

@@ -17,7 +17,7 @@
</view>
<view class="logo-hd u-flex-col">
<view class="loginSwitch u-flex-col">
<view class="loginInputBox u-flex-col" v-show="!isSso && !ssoLoading">
<view class="loginInputBox u-flex-col" v-show=" true || !isSso && !ssoLoading">
<u-form :model="formData" :rules="rules" ref="dataForm" :errorType="['toast']" label-position="left"
label-width="150" label-align="left">
<u-form-item v-show="false" prop="account" :borderBottom="false">
@@ -49,9 +49,9 @@
<view class="remember-wrap">
<u-checkbox v-model="remember"><span class="remember-text">记住账号密码</span></u-checkbox>
</view>
<view class="remember-wrap">
<!-- <view class="remember-wrap">
<u-checkbox v-model="isCertify"><span class="remember-text">是否认证</span></u-checkbox>
</view>
</view> -->
<view class="loginBtnBox">
<u-button @click="login" type="primary" :loading="loading">{{ loading ? "登录中...":"登录"}}
</u-button>
@@ -130,7 +130,8 @@
getLoginConfig,
getSocialsUserList,
socialsLogin,
getTicket
getTicket,
socialAuthRedirect
} from '@/api/common.js'
import md5Libs from "@/uni_modules/vk-uview-ui/libs/function/md5";
import resources from '@/libs/resources'
@@ -171,7 +172,7 @@
},
sysConfigInfo: {},
appIcon: '',
sysName: '',
sysName: '综合监控系统',
copyright: '综合监控系统',
socialsList: [],
show: false,
@@ -183,7 +184,8 @@
preUrl: '',
ticketParams: "",
loginCode: '',
isKeyUp: true
isKeyUp: true,
ssoOptions: {} // 端点登录参数
}
},
watch: {
@@ -209,43 +211,59 @@
this.$refs.dataForm.setRules(this.rules);
},
onLoad(options) {
if (options?.JNPF_TICKET) {
this.ssoTicket = options.JNPF_TICKET
uni.navigateTo({
url: `/pages/login/otherLogin?ssoTicket=${this.ssoTicket}`
})
this.ssoOptions = options
if(options.code){
this.exchangeToken(options)
}else if(options.socialLogin){
this.getLogin()
}
this.ssoTicket = uni.getStorageSync('ssoTicket')
this.sysConfigInfo = uni.getStorageSync('sysConfigInfo')
console.log(this.define,'define-------------')
this.appIcon = !!this.sysConfigInfo.appIcon ? this.baseURL + this.sysConfigInfo.appIcon :
logoImg
this.sysName = !!this.sysConfigInfo.companyName ? this.sysConfigInfo.sysName :
'JNPF快速开发平台'
// this.copyright = !!this.sysConfigInfo.copyright ? this.sysConfigInfo.copyright :
// this.define.copyright
// this.copyright = !!this.sysConfigInfo.copyright && this.sysConfigInfo.copyright
else{
this.certifyLogin()
}
// if(JSON.stringify(options) == '{}'){
// // 端点登录
// this.certifyLogin()
// }else {
// this.getLogin()
// }
// if (options?.JNPF_TICKET) {
// this.ssoTicket = options.JNPF_TICKET
// uni.navigateTo({
// url: `/pages/login/otherLogin?ssoTicket=${this.ssoTicket}`
// })
// }
// this.ssoTicket = uni.getStorageSync('ssoTicket')
// this.sysConfigInfo = uni.getStorageSync('sysConfigInfo')
// console.log(this.define,'define-------------')
// this.appIcon = !!this.sysConfigInfo.appIcon ? this.baseURL + this.sysConfigInfo.appIcon :
// logoImg
// this.sysName = !!this.sysConfigInfo.companyName ? this.sysConfigInfo.sysName :
// '综合监控系统'
// // this.copyright = !!this.sysConfigInfo.copyright ? this.sysConfigInfo.copyright :
// // this.define.copyright
// // this.copyright = !!this.sysConfigInfo.copyright && this.sysConfigInfo.copyright
uni.setNavigationBarTitle({
title: this.sysName
})
let needCode = uni.getStorageSync('app_loginNeedCode')
this.isCode = needCode
this.changeCode()
// let needCode = uni.getStorageSync('app_loginNeedCode')
// this.isCode = needCode
// this.changeCode()
// this.getLoginConfig()
this.formData.password = '';
if (options.data) {
this.tenantUserInfo = JSON.parse(options.data)
// if (this.tenantUserInfo) this.show = true
}
this.initAccount()
// #ifndef H5
uni.onKeyboardHeightChange(res => {
this.isKeyUp = res.height == 0 ? true : false
return this.isKeyUp
})
// #endif
// this.formData.password = '';
// if (options.data) {
// this.tenantUserInfo = JSON.parse(options.data)
// // if (this.tenantUserInfo) this.show = true
// }
// this.initAccount()
// // #ifndef H5
// uni.onKeyboardHeightChange(res => {
// this.isKeyUp = res.height == 0 ? true : false
// return this.isKeyUp
// })
// // #endif
this.initLoginConfig()
// this.initLoginConfig()
},
methods: {
initAccount() {
@@ -499,30 +517,18 @@
this.imgUrl = `/api/oauth/ImageCode/${this.codeLength || 4}/${timestamp}`
},
login() {
this.$refs.dataForm.validate(valid => {
if (valid) {
this.loading = true
const password = md5Libs.md5(this.formData.password);
const encryptPassword = this.jnpf.aesEncryption.encrypt(password);
// let query = {
// account: this.formData.account,
// password: encryptPassword,
// timestamp: this.timestamp,
// code: this.formData.code,
// origin: this.formData.origin,
// jnpf_ticket: this.ssoTicket,
// grant_type: 'password',
// }
if(this.isCertify){
// 认证登录
this.certifyLogin()
}else {
if(this.ssoOptions.socialLogin){
this.$refs.dataForm.validate(valid => {
if (valid) {
this.loading = true
const password = md5Libs.md5(this.formData.password);
const encryptPassword = this.jnpf.aesEncryption.encrypt(password);
this.getLogin()
}
}
});
});
return
}
this.certifyLogin()
},
// 普通登录
getLogin(){
@@ -540,8 +546,9 @@
// query.Client_Id = uni.getStorageSync('cid')
// #endif
login(query).then(res => {
let token = res.data.accessToken
userStore.setToken(token)
const {accessToken,refreshToken} = res.data
userStore.setToken(accessToken)
userStore.setRefreshToken(refreshToken)
this.rememberAccount()
if(res.code == 0){
getPermissionInfo().then(res=>{
@@ -576,33 +583,24 @@
})
},
// 认证登录
certifyLogin(){
lx.biz.getAuthCode({
appId: "8889088-16130048", // AppID
success: (res) => {
console.log('免登授权码:', res.authCode)
this.exchangeToken(res.authCode)
},
fail: (err) => {
console.error('获取免登授权码失败:', err)
uni.showToast({
title: '免登失败,请重试',
icon: 'none'
})
this.loading = false
}
})
async certifyLogin(){
let type = '100'
let redirectUri = location.origin + '/pages/login/index?' + encodeURIComponent(`type=${type}&redirect=/`)
const res = await socialAuthRedirect(type,encodeURIComponent(redirectUri))
console.log(res,'res-------')
window.location.href = res.data
},
async exchangeToken(authCode) {
async exchangeToken(options) {
try {
const type = '110'
const code = authCode
const state = this.uuid()
const type = '100'
const code = '1222' || options?.code
const state = this.uuid() || options?.state
const res = await socialLogin(type, code, state)
const {accessToken,refreshToken} = res.data
const userStore = useUserStore()
// 存储Token和用户信息
userStore.setToken(res)
userStore.setToken(accessToken)
userStore.setRefreshToken(refreshToken)
uni.switchTab({
url: '/pages/index/indexWork'
});