feat: 调整登录
This commit is contained in:
@@ -3,13 +3,18 @@ import { join } from 'path'
|
|||||||
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
|
|
||||||
|
let mainWindow: BrowserWindow | null = null
|
||||||
|
|
||||||
function createWindow(): void {
|
function createWindow(): void {
|
||||||
// Create the browser window.
|
// Create the browser window.
|
||||||
const mainWindow = new BrowserWindow({
|
mainWindow = new BrowserWindow({
|
||||||
width: 900,
|
width: 900,
|
||||||
height: 670,
|
height: 670,
|
||||||
show: false,
|
show: false,
|
||||||
autoHideMenuBar: true,
|
autoHideMenuBar: true,
|
||||||
|
resizable: false, // 禁止拖拽放大缩小
|
||||||
|
maximizable: false, // 禁止最大化
|
||||||
|
minimizable: true, // 允许最小化
|
||||||
...(process.platform === 'linux' ? { icon } : {}),
|
...(process.platform === 'linux' ? { icon } : {}),
|
||||||
webPreferences: {
|
webPreferences: {
|
||||||
preload: join(__dirname, '../preload/index.js'),
|
preload: join(__dirname, '../preload/index.js'),
|
||||||
@@ -18,7 +23,7 @@ function createWindow(): void {
|
|||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('ready-to-show', () => {
|
mainWindow.on('ready-to-show', () => {
|
||||||
mainWindow.show()
|
mainWindow?.show()
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
@@ -52,6 +57,15 @@ app.whenReady().then(() => {
|
|||||||
// IPC test
|
// IPC test
|
||||||
ipcMain.on('ping', () => console.log('pong'))
|
ipcMain.on('ping', () => console.log('pong'))
|
||||||
|
|
||||||
|
// 监听登录成功事件,恢复窗口拖拽功能
|
||||||
|
ipcMain.on('login-success', () => {
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.setResizable(true)
|
||||||
|
mainWindow.setMaximizable(true)
|
||||||
|
console.log('窗口拖拽功能已恢复')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
createWindow()
|
createWindow()
|
||||||
|
|
||||||
app.on('activate', function () {
|
app.on('activate', function () {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<div class="fz-22 mb-20">手机扫码登录</div>
|
<div class="fz-22 mb-20">手机扫码登录</div>
|
||||||
<div class="w-48 h-48 bg-white rounded-lg mx-auto flex items-center justify-center">
|
<div class="w-48 h-48 bg-white rounded-lg mx-auto flex items-center justify-center">
|
||||||
<div class="qr text-center mt-20">
|
<div class="qr text-center mt-20">
|
||||||
<vue-qrcode value="https://www.1stg.me" width="195" margin="3" />
|
<VueQrcode value="https://www.1stg.me" :width="195" :margin="3" />
|
||||||
|
|
||||||
<!-- 二维码失效 -->
|
<!-- 二维码失效 -->
|
||||||
<div class="qrcode-error">
|
<div class="qrcode-error">
|
||||||
@@ -140,12 +140,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup ts>
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted } from 'vue'
|
import { ref, reactive, onMounted } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { User, Lock, Key } from '@element-plus/icons-vue'
|
import { User, Lock, Key } from '@element-plus/icons-vue'
|
||||||
import VueQrcode from 'vue-qrcode'
|
import VueQrcode from 'vue-qrcode'
|
||||||
|
|
||||||
|
// 路由实例
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
// 登录表单
|
// 登录表单
|
||||||
const loginFormRef = ref()
|
const loginFormRef = ref()
|
||||||
const loginForm = reactive({
|
const loginForm = reactive({
|
||||||
@@ -173,11 +177,8 @@ const showCaptcha = ref(false)
|
|||||||
const captchaCode = ref('8K9M')
|
const captchaCode = ref('8K9M')
|
||||||
const loginAttempts = ref(0)
|
const loginAttempts = ref(0)
|
||||||
|
|
||||||
// 生成二维码
|
|
||||||
const qrCodeUrl = ref('')
|
|
||||||
|
|
||||||
// 刷新验证码
|
// 刷新验证码
|
||||||
const refreshCaptcha = () => {
|
const refreshCaptcha = (): void => {
|
||||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
let code = ''
|
let code = ''
|
||||||
for (let i = 0; i < 4; i++) {
|
for (let i = 0; i < 4; i++) {
|
||||||
@@ -187,7 +188,7 @@ const refreshCaptcha = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理登录
|
// 处理登录
|
||||||
const handleLogin = async () => {
|
const handleLogin = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await loginFormRef.value.validate()
|
await loginFormRef.value.validate()
|
||||||
|
|
||||||
@@ -198,13 +199,18 @@ const handleLogin = async () => {
|
|||||||
loading.value = false
|
loading.value = false
|
||||||
loginAttempts.value++
|
loginAttempts.value++
|
||||||
|
|
||||||
// 模拟登录失败,显示验证码
|
// 模拟登录成功
|
||||||
if (loginAttempts.value >= 1) {
|
if (loginForm.username === 'admin' && loginForm.password === '123456') {
|
||||||
showCaptcha.value = true
|
ElMessage.success('登录成功')
|
||||||
|
// 登录成功后,跳转到首页
|
||||||
|
router.push({ name: 'home' })
|
||||||
|
// 登录成功后,通知主进程
|
||||||
|
if (window.electron && window.electron.ipcRenderer) {
|
||||||
|
window.electron.ipcRenderer.send('login-success')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
ElMessage.error('用户名或密码错误')
|
ElMessage.error('用户名或密码错误')
|
||||||
refreshCaptcha()
|
refreshCaptcha()
|
||||||
} else {
|
|
||||||
ElMessage.success('登录成功')
|
|
||||||
}
|
}
|
||||||
}, 1500)
|
}, 1500)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -213,7 +219,7 @@ const handleLogin = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理忘记密码
|
// 处理忘记密码
|
||||||
const handleForgotPassword = () => {
|
const handleForgotPassword = (): void => {
|
||||||
ElMessage.info('忘记密码功能开发中...')
|
ElMessage.info('忘记密码功能开发中...')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +227,7 @@ const handleForgotPassword = () => {
|
|||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const usernameInput = document.querySelector('input[placeholder="请输入用户名/邮箱/手机号"]')
|
const usernameInput = document.querySelector('input[placeholder="请输入用户名/邮箱/手机号"]')
|
||||||
if (usernameInput) {
|
if (usernameInput) {
|
||||||
usernameInput.focus()
|
;(usernameInput as HTMLInputElement).focus()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user