mirror of
https://github.com/kuaifan/dootask.git
synced 2026-01-24 19:28:11 +00:00
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:
parent
8eaba6f364
commit
2cb67fafe7
@ -301,7 +301,9 @@ export default {
|
|||||||
const routeName = this.$store.state.routeName;
|
const routeName = this.$store.state.routeName;
|
||||||
const dialogId = this.$store.state.dialogId;
|
const dialogId = this.$store.state.dialogId;
|
||||||
const projectId = this.$store.getters.projectData?.id;
|
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: {
|
watch: {
|
||||||
|
|||||||
@ -14,6 +14,18 @@
|
|||||||
* @returns {Object} { systemPrompt }
|
* @returns {Object} { systemPrompt }
|
||||||
*/
|
*/
|
||||||
export function getPageContext(store, routeParams = {}) {
|
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 routeName = store.state.routeName;
|
||||||
|
|
||||||
const contextMap = {
|
const contextMap = {
|
||||||
@ -324,6 +336,18 @@ function getDefaultContext() {
|
|||||||
* @returns {string} 场景标识,格式如 "routeName/entityType:entityId"
|
* @returns {string} 场景标识,格式如 "routeName/entityType:entityId"
|
||||||
*/
|
*/
|
||||||
export function getSceneKey(store, routeParams = {}) {
|
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 routeName = store.state.routeName;
|
||||||
const parts = [routeName || 'unknown'];
|
const parts = [routeName || 'unknown'];
|
||||||
|
|
||||||
|
|||||||
@ -97,6 +97,20 @@ function getRandomItems(arr, count) {
|
|||||||
return shuffled.slice(0, 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 提示,并尽量避免重复类型
|
* 随机选择提示词:优先展示 pin 提示,并尽量避免重复类型
|
||||||
* @param {Array} rawPrompts - 提示词列表
|
* @param {Array} rawPrompts - 提示词列表
|
||||||
@ -174,6 +188,18 @@ function selectPrompts(rawPrompts, count) {
|
|||||||
* @returns {Array} 快捷提示列表 [{ text, svg }],随机显示 3-6 个
|
* @returns {Array} 快捷提示列表 [{ text, svg }],随机显示 3-6 个
|
||||||
*/
|
*/
|
||||||
export function getWelcomePrompts(store, routeParams = {}) {
|
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 routeName = store.state.routeName;
|
||||||
|
|
||||||
const promptsMap = {
|
const promptsMap = {
|
||||||
@ -196,15 +222,7 @@ export function getWelcomePrompts(store, routeParams = {}) {
|
|||||||
const getPrompts = promptsMap[routeName];
|
const getPrompts = promptsMap[routeName];
|
||||||
const rawPrompts = getPrompts ? getPrompts(store, routeParams) : getDefaultPrompts(store);
|
const rawPrompts = getPrompts ? getPrompts(store, routeParams) : getDefaultPrompts(store);
|
||||||
|
|
||||||
// 随机选择 3-6 个提示词
|
return 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,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user