Kaynağa Gözat

fix(组件): 新增导出数据

gemercheung 2 yıl önce
ebeveyn
işleme
ed9ad0b7d7

+ 18 - 1
src/api/staff/list.ts

@@ -1,5 +1,5 @@
 import { defHttp } from '/@/utils/http/axios';
-import { PageParams, ListGetResultModel, DelParams, roleParams } from './model';
+import { PageParams, ListGetResultModel, DelParams, roleParams, ExportParam } from './model';
 import { Result, UploadFileParams } from '/#/axios';
 
 enum Api {
@@ -14,6 +14,7 @@ enum Api {
   getNumByStaff = '/zfb-api/zfb/shop/sys/user/getNumByStaff',
   clean = '/zfb-api/zfb/loginOutByUser',
   upload = '/zfb-api/zfb/sys/oss/upload',
+  staffExport = '/zfb-api/zfb/shop/sys/user/staffExport',
 }
 
 /**
@@ -139,3 +140,19 @@ export function uploadApi(
     params,
   );
 }
+
+export const exportApi = (params: ExportParam) =>
+  defHttp.post<Blob>(
+    {
+      url: Api.staffExport,
+      params,
+      responseType: 'blob',
+      headers: {
+        // @ts-ignore
+        ignoreCancelToken: true,
+      },
+    },
+    {
+      errorMessageMode: 'none',
+    },
+  );

+ 5 - 0
src/api/staff/model.ts

@@ -4,6 +4,11 @@ import { BasicPageParams, BasicFetchResult } from '/@/api/model/baseModel';
  */
 export type PageParams = BasicPageParams;
 
+export interface ExportParam extends PageParams {
+  staffName?: string;
+  staffPhone: string;
+}
+
 export interface DelParams {
   userId: number;
   toUserId: number;

+ 5 - 0
src/views/dashboard/analysis/index.vue

@@ -82,6 +82,11 @@
       title: '微信昵称',
       dataIndex: 'nickName',
       width: 120,
+      ellipsis: true,
+      customRender: ({ record }) => {
+        const { nickName } = record;
+        return nickName?.length ? nickName : ' -- ';
+      },
     },
     {
       title: '手机号',

+ 35 - 2
src/views/staff/list.vue

@@ -8,6 +8,12 @@
           @click="handleCreate"
           >新增</a-button
         >
+        <a-button
+          v-power="[RoleEnum.COMPANY_ADMIN, RoleEnum.PLAT_ADMIN]"
+          type="error"
+          @click="handleExport"
+          >导出数据</a-button
+        >
       </template>
       <template #headerTop v-if="getCheckRole([RoleEnum.COMPANY_ADMIN])">
         <Alert
@@ -65,7 +71,7 @@
   </div>
 </template>
 <script lang="ts">
-  import { defineComponent, computed, onMounted, ref } from 'vue';
+  import { defineComponent, computed, onMounted, ref, reactive } from 'vue';
   import {
     BasicTable,
     useTable,
@@ -82,13 +88,14 @@
   import DelListModal from './delListModal.vue';
   import { Alert } from 'ant-design-vue';
   // import { h } from 'vue';
-  import { ListApi, delApi, preDelApi, getNumByStaff } from '/@/api/staff/list';
+  import { ListApi, delApi, preDelApi, getNumByStaff, exportApi } from '/@/api/staff/list';
   import { useI18n } from '/@/hooks/web/useI18n';
   // import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
   import { RoleEnum } from '/@/enums/roleEnum';
   import { useGo } from '/@/hooks/web/usePage';
   import { Time } from '/@/components/Time';
   import { useUserStore } from '/@/store/modules/user';
+  import { ExportParams } from '/@/api/staff/model';
   export default defineComponent({
     components: {
       BasicTable,
@@ -120,6 +127,11 @@
         getNumByStaffData();
       });
 
+      let searchInfo: ExportParams = reactive({
+        staffName: '',
+        staffPhone: '',
+      });
+
       const columns: BasicColumn[] = [
         {
           title: 'ID',
@@ -238,6 +250,10 @@
           let order = sortInfo.order && sortInfo.order.replace('end', '');
           return { ...sortInfo, sidx: sortInfo.field, order: order };
         },
+        searchInfo: searchInfo,
+        handleSearchInfoFn(data) {
+          searchInfo = Object.assign(searchInfo, data);
+        },
       });
 
       function renderRoleType(type: number): string {
@@ -305,6 +321,22 @@
           },
         });
       }
+      async function handleExport() {
+        const data = await exportApi(searchInfo);
+        const downloadBlob = new Blob([data], {
+          type: 'application/msexcel',
+        });
+        const url = URL.createObjectURL(downloadBlob);
+        const a: HTMLAnchorElement = document.createElement('a');
+        document.body.appendChild(a);
+        a.style.display = 'none';
+        a.href = url;
+        const name = new Date().getTime();
+        a.download = `${name}.csv`;
+        a.click();
+        window.URL.revokeObjectURL(url);
+      }
+
       return {
         registerTable,
         registerDetail,
@@ -327,6 +359,7 @@
         surplusSubNum,
         getCheckRole,
         getNumByStaffData,
+        handleExport,
       };
     },
   });