excuteTest.vue 2.22 KB
<template>
  <div class="mt-8">
    <div>
      <Button disabled @click="handleExcute" type="primary"> 执行测试请求 </Button>
    </div>
    <!-- <div class="mt-8">
      <a-row type="flex" justify="center">
        <a-col :span="3"> 测试结果 </a-col>
        <a-col :span="21">
          <a-textarea
            allow-clear
            show-count
            v-model:value="testResult"
            placeholder="测试结果为:"
            :rows="8"
          />
        </a-col>
      </a-row>
    </div> -->
  </div>
</template>
<script lang="ts" setup name="testRequest">
  import { nextTick } from 'vue';
  import { Button } from 'ant-design-vue';
  // import { otherHttp } from '/@/utils/http/axios';

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

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

  //格式化替换像"http:xxxx/api/xx/{xx}/{xx}/{xx}这种格式"
  String.prototype.restfulFormat = function (replacements) {
    var formatString = function (str, replacements) {
      replacements =
        typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 1);
      return str.replace(/\{\{|\}\}|\{(\w+)\}/g, function (m, n) {
        if (m == '{{') {
          return '{';
        }
        if (m == '}}') {
          return '}';
        }
        return replacements[n];
      });
    };
    replacements =
      typeof replacements === 'object' ? replacements : Array.prototype.slice.call(arguments, 0);
    return formatString(this, replacements);
  };

  // const testResult = ref('');

  //执行测试接口
  const handleExcute = () => {
    emits('emitExcute');
    getValue();
  };

  const getValue = async () => {
    await nextTick();
    console.log(props.data);
  };

  // //TODO: 待优化 项目自带第三方请求
  // const otherHttpRequest = async (apiType, params = {}, api, joinPrefix = false) => {
  //   switch (apiType) {
  //     case 'GET':
  //       return await otherHttp.get(
  //         { url: api, params },
  //         {
  //           apiUrl: '',
  //           joinPrefix,
  //         }
  //       );
  //   }
  // };
</script>

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