Просмотр исходного кода

批量任务添加执行功能并联调

DESKTOP-6LTVLN7\Liumouren 1 неделя назад
Родитель
Сommit
2aecf7701c
6 измененных файлов с 251 добавлено и 121 удалено
  1. 1 1
      public/static/config/config.js
  2. 23 17
      src/api/rwgl.js
  3. 23 18
      src/components/AppVue/numberScroll.vue
  4. 12 32
      src/utils/request.js
  5. 1 0
      src/views/Wgn.vue
  6. 191 53
      src/views/rwgl/Index.vue

+ 1 - 1
public/static/config/config.js

@@ -3,7 +3,7 @@ let systemConfig = {
     defaultAccount: {
         username: "user_yztmh_dev",
     },
-    touristUserId: "191", //默认游客用户(user002)id,Oauth中配置
+    touristUserId: "191", //默认游客用户(user_yztmh_dev)id,Oauth中配置
     adminRoleId: "1", //默认管理员角色id,Oauth中配置“系统管理员”角色
     /*
          * 模型id如下

+ 23 - 17
src/api/rwgl.js

@@ -1,12 +1,14 @@
 import {
-    postform
+    postform,
+    post
 } from '../utils/request'
 import content from './content'
 
 
 const dmsPath = systemConfig.dmsDataProxy
 const multiSearch = dmsPath + "/content/multipleFormsOfJointInvestigation"
-const taskSearch = systemConfig.baseServicerPath+"/task/getTask"
+const taskSearch = systemConfig.baseServicerPath + "/task/getTask"
+const taskExecute = "/oneMap/task/execute"
 
 const taskDmsId = systemConfig.columnIds[6]
 
@@ -17,26 +19,26 @@ export function getCName(cName) {
     }))
 }
 
-export function getTasks(page, pageSize, name, status,type) {
+export function getTasks(page, pageSize, name, status, type) {
     let data = {
         "columnId": taskDmsId,
         "autoSelectItem": true,
         "page": page,
         "pageSize": pageSize,
         "columnAlias": "main",
-        "orderBy":"main,c_start_time,desc",
+        "orderBy": "main,c_start_time,desc",
         "conditionsList": JSON.stringify([
-            ...getEqualChecker(name,"c_name"),
-            ...getTypeChecker(status,"c_state"),
-            ...getTypeChecker(type,"c_type"),
+            ...getEqualChecker(name, "c_name"),
+            ...getTypeChecker(status, "c_state"),
+            ...getTypeChecker(type, "c_type"),
         ]),
     }
 
     return resolveDmsMultiTableResult(postform(taskSearch, data));
 }
 
-function getEqualChecker(value,param) {
-    if (value == null||value=="") {
+function getEqualChecker(value, param) {
+    if (value == null || value == "") {
         return []
     }
     return [{
@@ -46,22 +48,22 @@ function getEqualChecker(value,param) {
         "value": `%${value}%`
     }]
 }
-function getTypeChecker(value,param) {
-    
+function getTypeChecker(value, param) {
+
     if (value == null || value.length == 0) {
         return []
     }
     let output = []
     for (let i = 0; i < value.length; i++) {
         const e = value[i];
-        output.push(e+"")
+        output.push(e + "")
     }
     return [{
-            "columnId": "main",
-            "columnName": param,
-            "condition": "in",
-            "value": output
-        }]
+        "columnId": "main",
+        "columnName": param,
+        "condition": "in",
+        "value": output
+    }]
 }
 
 async function resolveResult(result) {
@@ -82,4 +84,8 @@ async function resolveDmsMultiTableResult(result) {
     } else {
         return null;
     }
+}
+
+export function executeTask(taskId) {
+    return post(taskExecute, { taskId });
 }

+ 23 - 18
src/components/AppVue/numberScroll.vue

@@ -3,35 +3,40 @@
 </template>
 
 <script setup>
-import { ref, watch, onMounted } from 'vue'
+import { ref, watch, onMounted } from "vue";
 
 const props = defineProps({
   value: { type: Number, default: 0 },
   duration: { type: Number, default: 1500 },
-  easing: { type: Function, default: (t) => t * (2 - t) }
-})
+  easing: { type: Function, default: (t) => t * (2 - t) },
+});
 
-const displayValue = ref(0)
-const numberEl = ref(null)
+const displayValue = ref(0);
+const numberEl = ref(null);
 
 function animate(start, end) {
-  const startTime = performance.now()
+  const startTime = performance.now();
   const frame = (currentTime) => {
-    const elapsed = currentTime - startTime
-    const progress = Math.min(elapsed / props.duration, 1)
-    displayValue.value = Math.floor(start + (end - start) * props.easing(progress))
+    const elapsed = currentTime - startTime;
+    const progress = Math.min(elapsed / props.duration, 1);
+    displayValue.value = Math.floor(
+      start * 1 + (end * 1 - start * 1) * props.easing(progress)
+    );
     if (progress < 1) {
-      requestAnimationFrame(frame)
+      requestAnimationFrame(frame);
     }
-  }
-  requestAnimationFrame(frame)
+  };
+  requestAnimationFrame(frame);
 }
 
-watch(() => props.value, (newVal, oldVal) => {
-  animate(oldVal, newVal)
-})
+watch(
+  () => props.value,
+  (newVal, oldVal) => {
+    animate(oldVal, newVal);
+  }
+);
 
 onMounted(() => {
-  animate(0, props.value)
-})
-</script>
+  animate(0, props.value);
+});
+</script>

+ 12 - 32
src/utils/request.js

@@ -91,40 +91,20 @@ function get(url, params) {
 }
 
 function post(url, data) {
-  var myHeaders = new Headers();
-  myHeaders.append("Content-Type", "application/json");
-  myHeaders.append("token", ls.get('token'));
-
-  var requestOptions = {
-    method: 'POST',
-    headers: myHeaders,
-    redirect: 'follow'
-  };
-
-  // console.log(url);
-  return fetch(url, requestOptions)
-    .then(response => { return response.json() })
-    .then(result => {
-      // console.log(result);
-      return result;
+  return new Promise((resolve, reject) => {
+    service({
+      method: 'POST',
+      url,
+      data: data,
+      headers: {
+        'Content-Type': 'application/json;'
+      }
+    }).then(res => {
+      resolve(res.data)
     }).catch(err => {
-      return JSON.parse(err)
+      reject(err)
     })
-
-  // return new Promise((resolve, reject) => {
-  //   service({
-  //     method: 'POST',
-  //     url,
-  //     data: data,
-  //     headers: {
-  //       'Content-Type': 'application/json;'
-  //     }
-  //   }).then(res => {
-  //     resolve(res.data)
-  //   }).catch(err => {
-  //     reject(err)
-  //   })
-  // })
+  })
 }
 
 function postform(url, data) {

+ 1 - 0
src/views/Wgn.vue

@@ -670,6 +670,7 @@ export default {
                 message: "任务创建成功",
                 type: "success",
               });
+              // 不直接开始任务,需要到任务管理页面启动
               that.showTaskFrom = false;
             } else {
               that.$message({

+ 191 - 53
src/views/rwgl/Index.vue

@@ -4,54 +4,87 @@
       <div class="left-row">
         <div>
           <div>状态:</div>
-          <el-tag size="large" :effect="focusTaskStatus.includes('all') ? 'dark' : ''" type="primary"
-            @click="changeTaskStatus()">
+          <el-tag
+            size="large"
+            :effect="focusTaskStatus.includes('all') ? 'dark' : ''"
+            type="primary"
+            @click="changeTaskStatus()"
+          >
             全部
           </el-tag>
           <template v-for="status in taskStatus" :key="status.index">
-            <el-tag size="large" :effect="focusTaskStatus.includes(status.index) ? 'dark' : ''" type="primary"
-              @click="changeTaskStatus(status)">
+            <el-tag
+              size="large"
+              :effect="focusTaskStatus.includes(status.index) ? 'dark' : ''"
+              type="primary"
+              @click="changeTaskStatus(status)"
+            >
               {{ status.name }}
             </el-tag>
           </template>
         </div>
         <div>
           <div>类别:</div>
-          <el-tag size="large" :effect="focusTaskType.includes('all') ? 'dark' : ''" type="primary"
-            @click="changeTaskType()">
+          <el-tag
+            size="large"
+            :effect="focusTaskType.includes('all') ? 'dark' : ''"
+            type="primary"
+            @click="changeTaskType()"
+          >
             全部
           </el-tag>
           <template v-for="type in taskType" :key="type.index">
-            <el-tag size="large" :effect="focusTaskType.includes(type.index) ? 'dark' : ''" type="primary"
-              @click="changeTaskType(type)">
+            <el-tag
+              size="large"
+              :effect="focusTaskType.includes(type.index) ? 'dark' : ''"
+              type="primary"
+              @click="changeTaskType(type)"
+            >
               {{ type.name }}
             </el-tag>
           </template>
         </div>
       </div>
       <div class="row">
-        <el-input class="searcher" v-model="searcher" placeholder="请输入任务名称相关关键字" />
+        <el-input
+          class="searcher"
+          v-model="searcher"
+          placeholder="请输入任务名称相关关键字"
+        />
         <el-button type="primary" @click="pullTaskData(1)">搜索</el-button>
         <el-button type="primary" @click="reset(), pullTaskData(1)">重置</el-button>
       </div>
     </div>
     <div class="lighter-container">
-      查询到{{ taskNum }}条任务
-      <el-table table-layout="fixed" row-key="main_id" :data="taskData" class="table">
+      <div class="task-count">查询到{{ taskNum }}条任务</div>
+      <el-table
+        table-layout="fixed"
+        row-key="main_id"
+        :data="taskData"
+        class="table"
+        :height="tableHeight"
+      >
         <el-table-column prop="main_c_name" label="名称" />
         <el-table-column prop="main_c_user_name" label="用户" />
         <el-table-column prop="main_c_state" label="类型">
           <template #default="scope">
-            <el-tag effect="dark" v-show="getType(scope.row.main_c_type) != null" disable-transitions>{{
-              getType(scope.row.main_c_type)?.name ?? "" }}
+            <el-tag
+              effect="dark"
+              v-show="getType(scope.row.main_c_type) != null"
+              disable-transitions
+              >{{ getType(scope.row.main_c_type)?.name ?? "" }}
             </el-tag>
           </template>
         </el-table-column>
         <el-table-column prop="main_c_state" label="状态">
           <template #default="scope">
-            <el-tag effect="dark" v-show="getStatus(scope.row.main_c_state) != null"
-              :type="statusStaticInfo[scope.row.main_c_state]?.tagType ?? ''" disable-transitions>{{
-                getStatus(scope.row.main_c_state)?.name ?? "" }}</el-tag>
+            <el-tag
+              effect="dark"
+              v-show="getStatus(scope.row.main_c_state) != null"
+              :type="statusStaticInfo[scope.row.main_c_state]?.tagType ?? ''"
+              disable-transitions
+              >{{ getStatus(scope.row.main_c_state)?.name ?? "" }}</el-tag
+            >
           </template>
         </el-table-column>
         <el-table-column prop="main_c_start_time" label="任务开始时间">
@@ -66,26 +99,44 @@
         </el-table-column>
         <el-table-column prop="main_c_file_name" label="结果">
           <template #default="scope">
-            <span class="link" v-if="scope.row.main_c_file != null && scope.row.main_c_file_name != null"
-              @click="downloadWithBlob(scope.row.main_c_file, scope.row.main_c_file_name)">
+            <span
+              class="link"
+              v-if="scope.row.main_c_file != null && scope.row.main_c_file_name != null"
+              @click="downloadWithBlob(scope.row.main_c_file, scope.row.main_c_file_name)"
+            >
               {{ scope.row.main_c_file_name }}
             </span>
           </template>
         </el-table-column>
-        <el-table-column label="操作" width="360">
+        <el-table-column label="操作" width="420">
           <template #default="scope">
-            <el-button type="primary" @click="
-              () => {
-                dialog = true;
-                focusTask = scope.row;
-              }
-            ">
+            <el-button
+              type="primary"
+              @click="
+                () => {
+                  dialog = true;
+                  focusTask = scope.row;
+                }
+              "
+            >
               查看详情
             </el-button>
-            <template v-if="scope.row.main_c_file != null && scope.row.main_c_file_name != null">
-              <el-button type="primary" @click="
-                downloadWithBlob(scope.row.main_c_file, scope.row.main_c_file_name)
-                ">
+            <el-button
+              v-if="scope.row.main_c_state == 0"
+              type="success"
+              @click="runTask(scope.row.main_id)"
+            >
+              运行
+            </el-button>
+            <template
+              v-if="scope.row.main_c_file != null && scope.row.main_c_file_name != null"
+            >
+              <el-button
+                type="primary"
+                @click="
+                  downloadWithBlob(scope.row.main_c_file, scope.row.main_c_file_name)
+                "
+              >
                 下载结果
               </el-button>
               <el-button type="primary" @click="preView(scope.row.main_c_file)">
@@ -95,9 +146,13 @@
           </template>
         </el-table-column>
       </el-table>
-      <div class="between-row">
+      <div class="between-row pagination-container">
         <div><!--empty div--></div>
-        <el-pagination layout="prev, pager, next" :total="taskNum" @change="(page) => pullTaskData(page)" />
+        <el-pagination
+          layout="prev, pager, next"
+          :total="taskNum"
+          @change="(page) => pullTaskData(page)"
+        />
       </div>
     </div>
     <el-dialog v-model="dialog" :show-close="true" width="750">
@@ -114,8 +169,11 @@
           {{ focusTask.main_c_comment }}
         </el-descriptions-item>
         <el-descriptions-item label="任务类型">
-          <el-tag effect="dark" v-show="getType(focusTask.main_c_type) != null" disable-transitions>{{
-            getType(focusTask.main_c_type)?.name ?? "" }}
+          <el-tag
+            effect="dark"
+            v-show="getType(focusTask.main_c_type) != null"
+            disable-transitions
+            >{{ getType(focusTask.main_c_type)?.name ?? "" }}
           </el-tag>
         </el-descriptions-item>
         <el-descriptions-item label="用户名">
@@ -125,8 +183,11 @@
           {{ focusTask.main_c_user_id }}
         </el-descriptions-item>
         <el-descriptions-item label="状态">
-          <el-tag effect="dark" :type="statusStaticInfo[focusTask.main_c_state]?.tagType ?? ''" disable-transitions>{{
-            getStatus(focusTask.main_c_state)?.name ?? "" }}
+          <el-tag
+            effect="dark"
+            :type="statusStaticInfo[focusTask.main_c_state]?.tagType ?? ''"
+            disable-transitions
+            >{{ getStatus(focusTask.main_c_state)?.name ?? "" }}
           </el-tag>
         </el-descriptions-item>
         <el-descriptions-item label="任务开始时间">
@@ -138,21 +199,32 @@
         <el-descriptions-item label="结果文件">
           {{ focusTask.main_c_file_name }}
 
-          <template v-if="focusTask.main_c_file != null && focusTask.main_c_file_name != null">
-            <el-button type="primary" size="small"
-              @click="downloadWithBlob(focusTask.main_c_file, focusTask.main_c_file_name)">
+          <template
+            v-if="focusTask.main_c_file != null && focusTask.main_c_file_name != null"
+          >
+            <el-button
+              type="primary"
+              size="small"
+              @click="downloadWithBlob(focusTask.main_c_file, focusTask.main_c_file_name)"
+            >
               下载结果
             </el-button>
-            <el-button type="primary" size="small" @click="preView(focusTask.main_c_file)">
+            <el-button
+              type="primary"
+              size="small"
+              @click="preView(focusTask.main_c_file)"
+            >
               预览结果
             </el-button>
           </template>
         </el-descriptions-item>
         <el-descriptions-item label="原始数据">
-          <template v-if="
-            focusTask.main_c_source_file_name != null &&
-            focusTask.main_c_source_file != null
-          ">
+          <template
+            v-if="
+              focusTask.main_c_source_file_name != null &&
+              focusTask.main_c_source_file != null
+            "
+          >
             {{ focusTask.main_c_source_file_name }}
             <br />
           </template>
@@ -168,7 +240,7 @@
 </template>
 
 <script>
-import { getTasks, getCName } from "@/api/rwgl";
+import { getTasks, getCName, executeTask } from "@/api/rwgl";
 
 export default {
   data() {
@@ -197,12 +269,18 @@ export default {
       focusTask: {},
       dialog: false,
       page: 1,
+      tableHeight: 0,
     };
   },
   mounted() {
     this.pullTaskStatus();
     this.pullTaskType();
     this.pullTaskData(1);
+    this.calculateTableHeight();
+    window.addEventListener("resize", this.calculateTableHeight);
+  },
+  beforeUnmount() {
+    window.removeEventListener("resize", this.calculateTableHeight);
   },
   methods: {
     async pullTaskStatus() {
@@ -211,8 +289,8 @@ export default {
       for (const key of Object.keys(oData)) {
         newData.push({
           index: Number(key),
-          name: oData[key]
-        })
+          name: oData[key],
+        });
       }
       this.taskStatus = newData.sort((a, b) => a.index - b.index);
     },
@@ -255,8 +333,8 @@ export default {
       for (const key of Object.keys(oData)) {
         newData.push({
           index: Number(key),
-          name: oData[key]
-        })
+          name: oData[key],
+        });
       }
       let taskType = newData.sort((a, b) => a.index - b.index);
       for (let i = 0; i < taskType.length; i++) {
@@ -267,7 +345,7 @@ export default {
           break;
         }
       }
-      this.taskType = taskType
+      this.taskType = taskType;
     },
     changeTaskType(types) {
       if (types == null) {
@@ -341,12 +419,62 @@ export default {
     preView(url) {
       window.open("fileView?url=" + systemConfig.dmsDataProxy + url, "_blank");
     },
+    async runTask(taskId) {
+      try {
+        const res = await executeTask(taskId);
+        if (res.code === 200) {
+          this.$message({
+            type: "success",
+            message: res.content || "任务已提交,正在后台执行",
+          });
+          // 先禁用按钮,防止重复点击
+          this.$refs.runTaskBtn.disabled = true;
+          // 刷新任务列表
+          setTimeout(() => {
+            // 执行成功后,刷新任务列表
+            this.pullTaskData(this.page);
+          }, 300);
+        } else {
+          this.$message({
+            type: "error",
+            message: res.message || "执行任务失败",
+          });
+        }
+      } catch (error) {
+        console.error("执行任务失败:", error);
+        this.$message({
+          type: "error",
+          message: "执行任务失败,请稍后重试",
+        });
+      }
+    },
     truncateText(text, maxLength = 40) {
       if (typeof text !== "string" || text.length <= maxLength) {
         return text;
       }
       return text.substring(0, maxLength) + "…";
     },
+    calculateTableHeight() {
+      // 计算表格高度:窗口高度 - header高度 - footer高度 - 页面padding - 其他元素高度
+      const windowHeight = window.innerHeight;
+      const headerHeight = 70; // Header组件高度
+      const footerHeight = 50; // Footer组件高度
+      const pagePadding = 40 * 2; // 页面上下padding
+      const filterAreaHeight = 120; // 筛选条件区域高度
+      const taskCountHeight = 30; // 任务数量文字高度
+      const paginationHeight = 50; // 分页区域高度
+      const containerMargin = 15 * 2; // 容器上下margin
+
+      this.tableHeight =
+        windowHeight -
+        headerHeight -
+        footerHeight -
+        pagePadding -
+        filterAreaHeight -
+        taskCountHeight -
+        paginationHeight -
+        containerMargin;
+    },
   },
 };
 </script>
@@ -413,7 +541,7 @@ link {
   margin-left: 0;
   padding-left: 90px;
   padding-right: 90px;
-  min-height: 80vh
+  min-height: 80vh;
 }
 
 .darkblue-background {
@@ -427,6 +555,7 @@ link {
 .blue-background,
 body {
   background: #0f3460;
+  overflow: hidden;
 }
 
 .bluedark-background {
@@ -447,6 +576,15 @@ body {
   border-radius: 3%;
 }
 
+.task-count {
+  margin-bottom: 10px;
+  color: #fff;
+}
+
+.pagination-container {
+  margin-top: 15px;
+}
+
 .lightblue-container {
   border-radius: 3%;
   padding: 10px;
@@ -490,7 +628,7 @@ body {
   justify-content: flex-start;
 }
 
-.left-row>* {
+.left-row > * {
   margin-right: 15px;
 }
 
@@ -512,8 +650,8 @@ body {
   flex-direction: column-reverse;
 }
 
-.dense-col>*,
-.start-reverse-col>* {
+.dense-col > *,
+.start-reverse-col > * {
   margin: 10px;
 }