测试博客提交修正

This commit is contained in:
Guarp 2025-03-08 16:55:35 +08:00
parent 04d4d37bba
commit 9cea0c0461

View File

@ -141,26 +141,6 @@ async function titleInputWindow() {
console.error('输入弹窗出错:', error)
}
}
async function inputDirectSubmitURL() {
const result = await Swal.fire({
title: '测试: 上传接口',
input: 'text',
inputLabel: '输入上传博客调用的POST接口url',
inputPlaceholder: '如"http://localhost:1234/blogs"',
showCancelButton: true,
cancelButtonText: '使用cyberURL',
confirmButtonText: '确定',
inputValidator: (value) => {
if (!value) {
return '输一下'
}
}
})
if (!result.isConfirmed) {
return 'https://mva-cyber.club:5001/blogs';
}
return result.value;
}
// 🚀
const submitBlog = async () => {
@ -173,7 +153,6 @@ const submitBlog = async () => {
const response = await swal.window('info', '允许评论吗?', '其他用户可以在你的博客下留言', '允许', '不允许');
let allowComments = response.isConfirmed;
const submitURL = await inputDirectSubmitURL();
let content = editorRef.value.getHtml(); // HTML
const images = [...imagesCache.value]; //
@ -253,37 +232,19 @@ const submitBlog = async () => {
console.log(Object.fromEntries(formData.entries()));
// 3
const tempURL = api.defaults.baseURL;
api.defaults.baseURL = submitURL;
api.post('', formData, {
api.post('/blogs', formData, {
headers: {
"Content-Type": "multipart/form-data",
},
}).then(response => {
if (response.code === 0) {
swal.window('success', '提交成功',`博客id: ${response.blogId || '未找到blogId字段'}`,'ok','好的');
return;
}
swal.window('error', '错误', `code${ ('为' + response.code) || '未返回'}\n返回信息: ${response.message}`, 'ok','好的');
}).catch((e) => {
swal.tip('error', `${e.message}\n${e.code}`);
});
api.defaults.baseURL = tempURL;
// api.post('/blogs', formData).then(response => {
// if (response.status !== 200) {
// swal.tip('error', `404'}`);
// return;
// }
// if (response.code === 0) {
// swal.window('success', `, id${response.blogId || 'blogId'}`);
// return;
// }
// swal.tip('error', ', code0')
// }).catch((e) => {
// swal.tip('error', `${e.message}`)
// });
if (response.code === 0) {
swal.window('success', `提交成功, 博客id${response.blogId || '未找到blogId字段'}`);
return;
}
swal.tip('error', '提交失败, code字段不为0')
}).catch((e) => {
swal.tip('error', `错误${e.message}`)
});
};