hookehuyr

✨ feat: 新增底部导航栏组件,新增我的页面

...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 * @Author: hookehuyr hookehuyr@gmail.com 2 * @Author: hookehuyr hookehuyr@gmail.com
3 * @Date: 2022-05-27 15:57:59 3 * @Date: 2022-05-27 15:57:59
4 * @LastEditors: hookehuyr hookehuyr@gmail.com 4 * @LastEditors: hookehuyr hookehuyr@gmail.com
5 - * @LastEditTime: 2022-09-20 13:51:26 5 + * @LastEditTime: 2022-09-21 14:59:55
6 * @FilePath: /swx/src/app.config.js 6 * @FilePath: /swx/src/app.config.js
7 * @Description: 7 * @Description:
8 */ 8 */
...@@ -21,6 +21,7 @@ export default { ...@@ -21,6 +21,7 @@ export default {
21 pages: [ 21 pages: [
22 'pages/index/index', 22 'pages/index/index',
23 'pages/foo/index', 23 'pages/foo/index',
24 + 'pages/my/index',
24 ], 25 ],
25 subpackages: [ // 配置在tabBar中的页面不能分包写到subpackages中去 26 subpackages: [ // 配置在tabBar中的页面不能分包写到subpackages中去
26 { 27 {
......
1 page { 1 page {
2 color: #222222; 2 color: #222222;
3 background-color: #F6F6F6; 3 background-color: #F6F6F6;
4 + padding: 0;
5 + margin: 0;
4 } 6 }
......
1 +<!--
2 + * @Date: 2022-09-21 11:59:20
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-09-21 15:11:47
5 + * @FilePath: /swx/src/components/navbar.vue
6 + * @Description: 底部导航栏
7 +-->
8 +<template>
9 + <view class="navbar-page">
10 + <view @tap="goTo('home')" class="home">
11 + <view style="height: 2rem;">
12 + <van-icon :name="icon_home" size="2rem" />
13 + </view>
14 + <view><text :style="homeStyle">首页</text></view>
15 + </view>
16 + <view class="add">
17 + <view>
18 + <van-icon :name="icon_add" size="4.5rem" />
19 + </view>
20 + </view>
21 + <view @tap="goTo('my')" class="my">
22 + <view style="height: 2rem;">
23 + <van-icon :name="icon_my" size="2rem" />
24 + </view>
25 + <view><text :style="myStyle">我的</text></view>
26 + </view>
27 + </view>
28 +</template>
29 +
30 +<script setup>
31 +import { ref, defineProps, computed, onMounted } from 'vue'
32 +import icon_home1 from '@/images/icon/home01@2x.png'
33 +import icon_home2 from '@/images/icon/home02@2x.png'
34 +import icon_my1 from '@/images/icon/my01@2x.png'
35 +import icon_my2 from '@/images/icon/my02@2x.png'
36 +import icon_add from '@/images/icon/new@2x.png'
37 +
38 +import Taro from '@tarojs/taro'
39 +
40 +const goTo = (page) => {
41 + if (page === 'home') {
42 + if (currentPage.value === 'home') return;
43 + Taro.redirectTo({
44 + url: '../index/index'
45 + })
46 + } else {
47 + if (currentPage.value === 'my') return;
48 + Taro.redirectTo({
49 + url: '../my/index'
50 + })
51 + }
52 +}
53 +
54 +const currentPage = ref('');
55 +
56 +onMounted(() => {
57 + let pages = getCurrentPages();
58 + let current_page = pages[pages.length - 1];
59 + let url = current_page.route;
60 + if (url == 'pages/index/index') {
61 + currentPage.value = 'home'
62 + } else {
63 + currentPage.value = 'my'
64 + }
65 +})
66 +
67 +const props = defineProps({
68 + activated: String,
69 +})
70 +
71 +const homeStyle = ref({})
72 +const myStyle = ref({})
73 +
74 +const icon_home = computed(() => {
75 + if (props.activated === 'home') {
76 + return icon_home1
77 + } else {
78 + return icon_home2
79 + }
80 +})
81 +const icon_my = computed(() => {
82 + if (props.activated === 'home') {
83 + return icon_my2
84 + } else {
85 + return icon_my1
86 + }
87 +})
88 +
89 +if (props.activated === 'home') {
90 + homeStyle.value = {
91 + color: '#2A5F45',
92 + fontSize: '0.9rem'
93 + }
94 + myStyle.value = {
95 + color: '#999999',
96 + fontSize: '0.9rem'
97 + }
98 +} else {
99 + homeStyle.value = {
100 + color: '#999999',
101 + fontSize: '0.9rem'
102 + }
103 + myStyle.value = {
104 + color: '#2A5F45',
105 + fontSize: '0.9rem'
106 + }
107 +}
108 +
109 +</script>
110 +
111 +<style lang="less">
112 +.navbar-page {
113 + position: fixed;
114 + bottom: 0;
115 + background-color: #FFFFFF;
116 + padding-top: 0.5rem;
117 + height: 5rem;
118 + width: 100%;
119 +
120 + .home {
121 + position: absolute;
122 + left: 20%;
123 + transform: translateX(-20%);
124 + text-align: center;
125 + }
126 +
127 + .add {
128 + position: absolute;
129 + top: -1.25rem;
130 + left: 50%;
131 + transform: translateX(-50%);
132 + }
133 +
134 + .my {
135 + position: absolute;
136 + left: 80%;
137 + transform: translateX(-80%);
138 + text-align: center;
139 + }
140 +}
141 +</style>
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-09-21 11:02:56 4 + * @LastEditTime: 2022-09-21 15:03:29
5 * @FilePath: /swx/src/pages/index/index.vue 5 * @FilePath: /swx/src/pages/index/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -28,12 +28,14 @@ ...@@ -28,12 +28,14 @@
28 <view style="padding: 0 1rem;"> 28 <view style="padding: 0 1rem;">
29 <activity-card v-for="(item, index) in activity_list" :key="index" :data="item"></activity-card> 29 <activity-card v-for="(item, index) in activity_list" :key="index" :data="item"></activity-card>
30 </view> 30 </view>
31 + <navbar activated="home" />
31 </template> 32 </template>
32 33
33 <script setup> 34 <script setup>
34 import Taro from '@tarojs/taro' 35 import Taro from '@tarojs/taro'
35 import { ref } from 'vue'; 36 import { ref } from 'vue';
36 import activityCard from '@/components/activity-card.vue' 37 import activityCard from '@/components/activity-card.vue'
38 +import navbar from '@/components/navbar.vue'
37 39
38 const activity_list = ref([{ 40 const activity_list = ref([{
39 title: '智慧没有烦恼', 41 title: '智慧没有烦恼',
......
1 +export default {
2 + navigationBarTitleText: '我的',
3 + usingComponents: {
4 + },
5 +}
File mode changed
1 +<!--
2 + * @Date: 2022-09-21 14:51:44
3 + * @LastEditors: hookehuyr hookehuyr@gmail.com
4 + * @LastEditTime: 2022-09-21 14:52:03
5 + * @FilePath: /swx/src/pages/my/index.vue
6 + * @Description: 文件描述
7 +-->
8 +<template>
9 + <view>my</view>
10 + <navbar activated="my" />
11 +
12 +</template>
13 +
14 +<script setup>
15 +import { ref } from "vue";
16 +import navbar from '@/components/navbar.vue'
17 +
18 +</script>
19 +
20 +<script>
21 +import "./index.less";
22 +
23 +export default {
24 + name: "myPage",
25 +};
26 +</script>