add ai chat entry

This commit is contained in:
Timi
2026-11-04 14:17:32 +08:00
parent aa1edd4056
commit 7067c63d46
4 changed files with 105 additions and 9 deletions
+57 -1
View File
@@ -8,6 +8,29 @@
:hide-nav="!tabBarStore.isShowing" :hide-nav="!tabBarStore.isShowing"
@change="onChangeTab" @change="onChangeTab"
> >
<template #rail-extra>
<t-button
class="ai-entry"
:class="{ on: route.path.startsWith('/management/help') }"
:aria-current="route.path.startsWith('/management/help') ? 'page' : undefined"
variant="text"
@click="router.push('/management/help')"
>
<t-icon name="file-1" size="1.375rem" />
<span>使用说明</span>
</t-button>
<t-button
v-if="userStore.hasRoles(gaoRoleCodes.storeManager)"
class="ai-entry"
:class="{ on: route.name === 'AiChat' }"
:aria-current="route.name === 'AiChat' ? 'page' : undefined"
variant="text"
@click="router.push('/ai/chat')"
>
<t-icon name="robot-2" size="1.375rem" />
<span>AI 小糕</span>
</t-button>
</template>
<page-transition <page-transition
:keep-alive="shouldKeepAlive" :keep-alive="shouldKeepAlive"
:page-background="globalUIStore.bodyBackground" :page-background="globalUIStore.bodyBackground"
@@ -20,7 +43,7 @@
import { AppShell, PageTransition, useLayout } from "timi-tdesign-mobile"; import { AppShell, PageTransition, useLayout } from "timi-tdesign-mobile";
import { useGlobalUIStore } from "@/store/globalUI"; import { useGlobalUIStore } from "@/store/globalUI";
import { useTabBarStore } from "@/store/tabBarStore"; import { useTabBarStore } from "@/store/tabBarStore";
import { permissionCodes } from "@/utils/permission"; import { gaoRoleCodes, permissionCodes } from "@/utils/permission";
import { useUserStore } from "timi-web-api/store"; import { useUserStore } from "timi-web-api/store";
import type { RouteLocationNormalizedLoaded } from "vue-router"; import type { RouteLocationNormalizedLoaded } from "vue-router";
@@ -117,6 +140,10 @@ async function syncVisibleTab(): Promise<void> {
watch(list, syncVisibleTab, { immediate: true }); watch(list, syncVisibleTab, { immediate: true });
function resolveTabValue(path: string): string { function resolveTabValue(path: string): string {
if (railVisible.value && path.startsWith("/management/help")) {
return path;
}
if (path.startsWith("/customers")) { if (path.startsWith("/customers")) {
return "/customers"; return "/customers";
} }
@@ -176,3 +203,32 @@ const pageClass = computed(() => ({
})); }));
</script> </script>
<style scoped lang="less">
.ai-entry {
--td-button-border-radius: var(--tui-rail-item-radius, .75rem);
width: calc(100% - 1.25rem);
height: auto;
display: flex;
margin: .125rem .625rem;
padding: var(--tui-rail-item-padding, .75rem 0);
color: var(--td-text-color-secondary);
font-size: var(--tui-rail-item-font-size, .75rem);
line-height: 1.4;
flex-direction: column;
:deep(.t-button__content) {
gap: .25rem;
display: flex;
align-items: center;
flex-direction: column;
}
&.on {
color: var(--tui-rail-active-color, var(--td-brand-color));
font-weight: 600;
background: var(--tui-rail-active-background, var(--td-brand-color-light));
}
}
</style>
+4 -1
View File
@@ -8,7 +8,7 @@
> >
<template #right> <template #right>
<t-button <t-button
v-if="canUseAi" v-if="canUseAi && !railVisible"
:disabled="aiChatPanelRef?.isBusy" :disabled="aiChatPanelRef?.isBusy"
@click="aiChatPanelRef?.openConversationList()" @click="aiChatPanelRef?.openConversationList()"
theme="primary" theme="primary"
@@ -21,6 +21,7 @@
<div v-if="canUseAi" class="ai-chat-page"> <div v-if="canUseAi" class="ai-chat-page">
<ai-chat-panel <ai-chat-panel
ref="aiChatPanel" ref="aiChatPanel"
:split="railVisible"
:store-name="currentStoreStore.currentStoreName" :store-name="currentStoreStore.currentStoreName"
:session-key="sessionKey" :session-key="sessionKey"
:store-id="aiStoreId" :store-id="aiStoreId"
@@ -30,6 +31,7 @@
<t-empty v-else description="当前账号无权使用门店智能助手" /> <t-empty v-else description="当前账号无权使用门店智能助手" />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { useLayout } from "timi-tdesign-mobile";
import { useUserStore } from "timi-web-api/store"; import { useUserStore } from "timi-web-api/store";
import AiChatPanel from "@/pages/ai/components/AiChatPanel.vue"; import AiChatPanel from "@/pages/ai/components/AiChatPanel.vue";
import { useCurrentStoreStore } from "@/store/currentStoreStore"; import { useCurrentStoreStore } from "@/store/currentStoreStore";
@@ -39,6 +41,7 @@ defineOptions({
name: "AiChatPage" name: "AiChatPage"
}); });
const { railVisible } = useLayout({ tablet: true });
const userStore = useUserStore(); const userStore = useUserStore();
const currentStoreStore = useCurrentStoreStore(); const currentStoreStore = useCurrentStoreStore();
const conversationResetToken = ref(0); const conversationResetToken = ref(0);
+27
View File
@@ -1,4 +1,15 @@
<template> <template>
<div class="chat-layout">
<ai-conversation-list
v-if="props.split"
:visible="true"
inline
:active-conversation-id="conversationId"
:disabled="isBusy"
:session-key="props.sessionKey"
@select="selectConversation"
@delete="handleConversationDelete"
/>
<shared-ai-chat-panel <shared-ai-chat-panel
ref="messageList" ref="messageList"
class="shared-panel" class="shared-panel"
@@ -61,6 +72,7 @@
</template> </template>
</shared-ai-chat-panel> </shared-ai-chat-panel>
<ai-conversation-list <ai-conversation-list
v-if="!props.split"
v-model:visible="conversationVisible" v-model:visible="conversationVisible"
:active-conversation-id="conversationId" :active-conversation-id="conversationId"
:disabled="isBusy" :disabled="isBusy"
@@ -68,6 +80,7 @@
@select="selectConversation" @select="selectConversation"
@delete="handleConversationDelete" @delete="handleConversationDelete"
/> />
</div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@@ -98,6 +111,7 @@ defineOptions({
}); });
interface Props { interface Props {
split?: boolean;
storeName: string; storeName: string;
sessionKey: string; sessionKey: string;
storeId?: string; storeId?: string;
@@ -430,3 +444,16 @@ onMounted(async () => {
} }
} }
</style> </style>
<style scoped lang="less">
.chat-layout {
height: 100%;
display: flex;
min-height: 0;
.shared-panel {
flex: 1;
min-width: 0;
}
}
</style>
+17 -7
View File
@@ -1,15 +1,17 @@
<template> <template>
<t-popup <component
:is="props.inline ? 'div' : TPopup"
v-model="popupVisible" v-model="popupVisible"
placement="right" placement="right"
destroy-on-close destroy-on-close
:z-index="popupZIndex" :z-index="popupZIndex"
:overlay-props="{ zIndex: popupZIndex - 1 }" :overlay-props="{ zIndex: popupZIndex - 1 }"
> >
<section class="ai-conversation-list" @scroll="handleScroll"> <section class="ai-conversation-list" :class="{ inline: props.inline }" @scroll="handleScroll">
<header class="header glass-header"> <header class="header glass-header">
<h3>历史会话</h3> <h3>历史会话</h3>
<t-button <t-button
v-if="!props.inline"
theme="danger" theme="danger"
shape="circle" shape="circle"
variant="text" variant="text"
@@ -77,11 +79,11 @@
/> />
</div> </div>
</section> </section>
</t-popup> </component>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { DialogPlugin } from "tdesign-mobile-vue"; import { DialogPlugin, Popup as TPopup } from "tdesign-mobile-vue";
import { deleteConversation as removeConversation, type GaoAiConversation, listConversations } from "@/api/GaoAiAPI"; import { deleteConversation as removeConversation, type GaoAiConversation, listConversations } from "@/api/GaoAiAPI";
import { getErrorMessage } from "@/utils/error"; import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message"; import { Message } from "@/utils/message";
@@ -93,6 +95,7 @@ defineOptions({
interface Props { interface Props {
visible: boolean; visible: boolean;
inline?: boolean;
activeConversationId: string; activeConversationId: string;
disabled: boolean; disabled: boolean;
sessionKey: string; sessionKey: string;
@@ -251,18 +254,18 @@ function formatConversationTime(conversation: GaoAiConversation): number {
return timestamp < 100000000000 ? timestamp * 1000 : timestamp; return timestamp < 100000000000 ? timestamp * 1000 : timestamp;
} }
watch(() => props.visible, async visible => { watch(() => props.inline || props.visible, async visible => {
if (visible) { if (visible) {
await reloadList(); await reloadList();
} }
}); }, { immediate: true });
watch(() => props.sessionKey, async () => { watch(() => props.sessionKey, async () => {
requestToken += 1; requestToken += 1;
conversationList.value = []; conversationList.value = [];
lastId.value = ""; lastId.value = "";
isNoMore.value = false; isNoMore.value = false;
if (props.visible) { if (props.inline || props.visible) {
await reloadList(); await reloadList();
} }
}); });
@@ -278,6 +281,13 @@ watch(() => props.sessionKey, async () => {
position: relative; position: relative;
flex-direction: column; flex-direction: column;
&.inline {
width: 18rem;
height: 100%;
padding: calc(var(--tui-nav-height) + .5rem) 0 0 0;
border-right: 1px solid var(--td-component-border);
}
.header { .header {
top: 0; top: 0;
z-index: 1; z-index: 1;