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
<script lang="ts" setup>
import { computed, nextTick, reactive, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { cloneDeep } from 'lodash-es';
 
import { buildAiFields } from '#/components/FormGenerator/src/helper/aiUtils';
import { vModelIgnoreList } from '#/components/FormGenerator/src/helper/config';
 
import { inputComponents, selectComponents, systemComponents } from '../helper/componentMap';
 
interface State {
  list: any[];
  selectedRowKeys: string[];
}
 
const emit = defineEmits(['register', 'reload']);
const state = reactive<State>({
  list: [],
  selectedRowKeys: [],
});
const { list, selectedRowKeys } = toRefs(state);
const { createMessage } = useMessage();
const [registerModal, { closeModal }] = useModalInner(init);
const columns = [
  { title: '字段名称', dataIndex: 'label', key: 'label', width: 200 },
  { title: '字段类型', dataIndex: 'jnpfKey', key: 'jnpfKey', width: 200 },
];
const jnpfKeyOptions = [...inputComponents, ...selectComponents, ...systemComponents];
const ignoreList = new Set(['popupAttr', 'relationFormAttr', 'table', ...vModelIgnoreList]);
 
const getJnpfKeyOptions = computed(() =>
  jnpfKeyOptions.filter((o) => !ignoreList.has(o.__config__.jnpfKey)).map((o) => ({ id: o.__config__.label, fullName: o.__config__.jnpfKey })),
);
 
function init(data) {
  state.list = cloneDeep(data.list).find((o) => o.isMain)?.fields || [];
  state.selectedRowKeys = state.list.map((o) => o.fieldName);
}
function onSelectChange(selectedRowKeys) {
  state.selectedRowKeys = selectedRowKeys || [];
}
function handleSubmit() {
  const list = state.list.filter((o) => state.selectedRowKeys.includes(o.fieldName));
  const fields = buildAiFields([{ fields: list, isMain: true }]);
  if (!fields.length) return createMessage.warning('请至少选择一个字段');
  emit('reload', fields);
  nextTick(() => closeModal());
}
</script>
<template>
  <BasicModal v-bind="$attrs" width="600px" class="jnpf-ai-field-Modal" @register="registerModal" title="推荐字段" @ok="handleSubmit" destroy-on-close>
    <a-table
      size="small"
      row-key="fieldName"
      :data-source="list"
      :columns="columns"
      :pagination="false"
      :row-selection="{ columnWidth: 50, selectedRowKeys, onChange: onSelectChange }">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'label'">
          <jnpf-input v-model:value="record.fieldTitle" placeholder="请输入" allow-clear :maxlength="100" />
        </template>
        <template v-if="column.key === 'jnpfKey'">
          <jnpf-select v-model:value="record.fieldComponent" :options="getJnpfKeyOptions" show-search allow-clear />
        </template>
      </template>
    </a-table>
  </BasicModal>
</template>
<style lang="scss">
.jnpf-ai-field-Modal {
  .scrollbar {
    padding: 0 !important;
  }
 
  .ant-table-wrapper {
    min-height: 400px;
  }
}
</style>