Compare commits
No commits in common. "58eff630d77e989fd65ab19491a40aeedfd70013" and "04d4d37bba470391fcf27d3f3c603d2b34d0eaf4" have entirely different histories.
58eff630d7
...
04d4d37bba
@ -141,6 +141,26 @@ async function titleInputWindow() {
|
|||||||
console.error('输入弹窗出错:', error)
|
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 () => {
|
const submitBlog = async () => {
|
||||||
@ -153,6 +173,7 @@ const submitBlog = async () => {
|
|||||||
const response = await swal.window('info', '允许评论吗?', '其他用户可以在你的博客下留言', '允许', '不允许');
|
const response = await swal.window('info', '允许评论吗?', '其他用户可以在你的博客下留言', '允许', '不允许');
|
||||||
let allowComments = response.isConfirmed;
|
let allowComments = response.isConfirmed;
|
||||||
|
|
||||||
|
const submitURL = await inputDirectSubmitURL();
|
||||||
|
|
||||||
let content = editorRef.value.getHtml(); // 获取 HTML 内容
|
let content = editorRef.value.getHtml(); // 获取 HTML 内容
|
||||||
const images = [...imagesCache.value]; // 复制图片数组
|
const images = [...imagesCache.value]; // 复制图片数组
|
||||||
@ -232,19 +253,37 @@ const submitBlog = async () => {
|
|||||||
console.log(Object.fromEntries(formData.entries()));
|
console.log(Object.fromEntries(formData.entries()));
|
||||||
// 3️⃣ 发送请求
|
// 3️⃣ 发送请求
|
||||||
|
|
||||||
api.post('/blogs', formData, {
|
const tempURL = api.defaults.baseURL;
|
||||||
|
api.defaults.baseURL = submitURL;
|
||||||
|
api.post('', formData, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "multipart/form-data",
|
"Content-Type": "multipart/form-data",
|
||||||
},
|
},
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.code === 0) {
|
if (response.code === 0) {
|
||||||
swal.window('success', `提交成功, 博客id${response.blogId || '未找到blogId字段'}`);
|
swal.window('success', '提交成功',`博客id: ${response.blogId || '未找到blogId字段'}`,'ok','好的');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
swal.window('error', '提交失败', `code字段为${response.code}; 错误信息: ${response.message}`, 'ok', '好的');
|
swal.window('error', '错误', `code${ ('为' + response.code) || '未返回'}\n返回信息: ${response.message}`, 'ok','好的');
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
swal.tip('error', `错误${e.message}`)
|
|
||||||
|
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', '提交失败, code字段不为0')
|
||||||
|
// }).catch((e) => {
|
||||||
|
// swal.tip('error', `错误${e.message}`)
|
||||||
|
// });
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user