Skip to content

Commit

Permalink
feat: confirm before delete (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Mar 24, 2023
1 parent 1574f28 commit 4ad1341
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 31 deletions.
1 change: 0 additions & 1 deletion .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"defineAsyncComponent": true,
"defineComponent": true,
"defineStore": true,
"deleteConfirm": true,
"deleteSQL": true,
"dialogErrorMessage": true,
"effectScope": true,
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chat_gpt"
version = "0.0.6"
version = "0.0.7"
description = "ChatGPT-Desktop"
authors = ["orangelckc", "bilibili-ayang"]
license = "MIT"
Expand Down
2 changes: 0 additions & 2 deletions src/api/openAi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ export const getOpenAICreditApi = async () => {

if (isThinking) {
return '请求的 API KEY 无效'
} else {
dialogErrorMessage(message as string)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const request = async (url: string, options?: FetchOptions) => {

return data
} catch ({ message }: any) {
throw new Error(`请求出错:${message}`)
dialogErrorMessage(`请求出错:${message}`)
}
}
8 changes: 7 additions & 1 deletion src/components/Function/components/HistoryDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ const handleUpdate = (item: SessionPayload) => {
>
<template v-if="!item.isEdit">
<icon-edit @click="handleEdit(item)" />
<icon-delete @click="deleteSession(item)" />
<a-popconfirm
type="error"
content="确定删除该会话吗?"
@ok="deleteSession(item)"
>
<icon-delete />
</a-popconfirm>
</template>
<template v-else>
<icon-check @click="handleUpdate(item)" />
Expand Down
21 changes: 21 additions & 0 deletions src/components/Function/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const functions = computed(() => [
handleClick: () => {
if (isThinking.value) {
chatController.value?.abort()
if (!sessionDataList.value.at(-1)?.message.content) {
sessionDataList.value.at(-1)!.message.content = '你停止了思考'
}
updateSessionData(sessionDataList.value.at(-1)!)
} else {
getAiMessage()
Expand All @@ -64,6 +67,7 @@ const functions = computed(() => [
content: '清空对话',
icon: IconDelete,
disabled: disabled.value,
isDelete: true,
handleClick: () => deleteSession()
},
{
Expand Down Expand Up @@ -105,10 +109,27 @@ const triggerScroll = () => {
:key="index"
:position="index === functions.length - 1 ? 'tr' : 'top'"
>
<template v-if="item.isDelete">
<a-popconfirm
type="error"
content="确定要删除该会话吗?"
@ok="item.handleClick"
>
<a-button type="text" :disabled="item.disabled">
<template #icon>
<component
:is="item.icon"
class="text-5.5 text-[var(--color-text-2)]"
/>
</template>
</a-button>
</a-popconfirm>
</template>
<a-button
type="text"
:disabled="item.disabled"
@click="item.handleClick"
v-else
>
<template #icon>
<component
Expand Down
15 changes: 8 additions & 7 deletions src/components/Input/components/RoleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ const handleClose = () => {
<div v-if="!item.is_default" @click.stop>
<div v-if="!item.isEdit" class="text-5 flex gap-5">
<icon-edit @click="handleEdit(item)" />
<icon-delete
@click="deleteRole(item.id!)"
:class="{
'pointer-events-none opacity-50':
item.id === currentSession?.role_id
}"
/>
<a-popconfirm
type="error"
position="tr"
content="确定删除该角色吗?"
@ok="deleteRole(item.id!)"
>
<icon-delete />
</a-popconfirm>
</div>
<div v-else class="text-5 flex gap-5">
<icon-check @click="handleUpdate(item)" />
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useDisableShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const useDisableShortcuts = () => {
'Control+g',
'Control+r',
'Control+u',
'Control+l',
'Control+Shift+g',
'Control+Shift+i',
'Control+Shift+p',
Expand Down
10 changes: 4 additions & 6 deletions src/sqls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ export const updateSQL = async (
* @param id 删除数据的 id
*/
export const deleteSQL = async (tableName: TableName, id?: number | string) => {
// TODO: 改为 arco 气泡确认框
const isDelete = await deleteConfirm()

if (!isDelete) return

if (id) {
// 查找要删除的项是否还在数据库
const findItem = await selectSQL(tableName, [{ key: 'id', value: id }])

if (!findItem.length) return
if (!findItem.length) {
Message.error('删除失败,该数据不存在于数据库!')
return
}

await executeSQL(`DELETE FROM ${tableName} WHERE id=${id};`)
} else {
Expand Down
16 changes: 15 additions & 1 deletion src/stores/role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,21 @@ export const useRoleStore = defineStore(

await deleteSQL('role', id)

getRoleList()
await getRoleList()

const { currentSession } = storeToRefs(useSessionStore())

const findRole = roleList.value.find(
(item) => item.id === currentRole.value?.id
)

if (!findRole) {
currentRole.value = roleList.value.find((item) => item.is_default)

if (currentSession.value?.role_id === id) {
currentSession.value.role_id = currentRole.value?.id as number
}
}
}

// 更改当前的角色
Expand Down
11 changes: 1 addition & 10 deletions src/utils/tauri.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { message, confirm } from '@tauri-apps/api/dialog'
import { message } from '@tauri-apps/api/dialog'

/**
* 错误弹框
Expand All @@ -10,12 +10,3 @@ export const dialogErrorMessage = (errorMessage: string) => {
type: 'error'
})
}

/**
* 删除询问弹框
*/
export const deleteConfirm = async () =>
await confirm('确定要删除吗?', {
title: import.meta.env.VITE_APP_NAME,
type: 'error'
})

0 comments on commit 4ad1341

Please sign in to comment.