Ver código fonte

登录,注册

wkyy 3 anos atrás
pai
commit
a82b415785
4 arquivos alterados com 464 adições e 97 exclusões
  1. 38 20
      apis/login.js
  2. 161 21
      pages/login/index.vue
  3. 208 25
      pages/login/register.vue
  4. 57 31
      pages/login/search.vue

+ 38 - 20
apis/login.js

@@ -11,40 +11,58 @@ export function findByOpenId(data) {
 	})
 }
 
-export function validateCode(data) {
-	 
+export function logout(data) {
+	var url='/mobile/regUser/logout';
 	return requestWhite({
-		method: 'post',
-		data:data ,
-		url: '/mobile/regUser/validateCode'
+		method: 'get',
+		data: data,
+		url: url
 	})
-} 
+}
 
-export function getVerifyCode(tel) {
+export function getVerifyCode(telephone) {
 	 
 	return requestWhite({
 		method: 'post',
 		data:{
-			telephone:tel
+			telephone:telephone
 		} ,
 		url: '/mobile/regUser/getVerifyCode'
 	})
 } 
 
-export function passwordLogin(data) {
+export function login(data) {
 	 
-	 var url=""
-	 if(data.form=="job"){
-	 	url='/mobile/jobUserApi/passwordLogin';
-	 }else if(data.form=="hr"){
-	 	url='/mobile/sysUserApi/passwordLogin';
-	 }else{
-	 	return 
-	 }
+	return requestWhite({
+		method: 'post',
+		data: data,
+		url: '/mobile/regUser/login'
+	})
+} 
+
+export function register(data) {
 	 
 	return requestWhite({
 		method: 'post',
-		data:data ,
-		url: url
+		data: data,
+		url: '/mobile/regUser/register'
 	})
-} 
+} 
+
+export function changePhone(data) {
+	 
+	return requestWhite({
+		method: 'post',
+		data: data,
+		url: '/mobile/regUser/changePhone'
+	})
+} 
+
+export function orgList(data) {
+	 
+	return requestWhite({
+		method: 'post',
+		data: data,
+		url: '/mobile/regUser/orgList'
+	})
+} 

+ 161 - 21
pages/login/index.vue

@@ -9,53 +9,187 @@
 				<u-form :model="form" ref="uForm">
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="profile-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请填写18位身份证号" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.idCard" placeholder="请填写18位身份证号" />
+						</u-form-item>
 					</view>
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="cellphone-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请填写手机号码" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.telephone" placeholder="请填写手机号码" />
+						</u-form-item>
 					</view>
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="lock-password-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请输入验证码" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.verifyCode" placeholder="请输入验证码" />
+						</u-form-item>
 					</view>
 				</u-form>
 				<view class="jpLogin-link">
 					<view class="jpLogin-link-l">
 						<p>没有账号,</p>
-						<span>去注册</span>
+						<span @click="getRegister">去注册</span>
 					</view>
-					<span>获取验证码</span>
+					<span @click="getCode">获取验证码</span>
 				</view>
 			</view>
 			<view style="margin-top: 60px;">
-				<u-button type="error" shape="circle" :custom-style="customStyle">登录</u-button>
+				<u-button type="error" shape="circle" :custom-style="customStyle" @click="finish">登录</u-button>
 			</view>
 			<view class="jpLogin-radio">
 				<u-radio-group v-model="value">
-					<u-radio activeColor="#ff5e5e"><view class="u-flex"><p>已阅读并同意</p><span>《会员服务协议》</span></view></u-radio>
+					<u-radio activeColor="#ff5e5e">
+						<view class="u-flex">
+							<p>已阅读并同意</p><span @click="getAgreement">《会员服务协议》</span>
+						</view>
+					</u-radio>
 				</u-radio-group>
 			</view>
+			<u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
+			</u-verification-code>
 		</view>
 	</view>
 </template>
 
 <script>
+	import * as loginApi from '@/apis/login.js'
+	import {
+		checkPhone
+	} from '@/utils'
+
 	export default {
 		data() {
 			return {
 				form: {
-					name: '',
+					idCard: '',
+					telephone: '',
+					verifyCode: '',
 				},
-				value:'0',
+				value: '0',
 				customStyle: {
 					background: '#FF5E5E'
-				}
+				},
+				isSendMsgIng: false,
+				sendMsgSecond: 60 * 2,
 			}
-			methods: {
+		},
+		methods: {
+			getRegister() {
+				uni.redirectTo({
+					url: '/pages/login/register'
+				});
+			},
+			getAgreement() {
+				uni.redirectTo({
+					url: '/pages/login/agreement'
+				});
+			},
+			codeChange(text) {
+				this.codeTips = text;
+			},
+			start() {
+				if (!this.isSendMsgIng) {
+					uni.showLoading({
+						title: "加载中",
+						mask: true,
+					})
+					loginApi.getVerifyCode(this.form.telephone).then((response) => {
+						uni.hideLoading();
+						this.carhelp.set("getvcodetime", new Date().getTime());
 
-			}
+						if (!"") {
+							//倒计时
+							uni.showToast({
+								title: "发送成功"
+							})
+						} else {
+							uni.showToast({
+								title: "您的验证码已经发送[5分钟有效],请勿重复点击"
+							})
+						}
+					}).catch(error => {
+						uni.showToast({
+							title: error,
+							icon: "none"
+						})
+					})
+				}
+			},
+			//倒计时
+			end() {
+				this.sendMsgSecond = 2 * 60;
+				this.isSendMsgIng = false;
+			},
+			// 获取验证码
+			getCode() {
+				if (this.$refs.uCode.canGetCode) {} else {
+					uni.showToast({
+						title: '倒计时结束后再发送',
+						icon: "none"
+					})
+					return
+				}
+
+				var checkPhoneResult = checkPhone(this.form.telephone);
 
+				if (false && checkPhoneResult !== true) {
+					uni.showToast({
+						title: checkPhoneResult,
+					})
+					return;
+				}
+				this.$refs.uCode.start();
+			},
+			finish() {
+				if (!this.carhelp.getOpenId()) {
+					uni.showToast({
+						title: "请使用“微信”访问本系统登录"
+					})
+					return
+				}
+				if (!this.form.idCard) {
+					uni.showToast({
+						title: "请输入身份证"
+					})
+					return
+				}
+				if (!this.form.telephone) {
+					uni.showToast({
+						title: "请输入手机号"
+					})
+					return
+				}
+				if (!this.form.verifyCode) {
+					uni.showToast({
+						title: "请输入验证码"
+					})
+					return
+				}
+			
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				loginApi.login({
+					verifyCode: this.form.verifyCode,
+					telephone: this.form.telephone,
+					openId: this.carhelp.getOpenId(),
+				}).then((response) => {
+					var token = response ? response.data.token : '';
+					this.carhelp.setToken(token);
+					this.carhelp.setPersonInfo(response.data.memberInfo);
+					//this.gotoUrl("pages/user/index")
+					uni.switchTab({
+						url: '/pages/index/index'
+					})
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
 		}
 	}
 </script>
@@ -94,19 +228,22 @@
 		width: 100%;
 		padding: 0 20px;
 		margin-bottom: 20px;
-		.u-form-item{
+
+		.u-form-item {
 			flex: 1;
 		}
-		.jpLogin-icon{
+
+		.jpLogin-icon {
 			font-size: 20px;
-			color:#FFC1C1;
+			color: #FFC1C1;
 			margin-right: 20px;
 			position: relative;
-			&:after{
+
+			&:after {
 				content: '';
 				width: 1px;
 				height: 16px;
-				background-color:#E6D6D6;
+				background-color: #E6D6D6;
 				position: absolute;
 				right: -10px;
 				top: 15px;
@@ -133,15 +270,18 @@
 			color: #1677FF;
 		}
 	}
-	.jpLogin-radio{
+
+	.jpLogin-radio {
 		margin-top: 16px;
 		text-align: center;
-		p{
+
+		p {
 			font-size: 14px;
 			color: #a0a4b8;
 		}
-		span{
-			color:#ff5e5e;
+
+		span {
+			color: #ff5e5e;
 			font-size: 14px;
 		}
 	}

+ 208 - 25
pages/login/register.vue

@@ -9,63 +9,239 @@
 				<u-form :model="form" ref="uForm">
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="user-2-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请填写您的真实姓名" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.realName" placeholder="请填写您的真实姓名" />
+						</u-form-item>
 						<u-icon custom-prefix="custom-icon" name="information-line" class="jpLogin-warn"></u-icon>
 					</view>
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="profile-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请填写18位身份证号" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.idCard" placeholder="请填写18位身份证号" />
+						</u-form-item>
 						<u-icon custom-prefix="custom-icon" name="information-line" class="jpLogin-warn"></u-icon>
 					</view>
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="building-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.sex" type="select" placeholder="请选择所属工会"/></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.orgName" type="select" placeholder="请选择所属工会" @click="getSearch" />
+						</u-form-item>
 					</view>
 					<view class="jpLogin-input" style="margin-top:60px;">
 						<u-icon custom-prefix="custom-icon" name="cellphone-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请填写手机号码" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.telephone" placeholder="请填写手机号码" />
+						</u-form-item>
 					</view>
 					<view class="jpLogin-input">
 						<u-icon custom-prefix="custom-icon" name="message-3-fill" class="jpLogin-icon"></u-icon>
-						<u-form-item><u-input v-model="form.name" placeholder="请输入验证码" /></u-form-item>
+						<u-form-item>
+							<u-input v-model="form.verifyCode" placeholder="请输入验证码" />
+						</u-form-item>
 					</view>
 				</u-form>
 				<view class="jpLogin-link">
 					<view class="jpLogin-link-l">
 						<p>已有账号,</p>
-						<span>登录</span>
+						<span @click="getLogin">登录</span>
 					</view>
-					<span>获取验证码</span>
+					<span  @click="getCode">获取验证码</span>
 				</view>
 			</view>
 			<view style="margin-top: 60px;">
-				<u-button type="error" shape="circle" :custom-style="customStyle">注册并登录</u-button>
+				<u-button type="error" shape="circle" :custom-style="customStyle" @click="finish">注册并登录</u-button>
 			</view>
 			<view class="jpLogin-radio">
 				<u-radio-group v-model="value">
-					<u-radio activeColor="#ff5e5e"><view class="u-flex"><p>已阅读并同意</p><span>《会员服务协议》</span></view></u-radio>
+					<u-radio activeColor="#ff5e5e">
+						<view class="u-flex">
+							<p>已阅读并同意</p><span @click="getAgreement">《会员服务协议》</span>
+						</view>
+					</u-radio>
 				</u-radio-group>
 			</view>
+			<u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start">
+			</u-verification-code>
 		</view>
 	</view>
 </template>
 
 <script>
+	import * as loginApi from '@/apis/login.js'
+	import {
+		checkPhone
+	} from '@/utils'
+
 	export default {
 		data() {
 			return {
 				form: {
-					name: '',
+					verifyCode: '',
+					realName: '',
+					idCard: '',
+					orgId: '',
+					orgName: '',
+					telephone: '',
 				},
-				value:'0',
-				customStyle:{
+				value: '0',
+				customStyle: {
 					background: '#FF5E5E'
-				}
+				},
+				isSendMsgIng: false,
+				sendMsgSecond: 60 * 2,
 			}
-			methods: {
+		},
+		onShow() {
+			var item=	this.carhelp.get("selectitem")
+			if(item){
+				console.log(item)
+				this.form.orgName = item.name;
+				this.form.orgId = item.id;
+			}		
+		},
+		methods: {
+			getSearch() {
+				uni.navigateTo({
+					url: '/pages/login/search'
+				});
+			},
+			getLogin() {
+				uni.redirectTo({
+					url: '/pages/login/index'
+				});
+			},
+			goAgreement() {
+				uni.redirectTo({
+					url: '/pages/login/agreement'
+				});
+			},
+			codeChange(text) {
+				this.codeTips = text;
+			},
+			start() {
+				if (!this.isSendMsgIng) {
+					uni.showLoading({
+						title: "加载中",
+						mask: true,
+					})
+					loginApi.getVerifyCode(this.form.telephone).then((response) => {
+						uni.hideLoading();
+						this.carhelp.set("getvcodetime", new Date().getTime());
 
-			}
+						if (!"") {
+							//倒计时
+							uni.showToast({
+								title: "发送成功"
+							})
+						} else {
+							uni.showToast({
+								title: "您的验证码已经发送[5分钟有效],请勿重复点击"
+							})
+						}
+					}).catch(error => {
+						uni.showToast({
+							title: error,
+							icon: "none"
+						})
+					})
+				}
+			},
+			//倒计时
+			end() {
+				this.sendMsgSecond = 2 * 60;
+				this.isSendMsgIng = false;
+			},
+			// 获取验证码
+			getCode() {
+				if (this.$refs.uCode.canGetCode) {} else {
+					uni.showToast({
+						title: '倒计时结束后再发送',
+						icon: "none"
+					})
+					return
+				}
+
+				var checkPhoneResult = checkPhone(this.form.telephone);
 
+				if (false && checkPhoneResult !== true) {
+					uni.showToast({
+						title: checkPhoneResult,
+					})
+					return;
+				}
+				this.$refs.uCode.start();
+			},
+			finish() {
+				if (!this.carhelp.getOpenId()) {
+					uni.showToast({
+						title: "请使用“微信”访问本系统登录"
+					})
+					return
+				}
+				if (!this.form.realName) {
+					uni.showToast({
+						title: "请输入姓名"
+					})
+					return
+				}
+				if (!this.form.idCard) {
+					uni.showToast({
+						title: "请输入身份证"
+					})
+					return
+				}
+				if (!this.form.orgName) {
+					uni.showToast({
+						title: "请选择工会"
+					})
+					return
+				}
+				if (!this.form.telephone) {
+					uni.showToast({
+						title: "请输入手机号"
+					})
+					return
+				}
+				if (!this.form.verifyCode) {
+					uni.showToast({
+						title: "请输入验证码"
+					})
+					return
+				}
+
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})
+				var headImg = "";
+				var userInfo = this.carhelp.get("xpgj_wx_user_info")
+				if (userInfo) {
+					headImg = userInfo.headimgurl;
+				}
+
+				loginApi.register({
+					realName: this.form.realName,
+					idCard: this.form.idCard,
+					orgId: this.form.orgId,
+					verifyCode: this.form.verifyCode,
+					telephone: this.form.telephone,
+					openId: this.carhelp.getOpenId(),
+					headImg: headImg
+				}).then((response) => {
+					var token = response ? response.data.token : '';
+					this.carhelp.setToken(token);
+					this.carhelp.setPersonInfo(response.data.memberInfo);
+					//this.gotoUrl("pages/user/index")
+					uni.switchTab({
+						url: '/pages/index/index'
+					})
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
 		}
 	}
 </script>
@@ -105,25 +281,29 @@
 		padding: 0 20px;
 		margin-bottom: 20px;
 		position: relative;
-		.u-form-item{
+
+		.u-form-item {
 			flex: 1;
 		}
-		.jpLogin-icon{
+
+		.jpLogin-icon {
 			font-size: 20px;
-			color:#FFC1C1;
+			color: #FFC1C1;
 			margin-right: 20px;
 			position: relative;
-			&:after{
+
+			&:after {
 				content: '';
 				width: 1px;
 				height: 16px;
-				background-color:#E6D6D6;
+				background-color: #E6D6D6;
 				position: absolute;
 				right: -10px;
 				top: 15px;
 			}
 		}
-		.jpLogin-warn{
+
+		.jpLogin-warn {
 			position: absolute;
 			right: 20px;
 			top: 14px;
@@ -151,15 +331,18 @@
 			color: #1677FF;
 		}
 	}
-	.jpLogin-radio{
+
+	.jpLogin-radio {
 		margin-top: 16px;
 		text-align: center;
-		p{
+
+		p {
 			font-size: 14px;
 			color: #a0a4b8;
 		}
-		span{
-			color:#ff5e5e;
+
+		span {
+			color: #ff5e5e;
 			font-size: 14px;
 		}
 	}

+ 57 - 31
pages/login/search.vue

@@ -3,58 +3,84 @@
 		<view class="search">
 			<u-search placeholder="输入关键字查询工会" v-model="keyword" :action-style="actionStyle"></u-search>
 		</view>
-		<view class="searchList">
-			<view class="searchList-item">
-				湖北荆鹏软件开发有限公司工会
-			</view>
-			<view class="searchList-item">
-				湖北荆鹏软件开发有限公司工会
-			</view>
-			<view class="searchList-item">
-				湖北荆鹏软件开发有限公司工会
-			</view>
-			<view class="searchList-item">
-				湖北荆鹏软件开发有限公司工会
-			</view>
-			<view class="searchList-item">
-				湖北荆鹏软件开发有限公司工会
-			</view>
-
+		<view class="searchList">		
+			<list>
+				<cell v-for="(item, index) in orgResult" :key="item.id">
+					<view class="searchList-item">
+						<text @click="getRegister(item)">{{item.name}}</text>
+					</view>
+				</cell>
+			</list>		
 			<u-divider color="#B6BDC3" style="margin-top:20px;">已经到底了</u-divider>
 		</view>
 	</view>
 </template>
 
 <script>
+	import * as loginApi from '@/apis/login.js'
+
 	export default {
 		data() {
 			return {
 				keyword: '',
-				actionStyle:{
+				pageIndex: 1,
+				pageSize: 100,
+				orgResult: [],
+				actionStyle: {
 					background: '#FF5E5E',
-					color:'#ffffff',
-					padding:'5px 0',
-					width:'60px',
-					borderRadius:'15px',
+					color: '#ffffff',
+					padding: '5px 0',
+					width: '60px',
+					borderRadius: '15px',
 				},
 			}
-			methods: {
-
+		},
+		methods: {
+			getRegister(item) {
+				this.carhelp.set("selectitem",item)
+				uni.navigateBack({
+					url: '/pages/login/register'
+				})
+			},
+			getList() {
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})
+				loginApi.orgList({
+					pageIndex: this.pageIndex,
+					pageSize: this.pageSize,
+					orgName: this.keyword
+				}).then((response) => {
+					var jsonData = response.data.data;
+					console.log(jsonData);
+					this.orgResult = jsonData;
+					uni.hideLoading()
+				})
+				.catch((error) => {
+					uni.showToast({
+						title: error
+					})
+				})
+			},
+			onReady() {
+				this.getList();
 			}
-
 		}
 	}
 </script>
 
 <style lang="scss" scoped>
-	.search{
-		padding:10px 15px;
+	.search {
+		padding: 10px 15px;
 	}
-	.searchList{
-		padding:0 15px;
-		.searchList-item{
+
+	.searchList {
+		padding: 0 15px;
+
+		.searchList-item {
 			border-bottom: 1px solid #E5E7EA;
-			padding:15px 0; 
+			padding: 15px 0;
 		}
 	}
 </style>