文件
fenleixinxi/uniapp/pages/search/index.vue
linda 376a7ed793 feat(uniapp): 小程序端(用户端 uni-app)源码入库到 uniapp/ 目录
需求:小程序端代码要同时同步到服务器与 git 远程仓库,此前前端仅存在于本地目录(无 remote,从未推送),
服务器与 gitcode 上只有后端。现并入本仓库,复用现有「push 即部署」链路,一次推送双端落地。

- 新增 uniapp/:小程序端源码全量快照(150 文件 / 1.2M)
  pages(13 页面) · components(fc-navbar/fc-tabbar/fc-post-card/fc-empty) ·
  common(api·utils·mock·assets·store·config) · static(74 图标 + 3 轮播插画 + LOGO) ·
  docs(01-04 交付文档) · tests(零依赖全链路用例) · tools(图标/主题/轮播配图生成脚本)
- 明确排除:AGENTS.md(含后台密码、服务器 root 密码、小程序 AppSecret,切勿入库)、
  unpackage/(构建产物,由 uniapp/.gitignore 忽略)、node_modules、.DS_Store、*.log
- .gitignore 新增 /uniapp/AGENTS.md 兜底(与根 /AGENTS.md、/fluniapp/ 同一约定)
- README.md 增补「本项目结构 + 部署链路」章节,说明 uniapp/ 为源码快照、
  小程序真正上线仍需微信开发者工具 cli upload

说明:本次为源码快照,未携带前端本地仓库历史——其历史提交中含 AGENTS.md 凭据,
若做 subtree 合并会把密码永久写入本仓库历史,故采用快照方式。
2026-10-17 14:19:03 +08:00

208 行
5.1 KiB
Vue

<template>
<view class="search fc-page">
<!-- 搜索框 -->
<view class="search__bar">
<view class="search__box">
<image class="fc-icon fc-icon--sm" :src="iconUrl('search')" mode="aspectFit" />
<input v-model="keyword" class="search__input" confirm-type="search" placeholder="搜索招聘、租房、二手…"
placeholder-class="search__ph" @confirm="doSearch" focus />
<image v-if="keyword" class="fc-icon fc-icon--sm" :src="iconUrl('close')" mode="aspectFit"
@click="keyword = ''" />
</view>
<text class="search__cancel" @click="doSearch">搜索</text>
</view>
<!-- 历史记录 -->
<view v-if="!searched" class="search__block">
<view class="search__block-head">
<text class="search__block-title">搜索历史</text>
<text class="search__block-clear" @click="clearHistory">清空</text>
</view>
<view class="search__chips">
<text v-for="(h, i) in history" :key="i" class="search__chip" @click="pickKeyword(h)">{{ h }}</text>
<text v-if="!history.length" class="search__empty-tip">暂无搜索历史</text>
</view>
<view class="search__block-head search__block-head--mt">
<view class="fc-inline">
<image class="fc-icon fc-icon--sm" :src="iconUrl('fire')" mode="aspectFit" />
<text class="search__block-title fc-inline__text">热门搜索</text>
</view>
</view>
<view class="search__chips">
<text v-for="(h, i) in hotKeywords" :key="i" class="search__chip search__chip--hot"
:class="{ 'search__chip--top': i < 3 }" @click="pickKeyword(h)">{{ h }}</text>
</view>
</view>
<!-- 搜索结果 -->
<view v-else class="search__result">
<view class="search__result-head">
<text>共找到 {{ total }} 条「{{ lastKeyword }}」相关信息</text>
</view>
<fc-empty v-if="!list.length" text="没有找到相关信息,换个关键词试试" />
<view v-else>
<fc-post-card v-for="p in list" :key="p.id" :post="p" @click="goDetail" />
</view>
</view>
</view>
</template>
<script>
import FcPostCard from '@/components/fc-post-card/fc-post-card.vue'
import FcEmpty from '@/components/fc-empty/fc-empty.vue'
import homeApi from '@/common/api/home.js'
import storage from '@/common/utils/storage.js'
import config from '@/common/config/index.js'
import { iconUrl } from '@/common/store/ui.js'
export default {
components: { FcPostCard, FcEmpty },
data() {
return {
keyword: '',
lastKeyword: '',
searched: false,
list: [],
total: 0,
history: [],
hotKeywords: [],
}
},
onLoad() {
this.history = storage.get(config.storageKeys.history, []) || []
this.loadHot()
},
methods: {
iconUrl,
async loadHot() {
try {
this.hotKeywords = await homeApi.hotKeywords()
} catch (e) {}
},
pickKeyword(k) {
this.keyword = k
this.doSearch()
},
async doSearch() {
const kw = (this.keyword || '').trim()
if (!kw) {
uni.showToast({ title: '请输入关键词', icon: 'none' })
return
}
this.lastKeyword = kw
this.saveHistory(kw)
try {
const res = await homeApi.feed({ keyword: kw, page: 1, size: 20 })
this.list = res.list
this.total = res.total
this.searched = true
} catch (e) {
uni.showToast({ title: '搜索失败', icon: 'none' })
}
},
saveHistory(kw) {
const list = (this.history || []).filter((x) => x !== kw)
list.unshift(kw)
this.history = list.slice(0, 10)
storage.set(config.storageKeys.history, this.history)
},
clearHistory() {
this.history = []
storage.remove(config.storageKeys.history)
uni.showToast({ title: '已清空', icon: 'none' })
},
goDetail(p) {
uni.navigateTo({ url: `/pages/detail/detail?id=${p.id}` })
},
},
}
</script>
<style lang="scss" scoped>
.search__bar {
display: flex;
align-items: center;
padding: 20rpx 24rpx;
background: #ffffff;
}
.search__box {
flex: 1;
height: 76rpx;
border-radius: $fc-radius-pill;
background: $fc-bg;
display: flex;
align-items: center;
padding: 0 24rpx;
}
.search__input {
flex: 1;
font-size: $fc-font;
margin-left: 12rpx;
}
.search__ph {
color: $fc-text-placeholder;
}
.search__cancel {
margin-left: 24rpx;
font-size: $fc-font;
color: $fc-primary-text;
font-weight: 600;
}
.search__block {
padding: 24rpx;
}
.search__block-head {
display: flex;
align-items: center;
justify-content: space-between;
&--mt {
margin-top: 40rpx;
}
}
.search__block-title {
font-size: $fc-font-lg;
font-weight: 700;
color: $fc-text;
}
.search__block-clear {
font-size: $fc-font-sm;
color: $fc-text-secondary;
}
.search__chips {
display: flex;
flex-wrap: wrap;
margin-top: 20rpx;
}
.search__chip {
padding: 14rpx 28rpx;
margin: 0 16rpx 16rpx 0;
border-radius: $fc-radius-pill;
background: #ffffff;
font-size: $fc-font-sm;
color: $fc-text-regular;
box-shadow: $fc-shadow;
&--hot {
background: $fc-primary-lighter;
color: $fc-primary-text;
}
&--top {
background: $fc-gradient-warm;
color: #ffffff;
}
}
.search__empty-tip {
font-size: $fc-font-sm;
color: $fc-text-placeholder;
}
.search__result {
padding-top: 20rpx;
}
.search__result-head {
padding: 0 24rpx 20rpx;
font-size: $fc-font-sm;
color: $fc-text-secondary;
}
</style>