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
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
236
237
238
239
240
<script lang="ts" setup>
import type { FormInstance } from 'ant-design-vue';
 
import { computed, nextTick, reactive, ref, toRefs, unref, watch } from 'vue';
 
import { ModalClose, useFullScreen } from '@jnpf/ui/modal';
 
import { RedoOutlined } from '@ant-design/icons-vue';
import { Modal as AModal } from 'ant-design-vue';
 
import { getDataInterfaceDataSelect } from '#/api/systemData/dataInterface';
import { $t } from '#/locales';
 
interface State {
  list: any[];
  listQuery: any;
  loading: boolean;
  total: number;
}
 
defineOptions({ inheritAttrs: false, name: 'SelectModal' });
const props = defineProps({
  config: {
    type: Object,
    default: () => {},
  },
  formData: Object,
});
 
const { handleFullScreen, getWrapClassName, fullScreenRef, resetFullScreen } = useFullScreen();
const visible = ref(false);
const formElRef = ref<FormInstance>();
const tableElRef = ref<any>(null);
const indexColumn = { width: 50, title: '序号', dataIndex: 'index', key: 'index', align: 'center', customRender: ({ index }) => index + 1 };
const state = reactive<State>({
  list: [],
  listQuery: {
    keyword: '',
    currentPage: 1,
    pageSize: 20,
  },
  loading: false,
  total: 0,
});
const { listQuery, list } = toRefs(state);
 
const getFormClass = computed(() => {
  return ['jnpf-basic-form', `jnpf-basic-form--compact`, 'search-form'];
});
const getColumns = computed<any[]>(() => {
  const columns = (props.config.columnOptions as any)
    .filter((o) => o.ifShow || o.ifShow === undefined)
    .map((o) => ({ title: o.label, dataIndex: o.value, ellipsis: true, width: o.width || 100 }));
  return [indexColumn, ...columns];
});
const searchInfo = computed(() => {
  const paramList = getParamList();
  const columnOptions = (props.config.columnOptions as any).map((o) => o.value).join(',');
  const info: any = {
    interfaceId: props.config.interfaceId,
    columnOptions,
    paramList,
  };
 
  return info;
});
const getPagination = computed<any>(() => {
  return {
    current: state.listQuery.currentPage,
    pageSize: state.listQuery.pageSize,
    size: 'small',
    defaultPageSize: 20,
    showTotal: (total) => $t('component.table.total', { total }),
    showSizeChanger: true,
    pageSizeOptions: ['20', '50', '80', '100'],
    showQuickJumper: true,
    total: state.total,
  };
});
const getScrollY = computed(() => {
  const scale = unref(fullScreenRef) ? 0.9 : 0.7;
  let height = window.innerHeight * scale - 52 - 38;
  height -= 44;
  return height;
});
const getTableBindValues = computed(() => {
  return {
    class: 'jnpf-basic-table',
    columns: unref(getColumns),
    pagination: unref(getPagination),
    size: 'small',
    loading: state.loading,
    rowKey: (record) => record,
    scroll: {
      y: unref(getScrollY),
    },
  };
});
 
defineExpose({ openViewModal });
 
watch(
  () => fullScreenRef.value,
  () => {
    nextTick(() => setTableHeight());
  },
);
 
function getForm() {
  const form = unref(formElRef);
  if (!form) {
    throw new Error('form is null!');
  }
  return form;
}
function openViewModal() {
  visible.value = true;
  setTimeout(() => {
    nextTick(() => {
      handleReset();
      setTableHeight();
      resetFullScreen();
      state.list = [];
      state.total = 0;
      const tableEl = tableElRef.value?.$el;
      const bodyEl = tableEl.querySelector('.ant-table-body');
      bodyEl!.style.height = `${unref(getScrollY)}px`;
    });
  }, 50);
}
function handleCancel() {
  visible.value = false;
}
 
function getParamList() {
  const templateJson: any[] = props.config.templateJson;
  if (!props.formData) return templateJson;
  for (const e of templateJson) {
    const data = props.formData;
    if (e.sourceType == 1) {
      e.defaultValue = data[e.relationField] || data[e.relationField] == 0 || data[e.relationField] == false ? data[e.relationField] : '';
    }
  }
  return templateJson;
}
function handleSearch() {
  state.listQuery.currentPage = 1;
  state.listQuery.pageSize = 20;
  initData();
}
function handleReset() {
  getForm().resetFields();
  state.listQuery.keyword = '';
  handleSearch();
}
function initData() {
  if (!props.config.interfaceId) return;
  state.loading = true;
  const query = {
    ...state.listQuery,
    ...unref(searchInfo),
  };
  getDataInterfaceDataSelect(query)
    .then((res) => {
      state.list = res.data.list;
      state.total = res.data.pagination.total;
      state.loading = false;
    })
    .catch(() => {
      state.loading = false;
    });
}
function handleTableChange(pagination) {
  state.listQuery.currentPage = pagination.current;
  state.listQuery.pageSize = pagination.pageSize;
  initData();
}
function setTableHeight() {
  const tableEl = tableElRef.value?.$el;
  const bodyEl = tableEl.querySelector('.ant-table-body');
  bodyEl!.style.height = `${unref(getScrollY)}px`;
}
</script>
 
<template>
  <div class="common-container">
    <AModal
      v-model:open="visible"
      title="查看数据"
      :width="800"
      class="common-container-modal"
      :wrap-class-name="getWrapClassName"
      @cancel="handleCancel"
      :footer="null"
      :mask-closable="false">
      <template #closeIcon>
        <ModalClose :full-screen="fullScreenRef" @cancel="handleCancel" @fullscreen="handleFullScreen" />
      </template>
      <div class="jnpf-common-search-box jnpf-common-search-box-modal">
        <a-form :colon="false" label-align="right" :model="listQuery" ref="formElRef" :class="getFormClass">
          <a-row :gutter="10">
            <a-col :span="8">
              <a-form-item :label="$t('common.keyword')" name="keyword">
                <a-input v-model:value="listQuery.keyword" :placeholder="$t('common.enterKeyword')" allow-clear @press-enter="handleSearch" />
              </a-form-item>
            </a-col>
            <a-col :span="8">
              <a-form-item label=" ">
                <a-button type="primary" class="mr-2" @click="handleSearch">{{ $t('common.queryText') }}</a-button>
                <a-button @click="handleReset">{{ $t('common.resetText') }}</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
        <div class="jnpf-common-search-box-right">
          <a-tooltip placement="top">
            <template #title>
              <span>{{ $t('common.redo') }}</span>
            </template>
            <RedoOutlined class="jnpf-common-search-box-right-icon" @click="initData" />
          </a-tooltip>
        </div>
      </div>
      <a-table :data-source="list" v-bind="getTableBindValues" @change="handleTableChange" ref="tableElRef">
        <template #bodyCell="{ column, record }">
          <template v-if="column.dataIndex !== 'index'">{{ record[column.dataIndex] }}</template>
        </template>
      </a-table>
    </AModal>
  </div>
</template>
<style lang="scss" scoped>
.jnpf-basic-table {
  :deep(.ant-table-pagination) {
    &.ant-pagination {
      margin: 10px 8px;
    }
  }
}
</style>