文件
yjyf/yjyf-app/pages/category/category.vue
MiAn 14533eadb7 feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制
1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
2026-11-23 15:10:30 +08:00

557 行
14 KiB
Vue

<template>
<view class="cat-page">
<view class="hero-header">
<YjyfNavBar
theme="orange"
title="全部分类"
:fixed="true"
:placeholder="true"
/>
<view class="search-box-wrap">
<view class="search-box">
<input
class="search-input"
v-model="keyword"
type="text"
placeholder="桌子 / 马桶 / 门锁 / 水龙头"
placeholder-class="search-placeholder"
confirm-type="search"
@confirm="onSearch"
/>
<view class="search-clear-btn clickable-hover" v-if="keyword" @tap="clearKeyword">
<image class="clear-ico" src="/static/icons/input-clear.svg" mode="aspectFit" />
</view>
<view class="search-action-btn clickable-hover" @tap="onSearch">
<image class="search-btn-icon" src="/static/icons/search.svg" mode="aspectFit" />
<text class="search-btn-txt">搜索</text>
</view>
</view>
</view>
</view>
<view class="cat-card-body">
<view class="search-tip-bar" v-if="keyword.trim()">
<text class="st-text">
匹配到 {{ displayCats.length }} 个类目、{{ matchedServices.length }} 项具体服务
</text>
<text class="st-reset clickable-hover" @tap="clearKeyword">重置</text>
</view>
<view class="cat-grid" v-if="displayCats.length > 0">
<view
class="cat-item clickable-hover"
v-for="item in displayCats"
:key="item.id"
@tap="selectCategory(item)"
>
<view class="cat-icon-wrap">
<image class="cat-icon-img" :src="item.icon_url" mode="aspectFit" v-if="item.icon_url" />
</view>
<text class="cat-name">{{ item.name }}</text>
</view>
</view>
<view class="srv-section" v-if="keyword.trim() && matchedServices.length > 0">
<text class="srv-sec-title" v-if="displayCats.length > 0">匹配服务项目</text>
<view
class="srv-row clickable-hover"
v-for="srv in matchedServices"
:key="srv.id"
@tap="onSelectMatchedService(srv)"
>
<image class="srv-thumb" :src="srv.image_url || '/static/icons/service-default.svg'" mode="aspectFill" />
<view class="srv-info">
<text class="srv-name">{{ srv.name }}</text>
<text class="srv-sub">{{ srv.cat_name || '标准上门服务' }} · {{ srv.price_type_text || '明码标价' }}</text>
</view>
<view class="srv-right">
<text class="srv-price">{{ srv.price_text }}</text>
<view class="srv-go">选规格</view>
</view>
</view>
</view>
<view class="empty-state" v-if="keyword.trim() && !searching && displayCats.length === 0 && matchedServices.length === 0">
<image class="empty-icon-img" src="/static/icons/empty-service.svg" mode="aspectFit" />
<text class="empty-title">未匹配到“{{ keyword.trim() }}”相关服务</text>
<text class="empty-desc">可直接发布自定义需求,由师傅在线评估报价</text>
<view class="custom-publish-btn clickable-hover" @tap="goCustomOrder">
<text class="btn-txt">发布自定义需求</text>
</view>
</view>
<view class="body-bottom-space"></view>
</view>
<GoodsPickerDrawer
:visible="showDrawer"
:cat-id="currentDrawerCatId"
:cat-name="currentDrawerCatName"
@update:visible="showDrawer = $event"
@select="onSpecSelected"
@custom="goCustomOrder"
/>
<YjyfTabBar :current="'order'" :standalone="true" />
</view>
</template>
<script setup>
import { ref, computed, watch } from 'vue';
import { onLoad, onShow } from '@dcloudio/uni-app';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import YjyfTabBar from '@/components/YjyfTabBar.vue';
import GoodsPickerDrawer from '@/components/GoodsPickerDrawer.vue';
import api from '@/utils/api.js';
import { useShare } from '@/utils/share.js';
const keyword = ref('');
const rawCats = ref([]);
const matchedServices = ref([]);
const searching = ref(false);
let searchTimer = null;
useShare(() => {
const catId = currentDrawerCatId.value;
const catName = currentDrawerCatName.value;
if (showDrawer.value && catId && catName) {
return {
title: `优匠优服 · ${catName}上门安装维修`,
path: `/pages/category/category?cat_id=${catId}`,
query: { cat_id: catId }
};
}
return {
title: '优匠优服 · 全品类家居安装与维修服务',
path: '/pages/category/category',
query: ''
};
});
const allCats = computed(() => {
return (rawCats.value || []).map(c => {
const cid = Number(c.id);
const name = (c.name || '').trim();
if (cid === 15 || name === '全部分类' || name === '其它' || name === '其他') {
return {
...c,
id: 15,
name: '其它',
is_other: true
};
}
return {
...c,
id: cid
};
});
});
const displayCats = computed(() => {
const kw = keyword.value.trim().toLowerCase();
if (!kw) return allCats.value;
return allCats.value.filter(c => c.name.toLowerCase().includes(kw));
});
const showDrawer = ref(false);
const currentDrawerCatId = ref(0);
const currentDrawerCatName = ref('');
async function queryServicesByKeyword(kw) {
if (!kw) {
matchedServices.value = [];
searching.value = false;
return;
}
searching.value = true;
try {
const res = await api.services({ keyword: kw }, { silent: true });
if (keyword.value.trim() === kw) {
matchedServices.value = (res && res.list) ? res.list : [];
}
} catch (e) {
matchedServices.value = [];
} finally {
searching.value = false;
}
}
watch(keyword, (val) => {
if (searchTimer) clearTimeout(searchTimer);
const kw = (val || '').trim();
if (!kw) {
matchedServices.value = [];
searching.value = false;
return;
}
searching.value = true;
searchTimer = setTimeout(() => {
queryServicesByKeyword(kw);
}, 260);
});
function selectCategory(cat) {
if (cat.is_other || cat.id === 15 || cat.name === '其它' || cat.name === '其他') {
goCustomOrder();
return;
}
currentDrawerCatId.value = cat.id;
currentDrawerCatName.value = cat.name;
showDrawer.value = true;
}
function onSelectMatchedService(srv) {
const catId = Number(srv.cat_id || 0);
if (catId) {
const hit = allCats.value.find(c => Number(c.id) === catId);
currentDrawerCatId.value = catId;
currentDrawerCatName.value = srv.cat_name || (hit ? hit.name : '服务规格');
showDrawer.value = true;
return;
}
uni.navigateTo({ url: '/pages/service/detail?id=' + srv.id });
}
function onSpecSelected(spec) {
showDrawer.value = false;
const rawAddons = spec.addons && spec.addons.length ? spec.addons : [];
const extras = rawAddons.map(ad => ({
id: ad.id,
key: 'addon_' + ad.id,
name: ad.name,
unit: ad.unit || '个',
price: Number(ad.price) || 0,
num: 0
}));
const hitCat = allCats.value.find(c => c.id === (spec.cat_id || currentDrawerCatId.value)) || null;
const firstGoods = {
service_id: spec.service_id,
item_name: spec.item_name,
spec_id: spec.spec_id || 0,
spec_name: spec.spec_name,
cat_id: spec.cat_id || currentDrawerCatId.value,
cat_name: spec.cat_name || currentDrawerCatName.value,
cat_icon_url: hitCat ? hitCat.icon_url : '',
unit: spec.unit || '件',
base_price: Number(spec.base_price) || 0,
num: 1,
service_type: spec.default_service_type || 'install',
service_type_name: spec.default_service_name || '安装',
service_types: spec.service_types || [],
images: [],
extras: extras
};
uni.setStorageSync('yjyf_first_goods', firstGoods);
try {
const pages = getCurrentPages();
if (pages && pages.length > 1 && pages[pages.length - 2].route.includes('order/quick')) {
uni.navigateBack();
return;
}
} catch (e) {}
uni.navigateTo({ url: '/pages/order/quick' });
}
function goCustomOrder() {
showDrawer.value = false;
uni.navigateTo({
url: `/pages/order/quick?cat_id=15&cat_name=${encodeURIComponent('其它')}&custom=1&mode=quote`
});
}
function clearKeyword() {
keyword.value = '';
matchedServices.value = [];
}
function onSearch() {
const kw = keyword.value.trim();
if (!kw) return;
if (searchTimer) clearTimeout(searchTimer);
uni.navigateTo({ url: '/pages/service/list?keyword=' + encodeURIComponent(kw) });
}
async function loadServerCats(targetCatId) {
try {
const res = await api.cats();
if (res && res.list && res.list.length > 0) {
rawCats.value = res.list;
if (targetCatId) {
const hit = allCats.value.find(c => c.id === targetCatId);
if (hit) selectCategory(hit);
}
}
} catch (e) {}
}
onLoad((query) => {
const targetCatId = query && query.cat_id ? parseInt(query.cat_id) : 0;
if (query && query.keyword) {
keyword.value = decodeURIComponent(query.keyword);
}
loadServerCats(targetCatId);
});
onShow(() => {});
</script>
<style lang="scss" scoped>
@import '@/uni.scss';
.cat-page {
min-height: 100vh;
background: $yjyf-bg-page;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
.hero-header {
background: $yjyf-gradient-primary;
padding-bottom: $yjyf-space-md;
box-sizing: border-box;
}
.search-box-wrap {
padding: 0 $yjyf-space-md;
margin-top: $yjyf-space-xs;
box-sizing: border-box;
}
.search-box {
height: 76rpx;
background: $yjyf-bg-card;
border-radius: $yjyf-radius-pill;
display: flex;
align-items: center;
padding: 0 8rpx 0 28rpx;
box-shadow: 0 6rpx 20rpx rgba(180, 50, 0, 0.12);
box-sizing: border-box;
}
.search-input {
flex: 1;
font-size: $yjyf-font-body;
color: $yjyf-text-main;
}
.search-placeholder {
font-size: $yjyf-font-body;
color: $yjyf-text-disabled;
}
.search-clear-btn {
width: 52rpx;
height: 52rpx;
display: flex;
align-items: center;
justify-content: center;
}
.clear-ico {
width: 30rpx;
height: 30rpx;
}
.search-action-btn {
height: 60rpx;
padding: 0 28rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.search-btn-icon {
width: 24rpx;
height: 24rpx;
margin-right: 6rpx;
}
.search-btn-txt {
font-size: $yjyf-font-sub;
font-weight: 700;
color: $yjyf-text-inverse;
line-height: 1;
}
.cat-card-body {
flex: 1;
background: $yjyf-bg-card;
border-top-left-radius: $yjyf-radius-lg;
border-top-right-radius: $yjyf-radius-lg;
padding: $yjyf-space-lg $yjyf-space-sm 20rpx;
box-sizing: border-box;
min-height: calc(100vh - 200rpx);
}
.search-tip-bar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 $yjyf-space-sm 20rpx;
border-bottom: 1rpx solid $yjyf-border-color;
margin-bottom: 20rpx;
}
.st-text {
font-size: $yjyf-font-sub;
color: $yjyf-text-secondary;
}
.st-reset {
font-size: $yjyf-font-sub;
color: $yjyf-primary;
font-weight: 600;
}
.cat-grid {
display: flex;
flex-wrap: wrap;
width: 100%;
box-sizing: border-box;
}
.cat-item {
width: 20%;
display: flex;
flex-direction: column;
align-items: center;
padding: 16rpx 0 20rpx;
box-sizing: border-box;
transition: transform 0.15s ease;
}
.cat-item:active {
transform: scale(0.92);
}
.cat-icon-wrap {
width: 92rpx;
height: 92rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: $yjyf-bg-page;
border: 1rpx solid $yjyf-border-color;
margin-bottom: 12rpx;
box-sizing: border-box;
}
.cat-icon-img {
width: 60rpx;
height: 60rpx;
}
.cat-name {
font-size: $yjyf-font-sub;
color: $yjyf-text-main;
font-weight: 600;
text-align: center;
white-space: nowrap;
}
.srv-section {
padding: 12rpx $yjyf-space-xs 0;
}
.srv-sec-title {
display: block;
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-text-main;
margin: 12rpx 0 16rpx;
}
.srv-row {
display: flex;
align-items: center;
padding: 20rpx;
margin-bottom: 16rpx;
border-radius: $yjyf-radius-md;
background: $yjyf-bg-page;
}
.srv-thumb {
width: 88rpx;
height: 88rpx;
border-radius: $yjyf-radius-sm;
background: $yjyf-primary-bg;
flex-shrink: 0;
}
.srv-info {
flex: 1;
min-width: 0;
margin-left: 20rpx;
display: flex;
flex-direction: column;
}
.srv-name {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-text-main;
}
.srv-sub {
margin-top: 6rpx;
font-size: $yjyf-font-micro;
color: $yjyf-text-secondary;
}
.srv-right {
display: flex;
flex-direction: column;
align-items: flex-end;
flex-shrink: 0;
margin-left: 16rpx;
}
.srv-price {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-primary;
}
.srv-go {
margin-top: 8rpx;
height: 48rpx;
padding: 0 22rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
color: $yjyf-text-inverse;
font-size: $yjyf-font-micro;
font-weight: 600;
display: inline-flex;
align-items: center;
justify-content: center;
}
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 120rpx 40rpx;
}
.empty-icon-img {
width: 160rpx;
height: 160rpx;
margin-bottom: $yjyf-space-md;
}
.empty-title {
font-size: 30rpx;
font-weight: 700;
color: $yjyf-text-main;
margin-bottom: 12rpx;
}
.empty-desc {
font-size: $yjyf-font-sub;
color: $yjyf-text-secondary;
text-align: center;
margin-bottom: 36rpx;
line-height: 1.5;
}
.custom-publish-btn {
height: 76rpx;
padding: 0 48rpx;
border-radius: $yjyf-radius-pill;
background: $yjyf-gradient-primary;
display: flex;
align-items: center;
justify-content: center;
box-shadow: $yjyf-shadow-button;
}
.btn-txt {
font-size: $yjyf-font-body;
font-weight: 700;
color: $yjyf-text-inverse;
line-height: 1;
}
.body-bottom-space {
height: 200rpx;
}
</style>