当前位置:   article > 正文

【小白专用】微信小程序个人中心、我的界面(示例一)23.11.04_微信小程序中个人中心页面

微信小程序中个人中心页面

微信小程序使用button按钮实现个人中心、我的界面(示例一)

微信小程序个人中心、我的界面,使用button按钮实现界面布局,更好的将分享好友、获取头像等功能展现出来,更多示例界面,请前往我的主页哦。

1、js代码:

  1. // pages/my/my3.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. login: {
  8. show: false,
  9. line: false,
  10. avatar: 'https://img0.baidu.com/it/u=3204281136,1911957924&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
  11. }
  12. },
  13. // 登录监听
  14. chooseAvatar(e) {
  15. this.setData({
  16. login: {
  17. show: true,
  18. line:true,
  19. avatar: e.detail.avatarUrl,
  20. }
  21. })
  22. },
  23. // 基本信息
  24. basicClick() {
  25. console.log('基本信息监听');
  26. },
  27. // 匿名反馈
  28. feedbackClick() {
  29. console.log('匿名反馈监听');
  30. },
  31. // 关于我们
  32. aboutClick() {
  33. console.log('关于我们监听');
  34. },
  35. // 退出监听
  36. exitClick() {
  37. let that = this;
  38. wx.showModal({
  39. title: '提示',
  40. content: '确定退出登录吗?',
  41. success(res) {
  42. if (res.confirm) {
  43. that.setData({
  44. login: {
  45. show: false,
  46. avatar: 'https://img0.baidu.com/it/u=3204281136,1911957924&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
  47. }
  48. })
  49. }
  50. }
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad(options) {
  57. },
  58. /**
  59. * 生命周期函数--监听页面初次渲染完成
  60. */
  61. onReady() {
  62. },
  63. /**
  64. * 生命周期函数--监听页面显示
  65. */
  66. onShow() {
  67. },
  68. /**
  69. * 生命周期函数--监听页面隐藏
  70. */
  71. onHide() {
  72. },
  73. /**
  74. * 生命周期函数--监听页面卸载
  75. */
  76. onUnload() {
  77. },
  78. /**
  79. * 页面相关事件处理函数--监听用户下拉动作
  80. */
  81. onPullDownRefresh() {
  82. },
  83. /**
  84. * 页面上拉触底事件的处理函数
  85. */
  86. onReachBottom() {
  87. },
  88. /**
  89. * 用户点击右上角分享
  90. */
  91. onShareAppMessage() {
  92. }
  93. })

2、wxml代码

  1. <!--pages/my/my3.wxml-->
  2. <view class="top-bg"></view>
  3. <view class="box">
  4. <!-- 头像 -->
  5. <view class="head-box">
  6. <button open-type="chooseAvatar" class="avatar" bindchooseavatar="chooseAvatar">
  7. <image class="head-img" src="{{login.avatar}}" mode="widthFix"></image>
  8. </button>
  9. <view class="tip">{{login.show?'欢迎使用':'当前未登录,请登录!'}}</view>
  10. </view>
  11. <!-- 第一部分列表 -->
  12. <view>
  13. <button class="row" style="width: 100%;" bindtap="basicClick">
  14. <view class="left">
  15. <icon class="icon-small" type="success" size="16"></icon>
  16. <text class="text">基本信息</text>
  17. </view>
  18. <view class="right">》</view>
  19. </button>
  20. <button class="row" style="width: 100%;" bindtap="feedbackClick">
  21. <view class="left">
  22. <icon class="icon-small" type="success" size="16"></icon>
  23. <text class="text">匿名反馈</text>
  24. </view>
  25. <view class="right">》</view>
  26. </button>
  27. <button class="row" style="width: 100%;border-bottom: none;" bindtap="aboutClick">
  28. <view class="left">
  29. <icon class="icon-small" type="success" size="16"></icon>
  30. <text class="text">关于我们</text>
  31. </view>
  32. <view class="right">》</view>
  33. </button>
  34. </view>
  35. </view>
  36. <!-- 第二部分列表 -->
  37. <view class="end">
  38. <button open-type="share" class="row" style="width: 100%;">
  39. <view class="left">
  40. <icon class="icon-small" type="success" size="16"></icon>
  41. <text class="text">分享好友</text>
  42. </view>
  43. <view class="right">》</view>
  44. </button>
  45. <button open-type="contact" class="row" style="width: 100%;border-bottom: none;">
  46. <view class="left">
  47. <icon class="icon-small" type="success" size="16"></icon>
  48. <text class="text">在线客服</text>
  49. </view>
  50. <view class="right">》</view>
  51. </button>
  52. </view>
  53. <!-- 第三部分列表 -->
  54. <view class="end">
  55. <button wx:if="{{login.line}}" bindtap="exitClick" class="row" style="width: 100%;border-bottom: none;">
  56. <view class="left">
  57. <icon class="icon-small" type="success" size="16"></icon>
  58. <text class="text">退出登录</text>
  59. </view>
  60. </button>
  61. <button class="row" open-type="chooseAvatar" bindchooseavatar="chooseAvatar" style="width: 100%;border-bottom: none;" wx:else>
  62. <view class="left">
  63. <icon class="icon-small" type="success" size="16"></icon>
  64. <text class="text">立即登录</text>
  65. </view>
  66. </button>
  67. </view>
  68. <view class="footer">
  69. <text>©微信小程序个人中心@wxd</text>
  70. </view>

3、wxss代码

  1. /* pages/my/my3.wxss */
  2. page {
  3. background-color: #f1f1f1;
  4. }
  5. /* 设置背景颜色 */
  6. .top-bg {
  7. height: 200rpx;
  8. background-color: #008c8c;
  9. }
  10. /* 圆角盒子 */
  11. .box {
  12. background-color: white;
  13. margin-top: -120rpx;
  14. border-top-left-radius: 50rpx;
  15. border-top-right-radius: 50rpx;
  16. padding: 0 20rpx;
  17. }
  18. /* 头像部分 */
  19. .head-box {
  20. display: flex;
  21. flex-direction: column;
  22. justify-content: center;
  23. align-items: center;
  24. border-bottom: 1rpx solid #fbdbdc;
  25. padding-bottom: 20rpx;
  26. }
  27. .avatar {
  28. margin-top: -80rpx;
  29. font-weight: inherit;
  30. display: flex;
  31. justify-content: center;
  32. background-color: rgba(0, 0, 0, 0);
  33. }
  34. .avatar::after {
  35. border: none;
  36. }
  37. .head-img {
  38. width: 140rpx;
  39. height: 140rpx;
  40. overflow: hidden;
  41. border-radius: 50%;
  42. background-color: #fbdbdc;
  43. }
  44. .tip {
  45. font-size: 26rpx;
  46. color: gray;
  47. margin: 15rpx 0;
  48. }
  49. /* 列表部分 */
  50. .row {
  51. display: flex;
  52. align-items: center;
  53. padding: 36rpx 10rpx;
  54. font-size: 30rpx;
  55. font-weight: inherit;
  56. background-color: rgba(0, 0, 0, 0);
  57. border-bottom: 1rpx solid #fbdbdc;
  58. }
  59. .row::after {
  60. border: none;
  61. }
  62. .text {
  63. margin-left: 15rpx;
  64. color: #636262;
  65. }
  66. .left {
  67. width: 90%;
  68. text-align: left;
  69. display: flex;
  70. align-items: center;
  71. }
  72. .right {
  73. width: 10%;
  74. text-align: right;
  75. color: rgb(148, 147, 147);
  76. }
  77. .end {
  78. background-color: white;
  79. margin-top: 20rpx;
  80. padding: 0 20rpx;
  81. }
  82. .footer {
  83. display: flex;
  84. justify-content: center;
  85. align-items: center;
  86. padding: 20rpx 0;
  87. font-size: 22rpx;
  88. margin: 30rpx 0;
  89. color: gray;
  90. }

4、json代码

  1. {
  2. "usingComponents": {},
  3. "navigationBarBackgroundColor": "#008c8c",
  4. "navigationBarTitleText": "个人中心"
  5. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/840898
推荐阅读
相关标签
  

闽ICP备14008679号