From 884d05a8ff870978254ea333d711686f7178ae83 Mon Sep 17 00:00:00 2001
From: BianLzhaoMin <11485688+bianliangzhaomin123@user.noreply.gitee.com>
Date: Wed, 5 Feb 2025 09:12:35 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/App.vue | 22 +++----
src/components/header/index.vue | 15 +++--
src/http/index.ts | 36 ++++++++++-
src/layout/header.vue | 106 +++++++++++++++++++++-----------
src/views/Login.vue | 38 +++++++++++-
src/views/home/index.vue | 35 ++++++++++-
6 files changed, 190 insertions(+), 62 deletions(-)
diff --git a/src/App.vue b/src/App.vue
index 9de85b6..d5611d0 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,20 +1,12 @@
diff --git a/src/components/header/index.vue b/src/components/header/index.vue
index 586ea97..18d94b0 100644
--- a/src/components/header/index.vue
+++ b/src/components/header/index.vue
@@ -55,7 +55,7 @@ const handlerLogout = () => {
type: 'warning',
})
.then(() => {
- router.push('/login')
+ // router.push('/login')
store.cleanUpToken('')
store.clearUserInfo('')
localStorage.clear()
@@ -65,6 +65,12 @@ const handlerLogout = () => {
message: '已退出登录',
duration: 1000,
})
+
+ setTimeout(() => {
+ window.location.replace(
+ 'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
+ )
+ }, 500)
})
.catch(() => {
ElMessage({
@@ -287,7 +293,7 @@ onMounted(() => {
-->
diff --git a/src/http/index.ts b/src/http/index.ts
index d133aee..7401883 100644
--- a/src/http/index.ts
+++ b/src/http/index.ts
@@ -15,6 +15,7 @@ const VITE_token = import.meta.env.VITE_token
const VITE_LocalFlag = import.meta.env.VITE_LocalFlag
const VITE_ENV = import.meta.env.VITE_ENV
+const iwsData: any = sessionStorage.getItem('data') || null
const service = axios.create({
baseURL: baseUrl,
@@ -40,10 +41,17 @@ service.interceptors.response.use(
return data
} else if (data.code == '403') {
ElMessage.error('请重新登录')
- router.push('/login')
+ setTimeout(() => {
+ window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
+ }, 500)
+ // router.push('/login')
+
} else if (data.code == '401') {
- ElMessage.error(data.msg)
- router.push('/login')
+ ElMessage.error('请登录')
+ // router.push('/login')
+ setTimeout(() => {
+ window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
+ }, 500)
} else if (data.code == '500') {
ElMessage({
type: 'error',
@@ -62,6 +70,16 @@ service.interceptors.response.use(
)
export function get(url: string, params: any) {
+ if (iwsData) {
+ service.get(`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`).then((res: any) => {
+ console.log(res, '请求结果')
+ if (res.code != 200) {
+ window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
+ }
+
+ return false
+ })
+ }
return new Promise((resolve, reject) => {
// NProgress.start()
service
@@ -81,6 +99,18 @@ export function get(url: string, params: any) {
})
}
export function post(url: string, params: any) {
+ if (iwsData) {
+ service.get(`http://sgwpdm.ah.sgcc.com.cn/iws/cas/api/validate/sk?sessionKey=${iwsData.sessionKey}`).then((res: any) => {
+ console.log(res, '请求结果')
+
+ if (res.code != 200) {
+ window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
+ }
+
+
+ return false
+ })
+ }
return new Promise((resolve, reject) => {
// NProgress.start()
service
diff --git a/src/layout/header.vue b/src/layout/header.vue
index 525b676..c401750 100644
--- a/src/layout/header.vue
+++ b/src/layout/header.vue
@@ -4,7 +4,7 @@ import { mainStore } from 'store/main'
import { useStore } from 'store/user'
import { cartStore } from 'store/cart'
import { ElMessage, ElMessageBox } from 'element-plus'
-import { getHotSearchListApi, getBookCarDetailsApi } from 'http/api/home/index'
+import { getHotSearchListApi, getBookCarDetailsApi, getCompanyListApi } from 'http/api/home/index'
import userClass from '../hooks/userClass'
import {
getUserInfo, //用户信息
@@ -30,6 +30,8 @@ const isAdmin = ref(false)
const roles = store.userInfo.roles
const activeLoginCompanyName = ref('')
const searchCheckVisible = ref(false)
+import { storeToRefs } from 'pinia'
+const { userInfo, token }: any = storeToRefs(store)
if (roles?.length > 0) {
isAdmin.value = roles.some((e: any) => e.roleKey == 'admin')
}
@@ -39,22 +41,37 @@ const isShowLogout = computed(() => {
return store.token
})
+watch(userInfo, (newValue, oldCount) => {
+ if (newValue.companyId) {
+ getCompanyListApi().then((res: any) => {
+ res.data.filter((e: any) => {
+ if (e.companyId == newValue.companyId) {
+ activeLoginCompanyName.value = e.companyName
+ }
+ })
+ })
+ }
+})
+watch(token, (newValue, oldCount) => {
+ if (newValue) {
+ getUserListData()
+ getBookCarDetailsData()
+ }
+})
+
const setActiveCompanyName = () => {
- const companyList = userStore.companyList
- const activeCompany: any = companyList.filter(
- (e: any) => e.companyId == store.userInfo.companyId,
- )
- activeLoginCompanyName.value = activeCompany[0]?.companyName
- localStorage.setItem('currentCompanyName', activeLoginCompanyName.value)
+ // const companyList = userStore.companyList
+ // const activeCompany: any = companyList.filter(
+ // (e: any) => e.companyId == store.userInfo.companyId,
+ // )
+ // activeLoginCompanyName.value = activeCompany[0]?.companyName
+ // localStorage.setItem('currentCompanyName', activeLoginCompanyName.value)
}
-if (userStore.companyList.length === 0) {
- getCompanyList().then((res) => {
- setActiveCompanyName()
- })
-} else {
- setActiveCompanyName()
-}
+// if (userStore.companyList.length === 0) {
+// } else {
+// setActiveCompanyName()
+// }
const placeholderText = ref('搜索设备关键词')
@@ -66,7 +83,7 @@ const handlerLogout = () => {
type: 'warning',
})
.then(() => {
- router.push('/login')
+ // router.push('/login')
store.cleanUpToken('')
store.clearUserInfo('')
localStorage.clear()
@@ -75,6 +92,9 @@ const handlerLogout = () => {
type: 'success',
message: '已退出登录',
})
+ setTimeout(() => {
+ window.location.replace('http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/')
+ }, 500)
})
.catch(() => {
ElMessage({
@@ -226,7 +246,6 @@ const getBookCarDetailsData = async () => {
})
cart.SET_CART_NUM(amountNum)
}
-getBookCarDetailsData()
const cartNum = computed(() => {
return cart.cartNum
@@ -245,6 +264,10 @@ const onCarts = () => {
})
}
+const nickNameNew = computed(() => {
+ return store.userInfo.nickName
+})
+
const onJumpUser = () => {
const isType: any = localStorage.getItem('rolesType')
if (isType == 3) {
@@ -275,6 +298,12 @@ const onJumpUser = () => {
// }
}
+const onClickLogin = () => {
+ window.location.replace(
+ 'http://sgwpdm.ah.sgcc.com.cn/iws/cas/login?appId=3874dcb953f184dc75450e33d6d6d4fa&service=http://sgwpdm.ah.sgcc.com.cn/iws/mall-view/',
+ )
+}
+
// 查看消息
const onJumpMessage = () => {
router.push({
@@ -292,12 +321,16 @@ const form: any = ref({
deptId: '',
})
const dialogUserInfoVisible = ref(false)
-const circleUrl = ref('https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg')
+// const circleUrl = ref('https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg')
+
+const circleUrl = computed(() => {
+ return store.userInfo.avatar
+})
const onAccountManage = () => {
dialogUserInfoVisible.value = true
}
const getUserListData = async () => {
- let res = await getUserInfo()
+ let res: any = await getUserInfo()
form.value = res.data
}
@@ -335,10 +368,9 @@ const resetPhone = async () => {
})
}
-onMounted(() => {
- getUserListData()
- circleUrl.value = store.userInfo.avatar
-})
+// onMounted(() => {
+// circleUrl.value = store.userInfo.avatar
+// })
@@ -348,18 +380,16 @@ onMounted(() => {