瀏覽代碼

报表修改或者自动报表运行

FinalYu 1 年之前
父節點
當前提交
4fb8416222
共有 2 個文件被更改,包括 107 次插入83 次删除
  1. 15 0
      chuanyi_client2/src/api/datasource.js
  2. 92 83
      chuanyi_client2/src/views/run_config/index.vue

+ 15 - 0
chuanyi_client2/src/api/datasource.js

@@ -546,6 +546,21 @@ export function getAllOkReportTable(params) {
 }
 
 /**
+ * 运行/停止报表
+ * @param params
+ * @returns {AxiosPromise}
+ */
+export function runAutoTableById(params) {
+    return request({
+        url: '/reportTable/runAutoTableById?id=' + params.id + '&runState=' + params.runState,
+        headers: {
+            isToken: true
+        },
+        method: 'post'
+    })
+}
+
+/**
  * 保存报表
  * @param data
  * @returns {AxiosPromise}

+ 92 - 83
chuanyi_client2/src/views/run_config/index.vue

@@ -62,26 +62,6 @@
                 <el-tag v-if="scope.row.reportTableType == 2" style="margin-right: 5px;">事件驱动报表</el-tag>
               </template>
             </el-table-column>
-<!--            <el-table-column-->
-<!--                align="center"-->
-<!--                label="自动报表"-->
-<!--                prop="isAutoReport"-->
-<!--                width="150">-->
-<!--              <template slot-scope="scope">-->
-<!--                <el-switch v-if="scope.row.isAutoReport == '2'" :value="true" active-color="#13ce66"-->
-<!--                           disabled></el-switch>-->
-<!--                <el-switch v-else :value="scope.row.isAutoReport == '1'" active-color="#13ce66"-->
-<!--                           @change="switchChangeEvent($event, scope.row)"-->
-<!--                           :disabled="uid != scope.row.userId"></el-switch>-->
-<!--              </template>-->
-<!--            </el-table-column>-->
-            <el-table-column
-                align="center"
-                label="当前版本"
-                sortable="custom"
-                prop="version"
-                width="120">
-            </el-table-column>
             <el-table-column
                 align="center"
                 label="创建时间"
@@ -95,13 +75,19 @@
                            v-if="uid == scope.row.userId"
                            size="small"
                            icon="el-icon-edit"
-                           @click="editReportItem(scope.row)">修改名称
+                           @click="editReportItem(scope.row)">修改
                 </el-button>
                 <el-button type="text"
-                           v-if="uid == scope.row.userId"
+                           v-if="scope.row.reportTableType == 1 && scope.row.runState == 0"
                            size="small"
-                           icon="el-icon-setting"
-                           @click="setReportStatus(scope.row)">设置报表状态
+                           icon="el-icon-video-play"
+                           @click="setReportStatus(scope.row)">启动
+                </el-button>
+                <el-button type="text"
+                           v-if="scope.row.reportTableType == 1 && scope.row.runState == 1"
+                           size="small"
+                           icon="el-icon-video-pause"
+                           @click="setReportStatus(scope.row)">停止
                 </el-button>
                 <el-button type="text"
                            v-if="uid == scope.row.userId"
@@ -168,7 +154,7 @@
 
     <!-- 新增报表 -->
     <el-dialog
-        title="新增报表"
+        :title="reportDialogTitle"
         width="600px"
         top="10vh"
         center
@@ -182,14 +168,14 @@
         <el-form-item label='报表名称' prop="reportTableName">
           <el-input placeholder="请输入报表名称" v-model="reportForm.reportTableName" maxlength="20"></el-input>
         </el-form-item>
-        <el-form-item label="报表类型" prop="reportTableType">
+        <el-form-item label="报表类型" prop="reportTableType" v-if="!reportForm.id">
           <el-radio-group v-model="reportForm.reportTableType" @input="changeReportType">
             <el-radio label="0">手动报表</el-radio>
             <el-radio label="1">自动报表</el-radio>
             <el-radio label="2">事件驱动报表</el-radio>
           </el-radio-group>
         </el-form-item>
-        <el-form-item label="报表模板" prop="tableTemplateId">
+        <el-form-item label="报表模板" prop="tableTemplateId" v-if="!reportForm.id">
           <el-select v-model="reportForm.tableTemplateId" filterable placeholder="请选择报表模板" style="width: 100%;">
             <el-option
                 v-for="item in reportTemplateList"
@@ -520,7 +506,7 @@ import {
   getReportTableById,
   getTableData,
   getTableTemplateById,
-  getUserByGroupId,
+  getUserByGroupId, runAutoTableById,
   saveReport,
   tableAssignUserById,
   tableExchangeTypeById,
@@ -552,6 +538,7 @@ export default {
       groupProps: {
         isLeaf: 'leaf'
       },
+      reportDialogTitle: '新增报表',
       showMainView: false,
       chooseMyReport: null,
       dialogReportTemplateVisible: false,
@@ -584,6 +571,7 @@ export default {
       chooseIsAutoReport: null,
       delFlag: 0,
       reportForm: {
+        id: null,
         reportTableName: '',
         reportTableType: null,
         tableTemplateId: null,
@@ -761,19 +749,19 @@ export default {
       let s = val.split(' ')
       if (s[0].indexOf('/') > -1) {
         this.radioByCron = 1
-        this.radioByCronValS = s[0].split('/')[1]
+        this.radioByCronValS = parseInt(s[0].split('/')[1])
       } else if (s[1].indexOf('/') > -1) {
         this.radioByCron = 2
-        this.radioByCronValM = s[1].split('/')[1]
+        this.radioByCronValM = parseInt(s[1].split('/')[1])
       } else if (s[2].indexOf('/') > -1) {
         this.radioByCron = 3
-        this.radioByCronValH = s[2].split('/')[1]
+        this.radioByCronValH = parseInt(s[2].split('/')[1])
       } else if (s[3] === '*') {
         this.radioByCron = 4
         this.radioByCronValD = s[2] + ':' + s[1] + ':' + s[0]
       } else {
         this.radioByCron = 5
-        this.radioByCronValMo = s[3]
+        this.radioByCronValMo = parseInt(s[3])
         this.radioByCronValMoD = s[2] + ':' + s[1] + ':' + s[0]
       }
     },
@@ -860,10 +848,13 @@ export default {
           if (this.radioByCronValD) {
             let times = this.radioByCronValD.split(':')
             result = '每天#{cron3}:#{cron2}:#{cron1}执行一次'
-            result = result.replace('#{cron1}', times[2])
-            result = result.replace('#{cron2}', times[1])
-            result = result.replace('#{cron3}', times[0])
-            result = result.replace(/00/g, '0')
+            result = result.replace('#{cron1}',
+                parseInt(times[2]) < 10 ? ('0' + times[2]) : times[2])
+            result = result.replace('#{cron2}',
+                parseInt(times[1]) < 10 ? ('0' + times[1]) : times[1])
+            result = result.replace('#{cron3}',
+                parseInt(times[0]) < 10 ? ('0' + times[0]) : times[0])
+            // result = result.replace(/00/g, '0')
           }
           break
           // 每月定时执行:0 0 2 1 * ?
@@ -871,11 +862,14 @@ export default {
           if (Number.isInteger(this.radioByCronValMo) && this.radioByCronValMoD) {
             let times = this.radioByCronValMoD.split(':')
             result = '每月#{cron4}号的#{cron3}:#{cron2}:#{cron1}执行一次'
-            result = result.replace('#{cron1}', times[2])
-            result = result.replace('#{cron2}', times[1])
-            result = result.replace('#{cron3}', times[0])
+            result = result.replace('#{cron1}',
+                parseInt(times[2]) < 10 ? ('0' + times[2]) : times[2])
+            result = result.replace('#{cron2}',
+                parseInt(times[1]) < 10 ? ('0' + times[1]) : times[1])
+            result = result.replace('#{cron3}',
+                parseInt(times[0]) < 10 ? ('0' + times[0]) : times[0])
             result = result.replace('#{cron4}', this.radioByCronValMo)
-            result = result.replace(/00/g, '0')
+            // result = result.replace(/00/g, '0')
           }
           break
         default:
@@ -896,21 +890,6 @@ export default {
         return
       }
       this.dialogAutoReportVisible = false
-      console.log(this.reportForm.cron)
-      // const loading = showLoading(this, '请稍候···')
-      // let params = {
-      //   'id': this.reportId,
-      //   'isAutoReport': '1',
-      //   'cron': this.cronVal
-      // }
-      // tableExchangeTypeById(params).then(res => {
-      //   loading.close()
-      //   this.dialogClose()
-      //   this.loadReport()
-      // }).catch((e) => {
-      //   loading.close()
-      //   showAlertWin(this, null, e)
-      // })
     },
     resetRadioVal() {
       this.radioByCron = null
@@ -968,13 +947,32 @@ export default {
       }
       this.dialogReportTypeVisible = true
     },
+    /** 修改自动报表运行状态 */
     setReportStatus(data) {
-      this.reportId = data.id
-      this.reportType = data.isAutoReport + ''
-      this.dialogReportTypeVisible = true
+      let status = data.runState == 0 ? '启动' : '停止'
+      let tips = '您确定要' + status + '该报表吗?'
+      showConfirmWin(this, null, tips, () => {
+        const loading = showLoading(this, '删除中,请稍候···')
+        let params = {
+          'id': data.id,
+          'runState': data.runState == 0 ? 1 : 0
+        }
+        runAutoTableById(params).then(res => {
+          loading.close()
+          let msg = res.data ? status + '成功!' : status + '失败!'
+          showAlertMsgWin(this, null, msg)
+          this.reportPage = 1
+          this.loadReport()
+        }).catch((e) => {
+          loading.close()
+          showAlertWin(this, null, e)
+        })
+      })
     },
+    /** 初始化报表信息 */
     resetReportFormVal() {
       this.reportForm = {
+        id: null,
         reportTableName: '',
         reportTableType: null,
         tableTemplateId: null,
@@ -991,6 +989,7 @@ export default {
     /** 新增报表 */
     addReportEvent() {
       this.resetReportFormVal()
+      this.reportDialogTitle = '新增报表'
       this.dialogReportTemplateVisible = true
     },
     /** 刷新报表 */
@@ -1024,7 +1023,11 @@ export default {
               return
             }
             let luckyData = JSON.parse(res.data.templateData)
-            this.saveReportInfo(loading, luckyData)
+            if (this.reportForm.id) {
+              this.updateReportInfo(loading, luckyData)
+            } else {
+              this.saveReportInfo(loading, luckyData)
+            }
           }).catch((e) => {
             loading.close()
             showAlertWin(this, null, e)
@@ -1625,29 +1628,19 @@ export default {
     },
     /** 修改报表信息 */
     editReportItem(data) {
-      showPromptWin(this, '修改报表名称', '请输入报表名称', data.reportTableName, (val) => {
-        if (!val || !val.trim()) {
-          return '报表名称不能为空'
-        }
-        if (val.length > 20) {
-          return '报表名称必须在20字以内'
-        }
-      }, (value) => {
-        const loading = showLoading(this, '修改中,请稍候···')
-        let params = {
-          'id': data.id,
-          'reportTableName': value
-        }
-        updateTableNameById(params).then(res => {
-          loading.close()
-          let msg = res.data ? '修改成功!' : '修改失败!'
-          showAlertMsgWin(this, null, msg)
-          this.reportPage = 1
-          this.loadReport()
-        }).catch((e) => {
-          loading.close()
-          showAlertWin(this, null, e)
-        })
+      const loading = showLoading(this, '修改中,请稍候···')
+      this.resetRadioVal()
+      getReportTableById(data.id).then(res => {
+        loading.close()
+        this.cronVal = res.data.cron
+        this.analysisCron(this.cronVal)
+        this.reportForm = res.data
+        this.reportForm.cronLabel = this.getCronLabel()
+        this.reportDialogTitle = '修改报表'
+        this.dialogReportTemplateVisible = true
+      }).catch((e) => {
+        loading.close()
+        showAlertWin(this, null, e)
       })
     },
     /** 报表移除 */
@@ -1811,7 +1804,7 @@ export default {
     },
     /** 保存报表信息 */
     saveReportInfo(loading, dataInfo) {
-      if (!loading) loading = showLoading(this, '数据加载中,请稍候···')
+      if (!loading) loading = showLoading(this, '保存中,请稍候···')
       this.reportForm.reportTableData = JSON.stringify(dataInfo)
       saveReport(this.reportForm).then(res => {
         loading.close()
@@ -1826,6 +1819,22 @@ export default {
         showAlertWin(this, null, e)
       })
     },
+    /** 修改报表信息 */
+    updateReportInfo(loading, dataInfo) {
+      if (!loading) loading = showLoading(this, '修改中,请稍候···')
+      updateReportTable(this.reportForm).then(res => {
+        loading.close()
+        let msg = res.data ? '修改成功!' : '修改失败!'
+        showAlertMsgWin(this, null, msg)
+        this.showMainView = false
+        this.dialogReportTemplateVisible = false
+        this.loadReport()
+        this.cancelSaveReport()
+      }).catch((e) => {
+        loading.close()
+        showAlertWin(this, null, e)
+      })
+    },
     /** 更新报表信息 */
     updateReport() {
       console.log(this.chooseMyReport)