index.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // nova-werun/components/my/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. const auth = require('../../service/auth.service')
  5. const uid = Parse?.User?.current()?.id
  6. let getSportData = require('../../service/getSportData')
  7. Component({
  8. /**
  9. * 组件的属性列表
  10. */
  11. properties: {
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. //屏幕高度
  18. statusBarHeight: 0, // 状态栏高度
  19. screenHeight: 0, // 屏幕高度
  20. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  21. bottomNavHeight: 0, // 底部导航栏高度
  22. contentHeight: 0, // 可用内容高度
  23. contentpadding: 0, //顶部padding高度
  24. navheight: 0,
  25. circlecount: 0,
  26. likesCount: 0,
  27. User1List: [],
  28. profile1List2: [],
  29. meChick:0,//当前用户累计签到天数
  30. },
  31. lifetimes: {
  32. detached: function () {
  33. // 在组件实例被从页面节点树移除时执行
  34. },
  35. attached: async function () {
  36. // 在组件实例进入页面节点树时执行
  37. // 计算
  38. const systemInfo = wx.getSystemInfoSync();
  39. const statusBarHeight = systemInfo.statusBarHeight || 0;
  40. const screenHeight = systemInfo.screenHeight || 0;
  41. const custom = wx.getMenuButtonBoundingClientRect();
  42. const customHeight = custom.height + 10 + 2 || 0;
  43. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  44. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  45. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  46. const navheight = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  47. this.setData({
  48. statusBarHeight,
  49. screenHeight: (screenHeight - 50 - bottomNavHeight) * 750 / systemInfo.windowWidth,
  50. customHeight,
  51. bottomNavHeight,
  52. contentHeight,
  53. contentpadding,
  54. navheight
  55. });
  56. this.getcircle()
  57. this.getname()
  58. },
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. /**获取累计签到天数 */
  65. async getMeChick() {
  66. let meChick = await getSportData.getChickCount(uid, 'ActivityData')||0
  67. this.setData({
  68. meChick
  69. })
  70. },
  71. gourl(e) {
  72. const url = e.currentTarget.dataset.url
  73. wx.navigateTo({
  74. url: `${url}` // 目标页面的路径
  75. });
  76. },
  77. gourl2(e) {
  78. const type = e.currentTarget.dataset.type
  79. const url = e.currentTarget.dataset.url
  80. wx.navigateTo({
  81. url: `${url}?type=` + type // 目标页面的路径
  82. });
  83. },
  84. //查全部朋友圈
  85. // async getcircle() {
  86. // const currentUser = Parse.User.current();
  87. // let Profilequery2 = new Parse.Query('Profile');
  88. // Profilequery2.equalTo('company', company);
  89. // Profilequery2.equalTo('user', currentUser.id);
  90. // Profilequery2.equalTo('isCheck', true);
  91. // Profilequery2.notEqualTo('isDeleted', true)
  92. // let P2 = await Profilequery2.find();
  93. // let profile1List2 = P2.map(item => item.toJSON());
  94. // let Profilequery = new Parse.Query('AIMoment');
  95. // Profilequery.equalTo('company', company);
  96. // Profilequery.equalTo('isVisible', true);
  97. // Profilequery.notEqualTo('isDeleted', true)
  98. // Profilequery.equalTo('profile', profile1List2[0].objectId);
  99. // Profilequery.descending('createdAt');
  100. // let count = await Profilequery.count();
  101. // if (count) {
  102. // this.setData({
  103. // circlecount: count
  104. // })
  105. // }
  106. // },
  107. async getcircle() {
  108. const currentUser = Parse.User.current();
  109. let Profilequery2 = new Parse.Query('Profile');
  110. Profilequery2.equalTo('company', company);
  111. Profilequery2.equalTo('user', currentUser?.id);
  112. Profilequery2.equalTo('isCheck', true);
  113. Profilequery2.notEqualTo('isDeleted', true);
  114. Profilequery2.include('user');
  115. Profilequery2.include('center');
  116. Profilequery2.include('department');
  117. let P2 = await Profilequery2.find();
  118. let profile1List2 = P2.map(item => item.toJSON());
  119. this.setData({
  120. profile1List2,
  121. })
  122. console.log('信息', this.data.profile1List2);
  123. let Profilequery = new Parse.Query('AIMoment');
  124. Profilequery.equalTo('company', company);
  125. Profilequery.equalTo('isVisible', true);
  126. Profilequery.notEqualTo('isDeleted', true);
  127. // Profilequery.equalTo('profile', profile1List2[0].objectId);
  128. Profilequery.equalTo('user', currentUser.id);
  129. Profilequery.descending('createdAt');
  130. let moments = await Profilequery.find(); // 查找所有动态
  131. if (moments.length) {
  132. this.setData({
  133. circlecount: moments.length
  134. });
  135. // 获取所有动态的ID
  136. let momentIds = moments.map(moment => moment.id);
  137. // 创建对 AIMomentLike 表的查询
  138. let LikeQuery = new Parse.Query('AIMomentLike');
  139. LikeQuery.equalTo('isLiked', true);
  140. LikeQuery.equalTo('company', company);
  141. LikeQuery.notEqualTo('isDeleted', true);
  142. LikeQuery.containedIn('moment', momentIds); // 使用 containedIn 来一次性查询多个动态的点赞
  143. // 统计点赞数量
  144. let likesCount = await LikeQuery.count();
  145. // 这里可以进一步处理 likesCount,按动态分配点赞数量
  146. console.log(`总点赞数量: ${likesCount}`);
  147. this.setData({
  148. likesCount,
  149. })
  150. }
  151. },
  152. //查看积分
  153. async getpoint() {
  154. },
  155. //获取头像名称
  156. async getname() {
  157. const currentUser = Parse.User.current();
  158. let Userquery = new Parse.Query('_User');
  159. Userquery.equalTo('company', company);
  160. Userquery.equalTo('objectId', currentUser?.id);
  161. Userquery.notEqualTo('isDeleted', true)
  162. let P2 = await Userquery.find();
  163. let User1List = P2.map(item => item.toJSON());
  164. this.setData({
  165. User1List
  166. })
  167. console.log(this.data.User1List);
  168. },
  169. /**退出登录 */
  170. outLogin() {
  171. wx.showModal({
  172. title: '提示',
  173. content: '你确定退出登录吗?',
  174. showCancel: true,
  175. cancelText: '取消',
  176. cancelColor: '#000000',
  177. confirmText: '确定',
  178. confirmColor: '#3CC51F',
  179. success: (result) => {
  180. if (result.confirm) {
  181. auth.logout()
  182. }
  183. },
  184. fail: () => {},
  185. complete: () => {}
  186. });
  187. },
  188. gourl(e) {
  189. const url = e.currentTarget.dataset.url
  190. wx.navigateTo({
  191. url: `${url}` // 目标页面的路径
  192. });
  193. },
  194. /**隐私协议 */
  195. async getArticle() {
  196. let query = new Parse.Query("Article")
  197. query.equalTo("company", company)
  198. query.equalTo("type", 'home')
  199. query.equalTo("isEnabled", true)
  200. query.select("title", "attachment")
  201. let res = await query.first()
  202. if (res && res.id) {
  203. let r = res.toJSON()
  204. if (r.attachment && r.attachment.length > 0) {
  205. this.setData({
  206. attachment: r
  207. })
  208. }
  209. }
  210. },
  211. //附件下载
  212. async openFile() {
  213. await this.getArticle()
  214. let {
  215. attachment
  216. } = this.data
  217. let url = attachment.attachment[0].url,
  218. name = attachment.title
  219. const _this = this
  220. let rep = this.getFileType(url)
  221. wx.showLoading({
  222. title: '加载中',
  223. })
  224. wx.downloadFile({
  225. url: url, //要预览的PDF的地址
  226. filePath: wx.env.USER_DATA_PATH + `/${name}.${rep}`,
  227. success: function (res) {
  228. if (res.statusCode === 200) { //成功
  229. var Path = res.filePath //返回的文件临时地址,用于后面打开本地预览所用
  230. wx.openDocument({
  231. filePath: Path, //要打开的文件路径
  232. showMenu: true,
  233. success: function (res) {
  234. wx.hideLoading()
  235. },
  236. fail: function (res) {
  237. wx.hideLoading()
  238. }
  239. })
  240. }
  241. },
  242. fail: function (res) {
  243. wx.hideLoading()
  244. },
  245. })
  246. },
  247. //解析文件类型
  248. getFileType(url) {
  249. let pdfReg = /^.+(\.pdf)$/
  250. let txtReg = /^.+(\.txt)$/
  251. let wordReg = /^.+(\.doc|\.docx)$/
  252. let excelReg = /^.+(\.xls|\.xlsx)$/
  253. let jpgPng = /^.+(\.png)$/
  254. let jpgJpg = /^.+(\.jpg)$/
  255. let jpgJpeg = /^.+(\.jpeg)$/
  256. if (pdfReg.test(url)) {
  257. return 'pdf'
  258. }
  259. if (txtReg.test(url)) {
  260. return 'txt'
  261. }
  262. if (wordReg.test(url)) {
  263. return 'doc'
  264. }
  265. if (excelReg.test(url)) {
  266. return 'xls'
  267. }
  268. if (jpgPng.test(url)) {
  269. return 'png'
  270. }
  271. if (jpgJpg.test(url)) {
  272. return 'jpg'
  273. }
  274. if (jpgJpeg.test(url)) {
  275. return 'jpeg'
  276. }
  277. },
  278. }
  279. })