2023-12-19 15:10:50 +00:00
|
|
|
|
<!-- 顶部导航栏 -->
|
2022-11-22 07:45:36 +00:00
|
|
|
|
<template>
|
|
|
|
|
<navbar
|
2024-03-13 14:46:46 +00:00
|
|
|
|
:alway="isAlways"
|
2022-11-22 07:45:36 +00:00
|
|
|
|
:back="false"
|
|
|
|
|
bg=""
|
|
|
|
|
:placeholder="isPlaceholder"
|
|
|
|
|
:bgStyles="bgStyles"
|
|
|
|
|
:opacity="isOpacity"
|
|
|
|
|
:sticky="sticky"
|
|
|
|
|
>
|
|
|
|
|
<template #item>
|
|
|
|
|
<view class="nav-box">
|
2023-02-07 07:51:37 +00:00
|
|
|
|
<view class="nav-icon" v-if="showLeftButton">
|
2024-03-13 14:46:46 +00:00
|
|
|
|
<view class="icon-box ss-flex" :class="{ 'inner-icon-box': data.styleType === 'inner' }">
|
2023-02-07 07:51:37 +00:00
|
|
|
|
<view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
|
|
|
|
|
<text class="sicon-back" v-if="hasHistory" />
|
|
|
|
|
<text class="sicon-home" v-else />
|
|
|
|
|
</view>
|
|
|
|
|
<view class="line"></view>
|
|
|
|
|
<view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
|
|
|
|
|
<text class="sicon-more" />
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
2022-11-22 07:45:36 +00:00
|
|
|
|
<view
|
|
|
|
|
class="nav-item"
|
|
|
|
|
v-for="(item, index) in navList"
|
|
|
|
|
:key="index"
|
|
|
|
|
:style="[parseImgStyle(item)]"
|
|
|
|
|
:class="[{ 'ss-flex ss-col-center ss-row-center': item.type !== 'search' }]"
|
|
|
|
|
>
|
|
|
|
|
<navbar-item :data="item" :width="parseImgStyle(item).width" />
|
|
|
|
|
</view>
|
|
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
</navbar>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
/**
|
|
|
|
|
* 装修组件 - 自定义标题栏
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @property {Number | String} alwaysShow = [0,1] - 是否常驻
|
2024-03-13 14:46:46 +00:00
|
|
|
|
* @property {Number | String} styleType = [inner] - 是否沉浸式
|
2024-08-25 06:06:33 +00:00
|
|
|
|
* @property {String | Number} type - 标题背景模式
|
|
|
|
|
* @property {String} color - 页面背景色
|
|
|
|
|
* @property {String} src - 页面背景图片
|
2022-11-22 07:45:36 +00:00
|
|
|
|
*/
|
|
|
|
|
import { computed, unref } from 'vue';
|
|
|
|
|
import sheep from '@/sheep';
|
|
|
|
|
import Navbar from './components/navbar.vue';
|
|
|
|
|
import NavbarItem from './components/navbar-item.vue';
|
2023-02-07 07:51:37 +00:00
|
|
|
|
import { showMenuTools } from '@/sheep/hooks/useModal';
|
2022-11-22 07:45:36 +00:00
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
data: {
|
|
|
|
|
type: Object,
|
|
|
|
|
default: () => ({}),
|
|
|
|
|
},
|
2023-02-07 07:51:37 +00:00
|
|
|
|
showLeftButton: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
|
|
|
|
},
|
2022-11-22 07:45:36 +00:00
|
|
|
|
});
|
2023-02-07 07:51:37 +00:00
|
|
|
|
const hasHistory = sheep.$router.hasHistory();
|
2022-11-22 07:45:36 +00:00
|
|
|
|
const sticky = computed(() => {
|
2024-03-13 14:46:46 +00:00
|
|
|
|
if (props.data.styleType === 'inner') {
|
|
|
|
|
if (props.data.alwaysShow) {
|
2022-11-22 07:45:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-13 14:46:46 +00:00
|
|
|
|
if (props.data.styleType === 'normal') {
|
2022-11-22 07:45:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const navList = computed(() => {
|
|
|
|
|
// #ifdef MP
|
2024-08-25 06:06:33 +00:00
|
|
|
|
return props.data.mpCells || [];
|
2022-11-22 07:45:36 +00:00
|
|
|
|
// #endif
|
2024-03-13 14:46:46 +00:00
|
|
|
|
return props.data.otherCells || [];
|
2022-11-22 07:45:36 +00:00
|
|
|
|
});
|
2024-03-13 14:46:46 +00:00
|
|
|
|
// 页面宽度
|
2022-11-22 07:45:36 +00:00
|
|
|
|
const windowWidth = sheep.$platform.device.windowWidth;
|
2024-03-13 14:46:46 +00:00
|
|
|
|
// 单元格宽度
|
2022-11-22 07:45:36 +00:00
|
|
|
|
const cell = computed(() => {
|
|
|
|
|
if (unref(navList).length) {
|
2024-03-13 14:46:46 +00:00
|
|
|
|
// 默认宽度为8个格子,微信公众号右上角有胶囊按钮所以是6个格子
|
2022-11-22 07:45:36 +00:00
|
|
|
|
let cell = (windowWidth - 90) / 8;
|
|
|
|
|
// #ifdef MP
|
|
|
|
|
cell = (windowWidth - 80 - unref(sheep.$platform.capsule).width) / 6;
|
|
|
|
|
// #endif
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 解析位置
|
|
|
|
|
const parseImgStyle = (item) => {
|
|
|
|
|
let obj = {
|
|
|
|
|
width: item.width * cell.value + (item.width - 1) * 10 + 'px',
|
|
|
|
|
left: item.left * cell.value + (item.left + 1) * 10 + 'px',
|
|
|
|
|
'border-radius': item.borderRadius + 'px',
|
|
|
|
|
};
|
|
|
|
|
return obj;
|
|
|
|
|
};
|
2024-03-13 14:46:46 +00:00
|
|
|
|
const isAlways = computed(() =>
|
|
|
|
|
props.data.styleType === 'inner' ? Boolean(props.data.alwaysShow) : true,
|
2022-11-22 07:45:36 +00:00
|
|
|
|
);
|
|
|
|
|
const isOpacity = computed(() =>
|
2024-03-13 14:46:46 +00:00
|
|
|
|
props.data.styleType === 'normal'
|
2023-02-07 07:51:37 +00:00
|
|
|
|
? false
|
|
|
|
|
: props.showLeftButton
|
|
|
|
|
? false
|
2024-03-13 14:46:46 +00:00
|
|
|
|
: props.data.styleType === 'inner',
|
2022-11-22 07:45:36 +00:00
|
|
|
|
);
|
2024-03-13 14:46:46 +00:00
|
|
|
|
const isPlaceholder = computed(() => props.data.styleType === 'normal');
|
2022-11-22 07:45:36 +00:00
|
|
|
|
const bgStyles = computed(() => {
|
2024-03-13 14:46:46 +00:00
|
|
|
|
return {
|
|
|
|
|
background:
|
2024-08-25 06:06:33 +00:00
|
|
|
|
props.data.bgType === 'img' && props.data.bgImg
|
2024-03-13 14:46:46 +00:00
|
|
|
|
? `url(${sheep.$url.cdn(props.data.bgImg)}) no-repeat top center / 100% 100%`
|
2024-08-25 06:06:33 +00:00
|
|
|
|
: props.data.bgColor,
|
2024-03-13 14:46:46 +00:00
|
|
|
|
};
|
2022-11-22 07:45:36 +00:00
|
|
|
|
});
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2024-03-13 14:46:46 +00:00
|
|
|
|
// 左侧按钮:返回上一页或首页
|
2023-02-07 07:51:37 +00:00
|
|
|
|
function onClickLeft() {
|
|
|
|
|
if (hasHistory) {
|
|
|
|
|
sheep.$router.back();
|
|
|
|
|
} else {
|
|
|
|
|
sheep.$router.go('/pages/index/index');
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2024-03-13 14:46:46 +00:00
|
|
|
|
// 右侧按钮:打开快捷菜单
|
2023-02-07 07:51:37 +00:00
|
|
|
|
function onClickRight() {
|
|
|
|
|
showMenuTools();
|
|
|
|
|
}
|
2022-11-22 07:45:36 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.nav-box {
|
|
|
|
|
width: 750rpx;
|
|
|
|
|
position: relative;
|
|
|
|
|
height: 100%;
|
|
|
|
|
|
|
|
|
|
.nav-item {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 50%;
|
|
|
|
|
transform: translateY(-50%);
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.nav-icon {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 50%;
|
|
|
|
|
transform: translateY(-50%);
|
|
|
|
|
left: 20rpx;
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.inner-icon-box {
|
|
|
|
|
border: 1px solid rgba(#fff, 0.4);
|
|
|
|
|
background: none !important;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.icon-box {
|
|
|
|
|
background: #ffffff;
|
2024-08-25 06:06:33 +00:00
|
|
|
|
box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
|
2023-02-07 07:51:37 +00:00
|
|
|
|
border-radius: 30rpx;
|
|
|
|
|
width: 134rpx;
|
|
|
|
|
height: 56rpx;
|
|
|
|
|
margin-left: 8rpx;
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.line {
|
|
|
|
|
width: 2rpx;
|
|
|
|
|
height: 24rpx;
|
|
|
|
|
background: #e5e5e7;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.sicon-back {
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.sicon-home {
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.sicon-more {
|
|
|
|
|
font-size: 32rpx;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
.icon-button {
|
|
|
|
|
width: 67rpx;
|
|
|
|
|
height: 56rpx;
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
&-left:hover {
|
|
|
|
|
background: rgba(0, 0, 0, 0.16);
|
|
|
|
|
border-radius: 30rpx 0px 0px 30rpx;
|
|
|
|
|
}
|
2024-08-25 06:06:33 +00:00
|
|
|
|
|
2023-02-07 07:51:37 +00:00
|
|
|
|
&-right:hover {
|
|
|
|
|
background: rgba(0, 0, 0, 0.16);
|
|
|
|
|
border-radius: 0px 30rpx 30rpx 0px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-22 07:45:36 +00:00
|
|
|
|
}
|
|
|
|
|
</style>
|