Browse Source

教师的批量导入

dusenyao 10 months ago
parent
commit
093c504c91

+ 16 - 3
src/api/user.js

@@ -56,14 +56,27 @@ export function StartBatchRegisterStudent(data) {
 }
 
 /**
- * 得到批量注册学员任务进度
+ * 开始批量注册教师
+ * @param {object} data
+ */
+export function StartBatchRegisterTeacher(data) {
+  return request({
+    method: 'post',
+    url: process.env.VUE_APP_FileServer,
+    params: getRequestParams('user_manager-StartBatchRegisterTeacher'),
+    data
+  });
+}
+
+/**
+ * 得到批量注册任务进度
  * @param {Object} data
  */
-export function GetBatchRegisterStudentProgress(data) {
+export function GetBatchRegisterTaskProgress(data) {
   return request({
     method: 'post',
     url: process.env.VUE_APP_FileServer,
-    params: getRequestParams('user_manager-GetBatchRegisterStudentProgress'),
+    params: getRequestParams('user_manager-GetBatchRegisterTaskProgress'),
     data
   });
 }

+ 8 - 2
src/views/student_manager/BatchRegistration.vue → src/components/common/BatchRegistration.vue

@@ -10,7 +10,7 @@
         :before-upload="beforeUpload"
         :http-request="request"
         :show-file-list="false"
-        accept=".xls"
+        accept=".xls,.xlsx"
       >
         <el-button size="small">选择文件</el-button>
       </el-upload>
@@ -34,6 +34,10 @@ const props = defineProps({
   visible: {
     type: Boolean,
     required: true
+  },
+  type: {
+    type: String,
+    required: true
   }
 });
 
@@ -43,7 +47,9 @@ let file_id = ref('');
 let file_name = ref('');
 const templateURL = ref('');
 
-GetFileResource({ resource_key_list: ['batch_register_student_template'] }).then(({ file_list }) => {
+let resource_key_list =
+  props.type === 'student' ? ['batch_register_student_template'] : ['batch_register_teacher_template'];
+GetFileResource({ resource_key_list }).then(({ file_list }) => {
   if (file_list.length <= 0) return;
   templateURL.value = file_list[0].file_url;
 });

+ 0 - 0
src/views/student_manager/ExecutiveReport.vue → src/components/common/ExecutiveReport.vue


+ 9 - 9
src/views/student_manager/index.vue

@@ -29,7 +29,7 @@
         </el-col>
       </el-row>
     </div>
-    <!-- 表格 -->
+
     <CommonTable
       name="学生列表"
       :min-height="554"
@@ -75,7 +75,7 @@
       </el-table>
     </CommonTable>
 
-    <BatchRegistration :visible.sync="visible" @batchRegister="batchRegister" />
+    <BatchRegistration :visible.sync="visible" type="student" @batchRegister="batchRegister" />
     <ExecutiveReport
       :visible.sync="visible_executive"
       :success-count="successCount"
@@ -102,12 +102,12 @@ import { PageQueryOrgStudentUserList } from '@/api/list';
 import { AuditOrgStudentUser } from '@/api/student';
 import { useList } from '@/utils/list';
 import { Message } from 'element-ui';
-import { StartBatchRegisterStudent, GetBatchRegisterStudentProgress } from '@/api/user';
+import { StartBatchRegisterStudent, GetBatchRegisterTaskProgress } from '@/api/user';
 
 import CommonTable from '@/components/common/CommonTable.vue';
 import DateSearch from '@/components/common/DateSearch.vue';
-import BatchRegistration from './BatchRegistration.vue';
-import ExecutiveReport from './ExecutiveReport.vue';
+import BatchRegistration from '../../components/common/BatchRegistration.vue';
+import ExecutiveReport from '../../components/common/ExecutiveReport.vue';
 
 const { page_capacity, cur_page, total_count, list, changePage, changePageSize } = useList();
 
@@ -174,8 +174,8 @@ let successCount = ref(0);
 let errorCount = ref(0);
 let executeReportFileUrl = ref('');
 let isInterrupt = ref(false);
-function getBatchRegisterProgress(batch_register_student_task_id) {
-  return GetBatchRegisterStudentProgress({ batch_register_student_task_id })
+function getBatchRegisterProgress(batch_register_task_id) {
+  GetBatchRegisterTaskProgress({ batch_register_task_id })
     .then(
       ({
         is_exist_task,
@@ -215,12 +215,12 @@ function getBatchRegisterProgress(batch_register_student_task_id) {
         return pageQueryOrgStudentUserList();
       }
       timer = setTimeout(() => {
-        getBatchRegisterProgress(batch_register_student_task_id);
+        getBatchRegisterProgress(batch_register_task_id);
       }, 100);
     })
     .catch(() => {
       timer = setTimeout(() => {
-        getBatchRegisterProgress(batch_register_student_task_id);
+        getBatchRegisterProgress(batch_register_task_id);
       }, 100);
     });
 }

+ 113 - 1
src/views/teacher_manager/index.vue

@@ -29,7 +29,7 @@
         </el-col>
       </el-row>
     </div>
-    <!-- 表格 -->
+
     <CommonTable
       name="教师列表"
       :min-height="554"
@@ -41,6 +41,10 @@
       @current-change="changePage($event, queryOrgTeacherUserList)"
       @size-change="changePageSize($event, queryOrgTeacherUserList)"
     >
+      <template #button>
+        <el-button type="primary" class="table-button" @click="visible = true">批量注册</el-button>
+      </template>
+
       <el-table :data="list">
         <el-table-column prop="user_name" label="用户名" width="180" />
         <el-table-column prop="user_real_name" label="姓名" width="180" />
@@ -96,6 +100,19 @@
         </el-table-column>
       </el-table>
     </CommonTable>
+
+    <BatchRegistration :visible.sync="visible" type="teacher" @batchRegister="batchRegister" />
+    <ExecutiveReport
+      :visible.sync="visible_executive"
+      :success-count="successCount"
+      :error-count="errorCount"
+      :execute-report-file-url="executeReportFileUrl"
+      :is-interrupt="isInterrupt"
+    />
+
+    <div v-show="loading" class="loading">
+      <el-progress type="circle" :percentage="percentage" :width="200" />
+    </div>
   </div>
 </template>
 
@@ -109,12 +126,16 @@ export default {
 import { ref } from 'vue';
 import { pageQueryOrgTeacherUserList } from '@/api/list';
 import { auditOrgTeacherUser, getPopedomList_OrgTeacherUse, setPopedom_OrgTeacherUser } from '@/api/teacher';
+import { StartBatchRegisterTeacher, GetBatchRegisterTaskProgress } from '@/api/user';
 import { useList } from '@/utils/list';
 import { Message } from 'element-ui';
 
 import DateSearch from '@/components/common/DateSearch.vue';
 import CommonTable from '@/components/common/CommonTable.vue';
+import BatchRegistration from '../../components/common/BatchRegistration.vue';
+import ExecutiveReport from '../../components/common/ExecutiveReport.vue';
 
+// 审核状态列表
 const auditedList = [
   {
     value: '',
@@ -192,6 +213,75 @@ function setPopedom(user_org_id) {
     Message.success('设置教师权限成功');
   });
 }
+
+// 批量导入
+let visible = ref(false);
+let visible_executive = ref(false);
+let loading = ref(false);
+let percentage = ref(0);
+let timer = null;
+let successCount = ref(0);
+let errorCount = ref(0);
+let executeReportFileUrl = ref(''); // 报告文件URL
+let isInterrupt = ref(false); // 任务是否中断
+function getBatchRegisterProgress(batch_register_task_id) {
+  GetBatchRegisterTaskProgress({ batch_register_task_id })
+    .then(
+      ({
+        is_exist_task,
+        is_finish,
+        is_interrupt,
+        progress_percent,
+        success_count,
+        error_count,
+        execute_report_file_url
+      }) => {
+        successCount.value = parseInt(success_count);
+        errorCount.value = parseInt(error_count);
+        executeReportFileUrl.value = execute_report_file_url;
+        if (is_exist_task === 'false') {
+          loading.value = false;
+          Message.warning('不存在这个批量注册任务');
+          return clearTimeout(timer);
+        }
+        if (is_interrupt === 'true') {
+          isInterrupt.value = true;
+          loading.value = false;
+          visible_executive.value = true;
+          return false;
+        }
+        percentage.value = parseInt(progress_percent);
+        if (is_finish === 'true') {
+          loading.value = false;
+          clearTimeout(timer);
+          visible_executive.value = true;
+          return false;
+        }
+        return true;
+      }
+    )
+    .then(is_continue => {
+      if (!is_continue) {
+        return queryOrgTeacherUserList();
+      }
+      timer = setTimeout(() => {
+        getBatchRegisterProgress(batch_register_task_id);
+      }, 100);
+    })
+    .catch(() => {
+      timer = setTimeout(() => {
+        getBatchRegisterProgress(batch_register_task_id);
+      }, 100);
+    });
+}
+
+function batchRegister(file_id) {
+  visible.value = false;
+  StartBatchRegisterTeacher({ file_id }).then(({ batch_register_teacher_task_id }) => {
+    loading.value = true;
+    getBatchRegisterProgress(batch_register_teacher_task_id);
+  });
+}
 </script>
 
 <style lang="scss" scoped>
@@ -221,6 +311,11 @@ function setPopedom(user_org_id) {
     }
   }
 
+  .table-button {
+    background-color: #0085ff;
+    border-color: #0085ff;
+  }
+
   .el-table {
     .el-link {
       padding: 2px 8px;
@@ -232,6 +327,23 @@ function setPopedom(user_org_id) {
       }
     }
   }
+
+  .loading {
+    position: fixed;
+    top: 0;
+    left: 0;
+    z-index: 3;
+    width: 100%;
+    height: 100%;
+    background-color: #fff;
+    opacity: 0.8;
+
+    .el-progress {
+      position: absolute;
+      top: calc(50% - 100px);
+      left: calc(50% - 100px);
+    }
+  }
 }
 
 // 权限管理