| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- // common-page/pages/web-view/index.js
- const Parse = getApp().Parse;
- const company = getApp().globalData.company;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- path: "",
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log('===========================================');
- console.log('======= web-view 页面加载 =======');
- console.log('===========================================');
- console.log('📦 接收到的 options:', options);
-
- // 解码 URL(如果被编码了)
- let path = decodeURIComponent(options.path || '');
- console.log('🔓 解码后的 path:', path);
- console.log(' - path 长度:', path.length);
-
- // 检查 URL 中是否包含 token
- if (path.includes('token=')) {
- console.log('✅ URL 中包含 token 参数');
- const tokenMatch = path.match(/token=([^&]+)/);
- if (tokenMatch && tokenMatch[1]) {
- console.log('🔑 提取到的 token (前20字符):', tokenMatch[1].substring(0, 20));
- }
- } else {
- console.log('⚠️ URL 中没有 token 参数!');
- }
-
- // 如果还有额外的参数(除了 path 和 url),拼接到 URL 后面
- let hasQuery = path.indexOf('?') !== -1;
- let parsm = hasQuery ? '&' : '?';
- let params = [];
-
- for (const key in options) {
- if(key != 'path' && key != 'url'){
- params.push(key + '=' + options[key]);
- console.log(` - 额外参数: ${key} = ${options[key]}`);
- }
- }
-
- // 只有当有额外参数时才拼接
- if(params.length > 0) {
- parsm = parsm + params.join('&');
- path = path + parsm;
- console.log('🔗 拼接额外参数后的 path:', path);
- }
-
- console.log('🌐 最终加载的 URL:', path);
- console.log('===========================================');
-
- this.setData({
- path: path
- })
- // ✅ 立即设置标题(优先使用传入的 storeName)
- const passedStoreName = options.storeName ? decodeURIComponent(options.storeName) : '';
- const passedStoreId = options.storeId || '';
-
- console.log('🏷️ 接收到的店铺信息:');
- console.log(' - storeId:', passedStoreId);
- console.log(' - storeName (原始):', options.storeName);
- console.log(' - storeName (解码):', passedStoreName);
-
- // 立即同步设置标题
- if (passedStoreName) {
- console.log('🎯 立即设置标题为:', passedStoreName);
- wx.setNavigationBarTitle({
- title: passedStoreName,
- success: () => {
- console.log('✅✅✅ 标题设置成功:', passedStoreName);
- },
- fail: (err) => {
- console.error('❌❌❌ 标题设置失败:', err);
- }
- });
- }
-
- // 异步加载完整店铺信息(作为备份)
- this.loadAndSetStoreTitle(passedStoreId, passedStoreName)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- console.log('📌 onReady: 页面渲染完成');
- // 不在这里设置,避免覆盖 onLoad 中的设置
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- console.log('📌 onShow: 页面显示');
- // 不在这里设置,避免覆盖 onLoad 中的设置
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- /**
- * 加载店铺信息并设置页面标题
- */
- loadAndSetStoreTitle: async function (storeId = '', storeName = '') {
- try {
- let finalName = storeName;
- if (!finalName) {
- // 如果没有传入名字,按传入的 storeId 精确查询;再不行按 company 兜底
- if (storeId) {
- const q = new Parse.Query('ShopStore');
- const s = await q.get(storeId);
- if (s) finalName = s.get('storeName') || '';
- }
- if (!finalName) {
- const storeQuery = new Parse.Query('ShopStore');
- storeQuery.equalTo('company', company);
- storeQuery.ascending('score');
- storeQuery.limit(1);
- const store = await storeQuery.first();
- if (store) finalName = store.get('storeName') || '';
- }
- }
- if (!finalName) return;
- // 延迟到本帧结束设置标题,避免被覆盖
- setTimeout(() => {
- const pages = getCurrentPages();
- const current = pages[pages.length - 1];
- console.log('📌 web-view 当前页面路由:', current && current.route);
- wx.setNavigationBarTitle({
- title: finalName
- })
- }, 0)
- } catch (e) {
- console.error('设置 web-view 标题失败:', e);
- }
- }
- })
|