index.vue 2.32 KB
<template>
  <div>
    <div class="mt-8">
      <div>
        <Button @click="handleTest" type="primary"> 测试接口 </Button>
      </div>
      <div v-if="showTestEditCell" class="mt-8">
        <a-row type="flex" justify="center">
          <a-col :span="3"> 参数设置 </a-col>
          <a-col :span="21">
            <TestHeaderEditCellTable ref="testEditCellTableRef" />
          </a-col>
        </a-row>
      </div>
    </div>
    <div class="mt-8"> </div>
  </div>
</template>
<script lang="ts" setup name="testRequest">
  import { ref, nextTick } from 'vue';
  import { Button } from 'ant-design-vue';
  import TestHeaderEditCellTable from './testEditHeaderCellTable.vue';

  const emits = defineEmits(['testHeaderInterface']);

  const props = defineProps({
    data: {
      type: Object,
    },
  });

  const showTestEditCell = ref(false);

  const excuteData = ref({});

  const testEditCellTableRef = ref<InstanceType<typeof TestHeaderEditCellTable>>();

  const testResult = ref('');

  const handleTest = () => {
    showTestEditCell.value = true;
    emits('testHeaderInterface');
    getValue();
  };

  const getValue = async () => {
    await nextTick();
    await nextTick(() => {
      const getValue = props.data?.list;
      testEditCellTableRef.value?.setTableArray(getValue);
    });
  };

  //测试表格里的数据转化为 key value 数组对象形式
  const getTestTableKeyValue = () => {
    return testEditCellTableRef.value?.getValue();
  };

  //获取数据
  const getTestValue = () => {
    const getTable = getTestTableKeyValue();
    //源地址
    const apiGetUrl = `${props.data?.requestOriginUrl}${props.data?.requestTypeAndUrl?.requestUrl}`;
    //请求类型
    const apiType = props.data?.requestTypeAndUrl?.requestHttpType;
    //替换key value
    const params: any = {};
    getTable?.map((it: any) => (params[it.key!] = it.value!));
    excuteData.value = {
      apiGetUrl,
      apiType,
      params,
      activeKey: props.data?.activeKey,
    };
    return excuteData.value;
  };

  //设置数据
  const setValue = () => {
    showTestEditCell.value = false;
    testResult.value = '';
  };

  defineExpose({
    setValue,
    handleTest,
    getTestValue,
  });
</script>

<style scoped lang="less"></style>