fix(icon): uni-icon 在微信不支持颜色,改用unocss-icons

This commit is contained in:
Burt 2024-01-03 17:34:52 +08:00
parent 6e3448582b
commit 821117f529
5 changed files with 44 additions and 8 deletions

View File

@ -28,5 +28,6 @@
"files.associations": { "files.associations": {
"pages.json": "jsonc", // pages.json "pages.json": "jsonc", // pages.json
"manifest.json": "jsonc" // manifest.json "manifest.json": "jsonc" // manifest.json
} },
"cSpell.words": ["Tabbar"]
} }

View File

@ -8,9 +8,9 @@
- 📑 pinia+适用于多端的持久化方案 - 📑 pinia+适用于多端的持久化方案
- 🎨 [UnoCSS](https://github.com/unocss/unocss) - 高性能且极具灵活性的即时原子化 CSS 引擎 - 🎨 [UnoCSS](https://unocss.dev/) - 高性能且极具灵活性的即时原子化 CSS 引擎
- 😃 [各种图标集为你所用](https://github.com/antfu/unocss/tree/main/packages/preset-icons) - 😃 [UnoCSS Icons](https://unocss.dev/presets/icons), [海量图标-https://icones.js.org/](https://icones.js.org/)
- 🔥 使用 [新的 `<script setup>` 语法](https://github.com/vuejs/rfcs/pull/227) - 🔥 使用 [新的 `<script setup>` 语法](https://github.com/vuejs/rfcs/pull/227)

View File

@ -1,22 +1,34 @@
<template> <template>
<!-- 自定义导航栏: 默认透明不可见, scroll-view 滚动到 50 时展示 --> <!-- 自定义导航栏: 默认透明不可见, scroll-view 滚动到 50 时展示 -->
<view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }"> <view class="fly-navbar" :style="{ paddingTop: safeAreaInsets?.top + 'px' }">
<navigator v-if="pages.length > 1" open-type="navigateBack" class="back"> <!-- 1/3多于1个页面用返回图标 -->
<uni-icons type="left" color="white" size="24" /> <navigator v-if="pages.length > 1" open-type="navigateBack" class="left-icon">
<button class="i-carbon-chevron-left text-white"></button>
</navigator> </navigator>
<navigator v-else open-type="switchTab" url="/pages/index/index" class="back"> <!-- 2/3只有1个页面如果不是tabbar需要首页图标 -->
<uni-icons type="home" color="white" size="24" /> <!-- 这种情况一般出现在用户直接打开分享出去的详情页面或者使用redirectTo等API -->
<navigator
v-else-if="isTabbar"
open-type="switchTab"
url="/pages/index/index"
class="left-icon"
>
<button class="i-carbon-home text-white"></button>
</navigator> </navigator>
<!-- 如果当前页就是tabbar页不用去首页也就是什么图标都不需要 -->
<view class="title">{{ title || '' }}</view> <view class="title">{{ title || '' }}</view>
</view> </view>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { getIsTabbar } from '@/utils/index'
defineProps<{ title?: string }>() defineProps<{ title?: string }>()
// //
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync()
// //
const pages = getCurrentPages() const pages = getCurrentPages()
const isTabbar = getIsTabbar()
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@ -29,7 +41,7 @@ const pages = getCurrentPages()
color: #000; color: #000;
background-color: transparent; background-color: transparent;
.back { .left-icon {
position: absolute; position: absolute;
left: 0; left: 0;
display: flex; display: flex;

View File

@ -26,5 +26,15 @@
"^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue" "^uni-(.*)": "@dcloudio/uni-ui/lib/uni-$1/uni-$1.vue"
} }
}, },
"tabBar": {
"list": [
{
"pagePath": "pages/index/index"
},
{
"pagePath": "pages/my/index"
}
]
},
"subPackages": [] "subPackages": []
} }

13
src/utils/index.ts Normal file
View File

@ -0,0 +1,13 @@
import pagesJson from '@/pages.json'
console.log(pagesJson)
/** 判断当前页面是否是tabbar页 */
export const getIsTabbar = () => {
if (!pagesJson.tabBar) {
return false
}
const pages = getCurrentPages()
const currPath = pages.at(-1).route
return !!pagesJson.tabBar.list.find((e) => e.pagePath === currPath)
}