index.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // nova-werun/components/my/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. //屏幕高度
  15. statusBarHeight: 0, // 状态栏高度
  16. screenHeight: 0, // 屏幕高度
  17. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  18. bottomNavHeight: 0, // 底部导航栏高度
  19. contentHeight: 0, // 可用内容高度
  20. contentpadding: 0, //顶部padding高度
  21. navheight:0,
  22. circlecount: 0,
  23. likesCount:0,
  24. User1List:[],
  25. profile1List2:[]
  26. },
  27. lifetimes: {
  28. detached: function () {
  29. // 在组件实例被从页面节点树移除时执行
  30. },
  31. attached: async function () {
  32. // 在组件实例进入页面节点树时执行
  33. // 计算
  34. const systemInfo = wx.getSystemInfoSync();
  35. const statusBarHeight = systemInfo.statusBarHeight || 0;
  36. const screenHeight = systemInfo.screenHeight || 0;
  37. const custom = wx.getMenuButtonBoundingClientRect();
  38. const customHeight = custom.height + 10 + 2 || 0;
  39. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  40. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  41. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  42. const navheight = (statusBarHeight+customHeight) * 750 / systemInfo.windowWidth;
  43. this.setData({
  44. statusBarHeight,
  45. screenHeight:(screenHeight-50-bottomNavHeight) * 750 / systemInfo.windowWidth,
  46. customHeight,
  47. bottomNavHeight,
  48. contentHeight,
  49. contentpadding,
  50. navheight
  51. });
  52. this.getcircle()
  53. this.getname()
  54. },
  55. },
  56. /**
  57. * 组件的方法列表
  58. */
  59. methods: {
  60. gourl(e) {
  61. const url = e.currentTarget.dataset.url
  62. wx.navigateTo({
  63. url: `${url}` // 目标页面的路径
  64. });
  65. },
  66. //查全部朋友圈
  67. // async getcircle() {
  68. // const currentUser = Parse.User.current();
  69. // let Profilequery2 = new Parse.Query('Profile');
  70. // Profilequery2.equalTo('company', company);
  71. // Profilequery2.equalTo('user', currentUser.id);
  72. // Profilequery2.equalTo('isCheck', true);
  73. // Profilequery2.notEqualTo('isDeleted', true)
  74. // let P2 = await Profilequery2.find();
  75. // let profile1List2 = P2.map(item => item.toJSON());
  76. // let Profilequery = new Parse.Query('AIMoment');
  77. // Profilequery.equalTo('company', company);
  78. // Profilequery.equalTo('isVisible', true);
  79. // Profilequery.notEqualTo('isDeleted', true)
  80. // Profilequery.equalTo('profile', profile1List2[0].objectId);
  81. // Profilequery.descending('createdAt');
  82. // let count = await Profilequery.count();
  83. // if (count) {
  84. // this.setData({
  85. // circlecount: count
  86. // })
  87. // }
  88. // },
  89. async getcircle() {
  90. const currentUser = Parse.User.current();
  91. let Profilequery2 = new Parse.Query('Profile');
  92. Profilequery2.equalTo('company', company);
  93. Profilequery2.equalTo('user', currentUser.id);
  94. Profilequery2.equalTo('isCheck', true);
  95. Profilequery2.notEqualTo('isDeleted', true);
  96. Profilequery2.include('user');
  97. Profilequery2.include('center');
  98. Profilequery2.include('department');
  99. let P2 = await Profilequery2.find();
  100. let profile1List2 = P2.map(item => item.toJSON());
  101. this.setData({
  102. profile1List2,
  103. })
  104. console.log('信息',this.data.profile1List2);
  105. let Profilequery = new Parse.Query('AIMoment');
  106. Profilequery.equalTo('company', company);
  107. Profilequery.equalTo('isVisible', true);
  108. Profilequery.notEqualTo('isDeleted', true);
  109. Profilequery.equalTo('profile', profile1List2[0].objectId);
  110. Profilequery.descending('createdAt');
  111. let moments = await Profilequery.find(); // 查找所有动态
  112. if (moments.length) {
  113. this.setData({
  114. circlecount: moments.length
  115. });
  116. // 获取所有动态的ID
  117. let momentIds = moments.map(moment => moment.id);
  118. // 创建对 AIMomentLike 表的查询
  119. let LikeQuery = new Parse.Query('AIMomentLike');
  120. LikeQuery.equalTo('isLiked', true);
  121. LikeQuery.equalTo('company', company);
  122. LikeQuery.notEqualTo('isDeleted', true);
  123. LikeQuery.containedIn('moment', momentIds); // 使用 containedIn 来一次性查询多个动态的点赞
  124. // 统计点赞数量
  125. let likesCount = await LikeQuery.count();
  126. // 这里可以进一步处理 likesCount,按动态分配点赞数量
  127. console.log(`总点赞数量: ${likesCount}`);
  128. this.setData({
  129. likesCount,
  130. })
  131. }
  132. },
  133. //查看积分
  134. async getpoint(){
  135. },
  136. //获取头像名称
  137. async getname(){
  138. const currentUser = Parse.User.current();
  139. let Userquery = new Parse.Query('_User');
  140. Userquery.equalTo('company', company);
  141. Userquery.equalTo('objectId', currentUser.id);
  142. Userquery.notEqualTo('isDeleted', true)
  143. let P2 = await Userquery.find();
  144. let User1List = P2.map(item => item.toJSON());
  145. this.setData({
  146. User1List
  147. })
  148. console.log(this.data.User1List);
  149. },
  150. gourl(e) {
  151. const url = e.currentTarget.dataset.url
  152. wx.navigateTo({
  153. url: `${url}`// 目标页面的路径
  154. });
  155. },
  156. }
  157. })