소스 검색

feature 学员登记需要授权获取头像

tiedan 4 년 전
부모
커밋
a45b04cf44
3개의 변경된 파일247개의 추가작업 그리고 161개의 파일을 삭제
  1. 65 1
      pages/studentRegistration/studentRegistration.js
  2. 169 159
      pages/studentRegistration/studentRegistration.wxml
  3. 13 1
      pages/studentRegistration/studentRegistration.wxss

+ 65 - 1
pages/studentRegistration/studentRegistration.js

@@ -2,6 +2,11 @@ const tools = require('../../utils/tools.js');
 const app = require('../../utils/util.js');
 const app = require('../../utils/util.js');
 Page({
 Page({
   data: {
   data: {
+    canIUse: wx.canIUse('button.open-type.getUserInfo'),
+    avatar:"",
+    loadvisible:false,
+    visible:false,
+
     jobArr: [],
     jobArr: [],
     jobtext: '请选择',
     jobtext: '请选择',
     kaihutext: '请选择',
     kaihutext: '请选择',
@@ -95,6 +100,20 @@ Page({
   //     currentDate: e.detail,
   //     currentDate: e.detail,
   //   });
   //   });
   // },
   // },
+
+  bindGetUserInfo (e) {
+    var that=this;
+    console.log(e.detail.userInfo)
+    console.log(typeof e.detail.userInfo)
+    if(typeof e.detail.userInfo!='undefined'){
+      that.setData({avatar:e.detail.userInfo.avatarUrl});
+    }
+
+    that.setData({visible:true});
+    console.log(that.data.avatar);
+    
+  },
+
   onChange(event) {
   onChange(event) {
     this.setData({
     this.setData({
       radio: event.detail,
       radio: event.detail,
@@ -233,6 +252,7 @@ Page({
     e.detail.value.tenure = this.data.tenure;
     e.detail.value.tenure = this.data.tenure;
     e.detail.value.sessionKey = this.data.sessionKey;
     e.detail.value.sessionKey = this.data.sessionKey;
     let aa = e.detail.value
     let aa = e.detail.value
+    console.log(this.data.avatar);
     if (aa.culture && aa.school && aa.studentDuty && aa.tenure && aa.studentDept && aa.studentPhone) {
     if (aa.culture && aa.school && aa.studentDuty && aa.tenure && aa.studentDept && aa.studentPhone) {
       wx.request({
       wx.request({
         url: app.globalData.publicUrl + '/wx/student/upStudent',
         url: app.globalData.publicUrl + '/wx/student/upStudent',
@@ -250,7 +270,8 @@ Page({
           buildingLeader: this.data.ldzIndex, //楼栋长
           buildingLeader: this.data.ldzIndex, //楼栋长
           unitLeader: this.data.dyzIndex, //单元长
           unitLeader: this.data.dyzIndex, //单元长
           welfarePosition: this.data.gygIndex, //公益岗位
           welfarePosition: this.data.gygIndex, //公益岗位
-          partyMember: this.data.dyIndex //党员
+          partyMember: this.data.dyIndex, //党员
+          wxPicture:this.data.avatar//微信头像
         },
         },
         success: () => {
         success: () => {
           wx.showModal({
           wx.showModal({
@@ -328,7 +349,16 @@ Page({
     })
     })
   },
   },
   onReady: function () {},
   onReady: function () {},
+
+
+
+
+
+
+
   async onLoad() {
   async onLoad() {
+    console.log(this.data.loadvisible);
+    var that=this;
     wx.showLoading({
     wx.showLoading({
       title: '加载中',
       title: '加载中',
       mask: true
       mask: true
@@ -339,6 +369,40 @@ Page({
       sessionKey: sessionKey
       sessionKey: sessionKey
     })
     })
     this.getjob(sessionKey)
     this.getjob(sessionKey)
+
+
+
+    // 查看是否授权
+    wx.getSetting({
+      success (res){
+        if (res.authSetting['scope.userInfo']) {
+          // 已经授权,可以直接调用 getUserInfo 获取头像昵称
+          wx.getUserInfo({
+            success: function(res) {
+              that.setData({visible:true,loadvisible:true,avatar:res.userInfo.avatar});
+              console.log(res.userInfo)
+              console.log(that.data.loadvisible);
+            }
+          })
+        }else{
+          // 如果没有授权,表单不可见
+          that.setData({loadvisible:true,visible:false});
+        }
+      },
+      fail(){
+        //接口调用失败需要返回重试
+        wx.showModal({
+          showCancel: false,
+          content: '网络错误,请稍后再试',
+          success() {
+            wx.navigateBack({
+              delta: 1
+            })
+          }
+        })
+
+      }
+    })
   },
   },
   getBanner(sessionKey) {
   getBanner(sessionKey) {
     wx.request({
     wx.request({

+ 169 - 159
pages/studentRegistration/studentRegistration.wxml

@@ -1,179 +1,189 @@
 <view class="home">
 <view class="home">
-	<form bindsubmit="formSubmit">
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">姓名</view>
-			<view class='weui-input'>
-				<input name="username" disabled value="{{ info.miniName }}" placeholder="请输入姓名" placeholder-style="font-size:25rpx" />
-			</view>
+	
+		<view wx:if="{{loadvisible&&!visible}}" class="needAuth">
+			
+			<van-button type="primary" size="large" wx:if="{{canIUse}}" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</van-button>
+			<view wx:else>请升级微信版本</view>
+			<view class="needAuth1">请你授权程序,确保正常使用小程序功能。</view>
+			
 		</view>
 		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">性别</view>
-			<radio-group name="{{item.name}}" data-index='{{index}}' data-idx='{{item.Id}}' data-questTypes='{{item.QuestType}}'>
-				<label class="checkbox my-choosebox {{ item.checked?'checkboxbox':''}}" checked="{{item.checked}}" wx:for-index="idx" wx:for="{{parameter}}">
-					<radio value="{{ item.value }}" />{{item.name}}
-				</label>
-			</radio-group>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">工作单位</view>
-			<view class='weui-input'>
-				<input class="" name="studentDept" value="{{ studentDept }}" placeholder="请输入工作单位" placeholder-style="font-size:25rpx" />
-			</view>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">文化程度</view>
-			<picker bindchange="kaihuListChange" name="culture" value="{{kaihuindex}}" range-key="{{'name'}}" range="{{kaihuList}}">
-				<view class="weui-input aaa">
-					{{kaihutext == null? '请选择':kaihutext}}
+		
+		<form bindsubmit="formSubmit" wx:if="{{loadvisible&&visible}}">
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">姓名</view>
+				<view class='weui-input'>
+					<input name="username" disabled value="{{ info.miniName }}" placeholder="请输入姓名" placeholder-style="font-size:25rpx" />
 				</view>
 				</view>
-			</picker>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">毕业学校</view>
-			<view class='weui-input'>
-				<input class="" name="school" value="{{ info.school }}" placeholder="请输入毕业学校" placeholder-style="font-size:25rpx" />
-			</view>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">所学专业</view>
-			<view class='weui-input'>
-				<input class="" name="mcajor" value="{{info.mcajor}}" placeholder="请输入所学专业" placeholder-style="font-size:25rpx" />
-			</view>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">现任职务</view>
-			<view class='weui-input'>
-				<picker bindchange="jobChange" range-key="{{'dictLabel'}}" name="studentDuty" value="{{zwIndex+1}}" range="{{jobArr}}">
-					<view class="weui-input aaa">
-						<!-- {{jobtext == null?'请选择':jobtext}} -->
-						{{jobArr[zwIndex].dictLabel}}
-					</view>
-				</picker>
-				<!-- <input class="" disabled name="studentDuty" value="{{ studentDuty }}" placeholder="请输入现任职务" placeholder-style="font-size:25rpx" /> -->
-			</view>
-		</view>
-		<!-- 是否党员 -->
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
-			</view>
-			<view class="xingbie">是否党员</view>
-			<view class='weui-input'>
-				<picker bindchange="dyChange" range-key="{{item}}" name="isdy" value="{{dyIndex}}" range="{{dyArr}}">
-					<view class="weui-input aaa">
-						<!-- {{dytext == null?'请选择':dytext}} -->
-						{{dyArr[dyIndex]}}
-					</view>
-				</picker>
-				<!-- <input class="" disabled name="studentDuty" value="{{ studentDuty }}" placeholder="请输入现任职务" placeholder-style="font-size:25rpx" /> -->
 			</view>
 			</view>
-		</view>
-		<!-- 是否网格长 -->
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">性别</view>
+				<radio-group name="{{item.name}}" data-index='{{index}}' data-idx='{{item.Id}}' data-questTypes='{{item.QuestType}}'>
+					<label class="checkbox my-choosebox {{ item.checked?'checkboxbox':''}}" checked="{{item.checked}}" wx:for-index="idx" wx:for="{{parameter}}">
+						<radio value="{{ item.value }}" />{{item.name}}
+					</label>
+				</radio-group>
+			</view>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">工作单位</view>
+				<view class='weui-input'>
+					<input class="" name="studentDept" value="{{ studentDept }}" placeholder="请输入工作单位" placeholder-style="font-size:25rpx" />
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">是否网格长</view>
-			<view class='weui-input'>
-				<picker bindchange="wgzChange" range-key="{{item}}" name="isdy" value="{{wgzIndex}}" range="{{wgzArr}}">
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">文化程度</view>
+				<picker bindchange="kaihuListChange" name="culture" value="{{kaihuindex}}" range-key="{{'name'}}" range="{{kaihuList}}">
 					<view class="weui-input aaa">
 					<view class="weui-input aaa">
-						<!-- {{wgztext == null?'请选择':wgztext}} -->
-						{{wgzArr[wgzIndex]}}
+						{{kaihutext == null? '请选择':kaihutext}}
 					</view>
 					</view>
 				</picker>
 				</picker>
 			</view>
 			</view>
-		</view>
-		<!-- 是否楼栋长 -->
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">毕业学校</view>
+				<view class='weui-input'>
+					<input class="" name="school" value="{{ info.school }}" placeholder="请输入毕业学校" placeholder-style="font-size:25rpx" />
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">是否楼栋长</view>
-			<view class='weui-input'>
-				<picker bindchange="ldzChange" range-key="{{item}}" name="isld" value="{{ldzIndex}}" range="{{ldzArr}}">
-					<view class="weui-input aaa">
-						<!-- {{ldztext == null?'请选择':ldztext}} -->
-						{{ldzArr[ldzIndex]}}
-					</view>
-				</picker>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">所学专业</view>
+				<view class='weui-input'>
+					<input class="" name="mcajor" value="{{info.mcajor}}" placeholder="请输入所学专业" placeholder-style="font-size:25rpx" />
+				</view>
 			</view>
 			</view>
-		</view>
-		<!-- 是否单元长 -->
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">现任职务</view>
+				<view class='weui-input'>
+					<picker bindchange="jobChange" range-key="{{'dictLabel'}}" name="studentDuty" value="{{zwIndex+1}}" range="{{jobArr}}">
+						<view class="weui-input aaa">
+							<!-- {{jobtext == null?'请选择':jobtext}} -->
+							{{jobArr[zwIndex].dictLabel}}
+						</view>
+					</picker>
+					<!-- <input class="" disabled name="studentDuty" value="{{ studentDuty }}" placeholder="请输入现任职务" placeholder-style="font-size:25rpx" /> -->
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">是否单元长</view>
-			<view class='weui-input'>
-				<picker bindchange="dyzChange" range-key="{{item}}" name="isld" value="{{dyzIndex}}" range="{{dyzArr}}">
-					<view class="weui-input aaa">
-						<!-- {{dyztext == null?'请选择':dyztext}} -->
-						{{dyzArr[dyzIndex]}}
-					</view>
-				</picker>
+			<!-- 是否党员 -->
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">是否党员</view>
+				<view class='weui-input'>
+					<picker bindchange="dyChange" range-key="{{item}}" name="isdy" value="{{dyIndex}}" range="{{dyArr}}">
+						<view class="weui-input aaa">
+							<!-- {{dytext == null?'请选择':dytext}} -->
+							{{dyArr[dyIndex]}}
+						</view>
+					</picker>
+					<!-- <input class="" disabled name="studentDuty" value="{{ studentDuty }}" placeholder="请输入现任职务" placeholder-style="font-size:25rpx" /> -->
+				</view>
 			</view>
 			</view>
-		</view>
-		<!-- 是否公益岗 -->
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="" style="width:20rpx;height:20rpx"> </image>
+			<!-- 是否网格长 -->
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">是否网格长</view>
+				<view class='weui-input'>
+					<picker bindchange="wgzChange" range-key="{{item}}" name="isdy" value="{{wgzIndex}}" range="{{wgzArr}}">
+						<view class="weui-input aaa">
+							<!-- {{wgztext == null?'请选择':wgztext}} -->
+							{{wgzArr[wgzIndex]}}
+						</view>
+					</picker>
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">是否公益岗</view>
-			<view class='weui-input'>
-				<picker bindchange="gygChange" range-key="{{item}}" name="isld" value="{{gygIndex}}" range="{{gygArr}}">
-					<view class="weui-input aaa">
-						<!-- {{gygtext == null?'请选择':gygtext}} -->
-						{{gygArr[gygIndex]}}
-					</view>
-				</picker>
+			<!-- 是否楼栋长 -->
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">是否楼栋长</view>
+				<view class='weui-input'>
+					<picker bindchange="ldzChange" range-key="{{item}}" name="isld" value="{{ldzIndex}}" range="{{ldzArr}}">
+						<view class="weui-input aaa">
+							<!-- {{ldztext == null?'请选择':ldztext}} -->
+							{{ldzArr[ldzIndex]}}
+						</view>
+					</picker>
+				</view>
 			</view>
 			</view>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx;"> </image>
+			<!-- 是否单元长 -->
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">是否单元长</view>
+				<view class='weui-input'>
+					<picker bindchange="dyzChange" range-key="{{item}}" name="isld" value="{{dyzIndex}}" range="{{dyzArr}}">
+						<view class="weui-input aaa">
+							<!-- {{dyztext == null?'请选择':dyztext}} -->
+							{{dyzArr[dyzIndex]}}
+						</view>
+					</picker>
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">任职时间</view>
-			<view class='weui-input aaa' style="font-size: 26rpx;  line-height: 56rpx;" catchtap="share1">
-				{{tenure == null ? '':tenure  }}
-				<view wx:if='{{!tenure}}' style="color:#808080;display: inline-block;height:60rpx;line-height:60rpx;font-size:25rpx">{{headmasterText}}</view>
+			<!-- 是否公益岗 -->
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">是否公益岗</view>
+				<view class='weui-input'>
+					<picker bindchange="gygChange" range-key="{{item}}" name="isld" value="{{gygIndex}}" range="{{gygArr}}">
+						<view class="weui-input aaa">
+							<!-- {{gygtext == null?'请选择':gygtext}} -->
+							{{gygArr[gygIndex]}}
+						</view>
+					</picker>
+				</view>
 			</view>
 			</view>
-			<van-popup show="{{postshow}}" position="bottom" custom-style="height: 50%;">
-				<!-- <van-datetime-picker bind:confirm="onConfirm" bind:cancel='onClose' type="date" value="{{currentDate}}" bind:input="onInput" min-date="{{ minDate }}" formatter="{{ formatter }}" /> -->
-				<van-datetime-picker bind:confirm="onConfirm" bind:cancel='onClose' min-date="{{minDate}}" max-date="{{currentDate}}" type="date" value="{{currentDate}}" formatter="{{formatter}}" />
-			</van-popup>
-		</view>
-		<view class='fwb'>
-			<view class="red-image">
-				<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx;"> </image>
+				</view>
+				<view class="xingbie">任职时间</view>
+				<view class='weui-input aaa' style="font-size: 26rpx;  line-height: 56rpx;" catchtap="share1">
+					{{tenure == null ? '':tenure  }}
+					<view wx:if='{{!tenure}}' style="color:#808080;display: inline-block;height:60rpx;line-height:60rpx;font-size:25rpx">{{headmasterText}}</view>
+				</view>
+				<van-popup show="{{postshow}}" position="bottom" custom-style="height: 50%;">
+					<!-- <van-datetime-picker bind:confirm="onConfirm" bind:cancel='onClose' type="date" value="{{currentDate}}" bind:input="onInput" min-date="{{ minDate }}" formatter="{{ formatter }}" /> -->
+					<van-datetime-picker bind:confirm="onConfirm" bind:cancel='onClose' min-date="{{minDate}}" max-date="{{currentDate}}" type="date" value="{{currentDate}}" formatter="{{formatter}}" />
+				</van-popup>
+			</view>
+			<view class='fwb'>
+				<view class="red-image">
+					<image src="/images/quan.png" style="width:20rpx;height:20rpx"> </image>
+				</view>
+				<view class="xingbie">联系电话</view>
+				<view class='weui-input'>
+					<input class="" name="studentPhone" value="{{ studentPhone }}" placeholder="请输入联系电话" placeholder-style="font-size:25rpx" />
+				</view>
 			</view>
 			</view>
-			<view class="xingbie">联系电话</view>
-			<view class='weui-input'>
-				<input class="" name="studentPhone" value="{{ studentPhone }}" placeholder="请输入联系电话" placeholder-style="font-size:25rpx" />
+			<view style="margin-top: 100rpx;margin-bottom:100rpx">
+				<van-button round formType="submit">提交报到信息</van-button>
 			</view>
 			</view>
-		</view>
-		<view style="margin-top: 100rpx;margin-bottom:100rpx">
-			<van-button round formType="submit">提交报到信息</van-button>
-		</view>
-	</form>
+		</form>
+
 </view>
 </view>

+ 13 - 1
pages/studentRegistration/studentRegistration.wxss

@@ -1,6 +1,7 @@
 .home {
 .home {
   margin: 0 40rpx;
   margin: 0 40rpx;
   margin-top: 40rpx;
   margin-top: 40rpx;
+  position: relative;
 }
 }
 
 
 van-button {
 van-button {
@@ -130,4 +131,15 @@ radio {
   line-height: 60rpx;
   line-height: 60rpx;
   padding-left: 20rpx;
   padding-left: 20rpx;
   width: 454rpx;
   width: 454rpx;
-}
+}
+.needAuth{
+  position: fixed;
+  bottom: 200rpx;
+}
+.needAuth1{
+  width:100%;
+  text-align: center;
+  font-size:26rpx;
+  padding-top:10rpx;
+}
+