autotask.vue 6.87 KB
Newer Older
wangcong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
<template>
  <div>
    <!-- <Card title="自动任务" :padding="0" shadow style="margin: 4px">
      <a href="#" slot="extra" @click.prevent="editAutotask"> 修改 </a>
      <Table :columns="autotaskCol" :data="tableData" max-height="200"></Table>
    </Card> -->
    <Card title="自动任务" :padding="0" shadow style="margin: 4px">
      <a slot="extra" @click="newAutotask"> 新增 </a>
      <List
        split
        style="max-height: 212px; overflow: scroll; margin: 0 0 0 16px"
      >
        <ListItem v-for="(item, index) in tableData" :key="index">
          <ListItemMeta
            :title="formTitle(item.task)"
            :description="triggerDef[item.trigger]"
          />
          <template slot="action">
            <li>
              <Button
                size="small"
                type="primary"
                icon="ios-create-outline"
                @click="editAutotask(index)"
              ></Button>
            </li>
            <li>
              <Button
                size="small"
                type="error"
                icon="ios-trash-outline"
                @click="deleteAutotask(index)"
              ></Button>
            </li>
          </template>
        </ListItem>
      </List>
      <Row type="flex" justify="center" v-if="tableData.length === 0">
        <span style="color: #ccc; margin-bottom: 8px">暂无数据</span>
      </Row>
    </Card>
    <Modal
      v-model="showEdit"
      title="编辑自动任务"
      :loading="loading"
      @on-ok="onOk"
      @on-cancel="onCancel"
      :z-index="1100"
    >
      <Form
        ref="AutotaskForm"
        :label-width="80"
        label-position="formLeft"
        :model="tempTask"
        :rules="taskRule"
      >
        <FormItem prop="trigger" label="触发时机">
          <Select v-model="tempTask.trigger" placeholder="选择触发时机">
            <Option value="before" label="任务发起前"></Option>
            <Option value="after" label="任务完成后"></Option>]
          </Select>
        </FormItem>
        <FormItem prop="task" label="执行任务">
          <Select v-model="tempTask.task" placeholder="选择执行任务">
            <Option
              v-for="item in extentionTasks"
              :value="item.beanName"
              :key="item.beanName"
              :label="item.name"
            >
              <span>{{ item.name }}</span>
              <br />
              <span style="color: #ccc">{{ item.beanName }}</span>
            </Option>
          </Select>
        </FormItem>
        <FormItem prop="params" label="附加参数">
          <Input v-model="tempTask.params"></Input>
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>
<script>
import { Modal } from "view-design";
export default {
  data() {
    return {
      loading: true,
      showEdit: false,
      editIndex: null,
      triggerDef: {
        before: "任务发起前",
        after: "任务完成后",
      },
      tableData: [],
      tempTask: {
        trigger: "",
        task: "",
        params: "",
      },
      taskRule: {
        trigger: [
          {
            required: true,
            trigger: "blur",
            validator: (rule, value, callback) => {
              if (value === "") {
                callback(new Error("请选择触发时机"));
              } else {
                callback();
              }
            },
          },
        ],
        task: [
          {
            required: true,
            trigger: "blur",
            validator: (rule, value, callback) => {
              if (value === "") {
                callback(new Error("请选择执行任务"));
              } else {
                callback();
              }
            },
          },
        ],
      },
      autotaskCol: [
        {
          type: "index",
          width: 60,
          align: "center",
        },
        {
          title: "响应时机",
          key: "trigger",
        },
        {
          title: "自动任务",
          key: "task",
        },
      ],
      autotaskEditCol: [
        {
          type: "index",
          width: 60,
          align: "center",
        },
        {
          title: "响应时机",
          key: "trigger",
        },
        {
          title: "自动任务",
          key: "task",
        },
      ],
      extentionTasks: [],
    };
  },
  components: {
    Modal,
  },
  props: {
    currentNode: {
      type: Object,
      required: true,
    },
  },
  mounted() {
    if (!this.currentNode.hasOwnProperty("properties")) {
      this.currentNode.properties = new Object();
    }
    if (!this.currentNode.properties.hasOwnProperty("autotask")) {
      this.currentNode.properties["autotask"] = new Array();
    }
    this.tableData = this.currentNode.properties.autotask;
    this.getAutotask();
  },
  methods: {
    getAutotask() {
      GMS.$http.get(`/sedu/workflow/autotask/autotasks`).then((res) => {
        this.extentionTasks = res.data;
        console.log(this.extentionTasks);
      });
    },
    onOk() {
      this.loading = false;
      setTimeout(() => {
        this.loading = true;
      });
      this.$refs["AutotaskForm"].validate((valid) => {
        if (valid) {
          if (this.editIndex == this.tableData.length) {
            this.tableData.push(this.tempTask);
            this.tempTask = new Object();
            this.tempTask = {
              trigger: "",
              task: "",
            };
          }
          console.log(this.currentNode.properties);
          console.log(this.tableData);
          // this.currentNode.properties.autotask = this.tableData;
          this.showEdit = false;
        } else {
          this.$Message.error("请填写必填项 !");
        }
      });
    },
    onCancel() {
      this.showEdit = false;
    },
    newAutotask() {
      let _this = this;
      _this.showEdit = false;
      _this.editIndex = _this.tableData.length;
      _this.tempTask = {
        trigger: "",
        task: "",
      };
      _this.showEdit = true;
    },
    editAutotask(index) {
      this.showEdit = false;
      this.editIndex = index;
      this.tempTask = this.tableData[index];
      this.showEdit = true;
    },
    deleteAutotask(index) {
      this.tableData.splice(index, 1);
    },
    formTitle(task) {
      return (
        this.extentionTasks.find((e) => e.beanName == task)?.name ?? "未知任务"
      );
    },
  },
  watch: {
    currentNode: {
      deep: true,
      handler(newValue, oldValue) {
        if (!newValue.hasOwnProperty("properties")) {
          newValue.properties = new Object();
        }
        if (!newValue.properties.hasOwnProperty("autotask")) {
          newValue.properties["autotask"] = new Array();
        }
        this.tableData = newValue.properties.autotask;
      },
    },
  },
};
</script>
<style>
.tablecell {
  height: 30px;
  display: table-cell;
  border: #e8e8e8 1px solid;
  vertical-align: middle;
  text-align: center;
}
</style>