diff --git a/tax-asst-client/README.md b/tax-asst-client/README.md index 7a556a5..1882377 100644 --- a/tax-asst-client/README.md +++ b/tax-asst-client/README.md @@ -74,3 +74,17 @@ $ npm run build:linux - [electron-vite-bytecode-example](https://github.com/alex8088/electron-vite-bytecode-example), source code protection - [electron-vite-decorator-example](https://github.com/alex8088/electron-vite-decorator-example), typescipt decorator - [electron-vite-worker-example](https://github.com/alex8088/electron-vite-worker-example), worker and fork + +## Configuration + +The API base URL can be configured in two ways: + +1. **Production Build**: Set `VITE_API_BASE_URL` in `.env.production` before building +2. **Runtime Configuration**: Modify `src/renderer/src/utils/config.json` after installation: + ```json + { + "apiBaseUrl": "http://your-api-server:port/path" + } + ``` + +The application will first check the config file, then fall back to the environment variable. diff --git a/tax-asst-client/electron-builder.yml b/tax-asst-client/electron-builder.yml index 80292cd..66b402f 100644 --- a/tax-asst-client/electron-builder.yml +++ b/tax-asst-client/electron-builder.yml @@ -6,9 +6,10 @@ directories: files: - '!**/.vscode/*' - '!src/*' + - 'src/renderer/src/utils/config.json' - '!electron.vite.config.{js,ts,mjs,cjs}' - '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}' - - '!{.env,.env.*,.npmrc,pnpm-lock.yaml}' + - '!{.env,.npmrc,pnpm-lock.yaml}' - '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}' asarUnpack: - resources/** diff --git a/tax-asst-client/src/renderer/src/App.vue b/tax-asst-client/src/renderer/src/App.vue index 5affcbe..6cdc774 100644 --- a/tax-asst-client/src/renderer/src/App.vue +++ b/tax-asst-client/src/renderer/src/App.vue @@ -1,5 +1,9 @@ - + diff --git a/tax-asst-client/src/renderer/src/main.ts b/tax-asst-client/src/renderer/src/main.ts index 50d67b0..3b0f43c 100644 --- a/tax-asst-client/src/renderer/src/main.ts +++ b/tax-asst-client/src/renderer/src/main.ts @@ -2,8 +2,9 @@ import './assets/main.css' import { createApp } from 'vue' import App from './App.vue' +import naive from 'naive-ui' import router from './router' // 路由 import { createPinia } from 'pinia' // 状态管理 -createApp(App).use(router).use(createPinia()).mount('#app') +createApp(App).use(naive).use(router).use(createPinia()).mount('#app') diff --git a/tax-asst-client/src/renderer/src/router/index.ts b/tax-asst-client/src/renderer/src/router/index.ts index 91fa4fc..a1d9445 100644 --- a/tax-asst-client/src/renderer/src/router/index.ts +++ b/tax-asst-client/src/renderer/src/router/index.ts @@ -3,9 +3,9 @@ import Login from '@renderer/views/Login.vue' import Home from '@renderer/views/Home..vue' export default createRouter({ - history: createWebHashHistory(), // hash模式 + history: createWebHashHistory(), routes: [ { path: '/', component: Login }, - { path:'/home', component: Home} + { path: '/home', component: Home } ] }) diff --git a/tax-asst-client/src/renderer/src/utils/request.ts b/tax-asst-client/src/renderer/src/utils/request.ts index f196eae..f650135 100644 --- a/tax-asst-client/src/renderer/src/utils/request.ts +++ b/tax-asst-client/src/renderer/src/utils/request.ts @@ -1,10 +1,23 @@ import axios from 'axios' +// import { readFileSync } from 'fs' +// import { join } from 'path' -const API_BASE_URL = import.meta.env.VITE_API_BASE_URL +// let API_BASE_URL = import.meta.env.VITE_API_BASE_URL + +// try { +// const configPath = join(__dirname, 'config.json') +// const config = JSON.parse(readFileSync(configPath, 'utf-8')) +// if (config.apiBaseUrl) { +// API_BASE_URL = config.apiBaseUrl +// } +// } catch (error) { +// console.warn('Failed to read config file, using environment variable:', error) +// } +let API_BASE_URL = import.meta.env.VITE_API_BASE_URL const instance = axios.create({ baseURL: API_BASE_URL, - timeout: 1000 + timeout: 5000 // Increased timeout for production }) // 添加请求拦截器 @@ -26,7 +39,11 @@ instance.interceptors.response.use( return response }, function (error) { - // 对响应错误做点什么 + if (error.code === 'ECONNABORTED') { + error.message = '请求超时,请检查网络连接' + } else if (!error.response) { + error.message = '无法连接到服务器,请检查API地址配置' + } return Promise.reject(error) } ) diff --git a/tax-asst-client/src/renderer/src/views/Login.vue b/tax-asst-client/src/renderer/src/views/Login.vue index 299ff3e..00503e4 100644 --- a/tax-asst-client/src/renderer/src/views/Login.vue +++ b/tax-asst-client/src/renderer/src/views/Login.vue @@ -1,22 +1,40 @@