feat: 扫码进去小程序的几种方式兼容支持
This commit is contained in:
1 parent
681ba3d8f1
commit
a4c29569bf
3 files changed
+108
-5
No files matched your search
@@ -2,11 +2,21 @@
|
||||
/**
|
||||
* 主包壳页面:主页 / 权益 / 我的 三块面板同屏共存,底部 Tab 栏只渲染一次
|
||||
* ---------------------------------------------------------------------------
|
||||
* 扫码入口:二维码指向本页并带商家 id(`merchant_id` / `scene` / `q` 三种来源都认),
|
||||
* 进来自动切到权益 Tab 再打开商家详情 —— 取值见 utils/nav.js 的 pickMerchantId / handleEntry。
|
||||
*/
|
||||
import { onMounted, ref } from "vue";
|
||||
import { onShow } from "@dcloudio/uni-app";
|
||||
import { nextTick, onMounted, ref } from "vue";
|
||||
import { onLoad, onShow } from "@dcloudio/uni-app";
|
||||
import { TABS } from "@/constant";
|
||||
import { consumePendingTab, registerTabController, setTabQuery } from "@/utils/nav";
|
||||
import {
|
||||
consumePendingMerchant,
|
||||
consumePendingTab,
|
||||
goDetail,
|
||||
pickMerchantId,
|
||||
registerTabController,
|
||||
setPendingMerchant,
|
||||
setTabQuery,
|
||||
} from "@/utils/nav";
|
||||
import HomePanel from "@/views/home/index.vue";
|
||||
import BenefitPanel from "@/views/benefit/index.vue";
|
||||
import MinePanel from "@/views/mine/index.vue";
|
||||
@@ -32,17 +42,39 @@ const goTab = (key, query = "") => {
|
||||
showPanel(key);
|
||||
};
|
||||
|
||||
/** Tab 控制器是否已就绪(onShow 可能早于 onMounted,未就绪时不消费扫码参数) */
|
||||
let shellReady = false;
|
||||
|
||||
/**
|
||||
* 扫码进店:先切权益 Tab 再打开商家详情。
|
||||
* 顺序不能反 —— 先切 Tab,「详情返回」才会落在权益页而不是主页。
|
||||
*/
|
||||
const runEntry = () => {
|
||||
if (!shellReady) return;
|
||||
const id = consumePendingMerchant();
|
||||
if (!id) return;
|
||||
goTab("benefit");
|
||||
nextTick(() => setTimeout(() => goDetail(id), 0));
|
||||
};
|
||||
|
||||
onLoad((options) => {
|
||||
setPendingMerchant(pickMerchantId(options));
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
// 面板的 onMounted 早于本页 onMounted,此时 ref 已就绪
|
||||
registerTabController({ go: goTab, getActive: () => active.value });
|
||||
// 从子页 / 登录页切过来:nav 里可能压着待切 Tab(登录回跳、reLaunch 冷启)
|
||||
const pending = consumePendingTab();
|
||||
goTab(pending?.key || active.value, pending?.query || "");
|
||||
shellReady = true;
|
||||
runEntry();
|
||||
});
|
||||
|
||||
onShow(() => {
|
||||
// 从板块列表 / 详情 / 登录页等返回:让当前面板按需刷新(各家内部有幂等守卫)
|
||||
showPanel(active.value);
|
||||
runEntry();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user