前言

感谢! 承蒙关照~

微信小程序我的界面

界面效果:

界面结构:

小程序代码:

我们先看me.json代码

{
"navigationBarTitleText": "个人中心"
}

me.wxml代码

<view class="bg">
<view class="head">
<view class="headIcon">
<image src="{{userInfo.avatarUrl}}" style="width:70px;height:70px;"></image>
</view>
<view class="login">
{{userInfo.nickName}}
</view>
</view>
<button class="button" open-type="getUserInfo" wx:if="{{hasUserInfo}}" bindgetuserinfo="doAuthorization"> 微信登录 </button>
</view> <view class="hr"></view>
<view class='item'>
<view class="title">手机绑定</view>
<view class="detail2">
<text>></text>
</view>
</view>
<view class="line"></view> <view class='item'>
<view class="title">阅读文章</view>
<view class="detail2">
<text>></text>
</view>
</view> <view class="hr"></view>
<view class='item'>
<view class="title">电影推荐</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">我的收藏</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">意见反馈</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="line"></view>
<view class="item">
<view class="title">设置</view>
<view class="detail2">
<text> ></text>
</view>
</view>
<view class="hr"></view>

me.wxss代码

.bg {
height: 150px;
background-color: #d53e37;
} .head {
display: flex;
flex-direction: column;
} .headIcon {
display: flex;
justify-content: center;
} .login {
display: flex;
color: #fff;
font-size: 15px;
margin-top: 15rpx;
justify-content: center;
} .button {
margin: 10px;
font-size: 14px;
} .head image {
border-radius: 50%;
} .hr {
width: 100%;
height: 15px;
background-color: #f4f5f6;
} .item {
display: flex;
flex-direction: row;
} .title {
padding-top: 15px;
padding-bottom: 15px;
padding-left: 15px;
font-size: 15px;
} .detail2 {
font-size: 15px;
position: absolute;
right: 10px;
height: 50px;
line-height: 50px;
color: #888;
} .line {
border: 1px solid #ccc;
opacity: 0.2;
}

me.js代码

//index.js
//获取应用实例
const app = getApp()
var openid = wx.getStorageSync("openid");
Page({
data: {
hasUserInfo: openid == ""
},
doAuthorization: function(e) {
var that = this;
console.log("调用了 doAuthorization 授权");
// console.log(e);
if (e.detail.userInfo == null) { //为null 用户拒绝了授权
//coding。。。。
console.log("用户拒绝授权");
} else {
//授权
wx.login({
success: function(res) {
console.log('login:code', res.code)
//发送请求
wx.request({
url: app.globalData.userInterfaceUrl + 'record/' + res.code, //接口地址
method: 'GET',
header: {
'content-type': 'application/json' //默认值
},
success: function(res) {
console.log("record 成功", res.data)
var res = res.data;
if (res.error) { //发生错误
console.log("错误:", res.msg);
} else { //返回成功
try {
wx.setStorageSync('openid', res.data.openid)
openid = wx.getStorageSync("openid");
} catch (e) {
console.log("wx.login 错误", e);
}
//加载用户信息
that.loadUserInfo();
that.setData({ //设置变量
hasUserInfo: false
});
}
},
fail: function(err) {
console.log("record 失败", err);
}
})
}
})
} },
loadUserInfo: function() {
var that = this;
if (openid != "") {
wx.getUserInfo({
success: res => {
console.log("wx获得用户信息:", res);
var data = {
"openid": openid,
"user": res.userInfo
}
//发送信息给服务器获得用户信息
wx.request({
url: app.globalData.userInterfaceUrl + 'login',
dataType: "json",
method: "POST",
data: data,
success: function(res) {
console.log("loadUserInfo(服務器返回) success", res.data);
if (!res.data.error) {
app.globalData.userInfo = res.data.data;
that.setData({
userInfo: app.globalData.userInfo
})
} else {
console.log("服务器获取用戶信息失敗");
//TODO:用户信息获取错误
}
},
fail: function(e) {
console.log("loadUserInfo(服务器返回)error", e);
//TODO:错误
},
complete: function(e) {
//完成
}
})
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}, // 事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onShow: function() {
var that = this;
console.log("openid:", openid);
that.loadUserInfo();
}
})

达叔小生:往后余生,唯独有你

You and me, we are family !

90后帅气小伙,良好的开发习惯;独立思考的能力;主动并且善于沟通

简书博客: 达叔小生

https://www.jianshu.com/u/c785ece603d1

结语

  • 下面我将继续对 其他知识 深入讲解 ,有兴趣可以继续关注
  • 小礼物走一走 or 点赞

微信小程序我的界面的更多相关文章

  1. 微信小程序之跨界面传参

    微信小程序在两个之间传参类似js传递url拼接参数,举个例子来说吧 input自己设置参数 //index.wxml <form bindsubmit="formSubmit" ...

  2. 微信小程序5 - 数据驱动界面

    微信小程序不可以使用js直接控制界面元素.而是通过改变 this.data中的属性,同步到界面 这个问题可以克服,带来的就是和H5不一样的编码方式.JS中更多的是改变数据的逻辑,而不是获取某个View ...

  3. 微信小程序开发--API界面交互

    一.wx:showActionSheet(上拉菜单) 属性 类型 默认值 必填 说明 itemList Array.<string>   是 按钮的文字数组,数组长度最大为 6 itemC ...

  4. 微信小程序如何刷新当前界面

    在微信小程序开发的过程中,在一个页面中对数据操作之后我们大多数时间都需要刷新一下当前界面以把操作之后的结果显示出来,但是如何在执行操作后进行本页面的刷新就成了一个问题很大但是很需要的操作.下面介绍一下 ...

  5. 迅雷首席架构师刘智聪:微信小程序的架构与系统设计的几点观感

    笔者注:本文来自于迅雷首席工程师刘智聪的个人分享,他毕业于南昌大学化学系,加入迅雷后设计开发了多款迅雷核心产品,凭借“大规模网络流媒体服务关键支撑技术”项目获得2015年国家科学技术进步奖二等奖,同时 ...

  6. 微信小程序开发:http请求

    在微信小程序进行网络通信,只能和指定的域名进行通信,微信小程序包括四种类型的网络请求. 普通HTTPS请求(wx.request) 上传文件(wx.uploadFile) 下载文件(wx.downlo ...

  7. [转]微信小程序开发:http请求

    本文转自:http://www.cnblogs.com/dragondean/p/5921079.html 在微信小程序进行网络通信,只能和指定的域名进行通信,微信小程序包括四种类型的网络请求. 普通 ...

  8. 微信小程序开发中的http请求总结

    在微信小程序进行网络通信,只能和指定的域名进行通信,微信小程序包括四种类型的网络请求. 普通HTTPS请求(wx.request) 上传文件(wx.uploadFile) 下载文件(wx.downlo ...

  9. 教你如何一键反编译获取任何微信小程序源代码(图形化界面,傻瓜式操作)

    一键获取微信小程序源代码 Tips: 一键获取微信小程序源码, 使用了C#加nodejs制作 直接解压在D盘根目录下后就可以使用 将小程序文件放到 wxapkg目录下3 这个目录下有一些demo 可以 ...

随机推荐

  1. Git冲突标记介绍

    <<<<<<< head 是指你本地的分支的 <<<<<<< HEADb789=======b45678910> ...

  2. JAVA课程设计-教学论坛系统

    团队课程设计博客 1. 团队名称:教学论坛系统设计团队 团队成员介绍: 郑佳亮(组长):201721123022,查看帖子,点赞,参与度,搜索,管理员删帖的后端,点赞,参与度前端 李于程(组员):20 ...

  3. Firefox 调试 JavaScript 代码

    第一步  新建 html 或者 jsp 文件 文件内容 <!DOCTYPE html> <html> <head> <meta charset="u ...

  4. Android.mk学习

    2019-03-31 学习变量 $(call my-dir) /usr/bin2/android-ndk-r16/build/core $(CLEAR_VARS) /usr/bin2/android- ...

  5. net::ERR_CONNECTION_RESET 问题排查

    后台服务器代码有问题 实体不对称,导致映射不对

  6. Google资深工程师深度讲解Go语言完整教程

    资源获取链接点击这里 欢迎大家来到深度讲解Go语言的课堂.本课程将从基本语法讲起,逐渐深入,帮助同学深度理解Go语言面向接口,函数式编程,错误处理,测试,并行计算等元素,并带领大家实现一个分布式爬虫的 ...

  7. YAML-CPP

    yaml作为一种便捷的文件格式,通过c++进行操作时,可以利用yaml-cpp进行. 一,yaml-cpp的安装 下载源码 git clone https://github.com/jbeder/ya ...

  8. 【机器学习】随机森林 Random Forest 得到模型后,评估参数重要性

    在得出random forest 模型后,评估参数重要性 importance() 示例如下 特征重要性评价标准 %IncMSE 是 increase in MSE.就是对每一个变量 比如 X1 随机 ...

  9. Player2.0

    由于上次做的播放器实在是有点丑,加之这期间学习了许多关于页面排版的东西,这次做第二次作业就重新来了一遍“换汤不换药”的操作.其实刚开始看到的作业要求的时候,有点傻眼猫咪,但是做到现在这个程度,本人也是 ...

  10. Python从入门到精通之Sixth!

    补充:enumerate 函数用于遍历序列(元组tuple.列表list.字典dict)中的元素以及它们的下标: >>> for i,j in enumerate(('a','b', ...