Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
commit
472b530be3
397 files changed
+46450
-34171
No files matched your search
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* features/admin/modules/agents/components/AgentFormModal.vue
|
||||
*
|
||||
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息、Dify/Iframe 配置和常见问题表单。
|
||||
* 用途:应用管理新增/编辑弹窗,集中承载 Agent 基础信息(含启用状态)、Dify/Iframe 配置和常见问题表单。
|
||||
* 依赖:agent.types AgentFormState、schedule.types ScheduleTask、AgentToolRunProgressConfig、vue-i18n。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form,并通过事件通知关闭、保存、增删常见问题。
|
||||
* 逻辑:父组件控制 visible/isEditing/isSaving 与保存;本组件直接编辑传入的 form(含 is_active),并通过事件通知关闭、保存、增删常见问题。
|
||||
*/
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -15,8 +15,7 @@ import type { ScheduleTask } from '@/shared/types/schedule.types';
|
||||
import type { AgentTypeCatalogEntry, IntentRouteOption } from '../composables/useAgentsAdminRegistry';
|
||||
import type { AdminContentProfileOption } from '@/features/admin/api/admin.api';
|
||||
import {
|
||||
DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS,
|
||||
DEFAULT_TRAINING_HR_CHAT_QUESTIONS,
|
||||
getDefaultTrainingChatQuestions,
|
||||
} from '@/features/chat/training/trainingChatQuestions';
|
||||
import {
|
||||
applyCatalogDefaultsToForm,
|
||||
@@ -188,10 +187,10 @@ const handleTrainingWorkspaceToggle = () => {
|
||||
if (props.form.training_workspace_enabled) {
|
||||
props.form.content_profile = 'training';
|
||||
if (!props.form.training_employee_chat_questions_text.trim()) {
|
||||
props.form.training_employee_chat_questions_text = DEFAULT_TRAINING_EMPLOYEE_CHAT_QUESTIONS.join('\n');
|
||||
props.form.training_employee_chat_questions_text = getDefaultTrainingChatQuestions('employee').join('\n');
|
||||
}
|
||||
if (!props.form.training_hr_chat_questions_text.trim()) {
|
||||
props.form.training_hr_chat_questions_text = DEFAULT_TRAINING_HR_CHAT_QUESTIONS.join('\n');
|
||||
props.form.training_hr_chat_questions_text = getDefaultTrainingChatQuestions('hr').join('\n');
|
||||
}
|
||||
} else if (props.form.content_profile === 'training') {
|
||||
props.form.content_profile = '';
|
||||
@@ -208,7 +207,6 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
watch(
|
||||
() => props.form.is_aggregate,
|
||||
(enabled) => {
|
||||
@@ -303,12 +301,13 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<template v-if="showDifyFields">
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">Dify应用类型</label>
|
||||
<select v-model="form.dify_app_type" class="w-full input-field text-sm">
|
||||
<option value="chatflow">Chatflow</option>
|
||||
<option value="workflow">Workflow</option>
|
||||
<div class="space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.difyAppType') }}</label>
|
||||
<select v-model="form.dify_app_type" class="w-full input-field text-sm">
|
||||
<option value="chatflow">{{ t('admin.agent.fields.difyAppTypes.chatflow') }}</option>
|
||||
<option value="workflow">{{ t('admin.agent.fields.difyAppTypes.workflow') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
@@ -341,6 +340,23 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="col-span-1 md:col-span-2 space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.isActive') }}</label>
|
||||
<div class="flex flex-col gap-2 rounded-xl border border-default bg-surface-soft/40 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||
<p class="text-sm leading-6 text-secondary">
|
||||
{{ form.is_active ? t('admin.agent.fields.isActiveHintOn') : t('admin.agent.fields.isActiveHintOff') }}
|
||||
</p>
|
||||
<label class="inline-flex shrink-0 items-center gap-2 rounded-xl border border-default bg-white px-3 py-2 text-sm text-secondary">
|
||||
<input
|
||||
v-model="form.is_active"
|
||||
type="checkbox"
|
||||
class="accent-brand-600"
|
||||
/>
|
||||
<span>{{ t('admin.agent.fields.isActiveEnable') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-1 md:col-span-2 space-y-2">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.fields.description') }}</label>
|
||||
<input
|
||||
@@ -565,30 +581,30 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
|
||||
<div class="col-span-1 md:col-span-2 space-y-3">
|
||||
<div class="flex flex-wrap items-center justify-between gap-3">
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">常见问题</label>
|
||||
<label class="text-xs font-bold text-muted uppercase tracking-wider">{{ t('admin.agent.suggestedQuestions.title') }}</label>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-1 rounded-lg border border-default px-3 py-1.5 text-xs font-medium text-secondary transition-colors hover:bg-surface-soft"
|
||||
@click="emit('addSuggestedQuestion')"
|
||||
>
|
||||
<Plus class="h-4 w-4" />
|
||||
添加问题
|
||||
{{ t('admin.agent.suggestedQuestions.add') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 text-sm">
|
||||
<label class="inline-flex items-center gap-2 text-secondary">
|
||||
<input v-model="form.suggested_questions_style" type="radio" value="plain" class="accent-brand-600" />
|
||||
<span>无样式</span>
|
||||
<span>{{ t('admin.agent.suggestedQuestions.stylePlain') }}</span>
|
||||
</label>
|
||||
<label class="inline-flex items-center gap-2 text-secondary">
|
||||
<input v-model="form.suggested_questions_style" type="radio" value="styled" class="accent-brand-600" />
|
||||
<span>有样式</span>
|
||||
<span>{{ t('admin.agent.suggestedQuestions.styleStyled') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div v-if="form.suggested_questions.length === 0" class="rounded-xl border border-dashed border-default px-4 py-5 text-sm text-muted">
|
||||
暂未配置常见问题,点击“添加问题”后会同步到对应 Agent 的 Chat 欢迎页。
|
||||
{{ t('admin.agent.suggestedQuestions.empty') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="space-y-3">
|
||||
@@ -602,14 +618,16 @@ const handleTrainingQuestionTypeChange = (form: AgentFormState, index: number) =
|
||||
v-model="item.question"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
placeholder="请输入常见问题,例如:查询我有多少假期?"
|
||||
:placeholder="t('admin.agent.suggestedQuestions.questionPlaceholder')"
|
||||
/>
|
||||
<input
|
||||
v-model="item.group"
|
||||
type="text"
|
||||
class="w-full input-field text-sm"
|
||||
:disabled="form.suggested_questions_style !== 'styled'"
|
||||
:placeholder="form.suggested_questions_style === 'styled' ? '可选:分组标题,例如:考勤与休假' : '无样式下无需分组'"
|
||||
:placeholder="form.suggested_questions_style === 'styled'
|
||||
? t('admin.agent.suggestedQuestions.groupPlaceholderStyled')
|
||||
: t('admin.agent.suggestedQuestions.groupPlaceholderPlain')"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -500,13 +500,13 @@ export function useAgentsAdmin() {
|
||||
payload.dify_api_key = form.value.dify_api_key;
|
||||
}
|
||||
await updateAdminAgent(form.value.id, payload);
|
||||
msg.success('应用更新成功');
|
||||
msg.success(t('admin.agent.updateSuccess'));
|
||||
} else {
|
||||
await createAdminAgent({
|
||||
...registryPayload,
|
||||
dify_api_key: form.value.dify_api_key,
|
||||
});
|
||||
msg.success('应用创建成功');
|
||||
msg.success(t('admin.agent.createSuccess'));
|
||||
}
|
||||
|
||||
await loadAgents();
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
* features/admin/modules/linked-services/LinkedServicesPage.vue
|
||||
* 关联服务管理独立页面:表格列表 + 新增/编辑弹窗。
|
||||
* 依赖:useLinkedServicesAdmin、LinkedServiceFormModal、DeleteConfirmDialog。
|
||||
* 逻辑:路由 /admin/linked-services;启用项自动出现在 Chat/工作台侧栏底部。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { onMounted } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Edit, Plus, Trash2 } from 'lucide-vue-next';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import LinkedServiceFormModal from './components/LinkedServiceFormModal.vue';
|
||||
import { useLinkedServicesAdmin } from './composables/useLinkedServicesAdmin';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const {
|
||||
services,
|
||||
form,
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
openCreateModal,
|
||||
openEditModal,
|
||||
closeFormModal,
|
||||
saveService,
|
||||
toggleEnabled,
|
||||
deleteServiceItem,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
} = useLinkedServicesAdmin();
|
||||
|
||||
onMounted(() => {
|
||||
void loadAll();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="admin-table-section animate-fade-in-up">
|
||||
<div v-if="isLoading" class="flex items-center justify-center py-20">
|
||||
<div class="animate-spin rounded-full h-10 w-10 border-b-2 border-brand-600" />
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<div class="admin-table-header admin-table-header--stacked">
|
||||
<div>
|
||||
<h2 class="section-title">{{ t('admin.linkedServices.title') }}</h2>
|
||||
<p class="section-desc mt-1">{{ t('admin.linkedServices.subtitle') }}</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="flex items-center gap-2 px-4 py-2 bg-brand-600 text-white rounded-xl hover:bg-brand-700 transition-all shadow-lg shadow-brand-200 active:scale-95 text-sm font-medium"
|
||||
@click="openCreateModal"
|
||||
>
|
||||
<Plus class="w-4 h-4" />
|
||||
<span>{{ t('admin.linkedServices.add') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="admin-table-wrap">
|
||||
<table class="admin-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.linkedServices.headers.name') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs">{{ t('admin.linkedServices.headers.url') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs w-28">{{ t('admin.linkedServices.headers.status') }}</th>
|
||||
<th class="px-6 py-4 text-left text-xs w-24">{{ t('admin.linkedServices.headers.sortOrder') }}</th>
|
||||
<th class="px-6 py-4 text-right text-xs w-40">{{ t('admin.linkedServices.headers.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="services.length === 0">
|
||||
<td colspan="5" class="px-6 admin-table-empty">{{ t('admin.linkedServices.empty') }}</td>
|
||||
</tr>
|
||||
<tr v-for="row in services" :key="row.id">
|
||||
<td class="px-6 py-4 text-sm font-medium text-primary">{{ row.name }}</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary font-mono break-all">{{ row.url }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center rounded-full px-2.5 py-1 text-xs font-medium transition-colors"
|
||||
:class="row.is_enabled
|
||||
? 'bg-emerald-50 text-emerald-700 hover:bg-emerald-100'
|
||||
: 'bg-surface-soft text-muted hover:bg-surface'"
|
||||
@click="toggleEnabled(row)"
|
||||
>
|
||||
{{ row.is_enabled ? t('admin.linkedServices.status.enabled') : t('admin.linkedServices.status.disabled') }}
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-sm text-secondary">{{ row.sort_order }}</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
<div class="inline-flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 rounded-lg text-muted hover:bg-surface-soft hover:text-secondary"
|
||||
:title="t('admin.edit')"
|
||||
@click="openEditModal(row)"
|
||||
>
|
||||
<Edit class="w-4 h-4" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="p-2 rounded-lg text-muted hover:bg-red-50 hover:text-red-600"
|
||||
:title="t('admin.delete')"
|
||||
@click="deleteServiceItem(row.id)"
|
||||
>
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<LinkedServiceFormModal
|
||||
:visible="showFormModal"
|
||||
:form="form"
|
||||
:is-saving="isSaving"
|
||||
@close="closeFormModal"
|
||||
@save="saveService"
|
||||
/>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirmDialog"
|
||||
:message="deleteConfirmMessage"
|
||||
@cancel="closeDeleteConfirm"
|
||||
@confirm="confirmDelete"
|
||||
/>
|
||||
</section>
|
||||
</template>
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* features/admin/modules/linked-services/components/LinkedServiceFormModal.vue
|
||||
* 关联服务创建/编辑居中弹窗。
|
||||
* 依赖:LinkedServiceFormState、admin 通用 modal 样式。
|
||||
* 逻辑:LinkedServicesPage 打开本组件;提交时 emit save。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import type { LinkedServiceFormState } from '@/features/admin/types/linked-service.types';
|
||||
|
||||
defineProps<{
|
||||
visible: boolean;
|
||||
form: LinkedServiceFormState;
|
||||
isSaving: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
save: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="visible" class="admin-modal-overlay animate-fade-in items-center">
|
||||
<div class="admin-modal-panel max-w-lg max-h-[92vh] scale-100">
|
||||
<div class="px-5 sm:px-8 pt-5 sm:pt-7 pb-4 border-b border-subtle">
|
||||
<h3 class="section-title">
|
||||
{{ form.id ? t('admin.linkedServices.edit') : t('admin.linkedServices.add') }}
|
||||
</h3>
|
||||
<p class="section-desc mt-1">{{ t('admin.linkedServices.formHint') }}</p>
|
||||
</div>
|
||||
<div class="px-5 sm:px-8 py-5 space-y-5 overflow-y-auto">
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.linkedServices.fields.name') }}</label>
|
||||
<input
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
class="input-field text-sm"
|
||||
:placeholder="t('admin.linkedServices.placeholders.name')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.linkedServices.fields.url') }}</label>
|
||||
<input
|
||||
v-model="form.url"
|
||||
type="url"
|
||||
class="input-field text-sm font-mono"
|
||||
:placeholder="t('admin.linkedServices.placeholders.url')"
|
||||
/>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<label class="label-field">{{ t('admin.linkedServices.fields.sortOrder') }}</label>
|
||||
<input v-model.number="form.sort_order" type="number" class="input-field text-sm" min="0" />
|
||||
</div>
|
||||
<label class="inline-flex items-center gap-2 text-sm text-secondary cursor-pointer">
|
||||
<input v-model="form.is_enabled" type="checkbox" class="w-4 h-4 rounded text-brand-600 border-default" />
|
||||
{{ t('admin.linkedServices.fields.enabled') }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="admin-modal-footer">
|
||||
<button type="button" class="btn-ghost" @click="emit('close')">{{ t('admin.cancel') }}</button>
|
||||
<button type="button" class="btn-primary disabled:opacity-70" :disabled="isSaving" @click="emit('save')">
|
||||
{{ isSaving ? t('admin.save') + '...' : form.id ? t('admin.update') : t('admin.add') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
+198
@@ -0,0 +1,198 @@
|
||||
/**
|
||||
* features/admin/modules/linked-services/composables/useLinkedServicesAdmin.ts
|
||||
* 关联服务管理:列表、新增/编辑弹窗、启用开关、删除。
|
||||
* 依赖:admin.api、linked-service.types、linked-nav.store、useMessage。
|
||||
* 逻辑:LinkedServicesPage 调用本 composable;保存/删除后刷新侧栏入口缓存。
|
||||
*/
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
createLinkedService,
|
||||
deleteLinkedService,
|
||||
listLinkedServices,
|
||||
updateLinkedService,
|
||||
} from '@/features/admin/api/admin.api';
|
||||
import { useLinkedNavStore } from '@/features/sso/stores/linked-nav.store';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
createEmptyLinkedServiceForm,
|
||||
linkedServiceRowToForm,
|
||||
type AdminLinkedServiceRow,
|
||||
type LinkedServiceFormState,
|
||||
} from '@/features/admin/types/linked-service.types';
|
||||
|
||||
export function useLinkedServicesAdmin() {
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const linkedNav = useLinkedNavStore();
|
||||
|
||||
const services = ref<AdminLinkedServiceRow[]>([]);
|
||||
const form = ref<LinkedServiceFormState>(createEmptyLinkedServiceForm());
|
||||
const isLoading = ref(true);
|
||||
const isSaving = ref(false);
|
||||
const showFormModal = ref(false);
|
||||
|
||||
const showDeleteConfirmDialog = ref(false);
|
||||
const deleteConfirmMessage = ref('');
|
||||
let deleteConfirmAction: (() => Promise<void> | void) | null = null;
|
||||
|
||||
/**
|
||||
* 拉取关联服务列表。
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
const loadServices = async (): Promise<void> => {
|
||||
try {
|
||||
services.value = await listLinkedServices();
|
||||
} catch (e) {
|
||||
console.error('Failed to load linked services', e);
|
||||
services.value = [];
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 页面初始化:加载列表并结束 loading。
|
||||
* @returns Promise<void>
|
||||
*/
|
||||
const loadAll = async (): Promise<void> => {
|
||||
isLoading.value = true;
|
||||
await loadServices();
|
||||
isLoading.value = false;
|
||||
};
|
||||
|
||||
/** 打开删除确认对话框。 */
|
||||
const openDeleteConfirm = (message: string, action: () => Promise<void> | void): void => {
|
||||
deleteConfirmMessage.value = message;
|
||||
deleteConfirmAction = action;
|
||||
showDeleteConfirmDialog.value = true;
|
||||
};
|
||||
|
||||
/** 关闭删除确认对话框。 */
|
||||
const closeDeleteConfirm = (): void => {
|
||||
showDeleteConfirmDialog.value = false;
|
||||
deleteConfirmAction = null;
|
||||
};
|
||||
|
||||
/** 执行删除确认动作。 */
|
||||
const confirmDelete = async (): Promise<void> => {
|
||||
if (!deleteConfirmAction) return;
|
||||
try {
|
||||
await deleteConfirmAction();
|
||||
} finally {
|
||||
closeDeleteConfirm();
|
||||
}
|
||||
};
|
||||
|
||||
/** 打开「新增关联服务」弹窗。 */
|
||||
const openCreateModal = (): void => {
|
||||
form.value = createEmptyLinkedServiceForm();
|
||||
form.value.sort_order = services.value.length;
|
||||
showFormModal.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开「编辑关联服务」弹窗。
|
||||
* @param row - 待编辑行
|
||||
*/
|
||||
const openEditModal = (row: AdminLinkedServiceRow): void => {
|
||||
form.value = linkedServiceRowToForm(row);
|
||||
showFormModal.value = true;
|
||||
};
|
||||
|
||||
/** 关闭表单弹窗。 */
|
||||
const closeFormModal = (): void => {
|
||||
showFormModal.value = false;
|
||||
form.value = createEmptyLinkedServiceForm();
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存关联服务:有 id 则更新,否则新建。
|
||||
* 核心逻辑:校验名称与 URL → 调 API → 刷新列表。
|
||||
*/
|
||||
const saveService = async (): Promise<void> => {
|
||||
if (!form.value.name.trim() || !form.value.url.trim()) {
|
||||
msg.warning(t('admin.linkedServices.msg.fillAll'));
|
||||
return;
|
||||
}
|
||||
isSaving.value = true;
|
||||
try {
|
||||
const payload = {
|
||||
name: form.value.name.trim(),
|
||||
url: form.value.url.trim(),
|
||||
is_enabled: form.value.is_enabled,
|
||||
sort_order: Number(form.value.sort_order || 0),
|
||||
};
|
||||
if (form.value.id) {
|
||||
await updateLinkedService(form.value.id, payload);
|
||||
} else {
|
||||
await createLinkedService(payload);
|
||||
}
|
||||
closeFormModal();
|
||||
await loadServices();
|
||||
void linkedNav.refresh();
|
||||
msg.success(t('admin.linkedServices.msg.saved'));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换启用状态并立即保存。
|
||||
* @param row - 目标行
|
||||
*/
|
||||
const toggleEnabled = async (row: AdminLinkedServiceRow): Promise<void> => {
|
||||
try {
|
||||
await updateLinkedService(row.id, {
|
||||
name: row.name,
|
||||
url: row.url,
|
||||
is_enabled: !row.is_enabled,
|
||||
sort_order: row.sort_order,
|
||||
});
|
||||
await loadServices();
|
||||
void linkedNav.refresh();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除指定关联服务。
|
||||
* @param id - 主键
|
||||
*/
|
||||
const deleteServiceItem = (id: number): void => {
|
||||
openDeleteConfirm(t('admin.linkedServices.confirmDelete'), async () => {
|
||||
try {
|
||||
await deleteLinkedService(id);
|
||||
await loadServices();
|
||||
void linkedNav.refresh();
|
||||
msg.success(t('admin.linkedServices.msg.deleted'));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
msg.error((e as Error).message || t('admin.msg.requestFailed'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
services,
|
||||
form,
|
||||
isLoading,
|
||||
isSaving,
|
||||
showFormModal,
|
||||
showDeleteConfirmDialog,
|
||||
deleteConfirmMessage,
|
||||
loadAll,
|
||||
openCreateModal,
|
||||
openEditModal,
|
||||
closeFormModal,
|
||||
saveService,
|
||||
toggleEnabled,
|
||||
deleteServiceItem,
|
||||
closeDeleteConfirm,
|
||||
confirmDelete,
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,14 @@
|
||||
/**
|
||||
* features/admin/modules/platform-apps/PlatformAppsPage.vue
|
||||
* 用途:平台应用说明(新手指南)管理——按 Agent 维护指南资料上传、启停与排序。
|
||||
* 依赖:admin.api 指南 CRUD/上传、vue-i18n、lucide 图标。
|
||||
* 逻辑:Admin 路由挂载;选择应用后拉取指南列表,弹窗内上传并保存元数据。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Plus, Trash2, Edit2, Play, FileText, Image as ImageIcon } from 'lucide-vue-next';
|
||||
import { listAdminAgents, listAdminAgentGuides, createAdminAgentGuide, updateAdminAgentGuide, deleteAdminAgentGuide, uploadAdminAgentGuideFile } from '@/features/admin/api/admin.api';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -29,9 +34,10 @@ const form = ref({
|
||||
|
||||
const isUploading = ref(false);
|
||||
const uploadError = ref('');
|
||||
const deleteDialogOpen = ref(false);
|
||||
const pendingDeleteGuideId = ref<number | null>(null);
|
||||
|
||||
/**
|
||||
* 拉取 Agent 列表并默认选中第一项,再加载其指南。
|
||||
*/
|
||||
const fetchAgents = async () => {
|
||||
try {
|
||||
agents.value = await listAdminAgents();
|
||||
@@ -44,6 +50,9 @@ const fetchAgents = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 按当前选中 Agent 拉取指南列表。
|
||||
*/
|
||||
const fetchGuides = async () => {
|
||||
if (!selectedAgentId.value) return;
|
||||
isLoading.value = true;
|
||||
@@ -65,6 +74,9 @@ onMounted(() => {
|
||||
fetchAgents();
|
||||
});
|
||||
|
||||
/**
|
||||
* 打开新建指南弹窗并重置表单。
|
||||
*/
|
||||
const openCreateModal = () => {
|
||||
isEditing.value = false;
|
||||
editingId.value = null;
|
||||
@@ -82,6 +94,10 @@ const openCreateModal = () => {
|
||||
isModalOpen.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开编辑指南弹窗并回填行数据。
|
||||
* @param guide - 列表行指南对象
|
||||
*/
|
||||
const openEditModal = (guide: any) => {
|
||||
isEditing.value = true;
|
||||
editingId.value = guide.id;
|
||||
@@ -99,6 +115,10 @@ const openEditModal = (guide: any) => {
|
||||
isModalOpen.value = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* 上传指南文件并回填 path/type/size;必要时校正 guide_usage 与文件类型一致性。
|
||||
* @param event - input file change 事件
|
||||
*/
|
||||
const handleFileUpload = async (event: Event) => {
|
||||
const file = (event.target as HTMLInputElement).files?.[0];
|
||||
if (!file) return;
|
||||
@@ -121,12 +141,15 @@ const handleFileUpload = async (event: Event) => {
|
||||
form.value.file_name = res.file_name;
|
||||
}
|
||||
} catch (err: any) {
|
||||
uploadError.value = err.message || '上传失败';
|
||||
uploadError.value = err.message || t('admin.platformApps.uploadFailed');
|
||||
} finally {
|
||||
isUploading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 提交新建或更新指南元数据。
|
||||
*/
|
||||
const submitForm = async () => {
|
||||
if (!selectedAgentId.value || !form.value.file_path || !form.value.file_name) return;
|
||||
|
||||
@@ -146,23 +169,24 @@ const submitForm = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const deleteGuide = (id: number) => {
|
||||
pendingDeleteGuideId.value = id;
|
||||
deleteDialogOpen.value = true;
|
||||
};
|
||||
const confirmDeleteGuide = async () => {
|
||||
const id = pendingDeleteGuideId.value;
|
||||
if (!id) return;
|
||||
/**
|
||||
* 确认后删除指南。
|
||||
* @param id - 指南主键
|
||||
*/
|
||||
const deleteGuide = async (id: number) => {
|
||||
if (!confirm(t('admin.platformApps.confirmDelete'))) return;
|
||||
try {
|
||||
await deleteAdminAgentGuide(id);
|
||||
await fetchGuides();
|
||||
} catch (error) {
|
||||
console.error('Failed to delete guide:', error);
|
||||
} finally {
|
||||
pendingDeleteGuideId.value = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换指南启停状态。
|
||||
* @param guide - 列表行指南对象
|
||||
*/
|
||||
const toggleStatus = async (guide: any) => {
|
||||
try {
|
||||
await updateAdminAgentGuide(guide.id, { status: guide.status === 1 ? 0 : 1 });
|
||||
@@ -172,6 +196,11 @@ const toggleStatus = async (guide: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 将字节数格式化为可读文件大小。
|
||||
* @param bytes - 文件字节数
|
||||
* @returns 如 `1.2 MB`
|
||||
*/
|
||||
const formatSize = (bytes: number) => {
|
||||
if (!bytes) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -180,6 +209,10 @@ const formatSize = (bytes: number) => {
|
||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||
};
|
||||
|
||||
/**
|
||||
* 按文件类型返回列表图标组件。
|
||||
* @param type - 文件类型(video/pdf/其它)
|
||||
*/
|
||||
const getIcon = (type: string) => {
|
||||
if (type === 'video') return Play;
|
||||
if (type === 'pdf') return FileText;
|
||||
@@ -195,7 +228,7 @@ const getIcon = (type: string) => {
|
||||
{{ t('admin.nav.platformApps') }}
|
||||
</h2>
|
||||
<p class="text-sm text-muted mt-1">
|
||||
管理应用的新手指南资料(支持视频、PDF等)
|
||||
{{ t('admin.platformApps.subtitle') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -203,7 +236,7 @@ const getIcon = (type: string) => {
|
||||
<div class="surface-panel rounded-2xl p-6 shadow-sm border border-subtle flex-1 flex flex-col gap-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<label class="font-medium text-sm text-default">选择应用:</label>
|
||||
<label class="font-medium text-sm text-default">{{ t('admin.platformApps.selectAgent') }}</label>
|
||||
<select v-model="selectedAgentId" class="input-field w-64" @change="fetchGuides">
|
||||
<option v-for="agent in agents" :key="agent.id" :value="agent.id">
|
||||
{{ agent.name }}
|
||||
@@ -212,7 +245,7 @@ const getIcon = (type: string) => {
|
||||
</div>
|
||||
<button v-if="selectedAgentId" type="button" class="btn-primary" @click="openCreateModal">
|
||||
<Plus class="w-5 h-5 mr-1" />
|
||||
<span>添加指南</span>
|
||||
<span>{{ t('admin.platformApps.addGuide') }}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -221,25 +254,25 @@ const getIcon = (type: string) => {
|
||||
</div>
|
||||
|
||||
<div v-else-if="!selectedAgentId" class="flex flex-col items-center justify-center py-20 text-muted">
|
||||
请先选择一个应用
|
||||
{{ t('admin.platformApps.selectAgentFirst') }}
|
||||
</div>
|
||||
|
||||
<div v-else-if="guides.length === 0" class="flex flex-col items-center justify-center py-20 text-muted">
|
||||
该应用暂无新手指南资料
|
||||
{{ t('admin.platformApps.emptyGuides') }}
|
||||
</div>
|
||||
|
||||
<div v-else class="overflow-x-auto rounded-xl border border-subtle">
|
||||
<table class="w-full text-left text-sm whitespace-nowrap">
|
||||
<thead class="bg-muted text-muted uppercase text-xs font-semibold tracking-wider border-b border-subtle">
|
||||
<tr>
|
||||
<th class="px-6 py-4">类型</th>
|
||||
<th class="px-6 py-4">资料名称</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colType') }}</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colFileName') }}</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.guideUsage') }}</th>
|
||||
<th class="px-6 py-4">Agent应用</th>
|
||||
<th class="px-6 py-4">文件大小</th>
|
||||
<th class="px-6 py-4">排序</th>
|
||||
<th class="px-6 py-4">状态</th>
|
||||
<th class="px-6 py-4 text-right">操作</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colAgent') }}</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colFileSize') }}</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colSort') }}</th>
|
||||
<th class="px-6 py-4">{{ t('admin.platformApps.colStatus') }}</th>
|
||||
<th class="px-6 py-4 text-right">{{ t('admin.platformApps.colActions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-subtle">
|
||||
@@ -269,14 +302,14 @@ const getIcon = (type: string) => {
|
||||
:class="guide.status === 1 ? 'bg-green-100 text-green-700 hover:bg-green-200' : 'bg-gray-100 text-gray-700 hover:bg-gray-200'"
|
||||
@click="toggleStatus(guide)"
|
||||
>
|
||||
{{ guide.status === 1 ? '已启用' : '已禁用' }}
|
||||
{{ guide.status === 1 ? t('admin.platformApps.statusEnabled') : t('admin.platformApps.statusDisabled') }}
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right space-x-2">
|
||||
<button type="button" class="btn-icon-ds" @click="openEditModal(guide)" title="编辑">
|
||||
<button type="button" class="btn-icon-ds" @click="openEditModal(guide)" :title="t('common.edit')">
|
||||
<Edit2 class="w-4 h-4" />
|
||||
</button>
|
||||
<button type="button" class="btn-icon-ds text-red-500 hover:bg-red-50" @click="deleteGuide(guide.id)" title="删除">
|
||||
<button type="button" class="btn-icon-ds text-red-500 hover:bg-red-50" @click="deleteGuide(guide.id)" :title="t('common.delete')">
|
||||
<Trash2 class="w-4 h-4" />
|
||||
</button>
|
||||
</td>
|
||||
@@ -290,13 +323,13 @@ const getIcon = (type: string) => {
|
||||
<div v-if="isModalOpen" class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm">
|
||||
<div class="bg-white dark:bg-gray-800 rounded-2xl shadow-xl w-full max-w-lg overflow-hidden flex flex-col max-h-[90vh]">
|
||||
<div class="px-6 py-4 border-b border-subtle flex justify-between items-center">
|
||||
<h3 class="text-lg font-bold text-default">{{ isEditing ? '编辑指南' : '添加指南' }}</h3>
|
||||
<h3 class="text-lg font-bold text-default">{{ isEditing ? t('admin.platformApps.editGuide') : t('admin.platformApps.addGuide') }}</h3>
|
||||
<button @click="isModalOpen = false" class="text-muted hover:text-default text-xl leading-none">×</button>
|
||||
</div>
|
||||
|
||||
<div class="p-6 overflow-y-auto space-y-4">
|
||||
<div v-if="!isEditing" class="space-y-2">
|
||||
<label class="text-sm font-medium text-default">上传文件</label>
|
||||
<label class="text-sm font-medium text-default">{{ t('admin.platformApps.uploadFile') }}</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="video/mp4,video/webm,application/pdf,image/png,image/jpeg"
|
||||
@@ -304,20 +337,20 @@ const getIcon = (type: string) => {
|
||||
@change="handleFileUpload"
|
||||
/>
|
||||
<div v-if="isUploading" class="text-sm text-blue-600 mt-2 flex items-center gap-2">
|
||||
<div class="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600"></div> 上传中...
|
||||
<div class="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600"></div> {{ t('admin.platformApps.uploading') }}
|
||||
</div>
|
||||
<div v-if="uploadError" class="text-sm text-red-500 mt-2">{{ uploadError }}</div>
|
||||
<div v-if="form.file_path && !isUploading" class="text-sm text-green-600 mt-2">已上传文件就绪</div>
|
||||
<div v-if="form.file_path && !isUploading" class="text-sm text-green-600 mt-2">{{ t('admin.platformApps.uploadReady') }}</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<label class="text-sm font-medium text-default">资料名称</label>
|
||||
<input v-model="form.file_name" type="text" class="input-field w-full" placeholder="如:人事助手使用手册" />
|
||||
<label class="text-sm font-medium text-default">{{ t('admin.platformApps.fileName') }}</label>
|
||||
<input v-model="form.file_name" type="text" class="input-field w-full" :placeholder="t('admin.platformApps.fileNamePlaceholder')" />
|
||||
</div>
|
||||
|
||||
<div class="space-y-2">
|
||||
<label class="text-sm font-medium text-default">备注说明</label>
|
||||
<textarea v-model="form.remark" class="input-field w-full h-20" placeholder="简要说明..."></textarea>
|
||||
<label class="text-sm font-medium text-default">{{ t('admin.platformApps.remark') }}</label>
|
||||
<textarea v-model="form.remark" class="input-field w-full h-20" :placeholder="t('admin.platformApps.remarkPlaceholder')"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
@@ -331,33 +364,32 @@ const getIcon = (type: string) => {
|
||||
<p class="text-xs text-muted">{{ t('admin.platformApps.guideUsageHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-sm font-medium text-default">排序权重</label>
|
||||
<label class="text-sm font-medium text-default">{{ t('admin.platformApps.sortOrder') }}</label>
|
||||
<input v-model.number="form.sort_order" type="number" class="input-field w-full" />
|
||||
<p class="text-xs text-muted">数值越小越靠前</p>
|
||||
<p class="text-xs text-muted">{{ t('admin.platformApps.sortOrderHint') }}</p>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<label class="text-sm font-medium text-default">状态</label>
|
||||
<label class="text-sm font-medium text-default">{{ t('admin.platformApps.status') }}</label>
|
||||
<select v-model="form.status" class="input-field w-full">
|
||||
<option :value="1">启用</option>
|
||||
<option :value="0">禁用</option>
|
||||
<option :value="1">{{ t('admin.platformApps.enable') }}</option>
|
||||
<option :value="0">{{ t('admin.platformApps.disable') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="px-6 py-4 border-t border-subtle bg-muted flex justify-end gap-3">
|
||||
<button type="button" class="btn-secondary" @click="isModalOpen = false">取消</button>
|
||||
<button type="button" class="btn-secondary" @click="isModalOpen = false">{{ t('admin.cancel') }}</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn-primary"
|
||||
@click="submitForm"
|
||||
:disabled="isUploading || !form.file_path || !form.file_name"
|
||||
>
|
||||
保存
|
||||
{{ t('admin.platformApps.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<DeleteConfirmDialog v-model="deleteDialogOpen" title="删除指南" message="确定要删除该指南吗?删除后不可恢复。" confirm-tone="danger" @confirm="confirmDeleteGuide" />
|
||||
</div>
|
||||
</template>
|
||||
+1066
File diff suppressed because it is too large.
Load diff
+590
@@ -0,0 +1,590 @@
|
||||
/**
|
||||
* features/admin/modules/procurement-contract/components/ContractRiskRulesPanel.vue
|
||||
* 用途:采购合同风险红线规则列表与新增/编辑(含迁移种子默认规则)。
|
||||
* 依赖:procurement-contract.api、DeleteConfirmDialog、useMessage、vue-i18n。
|
||||
* 逻辑:由 ProcurementContractPage「风险规则」Tab 挂载;CRUD 走 Admin rules API。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { CircleHelp, Plus, ShieldAlert, ShieldCheck, SlidersHorizontal } from 'lucide-vue-next';
|
||||
import {
|
||||
createAdminContractRiskRule,
|
||||
deleteAdminContractRiskRule,
|
||||
listAdminContractRiskRules,
|
||||
updateAdminContractRiskRule,
|
||||
type ContractRiskRuleRow,
|
||||
} from '@/features/admin/api/procurement-contract.api';
|
||||
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const rules = ref<ContractRiskRuleRow[]>([]);
|
||||
const filterStatus = ref('');
|
||||
|
||||
const showForm = ref(false);
|
||||
const editing = ref<ContractRiskRuleRow | null>(null);
|
||||
const formTitle = ref('');
|
||||
const formCategory = ref('');
|
||||
const formKeywords = ref('');
|
||||
const formTriggerType = ref<'keyword_missing' | 'keyword_present'>('keyword_missing');
|
||||
const formRiskLevel = ref<'high' | 'medium' | 'low'>('medium');
|
||||
const formRiskHint = ref('');
|
||||
const formSuggestion = ref('');
|
||||
const formNegotiation = ref('');
|
||||
const formStatus = ref<'enabled' | 'disabled'>('enabled');
|
||||
const formSortOrder = ref(100);
|
||||
|
||||
const clauseCategories = [
|
||||
'payment',
|
||||
'delivery',
|
||||
'acceptance',
|
||||
'warranty',
|
||||
'liability',
|
||||
'jurisdiction',
|
||||
'dispute',
|
||||
'ip',
|
||||
'other',
|
||||
] as const;
|
||||
|
||||
const showDeleteConfirm = ref(false);
|
||||
const pendingDelete = ref<ContractRiskRuleRow | null>(null);
|
||||
const deleting = ref(false);
|
||||
|
||||
const isEditMode = computed(() => Boolean(editing.value));
|
||||
const formTitleText = computed(() =>
|
||||
isEditMode.value
|
||||
? t('admin.procurementContract.ruleEditTitle')
|
||||
: t('admin.procurementContract.ruleCreateTitle'),
|
||||
);
|
||||
|
||||
const isBuiltinRule = computed(() => editing.value?.rule_kind === 'builtin');
|
||||
|
||||
const keywordLogicHint = computed(() =>
|
||||
formTriggerType.value === 'keyword_present'
|
||||
? t('admin.procurementContract.keywordPresentLogicHint')
|
||||
: t('admin.procurementContract.keywordMissingLogicHint'),
|
||||
);
|
||||
const ruleStats = computed(() => ({
|
||||
total: rules.value.length,
|
||||
enabled: rules.value.filter((rule) => rule.status === 'enabled').length,
|
||||
highRisk: rules.value.filter((rule) => rule.risk_level === 'high').length,
|
||||
}));
|
||||
|
||||
/**
|
||||
* 生成风险规则统计卡片,帮助管理员先扫状态再进入列表维护。
|
||||
*/
|
||||
const ruleSummaryCards = computed(() => [
|
||||
{
|
||||
key: 'total',
|
||||
label: t('admin.procurementContract.ruleStatTotal'),
|
||||
value: ruleStats.value.total,
|
||||
icon: SlidersHorizontal,
|
||||
className: 'border-slate-200 bg-white text-slate-600',
|
||||
},
|
||||
{
|
||||
key: 'enabled',
|
||||
label: t('admin.procurementContract.ruleStatEnabled'),
|
||||
value: ruleStats.value.enabled,
|
||||
icon: ShieldCheck,
|
||||
className: 'border-emerald-100 bg-emerald-50/80 text-emerald-700',
|
||||
},
|
||||
{
|
||||
key: 'highRisk',
|
||||
label: t('admin.procurementContract.ruleStatHighRisk'),
|
||||
value: ruleStats.value.highRisk,
|
||||
icon: ShieldAlert,
|
||||
className: 'border-rose-100 bg-rose-50/80 text-rose-700',
|
||||
},
|
||||
]);
|
||||
|
||||
/**
|
||||
* 加载风险规则列表。
|
||||
* @param options.silent - 为 true 时不切换 loading,避免启停时整表闪烁
|
||||
*/
|
||||
async function loadRules(options?: { silent?: boolean }): Promise<void> {
|
||||
const silent = Boolean(options?.silent);
|
||||
if (!silent) loading.value = true;
|
||||
try {
|
||||
rules.value = await listAdminContractRiskRules({
|
||||
status: filterStatus.value || undefined,
|
||||
});
|
||||
} catch (e: unknown) {
|
||||
console.error(e);
|
||||
msg.error(e instanceof Error ? e.message : t('admin.procurementContract.loadFailed'));
|
||||
} finally {
|
||||
if (!silent) loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 响应筛选条件变更并刷新规则列表。
|
||||
*/
|
||||
async function onFilterStatusChange(): Promise<void> {
|
||||
await loadRules();
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadRules();
|
||||
});
|
||||
|
||||
/**
|
||||
* 重置规则表单为新建默认值。
|
||||
*/
|
||||
function resetForm(): void {
|
||||
editing.value = null;
|
||||
formTitle.value = '';
|
||||
formCategory.value = 'payment';
|
||||
formKeywords.value = '';
|
||||
formTriggerType.value = 'keyword_missing';
|
||||
formRiskLevel.value = 'medium';
|
||||
formRiskHint.value = '';
|
||||
formSuggestion.value = '';
|
||||
formNegotiation.value = '';
|
||||
formStatus.value = 'enabled';
|
||||
formSortOrder.value = 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开新建规则弹窗。
|
||||
*/
|
||||
function openCreate(): void {
|
||||
resetForm();
|
||||
showForm.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开编辑规则弹窗(种子规则也可改,code 只读)。
|
||||
*/
|
||||
function openEdit(row: ContractRiskRuleRow): void {
|
||||
editing.value = row;
|
||||
formTitle.value = row.title;
|
||||
formCategory.value = row.clause_category;
|
||||
formKeywords.value = (row.keywords || []).join(',');
|
||||
formTriggerType.value = row.trigger_type === 'keyword_present' ? 'keyword_present' : 'keyword_missing';
|
||||
formRiskLevel.value =
|
||||
row.risk_level === 'high' || row.risk_level === 'low' ? row.risk_level : 'medium';
|
||||
formRiskHint.value = row.risk_hint || '';
|
||||
formSuggestion.value = row.suggestion || '';
|
||||
formNegotiation.value = row.negotiation_text || '';
|
||||
formStatus.value = row.status === 'disabled' ? 'disabled' : 'enabled';
|
||||
formSortOrder.value = Number(row.sort_order) || 100;
|
||||
showForm.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭规则表单。
|
||||
*/
|
||||
function closeForm(): void {
|
||||
showForm.value = false;
|
||||
editing.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交新建或更新规则。
|
||||
*/
|
||||
async function submitForm(): Promise<void> {
|
||||
if (!formTitle.value.trim() || !formCategory.value.trim()) {
|
||||
msg.error(t('admin.procurementContract.ruleRequiredFields'));
|
||||
return;
|
||||
}
|
||||
if (!formKeywords.value.trim()) {
|
||||
msg.error(t('admin.procurementContract.ruleKeywordsRequired'));
|
||||
return;
|
||||
}
|
||||
if (!formRiskHint.value.trim() || !formSuggestion.value.trim()) {
|
||||
msg.error(t('admin.procurementContract.ruleRequiredFields'));
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
try {
|
||||
// 与后端 _normalize_keywords 一致:逗号/中文逗号分隔
|
||||
const keywords = formKeywords.value
|
||||
.replace(/,/g, ',')
|
||||
.split(',')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean);
|
||||
const payload = {
|
||||
title: formTitle.value.trim(),
|
||||
clause_category: formCategory.value.trim(),
|
||||
// 当前采购合同审核只支持通用采购类型,保留固定值以兼容后端规则加载。
|
||||
contract_type: 'general_procurement',
|
||||
keywords,
|
||||
trigger_type: formTriggerType.value,
|
||||
risk_level: formRiskLevel.value,
|
||||
risk_hint: formRiskHint.value.trim(),
|
||||
suggestion: formSuggestion.value.trim(),
|
||||
negotiation_text: formNegotiation.value.trim() || null,
|
||||
status: formStatus.value,
|
||||
sort_order: Number(formSortOrder.value) || 100,
|
||||
};
|
||||
if (isEditMode.value && editing.value) {
|
||||
await updateAdminContractRiskRule(editing.value.id, payload);
|
||||
msg.success(t('admin.procurementContract.ruleEditOk'));
|
||||
} else {
|
||||
await createAdminContractRiskRule(payload);
|
||||
msg.success(t('admin.procurementContract.ruleCreateOk'));
|
||||
}
|
||||
closeForm();
|
||||
await loadRules({ silent: true });
|
||||
} catch (e: unknown) {
|
||||
msg.error(e instanceof Error ? e.message : t('admin.procurementContract.actionFailed'));
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 切换规则启停(种子与自定义规则均可)。
|
||||
* 核心逻辑:先乐观更新本地行,成功后再静默对齐服务端;失败则回滚。
|
||||
*/
|
||||
async function toggleStatus(row: ContractRiskRuleRow): Promise<void> {
|
||||
const prev = row.status;
|
||||
const next = prev === 'enabled' ? 'disabled' : 'enabled';
|
||||
row.status = next;
|
||||
try {
|
||||
const updated = await updateAdminContractRiskRule(row.id, { status: next });
|
||||
Object.assign(row, updated);
|
||||
// 当前筛选为「启用/停用」时,状态变更后该项应离开列表
|
||||
if (filterStatus.value && filterStatus.value !== next) {
|
||||
rules.value = rules.value.filter((r) => r.id !== row.id);
|
||||
}
|
||||
} catch (e: unknown) {
|
||||
row.status = prev;
|
||||
msg.error(e instanceof Error ? e.message : t('admin.procurementContract.actionFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开删除确认。
|
||||
*/
|
||||
function openDelete(row: ContractRiskRuleRow): void {
|
||||
pendingDelete.value = row;
|
||||
showDeleteConfirm.value = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭删除确认。
|
||||
*/
|
||||
function closeDelete(): void {
|
||||
showDeleteConfirm.value = false;
|
||||
pendingDelete.value = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认删除规则。
|
||||
*/
|
||||
async function confirmDelete(): Promise<void> {
|
||||
const row = pendingDelete.value;
|
||||
if (!row) return;
|
||||
deleting.value = true;
|
||||
try {
|
||||
await deleteAdminContractRiskRule(row.id);
|
||||
closeDelete();
|
||||
rules.value = rules.value.filter((r) => r.id !== row.id);
|
||||
} catch (e: unknown) {
|
||||
msg.error(e instanceof Error ? e.message : t('admin.procurementContract.actionFailed'));
|
||||
} finally {
|
||||
deleting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 风险等级文案。
|
||||
*/
|
||||
function riskLabel(level: string): string {
|
||||
if (level === 'high') return t('admin.procurementContract.riskHigh');
|
||||
if (level === 'medium') return t('admin.procurementContract.riskMedium');
|
||||
if (level === 'low') return t('admin.procurementContract.riskLow');
|
||||
return level;
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发类型文案。
|
||||
*/
|
||||
function triggerLabel(type: string): string {
|
||||
if (type === 'keyword_present') return t('admin.procurementContract.triggerPresent');
|
||||
return t('admin.procurementContract.triggerMissing');
|
||||
}
|
||||
|
||||
/**
|
||||
* 状态文案。
|
||||
*/
|
||||
function statusLabel(status: string): string {
|
||||
if (status === 'enabled') return t('admin.procurementContract.enable');
|
||||
if (status === 'disabled') return t('admin.procurementContract.disable');
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则关键词展示文本。
|
||||
* @param row - 风险规则行;关键词为空时返回短横线占位,避免表格空洞。
|
||||
*/
|
||||
function keywordText(row: ContractRiskRuleRow): string {
|
||||
const keywords = row.keywords || [];
|
||||
return keywords.length ? keywords.join(',') : '-';
|
||||
}
|
||||
|
||||
/**
|
||||
* 将内部条款分类编码转换为与规则弹窗一致的可读名称。
|
||||
* 核心逻辑:规则仍保存稳定编码,列表仅负责展示本地化文案。
|
||||
* @param category - 后端返回的条款分类编码。
|
||||
* @returns 用户可读的分类名称;历史未知编码保持原样,避免丢失信息。
|
||||
*/
|
||||
function categoryLabel(category: string): string {
|
||||
const key = `admin.procurementContract.category_${category}`;
|
||||
const translated = t(key);
|
||||
return translated === key ? category : translated;
|
||||
}
|
||||
|
||||
defineExpose({ loadRules, openCreate });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-5">
|
||||
<div class="grid gap-3 md:grid-cols-3">
|
||||
<div
|
||||
v-for="card in ruleSummaryCards"
|
||||
:key="card.key"
|
||||
class="rounded-xl border px-4 py-3 shadow-sm"
|
||||
:class="card.className"
|
||||
>
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<div class="text-xs font-medium text-muted">{{ card.label }}</div>
|
||||
<div class="mt-1 text-2xl font-semibold text-primary">{{ card.value }}</div>
|
||||
</div>
|
||||
<span class="inline-flex h-9 w-9 items-center justify-center rounded-lg bg-white/80 shadow-sm">
|
||||
<component :is="card.icon" class="h-4 w-4" />
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-3 rounded-xl border border-subtle bg-white px-4 py-3 shadow-sm sm:flex-row sm:items-center sm:justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<label class="flex shrink-0 items-center gap-2 text-sm font-medium text-secondary">
|
||||
<span>{{ t('admin.procurementContract.colStatus') }}</span>
|
||||
<select
|
||||
v-model="filterStatus"
|
||||
class="input-field h-10 w-48 min-w-48 py-0 text-sm"
|
||||
@change="onFilterStatusChange"
|
||||
>
|
||||
<option value="">{{ t('admin.procurementContract.all') }}</option>
|
||||
<option value="enabled">{{ t('admin.procurementContract.enable') }}</option>
|
||||
<option value="disabled">{{ t('admin.procurementContract.disable') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<button type="button" class="btn-primary inline-flex h-10 items-center gap-2 px-4 shadow-sm" @click="openCreate">
|
||||
<Plus class="h-4 w-4" />
|
||||
{{ t('admin.procurementContract.addRule') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="overflow-hidden rounded-xl border border-subtle bg-white shadow-sm">
|
||||
<div class="overflow-auto">
|
||||
<table class="w-full min-w-[1030px] whitespace-nowrap text-sm">
|
||||
<thead class="bg-slate-50/80 text-xs font-semibold text-muted">
|
||||
<tr>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colRuleTitle') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colCategory') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colKeywords') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colTrigger') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colRisk') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colStatus') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colSort') }}</th>
|
||||
<th class="px-5 py-3 text-left">{{ t('admin.procurementContract.colActions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="loading">
|
||||
<td colspan="8" class="px-4 py-8 text-center text-muted">
|
||||
{{ t('admin.procurementContract.loading') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-else-if="!rules.length">
|
||||
<td colspan="8" class="px-4 py-8 text-center text-muted">
|
||||
{{ t('admin.procurementContract.emptyRules') }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr v-for="row in rules" :key="row.id" class="border-t border-subtle transition-colors hover:bg-slate-50/70">
|
||||
<td class="px-5 py-4 align-top">
|
||||
<div class="font-semibold text-primary">{{ row.title }}</div>
|
||||
</td>
|
||||
<td class="px-5 py-4 align-top">
|
||||
<span class="inline-flex rounded-md border border-slate-200 bg-slate-50 px-2 py-1 text-xs font-medium text-slate-700">
|
||||
{{ categoryLabel(row.clause_category) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="max-w-[260px] px-5 py-4 align-top text-xs text-muted" :title="keywordText(row)">
|
||||
<div class="line-clamp-2 whitespace-normal leading-5">{{ keywordText(row) }}</div>
|
||||
</td>
|
||||
<td class="px-5 py-4 align-top text-secondary">{{ triggerLabel(row.trigger_type) }}</td>
|
||||
<td class="px-5 py-4 align-top">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="{
|
||||
'bg-rose-50 text-rose-700': row.risk_level === 'high',
|
||||
'bg-amber-50 text-amber-800': row.risk_level === 'medium',
|
||||
'bg-sky-50 text-sky-700': row.risk_level === 'low',
|
||||
}"
|
||||
>
|
||||
{{ riskLabel(row.risk_level) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-5 py-4 align-top">
|
||||
<span
|
||||
class="inline-flex rounded-full px-2.5 py-1 text-xs font-semibold"
|
||||
:class="row.status === 'enabled' ? 'bg-emerald-50 text-emerald-700' : 'bg-slate-100 text-slate-600'"
|
||||
>
|
||||
{{ statusLabel(row.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-5 py-4 align-top font-mono text-xs text-muted">{{ row.sort_order }}</td>
|
||||
<td class="px-5 py-4 align-top">
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-8 items-center rounded-lg border border-[#d8e0ec] bg-white px-3 text-xs font-semibold text-[#2f80d1] transition-colors hover:border-[#2f80d1] hover:bg-[#eaf4ff]"
|
||||
@click="openEdit(row)"
|
||||
>
|
||||
{{ t('admin.edit') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-8 items-center rounded-lg border border-[#d8e0ec] bg-white px-3 text-xs font-semibold text-[#172033] transition-colors hover:border-[#667792] hover:bg-slate-50"
|
||||
@click="toggleStatus(row)"
|
||||
>
|
||||
{{ row.status === 'enabled' ? t('admin.procurementContract.disable') : t('admin.procurementContract.enable') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex h-8 items-center rounded-lg border border-rose-200 bg-white px-3 text-xs font-semibold text-rose-600 transition-colors hover:border-rose-300 hover:bg-rose-50"
|
||||
@click="openDelete(row)"
|
||||
>
|
||||
{{ t('admin.delete') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="showForm"
|
||||
class="admin-modal-overlay animate-fade-in"
|
||||
@click.self="closeForm"
|
||||
>
|
||||
<div class="admin-modal-panel max-w-2xl max-h-[92vh] my-auto scale-100" role="dialog" aria-modal="true">
|
||||
<div class="admin-modal-header flex items-center justify-between gap-3">
|
||||
<h3 class="section-title">{{ formTitleText }}</h3>
|
||||
<button type="button" class="btn-ghost h-9 px-3 text-sm" @click="closeForm">
|
||||
{{ t('admin.close') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="admin-modal-body min-h-0 !space-y-0 grid grid-cols-1 gap-4 sm:grid-cols-2 items-start">
|
||||
<label class="flex flex-col gap-1.5 text-sm">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colRuleTitle') }}</span>
|
||||
<input v-model="formTitle" type="text" class="input-field w-full" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colCategory') }}</span>
|
||||
<select v-model="formCategory" class="input-field w-full" :disabled="isBuiltinRule">
|
||||
<option v-for="category in clauseCategories" :key="category" :value="category">
|
||||
{{ t(`admin.procurementContract.category_${category}`) }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm sm:col-span-2">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colKeywords') }}</span>
|
||||
<input
|
||||
v-model="formKeywords"
|
||||
type="text"
|
||||
class="input-field w-full"
|
||||
:disabled="isBuiltinRule"
|
||||
:placeholder="t('admin.procurementContract.ruleKeywordsPlaceholder')"
|
||||
/>
|
||||
<span class="text-xs leading-5 text-muted">{{ keywordLogicHint }}</span>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colTrigger') }}</span>
|
||||
<select v-model="formTriggerType" class="input-field w-full" :disabled="isBuiltinRule">
|
||||
<option value="keyword_missing">{{ t('admin.procurementContract.triggerMissing') }}</option>
|
||||
<option value="keyword_present">{{ t('admin.procurementContract.triggerPresent') }}</option>
|
||||
</select>
|
||||
<span v-if="isBuiltinRule" class="text-xs leading-5 text-amber-700">{{ t('admin.procurementContract.builtinRuleLogicHint') }}</span>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colRisk') }}</span>
|
||||
<select v-model="formRiskLevel" class="input-field w-full">
|
||||
<option value="high">{{ t('admin.procurementContract.riskHigh') }}</option>
|
||||
<option value="medium">{{ t('admin.procurementContract.riskMedium') }}</option>
|
||||
<option value="low">{{ t('admin.procurementContract.riskLow') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colStatus') }}</span>
|
||||
<select v-model="formStatus" class="input-field w-full">
|
||||
<option value="enabled">{{ t('admin.procurementContract.enable') }}</option>
|
||||
<option value="disabled">{{ t('admin.procurementContract.disable') }}</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="flex flex-col gap-1.5 text-sm">
|
||||
<div class="flex items-center gap-1.5">
|
||||
<label for="risk-rule-sort-order" class="font-medium text-secondary">{{ t('admin.procurementContract.colSort') }}</label>
|
||||
<span class="group relative inline-flex">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex text-muted transition-colors hover:text-brand-600 focus:outline-none focus-visible:text-brand-600"
|
||||
:aria-label="t('admin.procurementContract.ruleSortHint')"
|
||||
>
|
||||
<CircleHelp class="h-4 w-4" />
|
||||
</button>
|
||||
<span class="pointer-events-none absolute bottom-full left-1/2 z-10 mb-2 hidden w-60 -translate-x-1/2 rounded-lg border border-subtle bg-white px-3 py-2 text-xs font-normal leading-5 text-secondary shadow-lg group-hover:block group-focus-within:block">
|
||||
{{ t('admin.procurementContract.ruleSortHint') }}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<input id="risk-rule-sort-order" v-model.number="formSortOrder" type="number" class="input-field w-full" min="0" />
|
||||
</div>
|
||||
<label class="flex flex-col gap-1.5 text-sm sm:col-span-2">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colRiskHint') }}</span>
|
||||
<textarea v-model="formRiskHint" rows="2" class="input-field w-full resize-y" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm sm:col-span-2">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colSuggestion') }}</span>
|
||||
<textarea v-model="formSuggestion" rows="2" class="input-field w-full resize-y" />
|
||||
</label>
|
||||
<label class="flex flex-col gap-1.5 text-sm sm:col-span-2">
|
||||
<span class="font-medium text-secondary">{{ t('admin.procurementContract.colNegotiation') }}</span>
|
||||
<textarea v-model="formNegotiation" rows="2" class="input-field w-full resize-y" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="admin-modal-footer flex justify-end gap-2">
|
||||
<button type="button" class="btn-ghost h-10 px-4" @click="closeForm">
|
||||
{{ t('admin.cancel') }}
|
||||
</button>
|
||||
<button type="button" class="btn-primary h-10 px-4 disabled:opacity-70" :disabled="saving" @click="submitForm">
|
||||
{{ saving ? t('admin.procurementContract.saving') : t('admin.procurementContract.saveChanges') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DeleteConfirmDialog
|
||||
v-model="showDeleteConfirm"
|
||||
:message="t('admin.procurementContract.confirmDeleteRule', { title: pendingDelete?.title || '' })"
|
||||
:confirm-loading="deleting"
|
||||
@confirm="confirmDelete"
|
||||
@cancel="closeDelete"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* features/admin/modules/procurement-contract/contract-ocr-match-tokens.ts
|
||||
* 用途:采购合同比对区域的 V4 默认 OCR/正文匹配锚点与签章关键词(检测用 token,非 UI 文案)。
|
||||
* 依赖:procurement-contract.api 的 ContractComparisonRegionConfig 类型。
|
||||
* 逻辑:ProcurementContractPage「恢复 V4 默认配置」与新建区域配置时引用;勿当作 i18n 展示文案。
|
||||
*
|
||||
* NOTE: Strings below are OCR match tokens for Chinese contract PDFs. Keep them in Chinese
|
||||
* regardless of UI locale so region recognition against Chinese source documents still works.
|
||||
*/
|
||||
import type { ContractComparisonRegionConfig } from '@/features/admin/api/procurement-contract.api';
|
||||
|
||||
/** V4 默认比对区域配置(锚点/关键词为中文 OCR 匹配 token)。 */
|
||||
export const V4_REGION_CONFIG: ContractComparisonRegionConfig = {
|
||||
metadata_fields: ['contract_no', 'buyer', 'seller', 'version'],
|
||||
body_start_anchors: ['兹因甲方向乙方购买设备'],
|
||||
body_end_anchors: ['本合同一式两份', '以下无正文', '本页以下无正文'],
|
||||
signature_terms: ['甲方', '乙方', '盖章', '签署日期', '合同专用章'],
|
||||
attachment_start_anchors: ['附件', '性能需求表', '技术协议', '设备配置清单'],
|
||||
attachment_policy: 'page_count_only',
|
||||
};
|
||||
@@ -74,7 +74,6 @@ const {
|
||||
getApplicationSortMark,
|
||||
handleApplicationSearchChange,
|
||||
openApplicationChatLogs,
|
||||
openApplicationPermissionRequests,
|
||||
isLoading,
|
||||
currentTable,
|
||||
tableData,
|
||||
@@ -139,7 +138,6 @@ const applicationSortableKeys: ApplicationSortKey[] = [
|
||||
'unique_users',
|
||||
'last_active_at',
|
||||
'authorized_users',
|
||||
'pending_requests',
|
||||
'avg_score',
|
||||
];
|
||||
|
||||
@@ -531,7 +529,7 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="applicationSummary" class="grid grid-cols-2 gap-3 md:grid-cols-4">
|
||||
<div v-if="applicationSummary" class="grid grid-cols-1 gap-3 sm:grid-cols-3">
|
||||
<button type="button" class="rounded-xl border border-default bg-surface p-4 text-left" @click="setApplicationUsageFilter('all')">
|
||||
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryActive') }}</div>
|
||||
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.active_agents }}</div>
|
||||
@@ -545,25 +543,20 @@ onBeforeUnmount(() => {
|
||||
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryUnused') }}</div>
|
||||
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.unused_agents }}</div>
|
||||
</button>
|
||||
<div class="rounded-xl border border-default bg-surface p-4">
|
||||
<div class="text-sm text-muted">{{ t('admin.report.appOps.summaryPending') }}</div>
|
||||
<div class="mt-2 text-2xl font-bold text-primary">{{ applicationSummary.pending_permission_total }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="admin-report-table-wrap">
|
||||
<table class="admin-report-table admin-report-table--app-ops w-full table-fixed border-collapse">
|
||||
<colgroup>
|
||||
<col class="w-[14%]" />
|
||||
<col class="w-[7%]" />
|
||||
<col class="w-[7%]" />
|
||||
<col class="w-[16%]" />
|
||||
<col class="w-[7%]" />
|
||||
<col class="w-[7%]" />
|
||||
<col class="w-[8%]" />
|
||||
<col class="w-[8%]" />
|
||||
<col class="w-[8%]" />
|
||||
<col class="w-[18%]" />
|
||||
<col class="w-[8%]" />
|
||||
<col class="w-[10%]" />
|
||||
<col class="w-[10%]" />
|
||||
<col class="w-[10%]" />
|
||||
<col class="w-[12%]" />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -588,7 +581,7 @@ onBeforeUnmount(() => {
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-if="applicationItems.length === 0">
|
||||
<td colspan="10" class="text-center text-muted py-12">
|
||||
<td colspan="9" class="text-center text-muted py-12">
|
||||
{{ t('admin.report.appOps.empty') }}
|
||||
</td>
|
||||
</tr>
|
||||
@@ -600,7 +593,6 @@ onBeforeUnmount(() => {
|
||||
{{ row.last_active_at ? formatLocalDateTime(row.last_active_at) : '-' }}
|
||||
</td>
|
||||
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums">{{ row.authorized_users }}</td>
|
||||
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums">{{ row.pending_requests }}</td>
|
||||
<td class="px-3 py-3 text-left align-middle font-mono tabular-nums whitespace-nowrap">
|
||||
{{ row.avg_score == null ? '-' : row.avg_score }}
|
||||
<span v-if="row.feedback_count" class="text-xs text-muted">({{ row.feedback_count }})</span>
|
||||
@@ -612,14 +604,9 @@ onBeforeUnmount(() => {
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-3 py-3 text-left align-middle">
|
||||
<div class="flex flex-wrap gap-1">
|
||||
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationChatLogs(row)">
|
||||
{{ t('admin.report.appOps.actionLogs') }}
|
||||
</button>
|
||||
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationPermissionRequests(row)">
|
||||
{{ t('admin.report.appOps.actionRequests') }}
|
||||
</button>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary text-xs px-2 py-1" @click="openApplicationChatLogs(row)">
|
||||
{{ t('admin.report.appOps.actionLogs') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -207,18 +207,6 @@ export function useReportsAdmin() {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 下钻到权限申请列表,按 agent_id 精确过滤。
|
||||
* @param row - 应用运营行
|
||||
*/
|
||||
const openApplicationPermissionRequests = (row: ApplicationReportItem): void => {
|
||||
void router.push({
|
||||
name: 'AdminReports',
|
||||
params: { table: 'permission_requests' },
|
||||
query: { agent_id: String(row.agent_id) },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 导出应用运营报表 Excel(仅运营字段)。
|
||||
*/
|
||||
@@ -237,7 +225,6 @@ export function useReportsAdmin() {
|
||||
? formatLocalDateTime(row.last_active_at)
|
||||
: '-',
|
||||
[t('admin.report.appOps.columns.authorized_users')]: row.authorized_users,
|
||||
[t('admin.report.appOps.columns.pending_requests')]: row.pending_requests,
|
||||
[t('admin.report.appOps.columns.avg_score')]: row.avg_score ?? '-',
|
||||
[t('admin.report.appOps.columns.feedback_count')]: row.feedback_count,
|
||||
[t('admin.report.appOps.columns.tokens_used')]: row.tokens_used,
|
||||
@@ -405,7 +392,7 @@ const dataSourceTable = computed<Exclude<AdminReportTableId, 'usage_analysis'>>(
|
||||
});
|
||||
|
||||
/**
|
||||
* 从路由 query 灌入列筛选(用于应用运营下钻到聊天日志 / 权限申请)。
|
||||
* 从路由 query 灌入列筛选(用于应用运营下钻到聊天日志)。
|
||||
*/
|
||||
const applyRouteQueryFilters = (): void => {
|
||||
const next: Record<string, string> = {};
|
||||
@@ -1218,7 +1205,6 @@ watch([reportPageSize, sortedTableData], () => {
|
||||
getApplicationSortMark,
|
||||
handleApplicationSearchChange,
|
||||
openApplicationChatLogs,
|
||||
openApplicationPermissionRequests,
|
||||
isLoading,
|
||||
currentTable,
|
||||
tableData,
|
||||
|
||||
Reference in new issue
Block a user