!20 Merge branch 'dev' into snow

Merge pull request !20 from 王瑞雪/snow
This commit is contained in:
sophie authored and Gitee committed 2026-09-29 05:13:46 +00:00
commit 2065b73610
56 files changed
+4501 -1110

No files matched your search

@@ -41,8 +41,13 @@ export function useChatScroll(options: UseChatScrollOptions) {
const stopContainerWatch = watch(container, syncScrollListener, { immediate: true });
/**
* 判断是否显示“回到最新消息”按钮。
* 核心逻辑:只要用户离开底部就提供入口;流式回复只有两条消息时同样需要可恢复跟随。
* @returns 用户是否正在查看历史内容。
*/
const showScrollToBottom = computed(() =>
messages.value.length >= 4 && !isNearBottom.value,
messages.value.length > 0 && !isNearBottom.value,
);
const scrollToBottom = async () => {
@@ -118,9 +123,15 @@ export function useChatScroll(options: UseChatScrollOptions) {
stopContainerWatch();
};
/** 消息/思考态变化时自动滚动(思考结束滚到用户问题,否则贴底) */
/**
* 监听流式消息与会话状态,决定是否继续贴底跟随。
* 核心逻辑:用户在底部时显示最新生成内容;用户手动向上阅读后停止自动滚动,
* 直到其主动点击“回到最新消息”。
* @param isThinking - 当前回复是否仍在生成,用于纳入监听依赖。
* @param conversationId - 当前会话标识,用于在切换会话后重新评估滚动状态。
* @returns 无返回值;监听会在 composable 卸载时自动清理。
*/
const setupThinkingScrollWatch = (isThinking: Ref<boolean>, conversationId?: Ref<string | null>) => {
let wasThinking = false;
watch(
() => ({
messageCount: messages.value.length,
@@ -130,14 +141,14 @@ export function useChatScroll(options: UseChatScrollOptions) {
conversationId: conversationId?.value || '',
}),
() => {
if (wasThinking && !isThinking.value) {
wasThinking = false;
void scrollToUserQuestion();
} else {
if (isThinking.value) wasThinking = true;
if (isNearBottom.value) scheduleScrollToBottom();
else window.requestAnimationFrame(updateNearBottomState);
// [STEP 1] 用户停留在底部时随新内容向下滚动;离开底部后保留阅读位置。
if (isNearBottom.value) {
scheduleScrollToBottom();
return;
}
// [STEP 2] 内容高度变化可能使“接近底部”状态恢复,重新计算但不主动移动视口。
window.requestAnimationFrame(updateNearBottomState);
},
{ deep: false },
);
@@ -12,6 +12,12 @@ describe('isStrongLeaveIntent', () => {
// 断言:规则咨询不应触发本地请假表单,应继续走 Dify 问答。
expect(isStrongLeaveIntent('年假可以按照小时请假吗?')).toBe(false);
expect(isStrongLeaveIntent('怎么请年假?年假可以按照小时请假吗?')).toBe(false);
// 断言:扣薪/薪资计算属于知识库制度问答,不应弹出请假申请表单。
expect(isStrongLeaveIntent('请假扣多少薪资')).toBe(false);
expect(isStrongLeaveIntent('请假如何扣除薪资')).toBe(false);
expect(isStrongLeaveIntent('请病假怎么扣钱')).toBe(false);
expect(isStrongLeaveIntent('请假扣多少钱,计算公式是什么')).toBe(false);
expect(isStrongLeaveIntent('薪资福利中的请假扣款怎么算')).toBe(false);
});
it('保留强请假意图触发表单', () => {
@@ -140,6 +140,10 @@ export function getLeaveIntentNormalized(content: string): string {
/** 区分「真请假」与「咨询流程/材料」类弱意图 */
export function isStrongLeaveIntent(content: string): boolean {
const normalized = getLeaveIntentNormalized(content);
// [STEP 1] 薪资/扣薪属于制度计算问答,必须交给 Dify/FAQ,不能被“请假”关键词抢先拦截为申请表单。
// [PROMPT_UPDATE] 保留知识库中的计算公式、适用条件和口径,由知识库回答而非前端自行生成。
const leaveSalaryConsultationIntent = /(请假|休假|年假|事假|病假).{0,12}(薪资|工资|薪酬|扣薪|扣钱|扣款|扣除|多少钱|福利|计算|公式)|(?:薪资|工资|薪酬|扣薪|扣钱|扣款|扣除|多少钱|福利|计算公式).{0,12}(请假|休假|年假|事假|病假)/;
if (leaveSalaryConsultationIntent.test(normalized)) return false;
const weakConsultationIntent = /(请假流程|请假怎么走|请假步骤|请假如何申请|请假如何走流程|请假怎么办|请假需要什么|请假规定|请假管理办法|请假制度)/;
const weakLeaveQuestionIntent = /((怎么|如何).{0,8}(请假|请年假|休假|休年假|年假)|(请假|年假|休假).{0,12}(可以|可否|能否|是否|支持).{0,8}(按小时|按照小时|小时请|小时休))/;
const materialConsultationIntent = /(提交哪些|提交什么|需要哪些|需要什么|要提交哪些|要提交什么|哪些资料|哪些材料|什么资料|什么材料|申请材料|所需资料|所需材料)/;