diff --git a/teaching_integration_platform_admin_template/.env.development b/teaching_integration_platform_admin_template/.env.development index 7b3885a..7748426 100644 --- a/teaching_integration_platform_admin_template/.env.development +++ b/teaching_integration_platform_admin_template/.env.development @@ -1,6 +1,7 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' VITE_APP_TITLE = '无糖运营平台' -# VITE_APP_BASE_API = 'http://127.0.0.1:8080' -VITE_APP_BASE_API = 'http://39.106.16.162:8080' +VITE_APP_BASE_API = 'http://127.0.0.1:8080' +VITE_APP_OTHER_ORIGIN = 'http://127.0.0.1:8866' +# VITE_APP_BASE_API = 'http://39.106.16.162:8080' diff --git a/teaching_integration_platform_admin_template/.env.production b/teaching_integration_platform_admin_template/.env.production index d6a6065..3096538 100644 --- a/teaching_integration_platform_admin_template/.env.production +++ b/teaching_integration_platform_admin_template/.env.production @@ -1,3 +1,4 @@ NODE_ENV = 'production' VITE_APP_TITLE = '无糖运营平台' +VITE_APP_OTHER_ORIGIN = 'http://39.106.16.162:8866' # VITE_APP_BASE_API = '/prod-api' \ No newline at end of file diff --git a/teaching_integration_platform_admin_template/src/App.vue b/teaching_integration_platform_admin_template/src/App.vue index 9b44fe6..d1f4f72 100644 --- a/teaching_integration_platform_admin_template/src/App.vue +++ b/teaching_integration_platform_admin_template/src/App.vue @@ -3,7 +3,6 @@ diff --git a/teaching_integration_platform_admin_template/src/permission.ts b/teaching_integration_platform_admin_template/src/permission.ts index 5242431..690fbaa 100644 --- a/teaching_integration_platform_admin_template/src/permission.ts +++ b/teaching_integration_platform_admin_template/src/permission.ts @@ -6,7 +6,7 @@ import permissionStore from '@/store/modules/permission' //@ts-expect-error 修复ts校验 import nprogress from 'nprogress' import 'nprogress/nprogress.css' -const userStore :any = useUserStore(pinia) +const userStore: any = useUserStore(pinia) const usePermissionStore = permissionStore(pinia) // const whitelist = ['/login', '/404'] router.beforeEach(async (to, form, next) => { diff --git a/teaching_integration_platform_admin_template/src/store/modules/type/types.ts b/teaching_integration_platform_admin_template/src/store/modules/type/types.ts index 09bdbc7..da69225 100644 --- a/teaching_integration_platform_admin_template/src/store/modules/type/types.ts +++ b/teaching_integration_platform_admin_template/src/store/modules/type/types.ts @@ -8,4 +8,5 @@ export interface LoginStoreType { phone: string userInfo: object data: object + loginE: Record<'onLogin', null | (() => void)> } diff --git a/teaching_integration_platform_admin_template/src/store/modules/user.ts b/teaching_integration_platform_admin_template/src/store/modules/user.ts index ebe5493..ecdd170 100644 --- a/teaching_integration_platform_admin_template/src/store/modules/user.ts +++ b/teaching_integration_platform_admin_template/src/store/modules/user.ts @@ -11,7 +11,7 @@ import { GET_TKOEN, SET_TKOEN, REMOVE_TOKEN } from '@/utils/token' // 引入常量路由 import { constantRoute } from '@/router/routers' import permissionStore from './permission' -import {useRouter} from 'vue-router' +import { useRouter } from 'vue-router' // 引入路由 import { userLoginService, @@ -32,6 +32,7 @@ const useUserStore = defineStore('User', { phone: '', userInfo: {}, // 当前用户相关信息 data: {}, + loginE: { onLogin: null } } }, actions: { @@ -44,7 +45,7 @@ const useUserStore = defineStore('User', { }) if (res.code === 200) { this.token = res.data.token as string - SET_TKOEN('TOKEN', this.token) + SET_TKOEN('TOKEN', this.token, this.loginE.onLogin) // localStorage.setItem('TOKEN', this.token) ElNotification({ type: 'success', @@ -68,7 +69,7 @@ const useUserStore = defineStore('User', { if (res.code === 200) { this.token = res.data.token as string //接收返回的token // @ts-expect-error - SET_TKOEN('TOKEN', this.token) + SET_TKOEN('TOKEN', this.token, this.loginE.onLogin) // localStorage.setItem('TOKEN', this.token) ElNotification({ type: 'success', @@ -107,25 +108,25 @@ const useUserStore = defineStore('User', { const usePermissionStore = permissionStore() // console.log(usePermissionStore) // 清除token - REMOVE_TOKEN('TOKEN'), + REMOVE_TOKEN('TOKEN', this.loginE.onLogin), // ;(this.userName = ''), (this.avatar = '') // @ts-expect-error (this.userName = ''), // @ts-expect-error this.token = '' - // @ts-expect-error + // @ts-expect-error + + this.routes = '' + usePermissionStore.removeRouter() + location.reload() + const router = useRouter() + console.log(router.getRoutes()); - this.routes = '' - usePermissionStore.removeRouter() - location.reload() - const router = useRouter() - console.log(router.getRoutes()); - - }, }, - getters: {}, }, + getters: {}, +}, { persist: true, // 持久化 }, diff --git a/teaching_integration_platform_admin_template/src/utils/token.ts b/teaching_integration_platform_admin_template/src/utils/token.ts index 0abe1de..96abbec 100644 --- a/teaching_integration_platform_admin_template/src/utils/token.ts +++ b/teaching_integration_platform_admin_template/src/utils/token.ts @@ -1,12 +1,15 @@ // 设置token -export const SET_TKOEN = (name: string, data: string) => { +type OnLogin = null | ((token: any) => void) +export const SET_TKOEN = (name: string, data: string, onLogin: OnLogin) => { localStorage.setItem(name, data) + if (onLogin) onLogin(data) } // 获取token export const GET_TKOEN = (name: string) => { return localStorage.getItem(name) } // 移除token -export const REMOVE_TOKEN = (name: string) => { +export const REMOVE_TOKEN = (name: string, onLogin: OnLogin) => { localStorage.removeItem(name) + if (onLogin) onLogin('') } diff --git a/teaching_integration_platform_admin_template/src/views/home/index.vue b/teaching_integration_platform_admin_template/src/views/home/index.vue index 1ac0bcd..2dffa64 100644 --- a/teaching_integration_platform_admin_template/src/views/home/index.vue +++ b/teaching_integration_platform_admin_template/src/views/home/index.vue @@ -123,14 +123,8 @@ onMounted(() => { @@ -142,41 +136,31 @@ onMounted(() => {
- + +
- - + "> +
- - + +
@@ -184,24 +168,22 @@ onMounted(() => {
- + ">
- - + +
@@ -209,14 +191,8 @@ onMounted(() => {
- - + +
- - + +
@@ -240,14 +217,8 @@ onMounted(() => {
- - + +
- - + +
@@ -287,6 +259,7 @@ onMounted(() => { * { box-sizing: border-box; } + .nav { height: 92px; background: #ffffff; @@ -298,6 +271,7 @@ onMounted(() => { justify-content: center; align-items: center; } + .classList, .info { // background-color: yellow; @@ -309,10 +283,12 @@ onMounted(() => { align-items: center; margin-bottom: 16px; } + .classList { display: flex; justify-content: space-between; } + .lesson { padding-top: 30px; // padding-bottom: 30px; @@ -326,6 +302,7 @@ onMounted(() => { text-overflow: ellipsis; // flex-direction: column; } + .con { display: flex; // justify-content: space-between; @@ -340,6 +317,7 @@ onMounted(() => { justify-content: space-evenly; padding-bottom: 30px; } + .contt { // background-color: yellow; padding: 5px; @@ -348,9 +326,11 @@ onMounted(() => { // grid-template-columns: repeat(2, 1fr); // grid-gap: 11px; } + :deep(.el-scrollbar__wrap) { padding: 0; } + .button { justify-content: space-between; @@ -367,13 +347,16 @@ onMounted(() => { text-overflow: ellipsis; white-space: nowrap; } + .button :hover { overflow: visible; white-space: normal; } + a { text-decoration: none; } + .some, .stu { padding-top: 5px; @@ -387,6 +370,7 @@ a { justify-content: center; align-items: center; } + // .lessonlist-content { // display: flex; // justify-content: center; @@ -417,12 +401,14 @@ ul { justify-content: space-between; // align-items: center; } + .lessonlist-item-img { width: 17%; height: 40px; justify-content: center; align-items: center; } + .lessonlist-item-info { margin-left: 15px; width: 80%; @@ -432,11 +418,13 @@ ul { // flex-direction: column; justify-content: space-between; align-items: center; + h5 { // font-weight: bold; width: 80%; text-align: center; } + p { font-size: small; width: 20%; diff --git a/teaching_integration_platform_admin_template/src/views/login/index.vue b/teaching_integration_platform_admin_template/src/views/login/index.vue index 287fda9..0b3dd63 100644 --- a/teaching_integration_platform_admin_template/src/views/login/index.vue +++ b/teaching_integration_platform_admin_template/src/views/login/index.vue @@ -406,12 +406,16 @@ const login = async () => { isBtnLoading.value = false $router.push('/curriculumCenter/basicCourseInformation') channel.postMessage('') + + if ($route.query.redirect) { $router.push($route.query.redirect as string) channel.postMessage('') + } else { $router.push('/') channel.postMessage('') + } }) } catch (error) { @@ -433,12 +437,15 @@ const phoneLogin = async () => { isBtnLoading.value = false $router.push('/curriculumCenter/basicCourseInformation') channel.postMessage('') + if ($route.query.redirect) { $router.push($route.query.redirect as string) channel.postMessage('') + } else { $router.push('/') channel.postMessage('') + } }) .catch((error) => { diff --git a/teaching_integration_platform_admin_template/vite.config.ts b/teaching_integration_platform_admin_template/vite.config.ts index 5b2293c..2d49151 100644 --- a/teaching_integration_platform_admin_template/vite.config.ts +++ b/teaching_integration_platform_admin_template/vite.config.ts @@ -20,6 +20,9 @@ export default ({ command }: any) => { symbolId: 'icon-[dir]-[name]', }), ], + server: { + host: '0.0.0.0', + }, resolve: { alias: { '@': path.resolve('./src'), // 相对路径别名配置,使用 @ 代替 src diff --git a/teaching_integration_platform_template/.env.development b/teaching_integration_platform_template/.env.development index 6692c9c..dcb1be4 100644 --- a/teaching_integration_platform_template/.env.development +++ b/teaching_integration_platform_template/.env.development @@ -1,5 +1,6 @@ # 变量必须以 VITE_ 为前缀才能暴露给外部读取 NODE_ENV = 'development' VITE_APP_TITLE = '教学一体化平台' -# VITE_APP_BASE_API = 'http://127.0.0.1:8080' -VITE_APP_BASE_API = 'http://39.106.16.162:8080' \ No newline at end of file +VITE_APP_BASE_API = 'http://127.0.0.1:8080' +VITE_APP_OTHER_ORIGIN = 'http://127.0.0.1:5173' +# VITE_APP_BASE_API = 'http://39.106.16.162:8080' \ No newline at end of file diff --git a/teaching_integration_platform_template/.env.production b/teaching_integration_platform_template/.env.production index 0a20fe4..a3dd5a6 100644 --- a/teaching_integration_platform_template/.env.production +++ b/teaching_integration_platform_template/.env.production @@ -1,3 +1,4 @@ NODE_ENV = 'production' VITE_APP_TITLE = '教学一体化平台' +VITE_APP_OTHER_ORIGIN = 'http://39.106.16.162:5173' # VITE_APP_BASE_API = '/api' \ No newline at end of file diff --git a/teaching_integration_platform_template/src/App.vue b/teaching_integration_platform_template/src/App.vue index d31088e..ca321d5 100644 --- a/teaching_integration_platform_template/src/App.vue +++ b/teaching_integration_platform_template/src/App.vue @@ -3,7 +3,7 @@ diff --git a/teaching_integration_platform_template/src/Layout/tabbar/index.vue b/teaching_integration_platform_template/src/Layout/tabbar/index.vue index 83a5552..bb3ee87 100644 --- a/teaching_integration_platform_template/src/Layout/tabbar/index.vue +++ b/teaching_integration_platform_template/src/Layout/tabbar/index.vue @@ -12,11 +12,12 @@ v-show="!item.meta.hidden" @click="goToRouter(item, index)" :key="item.path">
{{ item.meta.title }}
-
- +
+ - {{ data.username }} + {{ userStore.userInfo.username }} @@ -28,7 +29,8 @@
-
  • 登录注册
  • +
  • 登录注册
  • +
    @@ -50,7 +52,7 @@ import useUserStore from '@/store/module/user'; const userStore = useUserStore() import { constRouter } from '@/router/module/constRouter' import { useRouter, useRoute } from 'vue-router' -import { onMounted, ref } from 'vue' +import { computed, onMounted, ref } from 'vue' import useSettingStore from '@/store/module/setting' const $router = useRouter() const $route = useRoute() @@ -72,23 +74,38 @@ onMounted(() => { } }) }) -const isLogin = ref(false) -const data = ref({}) -userGetInfoService(userStore.token).then(res => { - // @ts-ignore - if (res.code === 200) { - isLogin.value = true - data.value = res.data - } -}) function skip(url: string) { location.assign(url) } +// ======================== +let otherWin: any = null; +function send() { + if (otherWin) { + otherWin.focus(); + return + } + otherWin = window.open(import.meta.env.VITE_APP_OTHER_ORIGIN) + +} +window.onmessage = e => { + if (e.origin === import.meta.env.VITE_APP_OTHER_ORIGIN) { + userStore.setToken(e.data) + userStore.setUserInfo() + } +} +// ======================== // 退出登录 function logout() { - isLogin.value = false + try { + otherWin.postMessage('logout', import.meta.env.VITE_APP_OTHER_ORIGIN) + } catch (error) { + send() + setTimeout(() => { + otherWin.postMessage('logout', import.meta.env.VITE_APP_OTHER_ORIGIN) + }, 500) + } } const handleCommand = (command: string) => { switch (command) { diff --git a/teaching_integration_platform_template/src/store/module/user.ts b/teaching_integration_platform_template/src/store/module/user.ts index 55aa1d9..c2932c6 100644 --- a/teaching_integration_platform_template/src/store/module/user.ts +++ b/teaching_integration_platform_template/src/store/module/user.ts @@ -4,21 +4,39 @@ import { ref, reactive } from 'vue' const userStore = defineStore('userStore', () => { const userInfo = reactive({}) const isLogin = ref(false) - const token = ref('') + const token = ref(localStorage.getItem('TOKEN') || '') const verifyToken = () => { } - - userGetInfoService(token.value).then(res => { - // @ts-ignore - if (res.code === 200) { - Object.assign(userInfo, res.data) - isLogin.value = true + const clearUserInfo = () => { + Object.keys(userInfo).forEach(function (prop) { + delete userInfo[prop]; + }); + } + const setToken = (data: string) => { + token.value = data + localStorage.setItem('TOKEN', data) + } + const setUserInfo = async () => { + try { + const res = await userGetInfoService(token.value) + // @ts-ignore + if (res.code === 200) { + Object.assign(userInfo, res.data) + isLogin.value = true + } else isLogin.value = false + } catch (error) { + isLogin.value = false + clearUserInfo() } - }) + } + setUserInfo() return { token, + setToken, userInfo, isLogin, - verifyToken + verifyToken, + setUserInfo, + clearUserInfo } }) export default userStore