| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <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>
|