Files
huangguo_dhz/src/views/mobile/mobileSearch/index.vue
T
谢宇宁andClaude Opus 4.8 c957b45bad 初始化黄果短剧 H5 客户端
对接后端 hgmjapi.mfcg.me:
- 接口解密 key 更新为 resKey360
- 登录 sysType 使用原生 getDevType(后端已放开 pc/android)
- 修正榜单接口路径 /vid/rangking → /vid/ranking,方法改为 GET

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-08 19:41:43 +07:00

327 lines
8.3 KiB
Vue

<template>
<div class="search overflow-y-auto" ref="searchRef">
<MobileAdvBanner
class="advBanner"
:list="state.advList"
v-if="showAdvBanner && state.advList && state.advList.length"
/>
<div class="contentBox">
<van-dropdown-menu ref="menuRef" class="dropdownBox" :overlay="false">
<van-dropdown-item v-model="state.activeOpt" :options="state.options" @change="changeOpt" />
</van-dropdown-menu>
<div class="searchBox">
<van-field v-model="state.searchValue" :border="false" class="searchInput" />
<div class="searchBtn" @click="search()">搜索一下</div>
</div>
<div class="hotSearch">
<div class="hotSearchItem" v-for="i in state.hotKeywords.slice(0, 10)" :key="i" @click="search(i.name)">
{{ i.name }}
</div>
</div>
<div class="result" v-if="state.isSearch">
<div class="subTitle">搜索结果</div>
<div class="videoNum">
全部视频
<span>({{ state.total }})</span>
</div>
<div class="videoList">
<div class="videoItem" v-for="item in state.resultList" :key="item.id">
<AdvBox :advInfo="item" v-if="item.isAdv" />
<MobileVideoBox :videoInfo="item" v-else />
</div>
</div>
</div>
<div class="recommend" v-else>
<div class="subTitle">大家都在搜</div>
<div class="videoList">
<div class="videoItem" v-for="item in state.recommendList" :key="item.id">
<AdvBox :advInfo="item" v-if="item.isAdv" />
<MobileVideoBox :videoInfo="item" v-else />
</div>
</div>
</div>
<MobilePagination
class="pagination"
:total="state.total"
:pageNumber="state.pageNumber"
:pageSize="state.pageSize"
v-if="state.total > state.pageSize && state.isSearch"
@changePage="changePage"
/>
</div>
<MobileBottom />
</div>
</template>
<script lang="ts" setup>
import { reactive, computed, ref } from 'vue';
import { useGlobalStore } from '@/stores/global';
import { getAdItem } from '@/utils/getConfig';
import { AdType } from '@/enums/app';
import { useRoute, useRouter } from 'vue-router';
import CommunityApi from '@/service/community';
import insertAdv from '@/utils/insertAdv';
const route = useRoute();
const router = useRouter();
const globalStore = useGlobalStore();
const searchRef = ref();
const state = reactive({
options: [
{ text: '默认', value: undefined },
{ text: '最新上架', value: 0 },
{ text: '最多观看', value: 2 },
{ text: '最多收藏', value: 3 },
],
activeOpt: undefined,
searchValue: '',
hotKeywords: <any>[],
advList: <any>[],
resultList: <any>[],
recommendList: <any>[],
pageSize: 7,
pageNumber: 1,
total: 0,
isSearch: false,
});
const showAdvBanner = computed(() => {
return globalStore.showAdvBanner;
});
const changeOpt = (val: any) => {
search();
};
const search = async (value?: string, isChangePage?: boolean) => {
state.isSearch = true;
if (value) {
state.searchValue = value;
}
if (!isChangePage) {
state.pageNumber = 1;
}
let req = {
SortV: state.activeOpt,
keyWords: [state.searchValue],
pageNumber: state.pageNumber,
pageSize: state.pageSize,
realm: 'video',
};
const res: any = await CommunityApi.searchPost(req);
let videoList = res.list || [];
let params = {
insertNum: 6,
pageSize: state.pageSize,
pageNumber: state.pageNumber,
advNum: 6,
originArray: videoList,
};
state.resultList = insertAdv(params);
// state.resultList = res.list || [];
state.total = res.total || 0;
};
const queryRecommend = async () => {
try {
const res: any = await CommunityApi.searchVideo({});
let videoList = res.videos || [];
console.log(videoList);
let params = {
insertNum: 6,
pageSize: videoList.length,
pageNumber: state.pageNumber,
advNum: 6,
originArray: videoList,
};
state.recommendList = insertAdv(params);
// state.recommendList = res.videos || [];
} catch (error) {}
};
const changePage = (pageNumber: number) => {
state.pageNumber = pageNumber;
searchRef.value.scrollTo({ top: 0 });
search(undefined, true);
};
const getHotTag = async () => {
const res: any = await CommunityApi.getHotRecommend({
pageNumber: 1,
pageSize: 10,
});
state.hotKeywords = res.list || [];
};
const init = () => {
state.advList = getAdItem(AdType.HOMETOPBANNER);
getHotTag();
queryRecommend();
};
init();
</script>
<style scoped lang="scss">
.search {
height: 100vh;
// padding-top: 27px;
// box-sizing: border-box;
.advBanner {
width: 100%;
height: 70px;
}
.contentBox {
padding: 27px 16px 0;
box-sizing: border-box;
.searchBox {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
.searchInput {
width: 250px;
height: 42px;
border-radius: 6.986px;
border: 0.873px solid #ffc400;
background: #000;
padding: 0 14.85px;
font-size: 14px;
:deep(.van-field__control) {
color: #fff;
}
:deep(.van-cell__value) {
display: flex;
align-items: center;
}
}
.searchBtn {
width: 78.7px;
height: 42px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6.986px;
background: #ffc400;
box-shadow: 0px 0.873px 1.747px 0px rgba(0, 0, 0, 0.05);
color: #482f28;
font-size: 12.226px;
font-style: normal;
font-weight: 600;
line-height: 12.226px;
}
}
.hotSearch {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
padding: 0 17.1px;
box-sizing: border-box;
margin-bottom: 50.58px;
.hotSearchItem {
margin: 0 7px;
height: 21px;
color: #e5e7eb;
font-family: 'PingFang SC';
font-size: 13.972px;
font-style: normal;
font-weight: 400;
line-height: 20.958px; /* 150% */
text-decoration-line: underline;
text-decoration-style: solid;
text-decoration-skip-ink: auto;
text-decoration-thickness: auto;
text-underline-offset: auto;
text-underline-position: from-font;
}
}
.subTitle {
color: #fff;
font-family: 'PingFang SC';
font-size: 18px;
font-style: normal;
font-weight: 600;
line-height: 16px; /* 88.889% */
letter-spacing: 0.5px;
margin-bottom: 8px;
}
.videoNum {
color: #fff;
font-family: Inter;
font-size: 13px;
font-style: normal;
font-weight: 400;
line-height: 20px; /* 153.846% */
margin-bottom: 16px;
span {
color: #a0a6b4;
font-size: 12px;
}
}
.videoList {
display: grid;
grid-template-columns: 1fr 1fr;
grid-row-gap: 28px;
grid-column-gap: 12px;
margin-bottom: 28px;
}
.pagination {
margin-bottom: 30px;
}
}
.dropdownBox {
width: 76px;
height: 33px;
border-radius: 6.986px;
border: 0.873px solid #212121;
background: #151515;
margin-bottom: 13.6px;
// background: skyblue;
:deep(.van-dropdown-menu__bar) {
background: rgba(0, 0, 0, 0);
height: 100%;
}
:deep(.van-dropdown-menu__title) {
padding: 0;
padding-right: 6px;
}
:deep(.van-dropdown-menu__title--active:after) {
border-color: transparent transparent #a0a6b4 #a0a6b4;
}
:deep(.van-ellipsis) {
color: #a0a6b4;
font-size: 12px;
}
:deep(.van-dropdown-item) {
width: 76px;
left: 16px;
// top: 69px !important;
.van-dropdown-item__content {
border-radius: 5.548px;
border: 0.693px solid #212121;
background: #151515 !important;
padding: 7px 0;
box-sizing: border-box;
.van-dropdown-item__option {
background: #151515 !important;
padding: 0 13.87px;
// height: 20px;
}
.van-cell__title {
color: #a0a6b4;
font-size: 9.709px;
}
}
.van-cell:after {
display: none !important;
}
.van-cell__value {
display: none;
}
}
}
}
</style>