You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by ju...@apache.org on 2020/06/12 09:53:12 UTC

[incubator-apisix-dashboard] branch master updated: feat: patch fix

This is an automated email from the ASF dual-hosted git repository.

juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-apisix-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new d80f6cd  feat: patch fix
d80f6cd is described below

commit d80f6cd7c0e492a57508f6de078cdf9517acb22c
Author: juzhiyuan <jj...@gmail.com>
AuthorDate: Fri Jun 12 17:51:24 2020 +0800

    feat: patch fix
---
 src/config.ts             |   1 -
 src/utils/request.ts      |   3 +-
 src/views/login/index.vue | 119 +++++-----------------------------------------
 3 files changed, 12 insertions(+), 111 deletions(-)

diff --git a/src/config.ts b/src/config.ts
deleted file mode 100644
index b0c5240..0000000
--- a/src/config.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const API_KEY = 'edd1c9f034335f136f87ad84b625c8f1'
diff --git a/src/utils/request.ts b/src/utils/request.ts
index 2fb28d3..e730d5f 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -24,13 +24,12 @@
 
 import axios from 'axios'
 import { Message } from 'element-ui'
-import { API_KEY } from '@/config'
 
 const service = axios.create({
   baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
   timeout: 5000,
   headers: {
-    'X-API-KEY': API_KEY
+    'X-API-KEY': localStorage.getItem('GLOBAL_API_KEY')
   }
 })
 
diff --git a/src/views/login/index.vue b/src/views/login/index.vue
index dc79540..59257f4 100644
--- a/src/views/login/index.vue
+++ b/src/views/login/index.vue
@@ -29,7 +29,6 @@
     <el-form
       ref="loginForm"
       :model="loginForm"
-      :rules="loginRules"
       class="login-form"
       autocomplete="on"
       label-position="left"
@@ -40,42 +39,20 @@
         </h3>
       </div>
 
-      <el-form-item prop="username">
+      <el-form-item prop="apikey">
         <span class="svg-container">
           <svg-icon name="user" />
         </span>
         <el-input
-          ref="username"
-          v-model="loginForm.username"
-          :placeholder="$t('login.username')"
-          name="username"
+          ref="apikey"
+          v-model="loginForm.apikey"
+          placeholder="Please input API KEY here"
+          name="apikey"
           type="text"
           autocomplete="on"
         />
       </el-form-item>
 
-      <el-form-item prop="password">
-        <span class="svg-container">
-          <svg-icon name="password" />
-        </span>
-        <el-input
-          :key="passwordType"
-          ref="password"
-          v-model="loginForm.password"
-          :type="passwordType"
-          :placeholder="$t('login.password')"
-          name="password"
-          autocomplete="on"
-          @keyup.enter.native="handleLogin"
-        />
-        <span
-          class="show-pwd"
-          @click="showPwd"
-        >
-          <svg-icon :name="passwordType === 'password' ? 'eye-off' : 'eye-on'" />
-        </span>
-      </el-form-item>
-
       <el-button
         :loading="loading"
         type="primary"
@@ -102,10 +79,8 @@
 <script lang="ts">
 import { Component, Vue, Watch } from 'vue-property-decorator'
 import { Route } from 'vue-router'
-import { Dictionary } from 'vue-router/types/router'
 import { Form as ElForm, Input } from 'element-ui'
 import { UserModule } from '@/store/modules/user'
-import { isValidUsername } from '@/utils/validate'
 import LangSelect from '@/components/LangSelect/index.vue'
 
 @Component({
@@ -115,90 +90,18 @@ import LangSelect from '@/components/LangSelect/index.vue'
   }
 })
 export default class extends Vue {
-  private validateUsername = (rule: any, value: string, callback: Function) => {
-    if (!isValidUsername(value)) {
-      callback(new Error('Please enter the correct user name'))
-    } else {
-      callback()
-    }
-  }
-  private validatePassword = (rule: any, value: string, callback: Function) => {
-    if (value.length < 6) {
-      callback(new Error('The password can not be less than 6 digits'))
-    } else {
-      callback()
-    }
-  }
   private loginForm = {
-    username: 'admin',
-    password: '111111'
-  }
-  private loginRules = {
-    username: [{ validator: this.validateUsername, trigger: 'blur' }],
-    password: [{ validator: this.validatePassword, trigger: 'blur' }]
+    apikey: ''
   }
-  private passwordType = 'password'
   private loading = false
   private showDialog = false
   private redirect?: string
-  private otherQuery: Dictionary<string> = {}
 
-  @Watch('$route', { immediate: true })
-  private onRouteChange(route: Route) {
-    // TODO: remove the "as Dictionary<string>" hack after v4 release for vue-router
-    // See https://github.com/vuejs/vue-router/pull/2050 for details
-    const query = route.query as Dictionary<string>
-    if (query) {
-      this.redirect = query.redirect
-      this.otherQuery = this.getOtherQuery(query)
-    }
-  }
-
-  mounted() {
-    if (this.loginForm.username === '') {
-      (this.$refs.username as Input).focus()
-    } else if (this.loginForm.password === '') {
-      (this.$refs.password as Input).focus()
-    }
-  }
-
-  private showPwd() {
-    if (this.passwordType === 'password') {
-      this.passwordType = ''
-    } else {
-      this.passwordType = 'password'
-    }
-    this.$nextTick(() => {
-      (this.$refs.password as Input).focus()
-    })
-  }
-
-  private handleLogin() {
-    (this.$refs.loginForm as ElForm).validate(async(valid: boolean) => {
-      if (valid) {
-        this.loading = true
-        await UserModule.Login(this.loginForm)
-        this.$router.push({
-          path: this.redirect || '/',
-          query: this.otherQuery
-        })
-        // Just to simulate the time of the request
-        setTimeout(() => {
-          this.loading = false
-        }, 0.5 * 1000)
-      } else {
-        return false
-      }
-    })
-  }
-
-  private getOtherQuery(query: Dictionary<string>) {
-    return Object.keys(query).reduce((acc, cur) => {
-      if (cur !== 'redirect') {
-        acc[cur] = query[cur]
-      }
-      return acc
-    }, {} as Dictionary<string>)
+  private async handleLogin() {
+    console.log(this.loginForm)
+    await UserModule.Login({ username: '', password: '' })
+    localStorage.setItem('GLOBAL_API_KEY', this.loginForm.apikey)
+    window.location.replace('/dashboard')
   }
 }
 </script>