Files
template-10490/pages/search/[keywords].vue
赵忠林 7b43a20d43 chore(config): 更新环境变量和配置信息
- 更新 APPID 从10398 到 10490- 在页脚版权信息中添加电话号码显示
- 在顶部导航栏添加移动端电话展示- 注释掉开发环境 API 地址配置- 移除菜单样式中的 margin-right 设置
- 修改文章详情页作者字段为发布员
- 替换校园风光模块跳转链接 ID
-优化搜索关键词高亮逻辑
- 移除轮播图图片路径前缀拼接
- 调整顶部欢迎信息在不同设备上的显示方式- 更新顶部联系信息图标及文案内容
2025-10-27 15:13:27 +08:00

131 lines
4.1 KiB
Vue

<template>
<!-- 主体部分 -->
<div class="xl:w-screen-xl m-auto py-4 mt-[220px]">
<el-page-header :icon="ArrowLeft" @back="goBack">
<template #content>
<span class="text-large font-600"> {{ '站内搜索' }} </span>
</template>
<template #extra>
<!-- <el-radio-group v-model="where.model" @change="reload">-->
<!-- <el-radio-button label="文档" value="docs" />-->
<!-- <el-radio-button label="资讯" value="article" />-->
<!-- </el-radio-group>-->
</template>
<el-row :gutter="24" id="container" class="clearfix">
<el-col v-for="(item,index) in list" :key="index" :span="6" class="left mb-6">
<el-card shadow="hover" :body-style="{ padding: '0px' }" class=" hover:bg-gray-50 cursor-pointer">
<nuxt-link :to="`/detail/${item.articleId}.html`">
<el-image
:src="`${item.image}`"
fit="cover"
:lazy="true" class="w-full md:h-[166px] h-[199px] cursor-pointer bg-gray-50"/>
<div class="flex-1 px-4 py-5 sm:p-6 !p-4">
<div class="text-gray-700 dark:text-white text-base font-semibold flex flex-col gap-1.5">
<div class="flex-1 text-xl cursor-pointer flex min-h-[56px]">
<span v-html="replaceKeywords(item.title)"></span>
</div>
</div>
<div class="button-group flex justify-between items-center mt-3 text-sm">
<el-space class="flex items-end">
<div class="text-gray-400 gap-1 flex items-center"><el-icon><View /></el-icon><span>{{ getViews(item) }}</span></div>
</el-space>
<div class="text-gray-400">
{{ dayjs(item.createTime).format('YYYY.MM.DD') }}
</div>
</div>
</div>
</nuxt-link>
</el-card>
</el-col>
</el-row>
<Pagination :total="total" @done="search" :keywords="where.keywords" />
</el-page-header>
</div>
</template>
<script setup lang="ts">
import Banner from "@/components/Banner.vue";
import { ArrowLeft,View,Search } from '@element-plus/icons-vue'
import {useConfigInfo, useLayout, usePage} from "~/composables/configState";
import type {CmsArticle, CmsArticleParam} from "~/api/cms/cmsArticle/model";
import dayjs from "dayjs";
import {getViews} from "~/utils/common";
import {pageCmsArticle} from "~/api/cms/cmsArticle";
import {FILE_SERVER} from "~/config";
import {pageCmsArticleContent} from "~/api/cms/cmsArticleContent";
const route = useRoute();
const router = useRouter();
// 页面信息
const list = ref<CmsArticle[]>([]);
const i18n = useI18n();
const total = ref(0);
// 获取状态
const page = usePage();
const layout = useLayout();
const config = useConfigInfo()
// 搜索表单
const where = reactive<CmsArticleParam>({
keywords: undefined,
page: 1,
limit: 12,
// status: 0,
// parentId: undefined,
// categoryId: undefined,
// lang: i18n.locale.value
});
// 加载页面数据
const reload = async () => {
list.value = [];
pageCmsArticleContent(where).then(response => {
list.value = response?.list || [];
total.value = response?.count || 0;
})
// 设置页面标题
useSeoMeta({
description: `${where.keywords || route.params.keywords}`,
keywords: `${where.keywords || route.params.keywords}`,
titleTemplate: `【搜索结果】${where.keywords || route.params.keywords}` + ' - %s',
})
}
/**
* 搜索
* @param data
*/
const search = (data: CmsArticleParam) => {
where.page = data.page;
reload();
}
const goBack = () => {
router.back(); // 返回上一页
}
const replaceKeywords = (text: any) => {
if(where.keywords){
return text.replace(`${where.keywords}`,'<font color=#ff0000>' + where.keywords + '</font>');
}
}
watch(
() => route.params.keywords,
(keywords) => {
if(keywords){
where.keywords = String(keywords);
}
if(where.keywords == '关键词不能为空!'){
where.keywords = undefined;
}
reload();
},
{ immediate: true }
);
</script>
<style scoped lang="less">
</style>