"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
require("../../../../node_modules/element-plus/es/index.js");
;/* empty css                                                          */
;/* empty css                                                             */
;/* empty css                                                                  */
require("../../../../node_modules/element-plus/theme-chalk/el-tab-pane.css.js");
;/* empty css                                                            */
;/* empty css                                                               */
;/* empty css                                                             */
;/* empty css                                                              */
;/* empty css                                                                    */
;/* empty css                                                              */
;/* empty css                                                                  */
;/* empty css                                                               */
;/* empty css                                                               */
;/* empty css                                                                     */
;/* empty css                                                               */
const Vue = require("vue");
const index$7 = require("../../../../node_modules/@element-plus/icons-vue/dist/index.js");
const ParamsConfig = require("../../components/ParamsConfig.vue2.js");
require("../../store/index.js");
const vue3JsonViewer = require("../../../../node_modules/vue3-json-viewer/dist/vue3-json-viewer.js");
;/* empty css                                                                   */
const env = require("../../utils/env.js");
;/* empty css                                                              */
;/* empty css                                                                */
;/* empty css                 */
const _pluginVue_exportHelper = require("../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../node_modules/element-plus/es/components/tabs/index.js");
const index$1 = require("../../../../node_modules/element-plus/es/components/scrollbar/index.js");
const index$2 = require("../../../../node_modules/element-plus/es/components/form/index.js");
const index$3 = require("../../../../node_modules/element-plus/es/components/select/index.js");
const index$4 = require("../../../../node_modules/element-plus/es/components/input/index.js");
const index$5 = require("../../../../node_modules/element-plus/es/components/radio/index.js");
const index$6 = require("../../../../node_modules/element-plus/es/components/icon/index.js");
const index$8 = require("../../../../node_modules/element-plus/es/components/button/index.js");
const index$9 = require("../../../../node_modules/element-plus/es/components/tag/index.js");
const index$a = require("../../../../node_modules/element-plus/es/components/message/index.js");
const _hoisted_1 = { class: "data-source" };
const _hoisted_2 = { class: "config-section" };
const _hoisted_3 = { class: "desc-content" };
const _hoisted_4 = {
  key: 0,
  class: "condition-desc"
};
const _hoisted_5 = { class: "test-section" };
const _hoisted_6 = { class: "section-header" };
const _hoisted_7 = { class: "section-title" };
const _hoisted_8 = {
  key: 0,
  class: "response-area"
};
const _hoisted_9 = { class: "response-title" };
const _hoisted_10 = { class: "response-actions" };
const _hoisted_11 = { class: "response-status" };
const _hoisted_12 = { class: "response-time" };
const _hoisted_13 = {
  key: 1,
  class: "empty-response"
};
const _sfc_main = {
  __name: "dataSource",
  props: {
    requestConfigData: Object
  },
  setup(__props) {
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const props = __props;
    const activeName = Vue.ref("requestConfig");
    const loading = Vue.ref(false);
    const responseData = Vue.ref("");
    const requestTime = Vue.ref(0);
    const serversOptions = Vue.ref([]);
    for (const key in env.default.servers) {
      serversOptions.value.push({
        label: key,
        value: env.default.servers[key]
      });
    }
    Vue.watch(
      () => props.requestConfigData,
      () => {
        responseData.value = "";
        requestTime.value = 0;
      },
      { deep: true }
    );
    async function sendRequest() {
      var _a, _b;
      const requestConfig = props.requestConfigData;
      if (!requestConfig.serverName) {
        index$a.ElMessage.warning("请选择服务");
        return;
      }
      if (!requestConfig.url) {
        index$a.ElMessage.warning("请输入请求URL");
        return;
      }
      loading.value = true;
      responseData.value = "";
      const startTime = Date.now();
      try {
        const params = {};
        (props.requestConfigData.params || []).forEach((param) => {
          if (param.key) {
            params[param.key] = param.value;
          }
        });
        const baseUrl = requestConfig.serverName ? `/${requestConfig.serverName}` : "";
        const fullUrl = `${baseUrl}${requestConfig.url}`;
        let res;
        if (requestConfig.method === "get") {
          const queryString = new URLSearchParams(params).toString();
          const url = queryString ? `${fullUrl}?${queryString}` : fullUrl;
          res = await ctx.$http.get(url, loading.value);
        } else {
          if (requestConfig.contentType === "json") {
            res = await ctx.$http.post(fullUrl, params, loading.value);
          } else {
            res = await ctx.$http.postForm(fullUrl, params, loading.value);
          }
        }
        responseData.value = {
          status: 200,
          statusText: "OK",
          data: res.data || res
        };
      } catch (error) {
        responseData.value = {
          success: false,
          error: error.message || "未知错误",
          status: ((_a = error.response) == null ? void 0 : _a.status) || 0,
          statusText: ((_b = error.response) == null ? void 0 : _b.statusText) || "网络错误"
        };
      } finally {
        requestTime.value = Date.now() - startTime;
        loading.value = false;
      }
    }
    function copyResponse() {
      var _a;
      const dataToCopy = ((_a = responseData.value) == null ? void 0 : _a.data) || responseData.value;
      navigator.clipboard.writeText(JSON.stringify(dataToCopy, null, 2)).then(() => {
        index$a.ElMessage.success("复制成功");
      }).catch(() => {
        index$a.ElMessage.error("复制失败");
      });
    }
    return (_ctx, _cache) => {
      const _component_el_option = index$3.ElOption;
      const _component_el_select = index$3.ElSelect;
      const _component_el_form_item = index$2.ElFormItem;
      const _component_el_input = index$4.ElInput;
      const _component_el_radio = index$5.ElRadio;
      const _component_el_radio_group = index$5.ElRadioGroup;
      const _component_el_form = index$2.ElForm;
      const _component_el_icon = index$6.ElIcon;
      const _component_el_button = index$8.ElButton;
      const _component_el_tag = index$9.ElTag;
      const _component_el_tab_pane = index.ElTabPane;
      const _component_el_scrollbar = index$1.ElScrollbar;
      const _component_el_tabs = index.ElTabs;
      return Vue.openBlock(), Vue.createElementBlock("div", _hoisted_1, [
        Vue.createVNode(_component_el_tabs, {
          modelValue: Vue.unref(activeName),
          "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => Vue.isRef(activeName) ? activeName.value = $event : null),
          class: "data-source-tab"
        }, {
          default: Vue.withCtx(() => [
            Vue.createVNode(_component_el_scrollbar, { height: "540px" }, {
              default: Vue.withCtx(() => [
                Vue.createVNode(_component_el_tab_pane, {
                  label: "请求配置",
                  name: "requestConfig"
                }, {
                  default: Vue.withCtx(() => [
                    Vue.createElementVNode("div", _hoisted_2, [
                      Vue.createVNode(_component_el_form, {
                        "label-width": "auto",
                        model: __props.requestConfigData,
                        size: "small"
                      }, {
                        default: Vue.withCtx(() => [
                          Vue.createVNode(_component_el_form_item, { label: "服务名称" }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(_component_el_select, {
                                modelValue: __props.requestConfigData.serverName,
                                "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => __props.requestConfigData.serverName = $event),
                                placeholder: "请选择服务"
                              }, {
                                default: Vue.withCtx(() => [
                                  (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(serversOptions), (item) => {
                                    return Vue.openBlock(), Vue.createBlock(_component_el_option, {
                                      key: item.value,
                                      label: item.label,
                                      value: item.value
                                    }, null, 8, ["label", "value"]);
                                  }), 128))
                                ]),
                                _: 1
                              }, 8, ["modelValue"])
                            ]),
                            _: 1
                          }),
                          Vue.createVNode(_component_el_form_item, { label: "请求URL" }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(_component_el_input, {
                                modelValue: __props.requestConfigData.url,
                                "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => __props.requestConfigData.url = $event),
                                placeholder: "请输入请求URL"
                              }, null, 8, ["modelValue"])
                            ]),
                            _: 1
                          }),
                          Vue.createVNode(_component_el_form_item, { label: "请求方式" }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(_component_el_radio_group, {
                                modelValue: __props.requestConfigData.method,
                                "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => __props.requestConfigData.method = $event)
                              }, {
                                default: Vue.withCtx(() => [
                                  Vue.createVNode(_component_el_radio, { value: "get" }, {
                                    default: Vue.withCtx(() => _cache[6] || (_cache[6] = [
                                      Vue.createTextVNode("GET")
                                    ])),
                                    _: 1
                                  }),
                                  Vue.createVNode(_component_el_radio, { value: "post" }, {
                                    default: Vue.withCtx(() => _cache[7] || (_cache[7] = [
                                      Vue.createTextVNode("POST")
                                    ])),
                                    _: 1
                                  })
                                ]),
                                _: 1
                              }, 8, ["modelValue"])
                            ]),
                            _: 1
                          }),
                          Vue.createVNode(_component_el_form_item, { label: "内容类型" }, {
                            default: Vue.withCtx(() => [
                              Vue.createElementVNode("div", _hoisted_3, [
                                Vue.createVNode(_component_el_radio_group, {
                                  modelValue: __props.requestConfigData.contentType,
                                  "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => __props.requestConfigData.contentType = $event)
                                }, {
                                  default: Vue.withCtx(() => [
                                    Vue.createVNode(_component_el_radio, { value: "json" }, {
                                      default: Vue.withCtx(() => _cache[8] || (_cache[8] = [
                                        Vue.createTextVNode("JSON(RequestBody)")
                                      ])),
                                      _: 1
                                    }),
                                    Vue.createVNode(_component_el_radio, { value: "formData" }, {
                                      default: Vue.withCtx(() => _cache[9] || (_cache[9] = [
                                        Vue.createTextVNode("FormData(RequestParam)")
                                      ])),
                                      _: 1
                                    }),
                                    Vue.createVNode(_component_el_radio, { value: "download" }, {
                                      default: Vue.withCtx(() => _cache[10] || (_cache[10] = [
                                        Vue.createTextVNode("Download(RequestBody)")
                                      ])),
                                      _: 1
                                    }),
                                    Vue.createVNode(_component_el_radio, { value: "upload" }, {
                                      default: Vue.withCtx(() => _cache[11] || (_cache[11] = [
                                        Vue.createTextVNode("Upload(RequestParam)")
                                      ])),
                                      _: 1
                                    })
                                  ]),
                                  _: 1
                                }, 8, ["modelValue"]),
                                __props.requestConfigData.contentType == "upload" ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_4, " 单文件上传键名: file, 多文件上传键名: files。 ")) : Vue.createCommentVNode("", true)
                              ])
                            ]),
                            _: 1
                          }),
                          Vue.createVNode(_component_el_form_item, { label: "请求参数" }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(ParamsConfig.default, {
                                modelValue: __props.requestConfigData.params,
                                "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => __props.requestConfigData.params = $event)
                              }, null, 8, ["modelValue"])
                            ]),
                            _: 1
                          })
                        ]),
                        _: 1
                      }, 8, ["model"])
                    ]),
                    Vue.createElementVNode("div", _hoisted_5, [
                      Vue.createElementVNode("div", _hoisted_6, [
                        Vue.createElementVNode("span", _hoisted_7, [
                          Vue.createVNode(_component_el_icon, { class: "section-icon" }, {
                            default: Vue.withCtx(() => [
                              Vue.createVNode(Vue.unref(index$7.VideoPlay))
                            ]),
                            _: 1
                          }),
                          _cache[12] || (_cache[12] = Vue.createTextVNode(" 请求测试 "))
                        ]),
                        Vue.createVNode(_component_el_button, {
                          size: "small",
                          type: "primary",
                          icon: Vue.unref(index$7.VideoPlay),
                          loading: Vue.unref(loading),
                          onClick: sendRequest
                        }, {
                          default: Vue.withCtx(() => [
                            Vue.createTextVNode(Vue.toDisplayString(Vue.unref(loading) ? "请求中..." : "测试请求"), 1)
                          ]),
                          _: 1
                        }, 8, ["icon", "loading"])
                      ]),
                      Vue.unref(responseData) ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_8, [
                        Vue.createElementVNode("div", _hoisted_9, [
                          _cache[14] || (_cache[14] = Vue.createElementVNode("span", null, "响应结果", -1)),
                          Vue.createElementVNode("div", _hoisted_10, [
                            Vue.createVNode(_component_el_button, {
                              size: "small",
                              text: "",
                              icon: Vue.unref(index$7.CopyDocument),
                              onClick: copyResponse
                            }, {
                              default: Vue.withCtx(() => _cache[13] || (_cache[13] = [
                                Vue.createTextVNode(" 复制 ")
                              ])),
                              _: 1
                            }, 8, ["icon"])
                          ])
                        ]),
                        Vue.createElementVNode("div", _hoisted_11, [
                          Vue.createVNode(_component_el_tag, {
                            type: Vue.unref(responseData).status >= 200 && Vue.unref(responseData).status < 300 ? "success" : "danger",
                            size: "small"
                          }, {
                            default: Vue.withCtx(() => [
                              Vue.createTextVNode(Vue.toDisplayString(Vue.unref(responseData).status) + " " + Vue.toDisplayString(Vue.unref(responseData).statusText || ""), 1)
                            ]),
                            _: 1
                          }, 8, ["type"]),
                          Vue.createElementVNode("span", _hoisted_12, "耗时: " + Vue.toDisplayString(Vue.unref(requestTime)) + "ms", 1)
                        ]),
                        Vue.createVNode(Vue.unref(vue3JsonViewer.JsonViewer), {
                          value: Vue.unref(responseData).data,
                          "expand-depth": 1,
                          boxed: "",
                          "show-array-index": false
                        }, null, 8, ["value"])
                      ])) : (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_13, [
                        Vue.createVNode(_component_el_icon, { class: "empty-icon" }, {
                          default: Vue.withCtx(() => [
                            Vue.createVNode(Vue.unref(index$7.Document))
                          ]),
                          _: 1
                        }),
                        _cache[15] || (_cache[15] = Vue.createElementVNode("span", null, "暂无响应数据，点击发送请求进行测试", -1))
                      ]))
                    ])
                  ]),
                  _: 1
                }),
                Vue.createVNode(_component_el_tab_pane, {
                  label: "数据处理",
                  name: "dataHandler"
                }, {
                  default: Vue.withCtx(() => _cache[16] || (_cache[16] = [
                    Vue.createTextVNode("Config")
                  ])),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        }, 8, ["modelValue"])
      ]);
    };
  }
};
const DataSource = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-5c11127e"]]);
exports.default = DataSource;
