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

添加我的页面

上级 c65d9246
......@@ -2,7 +2,11 @@
<van-collapse v-model="activeNames">
<van-collapse-item :title="item.name" :name="item.id" v-for="item in data" :key="item.id">
<ul>
<li v-for="subItem in item.children" :key="subItem.id">{{subItem.name}}</li>
<li
v-for="subItem in item.children"
:key="subItem.id"
@click="onClick(subItem)"
>{{subItem.name}}</li>
</ul>
</van-collapse-item>
</van-collapse>
......@@ -11,6 +15,7 @@
<script>
export default {
props: {
courseId: String,
data: {
type: Array,
default: () => []
......@@ -20,6 +25,22 @@ export default {
return {
activeNames: []
}
},
computed: {
isWeapp() {
return this.$store.state.isWeapp
}
},
methods: {
onClick(data) {
if (this.isWeapp) {
wx.miniProgram.navigateTo({
url: `/pages/course/item?id=${this.courseId}&chapter_id=${data.id}`
})
} else {
window.alert('请在微信小程序中打开')
}
}
}
}
</script>
......
......@@ -9,7 +9,7 @@
@click="onTabClick"
>
<van-tab title="课程学习" name="0">
<course-chapter :data="detail.chapters"></course-chapter>
<course-chapter :courseId="courseId" :data="detail.chapters"></course-chapter>
</van-tab>
<van-tab title="知识点速学" name="1">
<course-tag></course-tag>
......
......@@ -10,7 +10,7 @@
</div>
<div class="nav">
<ul class="nav-list">
<li class="nav-item" @click="onClickNav('courseLearn')">
<li class="nav-item" @click="onClickNav('courseLearn', true)">
<img src="../../assets/images/home_menu_01.png" alt="课程学习" />
</li>
<li class="nav-item" @click="onClickNav('courseTest')">
......@@ -63,31 +63,32 @@ export default {
}
},
// 点击导航
async onClickNav(name) {
const isLogin = await this.$store.dispatch('checkLogin')
if (isLogin) {
// 已登录
if (this.isWeapp) {
// 小程序
wx.miniProgram.navigateTo({
url: `/pages/web/index?src=${window.location.origin}/course/learn`
})
} else {
// h5
this.$router.push({ name })
}
} else {
// 未登录
async onClickNav(name, requireLogin) {
const map = {
courseLearn: `/pages/web/index?src=${window.location.origin}/course/learn`,
courseTest: `/pages/web/index?src=${window.location.origin}/test`
}
const isLogin = requireLogin
? await this.$store.dispatch('checkLogin')
: false
// 未登录
if (requireLogin && !isLogin) {
if (this.isWeapp) {
// 小程序
wx.miniProgram.navigateTo({
url: `/pages/web/index?src=${window.location.origin}/login`
})
} else {
// h5
this.$router.push({ name: 'login' })
}
}
if (this.isWeapp) {
// 小程序
wx.miniProgram.navigateTo({ url: map[name] })
return
}
// h5
this.$router.push({ name })
}
},
beforeMount() {
......
<template></template>
<script>
export default {
name: 'my'
}
</script>
......@@ -37,5 +37,11 @@ export default [
path: '/login',
name: 'login',
component: () => import('../pages/login/login.vue')
},
// 我的
{
path: '/my',
name: 'my',
component: () => import('../pages/my/index.vue')
}
]
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论