Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
be379395f8 | |||
6191e9c171 |
@ -25,6 +25,7 @@
|
||||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.1",
|
||||
"@electron-toolkit/utils": "^3.0.0",
|
||||
"axios": "^1.7.2",
|
||||
"electron-updater": "^6.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -123,7 +123,8 @@ function createWindow() {
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
sandbox: false,
|
||||
webSecurity: false
|
||||
}
|
||||
})
|
||||
|
||||
@ -159,7 +160,10 @@ app.whenReady().then(() => {
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
app.on('browser-window-created', (_, window) => {
|
||||
optimizer.watchWindowShortcuts(window)
|
||||
})
|
||||
})
|
||||
|
||||
// 忽略证书错误
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors')
|
||||
|
||||
createWindow()
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
import electron, { contextBridge, ipcRenderer } from 'electron'
|
||||
import { electronAPI } from '@electron-toolkit/preload'
|
||||
|
||||
const http = require('http')
|
||||
|
||||
// Custom APIs for renderer
|
||||
const api = {}
|
||||
|
||||
@ -11,6 +13,7 @@ if (process.contextIsolated) {
|
||||
try {
|
||||
contextBridge.exposeInMainWorld('electron', electronAPI)
|
||||
contextBridge.exposeInMainWorld('api', api)
|
||||
contextBridge.exposeInMainWorld('http', http)
|
||||
contextBridge.exposeInMainWorld('baseConfig', {
|
||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||
})
|
||||
@ -23,6 +26,7 @@ if (process.contextIsolated) {
|
||||
} else {
|
||||
window.electron = electronAPI
|
||||
window.api = api
|
||||
window.http = http
|
||||
window.electronAPI = {
|
||||
getBaseConfig: () => ipcRenderer.invoke('getBaseConfig')
|
||||
}
|
||||
|
@ -2,11 +2,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'elf'; img-src https://*; child-src 'none';"/> -->
|
||||
<title>Electron</title>
|
||||
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP -->
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
|
||||
content="default-src 'self';connect-src 'self' https://127.0.0.1:53266; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:"
|
||||
/>
|
||||
</head>
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import Versions from './components/Versions.vue'
|
||||
import instance from './utils/http'
|
||||
|
||||
const getBaseConfig = async () => {
|
||||
return await window.baseConfig.getBaseConfig()
|
||||
@ -24,6 +25,11 @@ const intervalId = setInterval(async () => {
|
||||
console.log('检测到客户端运行')
|
||||
}
|
||||
}, 500)
|
||||
|
||||
instance.get('/lol-gameflow/v1/gameflow-phase')
|
||||
.then(res => console.info(res))
|
||||
.catch(err => console.info(err))
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
44
src/renderer/src/utils/http.js
Normal file
44
src/renderer/src/utils/http.js
Normal file
@ -0,0 +1,44 @@
|
||||
import axios from 'axios';
|
||||
|
||||
const baseConfig = async () => {
|
||||
return await window.baseConfig.getBaseConfig()
|
||||
}
|
||||
|
||||
|
||||
const baseInfo = await baseConfig()
|
||||
|
||||
const base_url = baseInfo['BASE_URL']
|
||||
const auth = baseInfo['Auth']
|
||||
|
||||
// const http = window.http;
|
||||
|
||||
|
||||
|
||||
// 创建 axios 实例
|
||||
const instance = axios.create({
|
||||
baseURL: base_url,
|
||||
timeout: 10000,
|
||||
auth: auth
|
||||
});
|
||||
|
||||
// instance.defaults.adapter = http;
|
||||
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(function (config) {
|
||||
// 在发送请求之前做些什么
|
||||
return config;
|
||||
}, function (error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// 添加响应拦截器
|
||||
instance.interceptors.response.use(function (response) {
|
||||
// 对响应数据做点什么
|
||||
return response.data; // 假设你的后端返回的是 { data: {...} } 格式的数据
|
||||
}, function (error) {
|
||||
// 对响应错误做点什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
export default instance;
|
Reference in New Issue
Block a user