Files
certd/packages/ui/certd-client/src/components/plugins/common/api-test.vue

68 lines
1.4 KiB
Vue
Raw Normal View History

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-10-25 18:32:47 +08:00
defineOptions({
name: "ApiTest"
});
2024-11-25 11:35:16 +08:00
const getScope: any = inject("get:scope");
const getPluginType: any = inject("get:plugin:type");
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 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;
2024-11-25 11:35:16 +08:00
debugger;
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,
2024-11-25 11:35:16 +08:00
input: form
2024-10-25 18:32:47 +08:00
},
{
onError(err: any) {
hasError.value = true;
message.value = `错误:${err.message}`;
},
showErrorNotify: false
}
);
2024-11-25 11:35:16 +08:00
message.value = "测试请求成功";
2024-10-25 18:32:47 +08:00
} finally {
loading.value = false;
}
};
</script>
<style lang="less"></style>