tj
2025-05-28 6ef1b14f735acdc3ff77a50da1bb09a5bb983dcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
  <view class="footer customer-footer">
    <view
      v-for="(item, index) in tabBar"
      :key="index"
      class="footer-item"
    >
      <view
        class="item"
        :class="{ cur: currentIndex === index }"
        @click="go(index, item)"
      >
        <view class="footer-text">{{ item.text }}</view>
      </view>
    </view>
  </view>
</template>
 
 
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useNavigator } from '@/composables/useNavigator'
const { navigateTo, reLaunchTo} = useNavigator()
 
interface TabItem {
  text: string
  pagePath: string
}
 
// props
const props = defineProps<{
  flg?: string
  bussincess?: boolean
}>()
 
const tabBar = ref<TabItem[]>([
  { text: '首页', pagePath: '/pages/home/home' },
  { text: '影视地图', pagePath: '/sub-pages/film-map/index' },
  { text: '我的种草', pagePath: '/sub-pages/customer/shopping/shopping' },
  { text: '社区', pagePath: '/sub-pages/community/index' },
  { text: '我的', pagePath: '/sub-pages/mine/index' },
])
 
function normalizePath(path: string): string {
  return path.replace(/^\/+/, '/')
}
 
const currentPath = computed(() => {
  // getCurrentPages 是全局函数,类型断言一下
  const pages = getCurrentPages() as { route: string }[]
  const currentPage = pages[pages.length - 1]
  return '/' + currentPage.route
})
 
const currentIndex = computed(() => {
  return tabBar.value.findIndex(
    (item) => normalizePath(item.pagePath) === normalizePath(currentPath.value)
  )
})
 
function go(index: number, item: TabItem) {
  // uni.reLaunch({
  //   url: item.pagePath,
  // })
  
  reLaunchTo(item.pagePath)
 
}
</script>
 
<style lang="scss" scoped>
@import './main.scss';
 
.footer-icon {
  width: 36rpx;
  height: 36rpx;
  margin-bottom: 4rpx;
}
</style>