5
5
:editor =" yiiEditor?.editor"
6
6
:menu =" options.mainMenu"
7
7
:data-theme =" isDark ? 'dark' : ''"
8
- />
8
+ >
9
+ <template #left >
10
+ <o-divider vertical />
11
+ <o-popover
12
+ ref =" popover"
13
+ tippy-class =" o-ai-settings-popover"
14
+ class =" o-simple-command-btn"
15
+ placement =" bottom"
16
+ trigger =" click"
17
+ arrow
18
+ >
19
+ <template #trigger >
20
+ <o-command-btn
21
+ icon =" settings"
22
+ tooltip =" Settings"
23
+ >
24
+ </o-command-btn >
25
+ </template >
26
+
27
+ <div >
28
+ <o-btn-group >
29
+ <div data-tippy-role =" tooltip" >
30
+ <o-btn label =" OpenAI"
31
+ :class =" { 'active': aiOption.provider === 'openai' }"
32
+ @click =" aiOption.provider = 'openai'" />
33
+ </div >
34
+ <div data-tippy-role =" tooltip" >
35
+ <o-btn label =" DeepSeek"
36
+ :class =" { 'active': aiOption.provider === 'deepseek' }"
37
+ @click =" aiOption.provider = 'deepseek'" />
38
+ </div >
39
+ </o-btn-group >
40
+ </div >
41
+
42
+ <div >
43
+ <o-input ref =" input"
44
+ v-model =" aiOption.apiKey"
45
+ type =" text"
46
+ placeholder =" API Key"
47
+ autofocus clearable >
48
+ <template #prefix >
49
+ <o-icon name =" search" class =" o-tips" />
50
+ </template >
51
+ </o-input >
52
+ </div >
53
+ </o-popover >
54
+ </template >
55
+ </o-main-menu >
9
56
</header >
10
57
11
58
<section class =" layout-content" >
23
70
</template >
24
71
25
72
<script setup lang="ts">
26
- import { computed , ref , provide , onMounted , onUnmounted } from ' vue' ;
73
+ import { computed , ref , provide , watch , onMounted , onUnmounted } from ' vue' ;
27
74
import { useData } from ' vitepress' ;
28
- import { YiiEditor , ODocToc , OMainMenu } from ' @yiitap/vue' ;
75
+ import {
76
+ YiiEditor ,
77
+ ODocToc ,
78
+ OMainMenu ,
79
+ OCommandBtn ,
80
+ ODivider ,
81
+ OIcon ,
82
+ OInput ,
83
+ OBtn ,
84
+ OBtnGroup ,
85
+ OPopover
86
+ } from ' @yiitap/vue' ;
29
87
import ' @yiitap/vue/dist/vue.css' ;
30
88
import { BasicFeaturesArticle , BasicFeaturesArticleZh } from ' ../../data/demo/article' ;
31
89
@@ -41,10 +99,14 @@ const { isDark } = useData();
41
99
const localeAlt = ref (' en' )
42
100
const yiiEditor = ref <InstanceType <typeof YiiEditor >>()
43
101
const tocRef = ref <InstanceType <typeof ODocToc >>()
102
+ const aiOption = ref <AiOption >({
103
+ provider: ' deepseek' ,
104
+ })
44
105
provide (' locale' , localeAlt )
45
106
46
107
const options = computed (() => {
47
108
return {
109
+ aiOption: aiOption .value ,
48
110
// locale: locale.value,
49
111
darkMode: isDark .value ,
50
112
// editable: editable.value,
@@ -79,8 +141,10 @@ const options = computed(() => {
79
141
' table' ,
80
142
' callout' ,
81
143
' emoji' ,
144
+ ' aiBlock' ,
82
145
],
83
146
extensions: [
147
+ ' OAiBlock' ,
84
148
' OBlockquote' ,
85
149
' OCallout' ,
86
150
' OCodeBlock' ,
@@ -98,12 +162,39 @@ const options = computed(() => {
98
162
}
99
163
})
100
164
165
+ const aiOptions = computed (() => {
166
+ return [
167
+ { label: ' OpenAI' , value: ' openai' },
168
+ { label: ' DeepSeek' , value: ' deepseek' },
169
+ ]
170
+ })
171
+
172
+ function init() {
173
+ localeAlt .value = props .locale
174
+ try {
175
+ const aiOptionString = localStorage .getItem (' yiitap.ai.option' )
176
+ if (aiOptionString ) {
177
+ aiOption .value = JSON .parse (aiOptionString )
178
+ }
179
+ } catch (e ) {
180
+ // ignore
181
+ }
182
+ }
183
+
101
184
const onScroll = (event : Event ) => {
102
185
tocRef .value ?.onScroll (event );
103
- };
186
+ }
187
+
188
+ watch (
189
+ aiOption ,
190
+ (newValue ) => {
191
+ localStorage .setItem (' yiitap.ai.option' , JSON .stringify (aiOption .value ))
192
+ },
193
+ { deep: true }
194
+ )
104
195
105
196
onMounted (() => {
106
- localeAlt . value = props . locale
197
+ init ()
107
198
window .addEventListener (" scroll" , onScroll );
108
199
});
109
200
@@ -132,8 +223,25 @@ onUnmounted(() => {
132
223
133
224
.layout-toc {
134
225
position : fixed ;
135
- top : 64 px ;
226
+ top : 120 px ;
136
227
right : 10px ;
137
228
z-index : 101 ;
138
229
}
230
+
231
+ .o-input {
232
+ width : 400px ;
233
+ }
234
+
235
+ .o-btn-group {
236
+ margin-bottom : 10px ;
237
+
238
+ .o-btn .active {
239
+ color : white ;
240
+ background : var (--vp-button-brand-bg );
241
+
242
+ &:hover {
243
+ background : var (--vp-button-brand-hover-bg )!important ;
244
+ }
245
+ }
246
+ }
139
247
</style >
0 commit comments