diff --git a/generated/core/OpenAPI.ts b/generated/core/OpenAPI.ts index bb0dc7f..8a670f9 100644 --- a/generated/core/OpenAPI.ts +++ b/generated/core/OpenAPI.ts @@ -20,7 +20,7 @@ export type OpenAPIConfig = { }; export const OpenAPI: OpenAPIConfig = { - BASE: 'http://oj.shuguangwl.com:8101', + BASE: 'http://localhost:8101', VERSION: '1.0', WITH_CREDENTIALS: true, CREDENTIALS: 'include', diff --git a/src/components/GlobalHeader.vue b/src/components/GlobalHeader.vue index 2092a0a..e15ee9c 100644 --- a/src/components/GlobalHeader.vue +++ b/src/components/GlobalHeader.vue @@ -1,5 +1,5 @@ diff --git a/src/components/User/UserInfo.vue b/src/components/User/UserInfo.vue index ffe64b6..80e7921 100644 --- a/src/components/User/UserInfo.vue +++ b/src/components/User/UserInfo.vue @@ -1,47 +1,43 @@ + \ No newline at end of file + +// 获取文件 +const getfile = async (event) => { + const files = event.target.files; + selectedFile.value = files[0]; // 选择第一个文件 + if (files.length > 0) { + console.log('选择的文件:', selectedFile.value); + await uploadFile(); // 上传文件 + } else { + console.log('没有选择文件'); + } +}; + +// 上传图片 +const uploadFile = async () => { + if (!selectedFile.value) { + alert('请先选择一个文件'); + return false; // 上传未成功 + } + + const formData = new FormData(); + formData.append('image', selectedFile.value); // 将文件添加到 FormData + formData.append('token', 123); // 将 token 添加到 FormData(可以替换为实际的 token) + + try { + const response = await axios.post('http://222.186.56.232:40061/api/index.php', formData, { + headers: { + 'Content-Type': 'multipart/form-data', // 设置内容类型 + }, + }); + form.value.userAvatar = response.data.url; // 更新头像 URL + console.log('文件上传成功:', response.data.url); + return true; // 上传成功 + } catch (error) { + console.error('文件上传失败:', error.response ? error.response.data : error.message); + return false; // 上传未成功 + } +}; + + + diff --git a/src/reuqest/axios.ts b/src/reuqest/axios.ts deleted file mode 100644 index b214efa..0000000 --- a/src/reuqest/axios.ts +++ /dev/null @@ -1,34 +0,0 @@ -// // src/axios.js -// import axios from 'axios'; -// import { inject } from 'vue'; - -// const loading = inject('loading'); - -// const instance = axios.create({ -// baseURL: 'http://127.0.0.1:8101', -// timeout: 10000, -// }); - -// instance.interceptors.request.use( -// (config) => { -// loading.value = true; -// return config; -// }, -// (error) => { -// loading.value = false; -// return Promise.reject(error); -// } -// ); - -// instance.interceptors.response.use( -// (response) => { -// loading.value = false; -// return response; -// }, -// (error) => { -// loading.value = false; -// return Promise.reject(error); -// } -// ); - -// export default instance; diff --git a/src/views/forum/ForumPublish.vue b/src/views/forum/ForumPublish.vue index 5833229..89a1edf 100644 --- a/src/views/forum/ForumPublish.vue +++ b/src/views/forum/ForumPublish.vue @@ -1,7 +1,7 @@