refactor layout

This commit is contained in:
Timi
2026-10-17 12:01:28 +08:00
parent fe467e8781
commit 469c595a7c
134 changed files with 11493 additions and 4437 deletions
+250 -148
View File
@@ -1,162 +1,214 @@
<template>
<div v-can="permissionCodes.pointRedemption.create" class="redemption-list">
<div class="filters glass">
<t-input
v-model.trim="keyword"
class="keyword"
clearable
borderless
placeholder="搜索客户、产品或 SKU"
>
<template #suffix-icon>
<div class="actions">
<t-button
v-if="customerId"
shape="circle"
theme="danger"
variant="text"
size="extra-small"
aria-label="清除客户选择"
@click.stop="clearCustomer"
>
<t-icon name="close" size="1rem" />
</t-button>
<t-button
size="extra-small"
theme="primary"
variant="outline"
content="选择客户"
@click.stop="customerSelectorVisible = true"
/>
</div>
</template>
</t-input>
<t-dropdown-menu class="menus">
<t-dropdown-item
v-model="dateFilterType"
:label="dateFilterLabel"
:options="dateOptions"
@change="selectDateFilter"
/>
</t-dropdown-menu>
</div>
<t-pull-down-refresh
v-model="refreshing"
:refresh-timeout="30000"
@refresh="reload"
@scrolltolower="load"
<div class="page-layout navbar redemption-list">
<t-navbar
fixed
:z-index="20"
title="积分兑换"
left-arrow
@left-click="$router.back()"
>
<div class="list-wrap">
<t-cell-group class="date-summary" theme="card" v-entrance-transition>
<template v-if="isCustomDate">
<t-cell
title="开始时间"
:note="dateRange[0] || '-'"
arrow
@click="openStartTime"
/>
<t-cell
title="结束时间"
:note="dateRange[1] || '-'"
arrow
@click="openEndTime"
/>
</template>
<t-cell title="兑换次数" :note="`${Text.display(result.total)} 次`" />
</t-cell-group>
<div v-if="result.list.length" class="items">
<t-cell-group theme="card">
<t-cell
v-for="item in result.list"
:key="item.id"
class="item"
arrow
v-entrance-transition="{ step: 30 }"
@click="toDetail(item)"
<template #right>
<div
class="nav-actions"
v-if="pageNavBarActionList.length"
v-can="permissionCodes.pointRedemption.create"
>
<t-popover
v-model:visible="pageNavBarActionVisible"
placement="bottom-right"
:show-arrow="false"
theme="light"
>
<t-button
class="trigger"
variant="text"
:aria-label="'更多操作'"
type="button"
>
<template #left-icon>
<t-image
v-if="getCustomerPhoto(item)"
:src="getCustomerPhoto(item)"
:alt="item.customer?.name || '客户照片'"
fit="cover"
class="avatar"
/>
<div
v-else
class="avatar fallback"
v-text="(item.customer?.name || item.customer?.code || '客').slice(0, 1)"
/>
<template #icon>
<t-icon name="ellipsis" />
</template>
<template #title>
<div class="title">
<strong v-text="item.productNameSnapshot || item.skuNameSnapshot || '未命名产品'" />
<t-tag
size="small"
:theme="item.status === 'FULLY_RETURNED' ? 'default' : 'success'"
:content="statusText(item.status)"
/>
</div>
</template>
<template #note>
<span class="orange" v-text="formatPoint(item.actualPointCost)" />
</template>
<template #description>
<span v-text="`${item.customer?.name || item.customerId || '未知客户'} · ${quantityText(item.quantity)} ${item.unitSnapshot || ''}`" />
</template>
</t-cell>
</t-cell-group>
</t-button>
<template #content>
<div class="menu">
<t-button
v-for="action in pageNavBarActionList"
:key="action.key"
class="menu-item"
variant="text"
type="button"
:theme="action.theme"
:loading="action.loading"
:disabled="action.disabled || action.loading"
@click="handlePageNavBarAction(action)"
>
<template v-if="action.icon" #icon>
<t-icon :name="action.icon" />
</template>
<span v-text="action.text" />
</t-button>
</div>
</template>
</t-popover>
</div>
<t-empty
v-else
:description="loading ? '正在加载兑换记录' : hasFilter ? '未找到匹配的兑换记录' : '暂无兑换记录'"
/>
</div>
</t-pull-down-refresh>
</template>
</t-navbar>
<main v-can="permissionCodes.pointRedemption.create" class="page-content scroll list">
<t-pull-down-refresh
class="pull-refresh"
v-model="refreshing"
:refresh-timeout="30000"
@refresh="reload"
@scrolltolower="load"
>
<div class="filters glass">
<t-input
v-model.trim="keyword"
class="keyword"
clearable
borderless
placeholder="搜索客户、产品或 SKU"
>
<template #suffix-icon>
<div class="actions">
<t-button
v-if="customerId"
shape="circle"
theme="danger"
variant="text"
size="extra-small"
aria-label="清除客户选择"
@click.stop="clearCustomer"
>
<t-icon name="close" size="1rem" />
</t-button>
<t-button
size="extra-small"
theme="primary"
variant="outline"
content="选择客户"
@click.stop="customerSelectorVisible = true"
/>
</div>
</template>
</t-input>
<t-dropdown-menu class="menus">
<t-dropdown-item
v-model="dateFilterType"
:label="dateFilterLabel"
:options="dateOptions"
@change="selectDateFilter"
/>
</t-dropdown-menu>
</div>
<div class="list-wrap">
<t-cell-group class="date-summary" theme="card" v-entrance-transition>
<template v-if="isCustomDate">
<t-cell
title="开始时间"
:note="dateRange[0] || '-'"
arrow
@click="openStartTime"
/>
<t-cell
title="结束时间"
:note="dateRange[1] || '-'"
arrow
@click="openEndTime"
/>
</template>
<t-cell title="兑换次数" :note="`${Text.display(result.total)} 次`" />
</t-cell-group>
<div v-if="result.list.length" class="items">
<t-cell-group theme="card">
<t-cell
v-for="item in result.list"
:key="item.id"
class="item"
arrow
v-entrance-transition="{ step: 30 }"
@click="toDetail(item)"
>
<template #left-icon>
<t-image
v-if="getCustomerPhoto(item)"
:src="getCustomerPhoto(item)"
:alt="item.customer?.name || '客户照片'"
fit="cover"
class="avatar"
/>
<div
v-else
class="avatar fallback"
v-text="(item.customer?.name || item.customer?.code || '客').slice(0, 1)"
/>
</template>
<template #title>
<div class="title">
<strong v-text="item.productNameSnapshot || item.skuNameSnapshot || '未命名产品'" />
<t-tag
size="small"
:theme="item.status === 'FULLY_RETURNED' ? 'default' : 'success'"
:content="statusText(item.status)"
/>
</div>
</template>
<template #note>
<span class="orange" v-text="formatPoint(item.actualPointCost)" />
</template>
<template #description>
<span v-text="`${item.customer?.name || item.customerId || '未知客户'} · ${quantityText(item.quantity)} ${item.unitSnapshot || ''}`" />
</template>
</t-cell>
</t-cell-group>
</div>
<t-empty
v-else
:description="loading ? '正在加载兑换记录' : hasFilter ? '未找到匹配的兑换记录' : '暂无兑换记录'"
/>
</div>
</t-pull-down-refresh>
</main>
<customer-selector
v-model="customerId"
v-model:visible="customerSelectorVisible"
@change="handleCustomerChange"
/>
<t-popup v-model="startVisible" placement="bottom">
<t-date-time-picker
v-if="startVisible"
v-model="startDraft"
format="YYYY-MM-DD HH:mm"
:mode="['date', 'minute']"
title="开始时间"
:default-value="dateRange[0]"
@cancel="cancelStartTime"
@confirm="confirmStartTime"
/>
</t-popup>
<t-popup v-model="endVisible" placement="bottom">
<t-date-time-picker
v-if="endVisible"
v-model="endDraft"
format="YYYY-MM-DD HH:mm"
:mode="['date', 'minute']"
title="结束时间"
:default-value="dateRange[1]"
@cancel="cancelEndTime"
@confirm="confirmEndTime"
/>
</t-popup>
</div>
<customer-selector
v-model="customerId"
v-model:visible="customerSelectorVisible"
@change="handleCustomerChange"
/>
<nav-bar-action-menu
v-can="permissionCodes.pointRedemption.create"
:actions="[{ key: 'create', icon: 'add', text: '客户兑换', theme: 'primary', action: toCreate }]"
/>
<t-popup v-model="startVisible" placement="bottom">
<t-date-time-picker
v-if="startVisible"
v-model="startDraft"
format="YYYY-MM-DD HH:mm"
:mode="['date', 'minute']"
title="开始时间"
:default-value="dateRange[0]"
@cancel="cancelStartTime"
@confirm="confirmStartTime"
/>
</t-popup>
<t-popup v-model="endVisible" placement="bottom">
<t-date-time-picker
v-if="endVisible"
v-model="endDraft"
format="YYYY-MM-DD HH:mm"
:mode="['date', 'minute']"
title="结束时间"
:default-value="dateRange[1]"
@cancel="cancelEndTime"
@confirm="confirmEndTime"
/>
</t-popup>
</template>
<script setup lang="ts">
import type { NavBarAction } from "@/types/NavBarAction";
import { type DropdownValue } from "tdesign-mobile-vue";
import { Text, Time, Toolkit } from "timi-web";
import CustomerAPI from "@/api/CustomerAPI";
import PointAPI from "@/api/PointAPI";
import CustomerSelector from "@/components/CustomerSelector.vue";
import { useNavBarStore } from "@/store/navBarStore";
import type { Customer } from "@/types/Customer";
import type { PointRedemption, PointRedemptionStatus } from "@/types/Point";
import { buildPresetDateRange, parseDateFilterType, parseDateTime } from "@/utils/date";
import { Message } from "@/utils/message";
@@ -165,11 +217,20 @@ import { getPackageQuantityText } from "@/utils/package";
import { getCustomerPhotoURL } from "@/utils/customer";
import { permissionCodes } from "@/utils/permission";
const pageNavBarActionVisible = ref(false);
const pageNavBarActionList = computed<NavBarAction[]>(() => (unref([{ key: "create", icon: "add", text: "客户兑换", theme: "primary", action: toCreate }]) as NavBarAction[]).filter(action => action.visible !== false));
async function handlePageNavBarAction(action: NavBarAction): Promise<void> {
pageNavBarActionVisible.value = false;
await action.action();
}
import type { Customer } from "@/types/Customer";
defineOptions({ name: "PointRedemptionList" });
const route = useRoute();
const router = useRouter();
const navBarStore = useNavBarStore();
const result = reactive({ total: 0, list: [] as PointRedemption[] });
type DateFilterType = "today" | "yesterday" | "thisWeek" | "thisMonth" | "lastMonth" | "all" | "custom";
const dateOptions: Array<{ label: string; value: DateFilterType }> = [
@@ -384,7 +445,7 @@ async function toDetail(item: PointRedemption): Promise<void> {
}
onMounted(async () => {
navBarStore.setCustomRightVisible(true);
try {
if (customerId.value) {
selectedCustomer.value = await CustomerAPI.detail(customerId.value);
@@ -405,7 +466,6 @@ watch(keyword, () => {
onUnmounted(() => {
reloadByKeyword.cancel();
navBarStore.clearRight();
});
</script>
@@ -502,4 +562,46 @@ onUnmounted(() => {
}
}
}
.nav-actions {
--td-popover-padding: 0 .5rem;
width: 6rem;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
:deep(.t-popover__content) { border-radius: .875rem; }
.trigger { padding: 0; }
.menu {
gap: .25rem;
display: grid;
padding: .5rem 0;
min-width: 9rem;
.menu-item {
--td-button-medium-height: 32px;
--td-button-medium-padding-horizontal: 10px;
gap: .25rem;
width: 100%;
font-weight: unset;
justify-content: flex-start;
}
}
}
:global(html.theme-dark) {
.nav-actions {
:deep(.t-popover__content) {
color: #e2e8f0;
background: rgba(30, 41, 59, .98);
}
.menu-item { color: #e2e8f0; }
}
}
</style>