Compare commits

..

2 Commits

6 changed files with 96 additions and 88 deletions

View File

@ -5,9 +5,13 @@ import icon from '../../resources/icon.png?asset'
import File from './file' import File from './file'
File({ app, shell, BrowserWindow, ipcMain }) File({ app, shell, BrowserWindow, ipcMain })
function createWindow() {
// Create the browser window. let mainWindow, loginWindow
const mainWindow = new BrowserWindow({
//登录窗口
function createLoginWindow(){
if(loginWindow) return
loginWindow = new BrowserWindow({
width: 888, width: 888,
height: 520, height: 520,
show: false, show: false,
@ -19,57 +23,113 @@ function createWindow() {
sandbox: false, sandbox: false,
nodeIntegration: true nodeIntegration: true
} }
})
const loginURL = is.dev ? `http://localhost:5173/#/login` : `file://${__dirname}/index.html/login`
loginWindow.loadURL(loginURL)
loginWindow.once('ready-to-show', () => {
loginWindow.show()
})
loginWindow.on('closed', () => {
loginWindow = null
})
}
//主窗口
function createMainWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 700,
show: false,
frame: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, '../preload/index.js'),
sandbox: false,
nodeIntegration: true
}
}) })
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
mainWindow.show() mainWindow.show()
}) })
mainWindow.webContents.setWindowOpenHandler((details) => { mainWindow.webContents.setWindowOpenHandler((details) => {
shell.openExternal(details.url) shell.openExternal(details.url)
return { action: 'deny' } return { action: 'deny' }
}) })
mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
// HMR for renderer base on electron-vite cli.
// Load the remote URL for development or the local html file for production.
if (is.dev && process.env['ELECTRON_RENDERER_URL']) { if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
// mainWindow.loadURL('https://file.ysaix.com:7868/')
} else { } else {
// mainWindow.loadURL('https://file.ysaix.com:7868/')
mainWindow.loadFile(join(__dirname, '../renderer/index.html')) mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
} }
} }
// This method will be called when Electron has finished // 初始化完成
// initialization and is ready to create browser windows. app.on('ready',()=>{
// Some APIs can only be used after this event occurs. // 设置应用程序用户模型标识符
app.whenReady().then(() => {
// Set app user model id for windows
electronApp.setAppUserModelId('com.electron') electronApp.setAppUserModelId('com.electron')
// Default open or close DevTools by F12 in development //一个新的browserWindow 被创建时触发
// and ignore CommandOrControl + R in production.
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
app.on('browser-window-created', (_, window) => { app.on('browser-window-created', (_, window) => {
optimizer.watchWindowShortcuts(window) optimizer.watchWindowShortcuts(window)
}) })
//窗口 最大、最小、关闭
ipcMain.on('minimize-window', () => {
if (loginWindow) {
loginWindow.minimize()
}
if (mainWindow) {
mainWindow.minimize()
}
});
ipcMain.on('maximize-window', () => {
mainWindow.isMaximized() ? mainWindow.unmaximize() : mainWindow.maximize();
});
ipcMain.on('close-window', () => {
if (loginWindow) {
loginWindow.destroy()
}
if (mainWindow) {
mainWindow.destroy()
}
});
createWindow() // 打开主窗口
ipcMain.on('openMainWindow', () => {
app.on('activate', function () { if (!mainWindow) {
// On macOS it's common to re-create a window in the app when the createMainWindow()
// dock icon is clicked and there are no other windows open. }
if (BrowserWindow.getAllWindows().length === 0) createWindow()
loginWindow.destroy()
loginWindow = null
}) })
// 打开登录窗口
ipcMain.on('openLoginWindow', () => {
if (!loginWindow) {
createLoginWindow()
}
mainWindow.destroy()
loginWindow.show()
loginWindow.focus()
})
createLoginWindow()
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createLoginWindow()
})
}) })
// Quit when all windows are closed, except on macOS. There, it's common // Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits // for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q. // explicitly with Cmd + Q.
@ -78,35 +138,3 @@ app.on('window-all-closed', () => {
app.quit() app.quit()
} }
}) })
ipcMain.on('toggle-top', (event) => {
const win = BrowserWindow.getFocusedWindow();
const isAlwaysOnTop = win.isAlwaysOnTop();
win.setAlwaysOnTop(!isAlwaysOnTop);
event.sender.send('top-status-changed', !isAlwaysOnTop);
})
ipcMain.on('minimize-window', () => {
const win = BrowserWindow.getFocusedWindow();
win.minimize();
});
ipcMain.on('maximize-window', () => {
const win = BrowserWindow.getFocusedWindow();
if (win.isMaximized()) {
win.unmaximize();
} else {
win.maximize();
}
});
ipcMain.on('close-window', () => {
const win = BrowserWindow.getFocusedWindow();
win.close();
});
ipcMain.on('set-winsize', (e, {x, y})=>{
const win = BrowserWindow.getFocusedWindow();
win.setSize(x,y);
win.center()
})

View File

@ -44,7 +44,7 @@ import { ElMessageBox } from 'element-plus'
import WindowTools from '@/components/window-tools/index.vue' import WindowTools from '@/components/window-tools/index.vue'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
const { ipcRenderer } = window.electron || {}
const userStore = useUserStore() const userStore = useUserStore()
const router = useRouter() const router = useRouter()
const currentRoute = ref('') const currentRoute = ref('')
@ -100,9 +100,11 @@ function logout() {
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
userStore.logOut().then(() => { userStore.logOut().then(() => {
router.replace('/login') // router.replace('/login')
ipcRenderer && ipcRenderer.send('openLoginWindow')
}).catch(()=>{ }).catch(()=>{
router.replace('/login') // router.replace('/login')
ipcRenderer && ipcRenderer.send('openLoginWindow')
}) })
}).catch(() => { }); }).catch(() => { });
} }

View File

@ -18,8 +18,6 @@ import uploaderState from '@/store/modules/uploader'
import { ref } from 'vue' import { ref } from 'vue'
let uploaderStore = ref(uploaderState()) let uploaderStore = ref(uploaderState())
const { ipcRenderer } = window.electron || {}
ipcRenderer ? ipcRenderer .send('set-winsize', { x: 1200, y: 700 }) : ''
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -12,7 +12,7 @@ export const constantRoutes = [
{ {
path: '/', path: '/',
component: Layout, component: Layout,
redirect: '/login', redirect: '/resource',
children: [ children: [
{ {
path: '/resource', path: '/resource',

View File

@ -4,6 +4,7 @@ import { getToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode' import errorCode from '@/utils/errorCode'
import { tansParams, blobValidate } from '@/utils/ruoyi' import { tansParams, blobValidate } from '@/utils/ruoyi'
import cache from '@/plugins/cache' import cache from '@/plugins/cache'
const { ipcRenderer } = window.electron || {}
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
@ -81,7 +82,7 @@ service.interceptors.response.use(res => {
ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => { ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
isRelogin.show = false; isRelogin.show = false;
useUserStore().logOut().then(() => { useUserStore().logOut().then(() => {
location.href = '/index#/login'; ipcRenderer && ipcRenderer.send('openLoginWindow')
}) })
}).catch(() => { }).catch(() => {
isRelogin.show = false; isRelogin.show = false;

View File

@ -35,21 +35,16 @@
</template> </template>
<script setup> <script setup>
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import Cookies from 'js-cookie'
import { encrypt, decrypt } from '@/utils/jsencrypt' import { encrypt, decrypt } from '@/utils/jsencrypt'
import useUserStore from '@/store/modules/user' import useUserStore from '@/store/modules/user'
import leftBg2 from '@/assets/images/login/left-bg2.png' import leftBg2 from '@/assets/images/login/left-bg2.png'
import WindowTools from '@/components/window-tools/index.vue' import WindowTools from '@/components/window-tools/index.vue'
import SelectSubject from '@/components/select-subject/index.vue' import SelectSubject from '@/components/select-subject/index.vue'
const { ipcRenderer } = window.electron || {} const { ipcRenderer } = window.electron || {}
const formRef = ref() const formRef = ref()
const userStore = useUserStore() const userStore = useUserStore()
const router = useRouter()
const isMaxSize = ref(false)
const btnLoading = ref(false) const btnLoading = ref(false)
const isSubject = ref(false) const isSubject = ref(false)
// //
@ -64,8 +59,6 @@ const rules = reactive({
password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }] password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }]
}) })
ipcRenderer ? ipcRenderer.send('set-winsize', { x: 888, y: 520 }) : ''
// //
const submitForm = async (formEl) => { const submitForm = async (formEl) => {
if (!formEl) return if (!formEl) return
@ -89,13 +82,12 @@ const submitForm = async (formEl) => {
await userStore.getInfo() await userStore.getInfo()
if(userStore.user.edustage || userStore.user.edusubject){ if(userStore.user.edustage || userStore.user.edusubject){
ElMessage.success('登录成功') ElMessage.success('登录成功')
router.push('/resource') ipcRenderer && ipcRenderer.send('openMainWindow')
} }
else{ else{
isSubject.value = true isSubject.value = true
} }
}finally{ }finally{
btnLoading.value = false btnLoading.value = false
} }
@ -106,7 +98,7 @@ const submitForm = async (formEl) => {
const successEditSubject = ()=>{ const successEditSubject = ()=>{
isSubject.value = false isSubject.value = false
ElMessage.success('登录成功') ElMessage.success('登录成功')
router.push('/resource') ipcRenderer && ipcRenderer.send('openMainWindow')
} }
const getCookie = () => { const getCookie = () => {
@ -121,19 +113,6 @@ const getCookie = () => {
onMounted(()=>{ onMounted(()=>{
getCookie() getCookie()
}) })
//
const minimizeWindow = () => {
ipcRenderer.send('minimize-window')
}
//
const maximizeWindow = () => {
ipcRenderer.send('maximize-window')
isMaxSize.value = !isMaxSize.value
}
//
const closeWindow = () => {
ipcRenderer.send('close-window')
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.login-container { .login-container {