simple navbar action

This commit is contained in:
Timi
2026-10-22 16:17:22 +08:00
parent de8374db0b
commit 1eef8c6ea1
52 changed files with 358 additions and 5516 deletions
@@ -7,41 +7,14 @@
@left-click="$router.back()"
>
<template #right>
<div
v-if="pageNavBarRight.icon || pageNavBarRight.text"
class="nav-right-slot"
>
<t-badge
v-if="pageNavBarRight.icon && pageNavBarRight.badge !== undefined"
class="badge"
:count="pageNavBarRight.badge"
:max-count="99"
:show-zero="false"
>
<button class="button" type="button" :disabled="pageNavBarRight.disabled" @click="handlePageNavBarRightAction">
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
</t-badge>
<button
v-else-if="pageNavBarRight.icon"
class="button"
type="button"
:disabled="pageNavBarRight.disabled"
@click="handlePageNavBarRightAction"
>
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
</button>
<button
v-else
class="nav-text"
type="button"
:disabled="pageNavBarRight.disabled"
:style="{ color: pageNavBarRight.disabled ? 'var(--td-text-color-disabled)' : pageNavBarRight.textColor || 'var(--td-text-color-primary, #333)' }"
:class="{ clickable: !!pageNavBarRight.action, disabled: pageNavBarRight.disabled }"
@click="handlePageNavBarRightAction"
v-text="pageNavBarRight.text"
/>
</div>
<button
v-if="userStore.hasPermissions(permissionCodes.productStock.create)"
class="nav-action"
type="button"
:disabled="!canSubmit"
@click="submit"
v-text="isSaving ? '提交中' : '提交'"
></button>
</template>
</t-navbar>
<div v-can="permissionCodes.productStock.create" class="product-stock-batch-configure">
@@ -176,7 +149,6 @@
</template>
<script setup lang="ts">
import { onBeforeRouteLeave } from "vue-router";
import { useUserStore } from "timi-web-api";
import { useCurrentStoreStore } from "@/store/currentStoreStore";
import AttachmentSelector from "@/components/attachmentSelector/AttachmentSelector.vue";
@@ -191,40 +163,10 @@ import { permissionCodes } from "@/utils/permission";
import { getCurrentStoreId } from "@/utils/store";
import { uploadPhotoList } from "@/utils/photo";
const pageNavBarRight = reactive({
icon: "",
badge: undefined as number | undefined,
text: "",
textColor: "",
disabled: false,
action: undefined as (() => void | Promise<void>) | undefined
});
function setPageNavBarRightText(value?: string, color?: string, action?: () => void | Promise<void>): void {
pageNavBarRight.text = value || "";
pageNavBarRight.textColor = color || "";
pageNavBarRight.disabled = false;
pageNavBarRight.action = action;
if (value) {
pageNavBarRight.badge = undefined;
pageNavBarRight.icon = "";
}
}
function setPageNavBarRightDisabled(value: boolean): void {
pageNavBarRight.disabled = value;
}
function clearPageNavBarRight(): void {
Object.assign(pageNavBarRight, { icon: "", badge: undefined, text: "", textColor: "", disabled: false, action: undefined });
}
async function handlePageNavBarRightAction(): Promise<void> {
if (pageNavBarRight.disabled || !pageNavBarRight.action) {
return;
}
await pageNavBarRight.action();
}
import { type ProductStockBatchSelection, useProductStockBatchStore } from "@/store/productStockBatchStore";
@@ -331,14 +273,6 @@ function isItemValid(item: ProductStockBatchSelection): boolean {
&& 0 < (itemAttachmentList.length || globalAttachmentList.length);
}
function updateNavBar(): void {
clearPageNavBarRight();
if (!userStore.hasPermissions(permissionCodes.productStock.create)) {
return;
}
setPageNavBarRightText(isSaving.value ? "提交中" : "提交", "var(--td-brand-color)", submit);
setPageNavBarRightDisabled(!canSubmit.value);
}
function selectUnit(item: ProductStockBatchSelection, unit: ProductSkuUnit): void {
if (isSaving.value) {
@@ -466,7 +400,6 @@ async function submit(): Promise<void> {
return;
}
isSaving.value = true;
updateNavBar();
try {
await ProductAPI.manualInBatch(buildRequest());
emitListDataChanged(listDataEventKeys.productStockChanged);
@@ -480,11 +413,9 @@ async function submit(): Promise<void> {
Message.error(getErrorMessage(error, "批量入库失败,请确认请求号后重试"));
} finally {
isSaving.value = false;
updateNavBar();
}
}
watch([canSubmit, isSaving], updateNavBar);
onMounted(() => {
const storeId = currentStoreStore.currentStoreId || getCurrentStoreId();
@@ -493,7 +424,6 @@ onMounted(() => {
if (!productStockBatchStore.selectedItemList.length) {
void router.replace({ name: "ProductStockBatchSelect" });
}
updateNavBar();
});
onActivated(() => {
@@ -505,12 +435,9 @@ onActivated(() => {
return;
}
activeStoreId.value = storeId;
updateNavBar();
});
onBeforeRouteLeave(() => clearPageNavBarRight());
onUnmounted(() => clearPageNavBarRight());
</script>
<style scoped lang="less">
@@ -612,44 +539,4 @@ onUnmounted(() => clearPageNavBarRight());
}
.nav-right-slot {
width: 6rem;
height: 100%;
display: flex;
align-items: center;
justify-content: flex-end;
.badge {
:deep(.t-badge__content) {
display: flex;
align-items: center;
}
}
.button,
.nav-text {
color: var(--td-text-color-primary, #333);
border: none;
padding: 0;
display: inline-flex;
background: transparent;
align-items: center;
justify-content: center;
}
.button {
&:disabled {
color: var(--td-text-color-disabled);
cursor: not-allowed;
}
}
.nav-text {
font: inherit;
cursor: default;
&.clickable { cursor: pointer; }
&.disabled { cursor: not-allowed; }
}
}
</style>