Ben Lin
2024-10-28 02e63339ca097d62794caf8f2fd374c34b155b65
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
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 新增任务 </a-button>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              icon: 'clarity:info-standard-line',
              tooltip: '查看任务详情',
              onClick: handleView.bind(null, record),
              name: undefined,
            },
            {
              //开始计划 
              tooltip: '开始计划',
              icon: 'startplan|svg',
              onClick: handleStart.bind(null, record),
              name: undefined,
            },
            {
              //立即运行 
              tooltip: '立即运行',
              icon: 'start|svg',
              onClick: RunImmediately.bind(null, record),
              name: undefined,
            },
            {
              //停止运行
              tooltip: '停止运行',
              icon: 'stop|svg',
              onClick: handleStop.bind(null, record),
              name: undefined,
            },
            {
              tooltip: '编辑',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
              name: undefined,
            },
            {
              tooltip: '删除',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除?',
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
              name: undefined,
            },
          ]"
        />
      </template>
    </BasicTable>
    <jobDrawer @register="registerDrawer" @success="handleSuccess" />
  </div>
</template>
<script lang="ts" setup>
  import { columns, searchFormSchema } from './job.data';
  import jobDrawer from './jobDrawer.vue';
  import { FluentJobParam } from '/@/api/tigerapi/model/tskModel';
  import { getListByPage } from '/@/api/tigerapi/system';
  import { AddTskJob, DeleteTsk_Job, ImmediateRun, StopTsk_Job } from '/@/api/tigerapi/tsk/tsk_job';
  import { useDrawer } from '/@/components/Drawer';
  import { BasicTable, TableAction, useTable } from '/@/components/Table';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useGo } from '/@/hooks/web/usePage';
  import { useI18n } from '/@/hooks/web/useI18n';
 
  const go = useGo();
  const { t } = useI18n();
  const { createErrorModal } = useMessage();
  const [registerDrawer, { openDrawer }] = useDrawer();
 
  const [registerTable, { reload }] = useTable({
    title: '任务列表',
    api: getListByPage,
    searchInfo: {
      TABLE_NAME: 'TSK_JOB',
      // option: {
      //   //根据据点查询,必需带这个参数
      //   UserId: useUserStore().getUserInfo.userId,
      //   ByOrg: true,
      //   CurOrg: useUserStore().getUserInfo.orgCode,
      // },
      NeedInclude: true,
    },
    afterFetch: afterFetch,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    canResize: true,
    showIndexColumn: false,
    actionColumn: {
      width: 205,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: undefined,
    },
  });
 
  /**
   * @description: 请求之后对返回值进行处理
   * @param {*} t
   * @return {*}
   */
  function afterFetch(t) {
    console.log(t);
    t.forEach((item) => {
      item.NextRunTime = item.Triggers[0].NextRunTime;
    });
    return t;
  }
 
  /**
   * 添加任务
   */
  function handleCreate() {
    openDrawer(true, {
      isUpdate: false,
    });
  }
 
  function handleEdit(record: Recordable) {
    openDrawer(true, {
      record,
      isUpdate: true,
    });
  }
 
  /**
   * 详情页面
   * @param {Recordable} record - 记录
   */
  function handleView(record: Recordable) {
    console.log(record.ID);
    go('/job_detail/' + record.ID + ',' + record.JobName + '');
  }
  /**
   * @description: 开始计划
   * @param {*} record
   * @return {*}
   */
  function handleStart(record: Recordable) {
    const param: FluentJobParam = {
      AssemblyName: record.AssemblyName,
      Args: JSON.parse(record.Triggers[0].Args),
      DataType: record.JobType,
      JobName: record.JobName,
      Remark: record.Remark,
    };
    AddTskJob(param).then((action) => {
      if (action.IsSuccessed) {
        reload();
      } else {
        createErrorModal({
          title: t('sys.api.errorTip'),
          content: action.Message,
          getContainer: () => document.body,
        });
      }
    });
  }
  /**
   * @description: 立即运行
   * @param {*} record
   * @return {*}
   */
  function RunImmediately(record: Recordable) {
    const param: FluentJobParam = {
      AssemblyName: record.AssemblyName,
      Args: JSON.parse(record.Triggers[0].Args),
      DataType: record.JobType,
      JobName: record.JobName,
      Remark: record.Remark,
    };
    ImmediateRun(param).then((action) => {
      if (action.IsSuccessed) {
        reload();
      } else {
        createErrorModal({
          title: t('sys.api.errorTip'),
          content: action.Message,
          getContainer: () => document.body,
        });
      }
    });
  }
 
  /**
   * @description: 立即停止
   * @param {*} record
   * @return {*}
   */
  function handleStop(record: Recordable) {
    const apiAction = StopTsk_Job(record);
    apiAction.then((action) => {
      if (action.IsSuccessed) {
        reload();
      }
    });
  }
 
  /**
   * @description: 删除任务
   * @param {*} record
   * @return {*}
   */
  function handleDelete(record: Recordable) {
    handleStop(record);
    const apiAction = DeleteTsk_Job(record);
    apiAction.then((action) => {
      if (action.IsSuccessed) {
        reload();
      }
    });
  }
 
  /**
   * @description: 返回成功
   * @return {*}
   */
  function handleSuccess() {
    reload();
  }
</script>