Files
kangyuan-mobile/sheep/components/s-layout/s-layout.vue
T

327 lines
7.7 KiB
Vue

<template>
<!-- :class="['theme-' + sys?.mode, 'main-' + sys?.theme, 'font-' + sys?.fontSize]" -->
<view class="page-app theme-ai" :style="[bgMain]">
<!-- :style="[bgMain]" -->
<view class="page-main">
<cardNavbar
v-if="navbar === 'normal'"
:title="title"
:showLeftButton="showLeftButton"
:bg="navBarColors.bg"
:color="navBarColors.color"
@clickLeft="onClickLeft"
:index="props.index"
>
<template #left>
<slot name="navLeft" />
</template>
<template #right>
<slot name="navRight" />
</template>
</cardNavbar>
<innerNavbar
v-if="navbar === 'inner'"
:title="title"
:showLeftButton="showLeftButton"
:bg="navBarColors.bg"
:color="navBarColors.color"
:scrollbg="navBarColors.scrollbg"
:scrollColor="navBarColors.scrollColor"
@clickLeft="onClickLeft"
:index="props.index"
>
<template #left>
<slot name="navLeft" />
</template>
<template #right>
<slot name="navRight" />
</template>
</innerNavbar>
<transparentNavbar
v-if="navbar === 'transparent'"
:title="title"
:showLeftButton="showLeftButton"
:bg="navBarColors.bg"
:color="navBarColors.color"
:scrollbg="navBarColors.scrollbg"
:scrollColor="navBarColors.scrollColor"
@clickLeft="onClickLeft"
:index="props.index"
>
<template #left>
<slot name="navLeft" />
</template>
<template #right>
<slot name="navRight" />
</template>
</transparentNavbar>
<!-- 页面内容插槽 -->
<!-- :style="{ paddingTop: paddingTop + 'px' }" -->
<view class="pageCon" :style="pageConStyle">
<!-- <view class="transparent_bg" style="z-index: 100;">
<image src="/static/transparent_bg.png" />
</view> -->
<slot />
</view>
</view>
<view class="">
<!-- 全局授权弹窗 -->
<s-auth-modal />
<!-- 全局快捷入口 -->
<s-menu-tools />
</view>
<cardTabber v-if="props.tabbar" :path="tabbarPath" />
</view>
</template>
<script setup>
import { getCurrentInstance, ref, computed, watch } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import innerNavbar from '@/components/card_navbar/inner-navbar';
import cardNavbar from '@/components/card_navbar/card_navbar';
import transparentNavbar from '@/components/card_navbar/transparent_navbar';
import cardTabber from '@/components/card_tabber/card_tabber.vue';
import sheep from '@/sheep';
const emits = defineEmits(['onClickLeft']);
const instance = getCurrentInstance();
const proxy = instance?.proxy;
const props = defineProps({
title: {
type: String,
default: '',
},
navbar: {
type: String,
default: 'normal',
},
opacityBgUi: {
type: String,
default: 'bg-white',
},
color: {
type: String,
default: '#ffffff',
},
tools: {
type: String,
default: 'title',
},
keyword: {
type: String,
default: '',
},
navbarStyle: {
type: Object,
default: () => ({
styleType: '',
type: '',
color: '',
src: '',
list: [],
alwaysShow: 0,
}),
},
bgStyle: {
type: Object,
default: () => ({
src: '',
color: '#F2F4F7',
}),
},
tabbar: {
type: [String, Boolean],
default: '',
},
onShareAppMessage: {
type: [Boolean, Object],
default: true,
},
leftWidth: {
type: [Number, String],
default: 100,
},
rightWidth: {
type: [Number, String],
default: 100,
},
defaultSearch: {
type: String,
default: '',
},
//展示返回按钮
showLeftButton: {
type: Boolean,
default: true,
},
goLeft: {
type: Boolean,
default: true,
},
theme: {
type: String,
default: '2',
},
navPreset: {
type: String,
default: '',
},
index: {
type: Number,
default: 0,
},
});
const sys = computed(() => sysStore);
const sysStore = sheep.$store('sys');
const userStore = sheep.$store('user');
const appStore = sheep.$store('app');
const modalStore = sheep.$store('modal');
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
let paddingTop = ref();
paddingTop.value = statusBarHeight + 44;
const tabbarPath = ref('');
const normalizePath = (p) => {
if (!p) return '';
return p.startsWith('/') ? p : `/${p}`;
};
const updateTabbarPath = () => {
if (typeof props.tabbar === 'string' && props.tabbar) {
tabbarPath.value = normalizePath(props.tabbar);
return;
}
const pages = getCurrentPages?.() || [];
const current = pages[pages.length - 1];
tabbarPath.value = normalizePath(current?.route || '');
};
onShow(() => updateTabbarPath());
watch(() => props.tabbar, () => updateTabbarPath(), { immediate: true });
const pageConStyle = computed(() => {
const style = {
paddingTop: paddingTop.value + 'px',
};
if (props.tabbar) {
style.paddingBottom = `calc(${uni.upx2px(100)}px + env(safe-area-inset-bottom))`;
}
return style;
});
const bgMain = computed(() => {
const bgColor = props.bgStyle.backgroundColor || props.bgStyle.color;
const bgImg = props.bgStyle.backgroundImage
? `url(${sheep.$url.cdn(props.bgStyle.backgroundImage)})`
: 'none';
return {
backgroundColor: bgColor,
backgroundImage: bgImg,
backgroundRepeat: 'no-repeat',
backgroundPosition: 'top center',
backgroundSize: '100% auto',
};
});
const navBarColors = computed(() => {
if (props.navPreset === 'float') {
if (props.navbar === 'normal') {
return {
bg: '#ffffff',
color: '#333333',
scrollbg: '#ffffff',
scrollColor: '#333333',
};
}
return {
bg: 'transparent',
color: '#ffffff',
scrollbg: '#ffffff',
scrollColor: '#333333',
};
}
if (props.navPreset === 'light') {
return {
bg: '#ffffff',
color: '#333333',
scrollbg: '#ffffff',
scrollColor: '#333333',
};
}
if (props.navPreset === 'transparent') {
return {
bg: 'transparent',
color: '#333333',
scrollbg: '#ffffff',
scrollColor: '#333333',
};
}
if (props.navPreset === 'dark') {
return {
bg: '#000000',
color: '#ffffff',
scrollbg: '#000000',
scrollColor: '#ffffff',
};
}
if (props.navPreset === 'blue') {
return {
bg: '#2556EC',
color: '#ffffff',
scrollbg: '#000000',
scrollColor: '#ffffff',
};
}
return {
bg: undefined,
color: undefined,
scrollbg: undefined,
scrollColor: undefined,
};
});
const onClickLeft = () => {
console.log('返回2');
emits('onClickLeft');
};
</script>
<style scoped lang="scss">
.one {
width: 100%;
height: 708rpx;
background-image: linear-gradient(to top, #f2f4f7 0%, rgba(251, 129, 55, 0.459) 36%);
}
.transparent_bg {
width: 100%;
height: 708rpx;
// position: fixed;
// top: 0;
// left: 0;
image {
width: 100%;
height: 100%;
}
}
.page-app {
min-height: 100vh;
display: flex;
flex-direction: column;
.page-main {
flex: 1;
display: flex;
flex-direction: column;
.pageCon {
flex: 1;
box-sizing: border-box;
}
}
}
.pageCon {
box-sizing: border-box;
}
</style>