|
@@ -0,0 +1,87 @@
|
|
|
|
|
+<template>
|
|
|
|
|
+ <view class="root-back-home"></view>
|
|
|
|
|
+</template>
|
|
|
|
|
+
|
|
|
|
|
+<script>
|
|
|
|
|
+ // 不带 path 的再次进入(聊天下拉、最近使用等)会停在上次的红包页。
|
|
|
|
|
+ // 页面栈只有这一页时,返回会直接退出小程序。先打开首页再回到当前页,返回就能进首页。
|
|
|
|
|
+ const REOPEN_SCENES = [1001, 1089, 1090, 1103, 1104, 1106]
|
|
|
|
|
+ const HOME_URL = '/pages/sell/index'
|
|
|
|
|
+ let padding = false
|
|
|
|
|
+
|
|
|
|
|
+ function getEntryScene() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (typeof uni.getEnterOptionsSync === 'function') {
|
|
|
|
|
+ const scene = uni.getEnterOptionsSync().scene
|
|
|
|
|
+ if (scene) return Number(scene)
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {}
|
|
|
|
|
+ try {
|
|
|
|
|
+ const app = getApp()
|
|
|
|
|
+ return Number(app && app.globalData && app.globalData.entryScene) || 0
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ return 0
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ export default {
|
|
|
|
|
+ methods: {
|
|
|
|
|
+ sync() {
|
|
|
|
|
+ if (padding) return true
|
|
|
|
|
+ const pages = getCurrentPages()
|
|
|
|
|
+ if (pages.length !== 1) return false
|
|
|
|
|
+ if (!REOPEN_SCENES.includes(getEntryScene())) return false
|
|
|
|
|
+
|
|
|
|
|
+ const page = pages[0]
|
|
|
|
|
+ const route = page.route || ''
|
|
|
|
|
+ if (route.indexOf('packet/pages/') !== 0) return false
|
|
|
|
|
+
|
|
|
|
|
+ const query = {}
|
|
|
|
|
+ const pageOptions = page.options || {}
|
|
|
|
|
+ if (pageOptions.bianhao) query.bianhao = pageOptions.bianhao
|
|
|
|
|
+ const bianhao = this.$parent && this.$parent.bianhao
|
|
|
|
|
+ if (bianhao && !query.bianhao) query.bianhao = bianhao
|
|
|
|
|
+ const qs = Object.keys(query)
|
|
|
|
|
+ .map((key) => key + '=' + encodeURIComponent(query[key]))
|
|
|
|
|
+ .join('&')
|
|
|
|
|
+ const url = '/' + route + (qs ? '?' + qs : '')
|
|
|
|
|
+
|
|
|
|
|
+ padding = true
|
|
|
|
|
+ const openPacket = (retry) => {
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
|
+ url,
|
|
|
|
|
+ success: () => {
|
|
|
|
|
+ padding = false
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: () => {
|
|
|
|
|
+ if (retry) {
|
|
|
|
|
+ setTimeout(() => openPacket(false), 200)
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ padding = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ uni.switchTab({
|
|
|
|
|
+ url: HOME_URL,
|
|
|
|
|
+ success: () => {
|
|
|
|
|
+ // 等首页切换完成再打开红包页,避免路由冲突
|
|
|
|
|
+ setTimeout(() => openPacket(true), 50)
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: () => {
|
|
|
|
|
+ padding = false
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+</script>
|
|
|
|
|
+
|
|
|
|
|
+<style lang="scss" scoped>
|
|
|
|
|
+ .root-back-home {
|
|
|
|
|
+ height: 0;
|
|
|
|
|
+ width: 0;
|
|
|
|
|
+ overflow: hidden;
|
|
|
|
|
+ }
|
|
|
|
|
+</style>
|