- 新增地址选择插件,支持地图位置选择并返回地址和经纬度 - 新增微信订阅消息发送功能,支持审核结果、提现通知等场景 - 新增订单支付状态查询、提现收款人姓名保存等接口 - 新增服务区域管理,支持按省市区划分并同步到信息发布 - 新增资金流水和营收报表导出功能 - 新增可用优惠券查询、订单退款拆分处理等功能 - 优化后台角标显示、首页数据统计、UI配置下发等 - 修复订单支付并发问题、地区管理逻辑等
543 行
13 KiB
Vue
543 行
13 KiB
Vue
<template>
|
||
<view class="cat-page fc-page">
|
||
<!-- 规范化统一全绿顶部导航栏:与通知中心统一全绿质感与居中标题 -->
|
||
<fc-navbar title="全部分类" theme="gradient" />
|
||
|
||
<!-- 顶栏通栏直接搜索:在当前分类内直接检索,无需跳转任何页面 -->
|
||
<view class="cat-search-bar">
|
||
<view class="cat-search-bar__inner">
|
||
<image class="fc-icon fc-icon--sm" :src="iconUrl('search')" mode="aspectFit" />
|
||
<input
|
||
v-model="keyword"
|
||
class="cat-search-bar__input"
|
||
:placeholder="searchPlaceholder"
|
||
placeholder-class="cat-search-bar__ph"
|
||
confirm-type="search"
|
||
@confirm="handleSearch"
|
||
/>
|
||
<view v-if="keyword" class="cat-search-bar__clear" @click="handleClear">
|
||
<text class="cat-search-bar__clear-txt">×</text>
|
||
</view>
|
||
</view>
|
||
<view class="cat-search-bar__btn" @click="handleSearch">
|
||
<text class="cat-search-bar__btn-txt">搜索</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 经典双联主体区域 -->
|
||
<view class="cat-main">
|
||
<!-- 左侧一级分类垂直菜单 -->
|
||
<scroll-view class="cat-sidebar" scroll-y :show-scrollbar="false">
|
||
<view
|
||
v-for="c in categories"
|
||
:key="c.id"
|
||
class="cat-sidebar__item"
|
||
:class="{ 'cat-sidebar__item--active': currentCategory && currentCategory.id === c.id }"
|
||
@click="selectCategory(c)"
|
||
>
|
||
<view v-if="currentCategory && currentCategory.id === c.id" class="cat-sidebar__bar"></view>
|
||
<image class="cat-sidebar__icon" :src="catIcon(c)" mode="aspectFit" />
|
||
<text class="cat-sidebar__name">{{ c.name }}</text>
|
||
</view>
|
||
</scroll-view>
|
||
|
||
<!-- 右侧内容区域(排序 + 信息流) -->
|
||
<scroll-view
|
||
class="cat-content"
|
||
scroll-y
|
||
:show-scrollbar="false"
|
||
@scrolltolower="loadMore"
|
||
>
|
||
<!-- 快捷排序选项 -->
|
||
<view class="cat-sort">
|
||
<view
|
||
v-for="s in sortOptions"
|
||
:key="s.value"
|
||
class="cat-sort__item"
|
||
:class="{ 'cat-sort__item--active': sort === s.value }"
|
||
@click="changeSort(s.value)"
|
||
>
|
||
{{ s.label }}
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 信息流列表:使用 compact 紧凑模式,适配窄容器,杜绝任何文字折行 -->
|
||
<view v-if="list.length" class="cat-list">
|
||
<fc-post-card
|
||
v-for="item in list"
|
||
:key="item.id"
|
||
:post="item"
|
||
:compact="true"
|
||
@click="goDetail"
|
||
/>
|
||
<view v-if="loading" class="cat-loading">正在加载中...</view>
|
||
<view v-else-if="!hasMore" class="cat-nomore">— 没有更多信息了 —</view>
|
||
</view>
|
||
|
||
<!-- 空状态 -->
|
||
<view v-else-if="!loading" class="cat-empty-wrap">
|
||
<template v-if="keyword && keyword.trim()">
|
||
<fc-empty icon="search" :text="'在当前分类未找到「' + keyword + '」相关信息'" />
|
||
<button class="cat-empty-btn" @click="handleClear">清空搜索条件</button>
|
||
</template>
|
||
<template v-else>
|
||
<fc-empty icon="inbox" text="该分类下暂无信息,快来抢先发布吧!" />
|
||
<button class="cat-empty-btn" @click="goPublish">立即发布此分类</button>
|
||
</template>
|
||
</view>
|
||
|
||
<!-- 底部留白防止遮挡 -->
|
||
<view class="cat-content__space"></view>
|
||
</scroll-view>
|
||
</view>
|
||
|
||
<!-- 底部 Tabbar(当前选中索引为 1) -->
|
||
<fc-tabbar :current="1" />
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import FcNavbar from '@/components/fc-navbar/fc-navbar.vue'
|
||
import FcTabbar from '@/components/fc-tabbar/fc-tabbar.vue'
|
||
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 { iconUrl, categoryIconUrl, catIcon, loadUiConfig } from '@/common/store/ui.js'
|
||
import { getNavMetrics } from '@/common/utils/navbar.js'
|
||
|
||
export default {
|
||
components: { FcNavbar, FcTabbar, FcPostCard, FcEmpty },
|
||
data() {
|
||
return {
|
||
statusBarHeight: 0,
|
||
navBarHeight: 44,
|
||
capsulePadding: 0,
|
||
keyword: '',
|
||
categories: [],
|
||
currentCategory: null,
|
||
sort: 'new',
|
||
sortOptions: [
|
||
{ label: '最新', value: 'new' },
|
||
{ label: '最热', value: 'hot' },
|
||
{ label: '附近', value: 'nearby' },
|
||
{ label: '价格', value: 'price' },
|
||
],
|
||
list: [],
|
||
page: 1,
|
||
size: 10,
|
||
total: 0,
|
||
hasMore: true,
|
||
loading: false,
|
||
// 请求序号:切换分类/排序/搜索时丢弃过期响应,避免「点了筛选但列表没变」
|
||
reqSeq: 0,
|
||
lat: null,
|
||
lng: null,
|
||
}
|
||
},
|
||
computed: {
|
||
/**
|
||
* 输入框占位文案,动态根据当前选中分类切换
|
||
*/
|
||
searchPlaceholder() {
|
||
const name = this.currentCategory ? this.currentCategory.name : '本地'
|
||
return '在“' + name + '”中搜索…'
|
||
},
|
||
},
|
||
onShow() {
|
||
loadUiConfig(true)
|
||
},
|
||
onLoad(options) {
|
||
this.initMetrics()
|
||
this.initLocation()
|
||
this.fetchCategories(options && options.categoryId)
|
||
},
|
||
methods: {
|
||
/** 暴露给模板:全功能分类图标解析(支持后台无上限扩展) */
|
||
catIcon,
|
||
/** 暴露给模板:图标地址解析 */
|
||
iconUrl,
|
||
/** 暴露给模板:分类图标解析 */
|
||
categoryIconUrl,
|
||
/**
|
||
* 初始化设备导航栏与胶囊避让度量
|
||
*/
|
||
initMetrics() {
|
||
const m = getNavMetrics()
|
||
this.statusBarHeight = m.statusBarHeight
|
||
this.navBarHeight = m.navBarHeight
|
||
this.capsulePadding = m.capsulePadding
|
||
},
|
||
/**
|
||
* 初始化获取当前用户定位坐标(用于“附近”距离计算与排序)
|
||
*/
|
||
initLocation() {
|
||
uni.getLocation({
|
||
type: 'gcj02',
|
||
success: (res) => {
|
||
this.lat = res.latitude
|
||
this.lng = res.longitude
|
||
// 定位晚于「附近」点击返回时,坐标到手后重排一次
|
||
if (this.sort === 'nearby' && this.currentCategory) {
|
||
this.page = 1
|
||
this.list = []
|
||
this.hasMore = true
|
||
this.fetchPosts()
|
||
}
|
||
},
|
||
fail: () => {},
|
||
})
|
||
},
|
||
/**
|
||
* 拉取全部分类数据
|
||
* @param {string|number} defaultCatId 默认选中的分类 ID
|
||
*/
|
||
async fetchCategories(defaultCatId) {
|
||
try {
|
||
const cats = await homeApi.categories()
|
||
this.categories = Array.isArray(cats) ? cats : []
|
||
if (this.categories.length) {
|
||
const target = defaultCatId
|
||
? this.categories.find((c) => String(c.id) === String(defaultCatId))
|
||
: null
|
||
this.selectCategory(target || this.categories[0])
|
||
}
|
||
} catch (e) {
|
||
uni.showToast({ title: '分类加载失败', icon: 'none' })
|
||
}
|
||
},
|
||
/**
|
||
* 切换当前选中的左侧分类
|
||
* @param {Object} cat 选中的分类对象
|
||
*/
|
||
selectCategory(cat) {
|
||
if (!cat || (this.currentCategory && this.currentCategory.id === cat.id)) return
|
||
this.currentCategory = cat
|
||
this.page = 1
|
||
this.list = []
|
||
this.hasMore = true
|
||
this.fetchPosts()
|
||
},
|
||
/**
|
||
* 切换排序规则
|
||
* @param {string} s 排序值 new|hot|nearby|price
|
||
*/
|
||
changeSort(s) {
|
||
if (this.sort === s) return
|
||
this.sort = s
|
||
this.page = 1
|
||
this.list = []
|
||
this.hasMore = true
|
||
this.fetchPosts()
|
||
// 「附近」依赖坐标:无坐标时补取一次定位(成功后自动重排)
|
||
if (s === 'nearby' && (!this.lat || !this.lng)) {
|
||
uni.showToast({ title: '正在获取定位…', icon: 'none' })
|
||
this.initLocation()
|
||
}
|
||
},
|
||
/**
|
||
* 获取当前分类下的信息列表(支持关键字在当前页面直接检索)
|
||
*/
|
||
async fetchPosts() {
|
||
if (!this.currentCategory) return
|
||
const seq = ++this.reqSeq
|
||
this.loading = true
|
||
try {
|
||
const params = {
|
||
categoryId: this.currentCategory.id,
|
||
sort: this.sort,
|
||
page: this.page,
|
||
size: this.size,
|
||
}
|
||
if (this.keyword && this.keyword.trim()) {
|
||
params.keyword = this.keyword.trim()
|
||
}
|
||
if (this.lat && this.lng) {
|
||
params.lat = this.lat
|
||
params.lng = this.lng
|
||
}
|
||
const res = await homeApi.feed(params)
|
||
// 期间又切换了分类/排序/搜索:以最后一次请求为准
|
||
if (seq !== this.reqSeq) return
|
||
const rows = (res && res.list) || []
|
||
this.list = this.page === 1 ? rows : this.list.concat(rows)
|
||
this.total = (res && res.total) || 0
|
||
this.hasMore = res ? !!res.hasMore : false
|
||
} catch (e) {
|
||
if (seq !== this.reqSeq) return
|
||
uni.showToast({ title: '加载信息失败', icon: 'none' })
|
||
} finally {
|
||
if (seq === this.reqSeq) this.loading = false
|
||
}
|
||
},
|
||
/**
|
||
* 触底加载下一页数据
|
||
*/
|
||
loadMore() {
|
||
if (this.hasMore && !this.loading) {
|
||
this.page += 1
|
||
this.fetchPosts()
|
||
}
|
||
},
|
||
/**
|
||
* 在当前页面直接执行搜索
|
||
*/
|
||
handleSearch() {
|
||
this.page = 1
|
||
this.list = []
|
||
this.hasMore = true
|
||
this.fetchPosts()
|
||
},
|
||
/**
|
||
* 清空搜索关键词并在当前分类下重置列表
|
||
*/
|
||
handleClear() {
|
||
this.keyword = ''
|
||
this.handleSearch()
|
||
},
|
||
/**
|
||
* 跳转到当前分类的发布页
|
||
*/
|
||
goPublish() {
|
||
const catId = this.currentCategory ? this.currentCategory.id : ''
|
||
uni.navigateTo({ url: `/pages/post/create?categoryId=${catId}` })
|
||
},
|
||
/**
|
||
* 查看信息详情
|
||
* @param {Object} post 点击的信息项
|
||
*/
|
||
goDetail(post) {
|
||
if (post && post.id) {
|
||
uni.navigateTo({ url: `/pages/detail/detail?id=${post.id}` })
|
||
}
|
||
},
|
||
},
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.cat-page {
|
||
height: 100vh;
|
||
display: flex;
|
||
flex-direction: column;
|
||
background: $fc-bg;
|
||
overflow: hidden;
|
||
}
|
||
|
||
/* 顶栏通栏直接搜索:整齐大方、不换行、直接当前页过滤 */
|
||
.cat-search-bar {
|
||
background: #ffffff;
|
||
padding: 16rpx 24rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16rpx;
|
||
border-bottom: 1rpx solid rgba(4, 48, 30, 0.05);
|
||
box-shadow: 0 4rpx 14rpx rgba(4, 48, 30, 0.03);
|
||
flex-shrink: 0;
|
||
z-index: 10;
|
||
}
|
||
.cat-search-bar__inner {
|
||
flex: 1;
|
||
height: 72rpx;
|
||
border-radius: 999rpx;
|
||
background: #f2fef7;
|
||
border: 1rpx solid rgba(0, 224, 112, 0.28);
|
||
display: flex;
|
||
align-items: center;
|
||
padding: 0 20rpx;
|
||
gap: 12rpx;
|
||
box-sizing: border-box;
|
||
transition: all 0.2s ease;
|
||
&:focus-within {
|
||
background: #ffffff;
|
||
border-color: #00c860;
|
||
box-shadow: 0 0 12rpx rgba(0, 200, 96, 0.15);
|
||
}
|
||
}
|
||
.cat-search-bar__input {
|
||
flex: 1;
|
||
height: 100%;
|
||
font-size: 26rpx;
|
||
color: $fc-text;
|
||
}
|
||
.cat-search-bar__ph {
|
||
font-size: 25rpx;
|
||
color: $fc-text-placeholder;
|
||
}
|
||
.cat-search-bar__clear {
|
||
width: 36rpx;
|
||
height: 36rpx;
|
||
border-radius: 50%;
|
||
background: rgba(4, 48, 30, 0.15);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
flex-shrink: 0;
|
||
}
|
||
.cat-search-bar__clear-txt {
|
||
font-size: 22rpx;
|
||
color: #ffffff;
|
||
line-height: 1;
|
||
margin-top: -2rpx;
|
||
}
|
||
.cat-search-bar__btn {
|
||
height: 72rpx;
|
||
padding: 0 32rpx;
|
||
border-radius: 999rpx;
|
||
background: $fc-gradient-primary;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
cursor: pointer;
|
||
box-shadow: 0 4rpx 14rpx rgba(0, 224, 112, 0.3);
|
||
flex-shrink: 0;
|
||
transition: transform 0.15s ease;
|
||
&:active {
|
||
transform: scale(0.96);
|
||
opacity: 0.9;
|
||
}
|
||
}
|
||
.cat-search-bar__btn-txt {
|
||
font-size: 26rpx;
|
||
font-weight: 700;
|
||
color: $fc-primary-ink;
|
||
}
|
||
|
||
/* 双联主体容器 */
|
||
.cat-main {
|
||
flex: 1;
|
||
display: flex;
|
||
min-height: 0; /* 必须,确保内部滚动条生效 */
|
||
}
|
||
|
||
/* 左侧分类栏:图标与标签左右水平排列,扩充宽度彻底杜绝 4 字分类名截断 */
|
||
.cat-sidebar {
|
||
width: 204rpx;
|
||
height: 100%;
|
||
background: #f6f8fa;
|
||
flex-shrink: 0;
|
||
border-right: 1rpx solid rgba(0, 0, 0, 0.05);
|
||
}
|
||
.cat-sidebar__item {
|
||
cursor: pointer;
|
||
position: relative;
|
||
height: 96rpx;
|
||
display: flex;
|
||
flex-direction: row;
|
||
align-items: center;
|
||
padding: 0 10rpx 0 18rpx;
|
||
box-sizing: border-box;
|
||
gap: 10rpx;
|
||
color: $fc-text-secondary;
|
||
font-size: 24rpx;
|
||
transition: all 0.15s ease;
|
||
border-bottom: 1rpx solid rgba(0, 0, 0, 0.02);
|
||
|
||
&--active {
|
||
background: #ffffff;
|
||
color: $fc-primary-text;
|
||
font-weight: 700;
|
||
|
||
.cat-sidebar__icon {
|
||
opacity: 1;
|
||
transform: scale(1.06);
|
||
}
|
||
}
|
||
}
|
||
.cat-sidebar__bar {
|
||
position: absolute;
|
||
left: 0;
|
||
top: 24rpx;
|
||
bottom: 24rpx;
|
||
width: 6rpx;
|
||
border-radius: 0 4rpx 4rpx 0;
|
||
background: $fc-primary;
|
||
}
|
||
.cat-sidebar__icon {
|
||
width: 34rpx;
|
||
height: 34rpx;
|
||
flex-shrink: 0;
|
||
opacity: 0.8;
|
||
transition: transform 0.15s ease, opacity 0.15s ease;
|
||
}
|
||
.cat-sidebar__name {
|
||
flex: 1;
|
||
line-height: 1.25;
|
||
white-space: nowrap;
|
||
text-align: left;
|
||
letter-spacing: -0.2rpx;
|
||
}
|
||
|
||
/* 右侧内容展示区 */
|
||
.cat-content {
|
||
flex: 1;
|
||
height: 100%;
|
||
padding: 14rpx 14rpx 0;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
/* 排序切换:轻巧微胶囊风格 */
|
||
.cat-sort {
|
||
display: flex;
|
||
align-items: center;
|
||
background: #ffffff;
|
||
border-radius: $fc-radius;
|
||
padding: 6rpx 8rpx;
|
||
margin-bottom: 14rpx;
|
||
box-shadow: 0 2rpx 8rpx rgba(4, 48, 30, 0.04);
|
||
}
|
||
.cat-sort__item {
|
||
cursor: pointer;
|
||
flex: 1;
|
||
text-align: center;
|
||
font-size: 23rpx;
|
||
color: $fc-text-secondary;
|
||
padding: 8rpx 0;
|
||
border-radius: 999rpx;
|
||
transition: all 0.15s ease;
|
||
|
||
&--active {
|
||
color: $fc-primary-text;
|
||
font-weight: 700;
|
||
background: $fc-primary-lighter;
|
||
}
|
||
}
|
||
|
||
/* 信息流列表 */
|
||
.cat-list {
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
.cat-loading,
|
||
.cat-nomore {
|
||
text-align: center;
|
||
padding: 24rpx 0;
|
||
font-size: 22rpx;
|
||
color: $fc-text-placeholder;
|
||
}
|
||
|
||
/* 空状态卡片 */
|
||
.cat-empty-wrap {
|
||
padding: 60rpx 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
align-items: center;
|
||
}
|
||
.cat-empty-btn {
|
||
margin-top: 30rpx;
|
||
height: 68rpx;
|
||
line-height: 68rpx;
|
||
padding: 0 44rpx;
|
||
background: $fc-gradient-primary;
|
||
color: $fc-primary-ink;
|
||
font-size: 26rpx;
|
||
font-weight: 700;
|
||
border-radius: 34rpx;
|
||
box-shadow: 0 6rpx 18rpx rgba(0, 224, 112, 0.4);
|
||
}
|
||
|
||
.cat-content__space {
|
||
height: 140rpx;
|
||
}
|
||
</style>
|