From fd24cb67a21ef10fda412c7a49fa427a783a691f Mon Sep 17 00:00:00 2001 From: YangFong Date: Wed, 4 Dec 2024 14:17:33 +0800 Subject: [PATCH] chore: update ui --- package.json | 3 +- .../CodemirrorEditor/EditorHeader/index.vue | 57 +++++++++++++------ .../ui/alert-dialog/AlertDialog.vue | 14 +++++ .../ui/alert-dialog/AlertDialogAction.vue | 20 +++++++ .../ui/alert-dialog/AlertDialogCancel.vue | 27 +++++++++ .../ui/alert-dialog/AlertDialogContent.vue | 42 ++++++++++++++ .../alert-dialog/AlertDialogDescription.vue | 25 ++++++++ .../ui/alert-dialog/AlertDialogFooter.vue | 21 +++++++ .../ui/alert-dialog/AlertDialogHeader.vue | 16 ++++++ .../ui/alert-dialog/AlertDialogTitle.vue | 22 +++++++ .../ui/alert-dialog/AlertDialogTrigger.vue | 11 ++++ src/components/ui/alert-dialog/index.ts | 9 +++ src/components/ui/sonner/Sonner.vue | 22 +++++++ src/components/ui/sonner/index.ts | 1 + src/stores/index.ts | 39 ++++++------- src/views/CodemirrorEditor.vue | 17 +++--- 16 files changed, 296 insertions(+), 50 deletions(-) create mode 100644 src/components/ui/alert-dialog/AlertDialog.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogAction.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogCancel.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogContent.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogDescription.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogFooter.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogHeader.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogTitle.vue create mode 100644 src/components/ui/alert-dialog/AlertDialogTrigger.vue create mode 100644 src/components/ui/alert-dialog/index.ts create mode 100644 src/components/ui/sonner/Sonner.vue create mode 100644 src/components/ui/sonner/index.ts diff --git a/package.json b/package.json index 093c682..0345864 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "tailwindcss-animate": "^1.0.7", "tiny-oss": "^0.5.1", "uuid": "^11.0.3", - "vue": "^3.5.13" + "vue": "^3.5.13", + "vue-sonner": "^1.3.0" }, "devDependencies": { "@antfu/eslint-config": "3.11.0", diff --git a/src/components/CodemirrorEditor/EditorHeader/index.vue b/src/components/CodemirrorEditor/EditorHeader/index.vue index 3f65709..2a019c5 100644 --- a/src/components/CodemirrorEditor/EditorHeader/index.vue +++ b/src/components/CodemirrorEditor/EditorHeader/index.vue @@ -1,4 +1,15 @@ + + diff --git a/src/components/ui/alert-dialog/AlertDialogAction.vue b/src/components/ui/alert-dialog/AlertDialogAction.vue new file mode 100644 index 0000000..60e5af7 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogAction.vue @@ -0,0 +1,20 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogCancel.vue b/src/components/ui/alert-dialog/AlertDialogCancel.vue new file mode 100644 index 0000000..61c5bb8 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogCancel.vue @@ -0,0 +1,27 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogContent.vue b/src/components/ui/alert-dialog/AlertDialogContent.vue new file mode 100644 index 0000000..83fdf99 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogContent.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogDescription.vue b/src/components/ui/alert-dialog/AlertDialogDescription.vue new file mode 100644 index 0000000..9f6db43 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogDescription.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogFooter.vue b/src/components/ui/alert-dialog/AlertDialogFooter.vue new file mode 100644 index 0000000..55d0a0e --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogFooter.vue @@ -0,0 +1,21 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogHeader.vue b/src/components/ui/alert-dialog/AlertDialogHeader.vue new file mode 100644 index 0000000..c61c449 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogHeader.vue @@ -0,0 +1,16 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogTitle.vue b/src/components/ui/alert-dialog/AlertDialogTitle.vue new file mode 100644 index 0000000..6cd13f9 --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogTitle.vue @@ -0,0 +1,22 @@ + + + diff --git a/src/components/ui/alert-dialog/AlertDialogTrigger.vue b/src/components/ui/alert-dialog/AlertDialogTrigger.vue new file mode 100644 index 0000000..4f5e2fd --- /dev/null +++ b/src/components/ui/alert-dialog/AlertDialogTrigger.vue @@ -0,0 +1,11 @@ + + + diff --git a/src/components/ui/alert-dialog/index.ts b/src/components/ui/alert-dialog/index.ts new file mode 100644 index 0000000..448d519 --- /dev/null +++ b/src/components/ui/alert-dialog/index.ts @@ -0,0 +1,9 @@ +export { default as AlertDialog } from './AlertDialog.vue' +export { default as AlertDialogAction } from './AlertDialogAction.vue' +export { default as AlertDialogCancel } from './AlertDialogCancel.vue' +export { default as AlertDialogContent } from './AlertDialogContent.vue' +export { default as AlertDialogDescription } from './AlertDialogDescription.vue' +export { default as AlertDialogFooter } from './AlertDialogFooter.vue' +export { default as AlertDialogHeader } from './AlertDialogHeader.vue' +export { default as AlertDialogTitle } from './AlertDialogTitle.vue' +export { default as AlertDialogTrigger } from './AlertDialogTrigger.vue' diff --git a/src/components/ui/sonner/Sonner.vue b/src/components/ui/sonner/Sonner.vue new file mode 100644 index 0000000..b82b29e --- /dev/null +++ b/src/components/ui/sonner/Sonner.vue @@ -0,0 +1,22 @@ + + + diff --git a/src/components/ui/sonner/index.ts b/src/components/ui/sonner/index.ts new file mode 100644 index 0000000..0d4a642 --- /dev/null +++ b/src/components/ui/sonner/index.ts @@ -0,0 +1 @@ +export { default as Toaster } from './Sonner.vue' diff --git a/src/stores/index.ts b/src/stores/index.ts index 7a0921e..6e66447 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -6,10 +6,10 @@ import { initRenderer } from '@/utils/renderer' import { useDark, useStorage, useToggle } from '@vueuse/core' import CodeMirror from 'codemirror' -import { ElMessage, ElMessageBox } from 'element-plus' import { marked } from 'marked' import { defineStore } from 'pinia' import { computed, markRaw, onMounted, ref, toRaw, watch } from 'vue' +import { toast } from 'vue-sonner' export const useStore = defineStore(`store`, () => { // 是否开启深色模式 @@ -361,7 +361,7 @@ export const useStore = defineStore(`store`, () => { reader.readAsText(file) reader.onload = (event) => { (editor.value!).setValue((event.target!).result as string) - ElMessage.success(`文档导入成功`) + toast.success(`文档导入成功`) } } @@ -372,26 +372,23 @@ export const useStore = defineStore(`store`, () => { // 重置样式 const resetStyleConfirm = () => { - ElMessageBox.confirm( - `此操作将丢失本地自定义样式,是否继续?`, - `提示`, - { - confirmButtonText: `确定`, - cancelButtonText: `取消`, - type: `warning`, - center: true, - }, - ) - .then(() => { + // ElMessageBox.confirm( + // `此操作将丢失本地自定义样式,是否继续?`, + // `提示`, + // { + // confirmButtonText: `确定`, + // cancelButtonText: `取消`, + // type: `warning`, + // center: true, + // }, + // ) + // .then(() => { resetStyle() - ElMessage({ - type: `success`, - message: `样式重置成功~`, - }) - }) - .catch(() => { - (editor.value!).focus() - }) + toast.success(`样式重置成功~`) + // }) + // .catch(() => { + // (editor.value!).focus() + // }) } return { diff --git a/src/views/CodemirrorEditor.vue b/src/views/CodemirrorEditor.vue index d1c1b64..db98a72 100644 --- a/src/views/CodemirrorEditor.vue +++ b/src/views/CodemirrorEditor.vue @@ -4,7 +4,6 @@ import CssEditor from '@/components/CodemirrorEditor/CssEditor.vue' import EditorHeader from '@/components/CodemirrorEditor/EditorHeader/index.vue' import InsertFormDialog from '@/components/CodemirrorEditor/InsertFormDialog.vue' import UploadImgDialog from '@/components/CodemirrorEditor/UploadImgDialog.vue' - import RunLoading from '@/components/RunLoading.vue' import { ContextMenu, @@ -24,12 +23,10 @@ import { } from '@/utils' import fileApi from '@/utils/file' import CodeMirror from 'codemirror' - -import { ElCol, ElMessage } from 'element-plus' - +import { ElCol } from 'element-plus' import { storeToRefs } from 'pinia' - import { onMounted, ref, toRaw, watch } from 'vue' +import { toast } from 'vue-sonner' const store = useStore() const displayStore = useDisplayStore() @@ -131,7 +128,7 @@ function beforeUpload(file: File) { // validate image const checkResult = checkImage(file) if (!checkResult.ok) { - ElMessage.error(checkResult.msg) + toast.error(checkResult.msg) return false } @@ -142,7 +139,7 @@ function beforeUpload(file: File) { const config = localStorage.getItem(`${imgHost}Config`) const isValidHost = imgHost === `default` || config if (!isValidHost) { - ElMessage.error(`请先配置 ${imgHost} 图床参数`) + toast.error(`请先配置 ${imgHost} 图床参数`) return false } return true @@ -151,7 +148,7 @@ function beforeUpload(file: File) { // 图片上传结束 function uploaded(imageUrl: string) { if (!imageUrl) { - ElMessage.error(`上传图片未知异常`) + toast.error(`上传图片未知异常`) return } toggleShowUploadImgDialog(false) @@ -160,7 +157,7 @@ function uploaded(imageUrl: string) { const markdownImage = `![](${imageUrl})` // 将 Markdown 形式的 URL 插入编辑框光标所在位置 toRaw(store.editor!).replaceSelection(`\n${markdownImage}\n`, cursor as any) - ElMessage.success(`图片上传成功`) + toast.success(`图片上传成功`) } function uploadImage(file: File, cb?: { (url: any): void, (arg0: unknown): void } | undefined) { isImgLoading.value = true @@ -176,7 +173,7 @@ function uploadImage(file: File, cb?: { (url: any): void, (arg0: unknown): void } }) .catch((err) => { - ElMessage.error(err.message) + toast.error(err.message) }) .finally(() => { isImgLoading.value = false