Bläddra i källkod

fea: 控制策略增加更改状态功能

vera_min 5 månader sedan
förälder
incheckning
19b4012c7b

+ 1 - 0
src/api/modules/policy.ts

@@ -7,6 +7,7 @@ export default {
   edit: (data: any) => post('/policy/policy/save', data),
   detail: (id: number) => get(`/policy/policy/detail?id=${id}`),
   saveParam: (data: object) => post('/policy/policy/saveParam', data),
+  setStatus: (data: any) => post('/policy/policy/setStatus', data),
   log: {
     getList: (data: any) => getRule("/api/v1/logs/runs", data),
   }

+ 13 - 1
src/views/modules/policy/index/components/addItem.vue

@@ -16,6 +16,12 @@
           <el-radio :label="2">自动</el-radio>
         </el-radio-group>
       </el-form-item>
+      <el-form-item label="状态" prop="status">
+        <el-radio-group v-model="ruleForm.status">
+          <el-radio :label="1">启用</el-radio>
+          <el-radio :label="2">禁用</el-radio>
+        </el-radio-group>
+      </el-form-item>
       <el-form-item label="说明" style="width: 388px;">
         <el-input  v-model="ruleForm.description" type="textarea" />
       </el-form-item>
@@ -63,6 +69,7 @@ interface RuleForm {
   id: any
   title: string
   types: number
+  status: number
   description: string,
   param: any[],
   flowId: string,
@@ -79,6 +86,7 @@ const ruleForm = ref<RuleForm>({
   id: null,
   title: '',
   types: 2,
+  status: 1,
   description: '',
   param: [ {
     key: "",
@@ -139,6 +147,9 @@ const rules = ref({
       trigger: 'change',
     },
   ],
+  status: [
+    { required: true, message: '请选择状态', trigger: 'blur' },
+  ],
   param: [{ required: true, validator: validateParam, trigger: 'change' }],
 })
 
@@ -231,11 +242,12 @@ const openDialog = (row?: any) => {
   resetForm();
   if (row) {
     policyApi.detail(row.id).then((res: any) => {
-      const { id, title, types, description, paramData, flowId } = res.data;
+      const { id, title, types, description, paramData, flowId, status } = res.data;
       ruleForm.value = {
         id: id,
         title: title,
         types: types,
+        status: status,
         description: description,
         param: paramData,
         flowId: flowId

+ 14 - 3
src/views/modules/policy/index/index.vue

@@ -2,7 +2,7 @@
   <el-card shadow="nover" class="page page-wrapper">
     <el-form :model="tableData.param" ref="queryRef" inline>
       <el-form-item>
-        <el-button @click="onOpenEdit(queryRef)">
+        <el-button @click="onOpenEdit('')">
           <el-icon>
             <ele-Plus />
           </el-icon>
@@ -16,7 +16,7 @@
         </el-button> -->
       </el-form-item>
     </el-form>
-    <el-table :data="tableData.data" style="width: 100%" @selection-change="handleSelectionChange" v-loading="tableData.loading">
+    <el-table :data="tableData.data" style="width: 100%" v-loading="tableData.loading">
       <!-- <el-table-column type="selection" width="55" align="center" /> -->
       <el-table-column label="序号" align="center" prop="id" width="100" />
       <el-table-column label="标题" prop="title" show-overflow-tooltip />
@@ -30,11 +30,13 @@
       <el-table-column prop="status" label="状态" width="80" align="center" >
         <template #default="scope">
           <el-tag type="success" size="small" v-if="scope.row.status == 1">启用</el-tag>
-          <el-tag type="info" size="small" v-else>禁用</el-tag>
+          <el-tag type="info" size="small" v-if="scope.row.status == 2">禁用</el-tag>
         </template>
       </el-table-column>
       <el-table-column label="操作" width="220" align="center" fixed="right">
         <template #default="scope">
+          <el-button size="small" text type="info" v-if="scope.row.status === 1" @click="setStatus(scope.row, 2)">禁用</el-button>
+          <el-button size="small" text type="primary" v-else @click="setStatus(scope.row, 1)">启用</el-button>
           <el-button size="small" text type="primary" @click="onOpenRecord(scope.row)">执行</el-button>
           <el-button size="small" text type="primary" @click="onOpenPolicyRecord(scope.row)">策略</el-button>
           <el-button size="small" text type="warning" @click="onOpenEdit(scope.row)">修改</el-button>
@@ -100,6 +102,15 @@ const onOpenPolicyRecord = async (row: any) => {
   window.open(url);
 };
 
+const setStatus = (row: any, status: number) => {
+  api.setStatus({
+    id: row.id,
+    status: status
+  }).then(() => {
+    ElMessage.success('操作成功');
+    updeteList();
+  });
+};
 
 const updeteList = ( ) => {
   if(tableData.value.param.pageNum !== 1) tableData.value.param.pageNum = 1;