ny
22 小时以前 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
<script lang="ts" setup>
import { ref } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { cloneDeep } from 'lodash-es';
 
import { noGroupList } from '#/components/FormGenerator/src/helper/config';
import { $t } from '#/locales';
 
const emit = defineEmits(['register', 'download']);
const [registerModal, { changeOkLoading }] = useModalInner(init);
const { createMessage } = useMessage();
const dataType = ref(0);
const showExportSelected = ref(false);
const selectIds = ref([]);
const isIndeterminate = ref(false);
const checkAll = ref(false);
const columnList = ref<any[]>([]);
const checkedList = ref<string[]>([]);
const defaultCheckedList = ref<string[]>([]);
 
function init(data) {
  showExportSelected.value = data.showExportSelected || data.showExportSelected == false ? data.showExportSelected : true;
  columnList.value = cloneDeep(data.columnList).filter((o) => !noGroupList.includes(o.__config__.jnpfKey));
  selectIds.value = data.selectIds || [];
  dataType.value = 0;
  checkedList.value = columnList.value.map((o) => o.id);
  handleCheckedChange(checkedList.value);
}
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 data = { dataType: dataType.value, selectKey: checkedList.value, selectIds: selectIds.value };
  emit('download', data);
}
</script>
<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    :title="$t('common.exportText')"
    :ok-text="$t('common.exportText')"
    @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="0">当前页面数据</a-radio>
          <a-radio :value="1">全部页面数据</a-radio>
          <a-radio :value="2" :disabled="!selectIds || !selectIds.length" v-if="showExportSelected">当前选择数据</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>