注册全局头部组件

parent e30b0992
...@@ -19,12 +19,12 @@ const containerMargin = ref(0); ...@@ -19,12 +19,12 @@ const containerMargin = ref(0);
const bgColor = ref(''); const bgColor = ref('');
onMounted(() => { onMounted(() => {
const capsuleButtonInfo = xma.getMenuButtonBoundingClientRect(); const capsuleButtonInfo = xma.xh.getMenuButtonBoundingClientRect();
const systemInfo = xma.getSystemInfoSync(); const systemInfo = xma.xh.getSystemInfoSync();
const gap = capsuleButtonInfo.top - systemInfo.statusBarHeight; const gap = capsuleButtonInfo.top - systemInfo.statusBarHeight;
navBarHeight.value = gap * 2 + capsuleButtonInfo.height + systemInfo.statusBarHeight; navBarHeight.value = gap * 2 + capsuleButtonInfo.height + systemInfo.statusBarHeight;
containerHeight.value = capsuleButtonInfo.height; // containerHeight.value = capsuleButtonInfo.height;
containerMargin.value = capsuleButtonInfo.top; // containerMargin.value = capsuleButtonInfo.top;
}); });
</script> </script>
......
<template> <template>
<view class="search" :style="{ background: background }"> <view class="content" :style="{ height: contentHeight, background: backgroundBox }">
<wd-icon <view class="search" :style="{ background }">
v-if="show" <wd-icon
name="thin-arrow-left" v-if="show"
class="icon" name="thin-arrow-left"
@tap="back" class="icon"
:style="{ color: backIcon }" @tap="back"
></wd-icon> :style="{ color: backIcon }"
<slot></slot> ></wd-icon>
<view class="searchBox"> <slot></slot>
<image <view class="searchBox" :style="{ border }" v-if="type === 1">
class="magnifyingGlass" <image
src="../../static/index/magnifyingGlass.png" class="magnifyingGlass"
mode="aspectFit|aspectFill|widthFix" src="../../static/index/magnifyingGlass.png"
/> mode="aspectFit|aspectFill|widthFix"
<input type="text" :value="test" class="text" @confirm="search" confirm-type="搜索" /> />
<input type="text" :value="test" class="text" @confirm="search" confirm-type="搜索" />
</view>
<text class="title" :style="{ color: textColor }" v-else>{{ title }}</text>
</view> </view>
</view> </view>
</template> </template>
...@@ -29,15 +32,36 @@ const props = defineProps({ ...@@ -29,15 +32,36 @@ const props = defineProps({
}, },
backIcon: { backIcon: {
type: String, type: String,
default: 'white', default: 'black',
}, },
show: { show: {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
backgroundBox: {
type: String,
default: '',
},
border: {
type: String,
default: '',
},
type: {
type: Number,
default: 1,
},
textColor: {
type: String,
default: '#333333',
},
title: {
type: String,
default: 'HELLO WORLD',
},
}); });
const contentHeight = ref('100rpx');
const emit = defineEmits(['toSearch']); const emit = defineEmits(['toSearch']);
const title = ref('小程序平台'); // const title = ref('小程序平台');
const { countInfo, addCount } = useCountStore(); const { countInfo, addCount } = useCountStore();
const test = ref(''); const test = ref('');
onLoad(() => { onLoad(() => {
...@@ -53,7 +77,8 @@ onLoad(() => { ...@@ -53,7 +77,8 @@ onLoad(() => {
console.log('上边界坐标', res.top); // 上边界坐标,单位:px console.log('上边界坐标', res.top); // 上边界坐标,单位:px
console.log('右边界坐标', res.right); // 右边界坐标,单位:px console.log('右边界坐标', res.right); // 右边界坐标,单位:px
console.log('下边界坐标', res.bottom); // 下边界坐标,单位:px console.log('下边界坐标', res.bottom); // 下边界坐标,单位:px
console.log('左边界坐标', res.left); // 左边界坐标,单位:px console.log('左边界坐标', res.left);
contentHeight.value = res.bottom * 2 + 10 + 'rpx'; // 左边界坐标,单位:px
}, },
}); });
}); });
...@@ -78,42 +103,61 @@ function onHandleClick() { ...@@ -78,42 +103,61 @@ function onHandleClick() {
</script> </script>
<style lang="scss"> <style lang="scss">
.search { .content {
width: 710rpx; position: sticky;
height: 80rpx; top: 0;
// background: rgba(255, 255, 255, 0.8); z-index: 999999;
border-radius: 16rpx 16rpx 16rpx 16rpx; transition: background-color 0.5s;
opacity: 0.8;
margin: 0 auto;
margin-top: 44rpx;
display: flex;
align-items: center;
padding-left: 20rpx;
box-sizing: border-box; box-sizing: border-box;
.arrow { .search {
width: 15rpx; position: absolute;
height: 24rpx; bottom: 10rpx;
} left: 50%;
.icon { transform: translateX(-50%);
font-size: 28rpx; width: 710rpx;
} height: 80rpx;
.searchBox { // background: rgba(255, 255, 255, 0.8);
opacity: 1; border-radius: 16rpx 16rpx 16rpx 16rpx;
width: 256rpx; opacity: 0.8;
height: 56rpx; margin: 0 auto;
background: #ffffff; // margin-top: 44rpx;
border-radius: 28rpx 28rpx 28rpx 28rpx;
display: flex; display: flex;
align-items: center; align-items: center;
padding-left: 20rpx; // padding-left: 20rpx;
margin-left: 20rpx; box-sizing: border-box;
.magnifyingGlass { text-align: center;
width: 26rpx; .arrow {
height: 26rpx; width: 15rpx;
height: 24rpx;
}
.icon {
font-size: 28rpx;
// left: 10rpx;
position: absolute;
}
.searchBox {
opacity: 1;
width: 256rpx;
height: 56rpx;
background: #ffffff;
border-radius: 28rpx 28rpx 28rpx 28rpx;
display: flex;
align-items: center;
padding-left: 20rpx;
margin-left: 20rpx;
.magnifyingGlass {
width: 26rpx;
height: 26rpx;
}
.text {
margin-left: 10rpx;
font-size: 24rpx;
}
} }
.text { .title {
margin-left: 10rpx; width: 100%;
font-size: 24rpx; font-size: 36rpx;
font-family: PingFang SC;
} }
} }
} }
......
...@@ -6,8 +6,10 @@ import Vconsole from 'vconsole'; ...@@ -6,8 +6,10 @@ import Vconsole from 'vconsole';
import './styles/flex.scss'; import './styles/flex.scss';
// 字体 // 字体
import '@/assets/iconfont/font.css'; import '@/assets/iconfont/font.css';
import Search from './components/index/Search.vue';
export function createApp() { export function createApp() {
const app = createSSRApp(App); const app = createSSRApp(App);
app.component('Search', Search);
const vConsole = new Vconsole(); const vConsole = new Vconsole();
app.use(store, vConsole); app.use(store, vConsole);
return { return {
......
<template> <template>
<div class="container" style="padding-bottom: 10rpx"> <!-- 搜索 -->
<Search
@toSearch="toSearch"
:backIcon="backIconColor"
:backgroundBox="backgroundBox"
:border="border"
>
<text class="title-icon" :style="{ color: textColor }">{{ categoryNames }}</text>
<!-- <image class="food" :src="pics" mode="widthFix" /> -->
</Search>
<view class="container" style="padding-bottom: 10rpx">
<view class="bg-img"></view> <view class="bg-img"></view>
<view class="top"> <view class="top">
<!-- 搜索 -->
<Search @toSearch="toSearch">
<text class="title-icon">{{ categoryNames }}</text>
<!-- <image class="food" :src="pics" mode="widthFix" /> -->
</Search>
<!-- 类别选择 --> <!-- 类别选择 -->
<scroll-view <scroll-view
v-if="topDiscountedProducts.length > 0" v-if="topDiscountedProducts.length > 0"
...@@ -110,17 +115,21 @@ ...@@ -110,17 +115,21 @@
> >
没有更多啦~ 没有更多啦~
</view> </view>
</div> </view>
</template> </template>
<script setup> <script setup>
import FoodDetails from '../../components/index/FoodDetails.vue'; import FoodDetails from '../../components/index/FoodDetails.vue';
import Search from '../../components/index/Search.vue'; // import Search from '../../components/index/Search.vue';
import Classification from '../../components/index/Classification.vue'; import Classification from '../../components/index/Classification.vue';
import Position from '../../components/index/Position.vue'; import Position from '../../components/index/Position.vue';
import Sort from '../../components/index/Sort.vue'; import Sort from '../../components/index/Sort.vue';
import { getByParentId, merchantList, prodSpecial } from '../../api/index'; import { getByParentId, merchantList, prodSpecial } from '../../api/index';
const backIconColor = ref('white');
const textColor = ref('#ffffff');
const backgroundBox = ref('');
const border = ref('');
const isLoadReachBottom = ref(null); const isLoadReachBottom = ref(null);
const imgUrl = import.meta.env.VITE_APP_IMG_URL; const imgUrl = import.meta.env.VITE_APP_IMG_URL;
const business = reactive(['优选商家', '超值半价', '今日可订', '经典单人']); const business = reactive(['优选商家', '超值半价', '今日可订', '经典单人']);
...@@ -344,12 +353,32 @@ function getLocationFn() { ...@@ -344,12 +353,32 @@ function getLocationFn() {
}); });
}); });
} }
// 监听页面滚动
onPageScroll((e) => {
if (e.scrollTop > 20) {
backIconColor.value = '';
textColor.value = 'black';
backgroundBox.value = '#fff';
border.value = '1rpx solid gray';
} else {
backIconColor.value = 'white';
textColor.value = 'white';
backgroundBox.value = '';
border.value = '';
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
page { page {
background: #f3f3f3; background: #f3f3f3;
} }
.title-icon {
font-family: 'YSBTH';
font-size: 24 * 2rpx;
margin-left: 50rpx;
margin-right: 10rpx;
}
.container { .container {
.bg-img { .bg-img {
width: 100%; width: 100%;
...@@ -364,12 +393,7 @@ page { ...@@ -364,12 +393,7 @@ page {
min-height: 420rpx; min-height: 420rpx;
border-radius: 0rpx 0rpx 0rpx 0rpx; border-radius: 0rpx 0rpx 0rpx 0rpx;
overflow: hidden; overflow: hidden;
.title-icon {
font-family: 'YSBTH';
font-size: 24 * 2rpx;
margin-left: 30rpx;
color: #ffffff;
}
.food { .food {
width: 178rpx; width: 178rpx;
height: 45rpx; height: 45rpx;
......
<template> <template>
<!-- 搜索 -->
<Search
:backgroundBox="backgroundBox"
background="rgba(255, 255, 255, 0.8)"
@toSearch="toSearch"
:show="false"
>
<image class="food" src="../../static/index/food.png" mode="widthFix" />
</Search>
<view class="container"> <view class="container">
<view class="top"> <view class="top">
<!-- 搜索 -->
<Search
background="rgba(255, 255, 255, 0.8)"
backIcon="black"
@toSearch="toSearch"
:show="false"
>
<image class="food" src="../../static/index/food.png" mode="widthFix" />
</Search>
<!-- 类别选择 --> <!-- 类别选择 -->
<view class="classification"> <view class="classification">
<view class="classification-top"> <view class="classification-top">
...@@ -164,7 +164,7 @@ import fab from '../../components/fab/fab.vue'; ...@@ -164,7 +164,7 @@ import fab from '../../components/fab/fab.vue';
import myIcon from '../../components/wd-icon-local/wd-icon.vue'; import myIcon from '../../components/wd-icon-local/wd-icon.vue';
import { onMounted, reactive, ref } from 'vue'; import { onMounted, reactive, ref } from 'vue';
import { useCountStore } from '@/store'; import { useCountStore } from '@/store';
import Search from '../../components/index/Search.vue'; // import Search from '../../components/index/Search.vue';
import FoodDetails from '../../components/index/FoodDetails.vue'; import FoodDetails from '../../components/index/FoodDetails.vue';
import ShopCard from '../../components/index/ShopCard.vue'; import ShopCard from '../../components/index/ShopCard.vue';
import Marketing from '../../components/index/Marketing.vue'; import Marketing from '../../components/index/Marketing.vue';
...@@ -181,7 +181,8 @@ import { ...@@ -181,7 +181,8 @@ import {
couponMainList, couponMainList,
receiveCoupon, receiveCoupon,
} from '../../api/index'; } from '../../api/index';
const backgroundBox = ref('#fa5151');
const border = ref('');
// import testJson from '../../static/json/test.json'; // import testJson from '../../static/json/test.json';
const nowTime = ref(new Date().getTime()); const nowTime = ref(new Date().getTime());
const title = ref('小程序平台'); const title = ref('小程序平台');
...@@ -515,24 +516,35 @@ onReachBottom(() => { ...@@ -515,24 +516,35 @@ onReachBottom(() => {
} }
show.value = true; show.value = true;
}); });
// 监听页面滚动
onPageScroll((e) => {
if (e.scrollTop > 20) {
// backgroundBox.value = '#fff';
// border.value = '1px solid #fa5151';
} else {
// backgroundBox.value = '#fa5151';
// border.value = '';
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
page { page {
background: #f3f3f3; background: #f3f3f3;
} }
.food {
width: 178rpx;
height: 45rpx;
margin-left: 25rpx;
}
.container { .container {
.top { .top {
width: 100%; width: 100%;
height: 440rpx; // height: 440rpx;
background: linear-gradient(180deg, #fa5151 0%, rgba(243, 243, 243, 0) 100%); background: linear-gradient(180deg, #fa5151 0%, rgba(243, 243, 243, 0) 100%);
border-radius: 0rpx 0rpx 0rpx 0rpx; border-radius: 0rpx 0rpx 0rpx 0rpx;
overflow: hidden; overflow: hidden;
.food {
width: 178rpx;
height: 45rpx;
margin-left: 25rpx;
}
.classification { .classification {
width: 710rpx; width: 710rpx;
height: 304rpx; height: 304rpx;
...@@ -613,6 +625,7 @@ page { ...@@ -613,6 +625,7 @@ page {
box-sizing: border-box; box-sizing: border-box;
white-space: nowrap; white-space: nowrap;
width: 80%; width: 80%;
z-index: -1;
.redBagBox { .redBagBox {
margin-right: 8rpx; margin-right: 8rpx;
width: 124rpx; width: 124rpx;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment