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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<script lang="ts" setup>
import type { TreeActionType } from '@jnpf/ui';
import type { BasicColumn } from '@jnpf/ui/vxeTable';
 
import { computed, nextTick, reactive, ref, unref, watch } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
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 { getTableInfoByTableName } from '#/api/system/authorize';
import { $t } from '#/locales';
 
defineOptions({ inheritAttrs: false });
const props = defineProps({
  value: { default: '' },
  title: { type: String, default: '' },
  popupTitle: { type: String, default: '字段名称' },
  disabled: { type: Boolean, default: false },
  allowClear: { type: Boolean, default: true },
  size: { type: String, default: 'default' },
  treeData: { type: Array, default: () => [] },
  menuType: { type: Number },
  dataType: { type: Number },
});
const emit = defineEmits(['update:value', 'change']);
const formItemContext = Form.useInjectFormItemContext();
const innerValue = ref(undefined);
const visible = ref(false);
 
const columns: BasicColumn[] = [
  { title: '名称', dataIndex: 'field' },
  { title: '说明', dataIndex: 'fieldName' },
];
const searchInfo = reactive({
  linkId: '',
  tableName: '',
  menuType: 0,
  dataType: 0,
});
const { createMessage } = useMessage();
const leftTreeRef = ref<Nullable<TreeActionType>>(null);
const treeLoading = ref(false);
const leftTreeData = ref<any[]>([]);
const [registerTable, { getForm, getSelectRows, getSelectRowKeys }] = useVxeTable({
  api: getTableInfoByTableName,
  columns,
  immediate: false,
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 8 },
    schemas: [
      {
        field: 'keyword',
        label: $t('common.keyword'),
        component: 'Input',
        componentProps: {
          placeholder: $t('common.enterKeyword'),
          submitOnPressEnter: true,
        },
      },
    ],
  },
  tableSetting: { size: false, setting: false },
  rowSelection: { type: 'radio' },
  rowKey: 'field',
});
 
const getSelectBindValue = computed(() => {
  return {
    ...pick(props, ['disabled', 'size', 'allowClear']),
    placeholder: '请输入',
    showArrow: true,
  };
});
 
watch(
  () => props.value,
  (val) => {
    setValue(val);
  },
  { immediate: true },
);
 
function setValue(value) {
  innerValue.value = value || undefined;
}
function onChange() {
  emit('change', innerValue.value);
}
async function openSelectModal() {
  if (props.disabled) return;
  if (!props.treeData.length) return createMessage.warning('请先进行数据连接!');
  visible.value = true;
  leftTreeData.value = props.treeData ? props.treeData.map((o: any) => ({ fullName: o.tableName, id: o.tableName, dbLink: o.dbLink })) : [];
  searchInfo.tableName = leftTreeData.value[0].fullName || '';
  searchInfo.linkId = leftTreeData.value[0].dbLink || '';
  searchInfo.menuType = props.menuType || 0;
  searchInfo.dataType = props.dataType || 0;
  nextTick(() => {
    const leftTree = unref(leftTreeRef);
    leftTree?.setSelectedKeys([searchInfo.tableName]);
    getForm().resetFields();
  });
}
function handleTreeSelect(id) {
  if (!id || searchInfo.tableName === id) return;
  searchInfo.tableName = id;
  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, searchInfo.tableName);
    formItemContext.onFieldChange();
    handleCancel();
    return;
  }
  const selectRow: any = getSelectRows()[0];
  innerValue.value = selectRow.field;
  emit('update:value', selectRow.field);
  emit('change', selectRow.field, searchInfo.tableName, selectRow.fieldName);
  formItemContext.onFieldChange();
  handleCancel();
}
</script>
 
<template>
  <div class="common-container">
    <a-input v-model:value="innerValue" v-bind="getSelectBindValue" @change="onChange">
      <template #addonAfter>
        <span @click="openSelectModal" class="cursor-pointer">选择</span>
      </template>
    </a-input>
    <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="leftTreeData" :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" />
          </div>
        </div>
      </div>
    </AModal>
  </div>
</template>