@nocobase/plugin-flow-engine 2.1.0-alpha.9 → 2.1.0-beta.10
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.
- package/dist/ai/docs/runjs/context/block-model.md +35 -35
- package/dist/ai/docs/runjs/context/collection-field.md +51 -53
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +30 -40
- package/dist/ai/docs/runjs/context/data-source.md +44 -52
- package/dist/ai/docs/runjs/context/element.md +38 -44
- package/dist/ai/docs/runjs/context/exit-all.md +35 -37
- package/dist/ai/docs/runjs/context/exit.md +35 -38
- package/dist/ai/docs/runjs/context/filter-manager.md +30 -36
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +21 -22
- package/dist/ai/docs/runjs/context/get-value.md +19 -20
- package/dist/ai/docs/runjs/context/get-var.md +55 -61
- package/dist/ai/docs/runjs/context/i18n.md +14 -17
- package/dist/ai/docs/runjs/context/import-async.md +45 -333
- package/dist/ai/docs/runjs/context/init-resource.md +20 -20
- package/dist/ai/docs/runjs/context/libs.md +31 -31
- package/dist/ai/docs/runjs/context/location.md +31 -34
- package/dist/ai/docs/runjs/context/logger.md +40 -41
- package/dist/ai/docs/runjs/context/make-resource.md +26 -27
- package/dist/ai/docs/runjs/context/message.md +41 -42
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +33 -36
- package/dist/ai/docs/runjs/context/notification.md +40 -41
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +29 -30
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +32 -37
- package/dist/ai/docs/runjs/context/request.md +45 -46
- package/dist/ai/docs/runjs/context/require-async.md +25 -28
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +34 -36
- package/dist/ai/docs/runjs/context/router.md +31 -43
- package/dist/ai/docs/runjs/context/set-value.md +17 -18
- package/dist/ai/docs/runjs/context/t.md +17 -20
- package/dist/ai/docs/runjs/context/view.md +46 -49
- package/dist/ai/docs/runjs/document.md +0 -1
- package/dist/ai/docs/runjs/import-modules.md +32 -32
- package/dist/ai/docs/runjs/index.md +13 -13
- package/dist/ai/docs/runjs/jsx.md +19 -19
- package/dist/ai/docs/runjs/model/form-block-model.md +3 -1
- package/dist/ai/docs/runjs/render.md +15 -15
- package/dist/ai/docs/runjs/resource/api-resource.md +53 -53
- package/dist/ai/docs/runjs/resource/multi-record-resource.md +64 -64
- package/dist/ai/docs/runjs/resource/single-record-resource.md +55 -55
- package/dist/ai/docs/runjs/resource/sql-resource.md +57 -57
- package/dist/ai/docs/runjs/window.md +5 -5
- package/dist/externalVersion.js +10 -10
- package/dist/node_modules/ses/package.json +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/package.json +2 -2
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# ctx.openView()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Opens a configured view (drawer, dialog, embed, etc.) programmatically. Provided by FlowModelContext; used in JSBlock, table cells, event flow, etc. to open ChildPage or PopupAction views.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **Table
|
|
11
|
-
| **
|
|
12
|
-
| **Association
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock** | Button opens detail/edit dialog; pass current row `filterByTk` |
|
|
10
|
+
| **Table cell** | Button in cell opens row detail dialog |
|
|
11
|
+
| **Event flow / JSAction** | Open next view or dialog after action success |
|
|
12
|
+
| **Association field** | `ctx.runAction('openView', params)` for select/edit dialog |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.openView`
|
|
14
|
+
> Note: `ctx.openView` requires a FlowModel context; if no model exists for the uid, a PopupActionModel is created and persisted.
|
|
15
15
|
|
|
16
16
|
## Signature
|
|
17
17
|
|
|
@@ -23,46 +23,46 @@ openView(uid: string, options?: OpenViewOptions): Promise<void>
|
|
|
23
23
|
|
|
24
24
|
### uid
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
Unique id of the view model. If missing, it is created and saved. Use a stable uid (e.g. `${ctx.model.uid}-detail`) so the same popup can be reused.
|
|
27
27
|
|
|
28
|
-
###
|
|
28
|
+
### options (common fields)
|
|
29
29
|
|
|
30
30
|
| Field | Type | Description |
|
|
31
|
-
|
|
32
|
-
| `mode` | `drawer` / `dialog` / `embed` |
|
|
33
|
-
| `size` | `small` / `medium` / `large` |
|
|
34
|
-
| `title` | `string` | View title
|
|
35
|
-
| `params` | `Record<string, any>` | Arbitrary
|
|
36
|
-
| `filterByTk` | `any` | Primary key
|
|
37
|
-
| `sourceId` | `string` | Source record
|
|
38
|
-
| `dataSourceKey` | `string` | Data source
|
|
39
|
-
| `collectionName` | `string` | Collection name
|
|
40
|
-
| `associationName` | `string` | Association field name
|
|
41
|
-
| `navigation` | `boolean` |
|
|
42
|
-
| `preventClose` | `boolean` |
|
|
43
|
-
| `defineProperties` | `Record<string, PropertyOptions>` |
|
|
44
|
-
| `defineMethods` | `Record<string, Function>` |
|
|
31
|
+
|-------|------|-------------|
|
|
32
|
+
| `mode` | `drawer` / `dialog` / `embed` | How to open: drawer, dialog, embed; default `drawer` |
|
|
33
|
+
| `size` | `small` / `medium` / `large` | Dialog/drawer size; default `medium` |
|
|
34
|
+
| `title` | `string` | View title |
|
|
35
|
+
| `params` | `Record<string, any>` | Arbitrary params passed to the view |
|
|
36
|
+
| `filterByTk` | `any` | Primary key for single-record detail/edit |
|
|
37
|
+
| `sourceId` | `string` | Source record id (associations) |
|
|
38
|
+
| `dataSourceKey` | `string` | Data source |
|
|
39
|
+
| `collectionName` | `string` | Collection name |
|
|
40
|
+
| `associationName` | `string` | Association field name |
|
|
41
|
+
| `navigation` | `boolean` | Use route navigation; forced `false` when passing `defineProperties` / `defineMethods` |
|
|
42
|
+
| `preventClose` | `boolean` | Prevent close |
|
|
43
|
+
| `defineProperties` | `Record<string, PropertyOptions>` | Inject properties into view models |
|
|
44
|
+
| `defineMethods` | `Record<string, Function>` | Inject methods into view models |
|
|
45
45
|
|
|
46
46
|
## Examples
|
|
47
47
|
|
|
48
|
-
### Basic
|
|
48
|
+
### Basic: open drawer
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
51
|
const popupUid = `${ctx.model.uid}-detail`;
|
|
52
52
|
await ctx.openView(popupUid, {
|
|
53
53
|
mode: 'drawer',
|
|
54
54
|
size: 'medium',
|
|
55
|
-
title: ctx.t('
|
|
55
|
+
title: ctx.t('Detail'),
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Pass current row context
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
62
|
const primaryKey = ctx.collection?.primaryKey || 'id';
|
|
63
63
|
await ctx.openView(`${ctx.model.uid}-1`, {
|
|
64
64
|
mode: 'dialog',
|
|
65
|
-
title: ctx.t('Row
|
|
65
|
+
title: ctx.t('Row detail'),
|
|
66
66
|
params: {
|
|
67
67
|
filterByTk: ctx.record?.[primaryKey],
|
|
68
68
|
record: ctx.record,
|
|
@@ -72,7 +72,7 @@ await ctx.openView(`${ctx.model.uid}-1`, {
|
|
|
72
72
|
|
|
73
73
|
### Open via runAction
|
|
74
74
|
|
|
75
|
-
When
|
|
75
|
+
When the model has an openView action (e.g. association field, clickable field):
|
|
76
76
|
|
|
77
77
|
```ts
|
|
78
78
|
await ctx.runAction('openView', {
|
|
@@ -83,7 +83,7 @@ await ctx.runAction('openView', {
|
|
|
83
83
|
});
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### Inject custom context
|
|
87
87
|
|
|
88
88
|
```ts
|
|
89
89
|
await ctx.openView(`${ctx.model.uid}-edit`, {
|
|
@@ -98,23 +98,23 @@ await ctx.openView(`${ctx.model.uid}-edit`, {
|
|
|
98
98
|
});
|
|
99
99
|
```
|
|
100
100
|
|
|
101
|
-
##
|
|
101
|
+
## Relation to ctx.viewer, ctx.view
|
|
102
102
|
|
|
103
|
-
|
|
|
104
|
-
|
|
105
|
-
| **Open
|
|
103
|
+
| Use | Recommended |
|
|
104
|
+
|-----|-------------|
|
|
105
|
+
| **Open configured flow view** | `ctx.openView(uid, options)` |
|
|
106
106
|
| **Open custom content (no flow)** | `ctx.viewer.dialog()` / `ctx.viewer.drawer()` |
|
|
107
|
-
| **Operate
|
|
107
|
+
| **Operate current view** | `ctx.view.close()`, `ctx.view.inputArgs` |
|
|
108
108
|
|
|
109
|
-
`ctx.openView` opens a
|
|
109
|
+
`ctx.openView` opens a FlowPage (ChildPageModel) with a full flow; `ctx.viewer` opens arbitrary React content.
|
|
110
110
|
|
|
111
111
|
## Notes
|
|
112
112
|
|
|
113
|
-
-
|
|
114
|
-
- When `defineProperties`
|
|
115
|
-
- Inside
|
|
113
|
+
- Prefer uids related to `ctx.model.uid` (e.g. `${ctx.model.uid}-xxx`) to avoid conflicts between blocks.
|
|
114
|
+
- When passing `defineProperties` / `defineMethods`, `navigation` is forced to `false` so context is not lost on refresh.
|
|
115
|
+
- Inside a popup, `ctx.view` is the current view and `ctx.view.inputArgs` holds the params passed when opening.
|
|
116
116
|
|
|
117
117
|
## Related
|
|
118
118
|
|
|
119
|
-
- [ctx.view](./view.md):
|
|
120
|
-
- [ctx.model](./model.md):
|
|
119
|
+
- [ctx.view](./view.md): current view instance
|
|
120
|
+
- [ctx.model](./model.md): current model; use for stable popupUid
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.render()
|
|
2
2
|
|
|
3
|
-
Renders React
|
|
3
|
+
Renders a React element, HTML string, or DOM node into a container. Without `container`, renders into `ctx.element` and inherits the app’s ConfigProvider, theme, etc.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **JSField / JSItem / JSColumn** |
|
|
11
|
-
| **
|
|
8
|
+
|----------|-------------|
|
|
9
|
+
| **JSBlock** | Custom block content (charts, lists, cards, etc.) |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | Custom editable field or table column |
|
|
11
|
+
| **Detail block** | Custom detail field display |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.render()`
|
|
13
|
+
> Note: `ctx.render()` needs a container. If you don’t pass `container` and `ctx.element` is missing (e.g. no-UI logic), an error is thrown.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
render(
|
|
@@ -22,27 +22,27 @@ render(
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
| Parameter | Type | Description |
|
|
25
|
-
|
|
26
|
-
| `vnode` | `React.ReactElement` \| `Node` \| `DocumentFragment` \| `string` | Content to
|
|
27
|
-
| `container` | `Element` \| `DocumentFragment` (
|
|
25
|
+
|------------|------|-------------|
|
|
26
|
+
| `vnode` | `React.ReactElement` \| `Node` \| `DocumentFragment` \| `string` | Content to render |
|
|
27
|
+
| `container` | `Element` \| `DocumentFragment` (optional) | Target container; default `ctx.element` |
|
|
28
28
|
|
|
29
|
-
**
|
|
29
|
+
**Returns**:
|
|
30
30
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
31
|
+
- For **React element**: `ReactDOMClient.Root` (for later `root.render()` updates).
|
|
32
|
+
- For **HTML string** or **DOM node**: `null`.
|
|
33
33
|
|
|
34
|
-
## vnode
|
|
34
|
+
## vnode types
|
|
35
35
|
|
|
36
36
|
| Type | Behavior |
|
|
37
|
-
|
|
38
|
-
| `React.ReactElement` (JSX) | Rendered
|
|
39
|
-
| `string` |
|
|
40
|
-
| `Node` (Element, Text, etc.) |
|
|
41
|
-
| `DocumentFragment` |
|
|
37
|
+
|------|----------|
|
|
38
|
+
| `React.ReactElement` (JSX) | Rendered with React `createRoot`; full React; inherits app context |
|
|
39
|
+
| `string` | Sanitized with DOMPurify and set as container `innerHTML`; existing React root is unmounted first |
|
|
40
|
+
| `Node` (Element, Text, etc.) | Container cleared then `appendChild`; existing React root unmounted first |
|
|
41
|
+
| `DocumentFragment` | Fragment children appended to container; existing React root unmounted first |
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### React (JSX)
|
|
46
46
|
|
|
47
47
|
```tsx
|
|
48
48
|
const { Button, Card } = ctx.libs.antd;
|
|
@@ -56,26 +56,23 @@ ctx.render(
|
|
|
56
56
|
);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### HTML string
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
62
|
ctx.render('<h1>Hello World</h1>');
|
|
63
63
|
|
|
64
|
-
// Combining with ctx.t for internationalization
|
|
65
64
|
ctx.render('<div style="padding:16px">' + ctx.t('Content') + '</div>');
|
|
66
65
|
|
|
67
|
-
// Conditional rendering
|
|
68
66
|
ctx.render(hasData ? `<ul>${items.map(i => `<li>${i}</li>`).join('')}</ul>` : '<span style="color:#999">' + ctx.t('No data') + '</span>');
|
|
69
67
|
```
|
|
70
68
|
|
|
71
|
-
###
|
|
69
|
+
### DOM node
|
|
72
70
|
|
|
73
71
|
```ts
|
|
74
72
|
const div = document.createElement('div');
|
|
75
73
|
div.textContent = 'Hello World';
|
|
76
74
|
ctx.render(div);
|
|
77
75
|
|
|
78
|
-
// Render an empty container first, then hand it over to a third-party library (e.g., ECharts) for initialization
|
|
79
76
|
const container = document.createElement('div');
|
|
80
77
|
container.style.width = '100%';
|
|
81
78
|
container.style.height = '400px';
|
|
@@ -84,31 +81,29 @@ const chart = echarts.init(container);
|
|
|
84
81
|
chart.setOption({ ... });
|
|
85
82
|
```
|
|
86
83
|
|
|
87
|
-
###
|
|
84
|
+
### Custom container
|
|
88
85
|
|
|
89
86
|
```ts
|
|
90
|
-
// Render to a specific DOM element
|
|
91
87
|
const customEl = document.getElementById('my-container');
|
|
92
88
|
ctx.render(<div>Content</div>, customEl);
|
|
93
89
|
```
|
|
94
90
|
|
|
95
|
-
### Multiple
|
|
91
|
+
### Multiple calls replace content
|
|
96
92
|
|
|
97
93
|
```ts
|
|
98
|
-
// The second call will replace the existing content in the container
|
|
99
94
|
ctx.render(<div>First</div>);
|
|
100
|
-
ctx.render(<div>Second</div>); // Only "Second"
|
|
95
|
+
ctx.render(<div>Second</div>); // Only "Second" is shown
|
|
101
96
|
```
|
|
102
97
|
|
|
103
98
|
## Notes
|
|
104
99
|
|
|
105
|
-
- **
|
|
106
|
-
- **HTML
|
|
107
|
-
- **
|
|
108
|
-
- **
|
|
100
|
+
- **Each call replaces**: Content is replaced, not appended.
|
|
101
|
+
- **HTML safety**: HTML is sanitized with DOMPurify; still avoid concatenating untrusted user input.
|
|
102
|
+
- **Don’t touch ctx.element directly**: `ctx.element.innerHTML` is deprecated; use `ctx.render()`.
|
|
103
|
+
- **No container**: When `ctx.element` is `undefined` (e.g. inside a module loaded by `ctx.importAsync`), pass `container` explicitly.
|
|
109
104
|
|
|
110
105
|
## Related
|
|
111
106
|
|
|
112
|
-
- [ctx.element](./element.md)
|
|
113
|
-
- [ctx.libs](./libs.md)
|
|
114
|
-
- [ctx.importAsync()](./import-async.md)
|
|
107
|
+
- [ctx.element](./element.md): default container when `container` is not passed
|
|
108
|
+
- [ctx.libs](./libs.md): React, antd, etc. for JSX
|
|
109
|
+
- [ctx.importAsync()](./import-async.md): load external React/components then use with `ctx.render()`
|
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
# ctx.request()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sends authenticated HTTP requests from RunJS. Requests use the app’s baseURL, token, locale, role, etc., and the app’s interceptors and error handling.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use whenever RunJS needs to call a remote HTTP API: JSBlock, JSField, JSItem, JSColumn, event flow, linkage, JSAction, etc.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
request(options: RequestOptions): Promise<AxiosResponse<any>>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`RequestOptions` extends Axios
|
|
15
|
+
`RequestOptions` extends Axios `AxiosRequestConfig`:
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
type RequestOptions = AxiosRequestConfig & {
|
|
19
|
-
skipNotify?: boolean | ((error: any) => boolean); //
|
|
20
|
-
skipAuth?: boolean; //
|
|
19
|
+
skipNotify?: boolean | ((error: any) => boolean); // Skip global error toast on failure
|
|
20
|
+
skipAuth?: boolean; // Skip auth redirect (e.g. 401 → login)
|
|
21
21
|
};
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
## Common
|
|
24
|
+
## Common parameters
|
|
25
25
|
|
|
26
26
|
| Parameter | Type | Description |
|
|
27
|
-
|
|
28
|
-
| `url` | string |
|
|
29
|
-
| `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method
|
|
30
|
-
| `params` | object | Query
|
|
31
|
-
| `data` | any | Request body
|
|
32
|
-
| `headers` | object | Custom
|
|
33
|
-
| `skipNotify` | boolean \| (error) => boolean |
|
|
34
|
-
| `skipAuth` | boolean |
|
|
27
|
+
|-----------|------|-------------|
|
|
28
|
+
| `url` | string | URL. Supports resource style (e.g. `users:list`, `posts:create`) or full URL |
|
|
29
|
+
| `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method; default `'get'` |
|
|
30
|
+
| `params` | object | Query params (serialized to URL) |
|
|
31
|
+
| `data` | any | Request body for post/put/patch |
|
|
32
|
+
| `headers` | object | Custom headers |
|
|
33
|
+
| `skipNotify` | boolean \| (error) => boolean | When true or function returns true, no global error message |
|
|
34
|
+
| `skipAuth` | boolean | When true, 401 etc. do not trigger auth redirect (e.g. to login) |
|
|
35
35
|
|
|
36
|
-
## Resource
|
|
36
|
+
## Resource-style URL
|
|
37
37
|
|
|
38
|
-
NocoBase
|
|
38
|
+
NocoBase resource API supports `resource:action` shorthand:
|
|
39
39
|
|
|
40
40
|
| Format | Description | Example |
|
|
41
|
-
|
|
42
|
-
| `collection:action` | Single
|
|
43
|
-
| `collection.relation:action` |
|
|
41
|
+
|--------|-------------|---------|
|
|
42
|
+
| `collection:action` | Single-table CRUD | `users:list`, `users:get`, `users:create`, `posts:update` |
|
|
43
|
+
| `collection.relation:action` | Association (need `resourceOf` or primary key in URL) | `posts.comments:list` |
|
|
44
44
|
|
|
45
|
-
Relative
|
|
45
|
+
Relative URLs are joined with the app baseURL (usually `/api`). For cross-origin, use a full URL and ensure CORS on the target.
|
|
46
46
|
|
|
47
|
-
## Response
|
|
47
|
+
## Response
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
Returns Axios response. Common usage:
|
|
50
50
|
|
|
51
|
-
- `response.data`:
|
|
52
|
-
- List
|
|
53
|
-
- Single
|
|
51
|
+
- `response.data`: response body
|
|
52
|
+
- List APIs often have `data.data` (records) + `data.meta` (pagination)
|
|
53
|
+
- Single/create/update often have `data.data` as one record
|
|
54
54
|
|
|
55
55
|
## Examples
|
|
56
56
|
|
|
57
|
-
### List
|
|
57
|
+
### List
|
|
58
58
|
|
|
59
59
|
```javascript
|
|
60
60
|
const { data } = await ctx.request({
|
|
@@ -64,22 +64,22 @@ const { data } = await ctx.request({
|
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
const rows = Array.isArray(data?.data) ? data.data : [];
|
|
67
|
-
const meta = data?.meta;
|
|
67
|
+
const meta = data?.meta;
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
###
|
|
70
|
+
### Create
|
|
71
71
|
|
|
72
72
|
```javascript
|
|
73
73
|
const res = await ctx.request({
|
|
74
74
|
url: 'users:create',
|
|
75
75
|
method: 'post',
|
|
76
|
-
data: { nickname: 'John
|
|
76
|
+
data: { nickname: 'John', email: 'john@example.com' },
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
const newRecord = res?.data?.data;
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
###
|
|
82
|
+
### Filter and sort
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
85
|
const res = await ctx.request({
|
|
@@ -93,16 +93,15 @@ const res = await ctx.request({
|
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
### Skip
|
|
96
|
+
### Skip error notify
|
|
97
97
|
|
|
98
98
|
```javascript
|
|
99
99
|
const res = await ctx.request({
|
|
100
100
|
url: 'some:action',
|
|
101
101
|
method: 'get',
|
|
102
|
-
skipNotify: true,
|
|
102
|
+
skipNotify: true,
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
-
// Or decide whether to skip based on error type
|
|
106
105
|
const res2 = await ctx.request({
|
|
107
106
|
url: 'some:action',
|
|
108
107
|
method: 'get',
|
|
@@ -110,9 +109,9 @@ const res2 = await ctx.request({
|
|
|
110
109
|
});
|
|
111
110
|
```
|
|
112
111
|
|
|
113
|
-
### Cross-
|
|
112
|
+
### Cross-origin
|
|
114
113
|
|
|
115
|
-
|
|
114
|
+
For other domains, the target must allow CORS. For its own token, pass in headers:
|
|
116
115
|
|
|
117
116
|
```javascript
|
|
118
117
|
const res = await ctx.request({
|
|
@@ -124,12 +123,12 @@ const res2 = await ctx.request({
|
|
|
124
123
|
url: 'https://api.other.com/items',
|
|
125
124
|
method: 'get',
|
|
126
125
|
headers: {
|
|
127
|
-
Authorization: 'Bearer <
|
|
126
|
+
Authorization: 'Bearer <target-token>',
|
|
128
127
|
},
|
|
129
128
|
});
|
|
130
129
|
```
|
|
131
130
|
|
|
132
|
-
###
|
|
131
|
+
### With ctx.render
|
|
133
132
|
|
|
134
133
|
```javascript
|
|
135
134
|
const { data } = await ctx.request({
|
|
@@ -141,7 +140,7 @@ const rows = Array.isArray(data?.data) ? data.data : [];
|
|
|
141
140
|
|
|
142
141
|
ctx.render([
|
|
143
142
|
'<div style="padding:12px">',
|
|
144
|
-
'<h4>' + ctx.t('User
|
|
143
|
+
'<h4>' + ctx.t('User list') + '</h4>',
|
|
145
144
|
'<ul>',
|
|
146
145
|
...rows.map((r) => '<li>' + (r.nickname ?? r.username ?? '') + '</li>'),
|
|
147
146
|
'</ul>',
|
|
@@ -151,13 +150,13 @@ ctx.render([
|
|
|
151
150
|
|
|
152
151
|
## Notes
|
|
153
152
|
|
|
154
|
-
- **
|
|
155
|
-
- **
|
|
156
|
-
- **
|
|
153
|
+
- **Errors**: Failed requests throw; by default a global error message is shown. Use `skipNotify: true` to handle yourself.
|
|
154
|
+
- **Auth**: Same-origin requests automatically send token, locale, role; cross-origin needs CORS and optional token in headers.
|
|
155
|
+
- **ACL**: Requests are subject to ACL; only resources the user can access are available.
|
|
157
156
|
|
|
158
157
|
## Related
|
|
159
158
|
|
|
160
|
-
- [ctx.message](./message.md)
|
|
161
|
-
- [ctx.notification](./notification.md)
|
|
162
|
-
- [ctx.render](./render.md)
|
|
163
|
-
- [ctx.makeResource](./make-resource.md)
|
|
159
|
+
- [ctx.message](./message.md): short feedback after request
|
|
160
|
+
- [ctx.notification](./notification.md): notification after request
|
|
161
|
+
- [ctx.render](./render.md): render result in UI
|
|
162
|
+
- [ctx.makeResource](./make-resource.md): build resource for chained loading (alternative to direct `ctx.request`)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.requireAsync()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Loads **UMD/AMD** or global scripts by URL asynchronously; can also load **CSS**. Use for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins, etc. in RunJS; pass a `.css` URL to load and inject styles. If a library provides ESM, prefer [ctx.importAsync()](./import-async.md).
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Use whenever RunJS needs to load UMD/AMD/global scripts or CSS: JSBlock, JSField, JSItem, JSColumn, event flow, JSAction, etc. Typical: ECharts, Chart.js, FullCalendar (UMD), dayjs (UMD), jQuery plugins.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
requireAsync<T = any>(url: string): Promise<T>;
|
|
@@ -16,40 +16,37 @@ requireAsync<T = any>(url: string): Promise<T>;
|
|
|
16
16
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
|-----------|------|-------------|
|
|
19
|
-
| `url` | `string` |
|
|
19
|
+
| `url` | `string` | Script or CSS URL. Supports **shorthand** `<package>@<version>/<path>` (ESM CDN adds `?raw` for raw UMD) or **full URL**. `.css` URLs load and inject styles. |
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Returns
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
23
|
+
- Loaded library object (first module value from UMD/AMD callback). Many UMD libs attach to `window` (e.g. `window.echarts`); return value may be `undefined`—use the library’s docs for how to access.
|
|
24
|
+
- For `.css` URLs, returns the result of `loadCSS`.
|
|
25
25
|
|
|
26
|
-
## URL
|
|
26
|
+
## URL format
|
|
27
27
|
|
|
28
|
-
- **Shorthand
|
|
29
|
-
- **Full URL**: Any CDN
|
|
30
|
-
- **CSS**:
|
|
28
|
+
- **Shorthand**: e.g. `echarts@5/dist/echarts.min.js`; with default ESM CDN (esm.sh) becomes `https://esm.sh/echarts@5/dist/echarts.min.js?raw`; `?raw` fetches the raw UMD file.
|
|
29
|
+
- **Full URL**: Any CDN URL, e.g. `https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js`.
|
|
30
|
+
- **CSS**: URLs ending in `.css` are loaded and injected.
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## vs ctx.importAsync()
|
|
33
33
|
|
|
34
|
-
- **ctx.requireAsync()**: Loads **UMD/AMD/global** scripts
|
|
35
|
-
- **ctx.importAsync()**: Loads **ESM
|
|
34
|
+
- **ctx.requireAsync()**: Loads **UMD/AMD/global** scripts; good for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins; lib often on `window`; return may be the lib or `undefined`.
|
|
35
|
+
- **ctx.importAsync()**: Loads **ESM**; returns module namespace. If a lib has ESM, prefer `ctx.importAsync()` for better module semantics and tree-shaking.
|
|
36
36
|
|
|
37
37
|
## Examples
|
|
38
38
|
|
|
39
|
-
### Basic
|
|
39
|
+
### Basic
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
-
// Shorthand path (resolved via ESM CDN as ...?raw)
|
|
43
42
|
const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');
|
|
44
43
|
|
|
45
|
-
// Full URL
|
|
46
44
|
const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');
|
|
47
45
|
|
|
48
|
-
// Load CSS and inject into the page
|
|
49
46
|
await ctx.requireAsync('https://cdn.example.com/theme.css');
|
|
50
47
|
```
|
|
51
48
|
|
|
52
|
-
### ECharts
|
|
49
|
+
### ECharts
|
|
53
50
|
|
|
54
51
|
```javascript
|
|
55
52
|
const container = document.createElement('div');
|
|
@@ -62,13 +59,13 @@ if (!echarts) throw new Error('ECharts library not loaded');
|
|
|
62
59
|
|
|
63
60
|
const chart = echarts.init(container);
|
|
64
61
|
chart.setOption({
|
|
65
|
-
title: { text: ctx.t('Sales
|
|
62
|
+
title: { text: ctx.t('Sales overview') },
|
|
66
63
|
series: [{ type: 'pie', data: [{ value: 1, name: ctx.t('A') }] }],
|
|
67
64
|
});
|
|
68
65
|
chart.resize();
|
|
69
66
|
```
|
|
70
67
|
|
|
71
|
-
### Chart.js
|
|
68
|
+
### Chart.js bar
|
|
72
69
|
|
|
73
70
|
```javascript
|
|
74
71
|
async function renderChart() {
|
|
@@ -83,7 +80,7 @@ async function renderChart() {
|
|
|
83
80
|
type: 'bar',
|
|
84
81
|
data: {
|
|
85
82
|
labels: ['A', 'B', 'C'],
|
|
86
|
-
datasets: [{ label: ctx.t('
|
|
83
|
+
datasets: [{ label: ctx.t('Count'), data: [12, 19, 3] }],
|
|
87
84
|
},
|
|
88
85
|
});
|
|
89
86
|
}
|
|
@@ -99,12 +96,12 @@ console.log(dayjs?.default || dayjs);
|
|
|
99
96
|
|
|
100
97
|
## Notes
|
|
101
98
|
|
|
102
|
-
- **Return
|
|
103
|
-
- **Network
|
|
104
|
-
- **
|
|
99
|
+
- **Return shape**: UMD libs vary; return may be the lib or `undefined`; if `undefined`, use the lib’s docs (often `window`).
|
|
100
|
+
- **Network**: Requires CDN access; for intranet set **ESM_CDN_BASE_URL** to your own service.
|
|
101
|
+
- **Choice**: If a lib has both ESM and UMD, prefer `ctx.importAsync()`.
|
|
105
102
|
|
|
106
103
|
## Related
|
|
107
104
|
|
|
108
|
-
- [ctx.importAsync()](./import-async.md)
|
|
109
|
-
- [ctx.render()](./render.md)
|
|
110
|
-
- [ctx.libs](./libs.md) -
|
|
105
|
+
- [ctx.importAsync()](./import-async.md): load ESM; good for Vue, dayjs (ESM), etc.
|
|
106
|
+
- [ctx.render()](./render.md): render charts etc. into container
|
|
107
|
+
- [ctx.libs](./libs.md): built-in React, antd, dayjs; no async load
|