workflow.js 741 B

123456789101112131415161718192021222324252627282930313233
  1. import { Model } from '@vuex-orm/core';
  2. import { nanoid } from 'nanoid';
  3. import Task from './task';
  4. class Workflow extends Model {
  5. static entity = 'workflows';
  6. static primaryKey = 'id';
  7. static fields() {
  8. return {
  9. id: this.uid(() => nanoid()),
  10. name: this.string(''),
  11. icon: this.string('riGlobalLine'),
  12. data: this.attr(null),
  13. drawflow: this.attr(null),
  14. dataSchema: this.attr([]),
  15. lastRunAt: this.number(),
  16. createdAt: this.number(),
  17. tasks: this.hasMany(Task, 'workflowId'),
  18. };
  19. }
  20. static async insert(payload) {
  21. const res = await super.insert(payload);
  22. await this.store().dispatch('saveToStorage', 'workflows');
  23. return res;
  24. }
  25. }
  26. export default Workflow;