From 1b0fa9bb30bfdd2181787e544f4edeacb0538c46 Mon Sep 17 00:00:00 2001 From: Lan Date: Mon, 7 Oct 2024 00:04:59 +0800 Subject: [PATCH] d --- .env.development | 2 +- .env.production | 2 +- package.json | 2 + pnpm-lock.yaml | 12 + src/router/index.ts | 1 - src/stores/fileData.ts | 39 +++ src/utils/api.ts | 19 +- src/views/RetrievewFileView.vue | 430 ++++++++++++++++++++++++-------- src/views/SendFileView.vue | 168 ++++++++----- 9 files changed, 499 insertions(+), 176 deletions(-) create mode 100644 src/stores/fileData.ts diff --git a/.env.development b/.env.development index 4e8eab4..64513e2 100644 --- a/.env.development +++ b/.env.development @@ -1 +1 @@ -VITE_API_BASE_URL_DEV=http://localhost:12345/ \ No newline at end of file +VITE_API_BASE_URL_DEV=http://localhost:12345 \ No newline at end of file diff --git a/.env.production b/.env.production index 53ff7e0..9b1c4f6 100644 --- a/.env.production +++ b/.env.production @@ -1 +1 @@ -VITE_API_BASE_URL_PROD=https://api.yourdomain.com \ No newline at end of file +VITE_API_BASE_URL_PROD=https://share.lanol.cn \ No newline at end of file diff --git a/package.json b/package.json index 3c380e4..6376793 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "lucide-vue-next": "^0.445.0", "pinia": "^2.2.2", "qrcode.vue": "^3.4.1", + "spark-md5": "^3.0.2", "vue": "^3.5.8", "vue-router": "^4.4.5" }, @@ -27,6 +28,7 @@ "@rushstack/eslint-patch": "^1.10.4", "@tsconfig/node20": "^20.1.4", "@types/node": "^20.16.7", + "@types/spark-md5": "^3.0.4", "@vitejs/plugin-vue": "^5.1.4", "@vitejs/plugin-vue-jsx": "^4.0.1", "@vue/eslint-config-prettier": "^9.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1c9524e..3c579fb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,6 +6,7 @@ specifiers: '@rushstack/eslint-patch': ^1.10.4 '@tsconfig/node20': ^20.1.4 '@types/node': ^20.16.7 + '@types/spark-md5': ^3.0.4 '@vitejs/plugin-vue': ^5.1.4 '@vitejs/plugin-vue-jsx': ^4.0.1 '@vue/eslint-config-prettier': ^9.0.0 @@ -24,6 +25,7 @@ specifiers: prettier: ^3.3.3 qrcode.vue: ^3.4.1 rimraf: ^6.0.1 + spark-md5: ^3.0.2 tailwindcss: ^3.4.13 typescript: ~5.4.5 vite: ^5.4.7 @@ -38,6 +40,7 @@ dependencies: lucide-vue-next: 0.445.0_vue@3.5.8 pinia: 2.2.2_typescript@5.4.5+vue@3.5.8 qrcode.vue: 3.4.1_vue@3.5.8 + spark-md5: 3.0.2 vue: 3.5.8_typescript@5.4.5 vue-router: 4.4.5_vue@3.5.8 @@ -47,6 +50,7 @@ devDependencies: '@rushstack/eslint-patch': 1.10.4 '@tsconfig/node20': 20.1.4 '@types/node': 20.16.7 + '@types/spark-md5': 3.0.4 '@vitejs/plugin-vue': 5.1.4_vite@5.4.7+vue@3.5.8 '@vitejs/plugin-vue-jsx': 4.0.1_vite@5.4.7+vue@3.5.8 '@vue/eslint-config-prettier': 9.0.0_edq2hqhb5ywdex3d2mazvmybbq @@ -930,6 +934,10 @@ packages: undici-types: 6.19.8 dev: true + /@types/spark-md5/3.0.4: + resolution: {integrity: sha512-qtOaDz+IXiNndPgYb6t1YoutnGvFRtWSNzpVjkAPCfB2UzTyybuD4Tjgs7VgRawum3JnJNRwNQd4N//SvrHg1Q==} + dev: true + /@typescript-eslint/eslint-plugin/7.18.0_rwblscj2v5mttegw6cqzsnmxke: resolution: {integrity: sha512-94EQTWZ40mzBc42ATNIBimBEDltSJ9RQHCC8vc/PDbxi4k8dVwUAv4o98dk50M1zB+JGFxp43FP7f8+FP8R6Sw==} engines: {node: ^18.18.0 || >=20.0.0} @@ -2959,6 +2967,10 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} + /spark-md5/3.0.2: + resolution: {integrity: sha512-wcFzz9cDfbuqe0FZzfi2or1sgyIrsDwmPwfZC4hiNidPdPINjeUwNfv5kldczoEAcjl9Y1L3SM7Uz2PUEQzxQw==} + dev: false + /speakingurl/14.0.1: resolution: {integrity: sha512-1POYv7uv2gXoyGFpBCmpDVSNV74IfsWlDW216UPjbWufNf+bSU6GdbDsxdcxtfwb4xlI3yxzOTKClUosxARYrQ==} engines: {node: '>=0.10.0'} diff --git a/src/router/index.ts b/src/router/index.ts index 5cc99f5..bf58e7f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -11,7 +11,6 @@ const router = createRouter({ { path: '/send', name: 'Send', - // 直接使用动态导入,不再包裹在 defineAsyncComponent 中 component: () => import('@/views/SendFileView.vue') } ] diff --git a/src/stores/fileData.ts b/src/stores/fileData.ts new file mode 100644 index 0000000..dbeaa9f --- /dev/null +++ b/src/stores/fileData.ts @@ -0,0 +1,39 @@ +import { defineStore } from 'pinia' +import { reactive } from 'vue' + +export const useFileDataStore = defineStore('fileData', () => { + const receiveData = reactive(JSON.parse(localStorage.getItem('receiveData') || '[]') || []) // 接收的数据 + const shareData = reactive(JSON.parse(localStorage.getItem('shareData') || '[]') || []) // 接收的数据 + function save() { + localStorage.setItem('receiveData', JSON.stringify(receiveData)) + localStorage.setItem('shareData', JSON.stringify(shareData)) + } + function addReceiveData(data: any) { + receiveData.unshift(data) + save() + } + + function addShareData(data: any) { + shareData.unshift(data) + save() + } + + function deleteReceiveData(index: number) { + receiveData.splice(index, 1) + save() + } + + function deleteShareData(index: number) { + shareData.splice(index, 1) + save() + } + return { + receiveData, + shareData, + save, + addShareData, + addReceiveData, + deleteReceiveData, + deleteShareData + } +}) diff --git a/src/utils/api.ts b/src/utils/api.ts index d090a29..bbad035 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -5,12 +5,13 @@ const baseURL = import.meta.env.MODE === 'production' ? import.meta.env.VITE_API_BASE_URL_PROD : import.meta.env.VITE_API_BASE_URL_DEV -console.log(baseURL) -console.log(import.meta.env.MODE) + +// 确保 baseURL 是一个有效的字符串 +const sanitizedBaseURL = typeof baseURL === 'string' ? baseURL : '' // 创建 axios 实例 const api = axios.create({ - baseURL, + baseURL: sanitizedBaseURL, timeout: 10000, // 请求超时时间 headers: { 'Content-Type': 'application/json' @@ -25,6 +26,12 @@ api.interceptors.request.use( if (token) { config.headers['Authorization'] = `Bearer ${token}` } + + // 确保 URL 是有效的 + if (config.url && !config.url.startsWith('http')) { + config.url = `${sanitizedBaseURL}/${config.url.replace(/^\//, '')}` + } + return config }, (error) => { @@ -43,7 +50,7 @@ api.interceptors.response.use( switch (error.response.status) { case 401: // 未授权,可能需要重新登录 - console.error('未授权,请重新登录') + console.error('未授权,请重新登录') break case 403: // 禁止访问 @@ -56,8 +63,10 @@ api.interceptors.response.use( default: console.error('发生错误:', error.response.data) } + } else if (error.request) { + console.error('未收到响应:', error.request) } else { - console.error('发生错误:', error.message) + console.error('请求配置错误:', error.message) } return Promise.reject(error) } diff --git a/src/views/RetrievewFileView.vue b/src/views/RetrievewFileView.vue index b261eca..21d9f62 100644 --- a/src/views/RetrievewFileView.vue +++ b/src/views/RetrievewFileView.vue @@ -1,75 +1,120 @@ \ No newline at end of file + diff --git a/src/views/SendFileView.vue b/src/views/SendFileView.vue index 8dfb8f5..1c7f54a 100644 --- a/src/views/SendFileView.vue +++ b/src/views/SendFileView.vue @@ -378,7 +378,7 @@