reghao před 3 roky
rodič
revize
96b49f043d

binární
public/logo.png


+ 6 - 6
src/api/user/account.js

@@ -4,9 +4,9 @@ const accountApi = {
   checkUsernameApi: '/api/user/account/check/username',
   selectUsernameApi: '/api/user/account/select/username',
   checkEmailApi: '/api/user/account/check/email',
-  regVerifyCodeApi: '/api/user/verifyCode',
-  registerApi: '/api/user/account/register',
-  userInfoApi: '/api/user/info'
+  verifyCodeApi: '/api/account/verifyCode',
+  registerApi: '/api/account/user/register',
+  userInfoApi: '/api/account/user/info'
 }
 
 export function getBase64Captcha(captchaUrl) {
@@ -25,9 +25,9 @@ export function isEmailExist(email) {
   return $axios.get(accountApi.checkEmailApi + '/' + email)
 }
 
-// 获取注册验证码
-export function getRegVerifyCode(verifyCode) {
-  return $axios.post(accountApi.regVerifyCodeApi, verifyCode)
+// 获取验证码
+export function getVerifyCode(verifyCode) {
+  return $axios.post(accountApi.verifyCodeApi, verifyCode)
 }
 
 export function register(userRegistry) {

+ 3 - 3
src/api/user/auth.js

@@ -1,9 +1,9 @@
 import $axios from '../index'
 
 const authApi = {
-  pubkeyApi: '/api/auth/pubkey',
-  loginApi: '/api/auth/login',
-  logoutApi: '/api/auth/logout'
+  pubkeyApi: '/api/account/pubkey',
+  loginApi: '/api/account/auth/signin',
+  logoutApi: '/api/account/auth/signout'
 }
 
 // 登录

+ 144 - 0
src/components/mobile-login-form.vue

@@ -0,0 +1,144 @@
+<template>
+  <div>
+    <v-row justify="center">
+      <v-col cols="10">
+        <v-text-field
+          v-model="userLogin.username"
+          placeholder="请输入手机号/邮箱"
+          label="手机号/邮箱"
+          :rules="[() => userLogin.username != null || '手机号/邮箱不能为空']"
+          clearable
+        />
+      </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="userLogin.password"
+              placeholder="请输入验证码"
+              label="验证码"
+              :rules="[() => userLogin.password != null || '验证码不能为空']"
+              clearable
+            />
+          </v-col>
+          <v-col cols="5">
+            <v-btn color="primary" @click="getVerifyCode">获取验证码</v-btn>
+          </v-col>
+        </v-row>
+      </v-col>
+    </v-row>
+    <v-row justify="center">
+      <v-col cols="5">
+        <img :src="captchaUrl" alt="图形验证码" title="点击刷新" style="cursor:pointer;" @click="getCaptcha">
+      </v-col>
+      <v-col cols="5">
+        <v-text-field
+          v-model="userLogin.captchaCode"
+          placeholder="图形验证码"
+          label="图形验证码"
+          :rules="[() => userLogin.captchaCode != null || '图形验证码不能为空']"
+          clearable
+        />
+      </v-col>
+    </v-row>
+    <v-row justify="center">
+      <v-btn color="primary" @click="submitLogin">登录/注册</v-btn>
+    </v-row>
+  </div>
+</template>
+
+<script>
+import { randomString, getCaptchaUrl } from '@/utils'
+import { getVerifyCode } from '@/api/user/account'
+import { getPubkey } from '@/api/user/auth'
+import { JSEncrypt } from 'jsencrypt'
+
+export default {
+  name: 'Register',
+  data() {
+    return {
+      captchaUrl: '',
+      captchaBase64: '',
+      showMessage: false,
+      userLogin: {
+        loginType: 2,
+        username: '',
+        password: '',
+        captchaCode: '',
+        r: '',
+        plat: 'web'
+      },
+      getVerifyCode1: {
+        notifyType: '',
+        receiver: ''
+      }
+    }
+  },
+  created() {
+    this.getCaptcha()
+    this.fetchPubkey()
+  },
+  methods: {
+    encryptPassword(password, pubkey, pubkeyR) {
+      var encryptor = new JSEncrypt()
+      encryptor.setPublicKey(pubkey)
+      return encryptor.encrypt(pubkeyR + password)
+    },
+    submitLogin() {
+      const encryptPassword = this.$options.methods.encryptPassword(this.userLogin.password, this.pubkey, this.pubkeyR)
+      this.userLogin.password = encryptPassword
+      // 将数据返回给父组件
+      this.$emit('login', this.userLogin)
+    },
+    getCaptcha() {
+      const randomStr = randomString(10)
+      this.userLogin.r = randomStr
+      // 图片上发送点击事件时,captchaUrl 的值发生变化,然后才去请求后端
+      this.captchaUrl = getCaptchaUrl(randomStr)
+      /* getBase64Captcha(this.captchaUrl)
+        .then(res => {
+          if (res.code === 0) {
+            this.captchaBase64 = 'data:image/jpg;base64,' + res.data
+          } else {
+            alert(res.data)
+          }
+        })
+        .catch(error => {
+          console.error(error.message)
+        })*/
+    },
+    fetchPubkey() {
+      getPubkey().then(res => {
+        if (res.code === 0) {
+          this.pubkey = res.data.pubkey
+          this.pubkeyR = res.data.r
+        } else {
+          alert(res.data)
+        }
+      }).catch(error => {
+        console.error(error.message)
+      })
+    },
+    getVerifyCode() {
+      this.getVerifyCode1.receiver = this.userLogin.username
+      this.getVerifyCode1.notifyType = 1
+      getVerifyCode(this.getVerifyCode1)
+        .then(res => {
+          if (res.code === 0) {
+            alert(res.msg)
+          } else {
+            console.error(res.msg)
+          }
+        })
+        .catch(error => {
+          console.error(error.message)
+        })
+    }
+  }
+}
+</script>
+
+<style>
+</style>

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

@@ -102,7 +102,7 @@ export default {
         verifyCode: ''
       },
       temp: '',
-      captchaUrl: process.env.VUE_APP_BASE_API + '/api/user/account/captcha',
+      captchaUrl: process.env.VUE_APP_BASE_API + '/api/account/captcha',
       showMessage: false,
       message: ''
     }
@@ -111,7 +111,7 @@ export default {
   },
   methods: {
     getCaptcha() {
-      this.captchaUrl = process.env.VUE_APP_BASE_API + '/api/user/account/captcha?t=' + new Date().getTime()
+      this.captchaUrl = process.env.VUE_APP_BASE_API + '/api/account/captcha?t=' + new Date().getTime()
     },
     save() {
       if (this.passoword.oldPassword === '') {

+ 4 - 3
src/store/modules/user.js

@@ -57,13 +57,14 @@ const actions = {
         if (res.code === 0) {
           const userInfo = res.data
           const token = userInfo.token
-
-          commit('SET_USER_INFO', userInfo)
           commit('SET_TOKEN', token)
           setToken(token)
+
+          const userId = userInfo.userId
+          console.log('userId: ' + userId)
+          commit('SET_USER_INFO', userInfo)
           resolve()
         } else {
-          alert(res.data)
           console.log(res.data)
         }
       }).catch(error => {

+ 1 - 1
src/utils/index.js

@@ -11,5 +11,5 @@ export function randomString(len) {
 // 获取 captcha url
 export function getCaptchaUrl(r) {
   // 图片上发送点击事件时,captchaUrl 的值发生变化,然后才去请求后端
-  return process.env.VUE_APP_BASE_API + '/api/auth/code/captcha?r=' + r
+  return process.env.VUE_APP_BASE_API + '/api/account/captcha?r=' + r
 }

+ 11 - 10
src/views/login.vue

@@ -27,15 +27,16 @@
               <h1>{{ this.$store.state.webInfo.name }} &nbsp; &nbsp;  {{ type }}</h1>
             </v-row>
             <v-row style="height: 48px" />
-            <LoginFrom v-show="showLogin" @login="userLogin" />
-            <RegisterFrom v-show="showLogin === false" @register="userRegister" />
+            <MobileLoginForm v-show="showLogin" @login="userLogin" />
+            <!--<LoginForm v-show="showLogin === null" @login="userLogin" />
+            <RegisterFrom v-show="showLogin === false" @register="userRegister" />-->
             <v-row justify="center">
-              <v-col cols="5">
+              <!--<v-col cols="5">
                 <v-btn text color="primary">忘记密码</v-btn>
-              </v-col>
-              <v-col cols="5" style="text-align:right">
+              </v-col>-->
+              <!--<v-col cols="5" style="text-align:right">
                 <v-btn text @click="moveRegister">{{ moveMessage }}</v-btn>
-              </v-col>
+              </v-col>-->
             </v-row>
           </v-card>
         </v-col>
@@ -62,14 +63,14 @@
 </template>
 
 <script>
-import LoginFrom from '@/components/login-form.vue'
-import RegisterFrom from '@/components/register-from.vue'
+import MobileLoginForm from '@/components/mobile-login-form.vue'
+/* import LoginForm from '@/components/login-form.vue'
+import RegisterFrom from '@/components/register-from.vue' */
 
 export default {
   name: 'Login',
   components: {
-    LoginFrom,
-    RegisterFrom
+    MobileLoginForm
   },
   data() {
     return {