Jelajahi Sumber

Register.vue 页面根据后端返回的"开放注册状态"来判断是否展示注册 form

reghao 5 bulan lalu
induk
melakukan
535e6f2c40
2 mengubah file dengan 34 tambahan dan 17 penghapusan
  1. 6 0
      src/api/account.js
  2. 28 17
      src/views/Register.vue

+ 6 - 0
src/api/account.js

@@ -11,6 +11,7 @@ const accountApi = {
   forgotApi: '/api/auth/forgot',
   loginApi: '/api/auth/signin',
   logoutApi: '/api/auth/signout',
+  getRegistryStatusApi: '/api/auth/registry',
   resetPasswordApi: '/api/account/user/reset',
   accountMyVipApi: '/api/user/vip/my',
   accountVipPlanApi: '/api/user/vip/plan',
@@ -70,6 +71,11 @@ export function logout() {
   return get(accountApi.logoutApi)
 }
 
+// 获取注册开放状态
+export function getRegistryStatus() {
+  return get(accountApi.getRegistryStatusApi)
+}
+
 export function updateAvatar(userAvatar) {
   return post(accountApi.updateAvatarApi, userAvatar)
 }

+ 28 - 17
src/views/Register.vue

@@ -13,12 +13,12 @@
                 <span>注册帐号</span>
               </div>
               <div class="text item">
-                <el-form ref="form" :model="userRegistry" label-width="100px">
-                  <el-form-item label="邮箱/手机号" label-width="100px">
+                <el-form v-if="registryEnable" ref="form" :model="userRegistry" label-width="100px">
+                  <el-form-item label="帐号" label-width="90px">
                     <el-input
                       v-model="userRegistry.principal"
                       placeholder="请输入邮箱或手机号"
-                      style="width: 45%; padding-right: 10px"
+                      style="width: 45%; padding-right: 5px"
                       clearable
                     />
                     <el-button :disabled="isBtn" @click="registerVerifyCode">{{ code }}</el-button>
@@ -31,7 +31,7 @@
                       clearable
                     />
                   </el-form-item>
-                  <el-form-item label="密码">
+                  <el-form-item label="密码" label-width="90px">
                     <el-input
                       v-model="userRegistry.credential"
                       type="password"
@@ -49,15 +49,12 @@
                       clearable
                     />
                   </el-form-item>
-                  <el-form-item>
-                    <el-button
-                      type="primary"
-                      :loading="isLoading"
-                      @click.native="registerBtn"
-                    >注册</el-button>
-                    <el-button type="plain" @click="login">返回登入</el-button>
-                  </el-form-item>
                 </el-form>
+                <div v-else class="text item">
+                  <span>系统当前未开放注册</span>
+                </div>
+                <el-button v-if="registryEnable" type="primary" :loading="isLoading" @click.native="registerBtn">注册</el-button>
+                <el-button type="plain" @click="login">返回登入</el-button>
               </div>
             </el-card>
           </el-row>
@@ -70,6 +67,7 @@
 <script>
 import { userMixin } from 'assets/js/mixin'
 import LoginBar from 'components/layout/LoginBar'
+import { getRegistryStatus } from '@/api/account'
 
 export default {
   name: 'Register',
@@ -77,20 +75,33 @@ export default {
     LoginBar
   },
   mixins: [userMixin],
+  data() {
+    return {
+      registryEnable: false
+    }
+  },
   watch: {
     $route() {
       this.$router.go()
     }
   },
+  mounted() {
+    this.getData()
+  },
   created() {
     document.title = '注册帐号'
-    this.fetchPubkey(2)
-  },
-  data() {
-    return {
-    }
   },
   methods: {
+    getData() {
+      getRegistryStatus().then(resp => {
+        if (resp.code === 0) {
+          this.registryEnable = resp.data
+          if (this.registryEnable) {
+            this.fetchPubkey(2)
+          }
+        }
+      })
+    },
     login() {
       this.$router.push('/login')
     }