front/src/views/h5/admin-center/workplace/index.vue
zzh b7d7ea1113
All checks were successful
Build and Deploy Front / deploy (push) Successful in 4m10s
feat: 工作台操作/运营体验改版,代发进度去掉待绑定
线路双指标对比、运营柱线趋势、操作区左右待办队列;创建代发必绑口径对齐前后端 Tab。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 11:23:22 +08:00

647 lines
18 KiB
Vue

<template>
<div
class="h5-wp"
:style="{ '--pull-y': `${pullY}px` }"
@touchstart.passive="onTouchStart"
@touchmove.passive="onTouchMove"
@touchend="onTouchEnd"
>
<div class="h5-wp__pull" :class="{ 'is-ready': pullY > 48, 'is-loading': loading && pullArmed }">
{{ pullHint }}
</div>
<header class="h5-wp__top">
<div class="h5-wp__identity">
<Banner compact with-clock />
</div>
<WorkplaceUrgentBar embedded class="h5-wp__inbox" />
<button
type="button"
class="h5-wp__refresh"
:disabled="loading"
:aria-label="updatedLabel || t('workplace.admin.opsRefresh')"
@click="refresh"
>
<IconRefresh :class="{ 'is-spinning': loading }" />
</button>
</header>
<!-- 运营 -->
<section class="h5-wp__panel" :class="{ 'is-open': open.ops }">
<button type="button" class="h5-wp__panel-toggle" @click="togglePanel('ops')">
<div class="h5-wp__panel-titles">
<h2>{{ t('workplace.admin.role.ops') }}</h2>
<p>{{ t('workplace.admin.role.opsHint') }}</p>
</div>
<span v-if="opsAlertCount > 0" class="h5-wp__badge">{{ opsAlertCount }}</span>
<span v-else class="h5-wp__badge is-ok">OK</span>
<IconDown class="h5-wp__chevron" />
</button>
<div v-show="open.ops" class="h5-wp__panel-body">
<div v-if="monitorAvailable" class="h5-wp__chips">
<button
v-for="dim in dims"
:key="dim"
type="button"
class="h5-wp__chip"
:class="{ 'is-active': opsDimension === dim }"
@click="setOpsDimension(dim)"
>
{{
dim === 'day'
? t('workplace.admin.period.today')
: dim === 'week'
? t('workplace.admin.period.week')
: t('workplace.admin.period.month')
}}
</button>
</div>
<p v-if="opsClearHint" class="h5-wp__clear">{{ opsClearHint }}</p>
<WorkplaceKpiGrid :items="opsKpis" :loading="opsPanelLoading" :columns="2" @select="onKpi" />
<div class="h5-wp__chips h5-wp__chips--end">
<button
type="button"
class="h5-wp__chip"
:class="{ 'is-active': trendMode === 'volume' }"
@click="trendMode = 'volume'"
>
{{ t('workplace.admin.role.opsTrendVolume') }}
</button>
<button
v-if="monitorAvailable"
type="button"
class="h5-wp__chip"
:class="{ 'is-active': trendMode === 'finance' }"
@click="trendMode = 'finance'"
>
{{ t('workplace.admin.role.opsTrendFinance') }}
</button>
</div>
<H5TrendBars
:title="
trendMode === 'finance'
? t('workplace.admin.role.opsTrendFinance')
: t('workplace.admin.role.opsTrend')
"
:labels="opsTrend.labels"
:series="opsTrend.series"
:loading="opsPanelLoading"
:empty-text="t('workplace.admin.role.chartEmpty')"
/>
</div>
</section>
<!-- 操作:只保留漏斗,去掉与 KPI 重复的卡片 -->
<section class="h5-wp__panel" :class="{ 'is-open': open.fulfill }">
<button type="button" class="h5-wp__panel-toggle" @click="togglePanel('fulfill')">
<div class="h5-wp__panel-titles">
<h2>{{ t('workplace.admin.role.fulfill') }}</h2>
<p>{{ t('workplace.admin.role.fulfillHint') }}</p>
</div>
<span v-if="fulfillHotTotal > 0" class="h5-wp__badge">{{ fulfillHotTotal }}</span>
<span v-else class="h5-wp__badge is-ok">OK</span>
<IconDown class="h5-wp__chevron" />
</button>
<div v-show="open.fulfill" class="h5-wp__panel-body">
<p v-if="!fulfillHotTotal" class="h5-wp__clear">{{ t('workplace.admin.role.clearHint') }}</p>
<WorkplaceFunnelBar
:title="t('workplace.admin.fulfillTitle')"
:segments="fulfillSegments"
@select="onFunnel"
/>
<WorkplaceFunnelBar
:title="t('workplace.admin.pickupTitle')"
:segments="pickupSegments"
@select="onFunnel"
/>
</div>
</section>
<!-- 客服 -->
<section class="h5-wp__panel" :class="{ 'is-open': open.cs }">
<button type="button" class="h5-wp__panel-toggle" @click="togglePanel('cs')">
<div class="h5-wp__panel-titles">
<h2>{{ t('workplace.admin.role.cs') }}</h2>
<p>{{ t('workplace.admin.role.csHint') }}</p>
</div>
<span v-if="csAlertCount > 0" class="h5-wp__badge">{{ csAlertCount }}</span>
<span v-else class="h5-wp__badge is-ok">OK</span>
<IconDown class="h5-wp__chevron" />
</button>
<div v-show="open.cs" class="h5-wp__panel-body">
<p v-if="csClearHint" class="h5-wp__clear">{{ csClearHint }}</p>
<WorkplaceKpiGrid :items="csKpis" :loading="loading" :columns="2" @select="onKpi" />
<WorkplaceRateBars
v-if="monitorAvailable && csRateItems.length"
:title="t('workplace.admin.role.csQuality')"
:items="csRateItems"
/>
<p v-else-if="!monitorAvailable" class="h5-wp__fallback">
{{ t('workplace.admin.role.csNoMonitor') }}
</p>
</div>
</section>
<!-- 客户 -->
<section class="h5-wp__panel" :class="{ 'is-open': open.customer }">
<button type="button" class="h5-wp__panel-toggle" @click="togglePanel('customer')">
<div class="h5-wp__panel-titles">
<h2>{{ t('workplace.admin.role.customer') }}</h2>
<p>
{{
monitorAvailable
? t('workplace.admin.role.customerHint')
: t('workplace.admin.role.customerNoMonitor')
}}
</p>
</div>
<span v-if="customerAlertCount > 0" class="h5-wp__badge">{{ customerAlertCount }}</span>
<span v-else-if="monitorAvailable" class="h5-wp__badge is-ok">OK</span>
<IconDown class="h5-wp__chevron" />
</button>
<div v-show="open.customer" class="h5-wp__panel-body">
<template v-if="monitorAvailable">
<div class="h5-wp__chips">
<button
v-for="period in regionPeriods"
:key="period"
type="button"
class="h5-wp__chip"
:class="{ 'is-active': regionPeriod === period }"
@click="regionPeriod = period"
>
{{
period === 'week'
? t('workplace.admin.period.byWeek')
: t('workplace.admin.period.byMonth')
}}
</button>
</div>
<WorkplaceKpiGrid :items="customerKpis" :loading="loading" :columns="2" @select="onKpi" />
<div class="h5-wp__chips h5-wp__chips--end">
<button
type="button"
class="h5-wp__chip"
:class="{ 'is-active': customerMetric === 'order' }"
@click="customerMetric = 'order'"
>
{{ t('h5Admin.workplace.customer.orders') }}
</button>
<button
type="button"
class="h5-wp__chip"
:class="{ 'is-active': customerMetric === 'receivable' }"
@click="customerMetric = 'receivable'"
>
{{ t('h5Admin.workplace.customer.receivable') }}
</button>
</div>
<H5RankBars
:title="
customerMetric === 'order'
? t('monitor.logistics.chart.customerOrdersByLine')
: t('monitor.logistics.chart.customerReceivableByLine')
"
:items="customerRankItems"
:loading="loading"
:format="customerMetric === 'receivable' ? 'currency' : 'number'"
:empty-text="t('workplace.admin.role.chartEmpty')"
/>
</template>
<p v-else class="h5-wp__fallback">{{ t('workplace.admin.role.customerNoMonitor') }}</p>
</div>
</section>
</div>
</template>
<script lang="ts" setup>
import { computed, reactive, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router';
import { IconDown, IconRefresh } from '@arco-design/web-vue/es/icon';
import { useAdminWorkplaceData } from '@/views/home/workplace/composables/useAdminWorkplaceData';
import {
buildCsKpis,
buildCsRateItems,
buildCustomerKpis,
buildCustomerLineRank,
buildFulfillSegments,
buildOpsKpis,
buildOpsTrend,
buildPickupSegments,
calcFulfillHotTotal,
clearHintFor,
kpiAlertSum,
} from '@/views/home/workplace/composables/workplaceRoleModels';
import { navigateWorkplaceDrill } from '@/views/home/workplace/utils/workplaceLinks';
import type { RegionPeriod } from '@/views/home/workplace/utils/regionTrend';
import Banner from '@/views/home/workplace/components/banner.vue';
import WorkplaceUrgentBar from '@/views/home/workplace/components/WorkplaceUrgentBar.vue';
import WorkplaceKpiGrid, {
type WorkplaceKpiItem,
} from '@/views/home/workplace/components/WorkplaceKpiGrid.vue';
import WorkplaceFunnelBar, {
type FunnelSegment,
} from '@/views/home/workplace/components/WorkplaceFunnelBar.vue';
import WorkplaceRateBars from '@/views/home/workplace/components/WorkplaceRateBars.vue';
import H5TrendBars from './components/H5TrendBars.vue';
import H5RankBars from './components/H5RankBars.vue';
defineOptions({ name: 'H5AdminWorkplace' });
type PanelKey = 'ops' | 'fulfill' | 'cs' | 'customer';
const { t, locale } = useI18n();
const router = useRouter();
const {
loading,
opsLoading,
stats,
businessTrend,
orderTrend,
monitor,
monitorOps,
monitorAvailable,
opsDimension,
updatedAt,
refresh,
setOpsDimension,
} = useAdminWorkplaceData();
const dims = ['day', 'week', 'month'] as const;
const regionPeriods = ['week', 'month'] as const;
const trendMode = ref<'volume' | 'finance'>('volume');
const regionPeriod = ref<RegionPeriod>('week');
const customerMetric = ref<'order' | 'receivable'>('order');
const open = reactive<Record<PanelKey, boolean>>({
ops: true,
fulfill: false,
cs: false,
customer: false,
});
const panelsReady = ref(false);
const pullY = ref(0);
const pullArmed = ref(false);
let touchStartY = 0;
let pulling = false;
watch(
() => monitorAvailable.value,
(ok) => {
if (!ok && trendMode.value === 'finance') trendMode.value = 'volume';
},
);
const updatedLabel = computed(() => {
if (!updatedAt.value) return '';
try {
const time = new Intl.DateTimeFormat(
String(locale.value).toLowerCase().startsWith('en') ? 'en-US' : 'zh-CN',
{ hour: '2-digit', minute: '2-digit' },
).format(updatedAt.value);
return t('workplace.admin.opsUpdated', { time });
} catch {
return '';
}
});
const pullHint = computed(() => {
if (loading.value && pullArmed.value) return t('h5Admin.workplace.pull.refreshing');
if (pullY.value > 48) return t('h5Admin.workplace.pull.release');
return t('h5Admin.workplace.pull.hint');
});
const opsPanelLoading = computed(() => loading.value || opsLoading.value);
const opsKpis = computed(() =>
buildOpsKpis(t, stats.value, monitorOps.value, monitorAvailable.value),
);
const opsAlertCount = computed(() => kpiAlertSum(opsKpis.value));
const opsClearHint = computed(() => clearHintFor(t, opsKpis.value));
const opsTrend = computed(() =>
buildOpsTrend(
t,
trendMode.value,
orderTrend.value,
businessTrend.value,
monitorOps.value,
monitorAvailable.value,
),
);
const fulfillHotTotal = computed(() => calcFulfillHotTotal(stats.value));
const fulfillSegments = computed(() => buildFulfillSegments(t, stats.value));
const pickupSegments = computed(() => buildPickupSegments(t, stats.value));
const csKpis = computed(() =>
buildCsKpis(t, stats.value, monitor.value, monitorAvailable.value),
);
const csAlertCount = computed(() => kpiAlertSum(csKpis.value));
const csClearHint = computed(() => clearHintFor(t, csKpis.value));
const csRateItems = computed(() => buildCsRateItems(t, monitor.value));
const customerKpis = computed(() => buildCustomerKpis(t, monitor.value));
const customerAlertCount = computed(
() => Number(monitor.value?.customer?.inactiveLogin7d) || 0,
);
const customerRankItems = computed(() =>
buildCustomerLineRank(t, monitor.value, customerMetric.value, regionPeriod.value),
);
watch(
[loading, opsAlertCount, fulfillHotTotal, csAlertCount, customerAlertCount],
() => {
if (loading.value || panelsReady.value) return;
panelsReady.value = true;
const opsHot = opsAlertCount.value > 0;
const fulfillHot = fulfillHotTotal.value > 0;
const csHot = csAlertCount.value > 0;
const customerHot = customerAlertCount.value > 0;
const anyHot = opsHot || fulfillHot || csHot || customerHot;
open.ops = opsHot || !anyHot;
open.fulfill = fulfillHot;
open.cs = csHot;
open.customer = customerHot;
},
);
function togglePanel(key: PanelKey) {
open[key] = !open[key];
}
function onKpi(item: WorkplaceKpiItem) {
navigateWorkplaceDrill(router, item.path, item.query);
}
function onFunnel(seg: FunnelSegment) {
navigateWorkplaceDrill(router, seg.path, seg.query);
}
function getScrollParent() {
return document.querySelector('.h5-admin-main') as HTMLElement | null;
}
function onTouchStart(e: TouchEvent) {
const main = getScrollParent();
if (!main || main.scrollTop > 2 || loading.value) {
pulling = false;
return;
}
touchStartY = e.touches[0]?.clientY || 0;
pulling = true;
pullArmed.value = false;
}
function onTouchMove(e: TouchEvent) {
if (!pulling) return;
const dy = (e.touches[0]?.clientY || 0) - touchStartY;
if (dy <= 0) {
pullY.value = 0;
return;
}
pullY.value = Math.min(72, dy * 0.42);
}
async function onTouchEnd() {
if (!pulling) return;
const shouldRefresh = pullY.value > 48;
pulling = false;
pullY.value = 0;
if (!shouldRefresh) return;
pullArmed.value = true;
try {
await refresh();
} finally {
pullArmed.value = false;
}
}
</script>
<style lang="less" scoped>
.h5-wp {
--aw-ink: #1a2e38;
padding: 12px;
display: flex;
flex-direction: column;
gap: 10px;
box-sizing: border-box;
background: #f5f6f8;
transform: translateY(var(--pull-y, 0px));
transition: transform 0.12s ease-out;
}
.h5-wp__pull {
height: 0;
overflow: hidden;
display: flex;
align-items: flex-end;
justify-content: center;
margin: -12px -12px 0;
padding-bottom: 0;
font-size: 12px;
font-weight: 600;
color: rgba(26, 46, 56, 0.45);
opacity: 0;
transition: opacity 0.12s ease;
&.is-ready,
&.is-loading {
height: 28px;
opacity: 1;
color: var(--app-primary-color);
}
}
.h5-wp__top {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
padding: 10px 12px;
border-radius: 16px;
background: #fff;
box-shadow:
inset 0 2px 8px rgba(15, 23, 42, 0.07),
inset 0 1px 1px rgba(15, 23, 42, 0.04);
}
.h5-wp__identity {
flex: 1 1 auto;
min-width: 0;
:deep(.banner) {
padding: 0;
width: auto;
}
:deep(.banner-row) {
min-height: 0;
}
}
.h5-wp__inbox {
order: 3;
flex: 1 1 100%;
min-width: 0;
}
.h5-wp__refresh {
display: inline-flex;
align-items: center;
justify-content: center;
width: 32px;
height: 32px;
flex-shrink: 0;
border: none;
border-radius: 10px;
background: transparent;
color: var(--aw-ink);
font-size: 16px;
cursor: pointer;
&:disabled {
opacity: 0.45;
}
:deep(.is-spinning) {
animation: h5-wp-spin 0.8s linear infinite;
}
}
@keyframes h5-wp-spin {
to {
transform: rotate(360deg);
}
}
.h5-wp__panel {
border-radius: 16px;
background: #fff;
box-shadow:
inset 0 2px 8px rgba(15, 23, 42, 0.07),
inset 0 1px 1px rgba(15, 23, 42, 0.04);
box-sizing: border-box;
overflow: hidden;
}
.h5-wp__panel-toggle {
width: 100%;
display: flex;
align-items: center;
gap: 8px;
padding: 14px;
border: none;
background: transparent;
text-align: left;
cursor: pointer;
}
.h5-wp__panel-titles {
flex: 1;
min-width: 0;
h2 {
margin: 0;
font-size: 15px;
font-weight: 700;
color: #1a2e38;
}
p {
margin: 2px 0 0;
font-size: 12px;
color: rgba(26, 46, 56, 0.48);
}
}
.h5-wp__badge {
flex-shrink: 0;
min-width: 22px;
height: 22px;
padding: 0 7px;
border-radius: 999px;
display: inline-flex;
align-items: center;
justify-content: center;
background: color-mix(in srgb, #c45a3a 14%, #fff);
color: #c45a3a;
font-size: 11px;
font-weight: 700;
&.is-ok {
background: rgba(15, 157, 108, 0.1);
color: #0f9d6c;
}
}
.h5-wp__chevron {
flex-shrink: 0;
color: rgba(26, 46, 56, 0.35);
font-size: 14px;
transition: transform 0.18s ease;
}
.h5-wp__panel.is-open .h5-wp__chevron {
transform: rotate(180deg);
}
.h5-wp__panel-body {
display: flex;
flex-direction: column;
gap: 12px;
padding: 0 14px 14px;
}
.h5-wp__chips {
display: inline-flex;
flex-wrap: wrap;
gap: 6px;
}
.h5-wp__chips--end {
justify-content: flex-end;
}
.h5-wp__chip {
height: 28px;
padding: 0 10px;
border: none;
border-radius: 999px;
background: rgba(15, 23, 42, 0.05);
color: rgba(26, 46, 56, 0.62);
font-size: 12px;
font-weight: 600;
cursor: pointer;
&.is-active {
background: color-mix(in srgb, var(--app-primary-color) 16%, #fff);
color: var(--app-primary-color);
}
}
.h5-wp__clear {
margin: 0;
padding: 6px 10px;
border-radius: 8px;
background: rgba(15, 157, 108, 0.08);
color: #0f9d6c;
font-size: 12px;
font-weight: 600;
}
.h5-wp__fallback {
margin: 0;
font-size: 12px;
color: rgba(26, 46, 56, 0.45);
}
:deep(.wk-inbox__nav) {
display: none;
}
:deep(.wk-inbox__all) {
flex-shrink: 0;
}
</style>