| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <template>
- <div class="home g-flex">
- <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, nextTick, watch, onMounted } from 'vue'
- import { fullloading, dialog } from '@/utils/vant'
- import { versionToNumber } from '@/filters'
- import { Tabbar } from '@mobile/components/base/tabbar/types'
- import { getAppUpdateInfo } from '@/services/api/common'
- import { useNavigation } from '@mobile/router/navigation'
- import { useLogin } from '@/business/login'
- import { useLoginStore } from '@/stores'
- import plus from '@/utils/h5plus'
- import AppTabbar from '@mobile/components/base/tabbar/index.vue'
- import RouterTransition from '@mobile/components/base/router-transition/index.vue'
- const { route, routerTo, getGlobalUrlParams } = useNavigation()
- const { userLogin } = useLogin()
- const loginStore = useLoginStore()
- const cssTransition = shallowRef(true) // 是否使用css动画
- const currentTab = shallowRef(0)
- const tabList: Tabbar[] = [
- {
- name: 'home-index',
- label: '首页',
- icon: 'g-icon-home--line',
- activeIcon: 'g-icon-home--fill',
- },
- {
- name: 'home-50102',
- label: '订单挂牌',
- icon: 'g-icon-listing--line',
- activeIcon: 'g-icon-listing--fill',
- },
- {
- name: 'home-spot',
- label: '现货挂牌',
- icon: 'g-icon-spot--line',
- activeIcon: 'g-icon-spot--fill',
- },
- {
- name: 'home-50101',
- label: '协议转让',
- icon: 'g-icon-transfer--line',
- activeIcon: 'g-icon-transfer--fill',
- },
- {
- name: 'home-mine',
- label: '我的',
- icon: 'g-icon-mine--line',
- activeIcon: 'g-icon-mine--fill',
- }
- ]
- const onTabClick = (index: number) => {
- const { name } = tabList[index]
- cssTransition.value = false
- if (name === 'home-index' || loginStore.token) {
- currentTab.value = index
- routerTo(name, true)
- } else {
- fullloading((hideLoading) => {
- userLogin(true).then(() => {
- currentTab.value = index
- routerTo(name, true)
- }).catch(() => {
- routerTo('user-login')
- }).finally(() => {
- hideLoading()
- })
- }, '加载中...')
- }
- }
- onMounted(() => {
- const { tabIndex } = getGlobalUrlParams()
- currentTab.value = tabIndex > -1 ? tabIndex : 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)
- if (data) {
- const { LastVersionCode, ApkUrl } = data[0] as Model.AppUpdateInfo
- if (Number(LastVersionCode) > Number(currentVersionCode)) {
- dialog({
- message: '发现新版本,是否下载?',
- showCancelButton: true,
- confirmButtonText: '下载'
- }).then(() => {
- plus.createDownload(ApkUrl)
- }).catch(() => {
- ondownload.cancel()
- })
- }
- }
- })
- }
- if (os === 'iOS') {
- plus.httpRequest({
- url: 'https://itunes.apple.com/lookup?id=6459789608'
- }).then((res) => {
- const results = res.data.results
- if (results?.length) {
- const { version, trackViewUrl } = results[0]
- if (versionToNumber(version) > versionToNumber(currentVersion)) {
- dialog({
- message: '发现新版本,是否更新?',
- showCancelButton: true,
- confirmButtonText: '更新'
- }).then(() => {
- plus.openURL(trackViewUrl)
- })
- }
- }
- })
- }
- })
- watch(() => route.name, () => {
- const { tabIndex } = getGlobalUrlParams()
- if (tabIndex > -1) {
- onTabClick(tabIndex)
- } else {
- nextTick(() => {
- cssTransition.value = true
- })
- }
- })
- </script>
- <style lang="less">
- @import './index.less';
- </style>
|