front/src/components/customer-side-rail/CustomerPortalTopTools.vue
zzh bf6e7263fc
Some checks failed
Build and Deploy Front / deploy (push) Failing after 16m30s
refine: 客户工作台与侧栏体验,收件地图与统计分区,顺带 H5/官网样式调整
EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-03 12:24:48 +08:00

327 lines
7.9 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="cpt-tools" role="toolbar" aria-label="门户快捷工具">
<button
type="button"
class="cpt-tools__wh"
:title="warehouseTitle"
:aria-label="warehouseTitle"
@click="openWarehousePeek"
>
<icon-home class="cpt-tools__wh-ico" />
<span class="cpt-tools__wh-name">{{ warehouseName }}</span>
<icon-down class="cpt-tools__wh-caret" />
</button>
<div class="cpt-tools__actions">
<a-dropdown
trigger="click"
position="br"
content-class="csr-dock-dropdown"
:popup-translate="[0, 8]"
@visible-change="onMessageVisible"
>
<button
type="button"
class="cpt-tools__chip"
:class="{ 'is-hot': messageTotal > 0 }"
:title="t('navbar.message')"
:aria-label="t('navbar.message')"
>
<icon-notification class="cpt-tools__chip-ico" />
<span class="cpt-tools__chip-label">{{ t('navbar.message') }}</span>
<span v-if="messageTotal > 0" class="cpt-tools__chip-count">
{{ messageBadge }}
</span>
</button>
<template #content>
<a-doption @click="goInbox('message')">
{{ t('navbar.messageInbox') }}({{ notificationCount }})
</a-doption>
<a-doption @click="goInbox('notice')">
{{ t('navbar.messageNotice') }}({{ noticeCount }})
</a-doption>
</template>
</a-dropdown>
<a-dropdown
trigger="click"
position="br"
content-class="csr-dock-dropdown"
:popup-translate="[0, 8]"
>
<button
type="button"
class="cpt-tools__chip"
:class="{
'is-on': printConnectionState.enabled,
'is-busy': printConnectionState.connecting,
}"
:title="printConnectionTitle"
:aria-label="t('nav.printControl.menu')"
>
<icon-printer class="cpt-tools__chip-ico" />
<span class="cpt-tools__chip-label">打印</span>
<span
class="cpt-tools__chip-dot"
:class="{
'is-on': printConnectionState.enabled,
'is-busy': printConnectionState.connecting,
}"
aria-hidden="true"
/>
</button>
<template #content>
<a-doption
:disabled="printConnectionState.connecting"
@click="onPrintConnectionClick"
>
{{ printConnectionTitle }}
</a-doption>
<a-doption @click="onPrintDownloadClick">
{{ t('nav.printControl.download') }}
</a-doption>
</template>
</a-dropdown>
</div>
<WarehouseAddressPeekModal v-model:visible="warehousePeekVisible" />
</div>
</template>
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { Message } from '@arco-design/web-vue';
import {
IconDown,
IconHome,
IconNotification,
IconPrinter,
} from '@arco-design/web-vue/es/icon';
import { useCurrentWarehouseStore } from '@/store';
import { getWarehouseList } from '@/api/system/warehouse';
import {
initHiprintClientState,
setHiprintClientEnabled,
useHiprintClientState,
} from '@/utils/hiprint/hiprintClientState';
import { PRINT_CONTROL_DOWNLOAD_URL } from '@/constants/printControl';
import { useInboxUnread } from '@/composables/useInboxUnread';
import WarehouseAddressPeekModal from '@/components/customer-side-rail/WarehouseAddressPeekModal.vue';
defineOptions({ name: 'CustomerPortalTopTools' });
const { t } = useI18n();
const router = useRouter();
const warehouseStore = useCurrentWarehouseStore();
const printConnectionState = useHiprintClientState();
const { notificationCount, noticeCount, totalCount, displayCount, refreshUnread } =
useInboxUnread();
const warehousePeekVisible = ref(false);
const warehouseName = computed(
() => warehouseStore.warehouseName || t('nav.contactService.selectWarehouse'),
);
const warehouseTitle = computed(() =>
t('nav.warehousePeek.currentPrefix', { name: warehouseName.value }),
);
const printConnectionTitle = computed(() => {
if (printConnectionState.connecting) return '打印连接中…';
return printConnectionState.enabled ? '打印已连接,点击断开' : '打印未连接,点击连接';
});
const messageTotal = computed(() => totalCount.value);
const messageBadge = computed(() => displayCount.value);
function openWarehousePeek() {
warehousePeekVisible.value = true;
}
function onMessageVisible(visible: boolean) {
if (visible) refreshUnread();
}
function goInbox(noticeType: 'message' | 'notice') {
router.push({ name: 'SystemAnnouncement', query: { noticeType } });
}
async function ensureWarehouseOptions() {
try {
const { items } = await getWarehouseList({ page: 1, pageSize: 100 });
const list = (items ?? [])
.filter((row) => row.id != null)
.map((row) => ({
label: row.warehouseName || String(row.id),
value: Number(row.id),
}));
warehouseStore.setOptions(list);
} catch {
/* ignore */
}
}
async function onPrintConnectionClick() {
if (printConnectionState.connecting) return;
try {
await setHiprintClientEnabled(!printConnectionState.enabled);
} catch (e: any) {
Message.warning(`连接失败:${e?.message || '请先启动 hiprint 客户端'}`);
}
}
function onPrintDownloadClick() {
window.open(PRINT_CONTROL_DOWNLOAD_URL, '_blank', 'noopener,noreferrer');
}
onMounted(() => {
initHiprintClientState().catch(() => undefined);
void ensureWarehouseOptions();
void refreshUnread();
});
</script>
<style lang="less" scoped>
.cpt-tools {
--cpt-ink: #1a2e38;
--cpt-muted: rgba(26, 46, 56, 0.52);
--cpt-h: 30px;
display: inline-flex;
align-items: center;
gap: 4px;
flex-shrink: 0;
height: var(--cpt-h);
padding: 0;
}
.cpt-tools__wh {
display: inline-flex;
align-items: center;
gap: 6px;
max-width: 180px;
height: 100%;
padding: 0 10px 0 8px;
border: none;
border-radius: 8px;
background: transparent;
color: var(--cpt-ink);
cursor: pointer;
transition: background-color 0.14s ease;
&:hover {
background: rgba(26, 46, 56, 0.05);
}
}
.cpt-tools__wh-ico {
flex-shrink: 0;
font-size: 15px;
color: var(--cpt-muted);
}
.cpt-tools__wh-name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 13px;
font-weight: 500;
letter-spacing: -0.01em;
line-height: 1.2;
}
.cpt-tools__wh-caret {
flex-shrink: 0;
font-size: 11px;
color: var(--cpt-muted);
}
.cpt-tools__actions {
display: inline-flex;
align-items: center;
gap: 2px;
height: 100%;
}
.cpt-tools__chip {
display: inline-flex;
align-items: center;
gap: 6px;
height: 100%;
min-width: 0;
padding: 0 10px;
border: none;
border-radius: 8px;
background: transparent;
color: var(--cpt-muted);
cursor: pointer;
transition: color 0.14s ease, background-color 0.14s ease;
&:hover {
color: var(--cpt-ink);
background: rgba(26, 46, 56, 0.05);
}
&.is-hot {
color: var(--app-primary-color, #1d7281);
}
&.is-on {
color: var(--app-primary-color, #1d7281);
}
&.is-busy {
opacity: 0.55;
pointer-events: none;
}
}
.cpt-tools__chip-ico {
flex-shrink: 0;
font-size: 15px;
}
.cpt-tools__chip-label {
flex-shrink: 0;
font-size: 13px;
font-weight: 500;
line-height: 1;
color: inherit;
}
.cpt-tools__chip-count {
flex-shrink: 0;
min-width: 16px;
height: 16px;
padding: 0 4px;
border-radius: 8px;
background: #f53f3f;
color: #fff;
font-size: 11px;
font-weight: 600;
line-height: 16px;
text-align: center;
letter-spacing: -0.02em;
}
.cpt-tools__chip-dot {
flex-shrink: 0;
width: 6px;
height: 6px;
border-radius: 50%;
background: #c9cdd4;
&.is-on {
background: #00b42a;
}
&.is-busy {
background: #ff7d00;
}
}
</style>