Skip to content

Commit

Permalink
perf: get focus to add border, lose focus to remove
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Mar 10, 2023
1 parent 87961ae commit 1a6dd47
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
14 changes: 13 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { appWindow } from '@tauri-apps/api/window'
import Theme from './components/Theme/index.vue'
import Avatar from './components/Avatar/index.vue'
import { useThemeStore, useUuidStore } from '@/stores'
Expand All @@ -7,15 +8,26 @@ import { initSQL } from '@/sqls'
const { themeClass } = storeToRefs(useThemeStore())
const { uuid } = storeToRefs(useUuidStore())
const borderClass = ref('')
onMounted(async () => {
initSQL()
// 监听窗口有无获取焦点
appWindow.onFocusChanged(({ payload }) => {
if (payload) {
borderClass.value = 'border border-[var(--border-color)] border-solid'
} else {
borderClass.value = ''
}
})
})
</script>

<template>
<div
class="app relative h-screen overflow-hidden rounded-xl"
:class="themeClass"
:class="[themeClass, borderClass]"
>
<Theme />

Expand Down
22 changes: 13 additions & 9 deletions src/sqls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ const tableName = 'history'
* @param sql sql 语句
*/
export const executeSQL = async (sql: string) => {
const sliceSQL = sql.slice(0, 6)

try {
await db.execute(sql)
if (sliceSQL === 'SELECT') {
return await db.select(sql)
} else {
await db.execute(sql)
}
} catch (error) {
let action = '创建'

if (sql.includes('INSERT')) {
if (sliceSQL === 'SELECT') {
action = '获取'
} else if (sliceSQL === 'INSERT') {
action = '添加'
} else if (sql.includes('UPDATE')) {
} else if (sliceSQL === 'UPDATE') {
action = '更新'
} else if (sql.includes('DELETE')) {
} else if (sliceSQL === 'DELETE') {
action = '删除'
}

Expand All @@ -43,11 +51,7 @@ export const initSQL = () => {
* 查找的 sql 语句
*/
export const selectSQL = async () => {
try {
return await db.select(`SELECT * FROM ${tableName} ORDER BY id;`)
} catch (error) {
dialogErrorMessage('数据查找失败,请重试~')
}
return await executeSQL(`SELECT * FROM ${tableName} ORDER BY id;`)
}

/**
Expand Down

0 comments on commit 1a6dd47

Please sign in to comment.