|
1 | 1 | <template> |
2 | | - <div class="LoginContent"> |
3 | | - <el-form ref="form" :model="form" label-width="80px"> |
4 | | - <div style="text-align: center"><h2>sunq's blog 管理后台</h2></div> |
5 | | - <el-form-item label="账号"> |
6 | | - <el-input v-model="form.CnName"></el-input> |
7 | | - </el-form-item> |
8 | | - <el-form-item label="密码"> |
9 | | - <el-input v-model="form.PassWord"></el-input> |
10 | | - </el-form-item> |
11 | | - <div style="text-align: center"> |
12 | | - <el-button type="primary" @click="OnLogin()">登录</el-button> |
13 | | - <!--<el-button type="primary" @click="OnRegist()">注册</el-button>--> |
14 | | - </div> |
15 | | - </el-form> |
16 | | - </div> |
| 2 | + <div class="LoginContent"> |
| 3 | + <el-form ref="form" :model="form" label-width="80px"> |
| 4 | + <div style="text-align: center"><h2>sunq's blog 管理后台</h2></div> |
| 5 | + <el-form-item label="账号"> |
| 6 | + <el-input v-model="form.CnName"></el-input> |
| 7 | + </el-form-item> |
| 8 | + <el-form-item label="密码"> |
| 9 | + <el-input v-model="form.PassWord"></el-input> |
| 10 | + </el-form-item> |
| 11 | + <div style="text-align: center"> |
| 12 | + <el-button type="primary" @click="OnLogin()">登录</el-button> |
| 13 | + <!--<el-button type="primary" @click="OnRegist()">注册</el-button>--> |
| 14 | + </div> |
| 15 | + </el-form> |
| 16 | + </div> |
17 | 17 | </template> |
18 | 18 |
|
19 | 19 | <script> |
20 | | - import axios from 'axios' |
21 | | - import { Loading } from 'element-ui' |
| 20 | +import axios from 'axios' |
| 21 | +import {Loading} from 'element-ui' |
22 | 22 |
|
23 | | - export default { |
24 | | - name: "LoginPage", |
25 | | - data:function () { |
26 | | - return{ |
27 | | - form:{ |
28 | | - CnName : '游客', |
29 | | - PassWord:'亲,github求个赞' |
30 | | - } |
| 23 | +export default { |
| 24 | + name: "LoginPage", |
| 25 | + data: function () { |
| 26 | + return { |
| 27 | + form: { |
| 28 | + CnName: '游客', |
| 29 | + PassWord: '亲,github求个赞' |
31 | 30 | } |
| 31 | + } |
| 32 | + }, |
| 33 | + methods: { |
| 34 | + OnLogin: function () { |
| 35 | + var That = this; |
| 36 | + var AjaxLoading = Loading.service({fullscreen: true}); |
| 37 | + axios.post('/api/UserReadOne', { |
| 38 | + CnName: this.form.CnName, |
| 39 | + PassWord: this.form.PassWord, |
| 40 | + UserType: 'Admin' |
| 41 | + }).then(function (response) { |
| 42 | + AjaxLoading.close(); |
| 43 | + if (response.data.status == '0') { |
| 44 | + That.$message({ |
| 45 | + message: '登录成功', |
| 46 | + type: 'success' |
| 47 | + }); |
| 48 | + window.localStorage.setItem("SQBlog", JSON.stringify(response.data.data)); |
| 49 | + window.localStorage.setItem("SQBlogUser", That.form.CnName); |
| 50 | + That.$router.push({name: 'Article'}); |
| 51 | +
|
| 52 | + // 登录成功后,调用菜单组件注册的方法,修改菜单组件的用户名 |
| 53 | + That.bus.$emit('changeUser', That.form.CnName); |
| 54 | + } else if (response.data.status == '1') { |
| 55 | + That.$message.error('账号或密码错误'); |
| 56 | + } |
| 57 | + }).catch(function (error) { |
| 58 | + }); |
32 | 59 | }, |
33 | | - methods:{ |
34 | | - OnLogin:function () { |
35 | | - var That = this; |
36 | | - var AjaxLoading = Loading.service({ fullscreen: true }); |
37 | | - axios.post('/api/UserReadOne',{ |
38 | | - CnName: this.form.CnName, |
39 | | - PassWord: this.form.PassWord, |
40 | | - UserType: 'Admin' |
41 | | - }).then(function (response) { |
42 | | - AjaxLoading.close(); |
43 | | - if (response.data.status == '0') { |
44 | | - That.$message({ |
45 | | - message: '登录成功', |
46 | | - type: 'success' |
47 | | - }); |
48 | | - window.localStorage.setItem("SQBlog",JSON.stringify(response.data.data)); |
49 | | - window.localStorage.setItem("SQBlogUser",That.form.CnName); |
50 | | - That.$router.push({name:'Article'}); |
51 | | - }else if(response.data.status == '1'){ |
52 | | - That.$message.error('账号或密码错误'); |
53 | | - } |
54 | | - }).catch(function (error) { |
55 | | - }); |
56 | | - }, |
57 | | - OnRegist:function () { |
58 | | - var That = this; |
59 | | - axios.post('/api/UserCreate',{ |
60 | | - CnName: this.form.CnName, |
61 | | - PassWord: this.form.PassWord, |
62 | | - UserType: 'Admin' |
63 | | - }).then(function (response) { |
64 | | - if (response.data.status == '200') { |
65 | | - That.$message({ |
66 | | - message: '注册成功', |
67 | | - type: 'success' |
68 | | - }); |
69 | | - } |
70 | | - }).catch(function (error) { |
71 | | - }); |
72 | | - } |
| 60 | + OnRegist: function () { |
| 61 | + var That = this; |
| 62 | + axios.post('/api/UserCreate', { |
| 63 | + CnName: this.form.CnName, |
| 64 | + PassWord: this.form.PassWord, |
| 65 | + UserType: 'Admin' |
| 66 | + }).then(function (response) { |
| 67 | + if (response.data.status == '200') { |
| 68 | + That.$message({ |
| 69 | + message: '注册成功', |
| 70 | + type: 'success' |
| 71 | + }); |
| 72 | + } |
| 73 | + }).catch(function (error) { |
| 74 | + }); |
73 | 75 | } |
74 | 76 | } |
| 77 | +} |
75 | 78 | </script> |
76 | 79 |
|
77 | 80 | <style scoped lang="less"> |
78 | | - @import "../assets/css/base.less"; |
79 | | - .LoginContent{ |
80 | | - width: 600px; |
81 | | - margin: 12rem auto 0; |
82 | | - } |
| 81 | +@import "../assets/css/base.less"; |
| 82 | +
|
| 83 | +.LoginContent { |
| 84 | + width: 600px; |
| 85 | + margin: 12rem auto 0; |
| 86 | +} |
83 | 87 | </style> |
0 commit comments