Browse Source

电脑统计

wangbin 3 years ago
parent
commit
8829755671
2 changed files with 76 additions and 1 deletions
  1. 48 0
      src/api/log.js
  2. 28 1
      src/view/logComputer/computerUseLog.vue

+ 48 - 0
src/api/log.js

@@ -58,4 +58,52 @@ export const computerUseLog = (data) => {
     method: 'post',
     data
   })
+}
+
+
+const handleFileError = (res, fileName) => {
+  if (typeof (res.data) !== 'undefined') {
+    if (res.data.type === 'application/json') {
+      const reader = new FileReader()
+      reader.onload = function() {
+        const message = JSON.parse(reader.result).msg
+        ElMessage({
+          showClose: true,
+          message: message,
+          type: 'error'
+        })
+      }
+      reader.readAsText(new Blob([res.data]))
+    }
+  } else {
+    var downloadUrl = window.URL.createObjectURL(new Blob([res]))
+    var a = document.createElement('a')
+    a.style.display = 'none'
+    a.href = downloadUrl
+    a.download = fileName
+    var event = new MouseEvent('click')
+    a.dispatchEvent(event)
+  }
+}
+
+// @Tags excel
+// @Summary 导出Excel
+// @Security ApiKeyAuth
+// @accept application/json
+// @Produce  application/octet-stream
+// @Param data body model.ExcelInfo true "导出Excel文件信息"
+// @Success 200
+// @Router /loging/exportExcel [post]
+export const exportExcel = (tableData, fileName) => {
+  service({
+    url: '/loging/exportExcel',
+    method: 'post',
+    data: {
+      fileName: fileName,
+      infoList: tableData
+    },
+    responseType: 'blob'
+  }).then((res) => {
+    handleFileError(res, fileName)
+  })
 }

+ 28 - 1
src/view/logComputer/computerUseLog.vue

@@ -37,6 +37,9 @@
         </el-form>
       </div>
       <div class="gva-table-box">
+        <div class="gva-btn-list">
+        <el-button class="excel-btn" size="small" type="primary" icon="download" @click="handleExcelExport">导出</el-button>
+      </div>
         <el-table :data="tableData"  @sort-change="sortChange" @selection-change="handleSelectionChange"
         border
         >
@@ -47,6 +50,13 @@
           <el-table-column align="left" label="电脑编号" min-width="100" prop="pc_code" sortable="custom"/>
           <el-table-column align="left" label="使用者" min-width="150" prop="operator" sortable="custom"/>
           <el-table-column align="left" label="日期" min-width="150" prop="create_date" />
+          <el-table-column align="left" label="拉取账号" min-width="150" prop="pull_account_total" />
+          <el-table-column align="left" label="进入主线" min-width="150" prop="enter_main_total" />
+          <el-table-column label="主线成功率" align="center"  min-width="100">
+            <template #default="scope">
+							{{ scope.row.enter_main_total == 0 || scope.row.pull_account_total == 0 ? 0 + '%' : Math.round(scope.row.enter_main_total/scope.row.pull_account_total * 10000) / 100 + '%'}}
+						</template>
+          </el-table-column>
           <el-table-column align="left" label="状态" min-width="150" prop="status" >
           <template #default="scope">
             <div>
@@ -97,7 +107,7 @@
   <script setup>
   import {
     computerUseLog,
-    logComputerNum,
+    exportExcel,
   } from '@/api/log'
   import { toSQLLine } from '@/utils/stringFun'
   import { ref } from 'vue'
@@ -252,8 +262,25 @@ const searchStatusOptions = ref([
       searchInfo.value.orderKey = toSQLLine(prop)
       searchInfo.value.desc = order === 'descending'
     }
+    console.log(searchInfo.value.create_date)
+    
     getTableData()
   }
+
+  const handleExcelExport = async() => {
+    var fileName = Date.parse(new Date()) + "-pc.xlsx"
+    if(searchInfo.value.create_date == null){
+      let dt = new Date()
+            var y = dt.getFullYear()
+            var mt = (dt.getMonth() + 1).toString().padStart(2,'0')
+            var day = dt.getDate().toString().padStart(2,'0')
+            var timeStr = y + "-" + mt + "-" + day
+      fileName = timeStr + "-pc.xlsx"
+    }else{
+      fileName = searchInfo.value.create_date + "-pc.xlsx"
+    }
+  exportExcel({ page: page.value, pageSize: pageSize.value, ...searchInfo.value },fileName)
+}
   
   // 查询
   const getTableData = async() => {