Use hello both in tab and dialog

This commit is contained in:
frostime 2023-05-20 16:01:39 +08:00
parent 5cf4d6efd1
commit de42dc1b55
2 changed files with 11 additions and 21 deletions

View file

@ -8,7 +8,6 @@
import { showMessage } from "siyuan"; import { showMessage } from "siyuan";
export let name: string; export let name: string;
export let i18n: any; export let i18n: any;
export let opendCount: number;
let time; let time;
let ver; let ver;
@ -17,14 +16,6 @@
time = new Date(); time = new Date();
}, 1000); }, 1000);
let intv2 = setInterval(async () => {
ver = await version();
showMessage(
`[${opendCount}] Hello ${name} v${ver}`,
5000
);
}, 10000);
onMount(async () => { onMount(async () => {
time = new Date(); time = new Date();
ver = await version(); ver = await version();
@ -36,7 +27,6 @@
onDestroy(() => { onDestroy(() => {
showMessage("Hello panel closed"); showMessage("Hello panel closed");
clearInterval(intv1); clearInterval(intv1);
clearInterval(intv2);
}); });
$: time_str = new Date(time).toLocaleTimeString(); $: time_str = new Date(time).toLocaleTimeString();
@ -46,7 +36,7 @@
<div id="hello"> <div id="hello">
<div class="fn__flex"> <div class="fn__flex">
<div class="fn__flex-1"> <div class="fn__flex-1">
<h2>[{opendCount}] Hello {name} v{ver}</h2> <h2>Hello {name} v{ver}</h2>
</div> </div>
<div class="fn__flex-1 b3-label__text __text-right"> <div class="fn__flex-1 b3-label__text __text-right">
{time_str} {time_str}

View file

@ -33,21 +33,22 @@ export default class SamplePlugin extends Plugin {
} }
}); });
let div = document.createElement("div");
new HelloExample({
target: div,
props: {
name: this.i18n.name,
i18n: this.i18n.hello
}
});
this.customTab = this.addTab({ this.customTab = this.addTab({
type: TAB_TYPE, type: TAB_TYPE,
init() { init() {
this.tab = new HelloExample({ this.element.appendChild(div);
target: this.element, console.log(this.element);
props: {
name: this.i18n.name,
opendCount: this.counter.hello,
i18n: this.i18n.hello
}
});
}, },
destroy() { destroy() {
console.log("destroy tab:", TAB_TYPE); console.log("destroy tab:", TAB_TYPE);
this.tab.$destroy(); //Call svelte component destroy
} }
}); });
@ -192,7 +193,6 @@ export default class SamplePlugin extends Plugin {
target: dialog.element.querySelector("#helloPanel"), target: dialog.element.querySelector("#helloPanel"),
props: { props: {
name: this.i18n.name, name: this.i18n.name,
opendCount: this.counter.hello,
i18n: this.i18n.hello i18n: this.i18n.hello
} }
}); });