support tablet

This commit is contained in:
Timi
2026-11-02 23:12:05 +08:00
parent c48b19bed5
commit d3879c9c77
123 changed files with 4153 additions and 2673 deletions
+1 -1
View File
@@ -243,7 +243,7 @@ function pad(value: number): string {
<style scoped lang="less">
.gao-chart-page {
gap: 1rem;
padding: calc(var(--app-nav-height) + 1rem) 1rem 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
+3 -3
View File
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-category-list">
<div class="tui-page-layout tui-navbar product-category-list">
<t-navbar
fixed
:z-index="20"
@@ -11,7 +11,7 @@
<navbar-actions :actions="actionList" :visible="canShowActionMenu" />
</template>
</t-navbar>
<main v-can="permissionCodes.productCategory.read" class="page-content scroll column list">
<main v-can="permissionCodes.productCategory.read" class="tui-page-content scroll column list">
<t-pull-down-refresh
class="pull-refresh"
v-model="isRefreshing"
@@ -372,7 +372,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-category-list {
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
.list {
+1 -1
View File
@@ -134,7 +134,7 @@ onMounted(async () => {
<style scoped lang="less">
.product-category-rank {
padding: calc(var(--app-nav-height) + 1rem) 0 6rem;
padding: calc(var(--tui-nav-height) + 1rem) 0 6rem;
.tip {
color: #52607a;
+1 -1
View File
@@ -261,7 +261,7 @@ function pad(value: number): string {
<style scoped lang="less">
.gao-chart-page {
gap: 1rem;
padding: calc(var(--app-nav-height) + 1rem) 1rem 1rem;
padding: calc(var(--tui-nav-height) + 1rem) 1rem 1rem;
display: flex;
flex-direction: column;
+56 -6
View File
@@ -1,17 +1,17 @@
<template>
<div class="page-layout navbar">
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
title="产品详情"
left-arrow
@left-click="$router.back()"
@left-click="goBack"
>
<template #right>
<navbar-actions :actions="actionList" />
</template>
</t-navbar>
<main class="page-content scroll column">
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.product.read" class="product-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-if="product">
@@ -148,12 +148,37 @@ import {
} from "@/utils/product";
import { Message } from "@/utils/message";
import { permissionCodes } from "@/utils/permission";
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
import { Text } from "timi-web";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
defineOptions({ name: "ProductDetail" });
const props = withDefaults(defineProps<{
/** 指定产品 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
productId?: string;
}>(), {
productId: ""
});
const emit = defineEmits<{
/** 内联在右栏时请求切换到编辑视图 */
edit: [];
}>();
function resolveId(): string {
return props.productId || String(route.params.id || "");
}
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
useExpandToMaster({
path: "/management/products",
id: () => resolveId()
});
/** 非空说明当前被内联在主从分栏的右栏里 */
const pane = usePane();
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
@@ -191,7 +216,7 @@ const actionList = computed<NavbarAction[]>(() => {
});
async function load(): Promise<void> {
const id = String(route.params.id || "");
const id = resolveId();
if (!id) {
return;
}
@@ -204,9 +229,26 @@ async function load(): Promise<void> {
}
async function edit(): Promise<void> {
if (product.value?.id) {
await router.push(`/management/products/${product.value.id}/edit`);
if (!product.value?.id) {
return;
}
// 分栏时右栏直接切到编辑视图,不跳路由,列表上下文保留
if (pane) {
emit("edit");
return;
}
await router.push(`/management/products/${product.value.id}/edit`);
}
function goBack(): void {
if (pane) {
pane.close();
return;
}
void router.back();
}
async function viewStock(): Promise<void> {
@@ -289,6 +331,10 @@ function remove(): void {
emitListDataChanged(listDataEventKeys.productChanged, id);
emitListDataChanged(listDataEventKeys.productStockChanged, id);
Message.success("产品已移除");
if (pane) {
pane.close();
return;
}
await router.replace("/management/products");
} catch (error) {
Message.error(getErrorMessage(error, "产品移除失败"));
@@ -299,6 +345,10 @@ function remove(): void {
});
}
watch(() => [props.productId, route.params.id], async () => {
await load();
});
onMounted(async () => {
try {
+43 -7
View File
@@ -1,11 +1,11 @@
<template>
<div class="page-layout navbar">
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
:title="routeNavBarTitle"
left-arrow
@left-click="$router.back()"
@left-click="exit()"
>
<template #right>
<t-button
@@ -18,7 +18,7 @@
/>
</template>
</t-navbar>
<main class="page-content scroll column">
<main class="tui-page-content scroll column">
<div v-can="savePermissionCode" class="product-edit">
<t-form class="form card" label-width="6rem" v-entrance-transition>
<t-form-item label="产品编码" required-mark help="使用英语、拼音或唯一数字">
@@ -40,7 +40,11 @@
<span class="picker-text" v-text="getProductStatusText(form.status)" />
</t-form-item>
<t-form-item label="备注">
<t-textarea v-model="form.remark" borderless maxlength="255" autosize placeholder="可填写产品说明" />
<t-textarea
:model-value="form.remark ?? ''"
@update:model-value="value => form.remark = String(value)"
borderless maxlength="255" autosize placeholder="可填写产品说明"
/>
</t-form-item>
<t-form-item label-width="0">
<attachment-selector
@@ -219,7 +223,7 @@
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { BottomPopup, useExpandToMaster, usePane } from "timi-tdesign-mobile";
import { DialogPlugin, type ColorObject } from "tdesign-mobile-vue";
import { type Attachment, AttachmentAPI, useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
@@ -248,6 +252,34 @@ defineOptions({ name: "ProductEdit" });
const route = useRoute();
const props = withDefaults(defineProps<{
/** 内联到主从分栏时由列表页传入,优先于路由参数 */
productId?: string;
}>(), {
productId: ""
});
/** 非空说明当前被内联在右栏里,退出走 close 而不是路由 */
const pane = usePane();
const routeId = computed(() => props.productId || String(route.params.id || ""));
// 竖屏整页编辑转横屏:回到分栏,并用 view=edit 让列表页把右栏还原成编辑
useExpandToMaster({
path: "/management/products",
id: () => routeId.value,
query: { view: "edit" }
});
/** 退出编辑:分栏时交回列表页,整页时回路由 */
function exit(saved = false): void {
if (pane) {
pane.close(saved);
return;
}
void router.back();
}
const routeNavBarTitle = computed(() => {
switch (route.name) {
case "ProductCreate":
@@ -255,12 +287,12 @@ const routeNavBarTitle = computed(() => {
case "ProductEdit":
return "编辑产品";
default:
return "";
// 内联在右栏时路由仍是列表页,标题不能只看 route.name
return pane ? "编辑产品" : "";
}
});
const router = useRouter();
const userStore = useUserStore();
const routeId = computed(() => String(route.params.id || ""));
const isCreateMode = computed(() => !routeId.value);
const savePermissionCode = computed(() => isCreateMode.value ? permissionCodes.product.create : permissionCodes.product.update);
const isSaving = ref(false);
@@ -1073,6 +1105,10 @@ async function save(): Promise<void> {
emitListDataChanged(listDataEventKeys.productChanged, productId);
emitListDataChanged(listDataEventKeys.productStockChanged, productId);
Message.success(isCreateMode.value ? "产品已创建" : "产品已保存");
if (pane) {
pane.close(true);
return;
}
await router.replace(`/management/products/${productId}`);
} catch (error) {
Message.error(getErrorMessage(error, "产品保存失败,请检查 SKU 编码、规格组合和单位配置"));
+119 -87
View File
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-list">
<div class="tui-page-layout tui-navbar product-list">
<t-navbar
fixed
:z-index="20"
@@ -18,100 +18,125 @@
/>
</template>
</t-navbar>
<main ref="productListRef" v-can="permissionCodes.product.read" class="page-content scroll column list">
<t-pull-down-refresh
class="pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<div class="filters glass">
<t-input
v-model="keyword"
class="keyword"
type="search"
borderless
placeholder="搜索产品名称(拼音)或编码"
/>
<t-dropdown-menu class="menus">
<t-dropdown-item
v-model="status"
label="状态"
:options="statusOptions"
@change="selectStatus"
/>
<t-dropdown-item
v-model="productType"
label="类型"
:options="productTypeOptions"
@change="selectProductType"
/>
<t-dropdown-item
:model-value="categoryIdList"
label="分类"
:options="categoryOptions"
multiple
:options-columns="2"
@change="selectCategory"
@confirm="confirmCategory"
@reset="resetCategory"
@update:model-value="updateCategory"
/>
</t-dropdown-menu>
</div>
<t-cell-group
v-if="productList.length"
class="list fix-last-cell-line empty-cell-title-margin"
theme="card"
<master-detail-page
ref="productListRef"
v-can="permissionCodes.product.read"
class="list"
:split="isWide"
:selected="!!selectedId"
:direction="paneDirection"
>
<template #master>
<t-pull-down-refresh
class="pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<t-cell v-for="item in productList" :key="item.id" class="item" arrow hover v-entrance-transition="{ step: 30 }" @click="toDetail(item)">
<template #leftIcon>
<t-image
v-if="getProductPhotoURL(item)"
:src="getProductPhotoURL(item)"
:alt="item.name || '产品图片'"
fit="cover"
class="avatar"
<div class="filters glass">
<t-input
v-model="keyword"
class="keyword"
type="search"
borderless
placeholder="搜索产品名称(拼音)或编码"
/>
<t-dropdown-menu class="menus">
<t-dropdown-item
v-model="status"
label="状态"
:options="statusOptions"
@change="selectStatus"
/>
<div
v-else
class="avatar fallback"
v-text="(item.name || '产').slice(0, 1)"
<t-dropdown-item
v-model="productType"
label="类型"
:options="productTypeOptions"
@change="selectProductType"
/>
</template>
<template #title>
<div class="text-bold" v-text="item.name || '未命名产品'" />
</template>
<template #note>
<t-tag
size="small"
variant="outline"
:theme="getProductStatusTheme(item.status)"
:content="getProductStatusText(item.status)"
<t-dropdown-item
:model-value="categoryIdList"
label="分类"
:options="categoryOptions"
multiple
:options-columns="2"
@change="selectCategory"
@confirm="confirmCategory"
@reset="resetCategory"
@update:model-value="updateCategory"
/>
</template>
<template #description>
<div class="description">
</t-dropdown-menu>
</div>
<t-cell-group
v-if="productList.length"
class="list fix-last-cell-line empty-cell-title-margin"
theme="card"
>
<t-cell v-for="item in productList" :key="item.id" class="item" arrow hover v-entrance-transition="{ step: 30 }" @click="toDetail(item)">
<template #leftIcon>
<t-image
v-if="getProductPhotoURL(item)"
:src="getProductPhotoURL(item)"
:alt="item.name || '产品图片'"
fit="cover"
class="avatar"
/>
<div
v-else
class="avatar fallback"
v-text="(item.name || '产').slice(0, 1)"
/>
</template>
<template #title>
<div class="text-bold" v-text="item.name || '未命名产品'" />
</template>
<template #note>
<t-tag
size="small"
variant="outline"
:content="getProductTypeText(item.productType)"
:theme="getProductStatusTheme(item.status)"
:content="getProductStatusText(item.status)"
/>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="productList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</t-pull-down-refresh>
</main>
</template>
<template #description>
<div class="description">
<t-tag
size="small"
variant="outline"
:content="getProductTypeText(item.productType)"
/>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="productList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</t-pull-down-refresh>
</template>
<template #detail>
<product-edit
v-if="editing"
:key="`edit-${selectedId}`"
:product-id="selectedId"
/>
<product-detail
v-else
:key="`detail-${selectedId}-${detailVersion}`"
:product-id="selectedId"
@edit="openEdit"
/>
</template>
</master-detail-page>
</div>
</template>
<script setup lang="ts">
import { type DropdownValue } from "tdesign-mobile-vue";
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
import ProductDetail from "@/pages/product/ProductDetail.vue";
import ProductEdit from "@/pages/product/ProductEdit.vue";
import { useUserStore } from "timi-web-api";
import { onBeforeRouteLeave } from "vue-router";
import ProductAPI from "@/api/ProductAPI";
@@ -124,9 +149,18 @@ import { permissionCodes } from "@/utils/permission";
defineOptions({ name: "ProductList" });
const router = useRouter();
const route = useRoute();
const productListRef = ref<HTMLElement | null>(null);
// 选中项、编辑态、切换方向、关闭逻辑、转屏、query 同步都在这里
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
useMasterDetailPane({
path: "/management/products",
detail: id => `/management/products/${id}`,
edit: id => `/management/products/${id}/edit`
});
const productListRef = ref<ComponentPublicInstance | null>(null);
const userStore = useUserStore();
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.product.create));
@@ -150,7 +184,7 @@ let unregisterProductListEvent: (() => void) | undefined;
let isDisposed = false;
function getProductListPage(): HTMLElement | null {
return productListRef.value?.querySelector<HTMLElement>(".pull-refresh") || null;
return (productListRef.value?.$el as HTMLElement | undefined)?.querySelector<HTMLElement>(".pull-refresh") || null;
}
function savePageScrollPosition(): void {
@@ -383,9 +417,7 @@ async function toCreate(): Promise<void> {
}
async function toDetail(item: Product): Promise<void> {
if (item.id) {
await router.push(`/management/products/${item.id}`);
}
openDetail(item.id || "");
}
onMounted(async () => {
@@ -435,7 +467,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-list {
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
.list {
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar">
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
@@ -19,7 +19,7 @@
/>
</template>
</t-navbar>
<main class="page-content scroll column">
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.productStock.create" class="product-stock-batch-configure">
<t-form class="form card" label-width="5rem" v-entrance-transition>
<t-form-item label="入库备注" required-mark>
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-stock-batch-select">
<div class="tui-page-layout tui-navbar product-stock-batch-select">
<t-navbar
fixed
:z-index="20"
@@ -19,7 +19,7 @@
/>
</template>
</t-navbar>
<main v-can="permissionCodes.productStock.create" class="page-content scroll column list">
<main v-can="permissionCodes.productStock.create" class="tui-page-content scroll column list">
<t-pull-down-refresh
class="list-wrap empty-cell-title-margin pull-refresh"
v-model="isRefreshing"
@@ -385,7 +385,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-stock-batch-select {
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
.list-wrap {
+40 -4
View File
@@ -1,13 +1,13 @@
<template>
<div class="page-layout navbar">
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
title="库存详情"
left-arrow
@left-click="$router.back()"
@left-click="goBack"
/>
<main class="page-content scroll column">
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.productStock.read" class="product-stock-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-else-if="product && sku && stock">
@@ -109,6 +109,7 @@
<script setup lang="ts">
import { shallowRef } from "vue";
import { useExpandToMaster, usePane } from "timi-tdesign-mobile";
import { useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import ProductProfile from "@/pages/product/component/ProductProfile.vue";
@@ -125,8 +126,43 @@ type ManualStockOperation = Extract<StockOperationType, "MANUAL_IN" | "MANUAL_OU
defineOptions({ name: "ProductStockDetail" });
const props = withDefaults(defineProps<{
/** 指定 SKU ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
skuId?: string;
/** 所属产品 ID,整页详情转回分栏时用来定位 SKU 列表。 */
productId?: string;
}>(), {
skuId: "",
productId: ""
});
const route = useRoute();
const router = useRouter();
/** 内联渲染时 id 来自 prop,整页渲染时来自路由参数。 */
function resolveId(): string {
return props.skuId || String(route.params.skuId || "");
}
// 竖屏整页详情转横屏:回到 SKU 列表并把选中项还原到右栏。
// 没带 productId(从别处跳进来)时不动,避免落到无效的列表路径
const masterProductId = props.productId || String(route.query.productId || "");
useExpandToMaster({
path: `/management/product-stocks/${masterProductId}/skus`,
id: () => (masterProductId ? resolveId() : "")
});
/** 非空说明当前被内联在主从分栏的右栏里。 */
const pane = usePane();
function goBack(): void {
if (pane) {
pane.close();
return;
}
void router.back();
}
const userStore = useUserStore();
const product = ref<Product>();
const sku = ref<ProductSku>();
@@ -190,7 +226,7 @@ function selectUnit(unitId: string): void {
}
async function loadAll(): Promise<void> {
const skuId = String(route.params.skuId || "");
const skuId = resolveId();
if (!skuId) {
return;
}
+3 -3
View File
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-stock-list">
<div class="tui-page-layout tui-navbar product-stock-list">
<t-navbar
fixed
:z-index="20"
@@ -18,7 +18,7 @@
/>
</template>
</t-navbar>
<main ref="productStockListRef" v-can="permissionCodes.productStock.read" class="page-content scroll column list">
<main ref="productStockListRef" v-can="permissionCodes.productStock.read" class="tui-page-content scroll column list">
<t-pull-down-refresh
class="list-wrap empty-cell-title-margin pull-refresh"
v-model="isRefreshing"
@@ -364,7 +364,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-stock-list {
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
.list-wrap {
+36 -6
View File
@@ -1,13 +1,13 @@
<template>
<div class="page-layout navbar">
<div class="tui-page-layout tui-navbar">
<t-navbar
fixed
:z-index="20"
title="库存流水详情"
left-arrow
@left-click="$router.back()"
@left-click="goBack"
/>
<main class="page-content scroll column">
<main class="tui-page-content scroll column">
<div v-can="permissionCodes.productStock.read" class="product-stock-record-detail">
<t-loading v-if="isLoading" class="loading" size="32px" />
<template v-else-if="record">
@@ -135,7 +135,7 @@
</template>
<script setup lang="ts">
import { BottomPopup } from "timi-tdesign-mobile";
import { BottomPopup, useExpandToMaster, usePane } from "timi-tdesign-mobile";
import { TimeLabel } from "timi-web";
import { useUserStore, type Attachment } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
@@ -154,8 +154,38 @@ import type { PhotoItem } from "@/types/Photo";
defineOptions({ name: "ProductStockRecordDetail" });
const props = withDefaults(defineProps<{
/** 指定库存流水 ID 时忽略路由参数,用于平板主从分栏的内联渲染。 */
recordId?: string;
}>(), {
recordId: ""
});
const route = useRoute();
const router = useRouter();
/** 内联渲染时 id 来自 prop,整页渲染时来自路由参数 */
function resolveId(): string {
return props.recordId || String(route.params.id || "");
}
// 竖屏整页进来后转成横屏:回到列表页并恢复右栏选中,而不是继续停在整页详情
useExpandToMaster({
path: "/management/product-stock-records",
id: () => resolveId()
});
/** 非空说明当前被内联在主从分栏的右栏里 */
const pane = usePane();
function goBack(): void {
if (pane) {
pane.close();
return;
}
void router.back();
}
const userStore = useUserStore();
const record = ref<StockRecord>();
const baseUnitName = ref("");
@@ -291,7 +321,7 @@ async function submitManualRevoke(): Promise<void> {
}
async function loadData(): Promise<void> {
const id = String(route.params.id || "");
const id = resolveId();
if (!id) {
return;
}
@@ -319,7 +349,7 @@ onMounted(async () => {
await loadData();
});
watch(() => String(route.params.id || ""), async (id, previousId) => {
watch(resolveId, async (id, previousId) => {
if (id && id !== previousId) {
await loadData();
}
+175 -169
View File
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-stock-record-list">
<div class="tui-page-layout tui-navbar product-stock-record-list">
<t-navbar
fixed
:z-index="20"
@@ -7,161 +7,175 @@
left-arrow
@left-click="handleNavBarBack"
/>
<main v-can="permissionCodes.productStock.read" class="page-content scroll column list">
<t-pull-down-refresh
class="pull-refresh has-dropdown-menu-navbar"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<dropdown-menu-navbar
v-model="keyword"
:filters="dropdownFilters"
placeholder="搜索产品名称(拼音)或编码"
@filter-change="handleFilterChange"
<master-detail-page
v-can="permissionCodes.productStock.read"
class="list"
:split="isWide"
:selected="!!selectedId"
:direction="paneDirection"
>
<template #master>
<t-pull-down-refresh
class="pull-refresh has-dropdown-menu-navbar"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<template #suffix-icon>
<div class="actions">
<t-button
size="extra-small"
theme="primary"
variant="outline"
content="选择产品"
@click.stop="productSelectorVisible = true"
/>
</div>
</template>
</dropdown-menu-navbar>
<div class="list-wrap">
<t-cell-group v-if="isCustomDate || filteredSku" class="summary" theme="card">
<template v-if="isCustomDate">
<t-cell
title="开始时间"
:note="dateRange[0] || '-'"
arrow
@click="openStartTime"
/>
<t-cell
title="结束时间"
:note="dateRange[1] || '-'"
arrow
@click="openEndTime"
/>
</template>
<template v-if="filteredSku">
<t-cell title="累计入库" :note="getStockSummaryText(inBaseQuantityTotal)" />
<t-cell title="累计出库" :note="getStockSummaryText(outBaseQuantityTotal)" />
</template>
</t-cell-group>
<t-cell-group v-if="filteredProduct && filteredSku" theme="card">
<t-cell class="sku">
<template #leftIcon>
<t-image
v-if="filteredSkuPhotoURL"
class="avatar"
:src="filteredSkuPhotoURL"
:alt="filteredProduct.name || '产品图片'"
fit="cover"
/>
<div
v-else
class="fallback"
v-text="(filteredProduct.name || filteredProduct.code || '产').slice(0, 1)"
/>
</template>
<template #title>
<div class="title">
<strong class="text-bold clip-text" v-text="filteredProduct.name || '未命名产品'" />
<product-sku-tags
v-if="filteredSku.specValueIdList?.length"
:product-name="filteredProduct.name"
:snapshot="filteredSkuSnapshot"
:fallback="filteredSku.specSummary || filteredSku.name"
/>
</div>
</template>
<template #note>
<t-tag
variant="light-outline"
<dropdown-menu-navbar
v-model="keyword"
:filters="dropdownFilters"
placeholder="搜索产品名称(拼音)或编码"
@filter-change="handleFilterChange"
>
<template #suffix-icon>
<div class="actions">
<t-button
size="extra-small"
theme="primary"
:content="getProductTypeText(filteredProduct.productType)"
variant="outline"
content="选择产品"
@click.stop="productSelectorVisible = true"
/>
</div>
</template>
</t-cell>
</t-cell-group>
<t-cell-group v-if="recordList.length" class="list empty-cell-title-margin" theme="card">
<t-cell
v-for="(record, index) in recordList"
:key="record.id || `${record.occurredAt}-${record.requestNo}-${index}`"
class="item"
:arrow="!!record.id"
:hover="!!record.id"
v-entrance-transition="{ step: 30 }"
@click="toDetail(record)"
>
<template #leftIcon>
<t-image
v-if="getCustomerPhotoURL(record.customer, 64)"
:src="getCustomerPhotoURL(record.customer, 64)"
:alt="getCustomerText(record)"
fit="cover"
class="avatar"
/>
<div
v-else-if="record.customer"
class="avatar fallback"
v-text="getCustomerText(record).slice(0, 1)"
/>
<t-image
v-else-if="record.operator"
:src="getOperatorAvatar(record)"
:alt="getOperatorText(record)"
fit="cover"
class="avatar"
/>
<span v-else class="icon" :class="getDeltaClass(record.onHandDelta)">
<t-icon :name="getOperationIcon(record.operationType)" size="1.25rem" />
</span>
</template>
<template #title>
<div class="title">
<span v-if="record.customer" class="actor" v-text="getCustomerText(record)" />
<span v-else-if="record.operator" class="actor" v-text="getOperatorText(record)" />
<strong class="operation" :class="getOperationClass(record.operationType)" v-text="getStockOperationText(record.operationType)" />
<strong class="product-name clip-text" v-text="record.productNameSnapshot || '未命名产品'" />
<t-tag
v-if="record.productNameSnapshot !== record.skuNameSnapshot"
size="small"
:content="record.skuNameSnapshot"
</dropdown-menu-navbar>
<div class="list-wrap">
<t-cell-group v-if="isCustomDate || filteredSku" class="summary" theme="card">
<template v-if="isCustomDate">
<t-cell
title="开始时间"
:note="dateRange[0] || '-'"
arrow
@click="openStartTime"
/>
<span
v-if="record.quantity !== undefined && record.quantity !== null && record.quantity !== ''"
class="quantity"
v-text="getStockQuantityText(record)"
<t-cell
title="结束时间"
:note="dateRange[1] || '-'"
arrow
@click="openEndTime"
/>
</div>
</template>
<template #description>
<div class="description">
<time-label :timestamp="record.occurredAt" underline />
<div class="delta">
<span>库存:</span>
<span
class="value"
:class="getDeltaClass(record.onHandDelta)"
v-text="getDeltaText(record.onHandDelta)"
</template>
<template v-if="filteredSku">
<t-cell title="累计入库" :note="getStockSummaryText(inBaseQuantityTotal)" />
<t-cell title="累计出库" :note="getStockSummaryText(outBaseQuantityTotal)" />
</template>
</t-cell-group>
<t-cell-group v-if="filteredProduct && filteredSku" theme="card">
<t-cell class="sku">
<template #leftIcon>
<t-image
v-if="filteredSkuPhotoURL"
class="avatar"
:src="filteredSkuPhotoURL"
:alt="filteredProduct.name || '产品图片'"
fit="cover"
/>
</div>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="recordList.length" :content="loadStateText" />
</div>
</t-pull-down-refresh>
</main>
<div
v-else
class="fallback"
v-text="(filteredProduct.name || filteredProduct.code || '产').slice(0, 1)"
/>
</template>
<template #title>
<div class="title">
<strong class="text-bold clip-text" v-text="filteredProduct.name || '未命名产品'" />
<product-sku-tags
v-if="filteredSku.specValueIdList?.length"
:product-name="filteredProduct.name"
:snapshot="filteredSkuSnapshot"
:fallback="filteredSku.specSummary || filteredSku.name"
/>
</div>
</template>
<template #note>
<t-tag
variant="light-outline"
theme="primary"
:content="getProductTypeText(filteredProduct.productType)"
/>
</template>
</t-cell>
</t-cell-group>
<t-cell-group v-if="recordList.length" class="list empty-cell-title-margin" theme="card">
<t-cell
v-for="(record, index) in recordList"
:key="record.id || `${record.occurredAt}-${record.requestNo}-${index}`"
class="item"
:arrow="!!record.id"
:hover="!!record.id"
v-entrance-transition="{ step: 30 }"
@click="toDetail(record)"
>
<template #leftIcon>
<t-image
v-if="getCustomerPhotoURL(record.customer, 64)"
:src="getCustomerPhotoURL(record.customer, 64)"
:alt="getCustomerText(record)"
fit="cover"
class="avatar"
/>
<div
v-else-if="record.customer"
class="avatar fallback"
v-text="getCustomerText(record).slice(0, 1)"
/>
<t-image
v-else-if="record.operator"
:src="getOperatorAvatar(record)"
:alt="getOperatorText(record)"
fit="cover"
class="avatar"
/>
<span v-else class="icon" :class="getDeltaClass(record.onHandDelta)">
<t-icon :name="getOperationIcon(record.operationType)" size="1.25rem" />
</span>
</template>
<template #title>
<div class="title">
<span v-if="record.customer" class="actor" v-text="getCustomerText(record)" />
<span v-else-if="record.operator" class="actor" v-text="getOperatorText(record)" />
<strong class="operation" :class="getOperationClass(record.operationType)" v-text="getStockOperationText(record.operationType)" />
<strong class="product-name clip-text" v-text="record.productNameSnapshot || '未命名产品'" />
<t-tag
v-if="record.productNameSnapshot !== record.skuNameSnapshot"
size="small"
:content="record.skuNameSnapshot"
/>
<span
v-if="record.quantity !== undefined && record.quantity !== null && record.quantity !== ''"
class="quantity"
v-text="getStockQuantityText(record)"
/>
</div>
</template>
<template #description>
<div class="description">
<time-label :timestamp="record.occurredAt" underline />
<div class="delta">
<span>库存:</span>
<span
class="value"
:class="getDeltaClass(record.onHandDelta)"
v-text="getDeltaText(record.onHandDelta)"
/>
</div>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="recordList.length" :content="loadStateText" />
</div>
</t-pull-down-refresh>
</template>
<template #detail>
<product-stock-record-detail
:key="`detail-${selectedId}-${detailVersion}`"
:record-id="selectedId"
/>
</template>
</master-detail-page>
<product-select-popup
v-model="selectedProductSku"
v-model:visible="productSelectorVisible"
@@ -196,10 +210,12 @@
<script setup lang="ts">
import { type DropdownValue } from "tdesign-mobile-vue";
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
import { TimeLabel, Time } from "timi-web";
import { UserAPI } from "timi-web-api";
import { onBeforeRouteLeave } from "vue-router";
import ProductAPI from "@/api/ProductAPI";
import ProductStockRecordDetail from "@/pages/product/ProductStockRecordDetail.vue";
import ProductSelectPopup from "@/components/productSelector/ProductSelectPopup.vue";
import ProductSkuTags from "@/components/ProductSkuTags.vue";
import type { ProductSkuSelectionValue } from "@/types/ProductSkuSelection";
@@ -221,6 +237,13 @@ type DirectionFilter = "ALL" | StockRecordDirection;
const pageSize = 15;
const route = useRoute();
// 选中项、切换方向、关闭逻辑、转屏、query 同步都在这里;库存流水没有内联编辑视图
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
path: "/management/product-stock-records",
detail: id => `/management/product-stock-records/${id}`
});
const pageNavBarBackTo = ref<string>();
const router = useRouter();
const recordList = ref<StockRecord[]>([]);
@@ -389,25 +412,8 @@ function getDeltaClass(value?: number | string): string {
return 0 < amount ? "positive" : amount < 0 ? "negative" : "gray";
}
async function toDetail(record: StockRecord): Promise<void> {
if (record.id) {
await router.push({
name: "ProductStockRecordDetail",
params: { id: record.id },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
}
function getCurrentRouteDepth(): number {
const transitionDepth = Array.isArray(route.query.transitionDepth)
? route.query.transitionDepth[0]
: route.query.transitionDepth;
const depth = Number(transitionDepth);
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
return depth;
}
return Number(route.meta.depth ?? 0);
function toDetail(record: StockRecord): void {
openDetail(record.id || "");
}
async function loadMore(force = false): Promise<void> {
@@ -671,7 +677,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-stock-record-list {
display: flex;
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
flex-direction: column;
.list-wrap {
+119 -111
View File
@@ -1,5 +1,5 @@
<template>
<div class="page-layout navbar product-stock-sku-list">
<div class="tui-page-layout tui-navbar product-stock-sku-list">
<t-navbar
fixed
:z-index="20"
@@ -7,104 +7,121 @@
left-arrow
@left-click="$router.back()"
/>
<main v-can="permissionCodes.productStock.read" class="page-content scroll column list">
<t-pull-down-refresh
class="list-wrap empty-cell-title-margin pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<div class="filters glass">
<t-input
v-model="keyword"
class="keyword"
type="search"
borderless
clearable
placeholder="搜索 SKU 名称、编码或规格"
/>
</div>
<div class="content">
<t-cell-group theme="card">
<t-cell title="产品" :note="product?.name" />
</t-cell-group>
<t-cell-group
v-if="skuStockList.length"
theme="card"
class="list fix-last-cell-line empty-cell-title-margin"
>
<t-cell
class="item"
v-for="item in skuStockList"
:key="item.skuId || item.id"
arrow
v-entrance-transition="{ step: 30 }"
@click="toDetail(item)"
<master-detail-page
v-can="permissionCodes.productStock.read"
class="list"
:split="isWide"
:selected="!!selectedId"
:direction="paneDirection"
>
<template #master>
<t-pull-down-refresh
class="list-wrap empty-cell-title-margin pull-refresh"
v-model="isRefreshing"
:refresh-timeout="30000"
@refresh="refresh"
@scrolltolower="loadMore"
>
<div class="filters glass">
<t-input
v-model="keyword"
class="keyword"
type="search"
borderless
clearable
placeholder="搜索 SKU 名称、编码或规格"
/>
</div>
<div class="content">
<t-cell-group theme="card">
<t-cell title="产品" :note="product?.name" />
</t-cell-group>
<t-cell-group
v-if="skuStockList.length"
theme="card"
class="list fix-last-cell-line empty-cell-title-margin"
>
<template #title>
<div class="title">
<strong v-text="item.sku?.name || '未命名 SKU 明细'" />
<div
v-if="getUnitList(item).length"
class="unit-options"
role="group"
:aria-label="`切换${item.sku?.name || 'SKU'}库存单位`"
>
<t-button
v-for="unit in getUnitList(item)"
:key="unit.id"
size="extra-small"
:theme="getSelectedUnit(item)?.id === unit.id ? 'primary' : 'default'"
:variant="getSelectedUnit(item)?.id === unit.id ? 'base' : 'outline'"
:aria-label="`切换到${unit.name || '未命名单位'}`"
:aria-pressed="getSelectedUnit(item)?.id === unit.id"
@click.stop="selectUnit(item, unit.id || '')"
<t-cell
class="item"
v-for="item in skuStockList"
:key="item.skuId || item.id"
arrow
v-entrance-transition="{ step: 30 }"
@click="toDetail(item)"
>
<template #title>
<div class="title">
<strong v-text="item.sku?.name || '未命名 SKU 明细'" />
<div
v-if="getUnitList(item).length"
class="unit-options"
role="group"
:aria-label="`切换${item.sku?.name || 'SKU'}库存单位`"
>
<span v-text="unit.name || '未命名单位'" />
</t-button>
<t-button
v-for="unit in getUnitList(item)"
:key="unit.id"
size="extra-small"
:theme="getSelectedUnit(item)?.id === unit.id ? 'primary' : 'default'"
:variant="getSelectedUnit(item)?.id === unit.id ? 'base' : 'outline'"
:aria-label="`切换到${unit.name || '未命名单位'}`"
:aria-pressed="getSelectedUnit(item)?.id === unit.id"
@click.stop="selectUnit(item, unit.id || '')"
>
<span v-text="unit.name || '未命名单位'" />
</t-button>
</div>
</div>
</div>
</template>
<template #leftIcon>
<t-image
v-if="getSkuPhotoURL(item)"
:src="getSkuPhotoURL(item)"
:alt="item.sku?.name || 'SKU 图片'"
fit="cover"
class="avatar"
/>
<div v-else class="avatar fallback" v-text="(item.sku?.name || 'S').slice(0, 1)" />
</template>
<template #description>
<div class="stock">
<span class="on-hand">
<span>库存</span>
<strong v-text="getStockQuantityText(item, item.onHandQuantity)" />
</span>
<span class="available">
<span>可用</span>
<strong v-text="getStockQuantityText(item, item.availableQuantity)" />
</span>
<span class="reserved">
<span>预占</span>
<strong v-text="getStockQuantityText(item, item.reservedQuantity)" />
</span>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="skuStockList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</div>
</t-pull-down-refresh>
</main>
</template>
<template #leftIcon>
<t-image
v-if="getSkuPhotoURL(item)"
:src="getSkuPhotoURL(item)"
:alt="item.sku?.name || 'SKU 图片'"
fit="cover"
class="avatar"
/>
<div v-else class="avatar fallback" v-text="(item.sku?.name || 'S').slice(0, 1)" />
</template>
<template #description>
<div class="stock">
<span class="on-hand">
<span>库存</span>
<strong v-text="getStockQuantityText(item, item.onHandQuantity)" />
</span>
<span class="available">
<span>可用</span>
<strong v-text="getStockQuantityText(item, item.availableQuantity)" />
</span>
<span class="reserved">
<span>预占</span>
<strong v-text="getStockQuantityText(item, item.reservedQuantity)" />
</span>
</div>
</template>
</t-cell>
</t-cell-group>
<center-tips v-else :content="emptyText" />
<center-tips v-if="skuStockList.length" :content="isLoading ? '正在加载更多' : isNoMore ? '已经到底了' : '上拉加载更多'" />
</div>
</t-pull-down-refresh>
</template>
<template #detail>
<product-stock-detail
:key="`detail-${selectedId}-${detailVersion}`"
:sku-id="selectedId"
:product-id="productId"
/>
</template>
</master-detail-page>
</div>
</template>
<script setup lang="ts">
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
import { useUserStore } from "timi-web-api";
import ProductAPI from "@/api/ProductAPI";
import ProductStockDetail from "@/pages/product/ProductStockDetail.vue";
import { getErrorMessage } from "@/utils/error";
import { convertBaseQuantityToPackageQuantity } from "@/utils/package";
import { getProductPhotoURL, getProductQuantityText } from "@/utils/product";
@@ -115,7 +132,6 @@ import type { Product, ProductSkuUnit, ProductStock } from "@/types/Product";
defineOptions({ name: "ProductStockSkuList" });
const router = useRouter();
const route = useRoute();
const userStore = useUserStore();
const keyword = ref("");
@@ -141,6 +157,14 @@ const emptyText = computed(() => {
return "该产品暂无启用库存管理的 SKU";
});
// ---------- 主从分栏 ----------
const { selectedId, detailVersion, paneDirection, isWide, openDetail } = useMasterDetailPane({
path: `/management/product-stocks/${productId.value}/skus`,
// 整页详情带上 productId,转回分栏时才知道该回到哪个产品的 SKU 列表
detail: id => `/management/product-stocks/${id}?productId=${encodeURIComponent(productId.value)}`
});
function getSkuPhotoURL(item: ProductStock): string {
return item.sku ? getProductPhotoURL(item.sku) : "";
}
@@ -191,17 +215,6 @@ let keywordTimer: number | undefined;
let requestToken = 0;
let suppressKeywordFetch = false;
function getCurrentRouteDepth(): number {
const transitionDepth = Array.isArray(route.query.transitionDepth)
? route.query.transitionDepth[0]
: route.query.transitionDepth;
const depth = Number(transitionDepth);
if (transitionDepth && Number.isInteger(depth) && 0 <= depth && depth <= 20) {
return depth;
}
return Number(route.meta.depth ?? 0);
}
async function fetch(reset = false): Promise<void> {
if (!reset && (isLoading.value || isNoMore.value)) {
return;
@@ -274,15 +287,10 @@ async function loadMore(): Promise<void> {
}
}
async function toDetail(item: ProductStock): Promise<void> {
if (!item.skuId) {
return;
function toDetail(item: ProductStock): void {
if (item.skuId) {
openDetail(item.skuId);
}
await router.push({
name: "ProductStockDetail",
params: { skuId: item.skuId },
query: { transitionDepth: String(getCurrentRouteDepth() + 1) }
});
}
onMounted(async () => {
@@ -322,7 +330,7 @@ onUnmounted(() => {
<style scoped lang="less">
.product-stock-sku-list {
padding: var(--app-nav-height) 0 1rem;
padding: var(--tui-nav-height) 0 1rem;
.list-wrap {
@@ -59,7 +59,11 @@
<t-input v-model.trim="sku.name" borderless maxlength="128" placeholder="如 黑色运动鞋;男;36" />
</t-form-item>
<t-form-item label="SKU 条码">
<t-input v-model.trim="sku.barcode" borderless maxlength="64" placeholder="选填" />
<t-input
:model-value="sku.barcode ?? ''"
@update:model-value="value => sku.barcode = String(value).trim()"
borderless maxlength="64" placeholder="选填"
/>
</t-form-item>
<t-form-item label="库存管理" content-align="right">
<t-switch v-model="sku.stockEnabled" size="small" :disabled="props.productType === 'SERVICE'" />
@@ -74,7 +78,11 @@
<t-switch :model-value="sku.status === 'ACTIVE'" size="small" @change="setSkuStatus" />
</t-form-item>
<t-form-item label="备注">
<t-input v-model.trim="sku.remark" borderless maxlength="255" placeholder="选填" />
<t-input
:model-value="sku.remark ?? ''"
@update:model-value="value => sku.remark = String(value).trim()"
borderless maxlength="255" placeholder="选填"
/>
</t-form-item>
<div class="photo-wrap">
<attachment-selector