Browse Source

兼职招聘投递 判断登录

xinfeng 6 years ago
parent
commit
c27daaf9a2
2 changed files with 31 additions and 10 deletions
  1. 3 0
      pages/job/_post/_id.vue
  2. 28 10
      plugins/common.js

+ 3 - 0
pages/job/_post/_id.vue

@@ -235,6 +235,9 @@
           return
         }
         //未签约,弹出提示
+        if (! await this.checkLogin(true)) {
+          return
+        }
         let {realname_re} = this.$store.state.userinfo
         realname_re = Number(realname_re)
         if (realname_re !== 2) {

+ 28 - 10
plugins/common.js

@@ -4,18 +4,17 @@ import Vue from 'vue'
 Vue.mixin({
   async fetch({ $axios, store, req }) {
     let headers = req && req.headers
-    let res = await $axios.$get('/api/user/getInfo', {headers});
-    if(res && res.data) {
+    let res = await $axios.$get('/api/user/getInfo', { headers });
+    if (res && res.data) {
       store.commit('updateUserinfo', { userinfo: res.data || {} })
     }
   },
-  components: {
-  },
+  components: {},
   data() {
-    return {
-    }
+    return {}
+  },
+  mounted() {
   },
-  mounted() {},
   computed: {
     userinfo() {
       return this.$store.state.userinfo
@@ -31,6 +30,25 @@ Vue.mixin({
         this.goLogin();
       }
     },
+    async checkLogin(goLogin = false) {
+      const userInfo = await this.getUserInfo();
+      if (!userInfo || !userInfo.nickname) {
+        this.$message.error('请先登录!')
+        if (goLogin) {
+          const { app } = this.$deviceType
+         
+          if (app) {
+            location.href = 'proginn://login'
+          } else if (location.origin.indexOf('local') !== 1 || location.origin.indexOf('dev') !== 1 ) {
+            location.href = 'https://dev.test.proginn.com/?loginbox=show'
+          } else {
+            location.href = 'https://www.proginn.com/?loginbox=show'
+          }
+        }
+        return false
+      }
+      return true
+    },
     async needVerify() {
       const userInfo = await this.getUserInfo();
       // 1是待审核,2审核通过,3是拒绝
@@ -56,9 +74,9 @@ Vue.mixin({
       location.href = 'https://www.proginn.com/';
     },
     goLogin(e, noAlert) {
-      if(noAlert) {
+      if (noAlert) {
         location.href = `https://www.proginn.com/?loginbox=show`
-      }else {
+      } else {
         this.$message.closeAll()
         this.$alert('未登录, 前往登录', '提示', {
           confirmButtonText: '确定',
@@ -79,7 +97,7 @@ Vue.mixin({
     async updateUserInfo() {
       let res = await this.$axios.$get('/api/user/getInfo');
       console.log('res', res.data)
-      if(res && res.data) {
+      if (res && res.data) {
         this.$store.commit('updateUserinfo', { userinfo: res.data || {} })
       }
     },