浏览代码

fixed goto search result

Rodja Trappe 1 年之前
父节点
当前提交
877188224b
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      website/search.py

+ 12 - 2
website/search.py

@@ -53,7 +53,17 @@ class Search:
         with self.results:
             for result in await ui.run_javascript(f'return window.fuse.search("{e.value}").slice(0, 50)'):
                 href: str = result['item']['url']
-                target = 'blank' if href.startswith('http') else ''
-                with ui.element('q-item').props(f'clickable href={href} target={target}'):
+                with ui.element('q-item').props(f'clickable').on('click', lambda href=href: self.clicked(href)):
                     with ui.element('q-item-section'):
                         ui.label(result['item']['title'])
+
+    async def clicked(self, url: str) -> None:
+        await ui.run_javascript(f'''
+            const url = "{url}"
+            if (url.startsWith("http"))
+                window.open(url, "_blank");
+            else
+                window.location.href = url;
+      ''', respond=False)
+        self.dialog.close()
+        print(url, flush=True)