Commit 3839be55 authored by zhangzedan's avatar zhangzedan

index user_registe

parent 4d147219
//app.js //app.js
var jsonData = require('app.json'); var pages = require('js/pages.js');
App({ // 将code传输到服务器
onLaunch: function () { function getIdInfo(code){
// 展示本地存储能力 wx.request({
var logs = wx.getStorageSync('logs') || [] url: 'http://192.168.31.6:8080/login/getMessageByCode',//自己的服务接口地址
logs.unshift(Date.now()) method: 'post',
wx.setStorageSync('logs', logs) data: {code: code},
success(res) {
// 登录 console.log(res)
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
let code = res.code
if(code){
wx.getUserInfo({
success: function (res) {
// console.log({encryptedData: res.encryptedData, iv: res.iv, code: code})
//3.解密用户信息 获取unionId
//...
}, },
fail: function () { fail(res) {
// console.log('获取用户信息失败') wx.showToast({
} title:"系统错误",
duration:5000,
icon:"none"
}) })
} }
}
}) })
// 获取用户信息 return {}
wx.getSetting({ }
success: res => { function getUserInfo(){
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({ wx.getUserInfo({
success: res => { success: function(res) {
// 可以将 res 发送给后台解码出 unionId return res.rawData
this.globalData.userInfo = res.userInfo },
fail: function(res){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 wx.showToast({
// 所以此处加入 callback 以防止这种情况 title:"系统错误",
if (this.userInfoReadyCallback) { duration:3000
this.userInfoReadyCallback(res)
}
}
}) })
} }
}
}) })
}, }
App({
globalData: { globalData: {
userId: null,
farmId: null,
userInfo: null userInfo: null
}, },
router: function(id){ onLaunch: function() {
console.log(id); // 登录
switch (id) { wx.login({
case 0: success: res => {
wx.navigateTo({ console.log(res)
url: 'pages/index/index', var _this = this;
// // 发送 res.code 到后台换取 openId, sessionKey, unionId
let code = res.code
if (code) {
// 根据code获取openid,以及是否是绑定用户
let info = getIdInfo(code)
// 以后修改为从info获取
let isUser = false
if(!isUser){
wx.showToast({
title:"第一次登录,请先填写个人信息",
icon:"none"
}) })
break; this.globalData.userInfo = getUserInfo()
case 1: setTimeout(function(){
wx.navigateTo({ wx.navigateTo({
url: 'pages/user/user', url: "../../pages/report/user/user_write"
}) })
break; }, 1000)
default:
// statements_def
break;
} }
} }
}
})
}
}) })
\ No newline at end of file
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
"pages":[ "pages":[
"pages/index/index", "pages/index/index",
"pages/logs/logs", "pages/logs/logs",
"pages/user/user" "pages/user/user",
"pages/report/user/user_write"
], ],
"window":{ "window":{
"backgroundTextStyle":"light", "backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#1cd8d7",
"navigationBarTitleText": "WeChat", "navigationBarTitleText": "智慧农场",
"navigationBarTextStyle":"black" "navigationBarTextStyle":"black"
} }
} }
/**app.wxss**/ /**app.wxss**/
@import 'weui.wxss';
input{
display: inline-block;
}
.container { .container {
height: 100%; height: 100%;
width: 100%; width: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
/* align-items: center; */ align-items: center;
justify-content: space-between; justify-content: space-between;
/* padding: 200rpx 0; */
box-sizing: border-box; box-sizing: border-box;
} }
.top{ .top{
width: 100%; width: 100%;
height: 10%; height: 70rpx;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
background-color: #1cd8d7;
border-bottom-left-radius: 20rpx;
border-bottom-right-radius: 20rpx;
}
.top image{
width: 45rpx;
height: 45rpx;
margin-right: 10rpx;
vertical-align: text-bottom;
} }
.top .button{ .top a{
display: inline-block;
width: 50%; width: 50%;
padding: 30rpx;
padding-top: 0;
padding-bottom: 0;
margin-top: 5rpx;
margin-bottom: 5rpx;
} }
.top .left{
text-align: left;
margin-left: 10rpx;
}
.top .right{
text-align: right;
margin-right: 10rpx;
}
/* .top .left{ /* .top .left{
} */ } */
\ No newline at end of file
var pages=[
"pages/index/index",
"pages/logs/logs",
"pages/user/user"
]
module.exports={
pages
}
\ No newline at end of file
...@@ -9,6 +9,15 @@ Page({ ...@@ -9,6 +9,15 @@ Page({
hasUserInfo: false, hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo') canIUse: wx.canIUse('button.open-type.getUserInfo')
}, },
onShow:function(){
if(app.userId){
wx.showToast({
title:"欢迎来到智慧农场~",
icon:"none",
duration:1500
})
}
},
// //事件处理函数 // //事件处理函数
// bindViewTap: function() { // bindViewTap: function() {
// wx.navigateTo({ // wx.navigateTo({
...@@ -54,7 +63,7 @@ Page({ ...@@ -54,7 +63,7 @@ Page({
// }, // },
toUser:function(){ toUser:function(){
wx.navigateTo({ wx.navigateTo({
url: '../user/user', url: "../../pages/user/user"
}) })
} }
}) })
<!--index.wxml--> <!--index.wxml-->
<view class="container"> <view class="container">
<view class="top"> <view class="top">
<button>我的</button> <a class="left"><image src="../../image/self.png"></image>我的</a>
<button>农场</button> <a class="right"><image src="../../image/farm.png"></image>农场</a>
<!-- <block wx:else> <!-- <block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image> <image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text> <text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block> --> </block> -->
</view> </view>
<view class="bottom"> <view class="bottom">
<button>历史体检报告</button> <button class="analy">体检报告解析</button>
<button>开始体检</button> <button class="start">开始体检</button>
<button>历史体检报告</button> <button class="curr" bindtap="toUser">我的体检报告</button>
<text class="user-motto" bindtap='toUser'>{{motto}}</text>
</view> </view>
</view> </view>
/**index.wxss**/ /**index.wxss**/
/* .userinfo { .bottom{
display: flex; position: fixed;
flex-direction: column; bottom: 10rpx;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
} }
.bottom button{
.userinfo-nickname { display: inline;
color: #aaa; margin: 5rpx;
padding-left: 15rpx;
padding-right: 15rpx;
padding-top: 8rpx;
padding-bottom: 8rpx;
/* background-color: blue; */
} }
/* .bottom */
.usermotto { .bottom .start{
margin-top: 200px; width: 130rpx;
} */ background-color: rgb(28,216,215);
/* .container{ box-shadow: 0rpx 0rpx 10px 2px #54fdfb;
padding-left: 25rpx;
} */ padding-right: 25rpx;
/* .top{ padding-top: 15rpx;
margin-top: 0; padding-bottom: 15rpx;
/* background-color: orange; */
/* border-radius: 65rpx; */
} }
\ No newline at end of file
.bottom{
margin-bottom: 0;
} */
\ No newline at end of file
const app = getApp()
Page({
data: {
userInfo:[
{
label:"姓名",
value:"",
choosed:0
},
{
label:"调查地点",
value:"",
choosed:0
},
{
label:"性别",
value:"",
choosed:1,
selects:[
{}
]
},
{
label:"年龄",
value:"",
choosed:0
},
{
label:"受教育程度",
value:"",
choosed:1,
selects:[
"高中以下",
"高中",
"大专",
"本科",
"研究生",
"博士及以上"
// {
// label:"高中以下",
// value:0
// },
// {
// label:"高中",
// value:1
// },
// {
// label:"大专",
// value:2
// },
// {
// label:"本科",
// value:3
// },
// {
// label:"研究生",
// value:4
// },
// {
// label:"博士及以上",
// value:5
// }
]
},
{
label:"从事农业时间",
value:"",
choosed:0
},
{
label:"之前从事的行业",
value:"",
choosed:0
}
],
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
onLoad:function(){
console.log("user_write.json")
},
commitInfo:function(){
app.userId=1;
console.log("提交成功");
wx.navigateBack({
delta: 1
})
}
})
\ No newline at end of file
{
"navigationBarTitleText": "负责人基本信息"
}
\ No newline at end of file
<view>
<div class="container">
<view wx:for="{{userInfo}}" wx:key="{{idx}}">
<text>{{item.label}}</text>
<input value="{{item.value}}" wx:if="{{!item.choosed}}" />
<picker mode="selector" range="{{item.selects}}" wx:else="{{item.choosed}}" ></picker>
</view>
<!-- <block>
<view>{{item.label}}</view>
</block> -->
<button class="commit" bindtap="commitInfo">开启智慧农场!</button>
</div>
</view>
\ No newline at end of file
input{
border: 1px solid black;
}
...@@ -16,32 +16,33 @@ Page({ ...@@ -16,32 +16,33 @@ Page({
}) })
}, },
onLoad: function () { onLoad: function () {
if (app.globalData.userInfo) { console.log(app.globalData.unionId);
this.setData({ // if (app.globalData.userInfo) {
userInfo: app.globalData.userInfo, // this.setData({
hasUserInfo: true // userInfo: app.globalData.userInfo,
}) // hasUserInfo: true
} else if (this.data.canIUse){ // })
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回 // } else if (this.data.canIUse){
// 所以此处加入 callback 以防止这种情况 // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
app.userInfoReadyCallback = res => { // // 所以此处加入 callback 以防止这种情况
this.setData({ // app.userInfoReadyCallback = res => {
userInfo: res.userInfo, // this.setData({
hasUserInfo: true // userInfo: res.userInfo,
}) // hasUserInfo: true
} // })
} else { // }
// 在没有 open-type=getUserInfo 版本的兼容处理 // } else {
wx.getUserInfo({ // // 在没有 open-type=getUserInfo 版本的兼容处理
success: res => { // wx.getUserInfo({
app.globalData.userInfo = res.userInfo // success: res => {
this.setData({ // app.globalData.userInfo = res.userInfo
userInfo: res.userInfo, // this.setData({
hasUserInfo: true // userInfo: res.userInfo,
}) // hasUserInfo: true
} // })
}) // }
} // })
// }
}, },
getUserInfo: function(e) { getUserInfo: function(e) {
console.log(e) console.log(e)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"ignore": [] "ignore": []
}, },
"setting": { "setting": {
"urlCheck": true, "urlCheck": false,
"es6": true, "es6": true,
"postcss": true, "postcss": true,
"minified": true, "minified": true,
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment