feat(invoice-check): 立账凭证检核增加收件人配置并迁移到chat页面
This commit is contained in:
1 parent
18e957545c
commit
7b80b4c395
72 files changed
+2705
-263
No files matched your search
@@ -0,0 +1,153 @@
|
||||
<!--
|
||||
features/voucher-check/components/VoucherCheckChatPanel.vue
|
||||
用途:立账凭证 Chat 主区:检核任务 / 企微发送记录 / 通知配置 Tab,当前 Tab 内批次明细下钻。
|
||||
依赖:workspace 立账凭证列表与详情、VoucherCheckNotifyConfigPanel、voucherCheckChat.utils、vue-router query、auth.store。
|
||||
逻辑:由 ChatViewContent 在 agent_code=voucher_check 时替换消息列表与输入框;
|
||||
view / runId / runNo 写入 /chat/:agentId 查询参数;通知配置仅平台管理员可见可改。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import AccountingVoucherCheckDetailView from '@/features/workspace/views/AccountingVoucherCheckDetailView.vue';
|
||||
import AccountingVoucherCheckView from '@/features/workspace/views/AccountingVoucherCheckView.vue';
|
||||
import type { VoucherCheckChatView } from '../constants';
|
||||
import {
|
||||
buildVoucherCheckChatQuery,
|
||||
parseVoucherCheckChatQuery,
|
||||
} from '../utils/voucherCheckChat.utils';
|
||||
import VoucherCheckNotifyConfigPanel from './VoucherCheckNotifyConfigPanel.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const auth = useAuthStore();
|
||||
|
||||
const isAdmin = computed(() => Boolean(auth.isAdmin));
|
||||
const parsedQuery = computed(() => parseVoucherCheckChatQuery(
|
||||
route.query.view,
|
||||
route.query.runId,
|
||||
route.query.runNo,
|
||||
));
|
||||
const activeView = computed<VoucherCheckChatView>(() => parsedQuery.value.view);
|
||||
const detailRunId = computed(() => parsedQuery.value.runId);
|
||||
const detailRunNo = computed(() => parsedQuery.value.runNo);
|
||||
|
||||
const tabs = computed(() => {
|
||||
const items: Array<{ key: VoucherCheckChatView; label: string }> = [
|
||||
{ key: 'tasks', label: t('workspace.voucherCheck.tabTasks') },
|
||||
{ key: 'notifications', label: t('workspace.voucherCheck.tabNotifications') },
|
||||
];
|
||||
if (isAdmin.value) {
|
||||
items.push({ key: 'notifyConfig', label: t('workspace.voucherCheck.tabNotifyConfig') });
|
||||
}
|
||||
return items;
|
||||
});
|
||||
|
||||
/**
|
||||
* 把当前 Tab / 批次明细写入 Chat 路由,保持刷新与旧地址重定向可用。
|
||||
* 核心逻辑:replace 避免 Tab 切换堆积历史;切 Tab 时清掉 runId。
|
||||
*/
|
||||
async function syncQuery(
|
||||
view: VoucherCheckChatView,
|
||||
runId: number | null,
|
||||
runNo: string | null = null,
|
||||
): Promise<void> {
|
||||
const nextQuery = buildVoucherCheckChatQuery(view, runId, runNo);
|
||||
const currentView = String(route.query.view || '');
|
||||
const currentRunId = String(route.query.runId || '');
|
||||
const currentRunNo = String(route.query.runNo || '');
|
||||
if (
|
||||
currentView === nextQuery.view
|
||||
&& currentRunId === (nextQuery.runId || '')
|
||||
&& currentRunNo === (nextQuery.runNo || '')
|
||||
) return;
|
||||
const query = { ...route.query, ...nextQuery };
|
||||
if (!runId) {
|
||||
delete query.runId;
|
||||
delete query.runNo;
|
||||
}
|
||||
await router.replace({ params: { ...route.params }, query });
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换主 Tab;详情下钻随 Tab 关闭,避免第四个隐形页。
|
||||
*/
|
||||
function selectView(view: VoucherCheckChatView): void {
|
||||
void syncQuery(view, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在当前 Tab 内打开批次明细。
|
||||
*/
|
||||
function openDetail(payload: { runId: number; runNo?: string | null }): void {
|
||||
void syncQuery(activeView.value, payload.runId, payload.runNo || null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从明细返回当前 Tab 列表。
|
||||
*/
|
||||
function closeDetail(): void {
|
||||
void syncQuery(activeView.value, null);
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query.view,
|
||||
(rawView) => {
|
||||
if (rawView) return;
|
||||
void syncQuery(activeView.value, detailRunId.value, detailRunNo.value);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
[isAdmin, activeView],
|
||||
() => {
|
||||
if (!isAdmin.value && activeView.value === 'notifyConfig') {
|
||||
void syncQuery('tasks', null);
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-[var(--surface-muted,#f4f7fb)]">
|
||||
<div class="px-5 pt-5">
|
||||
<h1 class="text-xl font-bold text-primary">{{ t('workspace.voucherCheck.title') }}</h1>
|
||||
<p class="mt-1 text-sm text-muted">{{ t('workspace.voucherCheck.subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 flex gap-0 border-b border-default px-5">
|
||||
<button
|
||||
v-for="tab in tabs"
|
||||
:key="tab.key"
|
||||
type="button"
|
||||
class="mb-[-1px] border-b-2 px-4 py-2.5 text-sm font-bold"
|
||||
:class="activeView === tab.key
|
||||
? 'border-brand-500 text-brand-600'
|
||||
: 'border-transparent text-muted hover:text-secondary'"
|
||||
@click="selectView(tab.key)"
|
||||
>
|
||||
{{ tab.label }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="min-h-0 flex-1 overflow-auto px-5 py-4">
|
||||
<VoucherCheckNotifyConfigPanel v-if="activeView === 'notifyConfig' && isAdmin" />
|
||||
<AccountingVoucherCheckDetailView
|
||||
v-else-if="detailRunId"
|
||||
:run-id="detailRunId"
|
||||
:run-no="detailRunNo"
|
||||
embedded
|
||||
@close="closeDetail"
|
||||
/>
|
||||
<AccountingVoucherCheckView
|
||||
v-else
|
||||
:active-tab="activeView === 'notifications' ? 'notifications' : 'tasks'"
|
||||
embedded
|
||||
@open-detail="openDetail"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,201 @@
|
||||
<!--
|
||||
features/voucher-check/components/VoucherCheckNotifyConfigPanel.vue
|
||||
用途:立账凭证 Chat「通知配置」Tab:按六类必检文件分别选择企微接收人。
|
||||
依赖:voucherCheck.api、UserPickerDialog、vue-i18n、useMessage。
|
||||
逻辑:仅平台管理员可见;规则来自销售 Profile,接收人写入独立配置表;
|
||||
行内只展示标签 +「选择」,点选打开公共选人弹窗;未绑企微的人可勾选但发送时会被跳过。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Loader2 } from 'lucide-vue-next';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import UserPickerDialog from '@/shared/components/UserPickerDialog.vue';
|
||||
import { userPickerLabel } from '@/shared/utils/userPicker.utils';
|
||||
import {
|
||||
getVoucherCheckNotifyConfig,
|
||||
saveVoucherCheckNotifyConfig,
|
||||
type VoucherCheckNotifyRule,
|
||||
type VoucherCheckNotifyUser,
|
||||
} from '@/features/workspace/api/voucherCheck.api';
|
||||
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const profileCode = ref('sales');
|
||||
const rules = ref<VoucherCheckNotifyRule[]>([]);
|
||||
const users = ref<VoucherCheckNotifyUser[]>([]);
|
||||
const updatedAt = ref<string | null>(null);
|
||||
const pickerOpen = ref(false);
|
||||
const pickerRuleCode = ref<string | null>(null);
|
||||
|
||||
const userMap = computed(() => {
|
||||
const next = new Map<number, VoucherCheckNotifyUser>();
|
||||
for (const user of users.value) next.set(user.id, user);
|
||||
return next;
|
||||
});
|
||||
|
||||
const pickerRule = computed(() =>
|
||||
rules.value.find((rule) => rule.code === pickerRuleCode.value) || null,
|
||||
);
|
||||
|
||||
const pickerSelectedIds = computed(() => pickerRule.value?.user_ids || []);
|
||||
|
||||
/**
|
||||
* 打开某文件类型的公共选人弹窗。
|
||||
*/
|
||||
function openPicker(ruleCode: string): void {
|
||||
pickerRuleCode.value = ruleCode;
|
||||
pickerOpen.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹窗确定后写回该行接收人。
|
||||
*/
|
||||
function applyPickerSelection(userIds: number[]): void {
|
||||
const row = rules.value.find((rule) => rule.code === pickerRuleCode.value);
|
||||
if (row) row.user_ids = [...userIds];
|
||||
pickerRuleCode.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从行内标签移除接收人,不必打开弹窗。
|
||||
*/
|
||||
function removeUser(ruleCode: string, userId: number): void {
|
||||
const row = rules.value.find((rule) => rule.code === ruleCode);
|
||||
if (!row) return;
|
||||
row.user_ids = row.user_ids.filter((id) => id !== userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载六行规则与候选人。
|
||||
*/
|
||||
async function loadConfig(): Promise<void> {
|
||||
loading.value = true;
|
||||
try {
|
||||
const data = await getVoucherCheckNotifyConfig(profileCode.value);
|
||||
profileCode.value = data.profile_code || 'sales';
|
||||
rules.value = (data.rules || []).map((rule) => ({
|
||||
...rule,
|
||||
user_ids: Array.isArray(rule.user_ids) ? [...rule.user_ids] : [],
|
||||
}));
|
||||
users.value = data.users || [];
|
||||
updatedAt.value = data.updated_at || null;
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('workspace.voucherCheck.notifyConfigLoadFailed'));
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存当前六行选人结果。
|
||||
*/
|
||||
async function saveConfig(): Promise<void> {
|
||||
saving.value = true;
|
||||
try {
|
||||
const recipients: Record<string, number[]> = {};
|
||||
for (const rule of rules.value) recipients[rule.code] = [...rule.user_ids];
|
||||
const data = await saveVoucherCheckNotifyConfig({
|
||||
profile_code: profileCode.value,
|
||||
recipients,
|
||||
});
|
||||
rules.value = (data.rules || []).map((rule) => ({
|
||||
...rule,
|
||||
user_ids: Array.isArray(rule.user_ids) ? [...rule.user_ids] : [],
|
||||
}));
|
||||
users.value = data.users || [];
|
||||
updatedAt.value = data.updated_at || null;
|
||||
msg.success(t('workspace.voucherCheck.notifyConfigSaved'));
|
||||
} catch (error: any) {
|
||||
msg.error(error?.message || t('workspace.voucherCheck.notifyConfigSaveFailed'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadConfig();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="overflow-hidden rounded-2xl border border-default bg-surface">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3 border-b border-default px-4 py-3">
|
||||
<div>
|
||||
<h2 class="text-sm font-semibold text-primary">{{ t('workspace.voucherCheck.notifyConfigTitle') }}</h2>
|
||||
<p class="mt-1 text-sm text-muted">{{ t('workspace.voucherCheck.notifyConfigSubtitle') }}</p>
|
||||
<p v-if="updatedAt" class="mt-1 text-xs text-muted">
|
||||
{{ t('workspace.voucherCheck.notifyConfigUpdatedAt', { time: updatedAt }) }}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-xl bg-brand-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-brand-700 disabled:opacity-50"
|
||||
:disabled="loading || saving"
|
||||
@click="saveConfig"
|
||||
>
|
||||
<Loader2 v-if="saving" class="h-3.5 w-3.5 animate-spin" />
|
||||
{{ t('workspace.voucherCheck.notifyConfigSave') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="flex items-center justify-center gap-2 px-4 py-10 text-sm text-muted">
|
||||
<Loader2 class="h-4 w-4 animate-spin" />
|
||||
{{ t('workspace.voucherCheck.loading') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="divide-y divide-default">
|
||||
<div
|
||||
v-for="rule in rules"
|
||||
:key="rule.code"
|
||||
class="grid gap-3 px-4 py-3 md:grid-cols-[220px_minmax(0,1fr)] md:items-center"
|
||||
>
|
||||
<div>
|
||||
<p class="text-sm font-semibold text-primary">{{ rule.name }}</p>
|
||||
<p class="mt-0.5 text-xs text-muted">
|
||||
{{ t('workspace.voucherCheck.notifyConfigFolder', { folder: rule.type_folder || '—' }) }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="inline-flex w-fit min-w-[18rem] max-w-full flex-wrap items-center gap-1.5 rounded-xl border border-default bg-surface px-2 py-1.5">
|
||||
<span
|
||||
v-for="userId in rule.user_ids"
|
||||
:key="userId"
|
||||
class="inline-flex items-center gap-1 rounded-lg bg-blue-50 px-2 py-0.5 text-xs font-medium text-blue-700"
|
||||
>
|
||||
{{ userPickerLabel(userMap.get(userId), userId) }}
|
||||
<span
|
||||
v-if="userMap.get(userId) && !userMap.get(userId)?.wecom_bound"
|
||||
class="text-amber-600"
|
||||
>!</span>
|
||||
<button
|
||||
type="button"
|
||||
class="ml-0.5 text-blue-400 hover:text-blue-600"
|
||||
@click="removeUser(rule.code, userId)"
|
||||
>✕</button>
|
||||
</span>
|
||||
<span v-if="rule.user_ids.length === 0" class="text-sm text-muted">
|
||||
{{ t('workspace.voucherCheck.notifyConfigEmptyUsers') }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="ml-auto shrink-0 rounded-lg border border-blue-200 bg-blue-50 px-2.5 py-1 text-xs font-semibold text-brand-600 hover:bg-blue-100"
|
||||
@click="openPicker(rule.code)"
|
||||
>
|
||||
{{ t('common.userPicker.select') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<UserPickerDialog
|
||||
v-model="pickerOpen"
|
||||
:users="users"
|
||||
:selected-ids="pickerSelectedIds"
|
||||
:title="t('workspace.voucherCheck.notifyConfigPickerTitle')"
|
||||
@confirm="applyPickerSelection"
|
||||
/>
|
||||
</article>
|
||||
</template>
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* features/voucher-check/constants.ts
|
||||
* 用途:立账凭证 Chat Tab 与深链约定。
|
||||
* 依赖:无。
|
||||
* 逻辑:Chat 主区 Tab 与旧工作台重定向共用 view;详情用 runId,可选 runNo 仅作标题展示。
|
||||
* notifyConfig 仅管理员可见,解析仍接受该值以便深链打开后由面板做权限回退。
|
||||
*/
|
||||
export const VOUCHER_CHECK_CHAT_VIEWS = ['tasks', 'notifications', 'notifyConfig'] as const;
|
||||
|
||||
export type VoucherCheckChatView = (typeof VOUCHER_CHECK_CHAT_VIEWS)[number];
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* features/voucher-check/utils/voucherCheckChat.utils.test.ts
|
||||
* 用途:锁定立账凭证 Chat 深链 query 的解析与回写规则。
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
buildVoucherCheckChatQuery,
|
||||
parseVoucherCheckChatQuery,
|
||||
} from './voucherCheckChat.utils';
|
||||
|
||||
describe('parseVoucherCheckChatQuery', () => {
|
||||
it('accepts tasks / notifications / notifyConfig and a positive runId', () => {
|
||||
expect(parseVoucherCheckChatQuery('notifications', '12', 'VC-202608-001')).toEqual({
|
||||
view: 'notifications',
|
||||
runId: 12,
|
||||
runNo: 'VC-202608-001',
|
||||
});
|
||||
expect(parseVoucherCheckChatQuery('notifyConfig', null, null)).toEqual({
|
||||
view: 'notifyConfig',
|
||||
runId: null,
|
||||
runNo: null,
|
||||
});
|
||||
});
|
||||
|
||||
it('falls back to tasks for unknown view and ignores invalid runId', () => {
|
||||
expect(parseVoucherCheckChatQuery('unknown', 'abc', ' ')).toEqual({
|
||||
view: 'tasks',
|
||||
runId: null,
|
||||
runNo: null,
|
||||
});
|
||||
expect(parseVoucherCheckChatQuery(undefined, '0', undefined)).toEqual({
|
||||
view: 'tasks',
|
||||
runId: null,
|
||||
runNo: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildVoucherCheckChatQuery', () => {
|
||||
it('always writes view and omits runId on list pages', () => {
|
||||
expect(buildVoucherCheckChatQuery('notifications', null)).toEqual({ view: 'notifications' });
|
||||
});
|
||||
|
||||
it('keeps the current tab when drilling into a run', () => {
|
||||
expect(buildVoucherCheckChatQuery('notifications', 9, 'VC-9')).toEqual({
|
||||
view: 'notifications',
|
||||
runId: '9',
|
||||
runNo: 'VC-9',
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* features/voucher-check/utils/voucherCheckChat.utils.ts
|
||||
* 用途:解析立账凭证 Chat 的 view / runId / runNo 查询参数。
|
||||
* 依赖:voucher-check/constants。
|
||||
* 逻辑:旧工作台重定向与 Chat Tab 共用;非法 view 回退检核任务。notifyConfig 为管理员通知配置页。
|
||||
*/
|
||||
import { VOUCHER_CHECK_CHAT_VIEWS, type VoucherCheckChatView } from '../constants';
|
||||
|
||||
export interface VoucherCheckChatQuery {
|
||||
view: VoucherCheckChatView;
|
||||
runId: number | null;
|
||||
runNo: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 把路由 query 归一成立账凭证 Chat 视图。
|
||||
* 核心逻辑:只接受 tasks / notifications / notifyConfig;runId 必须是正整数才进入批次明细;runNo 仅展示。
|
||||
* @param rawView - 路由 query.view
|
||||
* @param rawRunId - 路由 query.runId
|
||||
* @param rawRunNo - 路由 query.runNo
|
||||
*/
|
||||
export function parseVoucherCheckChatQuery(
|
||||
rawView: unknown,
|
||||
rawRunId: unknown,
|
||||
rawRunNo: unknown,
|
||||
): VoucherCheckChatQuery {
|
||||
const view = VOUCHER_CHECK_CHAT_VIEWS.includes(String(rawView) as VoucherCheckChatView)
|
||||
? String(rawView) as VoucherCheckChatView
|
||||
: 'tasks';
|
||||
const parsed = Number(rawRunId);
|
||||
const runId = Number.isInteger(parsed) && parsed > 0 ? parsed : null;
|
||||
const runNo = typeof rawRunNo === 'string' && rawRunNo.trim() ? rawRunNo.trim() : null;
|
||||
return { view, runId, runNo };
|
||||
}
|
||||
|
||||
/**
|
||||
* 把立账凭证视图写回 Chat 路由 query,便于刷新与旧工作台重定向共用同一深链。
|
||||
* 核心逻辑:始终带 view;仅在下钻明细时带 runId / runNo,避免空 query 污染地址栏。
|
||||
* @param view - 当前 Tab
|
||||
* @param runId - 明细批次排程 ID;列表态传 null
|
||||
* @param runNo - 批次号,仅详情标题使用
|
||||
*/
|
||||
export function buildVoucherCheckChatQuery(
|
||||
view: VoucherCheckChatView,
|
||||
runId: number | null,
|
||||
runNo: string | null = null,
|
||||
): Record<string, string> {
|
||||
const query: Record<string, string> = { view };
|
||||
if (runId) query.runId = String(runId);
|
||||
if (runId && runNo) query.runNo = runNo;
|
||||
return query;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<!--
|
||||
features/voucher-check/views/VoucherCheckChatRedirect.vue
|
||||
用途:把旧工作台立账凭证 URL 转到对应 Chat Agent 深链。
|
||||
依赖:listUserAgents、isVoucherCheckAgent、voucherCheckChat.utils。
|
||||
逻辑:按路径还原 view / runId / runNo,再在当前用户 Agent 列表中定位 voucher_check;
|
||||
未授权时提示并回应用管理。本页不渲染业务 UI。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { listUserAgents } from '@/features/auth/api/user.api';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { isVoucherCheckAgent } from '@/shared/utils/agent-registry.utils';
|
||||
import { WORKSPACE_PATHS } from '@/features/workspace/constants/routes';
|
||||
import type { VoucherCheckChatView } from '../constants';
|
||||
import { buildVoucherCheckChatQuery } from '../utils/voucherCheckChat.utils';
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
/**
|
||||
* 从旧工作台路径还原 Chat Tab 与批次明细。
|
||||
* 核心逻辑:runs/:runId 进入当前 Tab 下钻;?run_id= 兼容旧列表深链;?view=notifications 打开发送记录。
|
||||
*/
|
||||
function resolveLegacyTarget(): {
|
||||
view: VoucherCheckChatView;
|
||||
runId: number | null;
|
||||
runNo: string | null;
|
||||
} {
|
||||
const path = String(route.path || '');
|
||||
const view: VoucherCheckChatView = String(route.query.view || '') === 'notifications'
|
||||
? 'notifications'
|
||||
: 'tasks';
|
||||
const runNo = typeof route.query.runNo === 'string' && route.query.runNo.trim()
|
||||
? route.query.runNo.trim()
|
||||
: null;
|
||||
const detailMatch = path.match(/\/accounting-voucher-check\/runs\/(\d+)/);
|
||||
if (detailMatch) {
|
||||
return { view, runId: Number(detailMatch[1]), runNo };
|
||||
}
|
||||
const queryRunId = Number(Array.isArray(route.query.run_id) ? route.query.run_id[0] : route.query.run_id);
|
||||
if (Number.isInteger(queryRunId) && queryRunId > 0) {
|
||||
return { view, runId: queryRunId, runNo };
|
||||
}
|
||||
return { view, runId: null, runNo: null };
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找当前用户可用的立账凭证 Agent 并跳转 Chat。
|
||||
* 核心逻辑:admin 与已授权用户都能在 /api/agents 看到该 Agent;找不到则视为无权限。
|
||||
*/
|
||||
async function redirectToChat(): Promise<void> {
|
||||
const { view, runId, runNo } = resolveLegacyTarget();
|
||||
try {
|
||||
const agents = await listUserAgents();
|
||||
const agent = Array.isArray(agents) ? agents.find((item) => isVoucherCheckAgent(item)) : null;
|
||||
const agentId = Number(agent?.id);
|
||||
if (!Number.isInteger(agentId) || agentId <= 0) {
|
||||
msg.warning(t('errors.codes.VOUCHER_CHECK_FORBIDDEN'));
|
||||
await router.replace(WORKSPACE_PATHS.applications);
|
||||
return;
|
||||
}
|
||||
await router.replace({
|
||||
path: `/chat/${agentId}`,
|
||||
query: buildVoucherCheckChatQuery(view, runId, runNo),
|
||||
});
|
||||
} catch {
|
||||
msg.warning(t('errors.codes.VOUCHER_CHECK_FORBIDDEN'));
|
||||
await router.replace(WORKSPACE_PATHS.applications);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void redirectToChat();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex min-h-[40vh] items-center justify-center text-sm text-muted">
|
||||
{{ t('chat.loadingAgent') }}
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user