储能智慧云小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // pages/login/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 状态栏高度
  9. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  10. // 导航栏高度
  11. navBarHeight: wx.getStorageSync('navBarHeight'),
  12. // 导航栏和状态栏高度
  13. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  14. // 胶囊
  15. menu:wx.getStorageSync('menu'),
  16. account:'',
  17. password:'',
  18. passwordtype:true,
  19. checked:false,
  20. isChecked: false, // 单选框是否被勾选
  21. shakeClass: '', // 控制晃动动画的类名
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad(options) {
  27. },
  28. onpassword(){
  29. console.log(111);
  30. this.setData({
  31. passwordtype:!this.data.passwordtype
  32. })
  33. },
  34. checkboxChange(e) {
  35. console.log('checkbox发生change事件,携带value值为:', e.currentTarget.dataset.value)
  36. this.setData({
  37. checked:!e.currentTarget.dataset.value
  38. })
  39. },
  40. // 处理单选框状态变化
  41. onRadioChange(e) {
  42. this.setData({
  43. isChecked: e.detail.value === 'agree',
  44. });
  45. },
  46. bindKeyInput1: function (e) {
  47. this.setData({
  48. account: e.detail.value
  49. })
  50. },
  51. bindKeyInput2: function (e) {
  52. this.setData({
  53. password: e.detail.value
  54. })
  55. },
  56. // 处理登录按钮点击
  57. onLogin() {
  58. if (!this.data.checked) {
  59. return wx.showToast({
  60. title: '请勾选同意',
  61. icon: 'none',
  62. });
  63. }
  64. let data ={
  65. username:this.data.account,
  66. password:this.data.password,
  67. rememberMe: 1
  68. }
  69. console.log(data);
  70. api.request('/auth/login', 'POST',data).then((res) => {
  71. console.log(res);
  72. if (res.code==200&&res.status=='ok') {
  73. // 设置数据到本地存储
  74. wx.setStorage({
  75. key: 'cookies', // 存储的key值
  76. data:res.msg,
  77. success: function(ress) {
  78. console.log(ress);
  79. // 获取本地存储的数据
  80. wx.reLaunch({
  81. url: '/pages/index/index'
  82. });
  83. wx.showToast({
  84. title: '登录成功',
  85. icon: 'success',
  86. });
  87. }
  88. });
  89. }else{
  90. wx.showToast({
  91. title: res.msg,
  92. icon: 'none',
  93. });
  94. }
  95. // 在这里处理返回的数据
  96. })
  97. .catch((err) => {
  98. console.error('请求失败:', err);
  99. // 在这里处理请求失败的情况
  100. });
  101. },
  102. onprivacy(e){
  103. console.log(e.target.dataset.name);
  104. wx.navigateTo({
  105. url: `/pages/privacy/index?name=${e.target.dataset.name}`,
  106. })
  107. },
  108. /**
  109. * 生命周期函数--监听页面初次渲染完成
  110. */
  111. onReady() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面显示
  115. */
  116. onShow() {
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide() {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload() {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh() {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom() {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage() {
  142. }
  143. })