@@ -28,8 +28,6 @@ import { Dialog, Menu } from "siyuan"
28
28
import PageUtil from "~/siyuan/utils/pageUtil"
29
29
import { getAvailableOrigin } from "~/siyuan/utils/utils"
30
30
import { contentElement , contentHtml } from "~/siyuan/customElement"
31
- import { adjustIframeHeight } from "~/siyuan/iframeEvent"
32
- import { popContentIframeId } from "~/siyuan/siyuanConstants"
33
31
34
32
/**
35
33
* 顶栏按钮
@@ -50,8 +48,10 @@ export function initTopbar(pluginInstance: SiyuanBlog) {
50
48
topBarElement . addEventListener ( "click" , async ( ) => {
51
49
const sharePage =
52
50
"/plugins/siyuan-blog/#/share?id=" + PageUtil . getPageId ( ) + "&origin=" + getAvailableOrigin ( ) + "&isSsr=false"
53
- showPopView ( pluginInstance , topBarElement , sharePage )
54
- adjustIframeHeight ( popContentIframeId )
51
+ const popView = showPopView ( pluginInstance , topBarElement , sharePage , {
52
+ showLoading : true ,
53
+ } )
54
+ pluginInstance . popView = popView
55
55
} )
56
56
57
57
// topBarElement.addEventListener("click", async () => {
@@ -139,8 +139,14 @@ const showPage = (pluginInstance: SiyuanBlog, pageUrl: string, title?: string) =
139
139
* @param pluginInstance 插件实例对象
140
140
* @param boxElement 被点击的 box 元素
141
141
* @param pageUrl 当前页面的 URL
142
+ * @param options
142
143
*/
143
- const showPopView = ( pluginInstance : SiyuanBlog , boxElement : HTMLElement , pageUrl : string ) => {
144
+ const showPopView = (
145
+ pluginInstance : SiyuanBlog ,
146
+ boxElement : HTMLElement ,
147
+ pageUrl : string ,
148
+ options : { showLoading ?: boolean ; cancelLoading ?: any } = { }
149
+ ) => {
144
150
const popContentId = "pop-content"
145
151
let popContent = document . getElementById ( popContentId )
146
152
@@ -170,8 +176,28 @@ const showPopView = (pluginInstance: SiyuanBlog, boxElement: HTMLElement, pageUr
170
176
popContent . style . opacity = "0"
171
177
popContent . style . transition = "opacity 0.3s ease-in-out"
172
178
179
+ // 添加loading效果
180
+ if ( options . showLoading ) {
181
+ const loadingElement = document . createElement ( "div" )
182
+ loadingElement . className = "loading-spinner"
183
+ for ( let i = 0 ; i < 4 ; i ++ ) {
184
+ const divElement = document . createElement ( "div" )
185
+ loadingElement . appendChild ( divElement )
186
+ }
187
+ popContent . appendChild ( loadingElement )
188
+
189
+ // 定义cancelLoading函数,用于取消loading
190
+ const cancelLoading = ( ) => {
191
+ popContent ?. removeChild ( loadingElement )
192
+ }
193
+
194
+ // 在option中添加cancelLoading函数
195
+ options . cancelLoading = cancelLoading
196
+ }
197
+
173
198
// 填充内容
174
- popContent . innerHTML = contentElement ( pageUrl ) . innerHTML
199
+ const content = contentElement ( pageUrl )
200
+ popContent . appendChild ( content )
175
201
176
202
document . body . appendChild ( popContent )
177
203
@@ -204,4 +230,6 @@ const showPopView = (pluginInstance: SiyuanBlog, boxElement: HTMLElement, pageUr
204
230
}
205
231
} , 300 ) // 等待 300ms,即过渡时间,然后再删除浮动框
206
232
}
233
+
234
+ return options
207
235
}
0 commit comments