index.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. const _Http = getApp().globalData.http;
  2. let DataCarousel = null;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. user: {},
  9. annunciateList: [], //通告列表
  10. gridList: [],
  11. unreadNum: 0, //通告未读
  12. notice: "",
  13. msgCount: 1,
  14. subassembly: [], //首页部件
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. if (wx.getStorageSync('userauth').length != 0) {
  21. /* 首页宫格授权查询 */
  22. let auth = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['营销工具'], ['通告', '推广素材', '商学院', '提报']),
  23. gridList = [],
  24. subassembly = [];
  25. auth.forEach(v => {
  26. switch (v.systemmodulename) {
  27. case "通告":
  28. gridList.push({
  29. name: "通告",
  30. path: "/pages/annunciate/index",
  31. icon: "icon-a-shouyejingangqutonggao",
  32. apps: v.apps
  33. });
  34. if (v.apps[0].meta.wedgits.some(value => value.wedgit == 'homenoticelist')) subassembly.push('homenoticelist');
  35. this.setData({
  36. annunciateAuthList: v.apps[0].meta.auth.map(v => v.optionname)
  37. });
  38. break;
  39. case "推广素材":
  40. gridList.push({
  41. name: "推广素材",
  42. path: "/pages/promotional/index",
  43. icon: "icon-a-shouyejingangqutuiguangsucai",
  44. apps: v.apps
  45. })
  46. break;
  47. case "商学院":
  48. gridList.push({
  49. name: "商学院",
  50. path: "/pages/college/index",
  51. icon: "icon-a-shangxueyuanxuexi",
  52. apps: v.apps
  53. })
  54. break;
  55. case "提报":
  56. gridList.push({
  57. name: "提报",
  58. path: "/pages/submission/index",
  59. icon: "icon-a-tibaoguanlitibao",
  60. apps: v.apps
  61. })
  62. break;
  63. };
  64. });
  65. /* 首页小组件查询 */
  66. let home = getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['首页'])[0].apps[0].meta.wedgits;
  67. console.log("首页", home)
  68. if (home.some(v => v.wedgit == 'homedatadisplay')) subassembly.push('homedatadisplay');
  69. this.setData({
  70. gridList,
  71. subassembly
  72. })
  73. }
  74. this.refreshData(wx.getStorageSync('userMsg'))
  75. this.setData({ //获取胶囊位置信息
  76. capsule: wx.getMenuButtonBoundingClientRect()
  77. })
  78. },
  79. /* 查看通告详情 */
  80. toAnnunciateDetails(e) {
  81. const {
  82. item
  83. } = e.currentTarget.dataset;
  84. let authList = this.data.annunciateAuthList;
  85. wx.navigateTo({
  86. url: `/pages/annunciate/details?id=${item.sat_noticeid}&feedback=${authList.includes('反馈')}&auth=${authList}`,
  87. })
  88. },
  89. /* 获取通告列表 */
  90. queryNoticeList(i) {
  91. if (i == 5) return;
  92. _Http.basic({
  93. "classname": "saletool.notice.notice",
  94. "method": "queryNoticeList",
  95. "content": {
  96. "pageNumber": 1,
  97. "pageSize": 3
  98. }
  99. }).then(res => {
  100. console.log("通告列表", res)
  101. if (res.msg != '成功') return this.queryNoticeList(i + 1);
  102. this.setData({
  103. annunciateList: res.data,
  104. unreadNum: res.total - res.tips.readNum
  105. })
  106. })
  107. },
  108. /* 获取最新信息 */
  109. queryMessage(i) {
  110. if (i == 5) return;
  111. _Http.basic({
  112. "classname": "system.message.Message",
  113. "method": "queryMessage",
  114. content: {
  115. nocache: true,
  116. pageNumber: 1,
  117. pageSize: 3,
  118. pageTotal: 1,
  119. type: "系统"
  120. },
  121. }).then(res => {
  122. if (res.msg != '成功') return this.queryMessage(i + 1);
  123. this.setData({
  124. msgList: res.data,
  125. notice: res.data[0]
  126. })
  127. this.startDataCarousel();
  128. })
  129. },
  130. startDataCarousel() {
  131. clearInterval(DataCarousel);
  132. DataCarousel = setInterval(() => {
  133. let count = this.data.msgCount < this.data.msgList.length ? this.data.msgCount : 0;
  134. this.setData({
  135. msgCount: count + 1,
  136. notice: this.data.msgList[count]
  137. })
  138. }, 5000)
  139. },
  140. /* 更新站点信息 */
  141. refreshData(item) {
  142. this.setData({
  143. user: item
  144. })
  145. this.queryNoticeList(0); //获取通告列表
  146. this.queryMessage(0)
  147. },
  148. /* 宫格区域应用程序 */
  149. applications(e) {
  150. const {
  151. item
  152. } = e.currentTarget.dataset;
  153. wx.navigateTo({
  154. url: `${item.path}?auth=${JSON.stringify(item.apps)}`,
  155. });
  156. },
  157. /* 去消息详情 */
  158. toMsg(e) {
  159. const {
  160. item
  161. } = e.currentTarget.dataset;
  162. wx.navigateTo({
  163. url: '/pages/tabbar/message/details?id=' + item.objectid,
  164. })
  165. },
  166. /* 去通告 */
  167. toAnnunciate() {
  168. this.applications({
  169. currentTarget: {
  170. dataset: {
  171. item: this.data.gridList.find(v => v.name == '通告')
  172. }
  173. }
  174. })
  175. },
  176. /**
  177. * 生命周期函数--监听页面显示
  178. */
  179. onShow() {
  180. this.getTabBar().init();
  181. this.startDataCarousel();
  182. },
  183. /**
  184. * 生命周期函数--监听页面隐藏
  185. */
  186. onHide() {
  187. clearInterval(DataCarousel);
  188. },
  189. })