更新:访客模式可以查看图书首页

This commit is contained in:
2025-12-12 14:33:47 +08:00
parent 04e2196942
commit 34d6cfdf9e
10 changed files with 43 additions and 53 deletions

22
App.vue
View File

@@ -3,31 +3,9 @@
import update from "@/uni_modules/uni-upgrade-center-app/utils/check-update"; import update from "@/uni_modules/uni-upgrade-center-app/utils/check-update";
// #endif // #endif
import { useUserStore } from '@/stores/user'
export default { export default {
onLaunch: function() { onLaunch: function() {
const userStore = useUserStore()
console.log('App Launch') console.log('App Launch')
// 保存原生 switchTab 方法
const originalSwitchTab = uni.switchTab;
uni.switchTab = (options) => {
if (options.url.includes('/pages/book/index') && !uni.getStorageSync('token')) {
uni.showModal({
title: '提示',
content: '请先登录后访问该页面',
confirmText: '去登录',
success: (res) => {
console.log(res, 'res');
if (res.confirm) uni.navigateTo({
url: '/pages/login/login'
});
}
});
return; // 拦截跳转
}
// 已登录/非拦截页 → 执行原生跳转
originalSwitchTab.call(uni, options);
}
// 检测自动更新 // 检测自动更新
// #ifdef APP-PLUS // #ifdef APP-PLUS
update(); update();

View File

@@ -42,7 +42,7 @@ export const bookHomeApi = {
*/ */
getRecommendBooks() { getRecommendBooks() {
return skeletonClient.request<IRecommendBooksResponse>({ return skeletonClient.request<IRecommendBooksResponse>({
url: 'bookAbroad/home/getRecommendBooks', url: uni.getStorageSync('token') ? 'bookAbroad/home/getRecommendBooks' : 'visitor/bookAbroad/getRecommendBooks',
method: 'POST', method: 'POST',
data: {} data: {}
}) })
@@ -54,7 +54,7 @@ export const bookHomeApi = {
*/ */
getBookLabelList(type: number) { getBookLabelList(type: number) {
return skeletonClient.request<ILabelListResponse>({ return skeletonClient.request<ILabelListResponse>({
url: 'bookAbroad/home/getBookAbroadLableList', url: uni.getStorageSync('token') ? 'bookAbroad/home/getBookAbroadLableList' : 'visitor/bookAbroad//getBookAbroadLableList',
method: 'POST', method: 'POST',
data: { type } data: { type }
}) })
@@ -66,7 +66,7 @@ export const bookHomeApi = {
*/ */
getSubLabelList(pid: number) { getSubLabelList(pid: number) {
return skeletonClient.request<ILabelListResponse>({ return skeletonClient.request<ILabelListResponse>({
url: 'bookAbroad/home/getBookAbroadLableListByPid', url: uni.getStorageSync('token') ? 'bookAbroad/home/getBookAbroadLableListByPid' : 'visitor/bookAbroad//getBookAbroadLableListByPid',
method: 'POST', method: 'POST',
data: { pid } data: { pid }
}) })
@@ -78,7 +78,7 @@ export const bookHomeApi = {
*/ */
getBooksByLabel(lableId: number) { getBooksByLabel(lableId: number) {
return skeletonClient.request<IBookListResponse>({ return skeletonClient.request<IBookListResponse>({
url: 'bookAbroad/home/getAbroadBookListByLable', url: uni.getStorageSync('token') ? 'bookAbroad/home/getAbroadBookListByLable' : 'visitor/bookAbroad/getAbroadBookListByLable',
method: 'POST', method: 'POST',
data: { lableId } data: { lableId }
}) })

View File

@@ -2,7 +2,6 @@
import { mainClient, skeletonClient } from '@/api/clients' import { mainClient, skeletonClient } from '@/api/clients'
import type { IApiResponse } from '@/api/types' import type { IApiResponse } from '@/api/types'
import type { IAgreement } from '@/types/user' import type { IAgreement } from '@/types/user'
import { useUserStore } from '@/stores/user'
export const commonApi = { export const commonApi = {
/** /**
@@ -37,9 +36,8 @@ export const commonApi = {
* @returns 消息列表 * @returns 消息列表
*/ */
getMessageList(isBook: number, isMedical: number, isSociology: number) { getMessageList(isBook: number, isMedical: number, isSociology: number) {
const userStore = useUserStore()
return skeletonClient.request<IApiResponse>({ return skeletonClient.request<IApiResponse>({
url: userStore.token ? 'common/message/listByPage' : '/visitor/listByPage', url: uni.getStorageSync('token') ? 'common/message/listByPage' : '/visitor/listByPage',
method: 'POST', method: 'POST',
data: { isBook, isMedical, isSociology } data: { isBook, isMedical, isSociology }
}) })

View File

@@ -13,7 +13,6 @@ import type {
} from '@/types/course' } from '@/types/course'
import type { ISearchRequest, ISearchResponse } from '@/types/search' import type { ISearchRequest, ISearchResponse } from '@/types/search'
import type { ICommentListResponse, IAddCommentResponse, IComment } from '@/types/comment' import type { ICommentListResponse, IAddCommentResponse, IComment } from '@/types/comment'
import { useUserStore } from '@/stores/user'
/** /**
* 课程相关API * 课程相关API
@@ -55,9 +54,8 @@ export const courseApi = {
page: number, page: number,
limit: number limit: number
}) { }) {
const userStore = useUserStore()
return skeletonClient.request<IMarketCourseListResponse>({ return skeletonClient.request<IMarketCourseListResponse>({
url: userStore.token ? 'medical/home/getMarketCourseList' : 'visitor/getMarketCourseList', url: uni.getStorageSync('token') ? 'medical/home/getMarketCourseList' : 'visitor/getMarketCourseList',
method: 'POST', method: 'POST',
data data
}) })

View File

@@ -7,8 +7,6 @@ import type {
IMarketCourseListResponse, IMarketCourseListResponse,
ICourseMedicalLabelsResponse ICourseMedicalLabelsResponse
} from '@/types/course' } from '@/types/course'
import { useUserStore } from '@/stores/user'
import { skeletonClient } from '../clients'
const client = createRequestClient({ baseURL: SERVICE_MAP.MAIN }) const client = createRequestClient({ baseURL: SERVICE_MAP.MAIN })
@@ -23,9 +21,8 @@ export const courseSubjectClassificationApi = {
* @returns 分类数据 * @returns 分类数据
*/ */
getCourseMedicalTree() { getCourseMedicalTree() {
const userStore = useUserStore()
return client.request<ICourseCategoryResponse>({ return client.request<ICourseCategoryResponse>({
url: userStore.token ? 'medical/home/getCourseMedicalTree' : '/visitor/getCourseMedicalTree', url: uni.getStorageSync('token') ? 'medical/home/getCourseMedicalTree' : '/visitor/getCourseMedicalTree',
method: 'POST', method: 'POST',
data: {} data: {}
}) })

View File

@@ -35,16 +35,16 @@
<view class="mine-1"> <view class="mine-1">
<text class="mine-title">{{ $t('bookHome.block1') }}</text> <text class="mine-title">{{ $t('bookHome.block1') }}</text>
<view <view
v-if="data.page.records.length > 0" v-if="data?.page?.records.length > 0"
class="mine-more" class="mine-more"
@click="handleMoreClick" @click="handleMoreClick"
> >
{{ $t('bookHome.more') }} {{ $t('bookHome.more') }}
<image src="@/static/icon/icon_right.png" /> <image src="@/static/icon/icon_right.png" />
</view> </view>
<view v-if="data.page.records.length > 0" class="mine-1-list"> <view v-if="data?.page?.records.length > 0" class="mine-1-list">
<view <view
v-for="(item, index) in data.page.records" v-for="(item, index) in data?.page?.records"
:key="index" :key="index"
class="mine-item" class="mine-item"
@click="handleMyBookClick(item.id)" @click="handleMyBookClick(item.id)"
@@ -284,7 +284,7 @@ const vipInfo = computed(() => userStore.userInfo?.userEbookVip?.[0] || null)
/** /**
* 获取我的书单 * 获取我的书单
*/ */
const getMyBooks = () => bookHomeApi.getMyBooks(1, 10) const getMyBooks = () => uni.getStorageSync('token') ? bookHomeApi.getMyBooks(1, 10) : []
/** /**
* 获取推荐图书 * 获取推荐图书
@@ -364,6 +364,8 @@ const handleMyBookClick = (bookId: number) => {
* 处理图书点击 * 处理图书点击
*/ */
const handleBookClick = (bookId: number) => { const handleBookClick = (bookId: number) => {
getPrompt()
if(!uni.getStorageSync('token')) return
uni.navigateTo({ uni.navigateTo({
url: `/pages/book/detail?id=${bookId}` url: `/pages/book/detail?id=${bookId}`
}) })
@@ -382,6 +384,8 @@ const handleMoreClick = () => {
* 处理活动标签点击 * 处理活动标签点击
*/ */
const handleActivityLabelClick = async (labelId: number, index: number) => { const handleActivityLabelClick = async (labelId: number, index: number) => {
getPrompt()
if(!uni.getStorageSync('token')) return
currentActivityIndex.value = index currentActivityIndex.value = index
activityBooksSkeleton.value.reload() activityBooksSkeleton.value.reload()
} }
@@ -404,6 +408,25 @@ const handleCategoryLevel2Click = async (labelId: number, index: number) => {
categoryBooksSkeleton.value.reload() categoryBooksSkeleton.value.reload()
} }
/**
* 登录提示语
*/
const getPrompt = () => {
if(!uni.getStorageSync('token')) {
uni.showModal({
title: '提示',
content: '请先登录后访问该页面',
confirmText: '去登录',
success: (res) => {
console.log(res , 'res');
if (res.confirm) uni.navigateTo({
url: '/pages/login/login'
});
}
});
}
}
/** /**
* 页面显示 * 页面显示
*/ */

View File

@@ -457,17 +457,11 @@ const requestAll = async () => {
* 页面挂载 * 页面挂载
*/ */
onMounted(() => { onMounted(() => {
if(!userStore.token) {
uni.navigateTo({
url: '/pages/login/login'
});
}
// 重置分类索引 // 重置分类索引
currentIndex.value = 0 currentIndex.value = 0
// 请求所有数据 // 请求所有数据
requestAll() requestAll()
console.log('进来了2');
}) })
/** /**
@@ -485,7 +479,7 @@ onShow(() => {
// 刷新数据 // 刷新数据
// requestAll() // requestAll()
if(userStore.token){ if(uni.getStorageSync('token')){
getLearnCourse() getLearnCourse()
} }
}) })

View File

@@ -1,5 +1,5 @@
<template> <template>
<view class="user-page" :style="{ paddingTop: getNotchHeight() + 30 + 'px' }" v-if="userStore.token && uni.getStorageSync('token')"> <view class="user-page" :style="{ paddingTop: getNotchHeight() + 30 + 'px' }" v-if="tokenState">
<!-- 设置图标 --> <!-- 设置图标 -->
<view class="settings-icon" :style="{ top: getNotchHeight() + 30 + 'px' }" @click="goSettings"> <view class="settings-icon" :style="{ top: getNotchHeight() + 30 + 'px' }" @click="goSettings">
<wd-icon name="setting1" size="24px" color="#666" /> <wd-icon name="setting1" size="24px" color="#666" />
@@ -165,6 +165,7 @@
]) ])
// 湖分 // 湖分
const hufenData = ref() const hufenData = ref()
const tokenState = ref(false)
/** /**
* 获取平台信息 * 获取平台信息
@@ -273,9 +274,10 @@
url: '/pages/user/points/index' url: '/pages/user/points/index'
}) })
} }
onShow(() => { onShow(() => {
if (uni.getStorageSync('token')) { if (uni.getStorageSync('token')) {
tokenState.value = true
getData() getData()
} }

View File

@@ -148,7 +148,7 @@
console.log('运行Android上') console.log('运行Android上')
} else { } else {
isAndroid.value = false; isAndroid.value = false;
qudao.value = 'Google' qudao.value = 'IOS'
console.log('运行iOS上') console.log('运行iOS上')
} }
getData() getData()

View File

@@ -19,9 +19,9 @@
import { ref } from 'vue' import { ref } from 'vue'
const menuItems = ref([ const menuItems = ref([
{ // {
name: '分享APP' // name: '分享APP'
}, // },
{ {
name: '关于我们', name: '关于我们',
} }