【功能完善】TabBar 角标完善

pull/135/head
puhui999 2025-01-22 10:56:33 +08:00
parent a382a1a876
commit d46cfd3943
7 changed files with 61 additions and 45 deletions

View File

@ -15,6 +15,9 @@
:key="item.text" :key="item.text"
:text="item.text" :text="item.text"
:name="item.url" :name="item.url"
:badge="item.badge"
:dot="item.dot"
:badgeStyle="tabbar.badgeStyle"
:isCenter="getTabbarCenter(index)" :isCenter="getTabbarCenter(index)"
:centerImage="sheep.$url.cdn(item.iconUrl)" :centerImage="sheep.$url.cdn(item.iconUrl)"
@tap="sheep.$router.go(item.url)" @tap="sheep.$router.go(item.url)"
@ -33,6 +36,7 @@
<script setup> <script setup>
import { computed, unref } from 'vue'; import { computed, unref } from 'vue';
import sheep from '@/sheep'; import sheep from '@/sheep';
import SuTabbar from '@/sheep/ui/su-tabbar/su-tabbar.vue';
const tabbar = computed(() => { const tabbar = computed(() => {
return sheep.$store('app').template.basic?.tabbar; return sheep.$store('app').template.basic?.tabbar;

View File

@ -128,6 +128,14 @@ const adaptTemplate = async (appTemplate, templateId) => {
const tabBar = diyTemplate?.property?.tabBar; const tabBar = diyTemplate?.property?.tabBar;
if (tabBar) { if (tabBar) {
appTemplate.basic.tabbar = tabBar; appTemplate.basic.tabbar = tabBar;
// TODO 商城装修没有对 tabBar 进行角标配置,测试角标需打开以下注释
// appTemplate.basic.tabbar.items.forEach((tabBar) => {
// tabBar.dot = false
// tabBar.badge = 100
// })
// appTemplate.basic.tabbar.badgeStyle = {
// backgroundColor: '#882222',
// }
if (tabBar?.theme) { if (tabBar?.theme) {
appTemplate.basic.theme = tabBar?.theme; appTemplate.basic.theme = tabBar?.theme;
} }

View File

@ -6,24 +6,24 @@
</view> </view>
<template v-else> <template v-else>
<view class="u-tabbar-item__icon"> <view class="u-tabbar-item__icon">
<image <uni-badge
v-if="icon" absolute="rightTop"
:name="icon" size="small"
:color="isActive ? parentData.activeColor : parentData.inactiveColor" :text="badge || (dot ? 1 : null)"
:size="20" :customStyle="badgeStyle"
></image> :isDot="dot"
<block v-else> >
<slot v-if="isActive" name="active-icon" /> <image
<slot v-else name="inactive-icon" /> v-if="icon"
</block> :name="icon"
<!-- <u-badge :color="isActive ? parentData.activeColor : parentData.inactiveColor"
absolute :size="20"
:offset="[0, dot ? '34rpx' : badge > 9 ? '14rpx' : '20rpx']" ></image>
:customStyle="badgeStyle" <block v-else>
:isDot="dot" <slot v-if="isActive" name="active-icon" />
:value="badge || (dot ? 1 : null)" <slot v-else name="inactive-icon" />
:show="dot || badge > 0" </block>
></u-badge> --> </uni-badge>
</view> </view>
<slot name="text"> <slot name="text">
@ -44,16 +44,17 @@
/** /**
* TabbarItem 底部导航栏子组件 * TabbarItem 底部导航栏子组件
* @description 此组件提供了自定义tabbar的能力 * @description 此组件提供了自定义tabbar的能力
* @property {String | Number} name item标签的名称作为与u-tabbar的value参数匹配的标识符 * @property {String | Number} name item标签的名称作为与u-tabbar的value参数匹配的标识符
* @property {String} icon uView内置图标或者绝对路径的图片 * @property {String} icon uView内置图标或者绝对路径的图片
* @property {String | Number} badge 右上角的角标提示信息 * @property {String | Number} badge 右上角的角标提示信息
* @property {Boolean} dot 是否显示圆点将会覆盖badge参数默认 false * @property {Boolean} dot 是否显示圆点将会覆盖badge参数默认 false
* @property {String} text 描述文本 * @property {String} text 描述文本
* @property {Object | String} badgeStyle 控制徽标的位置对象或者字符串形式可以设置top和right属性默认 'top: 6px;right:2px;' * @property {Object | String} badgeStyle 控制徽标的位置对象或者字符串形式可以设置top和right属性默认 'top: 6px;right:2px;'
* @property {Object} customStyle 定义需要用到的外部样式 * @property {Object} customStyle 定义需要用到的外部样式
* *
*/ */
import { deepMerge, addStyle, sleep, $parent } from '@/sheep/helper'; import { $parent, addStyle } from '@/sheep/helper';
export default { export default {
name: 'su-tabbar-item', name: 'su-tabbar-item',
props: { props: {
@ -102,8 +103,8 @@
}, },
// topright // topright
badgeStyle: { badgeStyle: {
type: [Object, String], type: Object,
default: '', default: ()=>{},
}, },
isCenter: { isCenter: {
type: Boolean, type: Boolean,
@ -202,6 +203,7 @@
height: 25px; height: 25px;
} }
} }
.u-tabbar-item { .u-tabbar-item {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -230,5 +232,6 @@
:host { :host {
flex: 1; flex: 1;
} }
/* #endif */ /* #endif */
</style> </style>

View File

@ -1,3 +1,7 @@
## 1.2.22023-01-28
- 修复 运行/打包 控制台警告问题
## 1.2.12022-09-05
- 修复 当 text 超过 max-num 时badge 的宽度计算是根据 text 的长度计算,更改为 css 计算实际展示宽度,详见:[https://ask.dcloud.net.cn/question/150473](https://ask.dcloud.net.cn/question/150473)
## 1.2.02021-11-19 ## 1.2.02021-11-19
- 优化 组件UI并提供设计资源详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource) - 优化 组件UI并提供设计资源详见:[https://uniapp.dcloud.io/component/uniui/resource](https://uniapp.dcloud.io/component/uniui/resource)
- 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-badge](https://uniapp.dcloud.io/component/uniui/uni-badge) - 文档迁移,详见:[https://uniapp.dcloud.io/component/uniui/uni-badge](https://uniapp.dcloud.io/component/uniui/uni-badge)

View File

@ -1,7 +1,7 @@
<template> <template>
<view class="uni-badge--x"> <view class="uni-badge--x">
<slot /> <slot />
<text v-if="text" :class="classNames" :style="[badgeWidth, positionStyle, customStyle, dotStyle]" <text v-if="text" :class="classNames" :style="[positionStyle, customStyle, dotStyle]"
class="uni-badge" @click="onClick()">{{displayValue}}</text> class="uni-badge" @click="onClick()">{{displayValue}}</text>
</view> </view>
</template> </template>
@ -130,16 +130,13 @@
const match = whiteList[this.absolute] const match = whiteList[this.absolute]
return match ? match : whiteList['rightTop'] return match ? match : whiteList['rightTop']
}, },
badgeWidth() {
return {
width: `${this.width}px`
}
},
dotStyle() { dotStyle() {
if (!this.isDot) return {} if (!this.isDot) return {}
return { return {
width: '10px', width: '10px',
minWidth: '0',
height: '10px', height: '10px',
padding: '0',
borderRadius: '10px' borderRadius: '10px'
} }
}, },
@ -160,7 +157,7 @@
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" >
$uni-primary: #2979ff !default; $uni-primary: #2979ff !default;
$uni-success: #4cd964 !default; $uni-success: #4cd964 !default;
$uni-warning: #f0ad4e !default; $uni-warning: #f0ad4e !default;
@ -195,10 +192,13 @@
display: flex; display: flex;
overflow: hidden; overflow: hidden;
box-sizing: border-box; box-sizing: border-box;
font-feature-settings: "tnum";
min-width: 20px;
/* #endif */ /* #endif */
justify-content: center; justify-content: center;
flex-direction: row; flex-direction: row;
height: 20px; height: 20px;
padding: 0 4px;
line-height: 18px; line-height: 18px;
color: #fff; color: #fff;
border-radius: 100px; border-radius: 100px;

View File

@ -1,7 +1,7 @@
{ {
"id": "uni-badge", "id": "uni-badge",
"displayName": "uni-badge 数字角标", "displayName": "uni-badge 数字角标",
"version": "1.2.0", "version": "1.2.2",
"description": "数字角标(徽章)组件,在元素周围展示消息提醒,一般用于列表、九宫格、按钮等地方。", "description": "数字角标(徽章)组件,在元素周围展示消息提醒,一般用于列表、九宫格、按钮等地方。",
"keywords": [ "keywords": [
"", "",
@ -18,11 +18,7 @@
"directories": { "directories": {
"example": "../../temps/example_temps" "example": "../../temps/example_temps"
}, },
"dcloudext": { "dcloudext": {
"category": [
"前端组件",
"通用组件"
],
"sale": { "sale": {
"regular": { "regular": {
"price": "0.00" "price": "0.00"
@ -39,10 +35,11 @@
"data": "无", "data": "无",
"permissions": "无" "permissions": "无"
}, },
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui" "npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui",
"type": "component-vue"
}, },
"uni_modules": { "uni_modules": {
"dependencies": [], "dependencies": ["uni-scss"],
"encrypt": [], "encrypt": [],
"platforms": { "platforms": {
"cloud": { "cloud": {