@nocobase/plugin-flow-engine 2.1.0-alpha.7 → 2.1.0-alpha.9
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,39 +1,39 @@
|
|
|
1
1
|
# ctx.resource
|
|
2
2
|
|
|
3
|
-
The **FlowResource** instance in the current context
|
|
3
|
+
The **FlowResource** instance in the current context, used to access and operate on data. In most blocks (Forms, Tables, Details, etc.) and pop-up scenarios, the runtime environment pre-binds `ctx.resource`. In scenarios like JSBlock where there is no resource by default, you must first call [ctx.initResource()](./init-resource.md) to initialize it before using it via `ctx.resource`.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Applicable Scenarios
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`ctx.resource` can be used in any RunJS scenario that requires access to structured data (lists, single records, custom APIs, SQL). Forms, Tables, Detail blocks, and pop-ups are typically pre-bound. For JSBlock, JSField, JSItem, JSColumn, etc., if data loading is required, you can call `ctx.initResource(type)` first and then access `ctx.resource`.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
resource: FlowResource | undefined;
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
-
|
|
16
|
-
- In JSBlock
|
|
15
|
+
- In contexts with pre-binding, `ctx.resource` is the corresponding resource instance.
|
|
16
|
+
- In scenarios like JSBlock where there is no resource by default, it is `undefined` until `ctx.initResource(type)` is called.
|
|
17
17
|
|
|
18
|
-
## Common
|
|
18
|
+
## Common Methods
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Methods exposed by different resource types (MultiRecordResource, SingleRecordResource, APIResource, SQLResource) vary slightly. Below are the universal or commonly used methods:
|
|
21
21
|
|
|
22
22
|
| Method | Description |
|
|
23
|
-
|
|
24
|
-
| `getData()` |
|
|
23
|
+
|------|------|
|
|
24
|
+
| `getData()` | Get current data (list or single record) |
|
|
25
25
|
| `setData(value)` | Set local data |
|
|
26
|
-
| `refresh()` |
|
|
27
|
-
| `setResourceName(name)` | Set resource name (e.g
|
|
28
|
-
| `setFilterByTk(tk)` | Set primary key filter (single get
|
|
29
|
-
| `runAction(actionName, options)` | Call any resource action (e.g
|
|
30
|
-
| `on(event, callback)` / `off(event, callback)` | Subscribe/unsubscribe (e.g
|
|
26
|
+
| `refresh()` | Initiate a request with current parameters to refresh data |
|
|
27
|
+
| `setResourceName(name)` | Set resource name (e.g., `'users'`, `'users.tags'`) |
|
|
28
|
+
| `setFilterByTk(tk)` | Set primary key filter (for single record `get`, etc.) |
|
|
29
|
+
| `runAction(actionName, options)` | Call any resource action (e.g., `create`, `update`) |
|
|
30
|
+
| `on(event, callback)` / `off(event, callback)` | Subscribe/unsubscribe to events (e.g., `refresh`, `saved`) |
|
|
31
31
|
|
|
32
|
-
**MultiRecordResource**: `getSelectedRows()`, `destroySelectedRows()`, `setPage()`, `next()`, `previous()`, etc.
|
|
32
|
+
**MultiRecordResource Specific**: `getSelectedRows()`, `destroySelectedRows()`, `setPage()`, `next()`, `previous()`, etc.
|
|
33
33
|
|
|
34
34
|
## Examples
|
|
35
35
|
|
|
36
|
-
### List (
|
|
36
|
+
### List Data (Requires initResource first)
|
|
37
37
|
|
|
38
38
|
```js
|
|
39
39
|
ctx.initResource('MultiRecordResource');
|
|
@@ -42,7 +42,7 @@ await ctx.resource.refresh();
|
|
|
42
42
|
const rows = ctx.resource.getData();
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
### Table (
|
|
45
|
+
### Table Scenario (Pre-bound)
|
|
46
46
|
|
|
47
47
|
```js
|
|
48
48
|
const rows = ctx.resource?.getSelectedRows?.() || [];
|
|
@@ -54,7 +54,7 @@ await ctx.resource.destroySelectedRows();
|
|
|
54
54
|
ctx.message.success(ctx.t('Deleted'));
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
### Single
|
|
57
|
+
### Single Record
|
|
58
58
|
|
|
59
59
|
```js
|
|
60
60
|
ctx.initResource('SingleRecordResource');
|
|
@@ -64,29 +64,29 @@ await ctx.resource.refresh();
|
|
|
64
64
|
const record = ctx.resource.getData();
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
-
### Custom
|
|
67
|
+
### Calling a Custom Action
|
|
68
68
|
|
|
69
69
|
```js
|
|
70
|
-
await ctx.resource.runAction('create', { data: { name: 'John' } });
|
|
70
|
+
await ctx.resource.runAction('create', { data: { name: 'John Doe' } });
|
|
71
71
|
```
|
|
72
72
|
|
|
73
|
-
##
|
|
73
|
+
## Relationship with ctx.initResource / ctx.makeResource
|
|
74
74
|
|
|
75
|
-
- **ctx.initResource(type)**:
|
|
76
|
-
- **ctx.makeResource(type)**: Creates a new instance and returns it
|
|
77
|
-
- **ctx.resource**:
|
|
75
|
+
- **ctx.initResource(type)**: If `ctx.resource` does not exist, it creates and binds one; if it already exists, it returns the existing instance. This ensures `ctx.resource` is available.
|
|
76
|
+
- **ctx.makeResource(type)**: Creates a new resource instance and returns it, but does **not** write it to `ctx.resource`. This is suitable for scenarios requiring multiple independent resources or temporary usage.
|
|
77
|
+
- **ctx.resource**: Accesses the resource already bound to the current context. Most blocks/pop-ups are pre-bound; otherwise, it is `undefined` and requires `ctx.initResource`.
|
|
78
78
|
|
|
79
79
|
## Notes
|
|
80
80
|
|
|
81
|
-
-
|
|
82
|
-
- After
|
|
83
|
-
-
|
|
81
|
+
- It is recommended to perform a null check before use: `ctx.resource?.refresh()`, especially in scenarios like JSBlock where pre-binding might not exist.
|
|
82
|
+
- After initialization, you must call `setResourceName(name)` to specify the collection before loading data via `refresh()`.
|
|
83
|
+
- For the full API of each Resource type, see the links below.
|
|
84
84
|
|
|
85
85
|
## Related
|
|
86
86
|
|
|
87
|
-
- [ctx.initResource()](./init-resource.md)
|
|
88
|
-
- [ctx.makeResource()](./make-resource.md)
|
|
89
|
-
- [MultiRecordResource](../resource/multi-record-resource.md)
|
|
90
|
-
- [SingleRecordResource](../resource/single-record-resource.md)
|
|
91
|
-
- [APIResource](../resource/api-resource.md)
|
|
92
|
-
- [SQLResource](../resource/sql-resource.md)
|
|
87
|
+
- [ctx.initResource()](./init-resource.md) - Initialize and bind a resource to the current context
|
|
88
|
+
- [ctx.makeResource()](./make-resource.md) - Create a new resource instance without binding it to `ctx.resource`
|
|
89
|
+
- [MultiRecordResource](../resource/multi-record-resource.md) - Multiple records/Lists
|
|
90
|
+
- [SingleRecordResource](../resource/single-record-resource.md) - Single record
|
|
91
|
+
- [APIResource](../resource/api-resource.md) - General API resource
|
|
92
|
+
- [SQLResource](../resource/sql-resource.md) - SQL query resource
|
|
@@ -1,74 +1,76 @@
|
|
|
1
1
|
# ctx.route
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The current route matching information, corresponding to the `route` concept in React Router. It is used to retrieve the current matching route configuration, parameters, and more. It is typically used in conjunction with `ctx.router` and `ctx.location`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage /
|
|
11
|
-
| **View
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField** | Perform conditional rendering or display the current page identifier based on `route.pathname` or `route.params`. |
|
|
10
|
+
| **Linkage Rules / FlowEngine** | Read route parameters (e.g., `params.name`) for logic branching or to pass them to child components. |
|
|
11
|
+
| **View Navigation** | Internally compare `ctx.route.pathname` with a target path to determine whether to trigger `ctx.router.navigate`. |
|
|
12
12
|
|
|
13
|
-
> Note: `ctx.route` is only available in RunJS
|
|
13
|
+
> Note: `ctx.route` is only available in RunJS environments that contain a routing context (such as JSBlocks within a page, Flow pages, etc.). It may be null in pure backend or non-routing contexts (such as background workflows).
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
type RouteOptions = {
|
|
19
|
-
name?: string;
|
|
20
|
-
path?: string;
|
|
21
|
-
params?: Record<string, any>;
|
|
22
|
-
pathname?: string;
|
|
19
|
+
name?: string; // Unique route identifier
|
|
20
|
+
path?: string; // Route template (e.g., /admin/:name)
|
|
21
|
+
params?: Record<string, any>; // Route parameters (e.g., { name: 'users' })
|
|
22
|
+
pathname?: string; // Full path of the current route (e.g., /admin/users)
|
|
23
23
|
};
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
## Common
|
|
26
|
+
## Common Fields
|
|
27
27
|
|
|
28
28
|
| Field | Type | Description |
|
|
29
|
-
|
|
30
|
-
| `pathname` | `string` |
|
|
31
|
-
| `params` | `Record<string, any>` | Dynamic
|
|
32
|
-
| `path` | `string` |
|
|
33
|
-
| `name` | `string` |
|
|
29
|
+
|------|------|------|
|
|
30
|
+
| `pathname` | `string` | The full path of the current route, consistent with `ctx.location.pathname`. |
|
|
31
|
+
| `params` | `Record<string, any>` | Dynamic parameters parsed from the route template, such as `{ name: 'users' }`. |
|
|
32
|
+
| `path` | `string` | The route template, such as `/admin/:name`. |
|
|
33
|
+
| `name` | `string` | Unique route identifier, commonly used in multi-tab or multi-view scenarios. |
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Relationship with ctx.router and ctx.location
|
|
36
36
|
|
|
37
|
-
|
|
|
38
|
-
|
|
39
|
-
| **
|
|
40
|
-
| **
|
|
41
|
-
| **
|
|
42
|
-
| **
|
|
37
|
+
| Purpose | Recommended Usage |
|
|
38
|
+
|------|----------|
|
|
39
|
+
| **Read current path** | `ctx.route.pathname` or `ctx.location.pathname`; both are consistent during matching. |
|
|
40
|
+
| **Read route parameters** | `ctx.route.params`, e.g., `params.name` representing the current page UID. |
|
|
41
|
+
| **Navigation** | `ctx.router.navigate(path)` |
|
|
42
|
+
| **Read query parameters, state** | `ctx.location.search`, `ctx.location.state` |
|
|
43
43
|
|
|
44
|
-
`ctx.route`
|
|
44
|
+
`ctx.route` focuses on the "matched route configuration," while `ctx.location` focuses on the "current URL location." Together, they provide a complete description of the current routing state.
|
|
45
45
|
|
|
46
46
|
## Examples
|
|
47
47
|
|
|
48
|
-
###
|
|
48
|
+
### Reading pathname
|
|
49
49
|
|
|
50
50
|
```ts
|
|
51
|
-
|
|
51
|
+
// Display the current path
|
|
52
|
+
ctx.message.info('Current Page: ' + ctx.route.pathname);
|
|
52
53
|
```
|
|
53
54
|
|
|
54
|
-
###
|
|
55
|
+
### Branching based on params
|
|
55
56
|
|
|
56
57
|
```ts
|
|
58
|
+
// params.name is typically the current page UID (e.g., a Flow page identifier)
|
|
57
59
|
if (ctx.route.params?.name === 'users') {
|
|
58
|
-
//
|
|
60
|
+
// Execute specific logic on the user management page
|
|
59
61
|
}
|
|
60
62
|
```
|
|
61
63
|
|
|
62
|
-
###
|
|
64
|
+
### Displaying in a Flow page
|
|
63
65
|
|
|
64
66
|
```tsx
|
|
65
67
|
<div>
|
|
66
|
-
<h1>Current
|
|
67
|
-
<p>Route
|
|
68
|
+
<h1>Current Page - {ctx.route.pathname}</h1>
|
|
69
|
+
<p>Route Identifier: {ctx.route.params?.name}</p>
|
|
68
70
|
</div>
|
|
69
71
|
```
|
|
70
72
|
|
|
71
73
|
## Related
|
|
72
74
|
|
|
73
|
-
- [ctx.router](./router.md): navigation
|
|
74
|
-
- [ctx.location](./location.md):
|
|
75
|
+
- [ctx.router](./router.md): Route navigation. When `ctx.router.navigate()` changes the path, `ctx.route` will update accordingly.
|
|
76
|
+
- [ctx.location](./location.md): Current URL location (pathname, search, hash, state), used in conjunction with `ctx.route`.
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
# ctx.router
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A router instance based on React Router, used for programmatic navigation within RunJS. It is typically used in conjunction with `ctx.route` and `ctx.location`.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSBlock / JSField** |
|
|
10
|
-
| **Linkage /
|
|
11
|
-
| **JSAction /
|
|
12
|
-
| **View
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSBlock / JSField** | Navigate to detail pages, list pages, or external links after a button click. |
|
|
10
|
+
| **Linkage Rules / Event Flow** | Execute `navigate` to a list or detail page after successful submission, or pass `state` to the target page. |
|
|
11
|
+
| **JSAction / Event Handling** | Execute route navigation within logic such as form submissions or link clicks. |
|
|
12
|
+
| **View Navigation** | Update the URL via `navigate` during internal view stack switching. |
|
|
13
13
|
|
|
14
|
-
> Note: `ctx.router` is only available in RunJS
|
|
14
|
+
> Note: `ctx.router` is only available in RunJS environments with a routing context (e.g., JSBlock within a page, Flow pages, event flows, etc.); it may be null in pure backend or non-routing contexts (e.g., Workflows).
|
|
15
15
|
|
|
16
|
-
## Type
|
|
16
|
+
## Type Definition
|
|
17
17
|
|
|
18
18
|
```typescript
|
|
19
19
|
router: Router
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
`Router` is from `@remix-run/router
|
|
22
|
+
`Router` is derived from `@remix-run/router`. In RunJS, navigation operations such as jumping, going back, and refreshing are implemented via `ctx.router.navigate()`.
|
|
23
23
|
|
|
24
24
|
## Methods
|
|
25
25
|
|
|
26
26
|
### ctx.router.navigate()
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
Navigates to a target path, or executes a back/refresh action.
|
|
29
29
|
|
|
30
30
|
**Signature:**
|
|
31
31
|
|
|
@@ -35,65 +35,77 @@ navigate(to: string | number | null, options?: RouterNavigateOptions): Promise<v
|
|
|
35
35
|
|
|
36
36
|
**Parameters:**
|
|
37
37
|
|
|
38
|
-
- `to`: Target path (string), relative history position (number, e.g
|
|
39
|
-
- `options`:
|
|
40
|
-
- `replace?: boolean`:
|
|
41
|
-
- `state?: any`: State
|
|
38
|
+
- `to`: Target path (string), relative history position (number, e.g., `-1` to go back), or `null` (to refresh the current page).
|
|
39
|
+
- `options`: Optional configuration.
|
|
40
|
+
- `replace?: boolean`: Whether to replace the current history entry (default is `false`, which pushes a new entry).
|
|
41
|
+
- `state?: any`: State to pass to the target route. This data does not appear in the URL and can be accessed via `ctx.location.state` on the target page. It is suitable for sensitive information, temporary data, or information that should not be placed in the URL.
|
|
42
42
|
|
|
43
43
|
## Examples
|
|
44
44
|
|
|
45
|
-
### Basic
|
|
45
|
+
### Basic Navigation
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
|
+
// Navigate to the user list (pushes a new history entry, allows going back)
|
|
48
49
|
ctx.router.navigate('/admin/users');
|
|
49
50
|
|
|
51
|
+
// Navigate to a detail page
|
|
50
52
|
ctx.router.navigate(`/admin/users/${recordId}`);
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
###
|
|
55
|
+
### Replacing History (No new entry)
|
|
54
56
|
|
|
55
57
|
```ts
|
|
58
|
+
// Redirect to the home page after login; the user won't return to the login page when going back
|
|
56
59
|
ctx.router.navigate('/admin', { replace: true });
|
|
57
60
|
|
|
61
|
+
// Replace the current page with the detail page after successful form submission
|
|
58
62
|
ctx.router.navigate(`/admin/users/${newId}`, { replace: true });
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
###
|
|
65
|
+
### Passing State
|
|
62
66
|
|
|
63
67
|
```ts
|
|
68
|
+
// Carry data during navigation; the target page retrieves it via ctx.location.state
|
|
64
69
|
ctx.router.navigate('/admin/users/123', {
|
|
65
70
|
state: { from: 'dashboard', tab: 'profile' }
|
|
66
71
|
});
|
|
67
72
|
```
|
|
68
73
|
|
|
69
|
-
### Back and
|
|
74
|
+
### Back and Refresh
|
|
70
75
|
|
|
71
76
|
```ts
|
|
77
|
+
// Go back one page
|
|
72
78
|
ctx.router.navigate(-1);
|
|
73
79
|
|
|
80
|
+
// Go back two pages
|
|
74
81
|
ctx.router.navigate(-2);
|
|
75
82
|
|
|
83
|
+
// Refresh the current page
|
|
76
84
|
ctx.router.navigate(null);
|
|
77
85
|
```
|
|
78
86
|
|
|
79
|
-
##
|
|
87
|
+
## Relationship with ctx.route and ctx.location
|
|
80
88
|
|
|
81
|
-
|
|
|
82
|
-
|
|
83
|
-
| **
|
|
84
|
-
| **
|
|
85
|
-
| **
|
|
86
|
-
| **
|
|
89
|
+
| Purpose | Recommended Usage |
|
|
90
|
+
|------|----------|
|
|
91
|
+
| **Navigation/Jumping** | `ctx.router.navigate(path)` |
|
|
92
|
+
| **Read current path** | `ctx.route.pathname` or `ctx.location.pathname` |
|
|
93
|
+
| **Read state passed during navigation** | `ctx.location.state` |
|
|
94
|
+
| **Read route parameters** | `ctx.route.params` |
|
|
87
95
|
|
|
88
|
-
`ctx.router`
|
|
96
|
+
`ctx.router` is responsible for "navigation actions," while `ctx.route` and `ctx.location` are responsible for the "current route state."
|
|
89
97
|
|
|
90
98
|
## Notes
|
|
91
99
|
|
|
92
|
-
- `navigate(path)`
|
|
93
|
-
- `replace: true` replaces the current entry
|
|
94
|
-
-
|
|
100
|
+
- `navigate(path)` pushes a new history entry by default, allowing users to return via the browser's back button.
|
|
101
|
+
- `replace: true` replaces the current history entry without adding a new one, which is suitable for scenarios like post-login redirection or navigation after successful submission.
|
|
102
|
+
- **Regarding the `state` parameter**:
|
|
103
|
+
- Data passed via `state` does not appear in the URL, making it suitable for sensitive or temporary data.
|
|
104
|
+
- It can be accessed via `ctx.location.state` on the target page.
|
|
105
|
+
- `state` is saved in the browser history and remains accessible during forward/backward navigation.
|
|
106
|
+
- `state` will be lost after a hard page refresh.
|
|
95
107
|
|
|
96
108
|
## Related
|
|
97
109
|
|
|
98
|
-
- [ctx.route](./route.md):
|
|
99
|
-
- [ctx.location](./location.md):
|
|
110
|
+
- [ctx.route](./route.md): Current route match information (pathname, params, etc.).
|
|
111
|
+
- [ctx.location](./location.md): Current URL location (pathname, search, hash, state); `state` is read here after navigation.
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# ctx.setValue()
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Sets the value of the current field in editable field scenarios such as JSField and JSItem. Combined with `ctx.getValue()`, it enables two-way binding with the form.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
7
|
| Scenario | Description |
|
|
8
|
-
|
|
9
|
-
| **JSField** | Write user
|
|
10
|
-
| **JSItem** | Update current cell value in
|
|
11
|
-
| **JSColumn** | Update
|
|
8
|
+
|------|------|
|
|
9
|
+
| **JSField** | Write user-selected or calculated values into editable custom fields. |
|
|
10
|
+
| **JSItem** | Update the current cell value in editable items of tables/sub-tables. |
|
|
11
|
+
| **JSColumn** | Update the field value of the corresponding row based on logic during table column rendering. |
|
|
12
12
|
|
|
13
|
-
> Note
|
|
13
|
+
> **Note**: `ctx.setValue(v)` is only available in RunJS contexts with form binding. It is not available in scenarios without field binding, such as FlowEngine, linkage rules, or JSBlock. It is recommended to use optional chaining before use: `ctx.setValue?.(value)`.
|
|
14
14
|
|
|
15
|
-
## Type
|
|
15
|
+
## Type Definition
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
setValue<T = any>(value: T): void;
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
- **
|
|
21
|
+
- **Parameters**: `value` is the field value to be written. The type is determined by the form item type of the field.
|
|
22
22
|
|
|
23
23
|
## Behavior
|
|
24
24
|
|
|
25
|
-
- `ctx.setValue(v)` updates the current field
|
|
26
|
-
- If the form
|
|
25
|
+
- `ctx.setValue(v)` updates the value of the current field in the Ant Design Form and triggers related form linkage and validation logic.
|
|
26
|
+
- If the form has not finished rendering or the field is not registered, the call may be ineffective. It is recommended to use `ctx.getValue()` to confirm the write result.
|
|
27
27
|
|
|
28
28
|
## Examples
|
|
29
29
|
|
|
@@ -42,7 +42,7 @@ ctx.render(
|
|
|
42
42
|
);
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
###
|
|
45
|
+
### Setting default values based on conditions
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
const status = ctx.getValue();
|
|
@@ -51,9 +51,10 @@ if (status == null || status === '') {
|
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
###
|
|
54
|
+
### Writing back to the current field when linked to other fields
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
|
+
// Synchronously update the current field when another field changes
|
|
57
58
|
const otherValue = ctx.form?.getFieldValue('type');
|
|
58
59
|
if (otherValue === 'custom') {
|
|
59
60
|
ctx.setValue?.({ label: 'Custom', value: 'custom' });
|
|
@@ -62,11 +63,11 @@ if (otherValue === 'custom') {
|
|
|
62
63
|
|
|
63
64
|
## Notes
|
|
64
65
|
|
|
65
|
-
- In non-editable
|
|
66
|
-
-
|
|
66
|
+
- In non-editable fields (e.g., JSField in Read-only Mode, JSBlock), `ctx.setValue` may be `undefined`. It is recommended to use `ctx.setValue?.(value)` to avoid errors.
|
|
67
|
+
- When setting values for association fields (M2O, O2M, etc.), you need to pass a structure that matches the field type (e.g., `{ id, [titleField]: label }`), depending on the specific field configuration.
|
|
67
68
|
|
|
68
69
|
## Related
|
|
69
70
|
|
|
70
|
-
- [ctx.getValue()](./get-value.md)
|
|
71
|
-
- [ctx.form](./form.md)
|
|
72
|
-
- `js-field:value-change
|
|
71
|
+
- [ctx.getValue()](./get-value.md) - Get the current field value, used with setValue for two-way binding.
|
|
72
|
+
- [ctx.form](./form.md) - Ant Design Form instance, used to read or write other fields.
|
|
73
|
+
- `js-field:value-change` - A container event triggered when an external value changes, used to update the display.
|
|
@@ -74,7 +74,7 @@ interface FlowSQLRepository {
|
|
|
74
74
|
|
|
75
75
|
| Option | Type | Description |
|
|
76
76
|
|--------|------|-------------|
|
|
77
|
-
| `bind` | `Record<string, any>`
|
|
77
|
+
| `bind` | `Record<string, any>` | Bound variables. Use `$name` in SQL and pass object `{ name: value }` |
|
|
78
78
|
| `type` | `'selectRows'` \| `'selectRow'` \| `'selectVar'` | Result type: multiple rows, single row, single value; default `selectRows` |
|
|
79
79
|
| `dataSourceKey` | `string` | Data source key; default is main data source |
|
|
80
80
|
| `filter` | `Record<string, any>` | Extra filter (if supported) |
|
|
@@ -84,7 +84,7 @@ interface FlowSQLRepository {
|
|
|
84
84
|
| Option | Type | Description |
|
|
85
85
|
|--------|------|-------------|
|
|
86
86
|
| `uid` | `string` | Template unique id; use with `runById(uid, ...)` |
|
|
87
|
-
| `sql` | `string` | SQL text; supports `{{ctx.xxx}}` and
|
|
87
|
+
| `sql` | `string` | SQL text; supports `{{ctx.xxx}}` and `$name` placeholders |
|
|
88
88
|
| `dataSourceKey` | `string` | Optional data source key |
|
|
89
89
|
|
|
90
90
|
## Template Variables and Parameter Binding
|
|
@@ -105,21 +105,13 @@ Variable sources are the same as for `ctx.getVar()` (e.g. `ctx.user.*`, `ctx.rec
|
|
|
105
105
|
|
|
106
106
|
### Parameter binding
|
|
107
107
|
|
|
108
|
-
-
|
|
109
|
-
- **Positional**: use `?` in SQL and pass `bind: [value1, value2]`
|
|
108
|
+
- Use `$name` in SQL and pass `bind: { name: value }`
|
|
110
109
|
|
|
111
110
|
```js
|
|
112
|
-
// Named
|
|
113
111
|
const users = await ctx.sql.run(
|
|
114
|
-
'SELECT * FROM users WHERE status =
|
|
112
|
+
'SELECT * FROM users WHERE status = $status AND age > $minAge',
|
|
115
113
|
{ bind: { status: 'active', minAge: 18 }, type: 'selectRows' }
|
|
116
114
|
);
|
|
117
|
-
|
|
118
|
-
// Positional
|
|
119
|
-
const count = await ctx.sql.run(
|
|
120
|
-
'SELECT COUNT(*) AS total FROM users WHERE city = ? AND status = ?',
|
|
121
|
-
{ bind: ['Beijing', 'active'], type: 'selectVar' }
|
|
122
|
-
);
|
|
123
115
|
```
|
|
124
116
|
|
|
125
117
|
## Examples
|
|
@@ -132,7 +124,7 @@ const rows = await ctx.sql.run('SELECT * FROM users LIMIT 10');
|
|
|
132
124
|
|
|
133
125
|
// Single row
|
|
134
126
|
const user = await ctx.sql.run(
|
|
135
|
-
'SELECT * FROM users WHERE id =
|
|
127
|
+
'SELECT * FROM users WHERE id = $id',
|
|
136
128
|
{ bind: { id: 1 }, type: 'selectRow' }
|
|
137
129
|
);
|
|
138
130
|
|
|
@@ -160,7 +152,7 @@ const rows = await ctx.sql.run(
|
|
|
160
152
|
// Save (requires SQL config permission)
|
|
161
153
|
await ctx.sql.save({
|
|
162
154
|
uid: 'active-users-report',
|
|
163
|
-
sql: 'SELECT * FROM users WHERE status =
|
|
155
|
+
sql: 'SELECT * FROM users WHERE status = $status ORDER BY created_at DESC',
|
|
164
156
|
});
|
|
165
157
|
|
|
166
158
|
// Any logged-in user can run
|
|
@@ -197,7 +189,7 @@ const meta = ctx.resource.getMeta(); // page, pageSize, etc.
|
|
|
197
189
|
|
|
198
190
|
## Notes
|
|
199
191
|
|
|
200
|
-
- Use parameter binding (
|
|
192
|
+
- Use parameter binding (`$name`) instead of string concatenation to avoid SQL injection.
|
|
201
193
|
- With `type: 'selectVar'` the result is a scalar (e.g. for `COUNT`, `SUM`).
|
|
202
194
|
- Template variables `{{ctx.xxx}}` are resolved before execution; ensure the context defines them.
|
|
203
195
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# ctx.t()
|
|
2
2
|
|
|
3
|
-
i18n
|
|
3
|
+
An i18n shortcut function used in RunJS to translate text based on the current context's language settings. It is suitable for internationalizing inline copy such as buttons, titles, and prompts.
|
|
4
4
|
|
|
5
5
|
## Use Cases
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`ctx.t()` can be used in all RunJS execution environments.
|
|
8
8
|
|
|
9
|
-
## Type
|
|
9
|
+
## Type Definition
|
|
10
10
|
|
|
11
11
|
```ts
|
|
12
12
|
t(key: string, options?: Record<string, any>): string
|
|
@@ -16,35 +16,38 @@ t(key: string, options?: Record<string, any>): string
|
|
|
16
16
|
|
|
17
17
|
| Parameter | Type | Description |
|
|
18
18
|
|-----------|------|-------------|
|
|
19
|
-
| `key` | `string` | Translation key or template with placeholders (e.g
|
|
20
|
-
| `options` | `object` | Optional. Interpolation (e.g
|
|
19
|
+
| `key` | `string` | Translation key or template with placeholders (e.g., `Hello {{name}}`, `{{count}} rows`). |
|
|
20
|
+
| `options` | `object` | Optional. Interpolation variables (e.g., `{ name: 'John', count: 5 }`), or i18n options (e.g., `defaultValue`, `ns`). |
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Return Value
|
|
23
23
|
|
|
24
|
-
-
|
|
24
|
+
- Returns the translated string. If no translation exists for the key and no `defaultValue` is provided, it may return the key itself or the interpolated string.
|
|
25
25
|
|
|
26
26
|
## Namespace (ns)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
The **default namespace for the RunJS environment is `runjs`**. When `ns` is not specified, `ctx.t(key)` will look up the key in the `runjs` namespace.
|
|
29
29
|
|
|
30
30
|
```ts
|
|
31
|
-
|
|
31
|
+
// Looks up key from the 'runjs' namespace by default
|
|
32
|
+
ctx.t('Submit'); // Equivalent to ctx.t('Submit', { ns: 'runjs' })
|
|
32
33
|
|
|
34
|
+
// Looks up key from a specific namespace
|
|
33
35
|
ctx.t('Submit', { ns: 'myModule' });
|
|
34
36
|
|
|
37
|
+
// Searches multiple namespaces sequentially (first 'runjs', then 'common')
|
|
35
38
|
ctx.t('Save', { ns: ['runjs', 'common'] });
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
## Examples
|
|
39
42
|
|
|
40
|
-
### Simple
|
|
43
|
+
### Simple Key
|
|
41
44
|
|
|
42
45
|
```ts
|
|
43
46
|
ctx.t('Submit');
|
|
44
47
|
ctx.t('No data');
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
### With
|
|
50
|
+
### With Interpolation Variables
|
|
48
51
|
|
|
49
52
|
```ts
|
|
50
53
|
const text = ctx.t('Hello {{name}}', { name: ctx.user?.nickname || 'Guest' });
|
|
@@ -55,14 +58,14 @@ ctx.render(`<div>${text}</div>`);
|
|
|
55
58
|
ctx.message.success(ctx.t('Processed {{count}} rows', { count: rows.length }));
|
|
56
59
|
```
|
|
57
60
|
|
|
58
|
-
###
|
|
61
|
+
### Dynamic Copy (e.g., Relative Time)
|
|
59
62
|
|
|
60
63
|
```ts
|
|
61
64
|
if (minutes < 60) return ctx.t('{{count}} minutes ago', { count: minutes });
|
|
62
65
|
if (hours < 24) return ctx.t('{{count}} hours ago', { count: hours });
|
|
63
66
|
```
|
|
64
67
|
|
|
65
|
-
###
|
|
68
|
+
### Specifying a Namespace
|
|
66
69
|
|
|
67
70
|
```ts
|
|
68
71
|
ctx.t('Hello {{name}}', { name: 'Guest', ns: 'myModule' });
|
|
@@ -70,10 +73,10 @@ ctx.t('Hello {{name}}', { name: 'Guest', ns: 'myModule' });
|
|
|
70
73
|
|
|
71
74
|
## Notes
|
|
72
75
|
|
|
73
|
-
- **Localization
|
|
74
|
-
- i18next-style interpolation:
|
|
75
|
-
-
|
|
76
|
+
- **Localization Plugin**: To translate text, the Localization plugin must be activated. Missing translation keys will be automatically extracted to the localization management list for unified maintenance and translation.
|
|
77
|
+
- Supports i18next-style interpolation: Use `{{variableName}}` in the key and pass the corresponding variable in `options` to replace it.
|
|
78
|
+
- The language is determined by the current context (e.g., `ctx.i18n.language`, user locale).
|
|
76
79
|
|
|
77
80
|
## Related
|
|
78
81
|
|
|
79
|
-
- [ctx.i18n](./i18n.md):
|
|
82
|
+
- [ctx.i18n](./i18n.md): Read or switch languages
|