Skip to content

Commit ad0ea31

Browse files
committed
Update docs
1 parent 5f36e80 commit ad0ea31

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed

zh/guide/04-plugins.md

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,244 @@ appStore.removeCustomActions("core_state", 'first-action');
347347
remove()
348348
```
349349

350+
## 添加 UI
351+
352+
在最新的 GUI 版本中,暴露了全局变量 Vue,你可以使用完整的 Vue 框架能力开发自定义的插件 UI。
353+
354+
使用步骤:
355+
356+
- 创建自定义组件
357+
358+
- 创建模态框并绑定自定义组件
359+
360+
- 打开弹窗
361+
362+
### 创建自定义组件
363+
364+
> 使用教程:[defineComponent()](https://cn.vuejs.org/api/general.html#definecomponent)
365+
366+
代码示例:
367+
368+
```js
369+
const { ref, h, defineComponent } = Vue;
370+
371+
const component = defineComponent({
372+
template: /* html */ `
373+
<div>
374+
<Card title="图标">
375+
<div class="flex" style="flex-wrap: wrap">
376+
<Icon v-for="icon in icons" :key="icon" :icon="icon" :size="24" />
377+
</div>
378+
</Card>
379+
380+
<Card title="按钮" class="mt-8">
381+
<Button type="primary">主要按钮</Button>
382+
<Button>普通按钮</Button>
383+
<Button type="link">链接按钮</Button>
384+
<Button type="text">文本按钮</Button>
385+
<Button icon="refresh">图标按钮</Button>
386+
<Button size="small">小按钮</Button>
387+
<Button size="large">大按钮</Button>
388+
</Card>
389+
390+
<Card title="标签" class="mt-8">
391+
<Tag>default</Tag>
392+
<Tag color="cyan">cyan</Tag>
393+
<Tag color="green">green</Tag>
394+
<Tag color="red">red</Tag>
395+
<Tag color="primary">primary</Tag>
396+
<Tag size="small">小标签</Tag>
397+
</Card>
398+
399+
<Card title="其他组件" class="mt-8">
400+
<div class="flex items-center">
401+
多选:
402+
<CheckBox v-model="val1" :options="options" />
403+
单选:
404+
<Radio v-model="val2" :options="options" />
405+
<Dropdown :trigger="['hover']">
406+
<Button type="text">下拉菜单</Button>
407+
<template #overlay>
408+
<div><Button type="link">菜单1</Button></div>
409+
<div><Button type="link">菜单2</Button></div>
410+
<div><Button type="link">菜单3</Button></div>
411+
</template>
412+
</Dropdown>
413+
</div>
414+
<div class="flex items-center">
415+
下拉:
416+
<Select v-model="val7" :options="options" />
417+
开关:
418+
<Switch v-model="val8" />
419+
<Switch v-model="val9" border="square">另一种形态</Switch>
420+
</div>
421+
</Card>
422+
423+
<Card title="输入" class="mt-8">
424+
<div class="flex items-center">
425+
输入框:
426+
<Input v-model="val3" placeholder="输入框" />
427+
输入列表:
428+
<InputList v-model="val4" placeholder="请输入" />
429+
</div>
430+
长文本输入:
431+
<CodeViewer
432+
v-model="val5"
433+
lang="javascript"
434+
editable
435+
placeholder="代码查看器,可通过editable属性设置为可编辑"
436+
/>
437+
键值对输入:
438+
<KeyValueEditor v-model="val6" />
439+
</Card>
440+
441+
<Card title="表格" class="mt-8">
442+
<Table :data-source="dataSource" :columns="columns" />
443+
</Card>
444+
</div>
445+
`,
446+
setup() {
447+
return {
448+
icons: [
449+
"link",
450+
"loading",
451+
"selected",
452+
"disabled",
453+
"pin",
454+
"pinFill",
455+
"minimize",
456+
"maximize",
457+
"maximize2",
458+
"close",
459+
"arrowLeft",
460+
"arrowDown",
461+
"arrowRight",
462+
"speedTest",
463+
"empty",
464+
"github",
465+
"forbidden",
466+
"telegram",
467+
"expand",
468+
"collapse",
469+
"refresh",
470+
"error",
471+
"reset",
472+
"folder",
473+
"restartApp",
474+
"log",
475+
"settings",
476+
"stop",
477+
"restart",
478+
"messageSuccess",
479+
"messageError",
480+
"messageWarn",
481+
"messageInfo",
482+
"pause",
483+
"play",
484+
"clear",
485+
"clear2",
486+
"drag",
487+
"more",
488+
"add",
489+
"filter",
490+
"edit",
491+
"delete",
492+
"file",
493+
"code",
494+
"overview",
495+
"profiles",
496+
"subscriptions",
497+
"rulesets",
498+
"plugins",
499+
"scheduledTasks",
500+
"settings2",
501+
"grant",
502+
"preview",
503+
"rollback",
504+
],
505+
val1: ref(["1", "3"]),
506+
val2: ref("1"),
507+
val3: ref(""),
508+
val4: ref(["输入值1", "输入值2"]),
509+
val5: ref(""),
510+
val7: ref("1"),
511+
val8: ref(true),
512+
val9: ref(false),
513+
val6: ref({ plugin_name: Plugin.name, plugin_version: Plugin.version }),
514+
options: [
515+
{ label: "选项1", value: "1" },
516+
{ label: "选项2", value: "2" },
517+
{ label: "选项3", value: "3" },
518+
],
519+
columns: [
520+
{ key: "name", title: "插件名" },
521+
{ key: "version", title: "版本" },
522+
{ key: "downloads", title: "下载量" },
523+
],
524+
dataSource: [
525+
{ name: "插件1", version: "v1.0.0", downloads: "99+" },
526+
{ name: "插件2", version: "v2.0.0", downloads: "99+" },
527+
{ name: "插件3", version: "v3.0.0", downloads: "99+" },
528+
],
529+
};
530+
},
531+
});
532+
```
533+
534+
### 创建模态框并绑定自定义组件
535+
536+
方法签名:
537+
538+
```ts
539+
interface Options {
540+
title?: string;
541+
footer?: boolean;
542+
maxHeight?: string;
543+
maxWidth?: string;
544+
minWidth?: string;
545+
minHeight?: string;
546+
width?: string;
547+
height?: string;
548+
cancel?: boolean;
549+
submit?: boolean;
550+
cancelText?: string;
551+
submitText?: string;
552+
maskClosable?: boolean;
553+
onOk?: () => MaybePromise<boolean | void>;
554+
onCancel?: () => MaybePromise<boolean | void>;
555+
beforeClose?: (isOk: boolean) => MaybePromise<boolean | void>;
556+
afterClose?: (isOk: boolean) => void;
557+
}
558+
559+
function modal(options: Options): {
560+
open: () => void;
561+
close: () => void;
562+
setProps: (options: Options) => void;
563+
setComponent: (vnode: VNode) => void;
564+
destroy: () => void;
565+
};
566+
```
567+
568+
使用示例:
569+
570+
```ts
571+
const modal = Plugins.modal({
572+
title: "自定义UI使用示例",
573+
component: h(component),
574+
afterClose: () => {
575+
modal.destroy();
576+
},
577+
});
578+
```
579+
580+
最后打开模态框:
581+
582+
```js
583+
modal.open();
584+
```
585+
586+
注意事项:模态框关闭后应该 destroy,或使用全局变量(`window[Plugin.id] = window[Plugin.id] || {}`)存储模态框变量以避免重复创建 。
587+
350588
## 更多的示例
351589

352590
```javascript

0 commit comments

Comments
 (0)