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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<script lang="ts" setup>
import type { TreeActionType } from '@jnpf/ui';
import type { BasicColumn } from '@jnpf/ui/vxeTable';
 
import { computed, reactive, ref, unref, watch } from 'vue';
 
import { BasicLeftTree } from '@jnpf/ui';
import { ModalClose } from '@jnpf/ui/modal';
import { BasicVxeTable, useVxeTable } from '@jnpf/ui/vxeTable';
 
import { Modal as AModal, Form } from 'ant-design-vue';
import { pick } from 'lodash-es';
import { Grid as VxeGrid } from 'vxe-table';
 
import { getDataInterfaceSelectorList } from '#/api/systemData/dataInterface';
import { $t } from '#/locales';
import { useBaseStore } from '#/store';
 
defineOptions({ inheritAttrs: false });
const props = defineProps({
  value: { default: '' },
  title: { type: String, default: '' },
  popupTitle: { type: String, default: '数据接口' },
  dataType: { type: String, default: '' },
  disabled: { type: Boolean, default: false },
  allowClear: { type: Boolean, default: true },
  size: { type: String, default: 'default' },
  /**
   * sourceType
   * 1 - 过滤掉:鉴权、真分页、SQL的增加、修改、删除类型
   * 2 - 过滤掉:鉴权、SQL的增加、修改、删除类型
   * 3 - 过滤掉:鉴权、真分页、SQL的查询类型
   */
  sourceType: { type: Number, default: 1 },
});
const emit = defineEmits(['update:value', 'change']);
const formItemContext = Form.useInjectFormItemContext();
const baseStore = useBaseStore();
const innerValue = ref(undefined);
const visible = ref(false);
const options = ref<any[]>([]);
 
const columns: BasicColumn[] = [
  { title: '名称', dataIndex: 'fullName', minWidth: 100 },
  { title: '编码', dataIndex: 'enCode', width: 150 },
  { title: '类型', dataIndex: 'type', width: 100 },
];
const templateColumns: BasicColumn[] = [
  { title: $t('component.table.index'), type: 'seq', width: 50, align: 'center' },
  { title: '参数名称', dataIndex: 'field', key: 'field', minWidth: 100, slots: { default: 'field' } },
  { title: '参数类型', dataIndex: 'dataType', key: 'dataType', width: 150, slots: { default: 'dataType' } },
  { title: '默认值', dataIndex: 'defaultValue', key: 'defaultValue', width: 100 },
];
const typeOptions: any[] = [
  { fullName: '字符串', id: 'varchar' },
  { fullName: '整型', id: 'int' },
  { fullName: '日期时间', id: 'datetime' },
  { fullName: '浮点', id: 'decimal' },
  { fullName: '长整型', id: 'bigint' },
  { fullName: '文本', id: 'text' },
];
const searchInfo = reactive({
  category: '',
  sourceType: props.sourceType,
});
const leftTreeRef = ref<Nullable<TreeActionType>>(null);
const treeLoading = ref(false);
const treeData = ref<any[]>([]);
const [registerTable, { getForm, getSelectRows, setSelectedRowKeys, getSelectRowKeys }] = useVxeTable({
  api: getDataInterfaceSelectorList,
  columns,
  immediate: false,
  useSearchForm: true,
  showExpandColumn: true,
  formConfig: {
    baseColProps: { span: 8 },
    schemas: [
      {
        field: 'keyword',
        label: $t('common.keyword'),
        component: 'Input',
        componentProps: {
          placeholder: $t('common.enterKeyword'),
          submitOnPressEnter: true,
        },
      },
      {
        field: 'type',
        label: '类型',
        component: 'Select',
        componentProps: {
          options: [
            { id: '2', fullName: '静态数据' },
            { id: '1', fullName: 'SQL操作' },
            { id: '3', fullName: 'API操作' },
          ],
        },
      },
    ],
  },
  tableSetting: { size: false, setting: false },
  rowSelection: { type: 'radio' },
  afterFetch: (data) => {
    const list = data.map((o) => {
      let templateJson = o.parameterJson ? JSON.parse(o.parameterJson) : [];
      if (!templateJson) templateJson = [];
      return {
        ...o,
        templateJson,
      };
    });
    setTimeout(() => {
      setSelectedRowKeys(innerValue.value ? [innerValue.value] : []);
    }, 100);
    return list;
  },
});
 
const getSelectBindValue = computed(() => {
  return {
    ...pick(props, ['disabled', 'size', 'allowClear']),
    fieldNames: { label: 'fullName', value: 'id' },
    placeholder: '请选择',
    open: false,
    showSearch: false,
    showArrow: true,
  };
});
 
watch(
  () => props.value,
  (val) => {
    setValue(val);
  },
  { immediate: true },
);
watch(
  () => props.title,
  () => {
    setValue(props.value);
  },
);
 
function getTypeText(type) {
  const item = typeOptions.find((o) => o.id == type);
  return item && item.fullName ? item.fullName : '';
}
function setValue(value) {
  innerValue.value = value || undefined;
  options.value = [{ id: innerValue.value, fullName: props.title }];
}
function onChange() {
  options.value = [];
  emit('change', '', {});
}
async function openSelectModal() {
  if (props.disabled) return;
  visible.value = true;
  treeLoading.value = true;
  treeData.value = (await baseStore.getDictionaryData('DataInterfaceType')) as any[];
  if (!treeData.value.length) return (treeLoading.value = false);
  searchInfo.category = treeData.value[0].id;
  const leftTree = unref(leftTreeRef);
  leftTree?.setSelectedKeys([searchInfo.category]);
  treeLoading.value = false;
  getForm().resetFields();
}
function handleTreeSelect(id) {
  if (!id || searchInfo.category === id) return;
  searchInfo.category = id;
  searchInfo.sourceType = props.sourceType;
  getForm().resetFields();
}
function handleCancel() {
  visible.value = false;
}
function handleSubmit() {
  if (!getSelectRowKeys().length && !getSelectRows().length) return;
  if (!getSelectRows().length) {
    emit('update:value', innerValue.value);
    emit('change', innerValue.value, options.value[0]);
    formItemContext.onFieldChange();
    handleCancel();
    return;
  }
  const selectRow: any = getSelectRows()[0];
  options.value = getSelectRows();
  innerValue.value = selectRow.id;
  emit('update:value', selectRow.id);
  emit('change', selectRow.id, selectRow);
  formItemContext.onFieldChange();
  handleCancel();
}
</script>
 
<template>
  <div class="common-container">
    <a-select v-model:value="innerValue" v-bind="getSelectBindValue" :options="options" @change="onChange" @click="openSelectModal" />
    <AModal
      v-model:open="visible"
      :title="popupTitle"
      :width="1000"
      class="common-container-modal"
      @ok="handleSubmit"
      @cancel="handleCancel"
      :mask-closable="false"
      destroy-on-close>
      <template #closeIcon>
        <ModalClose :can-fullscreen="false" @cancel="handleCancel" />
      </template>
      <div class="jnpf-content-wrapper">
        <div class="jnpf-content-wrapper-left">
          <BasicLeftTree ref="leftTreeRef" :show-search="false" :tree-data="treeData" :loading="treeLoading" @select="handleTreeSelect" />
        </div>
        <div class="jnpf-content-wrapper-center">
          <div class="jnpf-content-wrapper-content">
            <BasicVxeTable @register="registerTable" :search-info="searchInfo" class="jnpf-sub-table">
              <template #expandedRowRender="{ record }">
                <VxeGrid :data="record.templateJson" :columns="templateColumns" :min-height="0">
                  <template #field="{ row: childRecord }">
                    <span class="required-sign">{{ childRecord.required ? '*' : '' }}</span>
                    {{ childRecord.field }}{{ childRecord.fieldName ? `(${childRecord.fieldName})` : '' }}
                  </template>
                  <template #dataType="{ row: childRecord }">
                    {{ getTypeText(childRecord.dataType) }}
                  </template>
                </VxeGrid>
              </template>
            </BasicVxeTable>
          </div>
        </div>
      </div>
    </AModal>
  </div>
</template>