lcap-frontend-library 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +271 -0
  2. package/bin/lcap-frontend-library.mjs +3 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +27 -0
  5. package/dist/init.d.ts +6 -0
  6. package/dist/init.js +79 -0
  7. package/dist/sync.d.ts +4 -0
  8. package/dist/sync.js +70 -0
  9. package/dist/utils.d.ts +19 -0
  10. package/dist/utils.js +101 -0
  11. package/package.json +34 -0
  12. package/packages/lcap-frontend-library/LEARNINGS.md +11 -0
  13. package/packages/lcap-frontend-library/SKILL.md +86 -0
  14. package/packages/lcap-frontend-library/commands/migrate.check.md +287 -0
  15. package/packages/lcap-frontend-library/commands/migrate.green.md +190 -0
  16. package/packages/lcap-frontend-library/commands/migrate.plan.md +169 -0
  17. package/packages/lcap-frontend-library/commands/migrate.red.md +160 -0
  18. package/packages/lcap-frontend-library/commands/migrate.scan.md +151 -0
  19. package/packages/lcap-frontend-library/commands/migrate.spec.md +144 -0
  20. package/packages/lcap-frontend-library/commands/migrate.tasks.md +179 -0
  21. package/packages/lcap-frontend-library/commands/speckit.create.md +201 -0
  22. package/packages/lcap-frontend-library/commands/speckit.implement.md +88 -0
  23. package/packages/lcap-frontend-library/commands/speckit.plan.md +79 -0
  24. package/packages/lcap-frontend-library/commands/speckit.self-check.md +177 -0
  25. package/packages/lcap-frontend-library/commands/speckit.specify.md +91 -0
  26. package/packages/lcap-frontend-library/commands/speckit.tasks.md +61 -0
  27. package/packages/lcap-frontend-library/references/frontend-design/LICENSE.txt +177 -0
  28. package/packages/lcap-frontend-library/references/frontend-design/SKILL.md +42 -0
  29. package/packages/lcap-frontend-library/references/lcap-extension-component/SKILL.md +360 -0
  30. package/packages/lcap-frontend-library/references/lcap-extension-component/api.md +331 -0
  31. package/packages/lcap-frontend-library/references/lcap-extension-component/block.md +160 -0
  32. package/packages/lcap-frontend-library/references/lcap-extension-component/i18n.md +95 -0
  33. package/packages/lcap-frontend-library/references/lcap-extension-component/icon.md +27 -0
  34. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/container.md +728 -0
  35. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/element.md +312 -0
  36. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/expression.md +154 -0
  37. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/index.md +113 -0
  38. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/modal.md +189 -0
  39. package/packages/lcap-frontend-library/references/lcap-extension-component/ide/popover.md +171 -0
  40. package/packages/lcap-frontend-library/references/lcap-extension-component/ide.md +799 -0
  41. package/packages/lcap-frontend-library/references/lcap-extension-component/implementation-rules.md +242 -0
  42. package/packages/lcap-frontend-library/references/lcap-extension-component/index.md +27 -0
  43. package/packages/lcap-frontend-library/references/lcap-extension-component/nasl-view-component.md +895 -0
  44. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/accessibility.md +185 -0
  45. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/child.md +82 -0
  46. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/data-source.md +261 -0
  47. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/event.md +171 -0
  48. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/form.md +266 -0
  49. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/function.md +80 -0
  50. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/link.md +137 -0
  51. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/slot.md +128 -0
  52. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-ant-design.md +1470 -0
  53. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-cloud-ui.md +259 -0
  54. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-element-plus.md +580 -0
  55. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-element-ui.md +1007 -0
  56. package/packages/lcap-frontend-library/references/lcap-extension-component/platform/theme-variables-mobile-ui.md +85 -0
  57. package/packages/lcap-frontend-library/references/lcap-extension-component/theme.md +234 -0
  58. package/packages/lcap-frontend-library/references/lcap-extension-component/workflow-guardrails.md +328 -0
  59. package/packages/lcap-frontend-library/references/nasl-logic-authoring/SKILL.md +201 -0
  60. package/packages/lcap-frontend-library/scripts/bash/create-component-files.sh +95 -0
  61. package/packages/lcap-frontend-library/scripts/bash/create-extension-project.sh +109 -0
  62. package/packages/lcap-frontend-library/scripts/bash/create-logic-files.sh +149 -0
  63. package/packages/lcap-frontend-library/scripts/bash/create-spec.sh +109 -0
  64. package/packages/lcap-frontend-library/scripts/bash/get-available-port.sh +35 -0
  65. package/packages/lcap-frontend-library/scripts/bash/list-specs.sh +19 -0
  66. package/packages/lcap-frontend-library/scripts/node/setup-extension-project.mjs +166 -0
  67. package/packages/lcap-frontend-library/templates/component-self-check.md +31 -0
  68. package/packages/lcap-frontend-library/templates/component-template.md +96 -0
  69. package/packages/lcap-frontend-library/templates/library-report-template.md +52 -0
  70. package/packages/lcap-frontend-library/templates/logic-template.md +44 -0
  71. package/packages/lcap-frontend-library/templates/migration-manifest-template.md +84 -0
  72. package/packages/lcap-frontend-library/templates/migration-plan-template.md +138 -0
  73. package/packages/lcap-frontend-library/templates/migration-report-template.md +227 -0
  74. package/packages/lcap-frontend-library/templates/migration-spec-template.md +135 -0
  75. package/packages/lcap-frontend-library/templates/migration-tasks-template.md +129 -0
  76. package/packages/lcap-frontend-library/templates/plan-template.md +299 -0
  77. package/packages/lcap-frontend-library/templates/self-check-report-template.md +148 -0
  78. package/packages/lcap-frontend-library/templates/tasks-template.md +81 -0
  79. package/packages/lcap-frontend-library/workflows/create/flow.md +199 -0
  80. package/packages/lcap-frontend-library/workflows/evolve/flow.md +249 -0
  81. package/packages/lcap-frontend-library/workflows/generate/flow.md +10 -0
  82. package/packages/lcap-frontend-library/workflows/harness/flow.md +82 -0
  83. package/packages/lcap-frontend-library/workflows/migrate/flow.md +302 -0
  84. package/packages/lcap-frontend-library/workflows/migrate/knowledge-base.md +564 -0
@@ -0,0 +1,185 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+
5
+ # 可访问性属性 <Badge type="tip" text="^3.9.0" />
6
+
7
+
8
+ 组件的[可访问属性](https://community.codewave.163.com/CommunityParent/fileIndex?filePath=20.%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91%2F10.%E9%A1%B5%E9%9D%A2%E8%AE%BE%E8%AE%A1%2F19.%E7%BB%84%E4%BB%B6%E5%8F%AF%E8%AE%BF%E9%97%AE%E5%B1%9E%E6%80%A7.md&version=3.13)是指在逻辑或表达式的可视化编辑面板中能够直接被访问和操作的组件属性。
9
+
10
+ 在设计组件的可访问属性时,需定义可访问属性的能力,主要包括以下两个方面:
11
+
12
+ - [设置组件属性状态支持同步](#设置组件属性状态支持同步);\[必要]
13
+ - [设置组件属性状态支持赋值](#设置组件属性状态支持赋值)。\[选配]
14
+
15
+ 当前该功能仅支持在 Vue框架使用。
16
+
17
+ ## 设置组件属性状态支持同步
18
+
19
+ ### 1. 功能说明
20
+
21
+ 支持将组件状态同步到定义的可访问属性,由可访问属性传递组件的状态。
22
+
23
+ 例如在事件逻辑中将数据表格的可访问属性disabled(禁用)赋值给局部变量,即通过可访问属性disabled(禁用)使局部变量获取到组件的禁用状态。
24
+
25
+
26
+
27
+ ### 2. 功能实现
28
+
29
+ 1. 在 api.ts文件中增加可读属性配置。例如“值”、“禁用”、“只读”属性。
30
+
31
+ ```typescript
32
+ export class UTabs<T, V> extends ViewComponent {
33
+ @Prop({
34
+ title: '值',
35
+ })
36
+ value: V;
37
+
38
+ @Prop({
39
+ title: '禁用',
40
+ })
41
+ disabled: nasl.core.Boolean;
42
+
43
+ @Prop({
44
+ title: '只读',
45
+ })
46
+ readonly: nasl.core.Boolean;
47
+
48
+ //...
49
+ }
50
+ ```
51
+
52
+ 1. 通过组件同步sync\:state事件来同步内部状态。
53
+
54
+ ```typescript
55
+ // sync mixin
56
+ import type { ComponentOptions, WatchOptionsWithHandler } from 'vue';
57
+
58
+ export type SyncOption = string | { [name: string]: string | (() => any) };
59
+ export interface SyncOptionItem {
60
+ name: string;
61
+ stateKey: string;
62
+ computed?: () => any;
63
+ }
64
+
65
+ function createWatch(name: string): WatchOptionsWithHandler<any> {
66
+ return {
67
+ handler(val, oldVal) {
68
+ if (val === oldVal) {
69
+ return;
70
+ }
71
+
72
+ this.$emit('sync:state', name, val);
73
+ },
74
+ immediate: true,
75
+ };
76
+ }
77
+
78
+ function normalizeSyncOptions(options: SyncOption[]) {
79
+ const syncMap: { [key: string]: SyncOptionItem } = {};
80
+ const computedMap: { [key: string]: () => any } = {};
81
+ const watchMap: Record<string, WatchOptionsWithHandler<any>> = {};
82
+
83
+ options.forEach((option) => {
84
+ if (typeof option === 'string') {
85
+ syncMap[option] = {
86
+ name: option,
87
+ stateKey: option,
88
+ };
89
+
90
+ watchMap[option] = createWatch(option);
91
+ return;
92
+ }
93
+
94
+ Object.keys(option).forEach((name) => {
95
+ const val = option[name];
96
+
97
+ if (typeof val === 'function') {
98
+ const stateKey = [name, 'sync'].join('__');
99
+ syncMap[name] = {
100
+ name,
101
+ stateKey,
102
+ };
103
+
104
+ watchMap[stateKey] = createWatch(name);
105
+ computedMap[stateKey] = val;
106
+ return;
107
+ }
108
+
109
+ syncMap[name] = {
110
+ name,
111
+ stateKey: val,
112
+ };
113
+ watchMap[val] = createWatch(name);
114
+ });
115
+ });
116
+
117
+ return {
118
+ syncMap,
119
+ computedMap,
120
+ watchMap,
121
+ };
122
+ }
123
+
124
+ export default (...options: SyncOption[]) => {
125
+ const {
126
+ syncMap,
127
+ watchMap,
128
+ computedMap,
129
+ } = normalizeSyncOptions(options);
130
+ return {
131
+ watch: {
132
+ ...watchMap,
133
+ },
134
+ computed: {
135
+ ...computedMap,
136
+ },
137
+ } as ComponentOptions<any>;
138
+ };
139
+ ```
140
+
141
+ ```javascript
142
+ import sync from './sync';
143
+ // u-tabs.vue
144
+ export default {
145
+ mixins: [
146
+ sync({
147
+ value() {
148
+ const itemVM = this.selectedVM;
149
+ if (!itemVM) {
150
+ return this.value;
151
+ }
152
+
153
+ if (this.dataSource !== undefined) {
154
+ return this.$at(itemVM, this.valueField);
155
+ }
156
+
157
+ return itemVM.value;
158
+ },
159
+ readonly: 'readonly',
160
+ disabled: 'disabled',
161
+ }),
162
+ ],
163
+ }
164
+ ```
165
+
166
+ ## 设置组件属性状态支持赋值
167
+
168
+ ### 1. 功能说明
169
+
170
+ 支持为可访问属性赋值。
171
+
172
+ 例如在事件逻辑中将数据表格设置为禁用,即数据表格的可访问属性disabled(禁用)赋值为true。
173
+
174
+
175
+
176
+ ### 2. 功能实现
177
+
178
+ 在 api.ts文件中通过为相关属性设置`settable: true`即可开启属性可赋值。
179
+
180
+ ```typescript
181
+ @Prop({
182
+ //...
183
+ settable: true,
184
+ })
185
+ ```
@@ -0,0 +1,82 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+
5
+ # 父组件和子组件
6
+
7
+ ## 1. 功能说明
8
+
9
+ 子组件在 IDE 中不会显示在右侧组件面板上,只能通过父组件 **+** 按钮添加。
10
+
11
+ 以 Tabs 选项卡组件为例:通过选项卡的 ***+*** -> **添加子选项** 可为父组件选项卡添加子组件标签页。
12
+
13
+
14
+
15
+
16
+
17
+ ## 2. 功能实现
18
+
19
+ ### 2.1 父组件插槽配置snippets
20
+
21
+ 在 api.ts 文件中定义组件。
22
+
23
+ - 父组件与子组件需要写在一个api.ts文件内,先写父组件,后写子组件。
24
+ - 子组件示例(snippets.code)书写规范可参考[区块示例说明](../block.md)template写法。
25
+
26
+
27
+ ```typescript
28
+ // api.ts
29
+
30
+ @Component({
31
+ title: '选项卡',
32
+ description: '选项卡切换组件,常用于平级区域大块内容的收纳和展现。',
33
+ })
34
+ export class UTabs extends ViewComponent {
35
+ // ...
36
+ constructor(options?: Partial<TabsOptions>) { super(); }
37
+ }
38
+
39
+ export class UTabsOptions extends ViewComponentOptions {
40
+ // ...
41
+
42
+ @Slot({
43
+ title: '默认',
44
+ description: '插入`<u-tab>`子组件。',
45
+ emptyBackground: 'add-sub', // 未添加子组件时背景显示配置
46
+ snippets: [ // 配置插入代码示例, 插入代码规则与区块示例一致
47
+ {
48
+ title: '子选项',
49
+ code: '<u-tab><template #title><u-text text="标签页"></u-text></template>内容</u-tab>',
50
+ },
51
+ ],
52
+ })
53
+ slotDefault: () => Array<UTab>;
54
+ }
55
+
56
+ @Component({
57
+ title: '子选项',
58
+ description: '子选项',
59
+ })
60
+ export class UTab extends ViewComponent {
61
+ // ...
62
+ constructor(options?: Partial<UTabOptions>) { super(); }
63
+ }
64
+
65
+ export class UTabOptions extends ViewComponentOptions {
66
+ // ...
67
+ }
68
+ ```
69
+
70
+ ### 2.2 页面编辑器适配
71
+
72
+ 在 api.ts 文件中配置 ideusage 将组件接入设计器。
73
+
74
+ ```typescript
75
+ @ExtensionComponent({
76
+ ideusage: {
77
+ idetype: 'container', // 父组件需要支持插槽
78
+ structured: true, // 设置为 true 才会出现 ”+“ 按钮
79
+ childAccept: "target.tag === 'u-tab'", // 限制子组件为 u-tab
80
+ }
81
+ })
82
+ ```
@@ -0,0 +1,261 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+
5
+ <script setup>
6
+ import { VTCodeGroup, VTCodeGroupTab } from '../../../.vitepress/components'
7
+ </script>
8
+
9
+ # 数据源
10
+
11
+ ## 1. 功能说明
12
+
13
+ 平台数据属性统一为dataSource属性,可以直接绑定后端逻辑,获取远程数据。
14
+
15
+ 以下以选择器组件为例:
16
+
17
+
18
+
19
+ ## 2. 功能实现
20
+
21
+ ### 2.1 增加数据源相关属性
22
+
23
+ 向 api.ts 文件中写入数据源相关属性。
24
+
25
+ 以下以选择器组件为例:包含“数据源”、“数据类型”、“文本字段”、“值字段”属性以及重新加载数据源的组件逻辑(reload)。
26
+
27
+ ```typescript
28
+ @Component({
29
+ title: '选择器',
30
+ description: '选择器',
31
+ })
32
+ export class SelectOptions<T, V> extends ViewComponent {
33
+ constructor(options?: Partial<SelectOptions<T, V>>) {
34
+ super();
35
+ }
36
+
37
+ @Method({
38
+ title: '重新加载数据',
39
+ description: '重新加载数据'
40
+ })
41
+ reload(): void {} // 需要提供重新加载数据源的方法
42
+ }
43
+ // api.ts
44
+ export class SelectOptions<T, V> extends ViewComponentOptions {
45
+ @Prop({
46
+ group: '数据属性',
47
+ title: '数据源',
48
+ description: '展示数据的输入源,可设置为数据集对象或者返回数据集的逻辑',
49
+ docDescription: '列表展示的数据。数据源可以绑定变量或者逻辑。变量或逻辑的返回值可以是数组,也可以是对象。对象格式为{list:[], total:10}',
50
+ })
51
+ dataSource: { list: nasl.collection.List<T>; total: nasl.core.Integer } | nasl.collection.List<T>;
52
+
53
+ @Prop({
54
+ group: '数据属性',
55
+ title: '数据类型',
56
+ description: '数据源返回的数据结构的类型,自动识别类型进行展示说明',
57
+ docDescription: '列表每一行的数据类型。该属性为展示属性,由数据源推倒得到,无需填写。',
58
+ })
59
+ dataSchema: T;
60
+
61
+
62
+ @Prop({
63
+ group: '数据属性',
64
+ title: '文本字段',
65
+ description: '选项文本的字段名',
66
+ setter: {
67
+ concept: "PropertySelectSetter"
68
+ }
69
+ })
70
+ textField: (item: T) => any;
71
+
72
+
73
+ @Prop({
74
+ group: '数据属性',
75
+ title: '值字段',
76
+ description: '选项文本的字段名',
77
+ setter: {
78
+ concept: "PropertySelectSetter"
79
+ }
80
+ })
81
+ valueField: (item: T) => V = ((item: T) => item.value) as any;;
82
+ }
83
+ ```
84
+
85
+ ### 2.2 组件内部加载数据和渲染
86
+
87
+
88
+ <VTCodeGroup>
89
+ <VTCodeGroupTab label="Vue2">
90
+
91
+ 参考[Element UI Select](https://element.eleme.cn/#/zh-CN/component/select)支持数据源示例。
92
+
93
+ ```typescript
94
+ <template>
95
+ <el-select v-bind="$attrs" v-on="$listeners" :loading="loading">
96
+ <template v-if="!!dataSource">
97
+ <el-option
98
+ v-for="item in list"
99
+ :key="lodashGet(item, valueField)"
100
+ :label="lodashGet(item, textField)"
101
+ :value="lodashGet(item, valueField)">
102
+ </el-option>
103
+ </template>
104
+ <slot v-else></slot>
105
+ </el-select>
106
+ </template>
107
+ <script>
108
+ import lodashGet from 'lodash/get';
109
+
110
+ export default {
111
+ props: {
112
+ dataSource: {
113
+ type: [Array, Object, Function]
114
+ },
115
+ textField: {
116
+ type: String,
117
+ default: 'text',
118
+ },
119
+ valueField: {
120
+ type: String,
121
+ default: 'value',
122
+ },
123
+ },
124
+ data() {
125
+ return {
126
+ list: [],
127
+ loading: false,
128
+ };
129
+ },
130
+ watch: {
131
+ dataSource: {
132
+ handler() {
133
+ this.$nextTick(() => {
134
+ this.loadDataSource();
135
+ });
136
+ },
137
+ immediate: true
138
+ },
139
+ },
140
+ methods: {
141
+ lodashGet,
142
+ normalizeData(data) {
143
+ if (Array.isArray(data)) {
144
+ return data;
145
+ }
146
+
147
+ if (typeof data === 'object' && Array.isArray(data.list)) {
148
+ return data.list;
149
+ }
150
+
151
+ return [];
152
+ },
153
+
154
+ async loadDataSource() {
155
+ if (typeof this.dataSource === 'function') {
156
+ this.loading = true;
157
+ const data = await this.dataSource({});
158
+ this.list = this.normalizeData(data);
159
+ this.loading = false;
160
+ } else {
161
+ this.list = this.normalizeData(this.dataSource);
162
+ }
163
+ },
164
+ async reload() {
165
+ return this.loadDataSource();
166
+ },
167
+ },
168
+ }
169
+ </script>
170
+ ```
171
+
172
+ </VTCodeGroupTab>
173
+ <VTCodeGroupTab label="React">
174
+
175
+ 参考[Ant Design Select](https://ant-design.antgroup.com/components/select-cn)支持数据源示例。
176
+
177
+ ```typescript
178
+ import React, { useState, useEffect, useImperativeHandle, useMemo } from 'react';
179
+ import { Select } from 'antd';
180
+ import lodashGet from 'lodash/get';
181
+
182
+ const normalizeData = (data) => {
183
+ if (Array.isArray(data)) {
184
+ return data;
185
+ }
186
+
187
+ if (typeof data === 'object' && Array.isArray(data.list)) {
188
+ return data.list;
189
+ }
190
+
191
+ return [];
192
+ }
193
+
194
+ const useDataSource = (dataSource) => {
195
+ const [data, setData] = useState([]);
196
+ const [loading, setLoading] = useState(false);
197
+
198
+ const loadDataSouce = useCallback(async () => {
199
+ if (typeof dataSource !== 'function') {
200
+ return;
201
+ }
202
+
203
+ setLoading(true);
204
+ const result = await this.dataSource({});
205
+ setData(normalizeData(result));
206
+ setLoading(false);
207
+ }, [dataSource]);
208
+
209
+ useEffect(() => {
210
+ loadDataSouce();
211
+ }, [loadDataSouce]);
212
+
213
+ return {
214
+ reload: loadDataSouce,
215
+ data: useMemo(() => {
216
+ if (typeof dataSource !== 'function') {
217
+ return normalizeData(dataSource);
218
+ }
219
+
220
+ return data;
221
+ }, [data, dataSource]),
222
+ loading,
223
+ }
224
+ }
225
+
226
+ export const Select = React.forwardRef((props, ref) => {
227
+ const {
228
+ dataSource,
229
+ textField = 'text',
230
+ valueField = 'value',
231
+ ...rest
232
+ } = props;
233
+
234
+ const { data, loading, reload } = useDataSource(dataSource);
235
+
236
+ const options = useMemo(() => {
237
+ return data.map((item) => {
238
+ return {
239
+ label: lodashGet(item, textField),
240
+ value: lodashGet(item, valueField),
241
+ };
242
+ });
243
+ }, [data, textField, valueField]);
244
+
245
+ useImperativeHandle(ref, () => {
246
+ return {
247
+ reload,
248
+ };
249
+ }, [reload]);
250
+
251
+ return (
252
+ <Select
253
+ {...rest}
254
+ options={options}
255
+ loading={loading}
256
+ />
257
+ );
258
+ });
259
+ ```
260
+ </VTCodeGroupTab>
261
+ </VTCodeGroup>
@@ -0,0 +1,171 @@
1
+ ---
2
+ outline: deep
3
+ ---
4
+ <script setup>
5
+ import { VTCodeGroup, VTCodeGroupTab } from '../../../.vitepress/components'
6
+ </script>
7
+
8
+
9
+ # 事件转换
10
+
11
+ ## 1. 功能说明
12
+
13
+ 平台事件触发仅支持一个 event 对象,需要将事件的参数合并到 event 对象下。
14
+
15
+
16
+
17
+ ## 2. 注意事项
18
+
19
+ 使用`@Event`来标注支持的事件,需要注意以下几点:
20
+
21
+ 1. 事件名需要以on 开头的小驼峰,例如click 需要写为onClick,row-click需要写为onRowClick;
22
+ 2. 事件名须为合法属性名,**禁止**使用引号字符串键或含 `:` 的键名(如 `'onUpdate:modelValue'`);与 Vue `update:modelValue` 对应时须写为 `onUpdateModelValue`;
23
+ 3. 事件参数仅允许有一个参数event,多个参数的情况需要转为一个匿名结构对象, 例如onSelect(value, item)需要转换为 onSelect({ value, item });
24
+ 4. 返回参数统一为void,匿名数据结构属性也必须使用 nasl 支持的类型;
25
+
26
+ ## 3. 功能实现
27
+
28
+ <VTCodeGroup>
29
+ <VTCodeGroupTab label="Vue2">
30
+
31
+ 参考[Element UI 导航菜单](https://element.eleme.cn/#/zh-CN/component/menu#menu-events)组件的select,open,close事件示例。
32
+
33
+ | 事件名称 | 说明 | 回调参数 |
34
+ | :----- | :------- | :-------------------- |
35
+ | select | 菜单激活回调 | index: 选中菜单项的 index, |
36
+ | open | 菜单项展开的回调 | index: 打开的菜单项的 index, |
37
+ | close | 菜单项收起的回调 | index: 收起的菜单项的 index, |
38
+
39
+ 1. 定义触发事件的处理方法。
40
+
41
+ ```vue
42
+ <template>
43
+ <el-menu @select="handleSelect" @open="handleOpen" @close="handleClose">
44
+ <!-- ... -->
45
+ </el-menu>
46
+ </template>
47
+ <script>
48
+ export default {
49
+ // ...
50
+ methods: {
51
+ handleSelect(index, indexPath) {
52
+ this.$emit('select', {
53
+ index,
54
+ indexPath,
55
+ });
56
+ },
57
+ handleOpen(index, indexPath) {
58
+ this.$emit('open', {
59
+ index,
60
+ indexPath,
61
+ });
62
+ }
63
+ handleClose(index, indexPath) {
64
+ this.$emit('close', {
65
+ index,
66
+ indexPath,
67
+ });
68
+ }
69
+ }
70
+ }
71
+ </script>
72
+ ```
73
+
74
+ 2. 向 api.ts 文件中写入相关事件。
75
+
76
+ ```typescript
77
+ // api.ts
78
+ @Event({
79
+ title: '菜单激活时',
80
+ description: '菜单激活回调',
81
+ })
82
+ onSelect: (event: {
83
+ index: nasl.core.String;
84
+ indexPath: nasl.core.String;
85
+ }) => void;
86
+
87
+ @Event({
88
+ title: '子菜单展开时',
89
+ description: '子菜单展开的回调',
90
+ })
91
+ onOpen: (event: {
92
+ index: nasl.core.String;
93
+ indexPath: nasl.core.String;
94
+ }) => void;
95
+
96
+ @Event({
97
+ title: '子菜单收起时',
98
+ description: '子菜单收起的回调',
99
+ })
100
+ onClose: (event: {
101
+ index: nasl.core.String;
102
+ indexPath: nasl.core.String;
103
+ }) => void;
104
+ ```
105
+
106
+ </VTCodeGroupTab>
107
+ <VTCodeGroupTab label="React">
108
+
109
+ 参考[Ant Design 分页](https://ant-design.antgroup.com/components/pagination-cn#api)组件的onChange,onShowSizeChange事件示例。
110
+
111
+ | 事件名称 | 说明 | 回调参数 |
112
+ | :--------------- | :----------- | :-------------- |
113
+ | onChange | 页码或每页条数改变的回调 | page:改变后的页码 |
114
+ | onShowSizeChange | 每页条数改变的回调 | current:当前状态或对象 |
115
+
116
+ 1. 定义触发事件的处理方法。
117
+
118
+ ```typescript
119
+ import React from 'react';
120
+ import { Pagination } from 'antd';
121
+
122
+ export const CwPagination = ({ onChange = () => {}, onShowSizeChange = () => {}, ...rest }) => {
123
+ const handleChange = (page, pageSize) => {
124
+ onChange({
125
+ page,
126
+ pageSize,
127
+ });
128
+ }
129
+
130
+ const handleShowSizeChange = (current, size) => {
131
+ onChange({
132
+ current,
133
+ size,
134
+ });
135
+ }
136
+
137
+ return (
138
+ <Pagination
139
+ {...rest}
140
+ onChange={handleChange}
141
+ onShowSizeChange={handleShowSizeChange}
142
+ />
143
+ )
144
+ }
145
+ ```
146
+
147
+ 1. 向 api.ts 文件中写入相关事件。
148
+
149
+ ```typescript
150
+ // api.ts
151
+ @Event({
152
+ title: '切换分页后',
153
+ description: '切换分页后',
154
+ })
155
+ onChange: (event: {
156
+ page: nasl.core.Integer;
157
+ pageSize: nasl.core.Integer;
158
+ }) => void;
159
+
160
+ @Event({
161
+ title: '分页大小改变时',
162
+ description: 'pageSize变化的回调',
163
+ })
164
+ onShowSizeChange: (event: {
165
+ current: nasl.core.Integer;
166
+ size: nasl.core.Integer;
167
+ }) => void;
168
+ ```
169
+
170
+ </VTCodeGroupTab>
171
+ </VTCodeGroup>