2024-10-25 18:32:47 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="api-test">
|
|
|
|
|
<div>
|
|
|
|
|
<fs-button :loading="loading" type="primary" text="测试" icon="ion:refresh-outline" @click="doTest"></fs-button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="helper" :class="{ error: hasError }">
|
|
|
|
|
{{ message }}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ComponentPropsType, doRequest } from "/@/components/plugins/lib";
|
2024-11-25 11:35:16 +08:00
|
|
|
import { ref, inject } from "vue";
|
2024-11-25 23:48:04 +08:00
|
|
|
import { Form } from "ant-design-vue";
|
2026-02-15 12:59:08 +08:00
|
|
|
import { getInputFromForm } from "./utils";
|
2024-10-25 18:32:47 +08:00
|
|
|
|
|
|
|
|
defineOptions({
|
2025-04-28 21:55:23 +08:00
|
|
|
name: "ApiTest",
|
2024-10-25 18:32:47 +08:00
|
|
|
});
|
|
|
|
|
|
2024-11-25 11:35:16 +08:00
|
|
|
const getScope: any = inject("get:scope");
|
2025-06-26 18:43:16 +08:00
|
|
|
const getPluginType: any = inject("get:plugin:type", () => {
|
|
|
|
|
return "access";
|
|
|
|
|
});
|
2024-11-25 23:48:04 +08:00
|
|
|
const formItemContext = Form.useInjectFormItemContext();
|
2024-10-25 18:32:47 +08:00
|
|
|
const props = defineProps<{} & ComponentPropsType>();
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
"update:value": any;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const message = ref("");
|
|
|
|
|
const hasError = ref(false);
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
const doTest = async () => {
|
|
|
|
|
if (loading.value) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 23:48:04 +08:00
|
|
|
formItemContext.onFieldChange();
|
|
|
|
|
|
2024-11-25 11:35:16 +08:00
|
|
|
const { form } = getScope();
|
|
|
|
|
const pluginType = getPluginType();
|
|
|
|
|
|
2024-10-25 18:32:47 +08:00
|
|
|
message.value = "";
|
|
|
|
|
hasError.value = false;
|
|
|
|
|
loading.value = true;
|
2026-02-15 12:59:08 +08:00
|
|
|
const { input, record } = getInputFromForm(form, pluginType);
|
2024-10-25 18:32:47 +08:00
|
|
|
try {
|
|
|
|
|
const res = await doRequest(
|
|
|
|
|
{
|
2024-11-25 11:35:16 +08:00
|
|
|
type: pluginType,
|
|
|
|
|
typeName: form.type,
|
2024-10-25 18:32:47 +08:00
|
|
|
action: props.action,
|
2026-02-15 12:59:08 +08:00
|
|
|
input,
|
|
|
|
|
record,
|
2024-10-25 18:32:47 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
onError(err: any) {
|
|
|
|
|
hasError.value = true;
|
|
|
|
|
message.value = `错误:${err.message}`;
|
|
|
|
|
},
|
2025-04-28 21:55:23 +08:00
|
|
|
showErrorNotify: false,
|
2024-10-25 18:32:47 +08:00
|
|
|
}
|
|
|
|
|
);
|
2024-11-25 11:35:16 +08:00
|
|
|
message.value = "测试请求成功";
|
2025-03-14 13:16:48 +08:00
|
|
|
if (res) {
|
|
|
|
|
message.value += `,返回:${JSON.stringify(res)}`;
|
|
|
|
|
}
|
2024-10-25 18:32:47 +08:00
|
|
|
} finally {
|
|
|
|
|
loading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less"></style>
|