main
cysamurai 6 months ago
parent ecef181a85
commit 1730761e5f

@ -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-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-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 - [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.

@ -6,9 +6,10 @@ directories:
files: files:
- '!**/.vscode/*' - '!**/.vscode/*'
- '!src/*' - '!src/*'
- 'src/renderer/src/utils/config.json'
- '!electron.vite.config.{js,ts,mjs,cjs}' - '!electron.vite.config.{js,ts,mjs,cjs}'
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}' - '!{.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}' - '!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}'
asarUnpack: asarUnpack:
- resources/** - resources/**

@ -1,5 +1,9 @@
<script setup lang="ts"></script> <script setup lang="ts">
import { NDialogProvider } from 'naive-ui'
</script>
<template> <template>
<n-dialog-provider>
<router-view></router-view> <router-view></router-view>
</n-dialog-provider>
</template> </template>

@ -2,8 +2,9 @@ import './assets/main.css'
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import naive from 'naive-ui'
import router from './router' // 路由 import router from './router' // 路由
import { createPinia } from 'pinia' // 状态管理 import { createPinia } from 'pinia' // 状态管理
createApp(App).use(router).use(createPinia()).mount('#app') createApp(App).use(naive).use(router).use(createPinia()).mount('#app')

@ -3,7 +3,7 @@ import Login from '@renderer/views/Login.vue'
import Home from '@renderer/views/Home..vue' import Home from '@renderer/views/Home..vue'
export default createRouter({ export default createRouter({
history: createWebHashHistory(), // hash模式 history: createWebHashHistory(),
routes: [ routes: [
{ path: '/', component: Login }, { path: '/', component: Login },
{ path: '/home', component: Home } { path: '/home', component: Home }

@ -1,10 +1,23 @@
import axios from 'axios' 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({ const instance = axios.create({
baseURL: API_BASE_URL, baseURL: API_BASE_URL,
timeout: 1000 timeout: 5000 // Increased timeout for production
}) })
// 添加请求拦截器 // 添加请求拦截器
@ -26,7 +39,11 @@ instance.interceptors.response.use(
return response return response
}, },
function (error) { function (error) {
// 对响应错误做点什么 if (error.code === 'ECONNABORTED') {
error.message = '请求超时,请检查网络连接'
} else if (!error.response) {
error.message = '无法连接到服务器请检查API地址配置'
}
return Promise.reject(error) return Promise.reject(error)
} }
) )

@ -1,16 +1,34 @@
<script setup lang="ts"> <script setup lang="ts">
import { loginByJson } from '@renderer/api/api' import { loginByJson } from '@renderer/api/api'
import router from '@renderer/router' import router from '@renderer/router'
import { NFlex, NInput, NButton } from 'naive-ui' import { NFlex, NInput, NButton, useDialog } from 'naive-ui'
const dialog = useDialog()
const login = async () => { const login = async () => {
try {
let res = await loginByJson({ let res = await loginByJson({
ticketNumber: 'A0001', ticketNumber: 'A0001',
phoneNumber: '13312341234' phoneNumber: '13312341234'
}) })
console.log(res) console.log('Login response:', res)
if (res.data.code == 200) { if (res.data.code == 200) {
router.push('/home') router.push('/home')
} else {
console.error('Login failed:', res.data)
dialog.error({
title: '登录失败',
content: '登录失败: ' + (res.data.message || '未知错误'),
positiveText: '确定'
})
}
} catch (error: unknown) {
console.error('Login error:', error)
dialog.error({
title: '登录失败',
content: '登录请求失败: ' + (error instanceof Error ? error.message : '网络错误'),
positiveText: '确定'
})
} }
} }
</script> </script>

Loading…
Cancel
Save