Browse Source

测试axios

sunChengjie 1 year ago
parent
commit
212028d26f
2 changed files with 100 additions and 83 deletions
  1. 9 1
      src/api/index.js
  2. 91 82
      src/pages/login.vue

+ 9 - 1
src/api/index.js

@@ -1 +1,9 @@
-import request from '../utils/request';
+import request from '../utils/request';
+
+export function employee_login(data) {
+    return request({
+        url: '/appSysUser/employee_login',
+        method: 'post',
+        data: data
+    })
+}

+ 91 - 82
src/pages/login.vue

@@ -4,13 +4,13 @@
 		<div class="login">
 			<div class="item">
 				<van-cell-group>
-			       <van-field v-model="name"  placeholder="请输入登录名" />
-			    </van-cell-group>
+					<van-field v-model="name" placeholder="请输入登录名" />
+				</van-cell-group>
 			</div>
 			<div class="item">
 				<van-cell-group>
-			       <van-field v-model="password" type="password"  placeholder="请输入密码" />
-			    </van-cell-group>
+					<van-field v-model="password" type="password" placeholder="请输入密码" />
+				</van-cell-group>
 			</div>
 			<!-- <div class="item">
 				<van-cell-group>
@@ -33,96 +33,105 @@
 
 
 <script>
-	import {Toast,Dialog} from 'vant'
-	export default{
-		data(){
-			return{
-				name:"",
-				password:"",
-				yzm:""
-			}
-		},
-		created:function(){
-			if(localStorage.getItem('name')!=null){
-				this.name = localStorage.getItem('name')
+import { employee_login } from '../api/index'
+import { Toast, Dialog } from 'vant'
+export default {
+	data() {
+		return {
+			name: "",
+			password: "",
+			yzm: ""
+		}
+	},
+	created: function () {
+		if (localStorage.getItem('name') != null) {
+			this.name = localStorage.getItem('name')
+		}
+		if (localStorage.getItem('password') != null) {
+			this.password = localStorage.getItem('password')
+		}
+	},
+	methods: {
+		//登录
+		async login() {
+			if (this.name == '' || this.name == undefined) {
+				Toast('请输入登录名');
+				return;
 			}
-			if(localStorage.getItem('password')!=null){
-				this.password = localStorage.getItem('password')
+			if (this.password == '' || this.password == undefined) {
+				Toast('请输入登录名');
+				return;
 			}
-		},
-		methods:{
-			//登录
-			login(){
-				if(this.name == '' || this.name == undefined){
-					Toast('请输入登录名');
-					return;
-				}
-				if(this.password == '' || this.password == undefined){
-					Toast('请输入登录名');
-					return;
-				}
-				this.$http.post(this.$store.state.host+"/appSysUser/employee_login",{account:this.name,password:this.password},{emulateJSON:true})
-					.then(res=>{
-						//发送成功
-						if(res.body.result=='success'){
-							//localStorage
-							localStorage.setItem("userId",res.body.userId);
-							localStorage.setItem("roomId",res.body.roomId);
-              localStorage.setItem("accountType",res.body.accountType);
-							localStorage.setItem("name",this.name);
-							localStorage.setItem("password",this.password);
-							this.$router.push({path:'/'});
-						}else{
-							Toast('登录失败!');
-						}
-				},res=>{
-						//发送失败
+			await employee_login({ account: this.name, password: this.password })
+			// this.$http.post(this.$store.state.host + "/appSysUser/employee_login", { account: this.name, password: this.password }, { emulateJSON: true })
+				.then(res => {
+					//发送成功
+					if (res.body.result == 'success') {
+						//localStorage
+						localStorage.setItem("userId", res.body.userId);
+						localStorage.setItem("roomId", res.body.roomId);
+						localStorage.setItem("accountType", res.body.accountType);
+						localStorage.setItem("name", this.name);
+						localStorage.setItem("password", this.password);
+						this.$router.push({ path: '/' });
+					} else {
+						Toast('登录失败!');
+					}
+				}, res => {
+					//发送失败
 					Toast("发送失败!")
 				})
-			}
 		}
 	}
+}
 </script>
 <style scoped lang="less">
-	.content{
-		.loginimg{
-			width:3.48rem;
-			margin: 0 auto;
-			display: block;
-			padding: 2.15rem .8rem;
+.content {
+	.loginimg {
+		width: 3.48rem;
+		margin: 0 auto;
+		display: block;
+		padding: 2.15rem .8rem;
+	}
+
+	.login {
+		width: 5.8rem;
+		margin: 0 auto;
+
+		.item {
+			border: .01rem solid #bfbfbf;
+			border-radius: .1rem;
+			margin-bottom: .5rem;
+			background: white;
+			overflow: hidden;
+			color: #999999;
 		}
-		.login{
-			width: 5.8rem;
-			margin: 0 auto;
-			.item{
-				border: .01rem solid #bfbfbf;
-				border-radius: .1rem;
-				margin-bottom: .5rem;
-				background: white;
-				overflow: hidden;
-				color: #999999;
-			}
-			.item:nth-of-type(3){
-				margin-bottom: .2rem;
+
+		.item:nth-of-type(3) {
+			margin-bottom: .2rem;
+		}
+
+		.btn {
+			button {
+				width: 100%;
 			}
-			.btn{
-				button{
-					width: 100%;
-				}
+		}
+
+		.register {
+			font-size: .24rem;
+			display: flex;
+			justify-content: space-between;
+			//margin-top: .2rem;
+			margin-bottom: .2rem;
+
+			a {
+				color: #999999;
 			}
-			.register{
-				font-size: .24rem;
-				display: flex;
-				justify-content: space-between;
-				//margin-top: .2rem;
-				margin-bottom: .2rem;
-				a{
-					color: #999999;
-				}
-				a:nth-of-type(1){
-					color: #02bfb3;
-				}
+
+			a:nth-of-type(1) {
+				color: #02bfb3;
 			}
 		}
 	}
+}
 </style>