Merge branch 'main' of http://27.128.240.72:3000/zhuhao/AIx_Smarttalk
# Conflicts: # src/main/index.js
This commit is contained in:
parent
df87aafca4
commit
7782de699f
|
@ -1,4 +1,4 @@
|
|||
import { app, shell, BrowserWindow, ipcMain } from 'electron'
|
||||
import { app, shell, BrowserWindow, ipcMain, session } from 'electron'
|
||||
import { join } from 'path'
|
||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
|
@ -6,12 +6,15 @@ import File from './file'
|
|||
import Tool from './tool'
|
||||
|
||||
File({ app, shell, BrowserWindow, ipcMain })
|
||||
// zdg: 创建工具-如 悬浮球
|
||||
Tool(app, shell, BrowserWindow, ipcMain)
|
||||
|
||||
function createWindow() {
|
||||
// Create the browser window.
|
||||
const mainWindow = new BrowserWindow({
|
||||
|
||||
|
||||
let mainWindow, loginWindow
|
||||
|
||||
//登录窗口
|
||||
function createLoginWindow() {
|
||||
if (loginWindow) return
|
||||
loginWindow = new BrowserWindow({
|
||||
width: 888,
|
||||
height: 520,
|
||||
show: false,
|
||||
|
@ -24,53 +27,154 @@ function createWindow() {
|
|||
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.show()
|
||||
})
|
||||
|
||||
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||
shell.openExternal(details.url)
|
||||
return { action: 'deny' }
|
||||
})
|
||||
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']) {
|
||||
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
||||
|
||||
// mainWindow.loadURL('https://file.ysaix.com:7868/')
|
||||
|
||||
} else {
|
||||
// mainWindow.loadURL('https://file.ysaix.com:7868/')
|
||||
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
||||
}
|
||||
}
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.whenReady().then(() => {
|
||||
// Set app user model id for windows
|
||||
// 作业窗口相关-开发中
|
||||
let workWindow
|
||||
function createWork(data) {
|
||||
if (workWindow) return
|
||||
workWindow = new BrowserWindow({
|
||||
width: 650,
|
||||
height: 500,
|
||||
show: false,
|
||||
frame: true,
|
||||
|
||||
autoHideMenuBar: true,
|
||||
...(process.platform === 'linux' ? { icon } : {}),
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
|
||||
workWindow.webContents.session.cookies.set(
|
||||
{
|
||||
url: 'https://file.ysaix.com:7868',
|
||||
name: 'Admin-Token',
|
||||
value: data
|
||||
},
|
||||
function (error) {
|
||||
if (error) {
|
||||
console.error('Set cookie failed:', error)
|
||||
} else {
|
||||
console.log('Cookie set successfully.')
|
||||
}
|
||||
}
|
||||
)
|
||||
workWindow.loadURL(
|
||||
'https://file.ysaix.com:7868/teaching/classtaskassign?titleName=%E4%BD%9C%E4%B8%9A%E5%B8%83%E7%BD%AE'
|
||||
)
|
||||
|
||||
workWindow.once('ready-to-show', () => {
|
||||
workWindow.show()
|
||||
})
|
||||
workWindow.on('closed', () => {
|
||||
workWindow = null
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化完成
|
||||
app.on('ready', () => {
|
||||
// 设置应用程序用户模型标识符
|
||||
electronApp.setAppUserModelId('com.electron')
|
||||
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
//一个新的browserWindow 被创建时触发
|
||||
app.on('browser-window-created', (_, 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()
|
||||
})
|
||||
|
||||
createWindow()
|
||||
ipcMain.on('close-window', () => {
|
||||
if (loginWindow) {
|
||||
loginWindow.destroy()
|
||||
}
|
||||
if (mainWindow) {
|
||||
mainWindow.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
// 打开主窗口
|
||||
ipcMain.on('openMainWindow', () => {
|
||||
if (!mainWindow) {
|
||||
createMainWindow()
|
||||
}
|
||||
|
||||
loginWindow.destroy()
|
||||
loginWindow = null
|
||||
})
|
||||
// 打开登录窗口
|
||||
ipcMain.on('openLoginWindow', () => {
|
||||
if (!loginWindow) {
|
||||
createLoginWindow()
|
||||
}
|
||||
mainWindow.destroy()
|
||||
loginWindow.show()
|
||||
loginWindow.focus()
|
||||
})
|
||||
|
||||
//打开作业窗口
|
||||
ipcMain.on('openWork', (e, data) => {
|
||||
createWork(data)
|
||||
})
|
||||
// zdg: 创建工具窗口-如 悬浮球
|
||||
// Tool(app, shell, BrowserWindow, ipcMain)
|
||||
createLoginWindow()
|
||||
app.on('activate', function () {
|
||||
// On macOS it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (BrowserWindow.getAllWindows().length === 0) createWindow()
|
||||
if (BrowserWindow.getAllWindows().length === 0) createLoginWindow()
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -82,35 +186,3 @@ app.on('window-all-closed', () => {
|
|||
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()
|
||||
})
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<template>
|
||||
<div class="header-tool flex">
|
||||
<span title="最小化" @click="minimizeWindow"><i class="iconfont icon-zuixiaohua"></i></span>
|
||||
<span v-if="isHasMax" :title="isMaxSize ? '向下还原' : '最大化'" @click="maximizeWindow">
|
||||
<i class="iconfont" :class="isMaxSize ? 'icon-zuidahua' : 'icon-window-max_line'"></i></span>
|
||||
<span class="close" title="关闭" @click="closeWindow"><i class="iconfont icon-close"></i></span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
|
||||
const props = defineProps({
|
||||
isHasMax: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
})
|
||||
const isMaxSize = ref(false)
|
||||
|
||||
// 最小化
|
||||
const minimizeWindow = () => {
|
||||
ipcRenderer?.send('minimize-window')
|
||||
}
|
||||
//最大化
|
||||
const maximizeWindow = () => {
|
||||
ipcRenderer?.send('maximize-window')
|
||||
isMaxSize.value = !isMaxSize.value
|
||||
}
|
||||
//关闭
|
||||
const closeWindow = () => {
|
||||
ipcRenderer?.send('close-window')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.header-tool {
|
||||
-webkit-app-region: no-drag;
|
||||
|
||||
span {
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
padding: 2px 10px;
|
||||
|
||||
&:hover {
|
||||
background-color: #c4c4c4;
|
||||
}
|
||||
}
|
||||
|
||||
.close {
|
||||
&:hover {
|
||||
background-color: #fb4a3e;
|
||||
|
||||
.iconfont {
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
|
@ -14,12 +14,7 @@
|
|||
</div>
|
||||
|
||||
<div class="right-section flex">
|
||||
<div class="header-tool flex">
|
||||
<span title="最小化" @click="minimizeWindow"><i class="iconfont"></i></span>
|
||||
<span :title="isMaxSize ? '向下还原' : '最大化'" @click="maximizeWindow"><i class="iconfont">{{ isMaxSize ? '' :
|
||||
'' }}</i></span>
|
||||
<span class="close" title="关闭" @click="closeWindow"><i class="iconfont"></i></span>
|
||||
</div>
|
||||
<WindowTools/>
|
||||
<div class="user flex">
|
||||
<div class="avatar-container">
|
||||
<el-dropdown @command="handleCommand" class="right-menu-item hover-effect" trigger="click">
|
||||
|
@ -46,11 +41,11 @@
|
|||
import { ref, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import WindowTools from '@/components/window-tools/index.vue'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
const isMaxSize = ref(false)
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const currentRoute = ref('')
|
||||
|
||||
|
@ -81,19 +76,6 @@ watch(
|
|||
{ immediate: true }
|
||||
)
|
||||
|
||||
// 最小化
|
||||
const minimizeWindow = () => {
|
||||
ipcRenderer.send('minimize-window')
|
||||
}
|
||||
//最大化
|
||||
const maximizeWindow = () => {
|
||||
ipcRenderer?.send('maximize-window')
|
||||
isMaxSize.value = !isMaxSize.value
|
||||
}
|
||||
//关闭
|
||||
const closeWindow = () => {
|
||||
ipcRenderer.send('close-window')
|
||||
}
|
||||
|
||||
const changePage = (url) => {
|
||||
router.push(url)
|
||||
|
@ -118,11 +100,11 @@ function logout() {
|
|||
type: 'warning'
|
||||
}).then(() => {
|
||||
userStore.logOut().then(() => {
|
||||
// location.href = '/index#/login';
|
||||
router.replace('/login')
|
||||
// router.replace('/login')
|
||||
ipcRenderer && ipcRenderer.send('openLoginWindow')
|
||||
}).catch(()=>{
|
||||
router.replace('/login')
|
||||
// location.href = '/index#/login';
|
||||
// router.replace('/login')
|
||||
ipcRenderer && ipcRenderer.send('openLoginWindow')
|
||||
})
|
||||
}).catch(() => { });
|
||||
}
|
||||
|
@ -213,25 +195,6 @@ watch(()=> userStore.avatar,() => {
|
|||
padding-bottom: 5px;
|
||||
flex-direction: column;
|
||||
|
||||
.header-tool {
|
||||
-webkit-app-region: no-drag;
|
||||
span {
|
||||
border-radius: 3px;
|
||||
cursor: pointer;
|
||||
padding: 2px 10px;
|
||||
&:hover {
|
||||
background-color: #c4c4c4;
|
||||
}
|
||||
}
|
||||
.close{
|
||||
&:hover{
|
||||
background-color: #fb4a3e;
|
||||
.iconfont{
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.user {
|
||||
.user-info {
|
||||
|
|
|
@ -18,8 +18,6 @@ import uploaderState from '@/store/modules/uploader'
|
|||
import { ref } from 'vue'
|
||||
let uploaderStore = ref(uploaderState())
|
||||
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
ipcRenderer ? ipcRenderer .send('set-winsize', { x: 1200, y: 700 }) : ''
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
|
@ -13,7 +13,7 @@ export const constantRoutes = [
|
|||
{
|
||||
path: '/',
|
||||
component: Layout,
|
||||
redirect: '/login',
|
||||
redirect: '/resource',
|
||||
children: [
|
||||
{
|
||||
path: '/resource',
|
||||
|
|
|
@ -4,6 +4,7 @@ import { getToken } from '@/utils/auth'
|
|||
import errorCode from '@/utils/errorCode'
|
||||
import { tansParams, blobValidate } from '@/utils/ruoyi'
|
||||
import cache from '@/plugins/cache'
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
|
||||
import useUserStore from '@/store/modules/user'
|
||||
|
||||
|
@ -81,7 +82,7 @@ service.interceptors.response.use(res => {
|
|||
ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', { confirmButtonText: '重新登录', cancelButtonText: '取消', type: 'warning' }).then(() => {
|
||||
isRelogin.show = false;
|
||||
useUserStore().logOut().then(() => {
|
||||
location.href = '/index#/login';
|
||||
ipcRenderer && ipcRenderer.send('openLoginWindow')
|
||||
})
|
||||
}).catch(() => {
|
||||
isRelogin.show = false;
|
||||
|
|
|
@ -7,10 +7,7 @@
|
|||
<img class="welcome-img" :src="leftBg2" />
|
||||
</div>
|
||||
<div class="box-item login">
|
||||
<div class="header-tool flex">
|
||||
<span @click="minimizeWindow" title="最小化"><i class="iconfont"></i></span>
|
||||
<span @click="closeWindow" title="关闭"><i class="iconfont"></i></span>
|
||||
</div>
|
||||
<WindowTools :isHasMax="false"/>
|
||||
<div class="login-title">账号登录</div>
|
||||
<el-form ref="formRef" class="login-form" :model="loginForm" :rules="rules" size="large">
|
||||
<el-form-item prop="username">
|
||||
|
@ -38,19 +35,16 @@
|
|||
</template>
|
||||
<script setup>
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import Cookies from 'js-cookie'
|
||||
import { encrypt, decrypt } from '@/utils/jsencrypt'
|
||||
import useUserStore from '@/store/modules/user'
|
||||
import leftBg2 from '@/assets/images/login/left-bg2.png'
|
||||
import WindowTools from '@/components/window-tools/index.vue'
|
||||
import SelectSubject from '@/components/select-subject/index.vue'
|
||||
|
||||
const { ipcRenderer } = window.electron || {}
|
||||
const formRef = ref()
|
||||
const userStore = useUserStore()
|
||||
const router = useRouter()
|
||||
const isMaxSize = ref(false)
|
||||
const btnLoading = ref(false)
|
||||
const isSubject = ref(false)
|
||||
//表单
|
||||
|
@ -65,8 +59,6 @@ const rules = reactive({
|
|||
password: [{ required: true, trigger: 'blur', message: '请输入您的密码' }]
|
||||
})
|
||||
|
||||
ipcRenderer ? ipcRenderer.send('set-winsize', { x: 888, y: 520 }) : ''
|
||||
|
||||
//登录
|
||||
const submitForm = async (formEl) => {
|
||||
if (!formEl) return
|
||||
|
@ -90,13 +82,12 @@ const submitForm = async (formEl) => {
|
|||
await userStore.getInfo()
|
||||
if(userStore.user.edustage || userStore.user.edusubject){
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/resource')
|
||||
ipcRenderer && ipcRenderer.send('openMainWindow')
|
||||
}
|
||||
else{
|
||||
isSubject.value = true
|
||||
}
|
||||
|
||||
|
||||
}finally{
|
||||
btnLoading.value = false
|
||||
}
|
||||
|
@ -107,7 +98,7 @@ const submitForm = async (formEl) => {
|
|||
const successEditSubject = ()=>{
|
||||
isSubject.value = false
|
||||
ElMessage.success('登录成功')
|
||||
router.push('/resource')
|
||||
ipcRenderer && ipcRenderer.send('openMainWindow')
|
||||
}
|
||||
|
||||
const getCookie = () => {
|
||||
|
@ -122,19 +113,6 @@ const getCookie = () => {
|
|||
onMounted(()=>{
|
||||
getCookie()
|
||||
})
|
||||
// 最小化
|
||||
const minimizeWindow = () => {
|
||||
ipcRenderer.send('minimize-window')
|
||||
}
|
||||
//最大化
|
||||
const maximizeWindow = () => {
|
||||
ipcRenderer.send('maximize-window')
|
||||
isMaxSize.value = !isMaxSize.value
|
||||
}
|
||||
//关闭
|
||||
const closeWindow = () => {
|
||||
ipcRenderer.send('close-window')
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.login-container {
|
||||
|
|
Loading…
Reference in New Issue