Skip to content

Commit

Permalink
add: 新增迷你导航组件
Browse files Browse the repository at this point in the history
  • Loading branch information
jry committed Aug 8, 2024
1 parent 94839a6 commit eb82053
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 17 deletions.
17 changes: 2 additions & 15 deletions src/uni_modules/uview-plus/components/u-grid-item/u-grid-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
// #ifdef APP-NVUE
width: 0, // nvue下才这么计算,vue下放到computed中,否则会因为延时造成闪烁
// #endif
// #ifdef MP-TOUTIAO
width: '100%',
// #endif
classes: [], // 类名集合,用于判断是否显示右边和下边框
};
},
Expand All @@ -69,24 +66,14 @@
},
// #endif
computed: {
// #ifndef APP-NVUE || MP-TOUTIAO
// vue下放到computed中,否则会因为延时造成闪烁
width() {
if (this.parentData.col > 0) {
return 100 / Number(this.parentData.col) + '%'
} else {
return 0;
}
},
// #endif
itemStyle() {
const style = {
background: this.bgColor
}
// #ifndef MP
// #ifdef APP-NVUE
style['width'] = this.width
// #endif
// #ifdef MP
// #ifndef APP-NVUE
style['width'] = '100%'
// #endif
return deepMerge(style, addStyle(this.customStyle))
Expand Down
4 changes: 2 additions & 2 deletions src/uni_modules/uview-plus/components/u-grid/u-grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
@import "../../libs/css/components.scss";
$u-grid-width:100% !default;
.u-grid {
/* #ifdef MP */
/* #ifdef APP-NVUE */
width: $u-grid-width;
position: relative;
box-sizing: border-box;
Expand All @@ -105,7 +105,7 @@
align-items: center;
// 在uni-app中应尽量避免使用flex布局以外的方式,因为nvue/uvue等方案都支持flex布局
// 这里使用grid布局使用为目前20240409uni-app在抖音小程序开启virtualHost时有bug,存在事件失效问题。
/* #ifdef MP */
/* #ifndef APP-NVUE */
display: grid;
grid-template-columns: repeat(v-bind(col), 1fr);
/* #endif */
Expand Down
51 changes: 51 additions & 0 deletions src/uni_modules/uview-plus/components/u-navbar-mini/props.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { defineMixin } from '../../libs/vue'

export const props = defineMixin({
props: {
// 是否开启顶部安全区适配
safeAreaInsetTop: {
type: Boolean,
default: () => true
},
// 是否固定在顶部
fixed: {
type: Boolean,
default: () => true
},
// 左边的图标
leftIcon: {
type: String,
default: 'arrow-leftward'
},
// 背景颜色
bgColor: {
type: String,
default: () => 'rgba(0,0,0,.15)'
},
// 导航栏高度
height: {
type: [String, Number],
default: () => '32px'
},
// 图标的大小
iconSize: {
type: [String, Number],
default: '20px'
},
// 图标的颜色
iconColor: {
type: String,
default: '#fff'
},
// 点击左侧区域(返回图标),是否自动返回上一页
autoBack: {
type: Boolean,
default: () => true
},
// 首页路径
homeUrl: {
type: [String],
default: ''
}
}
})
148 changes: 148 additions & 0 deletions src/uni_modules/uview-plus/components/u-navbar-mini/u-navbar-mini.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<template>
<view class="u-navbar-mini" :class="[customClass]">
<view
class="u-navbar-mini__placeholder"
v-if="fixed"
:style="{
height: addUnit(getPx(height) + sys().statusBarHeight,'px'),
}"
></view>
<view class="u-navbar-mini__inner" :class="[fixed && 'u-navbar-mini--fixed']">
<u-status-bar
v-if="safeAreaInsetTop"
:bgColor="bgColor"
></u-status-bar>
<view
class="u-navbar-mini__content"
:class="[border && 'u-border-bottom']"
:style="{
height: addUnit(height),
backgroundColor: bgColor,
}"
>
<view
class="u-navbar-mini__content__left"
hover-class="u-navbar-mini__content__left--hover"
hover-start-time="150"
@tap="leftClick"
>
<slot name="left">
<up-icon
:name="leftIcon"
:size="iconSize"
:color="iconColor"
></up-icon>
</slot>
</view>
<view style="padding: 10px 10px;">
<up-line direction="col" color="#fff" length="16px"></up-line>
</view>
<view
class="u-navbar-mini__content__center" @tap="homeClick">
<slot name="center">
<up-icon name="home" :size="iconSize" :color="iconColor"></up-icon>
</slot>
</view>
</view>
</view>
</view>
</template>

<script>
import { props } from './props';
console.log(props)
import { mpMixin } from '../../libs/mixin/mpMixin';
import { mixin } from '../../libs/mixin/mixin';
import { addUnit, addStyle, getPx, sys } from '../../libs/function/index';
/**
* NavbarMini 迷你导航栏
* @description 此组件一般用于在全屏页面中,典型的如微信小程序左上角。
* @tutorial https://ijry.github.io/uview-plus/components/navbar-mini.html
* @property {Boolean} safeAreaInsetTop 是否开启顶部安全区适配 (默认 true )
* @property {Boolean} placeholder 固定在顶部时,是否生成一个等高元素,以防止塌陷 (默认 false )
* @property {Boolean} fixed 导航栏是否固定在顶部 (默认 false )
* @property {String} leftIcon 左边返回图标的名称,只能为uView自带的图标 (默认 'arrow-left' )
* @property {String} title 导航栏标题,如设置为空字符,将会隐藏标题占位区域
* @property {String} bgColor 导航栏背景设置 (默认 '#ffffff' )
* @property {String | Number} height 导航栏高度(不包括状态栏高度在内,内部自动加上)(默认 '44px' )
* @property {String | Number} iconSize 左侧返回图标的大小(默认 20px )
* @property {String | Number} leftIconColor 左侧返回图标的颜色(默认 #303133 )
* @property {Boolean} autoBack 点击左侧区域(返回图标),是否自动返回上一页(默认 false )
* @property {Object | String} titleStyle 标题的样式,对象或字符串
* @event {Function} leftClick 点击左侧区域
* @event {Function} rightClick 点击右侧区域
* @example <u-navbar-mini @click-left="onClickBack"></u-navbar-mini>
*/
export default {
name: 'u-navbar-mini',
mixins: [mpMixin, mixin, props],
data() {
return {
}
},
emits: ["leftClick", "homeClick"],
created() {
},
methods: {
addStyle,
addUnit,
sys,
getPx,
// 点击左侧区域
leftClick() {
// 如果配置了autoBack,自动返回上一页
this.$emit('leftClick')
if(this.autoBack) {
uni.navigateBack()
}
},
homeClick() {
if (this.homeUrl) {
uni.reLaunch({ url: this.homeUrl })
}
}
}
}
</script>

<style lang="scss" scoped>
@import "../../libs/css/components.scss";
.u-navbar-mini {
&__inner {
width: 180rpx;
border-radius: 20px;
overflow: hidden;
}
&--fixed {
position: fixed;
left: 20px;
right: 0;
top: 10px;
z-index: 11;
}
&__content {
@include flex(row);
padding: 0 15px;
align-items: center;
height: 44px;
background-color: #9acafc;
position: relative;
justify-content: space-between;
&__left {
@include flex(row);
align-items: center;
}
&__left {
&--hover {
opacity: 0.7;
}
}
}
}
</style>

0 comments on commit eb82053

Please sign in to comment.