Commit 3839be55 authored by zhangzedan's avatar zhangzedan

index user_registe

parent 4d147219
//app.js
var jsonData = require('app.json');
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
var pages = require('js/pages.js');
// 将code传输到服务器
function getIdInfo(code){
wx.request({
url: 'http://192.168.31.6:8080/login/getMessageByCode',//自己的服务接口地址
method: 'post',
data: {code: code},
success(res) {
console.log(res)
},
fail(res) {
wx.showToast({
title:"系统错误",
duration:5000,
icon:"none"
})
}
})
return {}
}
function getUserInfo(){
wx.getUserInfo({
success: function(res) {
return res.rawData
},
fail: function(res){
wx.showToast({
title:"系统错误",
duration:3000
})
}
})
}
App({
globalData: {
userId: null,
farmId: null,
userInfo: null
},
onLaunch: function() {
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
console.log(res)
var _this = this;
// // 发送 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 () {
// console.log('获取用户信息失败')
}
})
if (code) {
// 根据code获取openid,以及是否是绑定用户
let info = getIdInfo(code)
// 以后修改为从info获取
let isUser = false
if(!isUser){
wx.showToast({
title:"第一次登录,请先填写个人信息",
icon:"none"
})
this.globalData.userInfo = getUserInfo()
setTimeout(function(){
wx.navigateTo({
url: "../../pages/report/user/user_write"
})
}, 1000)
}
}
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
},
router: function(id){
console.log(id);
switch (id) {
case 0:
wx.navigateTo({
url: 'pages/index/index',
})
break;
case 1:
wx.navigateTo({
url: 'pages/user/user',
})
break;
default:
// statements_def
break;
}
}
})
\ No newline at end of file
......@@ -2,12 +2,13 @@
"pages":[
"pages/index/index",
"pages/logs/logs",
"pages/user/user"
"pages/user/user",
"pages/report/user/user_write"
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "WeChat",
"navigationBarBackgroundColor": "#1cd8d7",
"navigationBarTitleText": "智慧农场",
"navigationBarTextStyle":"black"
}
}
/**app.wxss**/
@import 'weui.wxss';
input{
display: inline-block;
}
.container {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
/* align-items: center; */
align-items: center;
justify-content: space-between;
/* padding: 200rpx 0; */
box-sizing: border-box;
}
.top{
width: 100%;
height: 10%;
height: 70rpx;
display: flex;
flex-direction: row;
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 a{
display: inline-block;
width: 50%;
padding: 30rpx;
padding-top: 0;
padding-bottom: 0;
margin-top: 5rpx;
margin-bottom: 5rpx;
}
.top .button{
width: 50%;
.top .left{
text-align: left;
margin-left: 10rpx;
}
.top .right{
text-align: right;
margin-right: 10rpx;
}
/* .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({
hasUserInfo: false,
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
onShow:function(){
if(app.userId){
wx.showToast({
title:"欢迎来到智慧农场~",
icon:"none",
duration:1500
})
}
},
// //事件处理函数
// bindViewTap: function() {
// wx.navigateTo({
......@@ -54,7 +63,7 @@ Page({
// },
toUser:function(){
wx.navigateTo({
url: '../user/user',
url: "../../pages/user/user"
})
}
})
<!--index.wxml-->
<view class="container">
<view class="top">
<button>我的</button>
<button>农场</button>
<a class="left"><image src="../../image/self.png"></image>我的</a>
<a class="right"><image src="../../image/farm.png"></image>农场</a>
<!-- <block wx:else>
<image bindtap="bindViewTap" class="userinfo-avatar" src="{{userInfo.avatarUrl}}" mode="cover"></image>
<text class="userinfo-nickname">{{userInfo.nickName}}</text>
</block> -->
</view>
<view class="bottom">
<button>历史体检报告</button>
<button>开始体检</button>
<button>历史体检报告</button>
<text class="user-motto" bindtap='toUser'>{{motto}}</text>
<button class="analy">体检报告解析</button>
<button class="start">开始体检</button>
<button class="curr" bindtap="toUser">我的体检报告</button>
</view>
</view>
/**index.wxss**/
/* .userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
.bottom{
position: fixed;
bottom: 10rpx;
}
.usermotto {
margin-top: 200px;
} */
/* .container{
} */
/* .top{
margin-top: 0;
.bottom button{
display: inline;
margin: 5rpx;
padding-left: 15rpx;
padding-right: 15rpx;
padding-top: 8rpx;
padding-bottom: 8rpx;
/* background-color: blue; */
}
.bottom{
margin-bottom: 0;
} */
\ No newline at end of file
/* .bottom */
.bottom .start{
width: 130rpx;
background-color: rgb(28,216,215);
box-shadow: 0rpx 0rpx 10px 2px #54fdfb;
padding-left: 25rpx;
padding-right: 25rpx;
padding-top: 15rpx;
padding-bottom: 15rpx;
/* background-color: orange; */
/* border-radius: 65rpx; */
}
\ 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({
})
},
onLoad: function () {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
console.log(app.globalData.unionId);
// if (app.globalData.userInfo) {
// this.setData({
// userInfo: app.globalData.userInfo,
// hasUserInfo: true
// })
// } else if (this.data.canIUse){
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// app.userInfoReadyCallback = res => {
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
// }
// } else {
// // 在没有 open-type=getUserInfo 版本的兼容处理
// wx.getUserInfo({
// success: res => {
// app.globalData.userInfo = res.userInfo
// this.setData({
// userInfo: res.userInfo,
// hasUserInfo: true
// })
// }
// })
// }
},
getUserInfo: function(e) {
console.log(e)
......
......@@ -4,7 +4,7 @@
"ignore": []
},
"setting": {
"urlCheck": true,
"urlCheck": false,
"es6": true,
"postcss": 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