From 012c87d02e77f777d3043fc81821d843a1fce5aa Mon Sep 17 00:00:00 2001 From: chunshan <1484082125@qq.com> Date: Sun, 2 Oct 2022 00:25:26 +0800 Subject: [PATCH 01/36] =?UTF-8?q?feat():=20=E2=9C=A8=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加 插件打开命令,对接 gitc message 类型。减少鼠标操作 --- public/plugin.json | 27 ++++++++++++++++++++------- src/components/home.vue | 26 ++++++++++++++++---------- src/composables/useDark.ts | 7 +++---- src/composables/usePluginEnter.ts | 6 ++---- src/composables/useUtools.ts | 7 ++++--- 5 files changed, 45 insertions(+), 28 deletions(-) diff --git a/public/plugin.json b/public/plugin.json index 3d8304b..3e62e87 100644 --- a/public/plugin.json +++ b/public/plugin.json @@ -1,13 +1,26 @@ { "main": "./index.html", "logo": "logo.png", - "features": [{ - "code": "git-commit", - "explain": "帮助开发快速完成git commit message", - "cmds": [ - "gitc" - ] - }], + "features": [ + { + "code": "git-commit", + "explain": "帮助开发快速完成git commit message", + "cmds": [ + "gitc", + "gitcfeat", + "gitcfix", + "gitcdocs", + "gitcstyle", + "gitcrefactor", + "gitcperf", + "gitctest", + "gitcbuild", + "gitcci", + "gitcchore", + "gitcrevert" + ] + } + ], "development": { "main": "http://localhost:8979/" } diff --git a/src/components/home.vue b/src/components/home.vue index 78c11fd..b685214 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -19,7 +19,7 @@ - + - + @@ -39,7 +40,7 @@ - Ctrl /Command + Alt 快速复制并关闭 + ctrl + Shift + c 复制结果 tab 快速切换输入框 @@ -53,14 +54,21 @@ import { nameToEmoji } from 'gemoji' import useUtools from "../composables/useUtools"; import { rawEmojis, typeData } from "../data"; const message = useMessage(); -const utools = useUtools() -const { ctrl_alt } = useMagicKeys(); -whenever(ctrl_alt, () => { +const utools = useUtools((data) => { + let payload: string = data.payload as string; + let cmd: string = payload.replace('gitc', ''); + if (cmd) { + type.value = cmd; + } +}) +const keys = useMagicKeys(); +const shiftCtrlC = keys['Shift+Ctrl+C'] +whenever(shiftCtrlC, () => { handleCopy() }) const handleCopy = async () => { if (!subject.value) { - message.error("必填项必填"); + message.error("简短描述必填"); return; } await copy(content.value); @@ -70,8 +78,6 @@ const handleCopy = async () => { }); }; // https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js -// TODO 后期引入默认emoji -// TODO 后期引入国际化 const typeOptions = ref(typeData); // 默认emoji const defatltEmoji = ref("✨"); @@ -90,7 +96,7 @@ const subject = ref(""); const body = ref(""); // 最后 -const footer = ref(""); +// const footer = ref(""); const emoji = ref(defatltEmoji.value) diff --git a/src/composables/useDark.ts b/src/composables/useDark.ts index d6c45f4..5bc8080 100644 --- a/src/composables/useDark.ts +++ b/src/composables/useDark.ts @@ -1,10 +1,9 @@ -import { Ref } from "vue"; -import usePluginEnter from "./usePluginEnter"; +import { Ref, onMounted } from "vue"; export default function useDark(): Ref { const isDark = ref(false); - usePluginEnter(() => { + onMounted(() => { isDark.value = window?.utools.isDarkColors(); - }); + }) return isDark; } diff --git a/src/composables/usePluginEnter.ts b/src/composables/usePluginEnter.ts index ebe419a..1b83a2b 100644 --- a/src/composables/usePluginEnter.ts +++ b/src/composables/usePluginEnter.ts @@ -7,9 +7,7 @@ export interface IPluginEnterAction { export default function usePluginEnter( hook: (action: IPluginEnterAction) => unknown ) { - onMounted(() => { - window?.utools?.onPluginEnter((action) => { - return hook(action); - }); + window?.utools?.onPluginEnter((action) => { + return hook(action); }); } diff --git a/src/composables/useUtools.ts b/src/composables/useUtools.ts index a4bbcdd..f911b74 100644 --- a/src/composables/useUtools.ts +++ b/src/composables/useUtools.ts @@ -1,9 +1,10 @@ -import usePluginEnter from "./usePluginEnter"; +import usePluginEnter, { IPluginEnterAction } from "./usePluginEnter"; -export default function useUtools(){ +export default function useUtools(_hook?: (action: IPluginEnterAction) => unknown) { let tools = reactive(window?.utools); - usePluginEnter(() => { + usePluginEnter((action) => { tools = window!.utools; + _hook && _hook(action); }); return tools; } From 7e9c8df5b1b830eee09a677b091ab924cc6e9e6a Mon Sep 17 00:00:00 2001 From: chunshan <1484082125@qq.com> Date: Sat, 8 Oct 2022 14:05:31 +0800 Subject: [PATCH 02/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B8=AE=E5=8A=A9=20?= =?UTF-8?q?=E9=A2=84=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 ++ src/App.vue | 2 -- src/components/home.vue | 72 +++++++++++++++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 11 deletions(-) diff --git a/components.d.ts b/components.d.ts index 2404231..a3e12ec 100644 --- a/components.d.ts +++ b/components.d.ts @@ -8,6 +8,8 @@ declare module 'vue' { NButton: typeof import('naive-ui')['NButton'] NCard: typeof import('naive-ui')['NCard'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] + NDrawer: typeof import('naive-ui')['NDrawer'] + NDrawerContent: typeof import('naive-ui')['NDrawerContent'] NGrid: typeof import('naive-ui')['NGrid'] NGridItem: typeof import('naive-ui')['NGridItem'] NInput: typeof import('naive-ui')['NInput'] diff --git a/src/App.vue b/src/App.vue index 5978430..526d94d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,8 +4,6 @@ - From 2f2ba9df4d73a8a77cdd5efb3180639d8e725bb8 Mon Sep 17 00:00:00 2001 From: chunshan <1484082125@qq.com> Date: Tue, 31 Jan 2023 09:31:55 +0800 Subject: [PATCH 05/36] fix --- src/components/home.vue | 53 ++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/components/home.vue b/src/components/home.vue index 9ec9280..d66c0f3 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -42,24 +42,21 @@ -

历史记录 清空

- - - - {{ item.content }} - - - - + + + {{ item.content }} + + +
@@ -120,12 +117,19 @@ interface commitInterface { } const historyLog = ref([]); const message = useMessage(); -const utools = useUtools((data) => { +useUtools((data) => { let payload: string = data.payload as string; let cmd: string = payload.replace('gitc', ''); if (cmd) { type.value = cmd; } + try { + let list = window?.utools?.dbStorage.getItem(_historyLogKEY); + historyLog.value = list ? JSON.parse(list) : []; + } catch (error) { + historyLog.value = []; + } + }) const keys = useMagicKeys(); const shiftCtrlC = keys['Shift+Ctrl+C'] @@ -164,9 +168,9 @@ const handleCopy = async () => { body: body.value, content: content.value }); - utools?.dbStorage.setItem(_historyLogKEY, JSON.stringify(historyLog.value)) + window?.utools?.dbStorage.setItem(_historyLogKEY, JSON.stringify(historyLog.value)) show.value = false; - utools?.hideMainWindow(); + window?.utools?.hideMainWindow(); }; // https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js const typeOptions = ref(typeData); @@ -175,7 +179,6 @@ const defatltEmoji = ref("✨"); // 类型 const type = ref("feat"); watch(type, (val) => { - // console.log(val) emoji.value = typeOptions.value.find((item) => item.value === val)?.emoji ?? defatltEmoji.value }) // 范围 @@ -236,18 +239,15 @@ const handleEditHistoryLog = (item: commitInterface) => { scope.value = item.scope ?? ''; body.value = item.body ?? ""; type.value = item.type; - message.success("双击"); + message.success("设置成功"); } const handleClearHigLog = () => { historyLog.value = []; - utools?.dbStorage.setItem(_historyLogKEY, JSON.stringify([])); + window?.utools?.dbStorage.setItem(_historyLogKEY, JSON.stringify([])); } -onMounted(() => { - let list = utools?.dbStorage.getItem(_historyLogKEY); - historyLog.value = list ? JSON.parse(list) : []; -}) + From a025da6e602e6cfad80c36040a2d0b784b46e1dc Mon Sep 17 00:00:00 2001 From: chunshan <1484082125@qq.com> Date: Thu, 8 Jun 2023 00:44:54 +0800 Subject: [PATCH 06/36] =?UTF-8?q?feat:=20=20emoji=E5=BC=80=E5=85=B3=2050?= =?UTF-8?q?=E5=AD=97=E6=8F=8F=E8=BF=B0=E9=99=90=E5=88=B6=20=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E7=BB=93=E6=9E=9C=E6=8E=92=E7=89=88=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components.d.ts | 2 ++ src/components/home.vue | 34 ++++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/components.d.ts b/components.d.ts index 8ecfbb2..df92411 100644 --- a/components.d.ts +++ b/components.d.ts @@ -7,6 +7,7 @@ declare module 'vue' { Home: typeof import('./src/components/home.vue')['default'] NButton: typeof import('naive-ui')['NButton'] NCard: typeof import('naive-ui')['NCard'] + NCheckbox: typeof import('naive-ui')['NCheckbox'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NDrawer: typeof import('naive-ui')['NDrawer'] NDrawerContent: typeof import('naive-ui')['NDrawerContent'] @@ -17,6 +18,7 @@ declare module 'vue' { NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NSelect: typeof import('naive-ui')['NSelect'] NSpace: typeof import('naive-ui')['NSpace'] + NSwitch: typeof import('naive-ui')['NSwitch'] NText: typeof import('naive-ui')['NText'] } } diff --git a/src/components/home.vue b/src/components/home.vue index d66c0f3..dcf5a94 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -1,9 +1,10 @@ diff --git a/src/components/SettingsView.vue b/src/components/SettingsView.vue index 5ee1ee1..3d8c432 100644 --- a/src/components/SettingsView.vue +++ b/src/components/SettingsView.vue @@ -33,11 +33,9 @@ diff --git a/src/components/home.vue b/src/components/home.vue index b1302bc..b4e0ba1 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -5,7 +5,7 @@ 设置 - 帮助 + 帮助 预览 重置内容   @@ -19,7 +19,7 @@ - + - + - + - + - - - - 帮助: - Ctrl + Shift + C 快速复制 并关闭工具 - Ctrl + Shift + R 重置内容 - Ctrl + P 快速打开预览,关闭预览 - Tab 快速切换输入框 - - 历史记录最多保存5条历史,单击复制信息内容,双击将对应信息内容设置到表单,方便二次编辑 - - - - + + + diff --git a/src/components/Help.vue b/src/components/Help.vue index 98b3f60..cae0358 100644 --- a/src/components/Help.vue +++ b/src/components/Help.vue @@ -47,7 +47,7 @@ const helpContent: { } ], "gitemoji关键字": [ - { commnet: "在该关键字下支持emoji中文或英文搜索" }, + { commnet: "在该关键字下可直接使用英文或中文(首字母)搜索emoji" }, { commnet: "选中emoji后按下回车可以快速复制" } ] } diff --git a/src/components/home.vue b/src/components/home.vue index b4e0ba1..db97c06 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -5,6 +5,7 @@ 设置 + 自定义emoji 帮助 预览 重置内容 @@ -44,7 +45,7 @@ v-model:value="emoji" placeholder="emoji" size="large" - :options="emojiOptions" + :options="emojisStore.emojiOptions.value" filterable :disabled="!settingsStore.settings.value.isEmoji" ref="searchEmoji" @@ -122,13 +123,13 @@ + - - diff --git a/src/store/emojis.ts b/src/store/emojis.ts index 673967e..daf9d97 100644 --- a/src/store/emojis.ts +++ b/src/store/emojis.ts @@ -2,6 +2,14 @@ import { useSearchTxtArr } from "@/composables/useSearch"; import { type RawEmoji, rawEmojis } from "@/data"; import EmojiLabel from "@/components/EmojiLabel.vue"; +const CUSTOM_EMOJIS_KEY = "CUSTOM_EMOJIS_STORE"; + +const readCustomEmojis = () => { + const customEmoji: RawEmoji[] = utools.dbStorage.getItem(CUSTOM_EMOJIS_KEY); + if (customEmoji === null) return []; + return customEmoji; +}; + const toEmojiOptions = (item: RawEmoji) => ({ ...item, searchTxtArr: useSearchTxtArr(item), @@ -17,27 +25,24 @@ const toEmojiOptions = (item: RawEmoji) => ({ }); export const useEmojisStore = createGlobalState(() => { - const CUSTOM_EMOJIS_KEY = "CUSTOM_EMOJIS_STORE"; - - const readCustomEmojis = () => { - const customEmoji: RawEmoji[] = utools.dbStorage.getItem(CUSTOM_EMOJIS_KEY); - if (customEmoji === null) return []; - return customEmoji; - }; - rawEmojis.push(...readCustomEmojis()); - let emojiOptions = ref(rawEmojis.map(toEmojiOptions)); + const rawEmojiOptions = rawEmojis.map(toEmojiOptions); + let customEmojis = readCustomEmojis(); + let emojiOptions = ref( + rawEmojiOptions.concat(...customEmojis.map(toEmojiOptions)) + ); /** * 除了增加新的emoji列表外,相同的emoji会覆盖已有的 - * @param coustomEmojis + * @param customEmojis */ - const updateEmojis = (coustomEmojis: RawEmoji[]) => { + const updateEmojis = (customEmojis: RawEmoji[]) => { type EmojiOptionsType = ReturnType; let newEmojis: EmojiOptionsType[] = []; let result: number; - // todo: 已有的自定义emoji再保存会重新参与遍历,应该排除上一次自定义emoji - coustomEmojis.forEach((userEmoji) => { + emojiOptions.value = rawEmojis.map(toEmojiOptions); + + customEmojis.forEach((userEmoji) => { result = emojiOptions.value.findIndex( (emoji) => emoji.name === userEmoji.name ); @@ -51,6 +56,7 @@ export const useEmojisStore = createGlobalState(() => { // 新的emoji会暂存在newEmojis,等自定义的全部遍历完在一起push else newEmojis.push(toEmojiOptions(userEmoji)); }); + emojiOptions.value.push(...newEmojis); }; @@ -58,5 +64,5 @@ export const useEmojisStore = createGlobalState(() => { utools.dbStorage.setItem(CUSTOM_EMOJIS_KEY, customEmoji); }; - return { emojiOptions, updateEmojis, readCustomEmojis, saveCustomEmojis }; + return { emojiOptions, updateEmojis, customEmojis, saveCustomEmojis }; }); From e4a5c84ae58f666a1b1b9f07e020bfee128e4197 Mon Sep 17 00:00:00 2001 From: xyeluo Date: Fri, 6 Oct 2023 23:49:12 +0800 Subject: [PATCH 30/36] =?UTF-8?q?feat:=20=F0=9F=9A=B8=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E8=AF=B4=E6=98=8E=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=83=A8=E5=88=86emoji?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CustomEmoji.vue | 21 ++++++---- src/components/Help.vue | 76 +++++++++++++++++++++++++++++----- src/data/rawEmojis.ts | 48 --------------------- src/store/emojis.ts | 71 ++++++++++++++++++++----------- 4 files changed, 125 insertions(+), 91 deletions(-) diff --git a/src/components/CustomEmoji.vue b/src/components/CustomEmoji.vue index 39b1a50..1416414 100644 --- a/src/components/CustomEmoji.vue +++ b/src/components/CustomEmoji.vue @@ -2,11 +2,17 @@ -
- 自定义emoji: + + 自定义emoji: 保存 -
- +
+
@@ -21,9 +27,9 @@ isOpenWindow.value = true defineExpose({ switchCustom }) const { error, success } = useMessage() -const { updateEmojis, customEmojis, saveCustomEmojis } = useEmojisStore() +const { updateEmojis, customEmojis } = useEmojisStore() -let userEmojis = ref(JSON.stringify(customEmojis, undefined, 2)) +let userEmojis = ref(customEmojis.value.length === 0 ? "" : JSON.stringify(customEmojis.value, undefined, 2)) let inputStatus = ref<"success" | "error">("success") const customEorror = (str: string) => { @@ -58,10 +64,11 @@ const validEmojiKey = (emojisData: RawEmoji[]) => { const saveEmojisData = () => { try { + if (userEmojis.value === "") return updateEmojis([]) let emojisData: RawEmoji[] = JSON.parse(userEmojis.value) + if (!validEmojiKey(emojisData)) return updateEmojis(emojisData) - saveCustomEmojis(emojisData) customSuccess("保存成功") } catch (err) { customEorror(`[JSON Error]:${err}`) diff --git a/src/components/Help.vue b/src/components/Help.vue index cae0358..3e382b1 100644 --- a/src/components/Help.vue +++ b/src/components/Help.vue @@ -10,26 +10,29 @@
{{ contents[0] }}:
-
+
    - - - {{ item.commnet }} - +
  • + + + + +
  • -
+ @@ -63,4 +94,27 @@ const helpContent: { .help-content { margin-left: var(--space); } +ul, +li { + margin: 0; + padding-left: 3px; + list-style-position: inside; +} +:deep(b) { + font-weight: 400; + padding: 0.01em 0.35em 0.2em 0.33em; + border-radius: 3px; +} +@media (prefers-color-scheme: dark) { + :deep(b) { + background-color: rgba(255, 255, 255, 0.2); + color: rgba(255, 255, 255, 0.82); + } +} +@media (prefers-color-scheme: light) { + :deep(b) { + background-color: rgb(244, 244, 248); + color: rgb(65, 68, 71); + } +} diff --git a/src/data/rawEmojis.ts b/src/data/rawEmojis.ts index 33202d9..50fca44 100644 --- a/src/data/rawEmojis.ts +++ b/src/data/rawEmojis.ts @@ -77,36 +77,6 @@ export const rawEmojis: RawEmoji[] = [ "pinyin": "xiu fu an quan wen ti", "emoji": "🔒", }, - { - "name": "apple", - "description": "修复在苹果系统上的问题", - "pinyin": "xiu fu zai ping guo xi tong shang de wen ti", - "emoji": "🍎", - }, - { - "name": "penguin", - "description": "修复在 Linux 系统上的问题", - "pinyin": "xiu fu zai Linux xi tong shang de wen ti", - "emoji": "🐧", - }, - { - "name": "checkered_flag", - "description": "修复在 Windows 系统上的问题", - "pinyin": "xiu fu zai Windows xi tong shang de wen ti", - "emoji": "🏁", - }, - { - "name": "robot", - "description": "修复在安卓系统上的问题", - "pinyin": "xiu fu zai an zhuo xi tong shang de wen ti", - "emoji": "🤖", - }, - { - "name": "green_apple", - "description": "修复在 iOS 系统上的问题", - "pinyin": "xiu fu zai iOS xi tong shang de wen ti", - "emoji": "🍏", - }, { "name": "bookmark", "description": "发布 / 版本标签", @@ -167,12 +137,6 @@ export const rawEmojis: RawEmoji[] = [ "pinyin": "dai ma chong gou", "emoji": "♻️", }, - { - "name": "whale", - "description": "Docker 容器相关", - "pinyin": "Docker rong qi xiang guan", - "emoji": "🐳", - }, { "name": "heavy_plus_sign", "description": "添加依赖", @@ -257,12 +221,6 @@ export const rawEmojis: RawEmoji[] = [ "pinyin": "tian jia huo zhe geng xin jing tai zi yuan", "emoji": "🍱", }, - { - "name": "ok_hand", - "description": "代码审核后更新代码", - "pinyin": "dai ma shen he hou geng xin dai ma", - "emoji": "👌", - }, { "name": "wheelchair", "description": "改进可访问性", @@ -371,12 +329,6 @@ export const rawEmojis: RawEmoji[] = [ "pinyin": "gai jin sou suo yin qing you hua", "emoji": "🔍", }, - { - "name": "wheel_of_dharma", - "description": "Kubernetes 相关的工作", - "pinyin": "Kubernetes xiang guan de gong zuo", - "emoji": "☸️", - }, { "name": "label", "description": "添加或者更新类型(Flow, TypeScript)", diff --git a/src/store/emojis.ts b/src/store/emojis.ts index daf9d97..3a5b748 100644 --- a/src/store/emojis.ts +++ b/src/store/emojis.ts @@ -6,7 +6,7 @@ const CUSTOM_EMOJIS_KEY = "CUSTOM_EMOJIS_STORE"; const readCustomEmojis = () => { const customEmoji: RawEmoji[] = utools.dbStorage.getItem(CUSTOM_EMOJIS_KEY); - if (customEmoji === null) return []; + if (customEmoji === null || customEmoji.length === 0) return []; return customEmoji; }; @@ -24,45 +24,66 @@ const toEmojiOptions = (item: RawEmoji) => ({ }) }); +/** + * 对自定义emoji数组的每个对象比较,name相同,后面覆盖前面 + * @param arr 自定义emoji数组对象 + * @returns + */ +const compareArrays = (arr: RawEmoji[]) => { + for (let i = 0; i < arr.length - 1; i++) { + for (let j = i + 1; j < arr.length; j++) { + if (arr[i].name === arr[j].name) { + arr[i] = { + ...arr[i], + ...arr[j] + }; + arr.splice(j, 1); + } + } + } + return arr; +}; + +type EmojiOptionsType = ReturnType; + export const useEmojisStore = createGlobalState(() => { - const rawEmojiOptions = rawEmojis.map(toEmojiOptions); + let newCustomEmojis = ref(readCustomEmojis()); + + const saveCustomEmojis = (customEmoji: RawEmoji[]) => { + utools.dbStorage.setItem(CUSTOM_EMOJIS_KEY, customEmoji); + }; - let customEmojis = readCustomEmojis(); - let emojiOptions = ref( - rawEmojiOptions.concat(...customEmojis.map(toEmojiOptions)) - ); - /** - * 除了增加新的emoji列表外,相同的emoji会覆盖已有的 - * @param customEmojis - */ const updateEmojis = (customEmojis: RawEmoji[]) => { - type EmojiOptionsType = ReturnType; + newCustomEmojis.value = compareArrays(customEmojis); + saveCustomEmojis(customEmojis); + }; + + let emojiOptions = computed(() => { let newEmojis: EmojiOptionsType[] = []; let result: number; - emojiOptions.value = rawEmojis.map(toEmojiOptions); + let emojiOptions = rawEmojis.map(toEmojiOptions); - customEmojis.forEach((userEmoji) => { - result = emojiOptions.value.findIndex( - (emoji) => emoji.name === userEmoji.name - ); + newCustomEmojis.value.forEach((userEmoji) => { + result = emojiOptions.findIndex((emoji) => emoji.name === userEmoji.name); if (result !== -1) { // 如果存在相同的name,自定义的会覆盖已有的 - emojiOptions.value[result] = toEmojiOptions({ - ...emojiOptions.value[result], + emojiOptions[result] = toEmojiOptions({ + ...emojiOptions[result], ...userEmoji }); } // 新的emoji会暂存在newEmojis,等自定义的全部遍历完在一起push else newEmojis.push(toEmojiOptions(userEmoji)); }); + emojiOptions.push(...newEmojis); + return emojiOptions; + }); - emojiOptions.value.push(...newEmojis); + return { + emojiOptions, + updateEmojis, + customEmojis: newCustomEmojis, + saveCustomEmojis }; - - const saveCustomEmojis = (customEmoji: RawEmoji[]) => { - utools.dbStorage.setItem(CUSTOM_EMOJIS_KEY, customEmoji); - }; - - return { emojiOptions, updateEmojis, customEmojis, saveCustomEmojis }; }); From 8e89b57b33bb4b6dc561d4ac2118655dfe9abd61 Mon Sep 17 00:00:00 2001 From: xyeluo Date: Sat, 7 Oct 2023 15:02:33 +0800 Subject: [PATCH 31/36] =?UTF-8?q?feat:=20=F0=9F=9A=B8=20=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 自定义emoji可省略`emoji`键 - 首次通过`gitc*`关键字进入时`简短描述`输入框自动获取焦点 --- src/components/CustomEmoji.vue | 11 +++++++---- src/components/Help.vue | 9 ++++++--- src/components/home.vue | 12 ++++++++---- src/composables/usePluginEnter.ts | 7 +++++++ src/composables/useSearch.ts | 26 ++++++++++++++------------ src/store/emojis.ts | 11 +++++------ src/store/settings.ts | 4 ++-- 7 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/components/CustomEmoji.vue b/src/components/CustomEmoji.vue index 1416414..0c7b650 100644 --- a/src/components/CustomEmoji.vue +++ b/src/components/CustomEmoji.vue @@ -23,7 +23,6 @@ import { type RawEmoji } from "@/data" import { useEmojisStore } from "@/store" let { isOpenWindow, switchWindow: switchCustom } = useWindowHandle() -isOpenWindow.value = true defineExpose({ switchCustom }) const { error, success } = useMessage() @@ -40,18 +39,22 @@ const customSuccess = (str: string) => { success(str) inputStatus.value = "success" } - +watch(isOpenWindow, (nVal) => { + if (nVal) { + inputStatus.value = "success" + } +}) /** * 验证自定义emoji的每个对象是否存在特定key * @param emojisData * @returns boolean 每个对象都存在keys时才返回true */ const validEmojiKey = (emojisData: RawEmoji[]) => { - const keys = ["name", "emoji"] + const keys = ["name"] return !emojisData.some((emojiItem) => { let flag = emojiItem.hasOwnProperty(keys[0]) ? false : keys[0] - flag = flag === false ? (emojiItem.hasOwnProperty(keys[1]) ? false : keys[1]) : flag + // flag = flag === false ? (emojiItem.hasOwnProperty(keys[1]) ? false : keys[1]) : flag if (keys.includes(flag as string)) { // 不存在flag键,终止遍历并返回true diff --git a/src/components/Help.vue b/src/components/Help.vue index 3e382b1..dca3454 100644 --- a/src/components/Help.vue +++ b/src/components/Help.vue @@ -29,7 +29,6 @@ diff --git a/src/components/Help.vue b/src/components/Help.vue index b389d22..4afdd29 100644 --- a/src/components/Help.vue +++ b/src/components/Help.vue @@ -52,6 +52,41 @@ const helpContent: { { commnet: "在该关键字下可直接使用英文或中文(首字母)搜索emoji" }, { commnet: "选中emoji后按下回车可以快速复制" } ], + "【自定义commit message】—— 更改已有或添加自己的message": [ + { + commnet: + "请填入JSON数组格式的文本,数组中的每个元素都为对象,每个对象都是一个msg所需信息,格式大概是message($范围): 描述" + }, + { + commnet: `每个对象包含以下三个键:
    +
  • value(必填):消息的内容,例:fire: 填入时不需要两端:name值相同的对象,后面的对象会覆盖前面的,据此可更改内置的emoji
  • +
  • label(必填):该value的描述
  • +
  • emoji(可省略):这个将会与下方emoji选项对应。例如这里填写了🐛,下方的emoji选项将会自动选中🐛:bug项
  • +
  • 以上的三个键的值都能作为搜索条件哦~
+ ` + }, + { + commnet: `以下是示例代码。第一和第二个为完整的自定义消息;第三个对象仅有必填项
+
+[
+    {
+        "value": "wuhu",
+        "label": "芜湖",
+        "emoji": "😛"
+    },
+    {
+        "value": "fly",
+        "label": "起飞",
+        "emoji": "🛫"
+    },
+    {
+        "value": "wtf",
+        "label": "公司倒闭了"
+    }
+]
+    
` + } + ], "【自定义emoji】—— 更改已有或添加自己的emoji": [ { commnet: diff --git a/src/components/home.vue b/src/components/home.vue index 990249c..25d9d9b 100644 --- a/src/components/home.vue +++ b/src/components/home.vue @@ -5,7 +5,8 @@ 设置 - 自定义emoji + 自定义msg + 自定义emoji 帮助 预览 重置内容 @@ -26,7 +27,9 @@ filterable placeholder="类型" size="large" - :options="typeOptions" + :filter="useFilterMsg" + :options="commitMsgStore.list" + :render-label="commitMsgLabelRender" :disabled="settingsStore.settings.value.isEmojiMode" > @@ -124,13 +127,14 @@ +