ToB企服应用市场:ToB评测及商务社交产业平台

标题: 小程序用户和登录页面展示 [打印本页]

作者: 曹旭辉    时间: 2022-12-21 20:46
标题: 小程序用户和登录页面展示
用户页面wxml
  1. <view >
  2.   <view >
  3.     <view >
  4.       <view >
  5.         <image  wx:if="{{userInfo}}" src="{{userInfo.avatarUrl}}"></image>
  6.         <image  wx:else="{{userInfo}}" src="/static/2.png"></image>
  7.         
  8.         <view  wx:if="{{userInfo}}">
  9.           <view bindtap="onClickLogout">
  10.             {{userInfo.nickName}}
  11.           </view>
  12.         </view>
  13.         <view  wx:else="{{userInfo}}">
  14.           <navigator url="/pages/auth/auth">登录</navigator>
  15.           |
  16.           <navigator url="/pages/auth/auth">注册 </navigator>
  17.         </view>
  18.       </view>
  19.       <view >查看个人主页</view>
  20.     </view>
  21.     <view >
  22.       <view >
  23.         <text>0</text>
  24.         <text>关注</text>
  25.       </view>
  26.       <view >
  27.         <text>0</text>
  28.         <text>粉丝</text>
  29.       </view>
  30.       <view >
  31.         <text>0</text>
  32.         <text>赞与收藏</text>
  33.       </view>
  34.       <view >
  35.         <text>0</text>
  36.         <text>好友动态</text>
  37.       </view>
  38.     </view>
  39.   </view>
  40.   <view >
  41.     <view >
  42.       <image src="/static/images/icon/transaction_order1_icon_show.png"></image>
  43.       <text>待支付</text>
  44.     </view>
  45.     <view >
  46.       <image src="/static/images/icon/transaction_order2_icon_show.png"></image>
  47.       <text>待支付</text>
  48.     </view>
  49.     <view >
  50.       <image src="/static/images/icon/transaction_order3_icon_show.png"></image>
  51.       <text>待支付</text>
  52.     </view>
  53.     <view >
  54.       <image src="/static/images/icon/transaction_order4_icon_show.png"></image>
  55.       <text>待支付</text>
  56.     </view>
  57.     <view >
  58.       <image src="/static/images/icon/transaction_order5_icon_show.png"></image>
  59.       <text>待支付</text>
  60.     </view>
  61.   </view>
  62.   <view >
  63.     <view >
  64.       <view >我的钱包</view>
  65.       <view >
  66.         <text>¥20</text>
  67.         <image  src='/static/images/icon/to_icon_show_small.png'></image>
  68.       </view>
  69.     </view>
  70.     <view >
  71.       <view >我的优惠券</view>
  72.       <view >
  73.         <text>暂无课用</text>
  74.         <image  src='/static/images/icon/to_icon_show_small.png'></image>
  75.       </view>
  76.     </view>
  77.     <view >
  78.       <view >领劵中心</view>
  79.       <view >
  80.         <text>你的福利都在这里</text>
  81.         <image  src='/static/images/icon/to_icon_show_small.png'></image>
  82.       </view>
  83.     </view>
  84.   </view>
  85.   <view >
  86.     <button open-type="contact">
  87.       <image src="/static/images/icon/wechat_contact_icon_show.png"></image>
  88.     </button>
  89.     <button bindtap="onClickCall">
  90.       <image src="/static/images/icon/phone_contact_icon_show.png"></image>
  91.     </button>
  92.   </view>
  93. </view>
复制代码
用户页面js
  1. // pages/home/home.js
  2. var app = getApp();
  3. Page({
  4.   /**
  5.    * 页面的初始数据
  6.    */
  7.   data: {
  8.     userInfo: null,
  9.   },
  10.   /**
  11.    * 生命周期函数--监听页面加载(第一次打开时会执行)
  12.    */
  13.   onLoad: function (options) {
  14.   },
  15.   /**
  16.    * 生命周期函数--监听页面初次渲染完成(第一次打开时会执行)
  17.    */
  18.   onReady: function () {
  19.   },
  20.   /**
  21.    * 生命周期函数--监听页面显示
  22.    */
  23.   onShow: function () {
  24.     //本地storage中获取值
  25.     // var phone = wx.getStorageSync('phone')
  26.     // this.setData({
  27.     //   phone:phone
  28.     // })
  29.     //从全局变量中获取值
  30.     this.setData({
  31.       // phone:app.globalData.phone
  32.       userInfo: app.globalData.userInfo
  33.     })
  34.   },
  35.    /**
  36.    * 用户注销
  37.    */
  38.   onClickLogout:function(){
  39.     app.delUserInfo();
  40.     this.setData({
  41.       userInfo: null
  42.     })
  43.   },
  44.   /**
  45.    * 生命周期函数--监听页面隐藏
  46.    */
  47.   onHide: function () {
  48.   },
  49.   /**
  50.    * 生命周期函数--监听页面卸载
  51.    */
  52.   onUnload: function () {
  53.   },
  54.   /**
  55.    * 页面相关事件处理函数--监听用户下拉动作
  56.    */
  57.   onPullDownRefresh: function () {
  58.   },
  59.   /**
  60.    * 页面上拉触底事件的处理函数
  61.    */
  62.   onReachBottom: function () {
  63.   },
  64.   /**
  65.    * 用户点击右上角分享
  66.    */
  67.   onShareAppMessage: function () {
  68.   }
  69. })
复制代码
用户页面css
  1. /* pages/home/home.wxss */
  2. .top-view{
  3.   background-color: #01ccb6;
  4.   color: white;
  5.   padding: 40rpx;
  6. }
  7. .top-view .user{
  8.   display: flex;
  9.   flex-direction: row;
  10.   justify-content: space-between;
  11.   align-items: center;
  12. }
  13. .top-view .user .row{
  14.   display: flex;
  15.   flex-direction: row;
  16.   justify-content: flex-start;
  17.   align-items: center;
  18. }
  19. .top-view .user .avatar{
  20.   width: 100rpx;
  21.   height: 100rpx;
  22.   border-radius: 50%;
  23. }
  24. .top-view .user .name{
  25.   display: flex;
  26.   flex-direction: row;
  27.   justify-content: space-around;
  28.   width: 200rpx;
  29. }
  30. .top-view .site{
  31.   background-color: rgba(0, 0, 0, 0.16);
  32.   padding: 20rpx;
  33.   border-top-left-radius: 32rpx;
  34.   border-bottom-left-radius: 32rpx;
  35. }
  36. .top-view .numbers{
  37.   display: flex;
  38.   flex-direction: row;
  39.   justify-content: space-between;
  40.   font-size: 28rpx;
  41.   padding: 40rpx;
  42.   padding-bottom: 0rpx;
  43. }
  44. .top-view .numbers .row{
  45.    display: flex;
  46.   flex-direction: column;
  47.   align-items: center;
  48. }
  49. .middle-view{
  50.   padding: 40rpx;
  51.   display: flex;
  52.   flex-direction: row;
  53.   justify-content: space-between;
  54.   font-size: 25rpx;
  55.   border-bottom: 18rpx solid #f5f5f5;
  56. }
  57. .middle-view .item{
  58.   display: flex;
  59.   flex-direction: column;
  60.   align-items: center;
  61. }
  62. .middle-view .item image{
  63.   width: 50rpx;
  64.   height: 50rpx;
  65.   margin-bottom: 20rpx;
  66. }
  67. .function-view{
  68.   padding: 40rpx;
  69.   font-size: 28rpx;
  70. }
  71. .function-view .row{
  72.   padding: 30rpx 0;
  73.   border-bottom: 1px solid #efefef;
  74.   
  75.   display: flex;
  76.   flex-direction: row;
  77.   justify-content: space-between;
  78. }
  79. .function-view .row .right{
  80.   color: #8c8c8c;
  81. }
  82. .function-view .row .go-icon{
  83.   margin: 0 20rpx;
  84.   width: 16rpx;
  85.   height: 16rpx;
  86. }
  87. .contact-view{
  88.   padding: 40rpx;
  89.   display: flex;
  90.   flex-direction: row;
  91.   justify-content: space-around;
  92. }
  93. .contact-view button {
  94.   background-color: transparent;
  95.   border: 0;
  96.   padding: 0;
  97. }
  98. .contact-view button::after{
  99.   border: 0;
  100. }
  101. .contact-view  image{
  102.   width: 204rpx;
  103.   height: 66rpx;
  104. }
复制代码
登录注册页wxml
  1. <view >
  2.   <image src='/static/2.png'></image>
  3.   <text>交流交易社区</text>
  4. </view>
  5. <view >
  6.   <view >
  7.     <text>手机</text>
  8.    
  9.     <input placeholder="请填写手机号码" placeholder-class='txt' maxlength='11' value="{{phone}}" bindinput="bindPhoneInput" />
  10.   </view>
  11.    <view >
  12.     <text>验证码</text>
  13.     <input placeholder="请填写验证码" placeholder-class='txt' maxlength='4' value="{{code}}" bindinput="bindCodeInput" />
  14.     <view  bindtap="onClickCheckCode">获取验证码</view>
  15.   </view>
  16.   <view>
  17.     <button   open-type="getUserInfo" bindgetuserinfo="onClickSubmit">登录 | 注册</button>
  18.   </view>
  19. </view>
复制代码
登录注册页js
  1. // pages/auth/auth.js
  2. var app = getApp()
  3. Page({
  4.   /**
  5.    * 页面的初始数据
  6.    */
  7.   data: {
  8.     phone: "15822539779",
  9.     code: "",
  10.   },
  11.   bindPhoneInput: function (e) {
  12.     this.setData({
  13.       phone: e.detail.value
  14.     });
  15.   },
  16.   bindCodeInput: function (e) {
  17.     this.setData({
  18.       code: e.detail.value
  19.     });
  20.   },
  21.   /**
  22.    * 点击获取短信验证码
  23.    */
  24.   onClickCheckCode: function (e) {
  25.     // 判断手机号格式是否正确
  26.     if (this.data.phone.length == 0) {
  27.       wx.showToast({
  28.         title: '请填写手机号码',
  29.         icon: 'none'
  30.       })
  31.       return
  32.     }
  33.     var reg = /^(1[3|4|5|6|7|8|9])\d{9}$/;
  34.     if (!reg.test(this.data.phone)) {
  35.       wx.showToast({
  36.         title: '手机格式错误',
  37.         icon: 'none'
  38.       })
  39.       return
  40.     }
  41.     // 发送短信验证码,登录成功之后获取jwt和微信用户信息,保存到globalData和本地存储中。
  42.     wx.request({
  43.       url: "http://127.0.0.1:8000/api/message/",
  44.       data: {
  45.         phone: this.data.phone
  46.       },
  47.       method: 'GET',
  48.       dataType: 'json',
  49.       success: function (res) {
  50.         // 根据后端发送的status判断是否发送成功
  51.         if (res.data.status) {
  52.           // 提示验证码倒计时或者提示发送成功
  53.           wx.showToast({
  54.             title: res.data.message,
  55.             icon: 'none'
  56.           });
  57.         } else {
  58.           // 短信发送失败
  59.           wx.showToast({
  60.             title: res.data.message,
  61.             icon: 'none'
  62.           });
  63.         }
  64.       }
  65.     })
  66.   },
  67.   onClickSubmit(e) {
  68.     console.log(e)
  69.     wx.request({
  70.       url: "http://127.0.0.1:8000/api/login/",
  71.       data: {
  72.         phone: this.data.phone,
  73.         code: this.data.code
  74.       },
  75.       method: 'POST',
  76.       dataType: 'json',
  77.       success: function (res) {
  78.         // 根据status状态判断是否成功
  79.         if (res.data.status) {
  80.           // 1.可以将手机号放到公共的位置,比如app.js里,方便别的页面进行获取
  81.           // app.globalData.phone = res.data.data.phone
  82.           // 2.上述方法是将值存在变量里的,一重启就没有了,我们也可以将值保存在cookie中
  83.           // wx.setStorageSync('phone', res.data.data.phone)
  84.           // 3.将上述两种存储优化一下,在全局的app中定义一个initUserInfo方法,将用户初始化的信息(电话和token)传入该函数,然后上面1和2两部就可以放到该函数内执行了
  85.           // 4.优化,我们还可以将wx的用户信息也初始化到initUserInfo函数内
  86.           app.initUserInfo(res.data.data, e.detail.userInfo)
  87.           // 登录成功之后,自动跳转到上一级页面
  88.           //getCurrentPages方法是记录程序的页面,包括上一页信息,下一页信息等,pages是一个列表,最后一个是元素是当前页面,前一个元素是上一页
  89.           // var pages = getCurrentPages()
  90.           // console.log(pages)
  91.           // 得到上一页
  92.           // prepage  = pages[pages.length-2]
  93.           // 使用该方法就可以之前跳转到登录之前的上一页
  94.           wx.navigateBack({})
  95.         } else {
  96.           wx.showToast({
  97.             title: "登录失败",
  98.             icon: 'none'
  99.           });
  100.         }
  101.       }
  102.     })
  103.   },
  104.   /**
  105.    * 生命周期函数--监听页面加载
  106.    */
  107.   onLoad(options) {
  108.   },
  109.   /**
  110.    * 生命周期函数--监听页面初次渲染完成
  111.    */
  112.   onReady() {
  113.   },
  114.   /**
  115.    * 生命周期函数--监听页面显示
  116.    */
  117.   onShow() {
  118.   },
  119.   /**
  120.    * 生命周期函数--监听页面隐藏
  121.    */
  122.   onHide() {
  123.   },
  124.   /**
  125.    * 生命周期函数--监听页面卸载
  126.    */
  127.   onUnload() {
  128.   },
  129.   /**
  130.    * 页面相关事件处理函数--监听用户下拉动作
  131.    */
  132.   onPullDownRefresh() {
  133.   },
  134.   /**
  135.    * 页面上拉触底事件的处理函数
  136.    */
  137.   onReachBottom() {
  138.   },
  139.   /**
  140.    * 用户点击右上角分享
  141.    */
  142.   onShareAppMessage() {
  143.   }
  144. })
复制代码
登录注册页css
  1. /* pages/auth/auth.wxss */
  2. .logo{
  3.   display: flex;
  4.   flex-direction: column;
  5.   align-items: center;
  6. }
  7. .logo image {
  8.   margin-top: 140rpx;
  9.   width: 216rpx;
  10.   height: 100rpx;
  11. }
  12. .logo text {
  13.   margin-top: 26rpx;
  14.   margin-bottom: 50rpx;
  15.   font-size: 24rpx;
  16.   line-height: 24rpx;
  17.   font-weight: 400;
  18.   color: #8c8c8c;
  19.   text-align: center;
  20. }
  21. .form{
  22.   padding: 40rpx;
  23. }
  24. .form .row-group{
  25.   padding: 20rpx 0;
  26.   border-bottom: 1rpx solid #ddd;
  27.   position: relative;
  28. }
  29. .form .row-group text{
  30.   font-size: 28rpx;
  31.   padding:10rpx 0;
  32. }
  33. .form .row-group input{
  34.   padding: 10rpx 0;
  35. }
  36. .form .row-group .txt{
  37.   color: #ccc;
  38. }
  39. .form .row-group .code{
  40.   position: absolute;
  41.   right: 0;
  42.   bottom: 26rpx;
  43.   z-index: 2;
  44.   width: 206rpx;
  45.   height: 60rpx;
  46.   border: 2rpx solid #00c8b6;
  47.   border-radius: 12rpx;
  48.   font-size: 26rpx;
  49.   font-weight: 400;
  50.   color: #00c8b6;
  51.   display: flex;
  52.   align-items: center;
  53.   justify-content: center;
  54. }
  55. .form .submit{
  56.   margin-top: 80rpx;
  57.   color: #fff;
  58.   border: 2rpx solid #00c8b6;
  59.   background-color: #00c8b6;
  60.   font-size: 32rpx;
  61.   font-weight: bold;
  62. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4