|
|
|
|
@ -200,6 +200,40 @@
|
|
|
|
|
</template>
|
|
|
|
|
</ElDialog>
|
|
|
|
|
|
|
|
|
|
<!-- 复制规则弹窗 -->
|
|
|
|
|
<ElDialog
|
|
|
|
|
v-model="copyDialogVisible"
|
|
|
|
|
title="复制规则"
|
|
|
|
|
width="480px"
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
destroy-on-close
|
|
|
|
|
>
|
|
|
|
|
<ElForm
|
|
|
|
|
ref="copyFormRef"
|
|
|
|
|
:model="copyForm"
|
|
|
|
|
:rules="copyRules"
|
|
|
|
|
label-width="80px"
|
|
|
|
|
>
|
|
|
|
|
<ElFormItem label="规则名称" prop="name" required>
|
|
|
|
|
<ElInput v-model="copyForm.name" placeholder="请输入规则名称" :maxlength="128" />
|
|
|
|
|
</ElFormItem>
|
|
|
|
|
<ElFormItem label="规则描述" prop="description">
|
|
|
|
|
<ElInput
|
|
|
|
|
v-model="copyForm.description"
|
|
|
|
|
type="textarea"
|
|
|
|
|
:rows="3"
|
|
|
|
|
placeholder="请输入规则描述"
|
|
|
|
|
/>
|
|
|
|
|
</ElFormItem>
|
|
|
|
|
</ElForm>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<ElButton @click="copyDialogVisible = false">取消</ElButton>
|
|
|
|
|
<ElButton type="primary" :loading="copySubmitting" @click="handleSubmitCopy">
|
|
|
|
|
确定
|
|
|
|
|
</ElButton>
|
|
|
|
|
</template>
|
|
|
|
|
</ElDialog>
|
|
|
|
|
|
|
|
|
|
<!-- 测试抽屉 -->
|
|
|
|
|
<RuleTestDrawer v-model="testDrawerVisible" :rule="currentTestRule" />
|
|
|
|
|
</div>
|
|
|
|
|
@ -210,7 +244,7 @@ defineOptions({ name: "RuleList" });
|
|
|
|
|
|
|
|
|
|
import { ref, reactive, onMounted } from "vue";
|
|
|
|
|
import { useRouter } from "vue-router";
|
|
|
|
|
import { ElMessage, ElMessageBox } from "element-plus";
|
|
|
|
|
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from "element-plus";
|
|
|
|
|
import { Plus, Search, Refresh, View } from "@element-plus/icons-vue";
|
|
|
|
|
import { RuleAPI } from "@/api/module_rule/rule";
|
|
|
|
|
import type { RuleItem, RulePageQuery, RuleStatus, RuleForm } from "@/api/module_rule/rule";
|
|
|
|
|
@ -329,13 +363,52 @@ function handleTest(row: RuleItem) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 复制
|
|
|
|
|
async function handleCopy(row: RuleItem) {
|
|
|
|
|
const copyDialogVisible = ref(false);
|
|
|
|
|
const copySubmitting = ref(false);
|
|
|
|
|
const copyFormRef = ref<FormInstance | null>(null);
|
|
|
|
|
const copySourceRule = ref<RuleItem | null>(null);
|
|
|
|
|
const copyForm = reactive<{ name: string; description: string }>({
|
|
|
|
|
name: "",
|
|
|
|
|
description: "",
|
|
|
|
|
});
|
|
|
|
|
const copyRules: FormRules = {
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: "请输入规则名称", trigger: "blur" },
|
|
|
|
|
{ max: 128, message: "最多 128 个字符", trigger: "blur" },
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function handleCopy(row: RuleItem) {
|
|
|
|
|
copySourceRule.value = row;
|
|
|
|
|
copyForm.name = `${row.name}-副本`;
|
|
|
|
|
copyForm.description = row.description || "";
|
|
|
|
|
copyDialogVisible.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function handleSubmitCopy() {
|
|
|
|
|
if (!copySourceRule.value) return;
|
|
|
|
|
try {
|
|
|
|
|
await RuleAPI.copy(row.id);
|
|
|
|
|
await copyFormRef.value?.validate();
|
|
|
|
|
} catch {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
copySubmitting.value = true;
|
|
|
|
|
try {
|
|
|
|
|
const src = copySourceRule.value;
|
|
|
|
|
const payload: RuleForm = {
|
|
|
|
|
name: copyForm.name.trim(),
|
|
|
|
|
category_id: src.category_id ?? null,
|
|
|
|
|
description: copyForm.description?.trim() || "",
|
|
|
|
|
prompt_template: src.prompt_template,
|
|
|
|
|
status: src.status,
|
|
|
|
|
};
|
|
|
|
|
await RuleAPI.create(payload);
|
|
|
|
|
ElMessage.success("复制成功");
|
|
|
|
|
copyDialogVisible.value = false;
|
|
|
|
|
loadList();
|
|
|
|
|
} catch (e) {
|
|
|
|
|
// 全局拦截器已处理
|
|
|
|
|
} finally {
|
|
|
|
|
copySubmitting.value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|