代码优化
This commit is contained in:
parent
01cdc5581c
commit
884d05a8ff
22
src/App.vue
22
src/App.vue
|
|
@ -1,20 +1,12 @@
|
|||
<script setup lang="ts">
|
||||
import { loginNewApi } from 'http/api/home/index'
|
||||
|
||||
onMounted(async () => {
|
||||
const origin = window.location.href
|
||||
|
||||
console.log(origin.split('ticket=')[1], 'origin')
|
||||
|
||||
if (origin.indexOf('ticket') != -1) {
|
||||
// console.log('origin.split爱玩送ticket')
|
||||
const res = await loginNewApi({
|
||||
ticket: origin.split('ticket=')[1].split('#/')[0],
|
||||
sysType: 0,
|
||||
})
|
||||
console.log(res, '登录结果')
|
||||
}
|
||||
})
|
||||
import { getUserInfoAPI } from 'http/api/login/index'
|
||||
import { mainStore } from 'store/main'
|
||||
import { useStore } from 'store/user'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
const userStore = mainStore()
|
||||
const store = useStore()
|
||||
const router = useRouter()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
|||
<div class="line"></div>
|
||||
</div> -->
|
||||
<div class="header-item">
|
||||
<a
|
||||
<!-- <a
|
||||
v-if="!isShowLogout"
|
||||
class="a-border-none"
|
||||
@click="$router.push('/login')"
|
||||
|
|
@ -298,9 +304,10 @@ onMounted(() => {
|
|||
v-if="!isShowLogout"
|
||||
style="padding: 0 20px 0 0"
|
||||
@click="$router.push('/register')"
|
||||
>注册</a
|
||||
>
|
||||
<a v-else @click="handlerLogout">退出登录</a>
|
||||
注册
|
||||
</a> -->
|
||||
<a @click="handlerLogout">退出登录</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
// })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -348,18 +380,16 @@ onMounted(() => {
|
|||
<div class="header-box">
|
||||
<div class="header-item" v-if="isShowLogout">
|
||||
<a class="user-name">
|
||||
<span class="name">
|
||||
{{ activeLoginCompanyName }} / {{ store.userInfo.nickName }}
|
||||
</span>
|
||||
<span class="name"> {{ activeLoginCompanyName }} / {{ nickNameNew }} </span>
|
||||
<el-icon style="margin-left: 4px">
|
||||
<ArrowDown />
|
||||
</el-icon>
|
||||
|
||||
<div class="user-center">
|
||||
<div style="text-align: right">
|
||||
<el-button size="small" @click="onAccountManage"
|
||||
>账号管理</el-button
|
||||
>
|
||||
<el-button size="small" @click="onAccountManage">
|
||||
账号管理
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="user-container">
|
||||
<el-avatar :size="50" :src="circleUrl" />
|
||||
|
|
@ -373,25 +403,27 @@ onMounted(() => {
|
|||
<div class="line"></div>
|
||||
</div>
|
||||
|
||||
<div class="header-item">
|
||||
<div class="header-item" v-if="isShowLogout">
|
||||
<a @click="onJumpMessage">消息</a>
|
||||
<div class="line"></div>
|
||||
</div>
|
||||
<div class="header-item">
|
||||
<div class="header-item" v-if="isShowLogout">
|
||||
<a @click="onJumpUser">个人中心</a>
|
||||
<div class="line"></div>
|
||||
</div>
|
||||
<div class="header-item">
|
||||
<a v-if="!isShowLogout" class="a-border-none" @click="$router.push('/login')"
|
||||
>登录</a
|
||||
>
|
||||
<span v-if="!isShowLogout" style="margin: 0 3px">/</span>
|
||||
<!-- <a v-if="!isShowLogout" class="a-border-none" @click="$router.push('/login')">
|
||||
登录
|
||||
</a> -->
|
||||
<a v-if="!isShowLogout" @click="onClickLogin"> 登录 </a>
|
||||
<!-- <span v-if="!isShowLogout" style="margin: 0 3px">/</span>
|
||||
<a
|
||||
v-if="!isShowLogout"
|
||||
style="padding: 0 20px 0 0"
|
||||
@click="$router.push('/register')"
|
||||
>注册</a
|
||||
>
|
||||
注册
|
||||
</a> -->
|
||||
<a v-else @click="handlerLogout">退出登录</a>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -464,10 +496,10 @@ onMounted(() => {
|
|||
</div>
|
||||
</div>
|
||||
<el-dialog
|
||||
v-model="dialogUserInfoVisible"
|
||||
title="账户管理"
|
||||
width="50%"
|
||||
title="账户管理"
|
||||
destroy-on-close
|
||||
v-model="dialogUserInfoVisible"
|
||||
:close-on-click-modal="false"
|
||||
:before-close="
|
||||
() => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { loginApi, getUserInfoAPI } from 'http/api/login/index'
|
||||
import { loginNewApi } from 'http/api/home/index'
|
||||
import { getCompanyListApi } from 'http/api/home/index'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { User, Lock } from '@element-plus/icons-vue'
|
||||
|
|
@ -82,6 +83,39 @@ const handlerLogin = async () => {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
const origin = window.location.href
|
||||
|
||||
console.log(origin.split('ticket=')[1], 'origin')
|
||||
|
||||
if (origin.indexOf('ticket') != -1) {
|
||||
// console.log('origin.split爱玩送ticket')
|
||||
const res: any = await loginNewApi({
|
||||
ticket: origin.split('ticket=')[1].split('#/')[0],
|
||||
sysType: 0,
|
||||
})
|
||||
|
||||
userStore.setToken(res.data.access_token)
|
||||
|
||||
localStorage.setItem('tokenNew', res.data.access_token)
|
||||
const result: any = await getUserInfoAPI()
|
||||
userStore.setUserInfo(result.user)
|
||||
const roles = result.roles
|
||||
const isAdmin = roles.some((e: any) => e == 'admin')
|
||||
|
||||
if (isAdmin) {
|
||||
localStorage.setItem('rolesType', '3')
|
||||
} else {
|
||||
localStorage.setItem('rolesType', '1')
|
||||
}
|
||||
store.editcurrentMenuItem('goodsManagement')
|
||||
// 跳转登录页面
|
||||
router.push({
|
||||
name: 'home',
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -138,8 +172,8 @@ const handlerLogin = async () => {
|
|||
class="primary-lease"
|
||||
type="primary"
|
||||
@click="handlerLogin"
|
||||
>立 即 登 录</el-button
|
||||
>
|
||||
>立 即 登 录
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item class="forget-password">
|
||||
<a href=""></a>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import { useStore } from 'store/user'
|
|||
import { mainStore } from 'store/main'
|
||||
import { getHotList } from 'http/api/equip'
|
||||
import userClass from '../../hooks/userClass'
|
||||
import { loginNewApi } from 'http/api/home/index'
|
||||
import { getUserInfoAPI } from 'http/api/login/index'
|
||||
|
||||
import imgSrc from '../../assets/img/home/nw.png'
|
||||
import swiper_1 from '../../assets/img/home/swiper01.png'
|
||||
|
|
@ -115,7 +117,7 @@ const getHotDeviceList = async () => {
|
|||
hotDeviceList.value = res.data
|
||||
}
|
||||
|
||||
getHotDeviceList()
|
||||
// getHotDeviceList()
|
||||
|
||||
/* 热搜卡片点击跳转至详情页 */
|
||||
const onClick = (val: any) => {
|
||||
|
|
@ -162,6 +164,37 @@ const onClickSwiper = (item: any) => {
|
|||
}
|
||||
|
||||
getSwiperListData()
|
||||
|
||||
onMounted(async () => {
|
||||
if (!store.token) {
|
||||
const origin = window.location.href
|
||||
|
||||
console.log(origin.split('ticket=')[1], 'origin')
|
||||
|
||||
if (origin.indexOf('ticket') != -1) {
|
||||
// console.log('origin.split爱玩送ticket')
|
||||
const res: any = await loginNewApi({
|
||||
ticket: origin.split('ticket=')[1].split('#/')[0],
|
||||
sysType: 0,
|
||||
})
|
||||
|
||||
store.setToken(res.data.access_token)
|
||||
localStorage.setItem('tokenNew', res.data.access_token)
|
||||
const result: any = await getUserInfoAPI()
|
||||
store.setUserInfo(result.user)
|
||||
const roles = result.roles
|
||||
const isAdmin = roles.some((e: any) => e == 'admin')
|
||||
|
||||
if (isAdmin) {
|
||||
localStorage.setItem('rolesType', '3')
|
||||
} else {
|
||||
localStorage.setItem('rolesType', '1')
|
||||
}
|
||||
userStore.editcurrentMenuItem('goodsManagement')
|
||||
// 跳转登录页面
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
|
|||
Loading…
Reference in New Issue