feat(admin): 新增师傅大厅筛选功能及表格布局组件

- 新增服务品类和服务类型筛选选项
- 新增订单距离筛选功能
- 新增admin-table-layout组件实现表格操作列固定
- 重构后台表格列布局,优化显示效果
- 新增位置相关工具函数及测试用例
- 升级版本号至1.0.89
这个提交包含在:
2026-11-19 14:39:28 +08:00
父节点 a608ef6506
当前提交 c37739656c
共有 50 个文件被更改,包括 572 次插入 和 405 次删除

查看文件

@@ -35,10 +35,9 @@
</view>
<view class="sort-bar">
<scroll-view class="sort-tabs-scroll" scroll-x="true" :show-scrollbar="false">
<view class="sort-tabs-inner">
<view class="sort-tabs-inner">
<view
v-for="s in sortTabs"
v-for="s in sortTabs.slice(0, 3)"
:key="s.key"
class="s-tab clickable-hover"
:class="{ on: sort === s.key }"
@@ -46,32 +45,26 @@
>
<text class="s-tab-txt">{{ s.name }}</text>
</view>
</view>
</scroll-view>
<view class="refresh-pill clickable-hover" @tap="manualRefresh">
<image
class="refresh-ico"
:class="{ spinning: loading }"
src="/static/icons/master/hall-refresh.svg"
mode="aspectFit"
/>
<text class="refresh-txt">刷新</text>
</view>
<view class="filter-trigger clickable-hover" :class="{ active: activeFilterChips.length }" @tap="openFilters">
<image class="filter-icon" src="/static/icons/filter-orange.svg" mode="aspectFit" />
<text>筛选{{ activeFilterChips.length ? '(' + activeFilterChips.length + ')' : '' }}</text>
</view>
</view>
<view class="active-filters" v-if="activeFilterChips.length">
<view class="active-filter" v-for="chip in activeFilterChips" :key="chip.key" @tap="clearFilter(chip.key)">
<text>{{ chip.label }}</text>
<image class="active-filter-close" src="/static/icons/close.svg" mode="aspectFit" />
</view>
<view class="clear-filters" @tap="clearAllFilters">清除</view>
</view>
</view>
<!-- 定位状态与接单区域快捷 bar(不遮挡,仅按需触发原生授权或区域校准) -->
<view
class="loc-status-bar clickable-hover"
:class="{ warn: !hasCoords && serverLocationSource === 'none' }"
@tap="handleLocationBarTap"
>
<view class="loc-bar-left">
<view class="loc-status-bar" :class="{ warn: !hasCoords && serverLocationSource === 'none' }">
<view class="loc-bar-left clickable-hover" @tap="handleLocationBarTap">
<image class="loc-bar-ico" src="/static/icons/master/hall-location-pin.svg" mode="aspectFit" />
<text class="loc-bar-txt">{{ locBarText }}</text>
</view>
<view class="loc-bar-action">
<text class="loc-bar-action-txt">{{ locBarActionText }}</text>
<image class="loc-bar-arrow" src="/static/icons/master/hall-arrow-right-orange.svg" mode="aspectFit" />
</view>
</view>
@@ -128,7 +121,7 @@
/>
<!-- 状态 2:异常错误重试态 -->
<view class="state-empty-wrap" v-else-if="loadError && !list.length">
<view class="state-empty-wrap" v-else-if="loadError">
<image class="state-img" src="/static/icons/master/hall-error.svg" mode="aspectFit" />
<text class="state-title">工单大厅加载失败</text>
<text class="state-sub">{{ loadError }}</text>
@@ -150,8 +143,8 @@
<view class="card-hd">
<view class="hd-left">
<text class="tag-urgent" v-if="Number(o.urgent)">急单</text>
<text class="tag-svc-type" :class="{ repair: o.service_type_tag === '维修' }">
{{ o.service_type_tag || '安装' }}
<text v-if="o.service_type_tag" class="tag-svc-type" :class="{ repair: o.service_type_tag === '维修' }">
{{ o.service_type_tag }}
</text>
<text class="svc-title">{{ o.service_name }}</text>
</view>
@@ -274,11 +267,12 @@
<view class="state-empty-wrap" v-else>
<image class="state-img" src="/static/icons/master/empty-orders.svg" mode="aspectFit" />
<text class="state-title">当前筛选下暂无待接工单</text>
<text class="state-sub">可尝试切换订单类型、刷新列表或扩展接单技能范围</text>
<text class="state-sub">{{ activeFilterChips.length ? '可清除筛选条件后查看其他订单' : '可尝试切换订单类型、刷新列表或扩展接单技能范围' }}</text>
<view class="state-actions">
<view class="cta-primary clickable-hover" v-if="activeFilterChips.length" @tap="clearAllFilters">清除筛选</view>
<view
class="cta-primary clickable-hover"
v-if="type !== 'all' && counts.all > 0"
v-else-if="type !== 'all' && counts.all > 0"
@tap="switchType('all')"
>
查看全部订单 ({{ formatCount(counts.all) }})
@@ -289,6 +283,37 @@
</view>
</YjyfRefreshScroll>
<view v-if="filtersOpen" class="filter-mask" @tap="filtersOpen = false">
<view class="filter-panel" @tap.stop>
<view class="filter-heading">
<text>订单筛选</text>
<view class="filter-close" @tap="filtersOpen = false"><image class="filter-close-icon" src="/static/icons/close.svg" mode="aspectFit" /></view>
</view>
<scroll-view class="filter-content" scroll-y>
<view class="filter-group">
<text class="filter-title">排序方式</text>
<view class="filter-options"><view v-for="item in sortTabs" :key="item.key" class="filter-option" :class="{ selected: draftSort === item.key }" @tap="draftSort = item.key">{{ item.name }}</view></view>
</view>
<view class="filter-group">
<text class="filter-title">订单距离</text>
<text class="filter-hint">只显示所选距离内的订单;与推荐范围分别设置</text>
<view class="filter-options"><view v-for="item in distanceOptions" :key="item.value" class="filter-option" :class="{ selected: draftDistance === item.value }" @tap="draftDistance = item.value">{{ item.label }}</view></view>
</view>
<view class="filter-group" v-if="filterOptions.service_types.length">
<text class="filter-title">服务类型</text>
<text class="filter-hint">根据订单中的服务明细筛选</text>
<view class="filter-options"><view class="filter-option" :class="{ selected: !draftServiceType }" @tap="draftServiceType = ''">全部</view><view v-for="item in visibleServiceTypes" :key="item.code" class="filter-option" :class="{ selected: draftServiceType === item.code }" @tap="draftServiceType = item.code">{{ item.name }}</view></view>
<view v-if="filterOptions.service_types.length > 5" class="filter-expand" @tap="showAllServiceTypes = !showAllServiceTypes">{{ showAllServiceTypes ? '收起服务类型' : '展开全部服务类型' }}</view>
</view>
<view class="filter-group" v-if="filterOptions.categories.length">
<text class="filter-title">服务品类</text>
<view class="filter-options"><view class="filter-option" :class="{ selected: !draftCategory }" @tap="draftCategory = 0">全部</view><view v-for="item in filterOptions.categories" :key="item.id" class="filter-option" :class="{ selected: draftCategory === Number(item.id) }" @tap="draftCategory = Number(item.id)">{{ item.name }}</view></view>
</view>
</scroll-view>
<view class="filter-footer"><view class="filter-reset" @tap="resetDraftFilters">重置</view><view class="filter-confirm" @tap="applyFilters">确定</view></view>
</view>
</view>
<!-- 4. 抢单防误点二次确认弹窗 -->
<view class="confirm-mask" v-if="selectedOrder" @tap="closeGrabConfirm">
<view class="confirm-dialog" @tap.stop>
@@ -323,12 +348,12 @@
import api from '@/utils/api.js';
import { isLogin, toLogin } from '@/utils/request.js';
import { setRole } from '@/utils/role.js';
import { savePickedLocation } from '@/utils/masterHallLocation.mjs';
import {
checkLocationPermissionStatus,
getCurrentCoordinates,
getSavedManualLocation,
saveManualLocation,
openMiniProgramLocationSettingSync
saveManualLocation
} from '@/utils/location.js';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import YjyfRefreshScroll from '@/components/YjyfRefreshScroll.vue';
@@ -347,7 +372,6 @@
const locationStatus = ref('prompt');
const locationCity = ref('');
const locationLabel = ref('');
const serveRadius = ref(15);
const serverLocationSource = ref('none');
const requestingLocation = ref(false);
const initializingLocation = ref(false);
@@ -357,20 +381,26 @@
const locBarText = computed(() => {
if (hasCoords.value) {
const name = locationLabel.value || locationCity.value || '已开启实时定位';
return `当前位置:${name}(${serveRadius.value}km内)`;
return `接单位置:${name}`;
}
if (serverLocationSource.value === 'saved') {
return `已按历史位置(${locationCity.value || '常驻城市'} · ${serveRadius.value}km内)为您推荐`;
return `接单位置:${locationCity.value || '已保存位置'}`;
}
return '未获取当前位置,开启或设置位置后可精准推荐附近订单';
});
const locBarActionText = computed(() => {
if (hasCoords.value) return '切换位置';
if (serverLocationSource.value === 'saved') return '设置位置';
return '选择位置';
return '选择接单位置';
});
const type = ref('all');
const sort = ref('recommend');
const filterOptions = ref({ categories: [], service_types: [] });
const distance = ref(0);
const category = ref(0);
const serviceType = ref('');
const filtersOpen = ref(false);
const draftSort = ref('recommend');
const draftDistance = ref(0);
const draftCategory = ref(0);
const draftServiceType = ref('');
const showAllServiceTypes = ref(false);
const visibleServiceTypes = computed(() => showAllServiceTypes.value ? filterOptions.value.service_types : filterOptions.value.service_types.slice(0, 5));
const selectedOrder = ref(null);
const grabbing = ref(false);
const togglingWork = ref(false);
@@ -390,9 +420,27 @@
{ key: 'recommend', name: '智能推荐' },
{ key: 'distance', name: '离我最近' },
{ key: 'new', name: '最新发布' },
{ key: 'amount', name: '报酬最高' },
{ key: 'amount', name: '实付最高' },
{ key: 'urgent', name: '急单优先' }
];
const distanceOptions = [
{ value: 0, label: '不限' }, { value: 5, label: '5km内' },
{ value: 15, label: '15km内' }, { value: 30, label: '30km内' }, { value: 50, label: '50km内' }
];
const activeFilterChips = computed(() => {
const chips = [];
if (sort.value === 'amount' || sort.value === 'urgent') chips.push({ key: 'sort', label: sortTabs.find(s => s.key === sort.value).name });
if (distance.value) chips.push({ key: 'distance', label: `${distance.value}km内` });
if (serviceType.value) {
const item = filterOptions.value.service_types.find(s => s.code === serviceType.value);
if (item) chips.push({ key: 'serviceType', label: item.name });
}
if (category.value) {
const item = filterOptions.value.categories.find(c => Number(c.id) === category.value);
if (item) chips.push({ key: 'category', label: item.name });
}
return chips;
});
// 基于真实待接工单生成可点击直达详情的实时广播条
const broadcastList = computed(() => {
@@ -438,9 +486,50 @@
if (locationCity.value) {
params.city = locationCity.value;
}
if (distance.value) params.distance_km = distance.value;
if (category.value) params.cat_id = category.value;
if (serviceType.value) params.service_type = serviceType.value;
return params;
}
function openFilters() {
draftSort.value = sort.value;
draftDistance.value = distance.value;
draftCategory.value = category.value;
draftServiceType.value = serviceType.value;
showAllServiceTypes.value = Boolean(serviceType.value && !filterOptions.value.service_types.slice(0, 5).some(item => item.code === serviceType.value));
filtersOpen.value = true;
}
function resetDraftFilters() {
draftSort.value = 'recommend';
draftDistance.value = 0;
draftCategory.value = 0;
draftServiceType.value = '';
}
function applyFilters() {
if ((draftDistance.value || draftSort.value === 'distance') && !hasCoords.value && serverLocationSource.value === 'none') {
uni.showToast({ title: '请先选择接单位置', icon: 'none' });
return;
}
sort.value = draftSort.value;
distance.value = draftDistance.value;
category.value = draftCategory.value;
serviceType.value = draftServiceType.value;
filtersOpen.value = false;
fetchHallList();
}
function clearFilter(key) {
if (key === 'sort') sort.value = 'recommend';
if (key === 'distance') distance.value = 0;
if (key === 'category') category.value = 0;
if (key === 'serviceType') serviceType.value = '';
fetchHallList();
}
function clearAllFilters() {
sort.value = 'recommend'; distance.value = 0; category.value = 0; serviceType.value = '';
fetchHallList();
}
function switchType(k) {
if (type.value === k) return;
type.value = k;
@@ -449,7 +538,8 @@
function switchSort(k) {
if (k === 'distance' && !hasCoords.value && serverLocationSource.value === 'none') {
handleRequestLocation();
handleLocationBarTap();
return;
}
if (sort.value === k) return;
sort.value = k;
@@ -539,106 +629,49 @@
}
}
function openLocationPage() {
const query = [];
if (coords.value.lat && coords.value.lng) {
query.push(`lat=${encodeURIComponent(coords.value.lat)}`);
query.push(`lng=${encodeURIComponent(coords.value.lng)}`);
}
if (locationCity.value) {
query.push(`city=${encodeURIComponent(locationCity.value)}`);
}
if (locationLabel.value) {
query.push(`label=${encodeURIComponent(locationLabel.value)}`);
}
if (serveRadius.value) {
query.push(`radius=${encodeURIComponent(serveRadius.value)}`);
}
const qs = query.length ? `?${query.join('&')}` : '';
uni.navigateTo({ url: `/pages/master/location${qs}` });
}
function handleLocationBarTap() {
if (hasCoords.value) {
openLocationPage();
return;
}
handleRequestLocation();
}
function handleRequestLocation() {
// #ifdef MP-WEIXIN
// 已被微信拒绝过权限时,必须在点击同步手势周期内直接唤起微信原生设置页
if (locationStatus.value === 'denied') {
requestingLocation.value = true;
openMiniProgramLocationSettingSync().then(async (res) => {
requestingLocation.value = false;
if (res && res.ok && res.lat && res.lng) {
locationStatus.value = 'granted';
await applyVerifiedLocation(res.lat, res.lng);
uni.showToast({ title: '定位已开启,已更新附近推荐', icon: 'none' });
} else {
openLocationPage();
}
});
return;
}
requestDeviceLocationInteractive();
return;
// #endif
// #ifndef MP-WEIXIN
openLocationPage();
// #endif
}
async function applyVerifiedLocation(lat, lng, customLabel = '', customCity = '') {
coords.value = { lat, lng };
if (customCity) locationCity.value = customCity;
if (customLabel) locationLabel.value = customLabel;
const res = await syncMasterLocation(lat, lng, customCity, customLabel);
const finalCity = customCity || (res && res.location_city) || locationCity.value || '';
const finalLabel = customLabel || (res && res.location_label) || finalCity || '已定位';
const finalRadius = (res && res.serve_radius) || serveRadius.value;
locationCity.value = finalCity;
locationLabel.value = finalLabel;
serveRadius.value = finalRadius;
saveManualLocation({ lat, lng, label: finalLabel, city: finalCity, serveRadius: finalRadius });
await fetchHallList();
}
async function requestDeviceLocationInteractive() {
if (requestingLocation.value) return;
if (requestingLocation.value || initializingLocation.value) return;
requestingLocation.value = true;
try {
const res = await getCurrentCoordinates({ timeout: 4500 });
if (res && res.ok && res.lat && res.lng) {
locationStatus.value = 'granted';
await applyVerifiedLocation(res.lat, res.lng);
uni.showToast({ title: '定位成功,已为您推荐附近工单', icon: 'none' });
} else {
if (res && res.reason === 'denied') {
locationStatus.value = 'denied';
const options = {
success: async (selection) => {
try {
++loadSeq;
const saved = await savePickedLocation(selection, api.masterUpdateLocation);
coords.value = { lat: saved.lat, lng: saved.lng };
locationCity.value = saved.city;
locationLabel.value = saved.label;
saveManualLocation({ ...saved, manual: true });
await fetchHallList();
uni.showToast({ title: '接单位置已更新', icon: 'none' });
} catch (e) {
loading.value = false;
uni.showToast({ title: e?.msg || e?.message || '保存位置失败,请重试', icon: 'none' });
} finally {
requestingLocation.value = false;
}
},
fail: (err) => {
requestingLocation.value = false;
if (!String(err?.errMsg || '').toLowerCase().includes('cancel')) {
uni.showToast({ title: '无法打开位置选择,请检查定位权限', icon: 'none' });
}
openLocationPage();
}
} finally {
requestingLocation.value = false;
};
if (hasCoords.value) {
options.latitude = Number(coords.value.lat);
options.longitude = Number(coords.value.lng);
}
}
function onLocationPageUpdated(payload) {
if (!payload) return;
if (payload.lat && payload.lng) {
coords.value = { lat: payload.lat, lng: payload.lng };
}
if (payload.city) locationCity.value = payload.city;
if (payload.label) locationLabel.value = payload.label;
if (payload.serveRadius) serveRadius.value = Number(payload.serveRadius) || serveRadius.value;
fetchHallList();
uni.chooseLocation(options);
}
async function resolveLocationSilent(timeoutMs = 3500) {
const saved = getSavedManualLocation();
if (saved && saved.manual) {
coords.value = { lat: saved.lat, lng: saved.lng };
locationCity.value = saved.city;
locationLabel.value = saved.label;
return true;
}
const status = await checkLocationPermissionStatus();
locationStatus.value = status;
@@ -675,7 +708,6 @@
}
// 若实时设备定位未获取,回读近期手动校准过的真实地点缓存
const saved = getSavedManualLocation();
if (saved) {
coords.value = { lat: saved.lat, lng: saved.lng };
if (saved.city) locationCity.value = saved.city;
@@ -704,7 +736,7 @@
toLogin('/pages/master/hall');
return;
}
if (initializingLocation.value) {
if (initializingLocation.value || requestingLocation.value) {
return;
}
const saved = getSavedManualLocation();
@@ -712,7 +744,6 @@
coords.value = { lat: saved.lat, lng: saved.lng };
if (saved.city) locationCity.value = saved.city;
if (saved.label) locationLabel.value = saved.label;
if (saved.serveRadius) serveRadius.value = saved.serveRadius;
} else if (!hasCoords.value) {
await resolveLocationSilent(3000);
}
@@ -760,12 +791,10 @@
if (hallRes.counts) {
counts.value = hallRes.counts;
}
if (hallRes.filter_options) filterOptions.value = hallRes.filter_options;
if (hallRes.location_city) {
locationCity.value = hallRes.location_city;
}
if (hallRes.serve_radius) {
serveRadius.value = Number(hallRes.serve_radius) || serveRadius.value;
}
serverLocationSource.value = hallRes.location_source || 'none';
} else if (hallResult.status === 'rejected') {
const err = hallResult.reason;
@@ -845,12 +874,10 @@
}
onMounted(() => {
uni.$on('masterLocationUpdated', onLocationPageUpdated);
initLocationAndLoad();
});
onBeforeUnmount(() => {
uni.$off('masterLocationUpdated', onLocationPageUpdated);
while (timers.length) {
clearTimeout(timers.pop());
}
@@ -1674,11 +1701,37 @@
}
}
.sort-tabs-inner {
display: inline-flex;
display: flex;
flex: 1;
min-width: 0;
align-items: center;
gap: 10rpx;
gap: 6rpx;
padding-right: $yjyf-space-xs;
}
.sort-tabs-inner .s-tab { flex: 1; min-width: 0; padding: 0 8rpx; }
.filter-trigger { flex-shrink: 0; min-height: 88rpx; display: flex; align-items: center; gap: 6rpx; color: $yjyf-primary; font-size: $yjyf-font-sub; font-weight: 600; }
.filter-icon { width: 26rpx; height: 26rpx; }
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8rpx; padding: 0 $yjyf-space-md $yjyf-space-sm; }
.active-filter { display: inline-flex; align-items: center; gap: 6rpx; min-height: 52rpx; padding: 0 16rpx; border-radius: $yjyf-radius-pill; background: $yjyf-primary-bg; color: $yjyf-primary; font-size: $yjyf-font-micro; }
.active-filter-close { width: 18rpx; height: 18rpx; }
.clear-filters { display: flex; align-items: center; min-height: 52rpx; padding: 0 12rpx; color: $yjyf-text-secondary; font-size: $yjyf-font-sub; }
.filter-mask { position: fixed; inset: 0; z-index: 1005; background: rgba(0, 0, 0, 0.48); display: flex; align-items: flex-end; }
.filter-panel { width: 100%; height: 78vh; display: flex; flex-direction: column; background: $yjyf-bg-card; border-radius: $yjyf-radius-lg $yjyf-radius-lg 0 0; overflow: hidden; }
.filter-heading { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 $yjyf-space-md; height: 96rpx; font-size: 32rpx; font-weight: 700; color: $yjyf-text-main; border-bottom: 1rpx solid $yjyf-border-color; }
.filter-close { width: 88rpx; height: 88rpx; display: flex; align-items: center; justify-content: center; }
.filter-close-icon { width: 28rpx; height: 28rpx; }
.filter-content { flex: 1; min-height: 0; height: 0; box-sizing: border-box; padding: 0 $yjyf-space-md; }
.filter-group { padding: 24rpx 0; border-bottom: 1rpx solid $yjyf-border-color; }
.filter-title { display: block; color: $yjyf-text-main; font-size: $yjyf-font-body; font-weight: 700; }
.filter-hint { display: block; margin-top: 8rpx; color: $yjyf-text-secondary; font-size: $yjyf-font-micro; line-height: 1.4; }
.filter-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12rpx; margin-top: 16rpx; }
.filter-option { min-height: 76rpx; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8rpx; box-sizing: border-box; border-radius: $yjyf-radius-sm; border: 1rpx solid transparent; background: $yjyf-bg-page; color: $yjyf-text-regular; font-size: $yjyf-font-sub; }
.filter-option.selected { color: $yjyf-primary; border-color: $yjyf-primary; background: $yjyf-primary-bg; font-weight: 600; }
.filter-expand { display: flex; align-items: center; min-height: 72rpx; color: $yjyf-primary; font-size: $yjyf-font-sub; }
.filter-footer { flex-shrink: 0; display: flex; gap: 16rpx; padding: 16rpx $yjyf-space-md calc(16rpx + env(safe-area-inset-bottom)); border-top: 1rpx solid $yjyf-border-color; background: $yjyf-bg-card; }
.filter-reset, .filter-confirm { flex: 1; height: 80rpx; display: flex; align-items: center; justify-content: center; border-radius: $yjyf-radius-pill; font-size: $yjyf-font-body; font-weight: 600; }
.filter-reset { background: $yjyf-bg-page; color: $yjyf-text-regular; }
.filter-confirm { background: $yjyf-gradient-primary; color: $yjyf-text-inverse; }
/* 位置状态与引导条(紧贴控制台下方,不阻挡主列表) */
.loc-status-bar {
@@ -1697,6 +1750,7 @@
.loc-bar-left {
flex: 1;
min-width: 0;
min-height: 88rpx;
display: flex;
align-items: center;
gap: 10rpx;
@@ -1719,18 +1773,6 @@
.loc-status-bar.warn .loc-bar-txt {
color: $yjyf-text-regular;
}
.loc-bar-action {
flex-shrink: 0;
display: inline-flex;
align-items: center;
padding: 4rpx 0;
}
.loc-bar-action-txt {
font-size: $yjyf-font-sub;
font-weight: 600;
color: $yjyf-primary;
line-height: 1;
}
.loc-bar-arrow {
width: 22rpx;
height: 22rpx;