Przeglądaj źródła

同步自动登录

zouling 1 rok temu
rodzic
commit
f06af152eb
4 zmienionych plików z 38 dodań i 9 usunięć
  1. 2 2
      config.js
  2. 1 0
      pages/login.vue
  3. 29 0
      store/modules/user.js
  4. 6 7
      utils/request.js

+ 2 - 2
config.js

@@ -1,8 +1,8 @@
 // 应用全局配置
 module.exports = {
-  baseUrl: 'https://vue.ruoyi.vip/prod-api',
+  // baseUrl: 'https://vue.ruoyi.vip/prod-api',
   // baseUrl: 'https://lyyy.qs163.cn/prod-api',
-  // baseUrl: 'http://192.168.101.168:8065',
+  baseUrl: 'http://192.168.101.168:8065',
   // baseUrl: 'http://192.168.101.11:8089',
   // baseUrlimg: 'http://114.99.127.243:2001',
   Clientid:'428a8310cd442757ae699df5d894f051',//

+ 1 - 0
pages/login.vue

@@ -185,6 +185,7 @@
 			  	var newObj={
 			  		username:that.loginForm.username,
 			  		password:base64.encode(that.loginForm.password),
+					captchaEnabled:that.captchaEnabled,
 			  	}	
 			  	uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
 			  }else{

+ 29 - 0
store/modules/user.js

@@ -13,6 +13,7 @@ const user = {
     avatar: storage.get(constant.avatar),
     roles: storage.get(constant.roles),
     permissions: storage.get(constant.permissions),
+	autologin:storage.get(constant.autologin),
 	wgtcode:storage.get(constant.wgtcode)
   },
 
@@ -36,6 +37,10 @@ const user = {
       state.permissions = permissions
       storage.set(constant.permissions, permissions)
     },
+	SET_AUTOLOGIN: (state, autologin) => {
+	  state.autologin = autologin
+	  storage.set(constant.autologin, autologin)
+	},
 	SET_WGTCODE: (state, wgtcode) => {
 	  state.wgtcode = wgtcode
 	  storage.set(constant.wgtcode, wgtcode)
@@ -53,12 +58,36 @@ const user = {
       const password = userInfo.password
       const code = userInfo.code
       const uuid = userInfo.uuid
+	  const strfrom = userInfo.strfrom||""
       return new Promise((resolve, reject) => {
         login(username, password, code, uuid).then(res => {
           setToken(res.token)
           commit('SET_TOKEN', res.token)
+		  commit('SET_AUTOLOGIN',true)
           resolve()
         }).catch(error => {
+			if(error==500&&strfrom=='request'){
+				uni.hideLoading()
+				// 清空数据
+				uni.showModal({
+				  title: '提示',
+				  content: '登录状态已过期,您可以继续留在该页面,或者重新登录?',
+				  cancelText: '取消',
+				  confirmText: '确定',
+				  success: function(res) { 
+				    if (res.confirm) {
+						commit('SET_TOKEN', '')
+						commit('SET_ROLES', [])
+						commit('SET_PERMISSIONS', [])
+						removeToken()
+						storage.clean()
+				      uni.reLaunch({ url: '/pages/login' })
+				    }else{
+						commit('SET_AUTOLOGIN',false)
+					}
+				  }
+				})
+			}
           reject(error)
         })
       })

+ 6 - 7
utils/request.js

@@ -5,7 +5,6 @@ import { getToken } from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
 import { toast, showConfirm, tansParams } from '@/utils/common'
 
-
 let timeout = 10000
 const baseUrl = config.baseUrl
 // const Clientid = config.Clientid
@@ -13,9 +12,11 @@ var confirmflag = config.confirmflag
 // 获取账号密码
 var newObj=JSON.parse(JSON.stringify(uni.getStorageSync('account')))
 var username=newObj.username;
-var password=base64.decode(newObj.password);
-var tenantId=newObj.tenantId;
-var companyName=newObj.companyName;
+var password=newObj.password;
+if(newObj){
+	password=base64.decode(newObj.password);	
+}
+var captchaEnabled=newObj.captchaEnabled;
 
 const request = config => {
   // 是否需要设置 token
@@ -61,13 +62,11 @@ const request = config => {
 			confirmflag = true;
 			setTimeout(function(){
 				var autologin=store.state.user.autologin;
-				if(username&&password&&tenantId&&companyName&&autologin){
+				if(username&&password&&!captchaEnabled&&autologin){
 					// 自动登录
 					var loginForm={
 						username:username,
 						password:password,
-						tenantId:tenantId,
-						companyName:companyName,
 						strfrom:'request'
 					}
 					store.dispatch('Logines', loginForm).then((res) => {