tzxq.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. Page({
  2. /**
  3. * 页面的初始数据
  4. */
  5. data: {
  6. noticeDetail: {}
  7. },
  8. onLoad: function (options) {
  9. const app = getApp();
  10. debugger
  11. if (options.noticeData) {
  12. const parsedNotice = JSON.parse(decodeURIComponent(options.noticeData));
  13. // 确保数据格式正确,映射字段到正确的显示名称
  14. const processedNotice = {
  15. ...parsedNotice,
  16. title: parsedNotice.title || parsedNotice.noticetitle || '',
  17. content: parsedNotice.roption || parsedNotice.noticecontent || ''
  18. };
  19. // 替换可能存在的占位符
  20. // if (processedNotice.content) {
  21. // const userInfo = app.globalData.userInfo || {};
  22. // processedNotice.content = processedNotice.content
  23. // .replace(/\[用户姓名\]/g, userInfo.name || '用户');
  24. // }
  25. this.setData({
  26. noticeDetail: processedNotice
  27. });
  28. return;
  29. }
  30. // 如果只传入了id,则从全局notices中获取
  31. if (options.id) {
  32. const noticeDetail = app.globalData.notices.find(notice => notice.id === options.id);
  33. const processedNotice = {
  34. ...noticeDetail,
  35. title: noticeDetail.title || noticeDetail.noticetitle || '',
  36. content: noticeDetail.roption || noticeDetail.noticecontent || ''
  37. };
  38. this.setData({
  39. noticeDetail: processedNotice
  40. });
  41. }
  42. },
  43. /**
  44. * 返回上一页
  45. */
  46. goBack: function() {
  47. wx.navigateBack();
  48. },
  49. })