feat: recycle system
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
class="list"
|
||||
:split="isWide"
|
||||
:selected="!!selectedId"
|
||||
:direction="paneDirection"
|
||||
:direction="paneTransitionDirection"
|
||||
>
|
||||
<template #master>
|
||||
<t-pull-down-refresh
|
||||
@@ -115,7 +115,13 @@
|
||||
</t-pull-down-refresh>
|
||||
</template>
|
||||
<template #detail>
|
||||
<product-edit v-if="selectedId === createPaneId" :key="createPaneId" />
|
||||
<product-sku-detail
|
||||
v-if="showingSkuDetail"
|
||||
:key="`${skuDetailProductId}-${skuDetailId}`"
|
||||
:product-id="skuDetailProductId"
|
||||
:sku-id="skuDetailId"
|
||||
/>
|
||||
<product-edit v-else-if="selectedId === createPaneId" :key="createPaneId" />
|
||||
<product-edit
|
||||
v-else-if="editing"
|
||||
:key="`edit-${selectedId}`"
|
||||
@@ -135,9 +141,10 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { type DropdownValue } from "tdesign-mobile-vue";
|
||||
import { MasterDetailPage, useMasterDetailPane } from "timi-tdesign-mobile";
|
||||
import { MasterDetailPage, useMasterDetailPane, type PaneDirection } from "timi-tdesign-mobile";
|
||||
import ProductDetail from "@/pages/product/ProductDetail.vue";
|
||||
import ProductEdit from "@/pages/product/ProductEdit.vue";
|
||||
import ProductSkuDetail from "@/pages/product/ProductSkuDetail.vue";
|
||||
import { useUserStore } from "timi-web-api";
|
||||
import { onBeforeRouteLeave } from "vue-router";
|
||||
import ProductAPI from "@/api/ProductAPI";
|
||||
@@ -158,10 +165,32 @@ const route = useRoute();
|
||||
const createPaneId = "__create__";
|
||||
const { selectedId, editing, detailVersion, paneDirection, isWide, openDetail, openEdit } =
|
||||
useMasterDetailPane({
|
||||
path: "/management/products",
|
||||
detail: id => id === createPaneId ? "/management/products/create" : `/management/products/${id}`,
|
||||
edit: id => `/management/products/${id}/edit`
|
||||
path: "/product/products",
|
||||
detail: id => id === createPaneId ? "/product/products/create" : `/product/products/${id}`,
|
||||
edit: id => `/product/products/${id}/edit`
|
||||
});
|
||||
const skuDetailProductId = computed(() => String(route.query.skuProductId || ""));
|
||||
const skuDetailId = computed(() => String(route.query.skuId || ""));
|
||||
const showingSkuDetail = computed(() => !!skuDetailId.value && skuDetailProductId.value === selectedId.value);
|
||||
const paneTransitionDirection = ref<PaneDirection>(paneDirection.value || "forward");
|
||||
|
||||
watch(paneDirection, direction => {
|
||||
if (direction) {
|
||||
paneTransitionDirection.value = direction;
|
||||
}
|
||||
});
|
||||
|
||||
watch([skuDetailProductId, skuDetailId], ([productId, skuId], [previousProductId, previousSkuId]) => {
|
||||
const wasSkuDetail = !!previousSkuId && previousProductId === selectedId.value;
|
||||
const isSkuDetail = !!skuId && productId === selectedId.value;
|
||||
if (!wasSkuDetail && isSkuDetail) {
|
||||
paneTransitionDirection.value = "forward";
|
||||
} else if (wasSkuDetail && !isSkuDetail) {
|
||||
paneTransitionDirection.value = "back";
|
||||
} else if (wasSkuDetail && isSkuDetail && previousSkuId !== skuId) {
|
||||
paneTransitionDirection.value = "none";
|
||||
}
|
||||
});
|
||||
const productListRef = ref<ComponentPublicInstance | null>(null);
|
||||
const userStore = useUserStore();
|
||||
const canCreate = computed(() => userStore.hasPermissions(permissionCodes.product.create));
|
||||
@@ -419,10 +448,20 @@ async function toCreate(): Promise<void> {
|
||||
openDetail(createPaneId);
|
||||
return;
|
||||
}
|
||||
await router.push("/management/products/create");
|
||||
await router.push("/product/products/create");
|
||||
}
|
||||
|
||||
async function toDetail(item: Product): Promise<void> {
|
||||
if (route.query.skuId || route.query.skuProductId) {
|
||||
await router.replace({
|
||||
path: route.path,
|
||||
query: {
|
||||
...route.query,
|
||||
skuProductId: undefined,
|
||||
skuId: undefined
|
||||
}
|
||||
});
|
||||
}
|
||||
openDetail(item.id || "");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user