keqiaoling před 1 měsícem
rodič
revize
fba283d453
6 změnil soubory, kde provedl 119 přidání a 78 odebrání
  1. 2 2
      config.js
  2. 14 9
      pages/loginSso.vue
  3. 1 1
      pages/trade/shoe-style/ShoeStyleView.vue
  4. 3 1
      utils/auth.js
  5. 2 0
      utils/permission.js
  6. 97 65
      utils/request.js

+ 2 - 2
config.js

@@ -1,7 +1,7 @@
 // 应用全局配置
 module.exports = {
 	// baseUrl: 'https://vue.ruoyi.vip/prod-api',
-	// baseUrl: 'https://tools-server.huaxiazhizao.com',
+	baseUrl: 'https://tools-server.huaxiazhizao.com',
 	devServer: {
 		disableHostCheck: true,
 		// historyApiFallback: true,
@@ -9,7 +9,7 @@ module.exports = {
 	},
  // 单点登录
 	VITE_SSO_LOGIN:true,
-	baseUrl: 'http://localhost:8083',
+	// baseUrl: 'http://localhost:8083',
 	// if (window.location.host.indexOf('localhost') > -1) {
 		// baseUrl: 'http://localhost:8083',
 	// }else {

+ 14 - 9
pages/loginSso.vue

@@ -27,11 +27,11 @@
 		data() {
 			return {
 				codeUrl: '',
-				ssoCode: ''
+				ssoCode: '',
 			}
 		},
 		onLoad(query) {
-			if(!isLoginSso){
+			if (!isLoginSso) {
 				uni.redirectTo({
 					url: '/pages/login'
 				})
@@ -40,6 +40,8 @@
 			// console.log(query, 3333)
 			this.ssoCode = query.ssoCode
 			setSsoAdminToken(this.ssoCode);
+
+			// console.log(getSsoAdminToken(), 'getSsoAdminToken')
 			this.loginSso()
 		},
 		methods: {
@@ -74,23 +76,26 @@
 				if (!this.ssoCode) {
 					if (!localStorage.getItem('ssoLogout')) {
 						localStorage.removeItem('ssoLogout');
-						setEnv();
+						// setEnv();
 					};
 					ssoLogout();
 					openWindowSso();
 					return;
 				};
+
 				// 请求头
 
 				getOpenToken().then(res => {
 					removeEnv()
 					setToken(res.data)
-					var options = uni.getStorageSync('options')
-					if (options) {
-						this.$tab.reLaunch('/pages/trade/shoe-style/ShoeStyleView')
-					} else { //如果没有上一页返回首页
-						this.$tab.reLaunch('/pages/trade/shoe-style/index')
-					}
+					this.$store.dispatch('GetInfo').then(res => {
+						var options = uni.getStorageSync('options')
+						if (options) {
+							this.$tab.reLaunch('/pages/trade/shoe-style/ShoeStyleView')
+						} else { //如果没有上一页返回首页
+							this.$tab.reLaunch('/pages/trade/shoe-style/index')
+						}
+					})
 				}).catch(err => {
 					console.log('获取token失效');
 					removeEnv();

+ 1 - 1
pages/trade/shoe-style/ShoeStyleView.vue

@@ -58,7 +58,7 @@
 		</uni-list>
 		<view style="height: 30rpx;"></view>
 
-		<uni-list  v-if="checkRole(['admin','SalesManager'])">
+		<uni-list  v-if="checkRole(['SalesManager'])">
 			<uni-list-item class="outPrice" title="大底价格参考" :rightText="data.outsolePrice" />
 			<uni-list-item class="outPrice" title="材料价格参考" :rightText="data.referPrice" />
 		</uni-list>

+ 3 - 1
utils/auth.js

@@ -36,7 +36,7 @@ export function removeSsoAdminToken() {
 const VITE_APP_ENV = 'beta'
 function getEnv() {
     // let jumpEnv = 'http://localhost:88';
-    // let curEnv = 'http://localhost:80/pages';
+    // let curEnv = 'http://localhost:81/pages';
     // let suffix = 'localhost';
     // if (VITE_APP_ENV == 'production') {
     //     // 生产环境
@@ -66,6 +66,7 @@ export function getOpenToken() {
     });
 };
 export function ssoLogout() {
+	removeEnv();
     document.cookie = "ssoLogout=true;path=/;domain=" + getEnv().suffix;
 };
 // 打开单点登录页面
@@ -74,6 +75,7 @@ export function openWindowSso() {
     removeSsoAdminToken();
     // 清除Token
     removeToken();
+	setEnv();
     // 登录失效跳转到单点登录页面
     window.open(getEnv().jumpEnv, '_self');
 };

+ 2 - 0
utils/permission.js

@@ -31,8 +31,10 @@ export function checkPermi(value) {
  * @returns {Boolean}
  */
 export function checkRole(value) {
+	console.log(value,value.length,'valuevaluevalue')
   if (value && value instanceof Array && value.length > 0) {
     const roles = store.getters && store.getters.roles
+	console.log(roles,'rolesrolesrolesroles')
     const permissionRoles = value
     const super_admin = "admin"
 

+ 97 - 65
utils/request.js

@@ -1,74 +1,106 @@
 import store from '@/store'
 import config from '@/config'
-import { getToken } from '@/utils/auth'
+import {
+	getToken,
+	getSsoAdminToken
+} from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
-import { toast, showConfirm, tansParams } from '@/utils/common'
+import {
+	toast,
+	showConfirm,
+	tansParams
+} from '@/utils/common'
 
+const ssoToken = getSsoAdminToken()
 let timeout = 10000
 const baseUrl = config.baseUrl
-
 const request = config => {
-  // 是否需要设置 token
-  const isToken = (config.headers || {}).isToken === false
-  config.header = config.header || {}
-    console.log(getToken(),isToken,'9999')
-  if (getToken() && !isToken) {
-    config.header['Authorization'] = 'Bearer ' + getToken()
-  }
-  // get请求映射params参数
-  if (config.params) {
-    let url = config.url + '?' + tansParams(config.params)
-    url = url.slice(0, -1)
-    config.url = url
-  }
-  return new Promise((resolve, reject) => {
-    uni.request({
-        method: config.method || 'get',
-        timeout: config.timeout ||  timeout,
-        url: config.baseUrl || baseUrl + config.url,
-        data: config.data,
-        header: config.header,
-        dataType: 'json'
-      }).then(response => {
-        let [error, res] = response
-        if (error) {
-          toast('后端接口连接异常')
-          reject('后端接口连接异常')
-          return
-        }
-        const code = res.data.code || 200
-        const msg = errorCode[code] || res.data.msg || errorCode['default']
-        if (code === 401) {
-          showConfirm('登录状态已过期,请重新登录!').then(res => {
-            if (res.confirm) {
-              store.dispatch('LogOut').then(res => {
-                uni.reLaunch({ url: '/pages/login' })
-              })
-            }
-          })
-          reject('无效的会话,或者会话已过期,请重新登录。')
-        } else if (code === 500) {
-          toast(msg)
-          reject('500')
-        } else if (code !== 200) {
-          toast(msg)
-          reject(code)
-        }
-        resolve(res.data)
-      })
-      .catch(error => {
-        let { message } = error
-        if (message === 'Network Error') {
-          message = '后端接口连接异常'
-        } else if (message.includes('timeout')) {
-          message = '系统接口请求超时'
-        } else if (message.includes('Request failed with status code')) {
-          message = '系统接口' + message.substr(message.length - 3) + '异常'
-        }
-        toast(message)
-        reject(error)
-      })
-  })
+	// 是否需要设置 token
+	const isToken = (config.headers || {}).isToken === false
+	config.header = config.header || {}
+	if (getToken() && !isToken) {
+		config.header['Authorization'] = 'Bearer ' + getToken()
+	}
+	// 存在ssoToken
+	// console.log(ssoToken,getSsoAdminToken(),'ssoTokenrequest')
+	if (getSsoAdminToken()) {
+		config.header['xxl_sso_sessionid'] = getSsoAdminToken() // 让每个请求携带自定义ssoToken 请根据实际情况自行修改
+	}
+	// get请求映射params参数
+	if (config.params) {
+		let url = config.url + '?' + tansParams(config.params)
+		url = url.slice(0, -1)
+		config.url = url
+	}
+	return new Promise((resolve, reject) => {
+		uni.request({
+				method: config.method || 'get',
+				timeout: config.timeout || timeout,
+				url: config.baseUrl || baseUrl + config.url,
+				data: config.data,
+				header: config.header,
+				dataType: 'json'
+			}).then(response => {
+				let [error, res] = response
+				if (error) {
+					console.log(error,config.baseUrl || baseUrl + config.url,'error')
+					toast('后端接口连接异常')
+					reject('后端接口连接异常')
+					return
+				}
+				const code = res.data.code || 200
+				const msg = errorCode[code] || res.data.msg || errorCode['default']
+				if (code === 401) {
+					showConfirm('登录状态已过期,请重新登录!').then(res => {
+						if (res.confirm) {
+							store.dispatch('LogOut').then(res => {
+								uni.reLaunch({
+									url: '/pages/login'
+								})
+							})
+						}
+					})
+					reject('无效的会话,或者会话已过期,请重新登录。')
+				} else if (code === 500) {
+					toast(msg)
+					reject('500')
+				} else if (code === 501) {
+					if (msg.indexOf('sso not login') > -1) {
+						showConfirm('单点秘钥不存在,请重新登录!').then(res => {
+							if (res.confirm) {
+								store.dispatch('LogOut').then(res => {
+									uni.reLaunch({
+										url: '/pages/login'
+									})
+								})
+							}
+						})
+						reject('无效的会话,或者会话已过期,请重新登录。')
+					} else {
+						toast(msg)
+						reject('501')
+					}
+				} else if (code !== 200) {
+					toast(msg)
+					reject(code)
+				}
+				resolve(res.data)
+			})
+			.catch(error => {
+				let {
+					message
+				} = error
+				if (message === 'Network Error') {
+					message = '后端接口连接异常'
+				} else if (message.includes('timeout')) {
+					message = '系统接口请求超时'
+				} else if (message.includes('Request failed with status code')) {
+					message = '系统接口' + message.substr(message.length - 3) + '异常'
+				}
+				toast(message)
+				reject(error)
+			})
+	})
 }
 
-export default request
+export default request