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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<script lang="ts" setup>
import { nextTick, reactive, toRefs } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
import { buildBitUUID } from '@jnpf/utils';
 
import { cloneDeep } from 'lodash-es';
 
import { alignOptions } from '#/utils/constants';
 
interface State {
  list: any[];
  childColumnsList: any[];
}
 
const emit = defineEmits(['register', 'confirm']);
const state = reactive<State>({
  list: [],
  childColumnsList: [],
});
const { list } = toRefs(state);
const [registerModal, { closeModal }] = useModalInner(init);
const columns = [
  { title: '表头列名', dataIndex: 'fullName', key: 'fullName', width: 200 },
  { title: '子列', dataIndex: 'childColumns', key: 'childColumns', width: 330 },
  { title: '对齐方式', dataIndex: 'align', key: 'align', width: 150 },
  { title: '操作', dataIndex: 'action', key: 'action', width: 50 },
];
 
function init(data) {
  state.list = cloneDeep(data.list);
  state.childColumnsList = cloneDeep(data.columnOptions).map((o) => ({ id: o.id, fullName: o.fullName }));
}
function handleAdd() {
  const id = `complex${buildBitUUID()}`;
  const item = { fullName: `表头列名${id}`, fullNameI18nCode: '', childColumns: [], align: 'center', id };
  state.list.push(item);
}
function handleDel(index) {
  state.list.splice(index, 1);
}
function getChildColumnsList(index) {
  const options: any[] = [];
  for (let i = 0; i < state.list.length; i++) {
    const e = state.list[i];
    if (e.childColumns?.length && index !== i) options.push(...e.childColumns);
  }
  let list: any[] = state.childColumnsList.filter((o) => !options.includes(o.id));
  if (list.length) list = list.map((o) => ({ ...o, align: 'left' }));
  return list;
}
function handleSubmit() {
  emit('confirm', state.list);
  nextTick(() => closeModal());
}
</script>
<template>
  <BasicModal
    v-bind="$attrs"
    width="1000px"
    class="JNPF-complex-header-Modal"
    @register="registerModal"
    title="复杂表头配置"
    @ok="handleSubmit"
    destroy-on-close>
    <a-table size="small" row-key="id" class="complex-header-table" :data-source="list" :columns="columns" :pagination="false">
      <template #bodyCell="{ column, record, index }">
        <template v-if="column.key === 'fullName'">
          <jnpf-i18n-input v-model:value="record.fullName" v-model:i18n="record.fullNameI18nCode" placeholder="请输入" allow-clear :maxlength="50" />
        </template>
        <template v-if="column.key === 'childColumns'">
          <JnpfSelect v-model:value="record.childColumns" placeholder="请选择" multiple show-search allow-clear :options="getChildColumnsList(index)" />
        </template>
        <template v-if="column.key === 'align'">
          <JnpfSelect v-model:value="record.align" placeholder="请选择" :options="alignOptions" />
        </template>
        <template v-if="column.key === 'action'">
          <a-button class="action-btn" type="link" color="error" @click="handleDel(index)" size="small">删除</a-button>
        </template>
      </template>
    </a-table>
    <div class="table-add-action" @click="handleAdd()">
      <a-button type="link" pre-icon="icon-ym icon-ym-btn-add">添加</a-button>
    </div>
  </BasicModal>
</template>
<style lang="scss">
.JNPF-complex-header-Modal {
  .ant-modal-body {
    height: 60vh;
 
    & > .scrollbar {
      padding: 0;
 
      .scrollbar__view {
        .table-add-action {
          margin-bottom: 10px;
        }
      }
    }
  }
}
</style>