index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company;
  3. const getTabs = require("../../../utils/getTabs")
  4. const login = require("../../../utils/login");
  5. const dateF = require("../../../utils/date")
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function (options) {
  16. // login.loginNow()
  17. try {
  18. let finalStoreId = options && options.storeId ? options.storeId : '';
  19. // 支持从 scene 读取(小程序码 getwxacodeunlimit 传参)
  20. if (!finalStoreId && options && options.scene) {
  21. const sceneStr = decodeURIComponent(options.scene);
  22. console.log('🎯 scene 参数:', sceneStr);
  23. if (sceneStr) {
  24. const pairs = sceneStr.split('&');
  25. for (const p of pairs) {
  26. const [k, v] = p.split('=');
  27. if (k === 'storeId' && v) {
  28. finalStoreId = v;
  29. break;
  30. }
  31. }
  32. }
  33. }
  34. if (finalStoreId) {
  35. wx.setStorageSync('storeId', finalStoreId);
  36. getApp().globalData.storeId = finalStoreId;
  37. console.log('✅ 已设置店铺 ID:', finalStoreId);
  38. } else {
  39. console.log('ℹ️ 未传入店铺 ID,继续使用默认值');
  40. }
  41. } catch (e) {
  42. console.error('设置店铺 ID 失败:', e);
  43. }
  44. // ✅ 立即加载并设置店铺名称作为页面标题
  45. await this.loadAndSetStoreTitle()
  46. },
  47. /**
  48. * 生命周期函数--监听页面初次渲染完成
  49. */
  50. onReady: function () {
  51. console.log('📌 引导页 onReady');
  52. },
  53. /**
  54. * 生命周期函数--监听页面显示
  55. */
  56. onShow: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面隐藏
  60. */
  61. onHide: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面卸载
  65. */
  66. onUnload: function () {
  67. },
  68. /**
  69. * 页面相关事件处理函数--监听用户下拉动作
  70. */
  71. onPullDownRefresh: function () {
  72. wx.reLaunch({
  73. url: '/index',
  74. });
  75. },
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {
  80. },
  81. /**
  82. * 用户点击右上角分享
  83. */
  84. onShareAppMessage: function () {
  85. let uid = Parse.User.current().id
  86. return {
  87. title: '分享',
  88. // path: `index?invite=${uid}`,
  89. path: `index`,
  90. imageUrl: '',
  91. }
  92. },
  93. /**
  94. * 加载店铺信息并设置页面标题
  95. */
  96. loadAndSetStoreTitle: async function () {
  97. try {
  98. console.log('===========================================');
  99. console.log('======= 引导页:开始设置页面标题 =======');
  100. console.log('===========================================');
  101. // 计算当前有效的店铺 ID
  102. const defaultStoreId = 'Zr65KGWXHx';
  103. const effectiveStoreId = wx.getStorageSync('storeId') || getApp().globalData.storeId || defaultStoreId;
  104. console.log('🏪 使用店铺 ID:', effectiveStoreId);
  105. // 查询指定的店铺
  106. const storeQuery = new Parse.Query('ShopStore');
  107. storeQuery.equalTo('objectId', effectiveStoreId);
  108. console.log('🔍 正在查询 ShopStore 表...');
  109. const store = await storeQuery.first();
  110. if (store) {
  111. const storeName = store.get('storeName');
  112. console.log('🏪 查询到店铺信息:', {
  113. storeId: store.id,
  114. storeName: storeName
  115. });
  116. if (storeName) {
  117. // ✅ 立即同步设置导航栏标题
  118. console.log('🎯 立即设置标题为:', storeName);
  119. wx.setNavigationBarTitle({
  120. title: storeName,
  121. success: () => {
  122. console.log('✅✅✅ 引导页标题设置成功:', storeName);
  123. console.log('===========================================');
  124. },
  125. fail: (err) => {
  126. console.error('❌❌❌ 引导页标题设置失败:', err);
  127. console.log('===========================================');
  128. }
  129. });
  130. } else {
  131. console.warn('⚠️ 店铺信息中没有 storeName 字段');
  132. console.log('📋 店铺所有字段:', store.attributes);
  133. console.log('===========================================');
  134. }
  135. } else {
  136. console.warn('⚠️ 未找到指定店铺信息 (ID:', effectiveStoreId, ')');
  137. console.log('💡 请检查:');
  138. console.log(' 1. ShopStore 表中是否存在该店铺');
  139. console.log(' 2. 店铺 ID 是否正确:', effectiveStoreId);
  140. console.log('===========================================');
  141. }
  142. } catch (error) {
  143. console.error('❌ 加载店铺信息失败:', error);
  144. console.log('===========================================');
  145. }
  146. }
  147. })