Selaa lähdekoodia

开发用户注册,登录,忘记密码接口

reghao 4 vuotta sitten
vanhempi
commit
2f79df4570

+ 10 - 0
src/api/user/account.js

@@ -0,0 +1,10 @@
+import $axios from '../index'
+
+const accountApi = {
+  regVerifyCodeApi: '/api/user/account/getcode'
+}
+
+// 获取注册验证码
+export function getRegVerifyCode(email) {
+  return $axios.get(accountApi.regVerifyCodeApi + '?email=' + email)
+}

+ 66 - 10
src/components/register-from.vue

@@ -23,6 +23,36 @@
         />
       </v-col>
     </v-row>
+    <v-row justify="center">
+      <v-col cols="10">
+        <v-row justify="center">
+          <v-col cols="5">
+            <v-text-field
+              v-model="registerUser.regVerifyCode"
+              placeholder="请输入验证码"
+              label="验证码"
+              :rules="[() => registerUser.regVerifyCode != null || '验证码不能为空']"
+              type="email"
+              clearable
+            />
+          </v-col>
+          <v-col cols="5">
+            <v-btn color="primary" @click="getVerifyCode">获取验证码</v-btn>
+          </v-col>
+        </v-row>
+      </v-col>
+      <!--<v-col cols="10">
+        <v-text-field
+          v-model="registerUser.email"
+          placeholder="请输入验证码"
+          label="验证码"
+          :rules="[() => registerUser.email != null || '验证码不能为空']"
+          type="email"
+          clearable
+        />
+        <v-btn color="primary" @click="getVerifyCode">获取验证码</v-btn>
+      </v-col>-->
+    </v-row>
     <v-row justify="center">
       <v-col cols="10">
         <v-text-field
@@ -78,11 +108,14 @@
 </template>
 
 <script>
+import { getRegVerifyCode } from '@/api/user/account'
+
 export default {
   name: 'Register',
   data() {
     return {
       captchaUrl: '/api/user/account/captcha',
+      showMessage: false,
       registerUser: {
         regType: 1,
         username: '',
@@ -97,8 +130,6 @@ export default {
   },
   methods: {
     submitRegister() {
-      console.log('用户注册')
-
       var re = /^(([^()[\]\\.,;:\s@\"]+(\.[^()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
       if (!re.test(this.registerUser.email)) {
         console.log('email 字段不符合要求')
@@ -117,19 +148,44 @@ export default {
       }
 
       /* if (this.registerUser.username !== 'admin') {
-        return
-      }*/
+                  return
+                }*/
 
       /* if (this.registerUser.mobile !== '') {
-        var myreg = /^[1][3,4,5,7,8][0-9]{9}$/
-        if (!myreg.test((this.registerUser.phone))) {
-          return
-        }
-      }*/
+                  var myreg = /^[1][3,4,5,7,8][0-9]{9}$/
+                  if (!myreg.test((this.registerUser.phone))) {
+                    return
+                  }
+                }*/
+      // 返回到父组件
       this.$emit('register', this.registerUser)
     },
     getVerifyImage() {
-      this.captchaUrl = '/api/user/account/captcha'
+      this.captchaUrl = '/api/user/account/captcha?t=' + new Date().getTime()
+    },
+    getVerifyCode() {
+      var email = this.registerUser.email
+      if (email == null || email === '') {
+        alert('请输入邮箱地址')
+        return
+      }
+
+      getRegVerifyCode(email)
+        .then(res => {
+          if (res.code === 0) {
+            alert(res.msg)
+          } else {
+            this.$notify({
+              title: res.code,
+              message: res.msg,
+              type: 'warning',
+              duration: 500
+            })
+          }
+        })
+        .catch(error => {
+          this.$message.error(error.message)
+        })
     }
   }
 }

+ 1 - 1
src/components/setting/user-password-setting.vue

@@ -111,7 +111,7 @@ export default {
   },
   methods: {
     getVerifyImage() {
-      this.captchaUrl = '/api/user/account/captcha'
+      this.captchaUrl = '/api/user/account/captcha?t=' + new Date().getTime()
     },
     save() {
       if (this.passoword.oldPassword === '') {

+ 4 - 3
src/views/login.vue

@@ -104,9 +104,10 @@ export default {
       }).then(response => response.json())
         .then(json => {
           if (json.code === 0) {
-            const user = json.data
-            // 保存用户
-            this.$store.commit('setUserInfo', user)
+            const userInfo = json.data
+            console.log(userInfo)
+            // 保存用户信息
+            this.$store.commit('setUserInfo', userInfo)
             // 跳转到首页
             this.$router.push('/')
           } else {