// pages/user/map/index.js const { museumApi } = require('../../../utils/api.js'); const { processHtmlContent } = require('../../../utils/htmlProcessor.js'); const WxParse = require('../../../utils/wxParse/wxParse.js'); Page({ /** * 页面的初始数据 */ data: { loading: false, detailData: null, processedContent: '', shouldShowBackButton: true }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { // 检查是否来自微信,如果是则隐藏返回按钮 if (options.isfrom === 'weixin') { this.setData({ shouldShowBackButton: false }); } // 加载详情数据 this.loadDetailData(); }, /** * 导航前往 */ openNavitor() { wx.openLocation({ latitude: 45.605550, longitude: 84.902629, name: '克拉玛依博物馆', address: '克拉玛依博物馆', scale: 18, success: function(res) { console.log('打开地图成功', res); }, fail: function(err) { console.error('打开地图失败', err); wx.showToast({ title: '打开地图失败', icon: 'none' }); } }); }, /** * 返回上一页 */ goBack() { wx.navigateBack({ delta: 1 }); }, /** * 加载详情数据 */ loadDetailData() { let that = this; this.setData({ loading: true }); museumApi.getMuseumDetail(2) .then(response => { if (response) { let article = response.context; this.setData({ detailData: response, // contentItems: parsedContent }); WxParse.wxParse('article', 'html', article, that, 5); } }) .catch(error => { console.error('获取地图详情数据失败:', error); this.setData({ detailData: null }); wx.showToast({ title: '加载失败', icon: 'none' }); }) .finally(() => { this.setData({ loading: false }); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } });