2929 <el-form
3030 ref =" loginForm"
3131 :model =" loginForm"
32- :rules =" loginRules"
3332 class =" login-form"
3433 autocomplete =" on"
3534 label-position =" left"
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"
10279<script lang="ts">
10380import { Component , Vue , Watch } from ' vue-property-decorator'
10481import { Route } from ' vue-router'
105- import { Dictionary } from ' vue-router/types/router'
10682import { Form as ElForm , Input } from ' element-ui'
10783import { UserModule } from ' @/store/modules/user'
108- import { isValidUsername } from ' @/utils/validate'
10984import LangSelect from ' @/components/LangSelect/index.vue'
11085
11186@Component ({
@@ -115,90 +90,18 @@ import LangSelect from '@/components/LangSelect/index.vue'
11590 }
11691})
11792export 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