提交 ee4f119d authored 作者: 王鹏飞's avatar 王鹏飞

检测登录状态

上级 26d16f68
module.exports = {
domain: 'dev.ezijing.com',
url: 'https://transport.ezijing.com/api',
url: 'https://x-training2.ezijing.com/api',
webpack: {
externals: {
CKEDITOR: 'window.CKEDITOR',
......
......@@ -26,17 +26,5 @@ export function logout() {
}
// 获取用户信息
export function getUser() {
return httpRequest.get('/api/zy/user/getinfo')
}
// 绑定游客
export function bindVisitor(data) {
return httpRequest.post('/api/zy/user/bind-account', data)
}
// 获取是否VIP
export function getIsVip() {
return httpRequest.get('/api/zy/user/is-vip')
}
// 创建游客用户
export function createGuestUser() {
return httpRequest.get('/api/zy/user/create-guest-user')
return httpRequest.get('/api/passport/account/get-user-info')
}
import httpRequest from '@/utils/axios'
/**
* 获取课程列表
*/
export function getCourseModule() {
return httpRequest.get('/api/zy/v2/education/mokuai')
}
/**
* 获取课程列表
*/
export function getCourseList() {
return httpRequest.get('/api/zy/v2/education/courses/list')
}
/**
* 获取课程详情
* @param {string} courseId 课程ID
*/
export function getCourse(courseId) {
return httpRequest.get(`/api/zy/v2/education/courses/${courseId}`).then(response => {
response.chapters = response.chapters.filter(item => {
item.children = item.children.filter(child => child.type === 2)
return item.children.length
})
return response
})
}
/**
* 获取课程知识点
* @param {string} courseId 课程ID
*/
export function getCourseTagList(courseId) {
return httpRequest.get(`/api/zy/v2/education/tag/tree/${courseId}`)
}
/**
* 知识点详情
* @param {string} tagId 知识点ID
*/
export function getCourseTag(tagId) {
return httpRequest.get(`/api/zy/v2/education/tag/${tagId}`)
}
import httpRequest from '@/utils/axios'
/**
* 随堂测试课程章节列表
*/
export function getCourseChapterList() {
return httpRequest.get('/api/zy/v2/education/courses/my')
}
/* 模拟考试设置角色 */
export function setRole(data) {
return httpRequest.post('/api/zy/v2/examination/role', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/* 获取考试状态 */
export function getExamStatus(data) {
return httpRequest.get('/api/zy/v2/examination/examination-papers-status', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/* 知识点考题获取 */
export function getExam(data) {
return httpRequest.get('/api/zy/v2/examination/course-papers', data)
}
/* 知识点考题缓存 */
export function cacheExam(data) {
return httpRequest.post('/api/zy/v2/examination/course-papers', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
import httpRequest from '@/utils/axios'
/**
* 获取考前摸底试题
*/
export function getExamQuestion(params) {
return httpRequest.get('/api/zy/v2/examination/examination-papers', { params }, { headers: { 'Content-Type': 'multipart/form-data' } })
}
/**
* 缓存考前摸底试题
*/
export function setCache(params) {
return httpRequest.post('/api/zy/v2/examination/examination-papers', params)
}
/**
* 获取考试的状态
*/
export function getExamStatus(params) {
return httpRequest.get('/api/zy/v2/examination/examination-papers-status', { params })
}
/**
* 模拟考试设置角色
*/
export function setRoles(params) {
return httpRequest.post('/api/zy/v2/examination/role', params)
}
/**
* 获取我的已做试题
*/
export function getMyQuestion(params) {
return httpRequest.get('/api/zy/v2/examination/my-question', { params }, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/**
* 获取我的所有试题
*/
export function getAllQuestion(params) {
return httpRequest.get('/api/zy/v2/examination/my-question-all', { params })
}
/**
* 缓存错题集
*/
export function setMyCache(params) {
return httpRequest.post('/api/zy/v2/examination/cache-question', params)
}
/**
* 收藏试题
*/
export function addCollection(params) {
return httpRequest.post('/api/zy/v2/examination/add-collection', params)
}
/**
* 取消收藏试题
*/
export function deleteCollection(params) {
return httpRequest.post('/api/zy/v2/examination/delete-my-question', params)
}
/**
* 删除试题
*/
export function deleteQuestion(params) {
return httpRequest.post('/api/zy/v2/examination/delete-my-question', params)
}
/**
* 知识点题获取
*/
export function getCourseQuestion(params) {
return httpRequest.get('/api/zy/v2/examination/course-papers', { params })
}
/**
* 知识点题缓存
*/
export function setCourseCache(params) {
return httpRequest.post('/api/zy/v2/examination/course-papers', params)
}
import httpRequest from '@/utils/axios'
/**
* 获取我的已做试题
*/
export function getMyQuestion(data) {
return httpRequest.get('/api/zy/v2/examination/my-question', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/**
* 获取我的试题详情
*/
export function getMyQuestionDetail(data) {
return httpRequest.get('/api/zy/v2/examination/question/detail', data)
}
/**
* 获取我的所有试题
*/
export function getAllQuestion(data) {
return httpRequest.get('/api/zy/v2/examination/my-question-all', data)
}
/* 删除试题 */
export function deleteQuestion(data) {
return httpRequest.post('/api/zy/v2/examination/delete-my-question', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/* 收藏试题 */
export function collectQuestion(data) {
return httpRequest.post('/api/zy/v2/examination/add-collection', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/* 缓存试题 */
export function cacheQuestion(data) {
return httpRequest.post('/api/zy/v2/examination/cache-question', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
/* 意见反馈 */
export function submitFeedback(data) {
return httpRequest.post('/api/zy/v2/feedback/commit', data)
}
/* 获取考试状态 */
export function getExamStatus(data) {
return httpRequest.get('/api/zy/v2/examination/examination-papers-status', data, {
headers: { 'Content-Type': 'multipart/form-data' }
})
}
import httpRequest from '@/utils/axios'
/**
* 获取我的试题
*/
export function getMyQuestions(params) {
return httpRequest.get('/api/zy/v2/examination/my-question', { params })
}
/**
* 删除试题
*/
export function deleteQuestion(data) {
return httpRequest.post('/api/zy/v2/examination/delete-my-question', data)
}
/**
* 收藏试题
*/
export function addCollection(data) {
return httpRequest.post('/api/zy/v2/examination/add-collection', data)
}
/**
* 取消收藏试题
*/
export function deleteCollection(data) {
return httpRequest.post('/api/zy/v2/examination/delete-my-question', data)
}
import httpRequest from '@/utils/axios'
/**
* 获取课程列表
*/
export function getCourseList() {
return httpRequest.get('/api/zy/v2/education/courses/my')
}
<template>
<div class="search-bar">
<el-input
prefix-icon="el-icon-search"
size="medium"
clearable
v-model="currentValue"
@change="onChange"
@keyup.enter.native="onSearch"
ref="formInput"
></el-input>
<el-button type="text" size="medium" @click="onSearch">搜索</el-button>
</div>
</template>
<script>
export default {
props: {
value: String,
focus: { type: Boolean, default: false }
},
data() {
return {
currentValue: this.value,
debounced: null
}
},
watch: {
value(value) {
this.currentValue = value
}
},
computed: {
formInput() {
return this.$refs.formInput
}
},
methods: {
bindFocus() {
this.focus && this.formInput.focus()
},
onChange() {
this.$emit('change', this.currentValue)
},
onSearch() {
this.$emit('search', this.currentValue)
}
},
mounted() {
this.bindFocus()
}
}
</script>
<style lang="scss">
.search-bar {
display: flex;
align-items: center;
.el-input {
width: 240px;
}
.el-button {
margin-left: 10px;
font-size: 18px;
font-weight: 400;
color: #333;
}
}
</style>
<template>
<div class="course-list" element-loading-text="加载中..." v-loading="!loaded">
<template v-if="list.length">
<course-list-item v-for="item in list" :data="item" :key="item.id" v-bind="$attrs" v-on="$listeners" />
</template>
<template v-else>
<slot name="empty">
<div class="empty">暂无相关课程</div>
</slot>
</template>
</div>
</template>
<script>
import * as api from '@/api/course.js'
import CourseListItem from './CourseListItem.vue'
export default {
name: 'CourseList',
components: { CourseListItem },
props: {
requestCallback: Function
},
data() {
return {
loaded: false,
list: []
}
},
methods: {
getCourseList() {
api
.getCourseModule()
.then(response => {
this.list = this.requestCallback ? this.requestCallback(response) : response
this.$emit('request-success', response)
})
.finally(() => {
this.loaded = true
})
}
},
beforeMount() {
this.getCourseList()
}
}
</script>
<template>
<div class="course-item">
<div class="course-item-top">
<img class="course-item-pic" :src="data.photo" v-if="data.photo" />
<div class="course-item-content">
<div class="course-item__title">{{ data.title }}</div>
<div class="course-item__tools">
<div class="course-item__text course-item__text__course">{{ data.course_num }}节课</div>
<div class="course-item__text course-item__text__video">{{ data.video_num }}节视频课</div>
<div class="course-item__text course-item__text__freevideo">{{ data.free_video_num }}个免费视频</div>
</div>
</div>
</div>
<div class="course-item-bottom">
<div class="course-child" v-for="item in data.child" :key="item.id" @click="$emit('on-click', item)">
<div class="name">{{ item.course_name }}</div>
<div class="progress" v-if="showProgress">{{ item.video_progress | progressText }}</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: 'CourseListItem',
props: {
data: { type: Object, required: true },
showProgress: { type: Boolean, default: false }
},
data() {
return {}
},
filters: {
progressText(value) {
value = parseInt(value)
if (value === 0) {
return '未开始'
}
if (value === 100) {
return '已学完'
}
return `已学${value}%`
}
}
}
</script>
<style lang="scss" scoped>
.course-item {
background: #ffffff;
border-radius: 8px;
padding: 30px;
margin-bottom: 20px;
}
.course-item-top {
display: flex;
}
.course-item-pic {
width: 160px;
height: 90px;
margin-right: 20px;
border-radius: 2px;
overflow: hidden;
}
.course-item-content {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
}
.course-item__title {
font-size: 18px;
color: #222;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
overflow: hidden;
}
.course-item__text {
display: inline-block;
font-size: 14px;
}
.course-item__text + .course-item__text {
margin-left: 0.1rem;
}
.course-item__text__course {
color: #88bbff;
}
.course-item__text__video {
color: #5ad0b2;
}
.course-item__text__freevideo {
color: #d05a5a;
}
.course-child {
display: flex;
align-items: center;
padding: 20px 0;
border-bottom: 1px solid #eee;
cursor: pointer;
&:hover {
color: #c01540;
}
.name {
flex: 1;
font-size: 18px;
}
.progress {
margin-left: 20px;
font-size: 12px;
color: #999;
}
}
</style>
<template>
<el-collapse v-model="activeNames" v-if="list.length">
<el-collapse-item :title="item.name" :name="item.id" v-for="item in list" :key="item.id">
<ul>
<li
:class="{ 'is-active': subItem.id === activeId }"
v-for="subItem in item.tag"
:key="subItem.id"
@click="$emit('on-click', subItem)"
>
<div class="name">{{ subItem.title }}</div>
</li>
</ul>
</el-collapse-item>
</el-collapse>
</template>
<script>
import * as api from '@/api/course.js'
export default {
props: {
activeId: { type: String },
courseId: {
type: String,
default() {
return this.$route.params.id
}
}
},
data() {
return {
list: [],
activeNames: []
}
},
watch: {
parentId(value) {
this.activeNames = [value]
}
},
computed: {
parentId() {
for (const item of this.list) {
if (item.tag && item.tag.length) {
for (const subitem of item.tag) {
if (subitem.id === this.activeId) {
return item.id
}
}
}
}
return ''
}
},
methods: {
// 获取知识点列表
getCourseTagList() {
api.getCourseTagList(this.courseId).then(response => {
const { chapters = [] } = response
this.list = chapters
})
}
},
beforeMount() {
this.getCourseTagList()
}
}
</script>
<style lang="scss" scoped>
.el-collapse {
border: 0;
}
::v-deep .el-collapse-item__header {
font-size: 14px;
font-weight: 600;
color: #222;
}
::v-deep .el-collapse-item__content {
padding-bottom: 10px;
}
li {
display: flex;
padding: 5px 0;
cursor: pointer;
color: #666;
&:hover,
&.is-active {
color: #c01540;
}
.name {
flex: 1;
overflow: hidden;
}
.progress {
margin-left: 20px;
color: #999;
}
}
</style>
<template>
<div class="my-question-list" element-loading-text="加载中..." v-loading="!loaded">
<div class="my-question-list-hd">
<div class="title"><slot name="title"></slot></div>
<div class="tools">
<span>选择题型</span>
<el-radio-group v-model="questionType" @change="handleTypeChange">
<el-radio :label="0">全部</el-radio>
<el-radio :label="1">单选题</el-radio>
<el-radio :label="2">多选题</el-radio>
<el-radio :label="6">判断题</el-radio>
<el-radio :label="5">案例题</el-radio>
</el-radio-group>
</div>
</div>
<div class="my-question-list-bd">
<template v-if="list.length">
<my-question-list-item
v-for="item in list"
:data="item"
:key="item.id"
v-bind="$attrs"
v-on="$listeners"
@on-remove="handleRemove"
@on-addCollection="handleAddCollection"
@on-removeCollection="handleRemoveCollection"
@on-goDetails="goDetails(item.num)"
></my-question-list-item>
</template>
<div class="empty" v-else>暂无试题</div>
</div>
<div class="my-question-list-ft" v-if="list.length">
<div class="buttons">
<el-button size="medium" @click="toggleSelectAll(!isAllChecked)">
{{ isAllChecked ? '取消全选' : '全选' }}
</el-button>
<el-button size="medium" @click="handleBatchRemove" v-if="hasRemove">删除</el-button>
</div>
<div class="pagations">
<el-pagination
@current-change="handleCurrentChange"
:current-page.sync="currentPage"
layout="prev, pager, next"
:total="total"
>
</el-pagination>
</div>
</div>
</div>
</template>
<script>
import * as api from '@/api/question.js'
import MyQuestionListItem from './MyQuestionListItem'
export default {
components: { MyQuestionListItem },
props: {
requestCallback: Function,
requestParams: { type: Object, default: () => ({}) }
},
data() {
return {
loaded: false,
questionType: 0,
list: [],
total: 0,
currentPage: 1
}
},
computed: {
// 已选中
checkedList() {
return this.list.filter(item => item.checked)
},
// 是否全选
isAllChecked() {
return this.checkedList.length === this.list.length
},
// 是否显示删除按钮
hasRemove() {
return !!this.checkedList.length
}
},
methods: {
// 跳详情
goDetails(i) {
window.localStorage.removeItem('answerRecord')
this.$router.push({
path: '/my/questions/details',
query: {
type: this.requestParams.type,
qType: this.questionType,
index: i
}
})
},
// 获取试题列表
getMyQuestions() {
this.loaded = false
const params = Object.assign({}, this.requestParams, {
question_type: this.questionType,
page: this.currentPage,
page_size: 10
})
api
.getMyQuestions(params)
.then(response => {
const { list, total } = this.requestCallback ? this.requestCallback(response) : response
this.total = total
this.list = list.map(item => {
item.checked = false
return item
})
this.$emit('request-success', response)
})
.finally(() => {
this.loaded = true
})
},
// 类型改变
handleTypeChange(value) {
this.currentPage = 1
this.getMyQuestions()
},
// 页码改变
handleCurrentChange(value) {
this.getMyQuestions()
},
// 全选、取消全选
toggleSelectAll(checked) {
this.list = this.list.map(item => {
item.checked = checked
return item
})
},
// 收藏
handleAddCollection(data) {
api.addCollection({ question_id: data.question_id }).then(response => {
data.is_collection = true
})
},
// 取消收藏
handleRemoveCollection(data) {
api.deleteCollection({ question_id: data.question_id, type: 2 }).then(response => {
data.is_collection = false
})
},
// 删除
handleRemove(data) {
this.handleRemoveReqeust({ question_id: data.question_id })
},
// 批量删除
handleBatchRemove() {
const ids = this.checkedList.map(item => {
return item.question_id
})
this.handleRemoveReqeust({ question_id: ids.join(',') })
},
// 删除接口
handleRemoveReqeust(params) {
const requestParams = Object.assign({}, params, this.requestParams)
api.deleteQuestion(requestParams).then(response => {
this.$message({ message: '删除成功', type: 'success' })
this.getMyQuestions()
})
}
},
beforeMount() {
this.getMyQuestions()
}
}
</script>
<style lang="scss" scoped>
.my-question-list-hd {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 8px;
font-size: 18px;
border-bottom: 1px solid #ccc;
::v-deep .el-radio {
font-size: 18px;
}
::v-deep .el-radio__label {
font-size: 18px;
font-weight: 400;
}
::v-deep .el-radio__inner {
width: 18px;
height: 18px;
}
}
.my-question-list-ft {
padding-top: 20px;
display: flex;
justify-content: space-between;
align-items: center;
::v-deep .el-button {
width: 100px;
}
}
</style>
<template>
<div class="my-question-list-item">
<el-checkbox v-model="data.checked"></el-checkbox>
<div class="badge" :class="`questiont-type_${data.question_type}`">{{ questionTypeName }}</div>
<div class="name" v-html="data.question_content" @click="goDetails"></div>
<div class="tools">
<i class="el-icon-delete" @click="$emit('on-remove', data)"></i>
<i
class="el-icon-star-on"
:class="{ 'is-active': data.is_collection }"
@click="toggleCollection"
v-if="hasCollection"
></i>
</div>
</div>
</template>
<script>
export default {
props: {
data: { type: Object, default: () => ({}) },
hasCollection: { type: Boolean, default: true }
},
data() {
return {
radio: false
}
},
computed: {
questionTypeName() {
const map = { 1: '单选题', 2: '多选题', 5: '案例题', 6: '判断题' }
return map[this.data.question_type]
}
},
methods: {
toggleCollection() {
this.data.is_collection ? this.$emit('on-removeCollection', this.data) : this.$emit('on-addCollection', this.data)
},
goDetails() {
this.$emit('on-goDetails')
}
}
}
</script>
<style lang="scss" scoped>
.my-question-list-item {
display: flex;
align-items: center;
padding: 22px 0;
border-bottom: 1px solid #eee;
&:hover {
.name {
color: #c01540;
}
}
.badge {
margin: 0 8px;
width: 60px;
height: 18px;
font-size: 12px;
line-height: 18px;
color: #fff;
text-align: center;
background: #ffbe44;
border-radius: 9px;
}
.questiont-type_1 {
background: #f47c46;
}
.questiont-type_2 {
background: #ffbe44;
}
.questiont-type_5 {
background: #7ed6e8;
}
.questiont-type_6 {
background: #83da60;
}
.name {
flex: 1;
padding: 0 10px;
font-size: 18px;
}
.tools {
padding-left: 20px;
display: flex;
font-size: 18px;
color: #d4d4d4;
i {
margin-left: 10px;
cursor: pointer;
}
.is-active {
color: #ffcd39;
}
}
}
</style>
......@@ -93,6 +93,7 @@ export default {
height: 32px;
border-radius: 50%;
overflow: hidden;
margin-right: 8px;
img {
width: 100%;
height: 100%;
......
......@@ -5,15 +5,14 @@ import App from './app.vue'
import './style.scss'
import ElementUI from 'element-ui'
// import BeforeEnter from './utils/beforeEnter'
// const before = new BeforeEnter()
import BeforeEnter from './utils/beforeEnter'
const before = new BeforeEnter()
Vue.use(ElementUI)
/* 导航守卫 */
router.beforeEach((to, from, next) => {
// before.update(to, from, next)
next()
before.update(to, from, next)
})
Vue.prototype.msgCenter = new Vue()
......
<template>
<course-list :showProgress="true" @on-click="handleClick" />
</template>
<script>
import CourseList from '@/components/CourseList.vue'
export default {
components: { CourseList },
methods: {
handleClick(data) {
this.$router.push({ name: 'courseLearnItem', params: { id: data.id } })
}
}
}
</script>
<template>
<app-layout :showUser="false" :menus="navList"></app-layout>
</template>
<script>
import AppLayout from '@/components/layout'
export default {
components: { AppLayout },
data() {
return {
navList: [
{ title: '我的已学课程', path: '/my/course' },
{ title: '我的已做试题', path: '/my/questions' }
]
}
}
}
</script>
<template>
<app-container>
<my-question-list :requestParams="{ type: 3 }" @request-success="handleRequestSuccess">
<template #title>做题总数:{{ total }}</template>
</my-question-list>
</app-container>
</template>
<script>
import AppContainer from '@/components/AppContainer'
import MyQuestionList from '@/components/MyQuestionList'
export default {
components: { AppContainer, MyQuestionList },
data() {
return {
total: 0
}
},
methods: {
handleRequestSuccess(response) {
this.total = response.total
}
}
}
</script>
<template>
<app-container>
<my-question-list :hasCollection="false" :requestParams="{ type: 2 }" @request-success="handleRequestSuccess">
<template #title>收藏总数:{{ total }}</template>
</my-question-list>
</app-container>
</template>
<script>
import AppContainer from '@/components/AppContainer'
import MyQuestionList from '@/components/MyQuestionList'
export default {
components: { AppContainer, MyQuestionList },
data() {
return {
total: 0
}
},
methods: {
handleRequestSuccess(response) {
this.total = response.collection_total
}
}
}
</script>
<template>
<app-container>
<my-question-list :requestParams="{ type: 1 }" @request-success="handleRequestSuccess">
<template #title>错题总数:{{ total }}</template>
</my-question-list>
</app-container>
</template>
<script>
import AppContainer from '@/components/AppContainer'
import MyQuestionList from '@/components/MyQuestionList'
export default {
components: { AppContainer, MyQuestionList },
data() {
return {
total: 0
}
},
methods: {
handleRequestSuccess(response) {
this.total = response.error_total
}
}
}
</script>
......@@ -26,15 +26,5 @@ export default [
},
...userGroup
]
},
/* 我的 */
{
path: '/my',
component: () => import('@/pages/my/layout'),
redirect: '/my/course',
children: [
{ path: 'course', component: () => import(/* webpackChunkName: "my" */ '@/pages/my/course') },
{ path: 'questions', component: () => import(/* webpackChunkName: "my" */ '@/pages/my/questions/questionAll') }
]
}
]
import Vue from 'vue'
import Vuex from 'vuex'
import { getUser, logout, getIsVip, createGuestUser } from '@/api/account'
import { getUser, logout } from '@/api/account'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
user: {},
isVip: false,
isLogin: false,
isIos: /iphone|ipad|ipod/i.test(navigator.userAgent),
isAndroid: /android/i.test(navigator.userAgent),
isWeapp: /miniProgram/.test(navigator.userAgent),
guestUser: { user_id: '', student_id: '' }
isAndroid: /android/i.test(navigator.userAgent)
},
mutations: {
setUser(state, user) {
state.user = user
},
setIsWeapp(state, isWeapp) {
state.isWeapp = isWeapp
},
setIsLogin(state, isLogin) {
state.isLogin = isLogin
},
setIsVip(state, isVip) {
state.isVip = isVip
},
setGuestUser(state, user) {
state.guestUser = user
window.localStorage.setItem('guestUser', JSON.stringify(user))
}
},
actions: {
......@@ -50,7 +37,7 @@ const store = new Vuex.Store({
async checkLogin({ commit }) {
const isLogin = await getUser()
.then(response => {
commit('setUser', response)
commit('setUser', response.data)
return true
})
.catch(() => {
......@@ -59,41 +46,8 @@ const store = new Vuex.Store({
})
commit('setIsLogin', isLogin)
return isLogin
},
// 检测是否付费
async checkIsVip({ commit, state }) {
if (!state.isVip) {
await getIsVip().then(response => commit('setIsVip', response.is_vip))
}
return state.isVip
},
// 创建游客用户
async createGuestUser({ commit, state }) {
const { user_id: userId, student_id: studentId } = state.guestUser
if (!userId || !studentId) {
await createGuestUser().then(response => commit('setGuestUser', response))
}
return state.guestUser
},
// 加载本地游客信息
loadGuestUser({ commit, state }) {
const localGuestUser = window.localStorage.getItem('guestUser')
let guestUser = { user_id: '', student_id: '' }
if (localGuestUser) {
try {
guestUser = JSON.parse(localGuestUser)
} catch (error) {
console.log(error)
}
}
commit('setGuestUser', guestUser)
}
}
})
export default store
// 加载本地游客用户
// store.dispatch('loadGuestUser')
// 检测是否付费
// store.dispatch('checkIsVip')
......@@ -6,18 +6,10 @@ export default class BeforeEnter {
}
async update(to, from, next) {
// 设置游客用户信息
const { user_id: userId, student_id: studentId } = to.query
if (userId && studentId) {
store.commit('setGuestUser', { user_id: userId, student_id: studentId })
}
// 创建游客用户
// await store.dispatch('createGuestUser')
const isLogin = store.state.isLogin || (await store.dispatch('checkLogin'))
if (to.meta.requiredLogin && !isLogin) {
next(`/login?redirect_uri=${encodeURIComponent(window.location.href)}`)
// if (to.meta.requiredLogin && !isLogin) {
if (!isLogin) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return
}
next()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论