feat(ai-assistant): 支持任务弹窗和对话弹窗的场景检测

- 在 page-context.js 的 getPageContext 和 getSceneKey 函数中优先检测弹窗状态
  - 当 taskId > 0 时使用 single-task 上下文
  - 当 dialogModalShow && dialogId > 0 时使用 single-dialog 上下文
  - 在 welcome-prompts.js 中添加弹窗场景检测逻辑
  - 提取 formatPrompts 辅助函数减少代码重复
  - 在 index.vue 的 welcomePromptsKey 中监听 taskId 和 dialogModalShow 变化
This commit is contained in:
kuaifan 2026-01-18 23:52:26 +00:00
parent 8eaba6f364
commit 2cb67fafe7
3 changed files with 54 additions and 10 deletions

View File

@ -301,7 +301,9 @@ export default {
const routeName = this.$store.state.routeName;
const dialogId = this.$store.state.dialogId;
const projectId = this.$store.getters.projectData?.id;
return `${routeName}|${dialogId}|${projectId}`;
const taskId = this.$store.state.taskId;
const dialogModalShow = this.$store.state.dialogModalShow;
return `${routeName}|${dialogId}|${projectId}|${taskId}|${dialogModalShow}`;
},
},
watch: {

View File

@ -14,6 +14,18 @@
* @returns {Object} { systemPrompt }
*/
export function getPageContext(store, routeParams = {}) {
// 优先检测弹窗场景
const taskId = store.state.taskId;
if (taskId > 0) {
return getSingleTaskContext(store, { taskId });
}
const dialogModalShow = store.state.dialogModalShow;
const dialogId = store.state.dialogId;
if (dialogModalShow && dialogId > 0) {
return getSingleDialogContext(store, { dialogId });
}
const routeName = store.state.routeName;
const contextMap = {
@ -324,6 +336,18 @@ function getDefaultContext() {
* @returns {string} 场景标识格式如 "routeName/entityType:entityId"
*/
export function getSceneKey(store, routeParams = {}) {
// 优先检测弹窗场景
const taskId = store.state.taskId;
if (taskId > 0) {
return `modal-task/task:${taskId}`;
}
const dialogModalShow = store.state.dialogModalShow;
const dialogId = store.state.dialogId;
if (dialogModalShow && dialogId > 0) {
return `modal-dialog/dialog:${dialogId}`;
}
const routeName = store.state.routeName;
const parts = [routeName || 'unknown'];

View File

@ -97,6 +97,20 @@ function getRandomItems(arr, count) {
return shuffled.slice(0, count);
}
/**
* 格式化提示词选择随机数量并转换为当前语言
* @param {Array} rawPrompts - 原始提示词列表
* @returns {Array} 格式化后的提示词列表 [{ text, svg }]
*/
function formatPrompts(rawPrompts) {
const displayCount = Math.floor(Math.random() * 4) + 3; // 3, 4, 5, 或 6
const selectedPrompts = selectPrompts(rawPrompts, displayCount);
return selectedPrompts.map(item => ({
text: getText(item.text),
svg: item.svg,
}));
}
/**
* 随机选择提示词优先展示 pin 提示并尽量避免重复类型
* @param {Array} rawPrompts - 提示词列表
@ -174,6 +188,18 @@ function selectPrompts(rawPrompts, count) {
* @returns {Array} 快捷提示列表 [{ text, svg }]随机显示 3-6
*/
export function getWelcomePrompts(store, routeParams = {}) {
// 优先检测弹窗场景
const taskId = store.state.taskId;
if (taskId > 0) {
return formatPrompts(getSingleTaskPrompts());
}
const dialogModalShow = store.state.dialogModalShow;
const dialogId = store.state.dialogId;
if (dialogModalShow && dialogId > 0) {
return formatPrompts(getSingleDialogPrompts());
}
const routeName = store.state.routeName;
const promptsMap = {
@ -196,15 +222,7 @@ export function getWelcomePrompts(store, routeParams = {}) {
const getPrompts = promptsMap[routeName];
const rawPrompts = getPrompts ? getPrompts(store, routeParams) : getDefaultPrompts(store);
// 随机选择 3-6 个提示词
const displayCount = Math.floor(Math.random() * 4) + 3; // 3, 4, 5, 或 6
const selectedPrompts = selectPrompts(rawPrompts, displayCount);
// 转换文本为当前语言
return selectedPrompts.map(item => ({
text: getText(item.text),
svg: item.svg,
}));
return formatPrompts(rawPrompts);
}
/**