Browse Source

feat: 文库详情页未登录跳转到登录页

Signed-off-by: tangshizhe <48740614+tangshizhe@users.noreply.github.com>
tangshizhe 1 năm trước cách đây
mục cha
commit
d773f924b7

+ 5 - 0
jydocs-mobile/src/App.vue

@@ -13,6 +13,7 @@
 import layout from '@/components/layout.vue'
 import { iosBackRefresh } from '@/utils/globalFunctions'
 import { hiddenBottomBar } from '@/utils/globalFunctionsForApp'
+import { mapActions } from 'vuex'
 export default {
   name: 'App',
   components: {
@@ -36,8 +37,12 @@ export default {
   mounted () {
     hiddenBottomBar()
     this.bindEventsForH5()
+    this.getLoginStatus()
   },
   methods: {
+    ...mapActions({
+      getLoginStatus: 'main/getLoginStatus'
+    }),
     bindEventsForH5 () {
       if (this.$envs.inH5) {
         iosBackRefresh()

+ 9 - 0
jydocs-mobile/src/api/main.ts

@@ -129,3 +129,12 @@ export function getAccountInfo () {
     method: 'post'
   })
 }
+
+// 获取用户手机号邮箱等信息
+export function getUserID () {
+  return $request({
+    baseURL: '',
+    url: '/jypay/user/getSimpleData',
+    method: 'post'
+  })
+}

+ 16 - 2
jydocs-mobile/src/store/modules/main.ts

@@ -15,7 +15,8 @@ import {
   getShare,
   getDocPay,
   getIndexTags,
-  getAccountInfo
+  getAccountInfo,
+  getUserID
 } from '@/api/main'
 
 interface InterfaceStore<S> extends StoreOptions<S> {
@@ -77,7 +78,8 @@ const modulesOption: modulesOption = {
     // 页面数据缓存(用于跳出页面返回时恢复)
     homePageData: recoveryPageData('jy-docs-home-page'),
     searchPageData: recoveryPageData('jy-docs-search-page'),
-    userLib: recoveryPageData('jy-docs-user-lib')
+    userLib: recoveryPageData('jy-docs-user-lib'),
+    loginInfo: {}
   },
   mutations: {
     // 保存首页数据
@@ -87,6 +89,10 @@ const modulesOption: modulesOption = {
       }
       sessionStorage.setItem('jy-docs-home-page', JSON.stringify(state.homePageData))
     },
+    saveLoginInfo (state, data) {
+      state.loginInfo = data.data
+      sessionStorage.setItem('jy-login-info', JSON.stringify(data.data))
+    },
     // 搜索页面数据
     saveSearchPageState (state, data) {
       console.log(data)
@@ -124,6 +130,14 @@ const modulesOption: modulesOption = {
     }
   },
   actions: {
+    // 获取登录状态
+    async getLoginStatus (state) {
+      try {
+        const res = await getUserID()
+        state.commit('saveLoginInfo', res)
+        return res
+      } catch (error) {}
+    },
     // 首页数据
     async getHome (state) {
       getHomeHot({ sign: 'new', num: 5 }).then((res: APIStructure) => {

+ 10 - 0
jydocs-mobile/src/views/details/details.vue

@@ -284,6 +284,7 @@ export default class extends Vue {
   getDown: any
   getShow: any
   getShare: any
+  loginInfo: any
   links = ''
   docIds = ''
   fixed = false
@@ -338,6 +339,10 @@ export default class extends Vue {
     this.onList()
   }
 
+  mounted () {
+    this.loginInfo = sessionStorage.getItem('jy-login-info')
+  }
+
   get isvipFree () { // 会员免费
     return this.detailData.productType === 1
   }
@@ -431,6 +436,11 @@ export default class extends Vue {
   }
 
   async bottomBtn (type: string) {
+    // 未登录跳转登录
+    if (!this.loginInfo || !this.loginInfo.userId) {
+      window.location.href = '/jyapp/free/login?to=back'
+      return
+    }
     switch (type) {
       case '开通文库会员': {
         window.location.href = '/jy_mobile/order/create/docsvip/?type=buy'