mirror of
https://github.com/siyuan-note/plugin-sample-vite-svelte.git
synced 2025-06-08 02:46:02 +00:00
onDestroy
This commit is contained in:
parent
aba6dfd544
commit
82928ab218
4 changed files with 54 additions and 42 deletions
|
@ -3,26 +3,20 @@
|
||||||
* https://github.com/frostime/sy-plugin-template-vite
|
* https://github.com/frostime/sy-plugin-template-vite
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import { version } from "./api";
|
import { version } from "./api";
|
||||||
import { showMessage } from "siyuan";
|
import { showMessage } from "siyuan";
|
||||||
export let name: string;
|
export let name: string;
|
||||||
|
export let i18n: any;
|
||||||
|
|
||||||
let time;
|
let time;
|
||||||
let ver;
|
let ver;
|
||||||
|
|
||||||
onMount(async () => {
|
let intv1 = setInterval(async () => {
|
||||||
time = new Date();
|
|
||||||
ver = await version();
|
|
||||||
});
|
|
||||||
|
|
||||||
$: time_str = new Date(time).toLocaleTimeString();
|
|
||||||
|
|
||||||
setInterval(async () => {
|
|
||||||
time = new Date();
|
time = new Date();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
setInterval(async () => {
|
let intv2 = setInterval(async () => {
|
||||||
ver = await version();
|
ver = await version();
|
||||||
showMessage(
|
showMessage(
|
||||||
`Hello ${name} v${ver}`,
|
`Hello ${name} v${ver}`,
|
||||||
|
@ -30,50 +24,61 @@
|
||||||
);
|
);
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
time = new Date();
|
||||||
|
ver = await version();
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You must call this function when the component is destroyed.
|
||||||
|
*/
|
||||||
|
onDestroy(() => {
|
||||||
|
showMessage("Hello panel closed");
|
||||||
|
clearInterval(intv1);
|
||||||
|
clearInterval(intv2);
|
||||||
|
});
|
||||||
|
|
||||||
|
$: time_str = new Date(time).toLocaleTimeString();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="hello">
|
<div id="hello">
|
||||||
<div class="row">
|
<div class="fn__flex">
|
||||||
<div class="col left">
|
<div class="fn__flex-1">
|
||||||
<h2>Hello {name} v{ver}</h2>
|
<h2>Hello {name} v{ver}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="col right">
|
<div class="fn__flex-1 b3-label__text __text-alignright">
|
||||||
{time_str}
|
{time_str}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<p>
|
<div class="fn__flex-column">
|
||||||
使用这个模板之前,请阅读<a
|
<div class="fn__flex-1">
|
||||||
href="https://github.com/siyuan-note/plugin-sample">官方教程</a
|
<ul class="b3-list b3-list--background">
|
||||||
>, 确保自己已经理解了插件的基本开发流程。
|
<li class="b3-list-item">
|
||||||
</p>
|
<span class="b3-list-item__text">
|
||||||
|
{@html i18n.makesure}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="fn__space-column"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>
|
|
||||||
Before using this template, please read the <a
|
|
||||||
href="https://github.com/siyuan-note/plugin-sample">offical sample</a
|
|
||||||
>, make sure that you've known about the pipeline for plugin developing.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
#hello {
|
#hello {
|
||||||
margin: 1rem;
|
margin: 20px;
|
||||||
text-align: left;
|
|
||||||
}
|
}
|
||||||
.row {
|
.__text-alignright {
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
|
|
||||||
.col {
|
|
||||||
flex: 1;
|
|
||||||
}
|
|
||||||
.left {
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
.right {
|
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
.fn__space-column {
|
||||||
|
height: 8px;
|
||||||
|
display: inline-block;
|
||||||
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "SiYuan"
|
"name": "SiYuan",
|
||||||
|
"hello": {
|
||||||
|
"makesure": "Before using this template, please read the <a href=\"https://github.com/siyuan-note/plugin-sample\">offical sample</a>, make sure that you've known about the pipeline for plugin developing."
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,3 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "思源"
|
"name": "思源",
|
||||||
|
"hello": {
|
||||||
|
"makesure": "使用这个模板之前,请阅读<a href=\"https://github.com/siyuan-note/plugin-sample\">官方教程</a>, 确保自己已经理解了插件的基本开发流程。"
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ export default class SamplePlugin extends Plugin {
|
||||||
{
|
{
|
||||||
icon: "iconEmoji",
|
icon: "iconEmoji",
|
||||||
"title": "Hello SiYuan",
|
"title": "Hello SiYuan",
|
||||||
"callback": () => this.openHelloDialog()
|
"callback": () => this.openHelloInDialog()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ export default class SamplePlugin extends Plugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private openHelloDialog() {
|
private openHelloInDialog() {
|
||||||
this.counter.hello++;
|
this.counter.hello++;
|
||||||
let dialog = new Dialog({
|
let dialog = new Dialog({
|
||||||
title: "Hello World",
|
title: "Hello World",
|
||||||
|
@ -55,6 +55,7 @@ export default class SamplePlugin extends Plugin {
|
||||||
target: dialog.element.querySelector("#helloPanel"),
|
target: dialog.element.querySelector("#helloPanel"),
|
||||||
props: {
|
props: {
|
||||||
name: `[${this.counter.hello}]${this.i18n.name}`,
|
name: `[${this.counter.hello}]${this.i18n.name}`,
|
||||||
|
i18n: this.i18n.hello
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue