浏览代码

feat: 表格文件下载超过20000条数据使用CSV文件格式下载

zhouyuhao 1 年之前
父节点
当前提交
5d867824f1

+ 5 - 1
src/views/Booking/src/components/BookingTable/src/BookingTable.vue

@@ -323,8 +323,12 @@ const getExportTableData = (status: number) => {
 }
 // 导出表格 status: 1 导出当前表格 2 导出所有字段表格
 const exportTable = (status: number) => {
+  let type = 'xlsx'
+  if (allTable.value.data.length > 20000) {
+    type = 'csv'
+  }
   const exportConfig: any = {
-    type: 'xlsx',
+    type: type,
     message: false,
     filename: `Booking List_${dayjs().format('YYYYMMDDHH[h]mm[m]ss[s]')}`
   }

+ 68 - 0
src/views/Login/src/loginView.vue

@@ -9,6 +9,74 @@ import dayjs from 'dayjs'
 const router = useRouter()
 const route = useRoute()
 
+// 手动获取url中的参数,直接获取route.query的参数时如果有+号会被转义成空格
+const getQueryParams = (url: string) => {
+  const params = url.split('?')[1]
+  const query = {}
+  if (params) {
+    params.split('&').forEach((param) => {
+      const [key, value] = param.split('=')
+      query[key] = value
+    })
+  }
+  return query
+}
+console.log('route', route.query)
+const handleTokenRedirect = () => {
+  if (route.query.token && route.query.uname) {
+    const obj: any = getQueryParams(route.fullPath)
+    $api
+      .login({
+        uname: obj.uname,
+        token: obj.token
+      })
+      .then((res: any) => {
+        if (res.code === 200) {
+          const { data } = res
+          if (data.msg === 'today') {
+            ElMessageBox.alert('Your password will expire today, please reset', 'Prompt', {
+              confirmButtonText: 'OK',
+              type: 'warning',
+              confirmButtonClass: 'el-button--dark'
+            })
+          } else if (data.msg === 'last') {
+            ElMessageBox.alert(
+              `Your password will expire in${data.data}days, please reset`,
+              'Prompt',
+              {
+                confirmButtonText: 'OK',
+                type: 'warning',
+                confirmButtonClass: 'el-button--dark'
+              }
+            )
+          }
+          userStore.setUsername(res.data.uname || '')
+          router.push('/')
+        } else if (res.code === 400) {
+          const { data } = res
+          if (data.msg === 'Invalid token') {
+            ElMessageBox.alert('Invalid token', 'Prompt', {
+              confirmButtonText: 'OK',
+              type: 'warning',
+              confirmButtonClass: 'el-button--dark'
+            })
+          } else if (data.msg === 'passwordExpires') {
+            ElMessageBox.alert('Password expired, please change your password', 'Prompt', {
+              confirmButtonText: 'OK',
+              type: 'warning',
+              confirmButtonClass: 'el-button--dark'
+            })
+            userStore.setUsername(res.data.uname || '')
+            router.push({
+              name: 'Reset Password'
+            })
+          }
+        }
+      })
+  }
+}
+handleTokenRedirect()
+
 const loginForm = ref({
   username: '',
   password: '',

+ 5 - 1
src/views/Tracking/src/components/TrackingTable/src/TrackingTable.vue

@@ -399,8 +399,12 @@ const getExportTableData = (status: number) => {
 }
 // 导出表格 status: 1 导出当前表格 2 导出所有字段表格
 const exportTable = (status: number) => {
+  let type = 'xlsx'
+  if (allTable.value.data.length > 20000) {
+    type = 'csv'
+  }
   const exportConfig: any = {
-    type: 'xlsx',
+    type: type,
     message: false,
     filename: `Tracking List_${dayjs().format('YYYYMMDDHH[h]mm[m]ss[s]')}`
   }