index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // pages/user/map/index.js
  2. const { museumApi } = require('../../../utils/api.js');
  3. const { processHtmlContent } = require('../../../utils/htmlProcessor.js');
  4. const WxParse = require('../../../utils/wxParse/wxParse.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. loading: false,
  11. detailData: null,
  12. processedContent: '',
  13. shouldShowBackButton: true
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad(options) {
  19. // 检查是否来自微信,如果是则隐藏返回按钮
  20. if (options.isfrom === 'weixin') {
  21. this.setData({
  22. shouldShowBackButton: false
  23. });
  24. }
  25. // 加载详情数据
  26. this.loadDetailData();
  27. },
  28. /**
  29. * 导航前往
  30. */
  31. openNavitor() {
  32. wx.openLocation({
  33. latitude: 45.605550,
  34. longitude: 84.902629,
  35. name: '克拉玛依博物馆',
  36. address: '克拉玛依博物馆',
  37. scale: 18,
  38. success: function(res) {
  39. console.log('打开地图成功', res);
  40. },
  41. fail: function(err) {
  42. console.error('打开地图失败', err);
  43. wx.showToast({
  44. title: '打开地图失败',
  45. icon: 'none'
  46. });
  47. }
  48. });
  49. },
  50. /**
  51. * 返回上一页
  52. */
  53. goBack() {
  54. wx.navigateBack({
  55. delta: 1
  56. });
  57. },
  58. /**
  59. * 加载详情数据
  60. */
  61. loadDetailData() {
  62. let that = this;
  63. this.setData({
  64. loading: true
  65. });
  66. museumApi.getMuseumDetail(2)
  67. .then(response => {
  68. if (response) {
  69. let article = response.context;
  70. this.setData({
  71. detailData: response,
  72. // contentItems: parsedContent
  73. });
  74. WxParse.wxParse('article', 'html', article, that, 5);
  75. }
  76. })
  77. .catch(error => {
  78. console.error('获取地图详情数据失败:', error);
  79. this.setData({
  80. detailData: null
  81. });
  82. wx.showToast({
  83. title: '加载失败',
  84. icon: 'none'
  85. });
  86. })
  87. .finally(() => {
  88. this.setData({
  89. loading: false
  90. });
  91. });
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady() {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload() {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh() {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom() {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage() {
  127. }
  128. });