Skip to content

Commit d80f6cd

Browse files
author
juzhiyuan
committed
feat: patch fix
1 parent 5b7e154 commit d80f6cd

File tree

3 files changed

+12
-111
lines changed

3 files changed

+12
-111
lines changed

src/config.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/utils/request.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424

2525
import axios from 'axios'
2626
import { Message } from 'element-ui'
27-
import { API_KEY } from '@/config'
2827

2928
const service = axios.create({
3029
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
3130
timeout: 5000,
3231
headers: {
33-
'X-API-KEY': API_KEY
32+
'X-API-KEY': localStorage.getItem('GLOBAL_API_KEY')
3433
}
3534
})
3635

src/views/login/index.vue

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
<el-form
3030
ref="loginForm"
3131
:model="loginForm"
32-
:rules="loginRules"
3332
class="login-form"
3433
autocomplete="on"
3534
label-position="left"
@@ -40,42 +39,20 @@
4039
</h3>
4140
</div>
4241

43-
<el-form-item prop="username">
42+
<el-form-item prop="apikey">
4443
<span class="svg-container">
4544
<svg-icon name="user" />
4645
</span>
4746
<el-input
48-
ref="username"
49-
v-model="loginForm.username"
50-
:placeholder="$t('login.username')"
51-
name="username"
47+
ref="apikey"
48+
v-model="loginForm.apikey"
49+
placeholder="Please input API KEY here"
50+
name="apikey"
5251
type="text"
5352
autocomplete="on"
5453
/>
5554
</el-form-item>
5655

57-
<el-form-item prop="password">
58-
<span class="svg-container">
59-
<svg-icon name="password" />
60-
</span>
61-
<el-input
62-
:key="passwordType"
63-
ref="password"
64-
v-model="loginForm.password"
65-
:type="passwordType"
66-
:placeholder="$t('login.password')"
67-
name="password"
68-
autocomplete="on"
69-
@keyup.enter.native="handleLogin"
70-
/>
71-
<span
72-
class="show-pwd"
73-
@click="showPwd"
74-
>
75-
<svg-icon :name="passwordType === 'password' ? 'eye-off' : 'eye-on'" />
76-
</span>
77-
</el-form-item>
78-
7956
<el-button
8057
:loading="loading"
8158
type="primary"
@@ -102,10 +79,8 @@
10279
<script lang="ts">
10380
import { Component, Vue, Watch } from 'vue-property-decorator'
10481
import { Route } from 'vue-router'
105-
import { Dictionary } from 'vue-router/types/router'
10682
import { Form as ElForm, Input } from 'element-ui'
10783
import { UserModule } from '@/store/modules/user'
108-
import { isValidUsername } from '@/utils/validate'
10984
import LangSelect from '@/components/LangSelect/index.vue'
11085
11186
@Component({
@@ -115,90 +90,18 @@ import LangSelect from '@/components/LangSelect/index.vue'
11590
}
11691
})
11792
export default class extends Vue {
118-
private validateUsername = (rule: any, value: string, callback: Function) => {
119-
if (!isValidUsername(value)) {
120-
callback(new Error('Please enter the correct user name'))
121-
} else {
122-
callback()
123-
}
124-
}
125-
private validatePassword = (rule: any, value: string, callback: Function) => {
126-
if (value.length < 6) {
127-
callback(new Error('The password can not be less than 6 digits'))
128-
} else {
129-
callback()
130-
}
131-
}
13293
private loginForm = {
133-
username: 'admin',
134-
password: '111111'
135-
}
136-
private loginRules = {
137-
username: [{ validator: this.validateUsername, trigger: 'blur' }],
138-
password: [{ validator: this.validatePassword, trigger: 'blur' }]
94+
apikey: ''
13995
}
140-
private passwordType = 'password'
14196
private loading = false
14297
private showDialog = false
14398
private redirect?: string
144-
private otherQuery: Dictionary<string> = {}
14599
146-
@Watch('$route', { immediate: true })
147-
private onRouteChange(route: Route) {
148-
// TODO: remove the "as Dictionary<string>" hack after v4 release for vue-router
149-
// See https://github.com/vuejs/vue-router/pull/2050 for details
150-
const query = route.query as Dictionary<string>
151-
if (query) {
152-
this.redirect = query.redirect
153-
this.otherQuery = this.getOtherQuery(query)
154-
}
155-
}
156-
157-
mounted() {
158-
if (this.loginForm.username === '') {
159-
(this.$refs.username as Input).focus()
160-
} else if (this.loginForm.password === '') {
161-
(this.$refs.password as Input).focus()
162-
}
163-
}
164-
165-
private showPwd() {
166-
if (this.passwordType === 'password') {
167-
this.passwordType = ''
168-
} else {
169-
this.passwordType = 'password'
170-
}
171-
this.$nextTick(() => {
172-
(this.$refs.password as Input).focus()
173-
})
174-
}
175-
176-
private handleLogin() {
177-
(this.$refs.loginForm as ElForm).validate(async(valid: boolean) => {
178-
if (valid) {
179-
this.loading = true
180-
await UserModule.Login(this.loginForm)
181-
this.$router.push({
182-
path: this.redirect || '/',
183-
query: this.otherQuery
184-
})
185-
// Just to simulate the time of the request
186-
setTimeout(() => {
187-
this.loading = false
188-
}, 0.5 * 1000)
189-
} else {
190-
return false
191-
}
192-
})
193-
}
194-
195-
private getOtherQuery(query: Dictionary<string>) {
196-
return Object.keys(query).reduce((acc, cur) => {
197-
if (cur !== 'redirect') {
198-
acc[cur] = query[cur]
199-
}
200-
return acc
201-
}, {} as Dictionary<string>)
100+
private async handleLogin() {
101+
console.log(this.loginForm)
102+
await UserModule.Login({ username: '', password: '' })
103+
localStorage.setItem('GLOBAL_API_KEY', this.loginForm.apikey)
104+
window.location.replace('/dashboard')
202105
}
203106
}
204107
</script>

0 commit comments

Comments
 (0)