feat(规则管理): 规则分类排序,规则列表页面新增规则复制弹窗功能

master
3 days ago
parent b8387f6899
commit 4ce045c9de

@ -120,11 +120,11 @@ const RuleAPI = {
});
},
/** 批量修改状态(预留 */
/** 批量修改状态(PUT /rule/status/batch */
batchStatus(ids: number[], status: RuleStatus) {
return request<ApiResponse>({
url: `${RULE_PATH}/status/batch`,
method: "patch",
method: "put",
data: { ids, status },
});
},

@ -125,6 +125,7 @@
defineOptions({ name: "RuleCategory" });
import { ref, reactive, computed, onMounted } from "vue";
import { useRuleCategory } from "@/views/module_rule/useRuleCategory";
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from "element-plus";
import { Plus, Edit, Delete, ArrowRight } from "@element-plus/icons-vue";
import { RuleCategoryAPI } from "@/api/module_rule/rule";
@ -133,9 +134,10 @@ import { useUserStoreHook } from "@stores";
defineExpose({ loadTree });
const { loadTree: loadTreeWithOrder, loading } = useRuleCategory();
const treeRef = ref();
const treeData = ref<RuleCategoryNode[]>([]);
const loading = ref(false);
const defaultExpandAll = ref(true);
const treeProps = {
@ -155,16 +157,7 @@ function filterNode(value: string, data: any) {
//
async function loadTree() {
loading.value = true;
try {
const resp = await RuleCategoryAPI.tree();
const list = (resp?.data?.data as RuleCategoryNode[]) || [];
treeData.value = Array.isArray(list) ? list : [];
} catch (e) {
treeData.value = [];
} finally {
loading.value = false;
}
treeData.value = await loadTreeWithOrder()
}
// ============ ============

@ -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;
}
}

Loading…
Cancel
Save