login.vue 7.4 KB
<template>
	<view class="oneSubmitted">
		<topbar bg_color="#2d81ff">
			<text style="color: #fff;"></text>
			<text style="color: #fff;">登录</text>
			<text style="color: #fff;"></text>
		</topbar>
		<!-- 登录-->
		<view class="header-wrap"></view>

		<view class="content-wrap1 area flex">
			<view class="content-item flex">
				<image class="img" src="/static/images/logo.png" mode=""></image>
				<!-- <view class="botm-btn" @tap="login_fuc" style="position: relative;">登录</view> -->
				<view class="botm-btn-2" @click="openMajor">
					<text style="color: #979797;" v-if="!school.id">请选择学校</text>
					<text v-else>{{ school.name }}</text>
				</view>
				<view class="botm-btn" style="position: relative;" v-if="!school.id">
					<button style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;" @click="prompt"></button>
					登录
				</view>
				<view class="botm-btn" style="position: relative;" v-else>
					<button open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber" style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;opacity: 0;"></button>
					登录
				</view>
				<view class="samll-text" style="color: red;">
					本小程序为中志教育内部系统,不对外开放
				</view>
				<!-- <view class="botm-btn botm-btn1" @tap="login_fuc1" style="position: relative;">
					教师登录
				</view> -->
			</view>
		</view>
		<u-picker :show="show" :columns="columns" @cancel="show = false" keyName="name" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	import Vue from 'vue'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	var that 
	export default {
		data() {
			return {
				show: false,
				columns: [],
				school: {}
			}
		},
		onLoad(option) {
			that=this
			console.log(option);
			console.log(process.env.NODE_ENV)
			this.getColumns()
		},
		methods: {
			prompt() {
				uni.showToast({
					icon: 'none',
					title: '请选择学校'
				})
			},
			confirm(e) {
				this.school = e.value[0]
				this.show = false
			},
			getColumns() {
				var jkurl='/login/school'
				that.$service.P_get(jkurl).then(res => {
					console.log(res)
					this.columns = [res.data]
				})
			},
			openMajor() {
				this.show = true
			},
			onGetPhoneNumber(e){
				var that =this
					if(e.detail.errMsg=="getPhoneNumber:fail user deny"){       //用户决绝授权  
					}else{      //允许授权  
							console.log(e)  
							//e.detail.encryptedData      //加密的用户信息  
							//e.detail.iv     //加密算法的初始向量  时要用到  
							// uni.setStorageSync('res_code', res_login.code);
							var datas={
								code: e.detail.code
							}
							var jkurl='login/getPhone'
							
							that.$service.P_post(jkurl, datas).then(res => {
								that.btnkg = 0
								console.log(res)
								if (res.code == 1) {
									that.htmlReset = 0
									var datas = res.data
									console.log(typeof datas)
							
									// if (typeof datas == 'string') {
									// 	datas = JSON.parse(datas)
									// }
									 var datas=JSON.stringify(datas)
									console.log(res)
									// uni.showModal({
									// 	title:e.detail.code,
									// 	content:datas
									// })
									// return
									that.getdata(datas)
								} else {
									if (res.msg) {
										uni.showToast({
											icon: 'none',
											title: res.msg
										})
									} else {
										uni.showToast({
											icon: 'none',
											title: '获取数据失败'
										})
									}
								}
							}).catch(e => {
								that.htmlReset = 1
								that.btnkg = 0
								// that.$refs.htmlLoading.htmlReset_fuc(1)
								console.log(e)
								uni.showToast({
									icon: 'none',
									title: '获取数据失败,请检查您的网络连接'
								})
							})
					}  
			},
			login_fuc(){
				// /pages/index/index
				// console.log(that.$service.VER)
				// return
				if(that.$service.VER==0){
					uni.setStorageSync('identity',0)
					uni.switchTab({
						url:'/pages/index/index'
					})
					return
					
				}else{
					
					that.getdata('18300000000')
				}
				
			},
			login_fuc1(){
				that.getdata('15536043014')
				return
				uni.setStorageSync('identity',1)
				uni.reLaunch({
					url:'/pages/tch_index/tch_index'
				})
			},
			getdata(tel){
				
				wx.login({
					success: function(res_login) {
						console.log(res_login)
						uni.setStorageSync('res_code', res_login.code);
						var datas={
							code: res_login.code,
							type:1,
							phone:tel,
							school_id: that.school.id
						}
						var jkurl='/login'
						
						that.$service.P_post(jkurl, datas).then(res => {
							that.btnkg = 0
							console.log(res)
							if (res.code == 1) {
								that.htmlReset = 0
								var datas = res.data
								console.log(typeof datas)
						
								if (typeof datas == 'string') {
									datas = JSON.parse(datas)
								}
								console.log(res)
								var identity=datas.identity
								var token=datas.token
								uni.setStorageSync('identity',identity)
								uni.setStorageSync('token',token)
								that.$store.commit('login', datas)
								uni.showToast({
									icon: 'none',
									title: '登陆成功'
								})
								setTimeout(function(){
									// uni.reLaunch({
									// 	url:'/new_tec/homePage/homePage'
									// })
									// return
									if(identity==2){
										uni.reLaunch({
											url:'/pages/tch_index/tch_index'
										})
									}else if(identity==1){
										uni.switchTab({
											url:'/pages/index/index'
										})
									} else {
										uni.reLaunch({
											url:'/pages/admin_index/admin_index'
										})
									}
								},1000)
								
							} else {
							
								if (res.msg) {
									uni.showToast({
										icon: 'none',
										title: res.msg
									})
								} else {
									uni.showToast({
										icon: 'none',
										title: '获取数据失败'
									})
								}
							}
						}).catch(e => {
							that.htmlReset = 1
							that.btnkg = 0
							// that.$refs.htmlLoading.htmlReset_fuc(1)
							console.log(e)
							uni.showToast({
								icon: 'none',
								title: '获取数据失败,请检查您的网络连接'
							})
						})
					}
				})
				
			},
		}
	}
</script>

<style lang="scss" scoped>
	.oneSubmitted {
		position: relative;
	}

	.content-wrap1 {
		min-height: 608rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
		justify-content: center;
		align-items: center;
		position: relative;
		margin-top: -200rpx;
		padding-top: 80rpx;
		padding-bottom: 60rpx;
	}

	.content-item {
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.img {
		width: 172rpx;
		height: 172rpx;
		background: #2D81FF;
		border-radius: 32rpx;
	}

	.botm-btn {
		width: 576rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: #2D81FF;
		box-shadow: 6rpx 10rpx 30rpx 0rpx rgba(45, 129, 255, 0.2);
		border-radius: 46rpx;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		margin: 28rpx 0 28rpx 0;
		
	}
	.botm-btn1{
		margin-top: 40rpx;
	}
	.botm-btn-2{
		margin-top: 40rpx;
		background-color: #F4F4F4;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 68rpx;
		border-radius: 200rpx;
		font-size: 25rpx;
	}
	.samll-text {
		height: 28rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #545D6E;
	}
	.login_top{
		width: 100%;
	}
</style>