From 91cdb24a6273ded1aa993ee6efef1018b15f8dc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Wed, 19 Feb 2025 11:01:56 +0800 Subject: [PATCH] =?UTF-8?q?Demo=EF=BC=9Aai=E8=83=BD=E5=8A=9B=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Edit/components/Contextmenu.vue | 7 +- web/src/pages/Edit/components/Edit.vue | 16 +++- .../pages/Edit/components/SidebarTrigger.vue | 8 +- web/src/pages/Edit/components/Toolbar.vue | 81 ++++++++++--------- web/src/store.js | 8 +- 5 files changed, 73 insertions(+), 47 deletions(-) diff --git a/web/src/pages/Edit/components/Contextmenu.vue b/web/src/pages/Edit/components/Contextmenu.vue index c5046e41..af18b281 100644 --- a/web/src/pages/Edit/components/Contextmenu.vue +++ b/web/src/pages/Edit/components/Contextmenu.vue @@ -140,8 +140,8 @@
{{ $t('contextmenu.exportNodeToPng') }}
-
-
+
+
{{ $t('contextmenu.aiCreate') }}
@@ -257,7 +257,8 @@ export default { isZenMode: state => state.localConfig.isZenMode, isDark: state => state.localConfig.isDark, supportNumbers: state => state.supportNumbers, - supportCheckbox: state => state.supportCheckbox + supportCheckbox: state => state.supportCheckbox, + enableAi: state => state.enableAi }), expandList() { return [ diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 77938fe6..b8349223 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -47,8 +47,8 @@ v-if="mindMap" :mindMap="mindMap" > - - + +
state.localConfig.isUseMomentum, extraTextOnExport: state => state.extraTextOnExport, - isDragOutlineTreeNode: state => state.isDragOutlineTreeNode + isDragOutlineTreeNode: state => state.isDragOutlineTreeNode, + enableAi: state => state.enableAi }) }, watch: { @@ -250,6 +251,11 @@ export default { } } }, + created() { + if (this.$route.query && this.$route.query.ai) { + this.setEnableAi(true) + } + }, mounted() { showLoading() // this.showNewFeatureInfo() @@ -282,6 +288,8 @@ export default { this.mindMap.destroy() }, methods: { + ...mapMutations(['setEnableAi']), + handleStartTextEdit() { this.mindMap.renderer.startTextEdit() }, diff --git a/web/src/pages/Edit/components/SidebarTrigger.vue b/web/src/pages/Edit/components/SidebarTrigger.vue index ffa5883a..9a98742c 100644 --- a/web/src/pages/Edit/components/SidebarTrigger.vue +++ b/web/src/pages/Edit/components/SidebarTrigger.vue @@ -44,7 +44,8 @@ export default { ...mapState({ isDark: state => state.localConfig.isDark, activeSidebar: state => state.activeSidebar, - isReadonly: state => state.isReadonly + isReadonly: state => state.isReadonly, + enableAi: state => state.enableAi }), triggerList() { @@ -54,6 +55,11 @@ export default { return ['outline', 'shortcutKey'].includes(item.value) }) } + if (!this.enableAi) { + list = list.filter(item => { + return item.value !== 'ai' + }) + } return list } }, diff --git a/web/src/pages/Edit/components/Toolbar.vue b/web/src/pages/Edit/components/Toolbar.vue index b7bdee47..cdca10d3 100644 --- a/web/src/pages/Edit/components/Toolbar.vue +++ b/web/src/pages/Edit/components/Toolbar.vue @@ -163,6 +163,27 @@ import { throttle, isMobile } from 'simple-mind-map/src/utils/index' * @Desc: 工具栏 */ let fileHandle = null +const defaultBtnList = [ + 'back', + 'forward', + 'painter', + 'siblingNode', + 'childNode', + 'deleteNode', + 'image', + 'icon', + 'link', + 'note', + 'tag', + 'summary', + 'associativeLine', + 'formula', + // 'attachment', + 'outerFrame', + 'annotation', + 'ai' +] + export default { name: 'Toolbar', components: { @@ -178,26 +199,6 @@ export default { data() { return { isMobile: isMobile(), - list: [ - 'back', - 'forward', - 'painter', - 'siblingNode', - 'childNode', - 'deleteNode', - 'image', - 'icon', - 'link', - 'note', - 'tag', - 'summary', - 'associativeLine', - 'formula', - // 'attachment', - 'outerFrame', - 'annotation', - 'ai' - ], horizontalList: [], verticalList: [], showMoreBtn: true, @@ -217,8 +218,24 @@ export default { ...mapState({ isDark: state => state.localConfig.isDark, isHandleLocalFile: state => state.isHandleLocalFile, - openNodeRichText: state => state.localConfig.openNodeRichText - }) + openNodeRichText: state => state.localConfig.openNodeRichText, + enableAi: state => state.enableAi + }), + + btnLit() { + let res = [...defaultBtnList] + if (!this.openNodeRichText) { + res = res.filter(item => { + return item !== 'formula' + }) + } + if (!this.enableAi) { + res = res.filter(item => { + return item !== 'ai' + }) + } + return res + } }, watch: { isHandleLocalFile(val) { @@ -226,21 +243,9 @@ export default { Notification.closeAll() } }, - openNodeRichText: { - immediate: true, - handler(val) { - const index = this.list.findIndex(item => { - return item === 'formula' - }) - if (val) { - if (index === -1) { - this.list.splice(13, 0, 'formula') - } - } else { - if (index !== -1) { - this.list.splice(index, 1) - } - } + btnLit: { + deep: true, + handler() { this.computeToolbarShow() } } @@ -268,7 +273,7 @@ export default { computeToolbarShow() { if (!this.$refs.toolbarRef) return const windowWidth = window.innerWidth - 40 - const all = [...this.list] + const all = [...this.btnLit] let index = 1 const loopCheck = () => { if (index > all.length) return done() diff --git a/web/src/store.js b/web/src/store.js index ff2e0f79..6c820f68 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -45,7 +45,8 @@ const store = new Vuex.Store({ model: '', port: 3456, method: 'POST' - } + }, + enableAi: false // 是否开启AI功能 }, mutations: { // 设置思维导图数据 @@ -142,6 +143,11 @@ const store = new Vuex.Store({ // 设置树节点拖拽 setIsDragOutlineTreeNode(state, data) { state.isDragOutlineTreeNode = data + }, + + // 设置是否启用AI功能 + setEnableAi(state, data) { + state.enableAi = data } }, actions: {