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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script lang="ts" setup>
import { computed, ref, unref } from 'vue';
 
import { ModalClose } from '@jnpf/ui/modal';
 
import { Modal as AModal } from 'ant-design-vue';
import { cloneDeep } from 'lodash-es';
 
import { interfaceSystemOptions, sourceTypeFlowOptions, sourceTypeOptions, systemFieldOptions, templateJsonColumns } from '#/utils/define';
 
defineOptions({ inheritAttrs: false });
const props = defineProps({
  // 参数json
  templateJson: { type: Array, default: () => [] },
  // 字段options
  fieldOptions: { type: Array, default: () => [] },
  // 参数来源类型 1:全部参数来源  2:参数来源不回显字段  3:参数来源不显示系统变量
  type: { type: Number, default: 1 },
  // 系统字段显示表单id
  showSystemFormId: { type: Boolean, default: true },
  // 系统字段显示完整名称
  showSystemFullLabel: { type: Boolean, default: false },
  showFieldFullLabel: { type: Boolean, default: false },
  isFlow: { type: Boolean, default: false },
  // 全局参数options
  globalOptions: { type: Array, default: () => [] },
});
const emit = defineEmits(['update:value', 'change', 'fieldChange']);
const visible = ref(false);
const templateList = ref<any[]>([]);
 
const getSystemFieldOptions = computed(() => {
  const list = props.isFlow ? systemFieldOptions : interfaceSystemOptions;
  const option = list.map((o) => ({ ...o, label: o.fullName ? `${o.id}(${o.fullName})` : o.id }));
  return props.showSystemFormId ? option : option.filter((o) => o.id != '@formId');
});
const getSourceTypeOptions = computed(() => {
  const options = props.isFlow ? sourceTypeFlowOptions : sourceTypeOptions;
  return props.type == 2 ? options.filter((o) => o.id != 1) : props.type == 3 ? options.filter((o) => o.id != 4) : options;
});
const getNotNullSourceTypeOptions = computed(() => unref(getSourceTypeOptions).filter((o) => o.id != 3));
 
function openSelectModal() {
  visible.value = true;
  templateList.value = cloneDeep(props.templateJson) || [];
}
function handleCancel() {
  visible.value = false;
}
function onFieldChange(e, row) {
  emit('fieldChange', e, row);
}
function handleSubmit() {
  for (let i = 0; i < templateList.value.length; i++) {
    for (let j = 0; j < props.templateJson.length; j++) {
      if ((props.templateJson[j] as any)?.id == templateList.value[i].id) {
        props.templateJson[j] = templateList.value[i];
      }
    }
  }
  handleCancel();
}
function onSourceTypeChange(record) {
  record.relationField = record.sourceType == 4 ? unref(getSystemFieldOptions)[0]?.id : '';
}
</script>
 
<template>
  <a-button class="!w-full" @click="openSelectModal">设置</a-button>
  <AModal
    class="interface-template-json-modal"
    v-model:open="visible"
    title="参数设置"
    :width="600"
    @ok="handleSubmit"
    @cancel="handleCancel"
    :mask-closable="false"
    centered>
    <template #closeIcon>
      <ModalClose :can-fullscreen="false" @cancel="handleCancel" />
    </template>
    <div class="jnpf-content-wrapper">
      <a-table
        class="w-full"
        :data-source="templateList"
        :columns="templateJsonColumns"
        size="small"
        :pagination="false"
        :scroll="{ x: 'max-content', y: 'calc(40vh - 39px)' }">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'field'">
            <span class="required-sign">{{ record.required ? '*' : '' }}</span>
            {{ record.field }}{{ record.fieldName ? `(${record.fieldName})` : '' }}
          </template>
          <template v-if="column.key === 'sourceType'">
            <jnpf-select
              v-if="record.required"
              v-model:value="record.sourceType"
              :options="getNotNullSourceTypeOptions"
              class="!w-[100px]"
              @change="onSourceTypeChange(record)" />
            <jnpf-select v-else v-model:value="record.sourceType" :options="getSourceTypeOptions" class="!w-[100px]" @change="onSourceTypeChange(record)" />
          </template>
          <template v-if="column.key === 'relationField'">
            <jnpf-select
              v-model:value="record.relationField"
              :options="fieldOptions"
              allow-clear
              show-search
              :field-names="{ label: showFieldFullLabel ? 'label' : 'fullName', options: 'options1' }"
              :option-label-prop="showFieldFullLabel ? 'label' : 'fullName'"
              class="!w-[204px]"
              @change="onFieldChange($event, record)"
              v-if="record.sourceType === 1" />
            <template v-else-if="record.sourceType === 2">
              <jnpf-input-number v-if="['int', 'decimal'].includes(record.dataType)" v-model:value="record.relationField" placeholder="请输入" allow-clear />
              <jnpf-date-picker
                v-else-if="record.dataType == 'datetime'"
                class="!w-full"
                v-model:value="record.relationField"
                placeholder="请选择"
                format="YYYY-MM-DD HH:mm:ss"
                allow-clear />
              <a-input v-else v-model:value="record.relationField" placeholder="请输入" allow-clear />
            </template>
            <jnpf-select
              v-model:value="record.relationField"
              :options="getSystemFieldOptions"
              :field-names="{ label: showSystemFullLabel ? 'label' : 'fullName', options: 'options1' }"
              :option-label-prop="showSystemFullLabel ? 'label' : 'fullName'"
              allow-clear
              class="!w-[204px]"
              v-else-if="record.sourceType === 4" />
            <jnpf-select
              v-model:value="record.relationField"
              :options="globalOptions"
              :field-names="{ label: 'fieldName', value: 'fieldName', options: 'options1' }"
              class="!w-[204px]"
              allow-clear
              v-else-if="record.sourceType === 5" />
          </template>
        </template>
        <template #emptyText>
          <p class="leading-[60px]">暂无数据</p>
        </template>
      </a-table>
    </div>
  </AModal>
</template>