index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. // index.js
  2. const db=wx.cloud.database();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. qrCode: "../../images/qr.png",
  9. flag: "true",
  10. imgToggle: "../../images/qrcode.png",
  11. list: [
  12. {
  13. src: "../../images/rice.png",
  14. text: "饭"
  15. },
  16. {
  17. src: "../../images/noodles.png",
  18. text: "面"
  19. },
  20. {
  21. src: "../../images/congee.png",
  22. text: "粥"
  23. },
  24. {
  25. src: "../../images/drink.png",
  26. text: "饮料"
  27. }
  28. ]
  29. },
  30. input_name:function(e){
  31. this.setData({user_name:e.detail.value})
  32. },
  33. input_pwds:function(e){
  34. this.setData({user_pwds:e.detail.value})
  35. },
  36. login:function(){
  37. console.log("登录获取的参数:"+this.data.user_name+","+this.data.user_pwds);
  38. var that=this;
  39. wx.request({
  40. url: 'http://localhost:8084/login',
  41. method:'POST',
  42. header:{'content-type':'application/x-www-form-urlencoded'},
  43. data:{
  44. 'user_name':that.data.user_name,
  45. 'user_pwds':that.data.user_pwds
  46. },
  47. success:function(res){
  48. var resData=res.data;
  49. console.log(":"+resData);
  50. if(resData==true){
  51. wx.showToast({
  52. title: '登录成功',
  53. icon:'success',
  54. duration:15000,
  55. success:function(){
  56. wx.navigateTo({
  57. url: '../insert/insert',
  58. })
  59. }
  60. })
  61. }else{
  62. wx.showToast({
  63. title: '登陆失败',
  64. icon:'none',
  65. duration:2000,
  66. })
  67. }
  68. }
  69. })
  70. },
  71. toggleLogin: function(){
  72. this.setData({
  73. flag: !this.data.flag
  74. })
  75. },
  76. /**
  77. * 生命周期函数--监听页面加载
  78. */
  79. onLoad: function (options) {
  80. // 增
  81. // db.collection('product').add({
  82. // data:{
  83. // name:'小刘',
  84. // age:20,
  85. // gender:'男'
  86. // },
  87. // success(res){
  88. // console.log('添加数据成功',res)
  89. // },
  90. // fail(res){
  91. // console.log('添加数据失败',res)
  92. // }
  93. // })
  94. // 删
  95. // db.collection('product').doc('6d85a2b962a6a5ac0a4953f76ba21682').remove({
  96. // success(res){
  97. // console.log("数据删除成功",res)
  98. // },
  99. // fail(res){
  100. // console.log("数据删除失败",res)
  101. // }
  102. // })
  103. // 改
  104. // db.collection('product').doc('058dfefe62a6a83308856bcf1ec46e96').update({
  105. // data:{
  106. // name:'CreatorRay',
  107. // QQ:505417246
  108. // },
  109. // success(res){
  110. // console.log("数据修改成功")
  111. // },
  112. // fail(res){
  113. // console.log("数据修改失败")
  114. // }
  115. // })
  116. // 查 get
  117. // db.collection('product').get({
  118. // success(res){
  119. // console.log("查询成功",res)
  120. // },
  121. // fail(res){
  122. // console.log("查询失败",res)
  123. // }
  124. // })
  125. // 查 where
  126. // db.collection('product').where({
  127. // name:'CreatorRay'
  128. // }).get({
  129. // success(res){
  130. // console.log('name 为 Creator 的数据成功查到',res)
  131. // },
  132. // fail(res){
  133. // console.log('查询失败',res)
  134. // }
  135. // })
  136. },
  137. /**
  138. * 生命周期函数--监听页面初次渲染完成
  139. */
  140. onReady: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面显示
  144. */
  145. onShow: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面隐藏
  149. */
  150. onHide: function () {
  151. },
  152. /**
  153. * 生命周期函数--监听页面卸载
  154. */
  155. onUnload: function () {
  156. },
  157. /**
  158. * 页面相关事件处理函数--监听用户下拉动作
  159. */
  160. onPullDownRefresh: function () {
  161. },
  162. /**
  163. * 页面上拉触底事件的处理函数
  164. */
  165. onReachBottom: function () {
  166. },
  167. /**
  168. * 用户点击右上角分享
  169. */
  170. onShareAppMessage: function () {
  171. }
  172. })