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
<script lang="ts" setup>
import { nextTick, reactive, toRefs } from 'vue';
 
import { useGlobSetting } from '@jnpf/hooks';
import { BasicPopup, usePopupInner } from '@jnpf/ui/popup';
 
import { Button } from 'ant-design-vue';
 
import { getDataInterfaceParam, getDataInterfaceRes } from '#/api/systemData/dataInterface';
 
interface State {
  id: string;
  title: string;
  url: string;
  tenantId: string;
  responseData: string;
  testLoading: boolean;
  paramList: any[];
}
 
const state = reactive<State>({
  id: '',
  title: '',
  url: '',
  tenantId: '',
  responseData: '',
  testLoading: false,
  paramList: [],
});
const { title, url, responseData, paramList, testLoading } = toRefs(state);
const globSetting = useGlobSetting();
const [registerPopup, { changeLoading }] = usePopupInner(init);
 
function init(data) {
  changeLoading(true);
  state.id = data.id || '';
  state.tenantId = data.tenantId || '';
  state.title = `接口预览 - ${data.fullName || ''}`;
  state.paramList = [];
  state.responseData = '';
  nextTick(() => {
    const prefix = globSetting.apiURL === '/dev' ? window.location.origin : '';
    state.url = `${prefix}${globSetting.apiURL}/api/system/DataInterface/${state.id}/Actions/Preview${state.tenantId ? `?tenantId=${state.tenantId}` : ''}`;
    getDataInterfaceParam(state.id)
      .then((res) => {
        state.paramList = res.data;
        changeLoading(false);
      })
      .catch(() => {
        changeLoading(false);
      });
  });
}
function test() {
  state.testLoading = true;
  const query = {
    paramList: state.paramList,
    tenantId: state.tenantId,
    origin: 'preview',
  };
  getDataInterfaceRes(state.id, query)
    .then((res) => {
      state.testLoading = false;
      state.responseData = JSON.stringify(res, null, 4);
    })
    .catch(() => {
      state.testLoading = false;
    });
}
</script>
<template>
  <BasicPopup v-bind="$attrs" @register="registerPopup" :title="title">
    <a-form :colon="false" layout="vertical" class="!mx-[10px]">
      <a-form-item label="Request URL">
        <a-input-search v-model:value="url" addon-before="POST" @search="test">
          <template #enterButton>
            <Button :loading="testLoading">测试接口</Button>
          </template>
        </a-input-search>
      </a-form-item>
      <a-form-item label="Request Param" v-if="paramList.length">
        <a-form-item-rest>
          <a-row v-for="item in paramList" :key="item.field" class="mt-[10px]" :gutter="20">
            <a-col :span="6">
              <a-input v-model:value="item.field" placeholder="key" allow-clear readonly />
            </a-col>
            <a-col :span="18">
              <a-input v-model:value="item.defaultValue" placeholder="value" allow-clear />
            </a-col>
          </a-row>
        </a-form-item-rest>
      </a-form-item>
      <a-form-item label="Response Body" class="value-item">
        <a-textarea :value="responseData" :auto-size="{ minRows: 20 }" />
      </a-form-item>
    </a-form>
  </BasicPopup>
</template>