ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<script lang="ts" setup>
import { ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { downloadByUrl } from '@jnpf/utils';
 
import { importInfo } from '../helper/config';
 
const [registerModal, { closeModal, changeOkLoading }] = useModalInner(init);
const { createMessage } = useMessage();
const dataType = ref(0);
const type = ref<string>('user');
const isIndeterminate = ref(false);
const checkAll = ref(false);
const columnList = ref<any[]>([]);
const checkedList = ref<string[]>([]);
const defaultCheckedList = ref<string[]>([]);
const listQuery = ref({});
const dataTypeList = [
  { fullName: '当前页面数据', id: 0 },
  { fullName: '全部页面数据', id: 1 },
];
 
function init(data) {
  type.value = data.type || 'user';
  columnList.value = importInfo[type.value].exportData.map((o) => ({ ...o, fullName: o.title, id: o.dataIndex }));
  dataType.value = 0;
  checkedList.value = columnList.value.map((o) => o.id);
  handleCheckedChange(checkedList.value);
  listQuery.value = data.listQuery;
}
function handleCheckAllChange(e) {
  const val = e.target.checked;
  checkedList.value = val ? columnList.value.map((o) => o.id) : defaultCheckedList.value;
  isIndeterminate.value = val ? false : !!defaultCheckedList.value.length;
}
function handleCheckedChange(val) {
  const checkedCount = val.length;
  checkAll.value = checkedCount === columnList.value.length;
  isIndeterminate.value = !!checkedCount && checkedCount < columnList.value.length;
}
function handleSubmit() {
  if (!checkedList.value.length) return createMessage.warning('请至少选择一个导出字段');
  changeOkLoading(true);
  const query = {
    ...listQuery.value,
    dataType: dataType.value,
    selectKey: checkedList.value.join(','),
  };
  importInfo[type.value]
    .exportExcel(query)
    .then((res) => {
      changeOkLoading(false);
      if (!res.data.url) return;
      downloadByUrl({ url: res.data.url });
      closeModal();
    })
    .catch(() => {
      changeOkLoading(false);
    });
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="导出" ok-text="导出" @ok="handleSubmit" destroy-on-close class="jnpf-export-modal">
    <a-form :colon="false" label-align="left" :label-col="{ style: { width: '90px' } }">
      <div class="export-line">
        <p class="export-label">导出方式</p>
      </div>
      <a-form-item>
        <a-radio-group v-model:value="dataType">
          <a-radio :value="item.id" v-for="item in dataTypeList" :key="item.id">{{ item.fullName }}</a-radio>
        </a-radio-group>
      </a-form-item>
      <div class="export-line">
        <p class="export-label">导出数据<span>请选择导出字段</span></p>
      </div>
      <a-checkbox :indeterminate="isIndeterminate" v-model:checked="checkAll" @change="handleCheckAllChange">全选</a-checkbox>
      <a-checkbox-group v-model:value="checkedList" class="options-list" @change="handleCheckedChange">
        <a-checkbox v-for="item in columnList" :key="item.id" :value="item.id" class="options-item">
          {{ item.fullName }}
        </a-checkbox>
      </a-checkbox-group>
    </a-form>
  </BasicModal>
</template>