@nocobase/plugin-flow-engine 2.1.0-alpha.6 → 2.1.0-alpha.8
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 +53 -51
- package/dist/ai/docs/runjs/context/collection.md +39 -39
- package/dist/ai/docs/runjs/context/data-source-manager.md +40 -30
- package/dist/ai/docs/runjs/context/data-source.md +52 -44
- package/dist/ai/docs/runjs/context/element.md +44 -38
- package/dist/ai/docs/runjs/context/exit-all.md +37 -35
- package/dist/ai/docs/runjs/context/exit.md +38 -35
- package/dist/ai/docs/runjs/context/filter-manager.md +36 -30
- package/dist/ai/docs/runjs/context/form.md +57 -57
- package/dist/ai/docs/runjs/context/get-model.md +22 -21
- package/dist/ai/docs/runjs/context/get-value.md +20 -19
- package/dist/ai/docs/runjs/context/get-var.md +61 -55
- package/dist/ai/docs/runjs/context/i18n.md +17 -14
- package/dist/ai/docs/runjs/context/import-async.md +333 -45
- 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 +34 -31
- package/dist/ai/docs/runjs/context/logger.md +41 -40
- package/dist/ai/docs/runjs/context/make-resource.md +27 -26
- package/dist/ai/docs/runjs/context/message.md +42 -41
- package/dist/ai/docs/runjs/context/modal.md +44 -44
- package/dist/ai/docs/runjs/context/model.md +36 -33
- package/dist/ai/docs/runjs/context/notification.md +41 -40
- package/dist/ai/docs/runjs/context/off.md +14 -14
- package/dist/ai/docs/runjs/context/on.md +30 -29
- package/dist/ai/docs/runjs/context/open-view.md +40 -40
- package/dist/ai/docs/runjs/context/render.md +37 -32
- package/dist/ai/docs/runjs/context/request.md +46 -45
- package/dist/ai/docs/runjs/context/require-async.md +28 -25
- package/dist/ai/docs/runjs/context/resource.md +34 -34
- package/dist/ai/docs/runjs/context/route.md +36 -34
- package/dist/ai/docs/runjs/context/router.md +43 -31
- package/dist/ai/docs/runjs/context/set-value.md +18 -17
- package/dist/ai/docs/runjs/context/sql.md +7 -15
- package/dist/ai/docs/runjs/context/t.md +20 -17
- package/dist/ai/docs/runjs/context/view.md +49 -46
- package/dist/ai/docs/runjs/document.md +1 -0
- 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 +1 -3
- 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/dist/server/collections/flowsql.js +1 -0
- package/package.json +2 -2
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# ctx.openView()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Programmatically open a specified view (drawer, dialog, embedded page, etc.). Provided by `FlowModelContext`, it is used to open configured `ChildPage` or `PopupAction` views in scenarios such as `JSBlock`, table cells, and workflows.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **Table
|
|
11
|
-
| **
|
|
12
|
-
| **Association
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock** | Open a detail/edit dialog after a button click, passing the current row's `filterByTk`. |
|
|
10
|
+
| **Table Cell** | Render a button within a cell that opens a row detail dialog when clicked. |
|
|
11
|
+
| **Workflow / JSAction** | Open the next view or a dialog after a successful operation. |
|
|
12
|
+
| **Association Field** | Open a selection/edit dialog via `ctx.runAction('openView', params)`. |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.openView`
|
|
14
|
+
> Note: `ctx.openView` is available in a RunJS environment where a `FlowModel` context exists. If the model corresponding to the `uid` does not exist, a `PopupActionModel` will be automatically 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
|
+
The unique identifier of the view model. If it does not exist, it will be automatically created and saved. It is recommended to use a stable UID, such as `${ctx.model.uid}-detail`, so that the configuration can be reused when opening the same dialog multiple times.
|
|
27
27
|
|
|
28
|
-
### options
|
|
28
|
+
### Common options 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 for single
|
|
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` | Opening method: drawer, dialog, or embedded. Defaults to `drawer`. |
|
|
33
|
+
| `size` | `small` / `medium` / `large` | Size of the dialog or drawer. Defaults to `medium`. |
|
|
34
|
+
| `title` | `string` | View title. |
|
|
35
|
+
| `params` | `Record<string, any>` | Arbitrary parameters passed to the view. |
|
|
36
|
+
| `filterByTk` | `any` | Primary key value, used for single record detail/edit scenarios. |
|
|
37
|
+
| `sourceId` | `string` | Source record ID, used in association scenarios. |
|
|
38
|
+
| `dataSourceKey` | `string` | Data source. |
|
|
39
|
+
| `collectionName` | `string` | Collection name. |
|
|
40
|
+
| `associationName` | `string` | Association field name. |
|
|
41
|
+
| `navigation` | `boolean` | Whether to use route navigation. If `defineProperties` or `defineMethods` are provided, this is forced to `false`. |
|
|
42
|
+
| `preventClose` | `boolean` | Whether to prevent closing. |
|
|
43
|
+
| `defineProperties` | `Record<string, PropertyOptions>` | Dynamically inject properties into the model within the view. |
|
|
44
|
+
| `defineMethods` | `Record<string, Function>` | Dynamically inject methods into the model within the view. |
|
|
45
45
|
|
|
46
46
|
## Examples
|
|
47
47
|
|
|
48
|
-
### Basic:
|
|
48
|
+
### Basic Usage: Open a 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('Details'),
|
|
56
56
|
});
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
###
|
|
59
|
+
### Passing 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 Details'),
|
|
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 a model is configured with an `openView` action (such as association fields or clickable fields), you can call:
|
|
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
|
+
### Injecting 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
|
+
## Relationship with ctx.viewer and ctx.view
|
|
102
102
|
|
|
103
|
-
|
|
|
104
|
-
|
|
105
|
-
| **Open configured flow view** | `ctx.openView(uid, options)` |
|
|
103
|
+
| Purpose | Recommended Usage |
|
|
104
|
+
|------|----------|
|
|
105
|
+
| **Open a configured flow view** | `ctx.openView(uid, options)` |
|
|
106
106
|
| **Open custom content (no flow)** | `ctx.viewer.dialog()` / `ctx.viewer.drawer()` |
|
|
107
|
-
| **Operate
|
|
107
|
+
| **Operate on the currently open view** | `ctx.view.close()`, `ctx.view.inputArgs` |
|
|
108
108
|
|
|
109
|
-
`ctx.openView` opens a FlowPage (ChildPageModel)
|
|
109
|
+
`ctx.openView` opens a `FlowPage` (`ChildPageModel`), which renders a complete flow page internally; `ctx.viewer` opens arbitrary React content.
|
|
110
110
|
|
|
111
111
|
## Notes
|
|
112
112
|
|
|
113
|
-
-
|
|
114
|
-
- When
|
|
115
|
-
- Inside
|
|
113
|
+
- It is recommended to associate the `uid` with `ctx.model.uid` (e.g., `${ctx.model.uid}-xxx`) to avoid conflicts between multiple blocks.
|
|
114
|
+
- When `defineProperties` or `defineMethods` are passed, `navigation` is forced to `false` to prevent context loss after a refresh.
|
|
115
|
+
- Inside the dialog, `ctx.view` refers to the current view instance, and `ctx.view.inputArgs` can be used to read the parameters passed during opening.
|
|
116
116
|
|
|
117
117
|
## Related
|
|
118
118
|
|
|
119
|
-
- [ctx.view](./view.md):
|
|
120
|
-
- [ctx.model](./model.md): current model
|
|
119
|
+
- [ctx.view](./view.md): The currently open view instance.
|
|
120
|
+
- [ctx.model](./model.md): The current model, used to construct a stable `popupUid`.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ctx.render()
|
|
2
2
|
|
|
3
|
-
Renders
|
|
3
|
+
Renders React elements, HTML strings, or DOM nodes into a specified container. If `container` is not provided, it defaults to rendering into `ctx.element` and automatically inherits the application's context, such as ConfigProvider and themes.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock** |
|
|
10
|
-
| **JSField / JSItem / JSColumn** |
|
|
11
|
-
| **
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock** | Render custom block content (charts, lists, cards, etc.) |
|
|
10
|
+
| **JSField / JSItem / JSColumn** | Render custom displays for editable fields or table columns |
|
|
11
|
+
| **Details Block** | Customize the display format of fields in details pages |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.render()`
|
|
13
|
+
> Note: `ctx.render()` requires a rendering container. If `container` is not passed and `ctx.element` does not exist (e.g., in pure logic scenarios without a UI), an error will be thrown.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
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 be rendered |
|
|
27
|
+
| `container` | `Element` \| `DocumentFragment` (Optional) | Target rendering container, defaults to `ctx.element` |
|
|
28
28
|
|
|
29
|
-
**
|
|
29
|
+
**Return Value**:
|
|
30
30
|
|
|
31
|
-
-
|
|
32
|
-
-
|
|
31
|
+
- When rendering a **React element**: Returns `ReactDOMClient.Root`, making it easy to call `root.render()` for subsequent updates.
|
|
32
|
+
- When rendering an **HTML string** or **DOM node**: Returns `null`.
|
|
33
33
|
|
|
34
|
-
## vnode
|
|
34
|
+
## vnode Type Description
|
|
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 using React's `createRoot`, providing full React capabilities and automatically inheriting the application context. |
|
|
39
|
+
| `string` | Sets the container's `innerHTML` after sanitization with DOMPurify; any existing React root will be unmounted first. |
|
|
40
|
+
| `Node` (Element, Text, etc.) | Appends via `appendChild` after clearing the container; any existing React root will be unmounted first. |
|
|
41
|
+
| `DocumentFragment` | Appends fragment child nodes to the container; any existing React root will be unmounted first. |
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
### React (JSX)
|
|
45
|
+
### Rendering React Elements (JSX)
|
|
46
46
|
|
|
47
47
|
```tsx
|
|
48
48
|
const { Button, Card } = ctx.libs.antd;
|
|
@@ -56,23 +56,26 @@ ctx.render(
|
|
|
56
56
|
);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
|
-
### HTML
|
|
59
|
+
### Rendering HTML Strings
|
|
60
60
|
|
|
61
61
|
```ts
|
|
62
62
|
ctx.render('<h1>Hello World</h1>');
|
|
63
63
|
|
|
64
|
+
// Combining with ctx.t for internationalization
|
|
64
65
|
ctx.render('<div style="padding:16px">' + ctx.t('Content') + '</div>');
|
|
65
66
|
|
|
67
|
+
// Conditional rendering
|
|
66
68
|
ctx.render(hasData ? `<ul>${items.map(i => `<li>${i}</li>`).join('')}</ul>` : '<span style="color:#999">' + ctx.t('No data') + '</span>');
|
|
67
69
|
```
|
|
68
70
|
|
|
69
|
-
### DOM
|
|
71
|
+
### Rendering DOM Nodes
|
|
70
72
|
|
|
71
73
|
```ts
|
|
72
74
|
const div = document.createElement('div');
|
|
73
75
|
div.textContent = 'Hello World';
|
|
74
76
|
ctx.render(div);
|
|
75
77
|
|
|
78
|
+
// Render an empty container first, then hand it over to a third-party library (e.g., ECharts) for initialization
|
|
76
79
|
const container = document.createElement('div');
|
|
77
80
|
container.style.width = '100%';
|
|
78
81
|
container.style.height = '400px';
|
|
@@ -81,29 +84,31 @@ const chart = echarts.init(container);
|
|
|
81
84
|
chart.setOption({ ... });
|
|
82
85
|
```
|
|
83
86
|
|
|
84
|
-
### Custom
|
|
87
|
+
### Specifying a Custom Container
|
|
85
88
|
|
|
86
89
|
```ts
|
|
90
|
+
// Render to a specific DOM element
|
|
87
91
|
const customEl = document.getElementById('my-container');
|
|
88
92
|
ctx.render(<div>Content</div>, customEl);
|
|
89
93
|
```
|
|
90
94
|
|
|
91
|
-
### Multiple
|
|
95
|
+
### Multiple Calls Will Replace Content
|
|
92
96
|
|
|
93
97
|
```ts
|
|
98
|
+
// The second call will replace the existing content in the container
|
|
94
99
|
ctx.render(<div>First</div>);
|
|
95
|
-
ctx.render(<div>Second</div>); // Only "Second"
|
|
100
|
+
ctx.render(<div>Second</div>); // Only "Second" will be displayed
|
|
96
101
|
```
|
|
97
102
|
|
|
98
103
|
## Notes
|
|
99
104
|
|
|
100
|
-
- **Each call replaces
|
|
101
|
-
- **HTML safety**: HTML is sanitized
|
|
102
|
-
- **
|
|
103
|
-
- **
|
|
105
|
+
- **Multiple calls will replace content**: Each `ctx.render()` call replaces the existing content in the container rather than appending to it.
|
|
106
|
+
- **HTML string safety**: Passed HTML is sanitized via DOMPurify to reduce XSS risks, but it is still recommended to avoid concatenating untrusted user input.
|
|
107
|
+
- **Do not manipulate ctx.element directly**: `ctx.element.innerHTML` is deprecated; `ctx.render()` should be used consistently instead.
|
|
108
|
+
- **Pass container when no default exists**: In scenarios where `ctx.element` is `undefined` (e.g., within modules loaded via `ctx.importAsync`), a `container` must be explicitly provided.
|
|
104
109
|
|
|
105
110
|
## Related
|
|
106
111
|
|
|
107
|
-
- [ctx.element](./element.md)
|
|
108
|
-
- [ctx.libs](./libs.md)
|
|
109
|
-
- [ctx.importAsync()](./import-async.md)
|
|
112
|
+
- [ctx.element](./element.md) - Default rendering container, used when no container is passed to `ctx.render()`.
|
|
113
|
+
- [ctx.libs](./libs.md) - Built-in libraries like React and Ant Design, used for JSX rendering.
|
|
114
|
+
- [ctx.importAsync()](./import-async.md) - Used in conjunction with `ctx.render()` after loading external React/component libraries on demand.
|
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
# ctx.request()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Initiate an authenticated HTTP request within RunJS. The request automatically carries the current application's `baseURL`, `Token`, `locale`, `role`, etc., and follows the application's request interception and error handling logic.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Applicable to any scenario in RunJS where a remote HTTP request needs to be initiated, such as JSBlock, JSField, JSItem, JSColumn, Workflow, Linkage, JSAction, etc.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
request(options: RequestOptions): Promise<AxiosResponse<any>>;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
`RequestOptions` extends Axios `AxiosRequestConfig`:
|
|
15
|
+
`RequestOptions` extends Axios's `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); // Whether to skip global error prompts when the request fails
|
|
20
|
+
skipAuth?: boolean; // Whether to skip authentication redirection (e.g., do not redirect to login page on 401)
|
|
21
21
|
};
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
## Common
|
|
24
|
+
## Common Parameters
|
|
25
25
|
|
|
26
26
|
| Parameter | Type | Description |
|
|
27
|
-
|
|
28
|
-
| `url` | string | URL. Supports resource style (e.g
|
|
29
|
-
| `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method
|
|
30
|
-
| `params` | object | Query
|
|
31
|
-
| `data` | any | Request body for post/put/patch |
|
|
32
|
-
| `headers` | object | Custom headers |
|
|
33
|
-
| `skipNotify` | boolean \| (error) => boolean |
|
|
34
|
-
| `skipAuth` | boolean |
|
|
27
|
+
|------|------|------|
|
|
28
|
+
| `url` | string | Request URL. Supports resource style (e.g., `users:list`, `posts:create`), or a full URL |
|
|
29
|
+
| `method` | 'get' \| 'post' \| 'put' \| 'patch' \| 'delete' | HTTP method, defaults to `'get'` |
|
|
30
|
+
| `params` | object | Query parameters, serialized into the URL |
|
|
31
|
+
| `data` | any | Request body, used for post/put/patch |
|
|
32
|
+
| `headers` | object | Custom request headers |
|
|
33
|
+
| `skipNotify` | boolean \| (error) => boolean | If true or the function returns true, global error prompts will not pop up on failure |
|
|
34
|
+
| `skipAuth` | boolean | If true, 401 errors etc. will not trigger authentication redirection (e.g., redirecting to the login page) |
|
|
35
35
|
|
|
36
|
-
## Resource
|
|
36
|
+
## Resource Style URL
|
|
37
37
|
|
|
38
|
-
NocoBase
|
|
38
|
+
NocoBase Resource API supports a shorthand `resource:action` format:
|
|
39
39
|
|
|
40
40
|
| Format | Description | Example |
|
|
41
|
-
|
|
42
|
-
| `collection:action` | Single
|
|
43
|
-
| `collection.relation:action` |
|
|
41
|
+
|------|------|------|
|
|
42
|
+
| `collection:action` | Single collection CRUD | `users:list`, `users:get`, `users:create`, `posts:update` |
|
|
43
|
+
| `collection.relation:action` | Associated resources (requires passing the primary key via `resourceOf` or URL) | `posts.comments:list` |
|
|
44
44
|
|
|
45
|
-
Relative
|
|
45
|
+
Relative paths will be concatenated with the application's `baseURL` (usually `/api`); cross-origin requests must use a full URL, and the target service must be configured with CORS.
|
|
46
46
|
|
|
47
|
-
## Response
|
|
47
|
+
## Response Structure
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
The return value is an Axios response object. Common fields include:
|
|
50
50
|
|
|
51
|
-
- `response.data`:
|
|
52
|
-
- List
|
|
53
|
-
- Single/create/update
|
|
51
|
+
- `response.data`: Response body
|
|
52
|
+
- List interfaces usually return `data.data` (array of records) + `data.meta` (pagination, etc.)
|
|
53
|
+
- Single record/create/update interfaces usually return the record in `data.data`
|
|
54
54
|
|
|
55
55
|
## Examples
|
|
56
56
|
|
|
57
|
-
### List
|
|
57
|
+
### List Query
|
|
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; // Pagination and other info
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
###
|
|
70
|
+
### Submit Data
|
|
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', email: '
|
|
76
|
+
data: { nickname: 'John Doe', email: 'johndoe@example.com' },
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
const newRecord = res?.data?.data;
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
###
|
|
82
|
+
### With Filtering and Sorting
|
|
83
83
|
|
|
84
84
|
```javascript
|
|
85
85
|
const res = await ctx.request({
|
|
@@ -93,15 +93,16 @@ const res = await ctx.request({
|
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
### Skip
|
|
96
|
+
### Skip Error Notification
|
|
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, // Do not pop up global message on failure
|
|
103
103
|
});
|
|
104
104
|
|
|
105
|
+
// Or decide whether to skip based on error type
|
|
105
106
|
const res2 = await ctx.request({
|
|
106
107
|
url: 'some:action',
|
|
107
108
|
method: 'get',
|
|
@@ -109,9 +110,9 @@ const res2 = await ctx.request({
|
|
|
109
110
|
});
|
|
110
111
|
```
|
|
111
112
|
|
|
112
|
-
### Cross-
|
|
113
|
+
### Cross-Origin Request
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
When using a full URL to request other domains, the target service must be configured with CORS to allow the current application's origin. If the target interface requires its own token, it can be passed via headers:
|
|
115
116
|
|
|
116
117
|
```javascript
|
|
117
118
|
const res = await ctx.request({
|
|
@@ -123,12 +124,12 @@ const res2 = await ctx.request({
|
|
|
123
124
|
url: 'https://api.other.com/items',
|
|
124
125
|
method: 'get',
|
|
125
126
|
headers: {
|
|
126
|
-
Authorization: 'Bearer <
|
|
127
|
+
Authorization: 'Bearer <target_service_token>',
|
|
127
128
|
},
|
|
128
129
|
});
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
###
|
|
132
|
+
### Displaying with ctx.render
|
|
132
133
|
|
|
133
134
|
```javascript
|
|
134
135
|
const { data } = await ctx.request({
|
|
@@ -140,7 +141,7 @@ const rows = Array.isArray(data?.data) ? data.data : [];
|
|
|
140
141
|
|
|
141
142
|
ctx.render([
|
|
142
143
|
'<div style="padding:12px">',
|
|
143
|
-
'<h4>' + ctx.t('User
|
|
144
|
+
'<h4>' + ctx.t('User List') + '</h4>',
|
|
144
145
|
'<ul>',
|
|
145
146
|
...rows.map((r) => '<li>' + (r.nickname ?? r.username ?? '') + '</li>'),
|
|
146
147
|
'</ul>',
|
|
@@ -150,13 +151,13 @@ ctx.render([
|
|
|
150
151
|
|
|
151
152
|
## Notes
|
|
152
153
|
|
|
153
|
-
- **
|
|
154
|
-
- **
|
|
155
|
-
- **
|
|
154
|
+
- **Error Handling**: Request failure will throw an exception, and a global error prompt will pop up by default. Use `skipNotify: true` to catch and handle it yourself.
|
|
155
|
+
- **Authentication**: Same-origin requests will automatically carry the current user's Token, locale, and role; cross-origin requests require the target to support CORS and pass the token in headers as needed.
|
|
156
|
+
- **Resource Permissions**: Requests are subject to ACL constraints and can only access resources the current user has permission for.
|
|
156
157
|
|
|
157
158
|
## Related
|
|
158
159
|
|
|
159
|
-
- [ctx.message](./message.md)
|
|
160
|
-
- [ctx.notification](./notification.md)
|
|
161
|
-
- [ctx.render](./render.md)
|
|
162
|
-
- [ctx.makeResource](./make-resource.md)
|
|
160
|
+
- [ctx.message](./message.md) - Display lightweight prompts after the request is completed
|
|
161
|
+
- [ctx.notification](./notification.md) - Display notifications after the request is completed
|
|
162
|
+
- [ctx.render](./render.md) - Render request results to the interface
|
|
163
|
+
- [ctx.makeResource](./make-resource.md) - Construct a resource object for chained data loading (alternative to `ctx.request`)
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.requireAsync()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Asynchronously loads **UMD/AMD** or globally mounted scripts via URL, as well as **CSS**. It is suitable for RunJS scenarios that require UMD/AMD libraries such as ECharts, Chart.js, FullCalendar (UMD version), or jQuery plugins. If a library also provides an ESM version, prioritize using [ctx.importAsync()](./import-async.md).
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Can be used in any RunJS scenario where UMD/AMD/global scripts or CSS need to be loaded on demand, such as JSBlock, JSField, JSItem, JSColumn, Workflow, JSAction, etc. Typical uses: ECharts, Chart.js, FullCalendar (UMD), dayjs (UMD), jQuery plugins, etc.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
requireAsync<T = any>(url: string): Promise<T>;
|
|
@@ -16,37 +16,40 @@ requireAsync<T = any>(url: string): Promise<T>;
|
|
|
16
16
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
|-----------|------|-------------|
|
|
19
|
-
| `url` | `string` |
|
|
19
|
+
| `url` | `string` | The script or CSS address. Supports **shorthand** `<package>@<version>/<file-path>` (appends `?raw` for the original UMD file when resolved via ESM CDN) or a **full URL**. Loads and injects styles if a `.css` file is passed. |
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## Return Value
|
|
22
22
|
|
|
23
|
-
-
|
|
24
|
-
-
|
|
23
|
+
- The loaded library object (the first module value of the UMD/AMD callback). Many UMD libraries attach themselves to `window` (e.g., `window.echarts`), so the return value might be `undefined`. In such cases, access the global variable as per the library's documentation.
|
|
24
|
+
- Returns the result of `loadCSS` when a `.css` file is passed.
|
|
25
25
|
|
|
26
|
-
## URL
|
|
26
|
+
## URL Format Description
|
|
27
27
|
|
|
28
|
-
- **Shorthand**: e.g
|
|
29
|
-
- **Full URL**: Any CDN
|
|
30
|
-
- **CSS**:
|
|
28
|
+
- **Shorthand path**: e.g., `echarts@5/dist/echarts.min.js`. Under the default ESM CDN (esm.sh), it requests `https://esm.sh/echarts@5/dist/echarts.min.js?raw`. The `?raw` parameter is used to fetch the original UMD file instead of an ESM wrapper.
|
|
29
|
+
- **Full URL**: Any CDN address can be used directly, such as `https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js`.
|
|
30
|
+
- **CSS**: A URL ending in `.css` will be loaded and injected into the page.
|
|
31
31
|
|
|
32
|
-
##
|
|
32
|
+
## Difference from 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. Suitable for ECharts, Chart.js, FullCalendar (UMD), jQuery plugins, etc. Libraries often attach to `window` after loading; the return value may be the library object or `undefined`.
|
|
35
|
+
- **ctx.importAsync()**: Loads **ESM modules** and returns the module namespace. If a library provides ESM, use `ctx.importAsync()` for better module semantics and Tree-shaking.
|
|
36
36
|
|
|
37
37
|
## Examples
|
|
38
38
|
|
|
39
|
-
### Basic
|
|
39
|
+
### Basic Usage
|
|
40
40
|
|
|
41
41
|
```javascript
|
|
42
|
+
// Shorthand path (resolved via ESM CDN as ...?raw)
|
|
42
43
|
const echarts = await ctx.requireAsync('echarts@5/dist/echarts.min.js');
|
|
43
44
|
|
|
45
|
+
// Full URL
|
|
44
46
|
const dayjs = await ctx.requireAsync('https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js');
|
|
45
47
|
|
|
48
|
+
// Load CSS and inject into the page
|
|
46
49
|
await ctx.requireAsync('https://cdn.example.com/theme.css');
|
|
47
50
|
```
|
|
48
51
|
|
|
49
|
-
### ECharts
|
|
52
|
+
### ECharts Chart
|
|
50
53
|
|
|
51
54
|
```javascript
|
|
52
55
|
const container = document.createElement('div');
|
|
@@ -59,13 +62,13 @@ if (!echarts) throw new Error('ECharts library not loaded');
|
|
|
59
62
|
|
|
60
63
|
const chart = echarts.init(container);
|
|
61
64
|
chart.setOption({
|
|
62
|
-
title: { text: ctx.t('Sales
|
|
65
|
+
title: { text: ctx.t('Sales Overview') },
|
|
63
66
|
series: [{ type: 'pie', data: [{ value: 1, name: ctx.t('A') }] }],
|
|
64
67
|
});
|
|
65
68
|
chart.resize();
|
|
66
69
|
```
|
|
67
70
|
|
|
68
|
-
### Chart.js
|
|
71
|
+
### Chart.js Bar Chart
|
|
69
72
|
|
|
70
73
|
```javascript
|
|
71
74
|
async function renderChart() {
|
|
@@ -80,7 +83,7 @@ async function renderChart() {
|
|
|
80
83
|
type: 'bar',
|
|
81
84
|
data: {
|
|
82
85
|
labels: ['A', 'B', 'C'],
|
|
83
|
-
datasets: [{ label: ctx.t('
|
|
86
|
+
datasets: [{ label: ctx.t('Quantity'), data: [12, 19, 3] }],
|
|
84
87
|
},
|
|
85
88
|
});
|
|
86
89
|
}
|
|
@@ -96,12 +99,12 @@ console.log(dayjs?.default || dayjs);
|
|
|
96
99
|
|
|
97
100
|
## Notes
|
|
98
101
|
|
|
99
|
-
- **Return
|
|
100
|
-
- **Network**: Requires CDN access
|
|
101
|
-
- **
|
|
102
|
+
- **Return value format**: UMD export methods vary; the return value may be the library object or `undefined`. If `undefined`, access it via `window` according to the library's documentation.
|
|
103
|
+
- **Network dependency**: Requires CDN access. In internal network environments, you can point to a self-hosted service via **ESM_CDN_BASE_URL**.
|
|
104
|
+
- **Choosing between importAsync**: If a library provides both ESM and UMD, prioritize `ctx.importAsync()`.
|
|
102
105
|
|
|
103
106
|
## Related
|
|
104
107
|
|
|
105
|
-
- [ctx.importAsync()](./import-async.md)
|
|
106
|
-
- [ctx.render()](./render.md)
|
|
107
|
-
- [ctx.libs](./libs.md)
|
|
108
|
+
- [ctx.importAsync()](./import-async.md) - Loads ESM modules, suitable for Vue, dayjs (ESM), etc.
|
|
109
|
+
- [ctx.render()](./render.md) - Renders charts and other components into a container.
|
|
110
|
+
- [ctx.libs](./libs.md) - Built-in React, antd, dayjs, etc., no asynchronous loading required.
|