fix(mobile): preserve assistant IDs and scope state
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
<text class="domain-name">我的资料</text>
|
||||
<text class="domain-desc">个人收藏,仅自己可见</text>
|
||||
</button>
|
||||
<button class="domain-option" :class="{ active: enterpriseEnabled }" @click="toggleEnterprise">
|
||||
<button class="domain-option" :class="{ active: enterpriseEnabled }" :disabled="asking" @click="changeScope">
|
||||
<text class="domain-name">企业知识</text>
|
||||
<text class="domain-desc">企业知识按岗位权限</text>
|
||||
</button>
|
||||
@@ -68,6 +68,7 @@
|
||||
import { computed, ref } from 'vue';
|
||||
import type { PersonalAskResponse, PersonalCitation } from '@/types/api';
|
||||
import { askPersonalAssistant, type KnowledgeScope } from '@/services/personal-assistant';
|
||||
import { personalItemRoute } from '@/services/personal-assistant-id';
|
||||
|
||||
const scopes = ref<KnowledgeScope[]>(['PERSONAL']);
|
||||
const queryText = ref('');
|
||||
@@ -77,7 +78,12 @@ const message = ref('');
|
||||
let requestGeneration = 0;
|
||||
const enterpriseEnabled = computed(() => scopes.value.includes('ENTERPRISE'));
|
||||
|
||||
const toggleEnterprise = () => {
|
||||
const scopeKey = (value: KnowledgeScope[]) => value.join(',');
|
||||
const changeScope = () => {
|
||||
if (asking.value) return;
|
||||
requestGeneration += 1;
|
||||
answer.value = undefined;
|
||||
message.value = '';
|
||||
scopes.value = enterpriseEnabled.value ? ['PERSONAL'] : ['PERSONAL', 'ENTERPRISE'];
|
||||
};
|
||||
|
||||
@@ -85,22 +91,24 @@ const submitQuestion = async () => {
|
||||
const question = queryText.value.trim();
|
||||
if (!question || asking.value) return;
|
||||
const generation = ++requestGeneration;
|
||||
const scopeSnapshot = [...scopes.value];
|
||||
asking.value = true;
|
||||
answer.value = undefined;
|
||||
message.value = '';
|
||||
try {
|
||||
const response = await askPersonalAssistant({ queryText: question, scope: scopes.value, outputFormat: 'ACTION_PLAN' });
|
||||
if (generation !== requestGeneration) return;
|
||||
const response = await askPersonalAssistant({ queryText: question, scope: scopeSnapshot, outputFormat: 'ACTION_PLAN' });
|
||||
if (generation !== requestGeneration || scopeKey(scopes.value) !== scopeKey(scopeSnapshot)) return;
|
||||
answer.value = response;
|
||||
} catch (error) {
|
||||
if (generation !== requestGeneration) return;
|
||||
const text = error instanceof Error ? error.message : '提问失败,请稍后重试';
|
||||
if (enterpriseEnabled.value && /ENTERPRISE_SCOPE_FORBIDDEN|企业知识|FORBIDDEN/i.test(text)) {
|
||||
scopes.value = ['PERSONAL'];
|
||||
const fallbackScope: KnowledgeScope[] = ['PERSONAL'];
|
||||
message.value = '当前岗位没有企业知识权限,已仅查询我的资料。';
|
||||
try {
|
||||
const personalResponse = await askPersonalAssistant({ queryText: question, scope: ['PERSONAL'], outputFormat: 'ACTION_PLAN' });
|
||||
if (generation !== requestGeneration) return;
|
||||
const personalResponse = await askPersonalAssistant({ queryText: question, scope: fallbackScope, outputFormat: 'ACTION_PLAN' });
|
||||
if (generation !== requestGeneration || scopeKey(scopes.value) !== scopeKey(fallbackScope)) return;
|
||||
answer.value = personalResponse;
|
||||
} catch (personalError) {
|
||||
if (generation !== requestGeneration) return;
|
||||
@@ -122,7 +130,7 @@ const citationLabel = (citation: PersonalCitation) => {
|
||||
|
||||
const openCitation = (citation: PersonalCitation) => {
|
||||
if (citation.domain !== 'PERSONAL' || !citation.itemId) return;
|
||||
uni.navigateTo({ url: `/pages/user/assistant/item?id=${citation.itemId}` });
|
||||
uni.navigateTo({ url: personalItemRoute(citation.itemId) });
|
||||
};
|
||||
|
||||
const goBack = () => uni.navigateBack();
|
||||
|
||||
Reference in New Issue
Block a user