feat: 配置修改
parent
3ae318e276
commit
afcf2de491
@ -0,0 +1,78 @@
|
||||
import { shell, BrowserWindow } from 'electron'
|
||||
import { join } from 'path'
|
||||
import icon from '../../../resources/icon.png?asset'
|
||||
import { is } from '@electron-toolkit/utils'
|
||||
export default class MainFrame {
|
||||
#frame: any = null
|
||||
#width = 1920
|
||||
#height = 1080
|
||||
create() {
|
||||
this.#frame = new BrowserWindow({
|
||||
width: this.#width,
|
||||
height: this.#height,
|
||||
show: false,
|
||||
// titleBarStyle:'hidden',
|
||||
frame: true, //无边框窗口
|
||||
resizable: false,
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
webPreferences: {
|
||||
preload: join(__dirname, '../preload/index.js'),
|
||||
sandbox: false
|
||||
}
|
||||
})
|
||||
this.#frame.on('ready-to-show', () => {
|
||||
this.#frame.show()
|
||||
})
|
||||
this.#frame.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
||||
this.#frame.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
} else {
|
||||
this.#frame.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
this.#frame.webContents.openDevTools() // 打开调试工具
|
||||
}
|
||||
//隐藏窗口
|
||||
hide() {
|
||||
this.#frame.hide()
|
||||
}
|
||||
//设置窗口大小
|
||||
setSize(w, h) {
|
||||
this.#frame.setSize(w, h) //设置窗口大小
|
||||
}
|
||||
//设置窗口最小值
|
||||
setMinimumSize(w, h) {
|
||||
this.#frame.setMinimumSize(w, h) //设置
|
||||
}
|
||||
//窗口居中
|
||||
center() {
|
||||
this.#frame.center() //窗口居中
|
||||
}
|
||||
//窗口是否可以改变
|
||||
setResizable(bool) {
|
||||
this.#frame.setResizable(bool) //窗口可调节大小
|
||||
}
|
||||
//接收窗口拖拽事件:
|
||||
setPosition(x, y) {
|
||||
this.#frame.setPosition(x, y)
|
||||
}
|
||||
//窗口关闭
|
||||
close() {
|
||||
this.#frame.close()
|
||||
}
|
||||
//最小化
|
||||
minimize() {
|
||||
this.#frame.minimize()
|
||||
}
|
||||
//判断是否最大化
|
||||
isFullScreen() {
|
||||
return this.#frame.isFullScreen()
|
||||
}
|
||||
//放大 & 缩小
|
||||
setFullScreen(bool) {
|
||||
this.#frame.setFullScreen(bool)
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
export default class EventRoute {
|
||||
public name: string;
|
||||
public callback: (api:any, data:any) => void;
|
||||
|
||||
constructor(name: string, callback: (api:any, data:any) => void) {
|
||||
this.name = name;
|
||||
this.callback = callback;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
export default class EventRouter {
|
||||
#api={};
|
||||
routers;
|
||||
constructor(){
|
||||
this.routers = new Array();
|
||||
}
|
||||
//添加api
|
||||
addApi(key,api){
|
||||
this.#api[key] = api;
|
||||
}
|
||||
//添加多个路由
|
||||
addRouters(routers){
|
||||
this.routers = this.routers.concat(routers);
|
||||
}
|
||||
//触发指定名称的路由回调
|
||||
router(data){
|
||||
for(let i=0;i<this.routers.length;i++){
|
||||
let r = this.routers[i];
|
||||
if(r.name == data.name && r.callback){
|
||||
r.callback(this.#api,data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
import EventRoute from "./EventRoute";
|
||||
const routers = new Array();
|
||||
|
||||
//关闭软件
|
||||
routers.push(new EventRoute("close-login", (api,data) => {
|
||||
console.log(data);
|
||||
api.mainWindow.close();
|
||||
}));
|
||||
//拖拽窗口
|
||||
routers.push(new EventRoute("custom-adsorption", (api,{data}) => {
|
||||
console.log(data);
|
||||
let x = data.appX;
|
||||
let y = data.appY;
|
||||
api.mainWindow.setPosition(x,y);
|
||||
}))
|
||||
//最小化
|
||||
routers.push(new EventRoute("min-win", (api,data) => {
|
||||
console.log(data);
|
||||
api.mainWindow.minimize();
|
||||
}))
|
||||
//最大化
|
||||
routers.push(new EventRoute("max-win", (api,data) => {
|
||||
console.log(data);
|
||||
if(api.mainWindow.isFullScreen()){
|
||||
api.mainWindow.setFullScreen(false);
|
||||
}else{
|
||||
api.mainWindow.setFullScreen(true);
|
||||
}
|
||||
}))
|
||||
//退出软件
|
||||
routers.push(new EventRoute("win-close", (api,data) => {
|
||||
console.log(data);
|
||||
api.app.exit();
|
||||
}))
|
||||
//退出登陆
|
||||
routers.push(new EventRoute("out-login", (api,data) => {
|
||||
console.log(data);
|
||||
api.mainWindow.setSize(900,670);
|
||||
api.mainWindow.center();
|
||||
api.mainWindow.setResizable(false);
|
||||
}))
|
||||
//进入后台管理系统首页
|
||||
routers.push(new EventRoute("resize-window", (api,data) => {
|
||||
console.log(data);
|
||||
api.mainWindow.setSize(1200,720);
|
||||
api.mainWindow.setMinimumSize(1000,500)
|
||||
api.mainWindow.center();
|
||||
api.mainWindow.setResizable(true);
|
||||
}))
|
||||
export default routers;
|
Loading…
Reference in New Issue