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
<script lang="ts" setup>
import { computed } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
 
import { cloneDeep } from 'lodash-es';
 
const props = defineProps({
  list: { type: Array, default: () => [] },
  dataSetList: { type: Array, default: () => [] },
});
 
const columns = [
  { title: '数据集', dataIndex: 'dataSet', key: 'dataSet', width: 100 },
  { title: '每页条数', dataIndex: 'limit', key: 'limit', width: 80 },
  { title: '操作', dataIndex: 'action', key: 'action', width: 50 },
];
const emptyItem: any = { dataSet: '', limit: null };
const { createMessage } = useMessage();
 
const getDataSetList = computed(() => props.dataSetList.map((o: any) => ({ id: o.fullName, fullName: o.fullName })));
 
function handleAdd() {
  if (props.list.length >= 2) {
    createMessage.warning('最多只能添加2个数据集');
    return;
  }
  props.list.push(cloneDeep(emptyItem));
}
function handleDel(index) {
  props.list.splice(index, 1);
}
</script>
<template>
  <div>
    <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 === 'dataSet'">
          <JnpfSelect v-model:value="record.dataSet" placeholder="请选择" :options="getDataSetList" class="!w-[84px]" :dropdown-match-select-width="false" />
        </template>
        <template v-if="column.key === 'limit'">
          <JnpfInputNumber v-model:value="record.limit" placeholder="请输入" class="!w-[64px]" :min="1" />
        </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>
  </div>
</template>