ソースを参照

vuex中添加gotype

11wqe1 1 ヶ月 前
コミット
355c4c1a0e
4 ファイル変更36 行追加19 行削除
  1. 11 2
      src/App.vue
  2. 14 0
      src/stores/counter.js
  3. 4 2
      src/views/Details.vue
  4. 7 15
      src/views/main.vue

+ 11 - 2
src/App.vue

@@ -5,12 +5,14 @@ import Header from './views/header.vue';
 import axios from 'axios';
 import qs from 'qs';
 import { ElMessageBox } from 'element-plus'
-import { userInfoStore, userCurrentRole,userCurrent } from './stores/counter'
+import { userInfoStore, userCurrentRole,userCurrent,pageGotype } from './stores/counter'
 
 const route = useRoute()
 const store = userInfoStore()
 const CurrentRole = userCurrentRole()
 const Current = userCurrent()
+const setgotype = pageGotype()
+
 const name = ref('')
 const isShow = ref(true)
 const setTimeState = ref(null)
@@ -22,7 +24,8 @@ onMounted(() => {
   let ticket = getUrlParam(window.parent.location.href, 'ticket')
   let userid = getUrlParam(window.parent.location.href, 'userid')
   axios.defaults.headers = { 'content-type': 'application/json;charset=utf-8' }
- 
+  // 获取gotype传参
+  pageType2()
   if (isGrantCode) {
     let params = {
       grantCode: isGrantCode,
@@ -74,6 +77,12 @@ const linkLogin = () => {
   }
 }
 
+const pageType2 = () => {
+  const val = route.query.gotype ? route.query.gotype :''
+  console.log('gotype',val);
+  setgotype.setpageType(val);
+}
+
 // 同步登录信息
 const userInfo = (data) => {
   // eduId  - 教育ID

+ 14 - 0
src/stores/counter.js

@@ -29,6 +29,20 @@ export const userCurrentRole = defineStore({
   }
 })
 
+export const pageGotype = defineStore({
+  id: 'pageGotype',
+  state: () => {
+    return {
+      gotype: ""
+    }
+  },
+  actions: {
+    setpageType(gotype) {
+      this.gotype = gotype
+    }
+  }
+})
+
 export const userCurrent = defineStore({
   id: 'userCurrentRoleId',
   state: () => {

+ 4 - 2
src/views/Details.vue

@@ -1,5 +1,5 @@
 <template>
-    <Header v-if="!gotype"></Header>
+    <Header v-if="!gotype.gotype"></Header>
     <el-page-header>
         <template #breadcrumb>
             <el-breadcrumb separator="/">
@@ -30,11 +30,13 @@ import AIExperienceCon from '@/components/main/AIExperienceCon.vue';
 import AIexplorationCon from '@/components/main/AIexplorationCon.vue';
 import Header from './header.vue';
 import { useRoute } from 'vue-router';  //1.先在需要跳转的页面引入useRouter
+import { pageGotype } from '../stores/counter'
+
 const { query, params } = useRoute()
 console.log(query, params)
+const gotype = pageGotype()
 
 const detailsTitle = ref('')
-const gotype = ref((window.topU && window.topU.gotype2) ? window.topU.gotype2 :'')
 onMounted(()=>{
     detailsTitle.value = params.title
 })

+ 7 - 15
src/views/main.vue

@@ -1,8 +1,8 @@
 <template>
   <div style="height:100%">
-    <Header v-if="!gotype"></Header>
+    <Header v-if="!gotype.gotype"></Header>
     <div class="container">
-      <div class="container-left" :style="leftShow ? { width: 0 } : { width: '240px' }" v-if="!gotype">
+      <div class="container-left" :style="leftShow ? { width: 0 } : { width: '240px' }" v-if="!gotype.gotype">
         <div class="container-left-top" @click="dialogVisible1 = !dialogVisible1">
           <span>
             <img class="icon-img" :src="img11" alt="AI 应用" />AI通识课
@@ -63,8 +63,8 @@
           <span v-else><el-icon><ArrowLeft /></el-icon></span>
         </div>
       </div>
-      <div class="main" :style="leftShow ? { width: '100%' } : ''" v-if="activeIndex == 0" :class="[gotype ? 'liyuan' : '']">
-        <div class="pgb" v-if="gotype && gotype == '/CourseCon'">
+      <div class="main" :style="leftShow ? { width: '100%' } : ''" v-if="activeIndex == 0" :class="[gotype.gotype ? 'liyuan' : '']">
+        <div class="pgb" v-if="gotype.gotype && gotype.gotype == 'CourseCon'">
           <div @click="backO" class="pgbL">
               <img src="../assets/icon/backPage.svg" alt="">
               <div>AI通识课</div>
@@ -135,11 +135,13 @@ import other from '@/components/main/other.vue';
 import Edu from '@/components/main/edu.vue';
 import Feedback from '@/components/main/feedback.vue';
 import Header from './header.vue'
-import { userCurrentRole, userInfoStore } from '../stores/counter'
+import { userCurrentRole, userInfoStore,pageGotype } from '../stores/counter'
 
 
 const user = userInfoStore()
 const CurrentRole = userCurrentRole()
+const gotype = pageGotype()
+
 const isupdateCourse = ref(false)
 const isLogin = ref(false)
 const activeIndex = ref(0)
@@ -156,11 +158,8 @@ const iframeRef1Url4 = ref('')
 const iframeRef2Dialog = ref(false)
 const leftShow = ref(false)
 const admin = ref(false)
-const gotype = ref((window.topU && window.topU.gotype2) ?  window.topU.gotype2 : '')
 
 onMounted(() => {
-  console.log('gotype',gotype.value);
-  console.log('gotype',sessionStorage.getItem('gotype2'));
   // let timer = setInterval(() => {
   //   if (JSON.stringify(user.user) != "{}") {
   //     clickSwitch(1)
@@ -283,13 +282,6 @@ const copyEmail = () => {
 }
 const backO = () => {
   window.location.href = `https://pbl.cocorobo.cn/pbl-teacher-table/dist/#/CourseCon?userid=${user.user.userid}&oid=${user.user.oid}&org=${user.user.org}&role=${user.user.role}&tType=${user.user.tType}`
-  try {
-      window.topU.gotype2 = '' 
-      window.topU.gotype = '' 
-    } catch (error) {
-      console.log(error);
-    }
-    sessionStorage.removeItem('gotype2');
 }
 const show = () => {
   console.log('show')