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
104
105
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
 
import { nextTick, reactive, ref, toRefs } from 'vue';
 
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
interface State {
  dataForm: any;
  formRules: any;
  options: any[];
}
 
const emit = defineEmits(['register', 'confirm']);
const formElRef = ref<FormInstance>();
const state = reactive<State>({
  dataForm: {
    businessKeyList: [],
    businessKeyTip: '',
  },
  formRules: {
    businessKeyList: [{ required: true, message: '必填', trigger: 'change', type: 'array' }],
    businessKeyTip: [{ required: true, message: '必填', trigger: 'change' }],
  },
  options: [],
});
const { dataForm, formRules, options } = toRefs(state);
const [registerModal, { closeModal }] = useModalInner(init);
const allowList = new Set([
  'areaSelect',
  'cascader',
  'checkbox',
  'datePicker',
  'groupSelect',
  'input',
  'inputNumber',
  'location',
  'organizeSelect',
  'posSelect',
  'radio',
  'roleSelect',
  'select',
  'textarea',
  'timePicker',
  'treeSelect',
  'userSelect',
  'usersSelect',
]);
 
function init(data) {
  getOptions(data.drawingList || []);
  nextTick(() => {
    formElRef.value?.clearValidate();
    state.dataForm.businessKeyList = data.businessKeyList;
    state.dataForm.businessKeyTip = data.businessKeyTip;
  });
}
function getOptions(drawingList) {
  let list: any[] = [];
  const loop = (data, parent?) => {
    if (!data) return;
    if (data.__config__ && data.__config__?.jnpfKey !== 'table' && data.__config__.children && Array.isArray(data.__config__.children)) {
      loop(data.__config__.children, data);
    }
    if (Array.isArray(data)) data.forEach((d) => loop(d, parent));
    if (data.__vModel__ && allowList.has(data.__config__.jnpfKey)) {
      list.push({
        id: data.__vModel__,
        fullName: data.__config__.label,
      });
    }
  };
  loop(drawingList);
  list = list.filter((o) => !o.id.includes('_jnpf_'));
  state.options = list;
}
async function handleSubmit() {
  try {
    const values = await formElRef.value?.validate();
    if (!values) return;
    emit('confirm', { ...state.dataForm });
    closeModal();
  } catch {}
}
</script>
<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="规则设置" @ok="handleSubmit" :min-height="100">
    <a-form :colon="false" :label-col="{ style: { width: '80px' } }" :model="dataForm" :rules="formRules" ref="formElRef">
      <p class="business-tip">选择需要设为业务主键的表单字段</p>
      <a-form-item label="联合字段" name="businessKeyList">
        <jnpf-select v-model:value="dataForm.businessKeyList" :options="options" multiple show-search />
      </a-form-item>
      <a-form-item label="提示语" name="businessKeyTip">
        <jnpf-input v-model:value="dataForm.businessKeyTip" placeholder="请输入" />
      </a-form-item>
    </a-form>
  </BasicModal>
</template>
<style lang="scss">
.business-tip {
  padding: 0 4px;
  margin-bottom: 10px;
  color: var(--text-color-label);
}
</style>