浏览代码

注册页面:当已登录时,访问跳回首页

zweizhao 7 年之前
父节点
当前提交
de001a7ccb
共有 3 个文件被更改,包括 27 次插入8 次删除
  1. 11 1
      pages/user/register.vue
  2. 11 7
      plugins/common.js
  3. 5 0
      store/index.js

+ 11 - 1
pages/user/register.vue

@@ -67,7 +67,7 @@
     <el-button type="primary" @click="doRegist">注册</el-button>
     <div class="checks">
       <span @click="doSwitch">{{usePhone ? '邮箱' : '手机'}}注册</span>
-      <span @click="goLogin">直接登录</span>
+      <span @click="goLogin($event, true)">直接登录</span>
     </div>
     <div class="logos">
       <a
@@ -164,6 +164,14 @@ export default {
       }
     }
   },
+  mounted() {
+    if(this.$store.getters.isLogin) {
+      this.$message('你已有注册的账号')
+      setTimeout(() => {
+        location.href = '/'
+      }, 1000)
+    }
+  },
   methods: {
     chengeVerMobile(val) {
       this.ruleFormPhone.ver = val
@@ -226,6 +234,8 @@ export default {
      * @params {function} run 闭包函数,用来启动验证码内部脚本
      */
     async getVerMobile(run) {
+      // todo 验证手机号是否注册
+      // let checkRes = await this.$post('')
       let mobile = this.ruleFormPhone.mobile.split('-')[1] || ''
       if(!mobile.trim()) {
         this.$message({

+ 11 - 7
plugins/common.js

@@ -26,13 +26,17 @@ Vue.mixin({
     },
   },
   methods: {
-    goLogin() {
-      this.$alert('未登录, 前往登录', '提示', {
-        confirmButtonText: '确定',
-        callback: action => {
-          location.href = `/?loginbox=show`
-        }
-      })
+    goLogin(e, noAlert) {
+      if(noAlert) {
+        location.href = `/?loginbox=show`
+      }else {
+        this.$alert('未登录, 前往登录', '提示', {
+          confirmButtonText: '确定',
+          callback: action => {
+            location.href = `/?loginbox=show`
+          }
+        })
+      }
     },
     noCompetence(title = "没有权限") {
       this.$alert(title, '提示', {

+ 5 - 0
store/index.js

@@ -9,6 +9,11 @@ const store = () => new Vuex.Store({
     userinfo: {},
     wxConfig: {},
   },
+  getters: {
+    isLogin(state) {
+      return !!state.userinfo.nickname
+    }
+  },
   mutations: {
     updateUserinfo(state, payload) {
       state.userinfo = payload.userinfo