|
|
@@ -1,14 +1,19 @@
|
|
|
<template>
|
|
|
<div class="home g-flex">
|
|
|
- <keep-alive>
|
|
|
- <component class="g-flex__body" :is="components[componentId]"></component>
|
|
|
- </keep-alive>
|
|
|
- <app-tabbar class="home-tabbar" :data-list="tabList" :dataIndex="tabIndex" @click="onTabClick" />
|
|
|
+ <router-view v-slot="{ Component }">
|
|
|
+ <RouterTransition :css="cssTransition">
|
|
|
+ <!-- 缓存所有组件 -->
|
|
|
+ <keep-alive>
|
|
|
+ <component class="g-flex__body" :is="Component" />
|
|
|
+ </keep-alive>
|
|
|
+ </RouterTransition>
|
|
|
+ </router-view>
|
|
|
+ <app-tabbar class="home-tabbar" :data-list="tabList" :data-index="currentTab" @click="onTabClick" />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { shallowRef, onActivated, onMounted, onUnmounted } from 'vue'
|
|
|
+import { shallowRef, nextTick, watch, onMounted } from 'vue'
|
|
|
import { fullloading, dialog } from '@/utils/vant'
|
|
|
import { Tabbar } from '@mobile/components/base/tabbar/interface'
|
|
|
import { GetAppUpdateInfo } from '@/services/api/common'
|
|
|
@@ -17,60 +22,53 @@ import { useLogin } from '@/business/login'
|
|
|
import { loginStore } from '@/stores'
|
|
|
import plus from '@/utils/h5plus'
|
|
|
import AppTabbar from '@mobile/components/base/tabbar/index.vue'
|
|
|
-import Home from './components/main/index.vue'
|
|
|
-import Purchase from '@mobile/views/purchase/list/index.vue'
|
|
|
-import SupplyDemand from '@mobile/views/supply-demand/list/index.vue'
|
|
|
-import Mine from '@mobile/views/mine/main/index.vue'
|
|
|
-
|
|
|
-const components = {
|
|
|
- home: Home,
|
|
|
- purchase: Purchase,
|
|
|
- supplyDemand: SupplyDemand,
|
|
|
- mine: Mine,
|
|
|
-}
|
|
|
+import RouterTransition from '@mobile/components/base/router-transition/index.vue'
|
|
|
|
|
|
const { token } = loginStore.$mapGetters()
|
|
|
+const { route, routerTo, getGlobalUrlParams } = useNavigation()
|
|
|
const { autoLogin } = useLogin()
|
|
|
-const { routerTo, getGlobalUrlParams } = useNavigation()
|
|
|
-const componentId = shallowRef('home')
|
|
|
-const tabIndex = shallowRef(0)
|
|
|
+const cssTransition = shallowRef(true) // 是否使用css动画
|
|
|
+const currentTab = shallowRef(0)
|
|
|
|
|
|
const tabList: Tabbar[] = [
|
|
|
{
|
|
|
- name: 'home',
|
|
|
+ name: 'home-index',
|
|
|
label: '首页',
|
|
|
icon: 'icon-home',
|
|
|
activeIcon: 'icon-home-active',
|
|
|
},
|
|
|
{
|
|
|
- name: 'purchase',
|
|
|
+ name: 'home-purchase',
|
|
|
label: '采购',
|
|
|
icon: 'icon-purchase',
|
|
|
activeIcon: 'icon-purchase-active',
|
|
|
},
|
|
|
{
|
|
|
- name: 'supplyDemand',
|
|
|
+ name: 'home-supply-demand',
|
|
|
label: '供求',
|
|
|
icon: 'icon-supply-demand',
|
|
|
activeIcon: 'icon-supply-demand-active',
|
|
|
},
|
|
|
{
|
|
|
- name: 'mine',
|
|
|
+ name: 'home-mine',
|
|
|
label: '我的',
|
|
|
icon: 'icon-mine',
|
|
|
activeIcon: 'icon-mine-active',
|
|
|
}
|
|
|
]
|
|
|
|
|
|
-const onTabClick = ({ name }: Tabbar, index: number) => {
|
|
|
- if (name === 'home' || token.value) {
|
|
|
- tabIndex.value = index
|
|
|
- componentId.value = name
|
|
|
+const onTabClick = (index: number) => {
|
|
|
+ const { name } = tabList[index]
|
|
|
+ cssTransition.value = false
|
|
|
+
|
|
|
+ if (name === 'home-index' || token.value) {
|
|
|
+ currentTab.value = index
|
|
|
+ routerTo(name, true)
|
|
|
} else {
|
|
|
fullloading((hideLoading) => {
|
|
|
autoLogin().then(() => {
|
|
|
- tabIndex.value = index
|
|
|
- componentId.value = name
|
|
|
+ currentTab.value = index
|
|
|
+ routerTo(name, true)
|
|
|
}).catch(() => {
|
|
|
routerTo('UserLogin')
|
|
|
}).finally(() => {
|
|
|
@@ -95,26 +93,29 @@ const versionToNumber = (value: number | string) => {
|
|
|
return 0
|
|
|
}
|
|
|
|
|
|
-const ondownload = plus.onDownload((filename: string, progress: number) => {
|
|
|
- if (progress === 100) {
|
|
|
- dialog({
|
|
|
- message: '新版本下载完成,是否安装?',
|
|
|
- showCancelButton: true,
|
|
|
- confirmButtonText: '安装'
|
|
|
- }).then(() => {
|
|
|
- plus.installApp(filename)
|
|
|
- }).catch(() => {
|
|
|
- plus.deleteFile(filename)
|
|
|
- })
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
onMounted(() => {
|
|
|
+ currentTab.value = tabList.findIndex((e) => e.name === route.name)
|
|
|
+
|
|
|
const os = plus.getSystemInfo('os')
|
|
|
const currentVersion = plus.getSystemInfo('version')
|
|
|
const currentVersionCode = plus.getSystemInfo('versionCode')
|
|
|
|
|
|
if (os === 'Android') {
|
|
|
+ // 监听下载进度
|
|
|
+ const ondownload = plus.onDownload((filename, progress) => {
|
|
|
+ if (progress === 100) {
|
|
|
+ dialog({
|
|
|
+ message: '新版本下载完成,是否安装?',
|
|
|
+ showCancelButton: true,
|
|
|
+ confirmButtonText: '安装'
|
|
|
+ }).then(() => {
|
|
|
+ plus.installApp(filename)
|
|
|
+ }).catch(() => {
|
|
|
+ plus.deleteFile(filename)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
// 获取应用更新信息
|
|
|
GetAppUpdateInfo().then((res) => {
|
|
|
const data = JSON.parse(res)
|
|
|
@@ -127,6 +128,8 @@ onMounted(() => {
|
|
|
confirmButtonText: '下载'
|
|
|
}).then(() => {
|
|
|
plus.createDownload(ApkUrl)
|
|
|
+ }).catch(() => {
|
|
|
+ ondownload.cancel()
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
@@ -154,19 +157,14 @@ onMounted(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-onUnmounted(() => {
|
|
|
- ondownload.cancel()
|
|
|
-})
|
|
|
-
|
|
|
-onActivated(() => {
|
|
|
- const { tabName, showLogin } = getGlobalUrlParams()
|
|
|
- const index = tabList.findIndex((e) => e.name === tabName)
|
|
|
- if (index > -1) {
|
|
|
- tabIndex.value = index
|
|
|
- componentId.value = tabList[index].name
|
|
|
- }
|
|
|
- if (showLogin) {
|
|
|
- routerTo('UserLogin')
|
|
|
+watch(() => route.name, () => {
|
|
|
+ const { tabIndex } = getGlobalUrlParams()
|
|
|
+ if (tabIndex > -1) {
|
|
|
+ onTabClick(tabIndex)
|
|
|
+ } else {
|
|
|
+ nextTick(() => {
|
|
|
+ cssTransition.value = true
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
</script>
|