index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. // ✅ 立即加载并设置店铺名称作为页面标题
  18. await this.loadAndSetStoreTitle()
  19. },
  20. /**
  21. * 生命周期函数--监听页面初次渲染完成
  22. */
  23. onReady: function () {
  24. console.log('📌 引导页 onReady');
  25. },
  26. /**
  27. * 生命周期函数--监听页面显示
  28. */
  29. onShow: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面隐藏
  33. */
  34. onHide: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面卸载
  38. */
  39. onUnload: function () {
  40. },
  41. /**
  42. * 页面相关事件处理函数--监听用户下拉动作
  43. */
  44. onPullDownRefresh: function () {
  45. wx.reLaunch({
  46. url: '/index',
  47. });
  48. },
  49. /**
  50. * 页面上拉触底事件的处理函数
  51. */
  52. onReachBottom: function () {
  53. },
  54. /**
  55. * 用户点击右上角分享
  56. */
  57. onShareAppMessage: function () {
  58. let uid = Parse.User.current().id
  59. return {
  60. title: '分享',
  61. // path: `index?invite=${uid}`,
  62. path: `index`,
  63. imageUrl: '',
  64. }
  65. },
  66. /**
  67. * 加载店铺信息并设置页面标题
  68. */
  69. loadAndSetStoreTitle: async function () {
  70. try {
  71. console.log('===========================================');
  72. console.log('======= 引导页:开始设置页面标题 =======');
  73. console.log('===========================================');
  74. // 查询 ShopStore 表,获取第一个店铺
  75. const storeQuery = new Parse.Query('ShopStore');
  76. storeQuery.equalTo('company', company);
  77. storeQuery.ascending('score');
  78. storeQuery.limit(1);
  79. console.log('🔍 正在查询 ShopStore 表...');
  80. const store = await storeQuery.first();
  81. if (store) {
  82. const storeName = store.get('storeName');
  83. console.log('🏪 查询到店铺信息:', {
  84. storeId: store.id,
  85. storeName: storeName
  86. });
  87. if (storeName) {
  88. // ✅ 立即同步设置导航栏标题
  89. console.log('🎯 立即设置标题为:', storeName);
  90. wx.setNavigationBarTitle({
  91. title: storeName,
  92. success: () => {
  93. console.log('✅✅✅ 引导页标题设置成功:', storeName);
  94. console.log('===========================================');
  95. },
  96. fail: (err) => {
  97. console.error('❌❌❌ 引导页标题设置失败:', err);
  98. console.log('===========================================');
  99. }
  100. });
  101. } else {
  102. console.warn('⚠️ 店铺信息中没有 storeName 字段');
  103. console.log('📋 店铺所有字段:', store.attributes);
  104. console.log('===========================================');
  105. }
  106. } else {
  107. console.warn('⚠️ 未找到店铺信息');
  108. console.log('💡 请检查:');
  109. console.log(' 1. ShopStore 表是否有数据');
  110. console.log(' 2. company 是否正确:', company);
  111. console.log('===========================================');
  112. }
  113. } catch (error) {
  114. console.error('❌ 加载店铺信息失败:', error);
  115. console.log('===========================================');
  116. }
  117. }
  118. })