index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // nova-werun/pages/home/signin/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. contentHeight2: 0,
  16. contentpadding: 0, //顶部padding高度
  17. //是否打卡
  18. issigin: false,
  19. images: [
  20. // 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1p97lf053250915.png',
  21. // 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/bt19fm050427168.png',
  22. 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/191d1m053251615.png'
  23. ],
  24. randomImage: '',
  25. accumulateChink:0,
  26. continuousChink:0
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. // 计算
  33. const systemInfo = wx.getSystemInfoSync();
  34. const statusBarHeight = systemInfo.statusBarHeight || 0;
  35. const screenHeight = systemInfo.screenHeight || 0;
  36. const custom = wx.getMenuButtonBoundingClientRect();
  37. const customHeight = custom.height + 10 + 2 || 0;
  38. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  39. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  40. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  41. this.setData({
  42. statusBarHeight,
  43. screenHeight,
  44. customHeight,
  45. bottomNavHeight,
  46. contentpadding,
  47. contentHeight
  48. });
  49. this.showRandomImage()
  50. this.order()
  51. this.accumulateChink()
  52. this.continuousChink()
  53. },
  54. /**
  55. * 生命周期函数--监听页面初次渲染完成
  56. */
  57. onReady: function () {
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow: function () {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload: function () {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. },
  89. //检查当天是否签到
  90. async order() {
  91. const currentUser = Parse.User.current();
  92. let EventLogquery = new Parse.Query('EventLog');
  93. EventLogquery.equalTo('user', currentUser.id);
  94. EventLogquery.equalTo('company', company);
  95. EventLogquery.notEqualTo('isDeleted', true)
  96. // 获取今天的日期
  97. const today = new Date();
  98. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  99. const todayEnd = new Date(todayStart);
  100. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  101. // 在查询条件中添加对 createdAt 的限制
  102. EventLogquery.greaterThanOrEqualTo('createdAt', todayStart);
  103. EventLogquery.lessThanOrEqualTo('createdAt', todayEnd);
  104. let P = await EventLogquery.first();
  105. if (P) {
  106. this.setData({
  107. issigin: true
  108. })
  109. return;
  110. }
  111. },
  112. async submit() {
  113. const currentUser = Parse.User.current();
  114. let EventLogquery = new Parse.Query('EventLog');
  115. EventLogquery.equalTo('user', currentUser.id);
  116. EventLogquery.equalTo('company', company);
  117. EventLogquery.notEqualTo('isDeleted', true)
  118. // 获取今天的日期
  119. const today = new Date();
  120. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  121. const todayEnd = new Date(todayStart);
  122. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  123. // 在查询条件中添加对 createdAt 的限制
  124. EventLogquery.greaterThanOrEqualTo('createdAt', todayStart);
  125. EventLogquery.lessThanOrEqualTo('createdAt', todayEnd);
  126. let P = await EventLogquery.first();
  127. if (P) {
  128. this.setData({
  129. issigin: true
  130. })
  131. console.log('今日已打卡');
  132. return;
  133. } else {
  134. const currentUser = Parse.User.current();
  135. let userquery = new Parse.Query('_User');
  136. userquery.equalTo('company', company);
  137. userquery.equalTo('objectId', currentUser.id);
  138. userquery.notEqualTo('isDeleted', true)
  139. let user = await userquery.first();
  140. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  141. let EventLog = new Parse.Object('EventLog');
  142. EventLog.set('points', 10)
  143. EventLog.set('company', companyPointer);
  144. EventLog.set('user', user.toPointer());
  145. try {
  146. let saveDate = await EventLog.save();
  147. console.log(saveDate);
  148. this.accumulateChink()
  149. this.setData({
  150. issigin: true
  151. })
  152. console.log("打卡成功");
  153. } catch (error) {
  154. console.error("保存数据时出现错误:", error);
  155. }
  156. }
  157. },
  158. //随机展示图片
  159. showRandomImage: function () {
  160. const randomIndex = Math.floor(Math.random() * this.data.images.length);
  161. this.setData({
  162. randomImage: this.data.images[randomIndex]
  163. });
  164. },
  165. //积累打卡
  166. async accumulateChink(){
  167. const currentUser = Parse.User.current();
  168. let EventLogquery = new Parse.Query('EventLog');
  169. EventLogquery.equalTo('user', currentUser.id);
  170. EventLogquery.equalTo('company', company);
  171. EventLogquery.notEqualTo('isDeleted', true)
  172. let P = await EventLogquery.find();
  173. let chickList = P.map(item => item.toJSON());
  174. this.setData({
  175. accumulateChink:chickList.length
  176. })
  177. },
  178. //连续打卡
  179. async continuousChink() {
  180. }
  181. })