-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { selectSQL, insertSQL, updateSQL, deleteSQL } from '@/sqls' | ||
import type { HistoryRecord, RecordData } from '@/types' | ||
|
||
export const useRecordStore = defineStore('recordStore', () => { | ||
const currentRecord = ref<number>() | ||
|
||
const recordList = ref<HistoryRecord[]>([]) | ||
|
||
const getRecord = async () => { | ||
recordList.value = await selectSQL() | ||
} | ||
|
||
const addRecord = async (data: RecordData[]) => { | ||
await insertSQL(data) | ||
|
||
getRecord() | ||
} | ||
|
||
const updateRecord = async (id: number, payload: HistoryRecord) => { | ||
await updateSQL(id, payload) | ||
|
||
getRecord() | ||
} | ||
|
||
const deleteRecord = async (id?: number) => { | ||
await deleteSQL(id) | ||
|
||
getRecord() | ||
} | ||
|
||
onMounted(getRecord) | ||
|
||
return { currentRecord, recordList, addRecord, updateRecord, deleteRecord } | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
export interface RecordData { | ||
role: string | ||
content: string | ||
} | ||
|
||
export interface HistoryRecord { | ||
id?: number | ||
title?: string | ||
data?: any[] | ||
data?: RecordData[] | ||
time?: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/** | ||
* 判断数据是否为 null 或者 undefined | ||
* @param value 数据 | ||
* @returns 判断结果 | ||
*/ | ||
export const isNil = (value: any) => value == null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters