当前位置:   article > 正文

微信小程序实现登录功能_wxlogin ts声明

wxlogin ts声明

一、效果

二、代码

 a、 login.json文件

  1. {
  2. "usingComponents": {},
  3. "navigationBarBackgroundColor": "#F2F2F2",
  4. "navigationBarTextStyle": "black",
  5. "navigationBarTitleText": "登录",
  6. "backgroundColor": "#eeeeee",
  7. "backgroundTextStyle": "light",
  8. "navigationStyle": "custom"
  9. }

b 、login.ts文件

  1. // pages/login/login.ts
  2. Page({
  3. /**
  4. * {
  5. "code": 200,
  6. "msg": null,
  7. "data": {
  8. "access_token": "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjo5ODExNywidXNlcl9rZXkiOiI1OWM3NzQ3OS0zZTdjLTQ0ZWEtYjJjMi0yMzYzMGQxOTQ5ZjgiLCJ1c2VybmFtZSI6InN6eSJ9.c1zGCLfLjWIQCzUsmOnkee12d1IxV4F0gDvhWOYswJy1M210Fw6o073Kjuxzd4A_AMGYRAcrdrKv3abHBbKghA",
  9. "expires_in": 720
  10. }
  11. }
  12. * 页面的初始数据
  13. */
  14. data: {
  15. is_disabled: false,
  16. username: "",
  17. password: "",
  18. showPwd: false,
  19. agree: false
  20. },
  21. //显示隐藏 密码
  22. show_no_pwd: function () {
  23. var ishow = !this.data.showPwd;
  24. this.setData({
  25. showPwd: ishow
  26. })
  27. },
  28. //协议勾选
  29. cnn_if_img: function () {
  30. var agrees = !this.data.agree;
  31. this.setData({
  32. agree: agrees
  33. })
  34. },
  35. //隐私声明
  36. cnn_if_cnn: function () {
  37. // console.log("====生命周期函数====")
  38. wx.navigateTo({
  39. url: '/pakageloginandregist/pages/login/privacy/privacypg'
  40. })
  41. },
  42. /**
  43. * 生命周期函数--
  44. * 监听页面加载
  45. */
  46. onLoad() {
  47. var that = this;
  48. },
  49. // 注册
  50. signup: function () {
  51. wx.navigateTo({
  52. url: '/pakageloginandregist/pages/regists/regist'
  53. })
  54. },
  55. // 登录
  56. login: function () {
  57. var that = this
  58. var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  59. if (that.data.username == '') {
  60. wx.showModal({
  61. title: '提示!',
  62. showCancel: false,
  63. content: '请输入账号!',
  64. success: function (res) { }
  65. })
  66. } else if (false) {//that.data.phone.length !=11
  67. wx.showModal({
  68. title: '提示!',
  69. showCancel: false,
  70. content: '手机号长度有误,请重新输入!',
  71. success: function (res) { }
  72. })
  73. } else if (false) {//!myreg.test(that.data.phone)
  74. wx.showModal({
  75. title: '提示!',
  76. showCancel: false,
  77. content: '请输入正确的账号!',
  78. success: function (res) { }
  79. })
  80. } else if (that.data.password == '') {
  81. wx.showModal({
  82. title: '提示!',
  83. showCancel: false,
  84. content: '请输入密码!',
  85. success: function (res) { }
  86. })
  87. } else {
  88. var agrees = this.data.agree;
  89. if (!agrees) {
  90. wx.showModal({
  91. title: '提示!',
  92. showCancel: false,
  93. content: '同意法律声明及隐私政策!',
  94. success: function (res) {
  95. that.loginPage()
  96. }
  97. })
  98. return;
  99. }
  100. //登录
  101. }
  102. },
  103. phoneInput: function (e: any) {
  104. this.data.username = e.detail.value
  105. },
  106. passwordInput: function (e: any) {
  107. this.data.password = e.detail.value
  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. })

c、login.wxml文件

  1. <!--pages/login/login.wxml-->
  2. <!-- 登录页面 -->
  3. <view class="background">
  4. <view class="head">
  5. <view class="tiltle">
  6. <view class="xiaoya">
  7. <text class="tiltle_healthy">nini<text class="tiltle_xiaoya">ok</text></text>
  8. </view>
  9. <text class="title_tag">saad wwav</text>
  10. </view>
  11. </view>
  12. <view class="first">
  13. <image class="user_name" src='/images/login/user_name.png' />
  14. <input id="name" placeholder="账号/手机号" placeholder-class='plas' maxlength='20' value='{{username}}' class='inputs' bindinput='phoneInput' type="text" />
  15. </view>
  16. <view class="second">
  17. <image class="user_name" src='/images/login/password.png' />
  18. <input id="psw" placeholder="密码" maxlength='20' placeholder-class='plas' class='inputs' value='{{password}}' type="{{showPwd?'text':'password'}}" bindinput='passwordInput' />
  19. <image class="show_no" bindtap="show_no_pwd" src="{{showPwd?'/images/login/show_pswd.png':'/images/login/no_pswd.png'}}" />
  20. </view>
  21. <view class="cnn_if">
  22. <image class="cnn_if_img" bindtap="cnn_if_img" src="{{agree?'/images/login/select_agree.png':'/images/login/no_agree.png'}}"></image>
  23. <view class="cnn_if_cnn" bindtap="cnn_if_cnn">已阅读并同意 <view style="color: #06c8ad;">《法律声明及隐私政策》</view>
  24. </view>
  25. </view>
  26. <button style="width: 80vw;height: 86rpx;border-radius:43rpx;background: linear-gradient(to right, #06c6ad, #01c6d9);" id="btn" form-type='submit' type="primary" class="click" disabled="{{is_disabled}}" bindtap="login">登 录</button>
  27. <view class="cha" bindtap='signup'>
  28. <text class="no">还没有账号?<text style="color: #06c8ad;">立即注册</text></text>
  29. </view>
  30. </view>

d、login.wxss文件

  1. /* pages/login/login.wxss */
  2. page {
  3. left: 0rpx;
  4. right: 0rpx;
  5. background-color: white;
  6. }
  7. .background{
  8. display: flex;
  9. flex-direction: column;
  10. justify-content: center;
  11. align-items: center;
  12. margin-top: 160rpx;
  13. }
  14. /* 标题 */
  15. .head{
  16. display: flex;
  17. width: 100%;
  18. justify-content: center;
  19. flex-direction: row;
  20. align-items: center;
  21. margin-top: 80rpx;
  22. }
  23. .headpic_vparent{
  24. width: 160rpx;
  25. height: 160rpx;
  26. border-radius: 80rpx;
  27. display: flex;
  28. align-items: center;
  29. justify-content: center;
  30. }
  31. .headpic{
  32. width: 140rpx;
  33. height: 150rpx;
  34. align-items: center;
  35. border-radius: 65rpx;
  36. }
  37. .tiltle{
  38. margin-left: 20rpx;
  39. }
  40. .user_name{
  41. width: 40rpx;
  42. height: 34rpx;
  43. margin-left: 20rpx;
  44. }
  45. .show_no{
  46. width: 66rpx;
  47. height: 40rpx;
  48. margin-right: 30rpx;
  49. }
  50. .tiltle_healthy{
  51. font-size: 40rpx;
  52. font-weight: bold;
  53. }
  54. .tiltle_xiaoya{
  55. font-size: 40rpx;
  56. color:#06c8ad;
  57. font-weight: bold;
  58. }
  59. /* 同意协议 */
  60. .cnn_if{
  61. height: 60rpx;
  62. margin-top: 100rpx;
  63. width: 80%;
  64. display: flex;
  65. flex-direction: row;
  66. align-items: center;
  67. justify-content: flex-start;
  68. }
  69. .cnn_if_img{
  70. width: 40rpx;
  71. height: 40rpx;
  72. margin-left: 30rpx;
  73. }
  74. .cnn_if_cnn{
  75. display: flex;
  76. flex-direction: row;
  77. font-size: 24rpx;
  78. margin-left: 10rpx;
  79. }
  80. /* 同意协议 */
  81. .title_tag{
  82. font-size: 32rpx;
  83. color: #CCCCCC;
  84. }
  85. /* 标题 */
  86. .first {
  87. width: 80%;
  88. height: 90rpx;
  89. display: flex;
  90. flex-direction: row;
  91. align-items: center;
  92. justify-content: center;
  93. margin-top: 80rpx;
  94. margin-left: 5%;
  95. margin-right: 5%;
  96. border-radius: 45rpx;
  97. background-color: #f2f2f2;
  98. }
  99. .plas {
  100. font-size: 30rpx;
  101. color: #CCCCCC;
  102. }
  103. .inputs {
  104. line-height: 100rpx;
  105. font-size: 30rpx;
  106. color: #000;
  107. margin-right: 60rpx;
  108. margin-left: 20rpx;
  109. width: 100%;
  110. }
  111. .second {
  112. width: 80%;
  113. height: 90rpx;
  114. display: flex;
  115. flex-direction: row;
  116. align-items: center;
  117. justify-content: center;
  118. margin-top: 30rpx;
  119. margin-left: 5%;
  120. margin-right: 5%;
  121. border-radius: 45rpx;
  122. background-color: #f2f2f2;
  123. }
  124. .click {
  125. width: 90%;
  126. height: 100rpx;
  127. line-height: 100rpx;
  128. margin: auto;
  129. margin-top: 20rpx;
  130. margin-left: 5%;
  131. margin-right: 5%;
  132. background-color: #F76968;
  133. text-align: center;
  134. color: white;
  135. font-size: 33rpx;
  136. border-radius: 15rpx;
  137. display:flex;
  138. align-items: center;
  139. justify-content: center;
  140. }
  141. .cha {
  142. width: 80%;
  143. height: 50rpx;
  144. margin: auto;
  145. margin-top: 30rpx;
  146. margin-left: 5%;
  147. margin-right: 5%;
  148. }
  149. .no {
  150. color: black;
  151. font-size: 28rpx;
  152. margin-left: 15rpx;
  153. font-family: "PingFangSC-regular";
  154. }

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

闽ICP备14008679号