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