@lovrabet/cli 1.1.21 → 1.1.22

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 (65) hide show
  1. package/lib/add-page/input-page-router.js +1 -1
  2. package/lib/add-page/main.js +1 -1
  3. package/lib/add-page/select-page-template.js +1 -1
  4. package/lib/api/api-doc-ui.js +1 -1
  5. package/lib/api/api-doc.js +1 -1
  6. package/lib/api/api-pull-ui.js +1 -1
  7. package/lib/api/fetch-model-list.js +1 -1
  8. package/lib/api/generate-api-file.js +1 -1
  9. package/lib/api/main.js +1 -1
  10. package/lib/api/pull-silent.js +1 -1
  11. package/lib/app-menu/app-menu-sync-ui.js +1 -1
  12. package/lib/app-menu/create-menu.js +1 -1
  13. package/lib/app-menu/get-local-pages.js +1 -1
  14. package/lib/app-menu/get-online-menu-list.js +1 -1
  15. package/lib/app-menu/valid-url.js +1 -1
  16. package/lib/auth/auth-server-ui.js +1 -1
  17. package/lib/auth/auth-server.js +1 -1
  18. package/lib/auth/constant.js +1 -1
  19. package/lib/auth/get-cookie.js +1 -1
  20. package/lib/auth/is-session-valid.js +1 -1
  21. package/lib/auth/logout.js +1 -1
  22. package/lib/cli.js +1 -1
  23. package/lib/cmd/build-watch.js +1 -1
  24. package/lib/cmd/build.js +1 -1
  25. package/lib/cmd/logs.js +1 -1
  26. package/lib/cmd/preview.js +1 -1
  27. package/lib/cmd/start.js +1 -1
  28. package/lib/config/config-help.js +1 -1
  29. package/lib/config/main.js +1 -1
  30. package/lib/constant/domain.js +1 -1
  31. package/lib/constant/env.js +1 -1
  32. package/lib/create-app/enhanced-guided-create.js +1 -1
  33. package/lib/create-app/format-elapsed.js +1 -1
  34. package/lib/create-app/main.js +1 -1
  35. package/lib/create-app/task-finished.js +1 -1
  36. package/lib/create-app/task-loading.js +1 -1
  37. package/lib/create-app/task-running.js +1 -1
  38. package/lib/create-app/task-time.js +1 -1
  39. package/lib/create-app/use-copy-project-template.js +1 -1
  40. package/lib/create-app/use-format-code.js +1 -1
  41. package/lib/create-app/use-install-dependencies.js +1 -1
  42. package/lib/help.js +1 -1
  43. package/lib/init/main.js +1 -1
  44. package/lib/mcp/cursor.js +1 -1
  45. package/lib/mcp/main.js +1 -1
  46. package/lib/utils/config.js +1 -1
  47. package/lib/utils/copy-directory.js +1 -1
  48. package/lib/utils/http-client.js +1 -1
  49. package/lib/utils/logger.js +1 -1
  50. package/lib/utils/router-updater.js +1 -1
  51. package/lib/utils/sleep.js +1 -1
  52. package/lib/utils/template-replacer.js +1 -1
  53. package/package.json +1 -1
  54. package/templates/projects/sub-app-react-demo/CHANGELOG.md +16 -0
  55. package/templates/projects/sub-app-react-demo/README.md +163 -54
  56. package/templates/projects/sub-app-react-demo/package-lock.json +1347 -149
  57. package/templates/projects/sub-app-react-demo/package.json +2 -2
  58. package/templates/projects/sub-app-react-demo/src/layouts/MainLayout.tsx +286 -55
  59. package/templates/projects/sub-app-react-demo/src/pages/data-screen/index.tsx +526 -0
  60. package/templates/projects/sub-app-react-demo/src/pages/index.tsx +942 -87
  61. package/templates/projects/sub-app-react-demo/src/pages/intro/index.tsx +560 -0
  62. package/templates/projects/sub-app-react-demo/src/pages/sdk-demo/index.tsx +113 -118
  63. package/templates/projects/sub-app-react-demo/src/pages/workbench/index.tsx +469 -0
  64. package/templates/projects/sub-app-react-demo/src/style.css +39 -0
  65. package/templates/projects/sub-app-react-demo/bun.lock +0 -600
@@ -12,9 +12,8 @@ import {
12
12
  } from "antd";
13
13
  import { ApiOutlined } from "@ant-design/icons";
14
14
  import { lovrabetClient } from "../../api/client";
15
- import { SortOrder } from "@lovrabet/sdk";
16
15
 
17
- const { Title, Paragraph } = Typography;
16
+ const { Title, Paragraph, Text } = Typography;
18
17
 
19
18
  export default function SdkDemo() {
20
19
  const [loading, setLoading] = useState(false);
@@ -44,9 +43,9 @@ export default function SdkDemo() {
44
43
  }, []);
45
44
 
46
45
  /**
47
- * 语法糖模式 - 最优雅的调用方式
46
+ * 使用 filter 接口查询数据
48
47
  */
49
- const loadDataWithSyntaxSugar = async () => {
48
+ const loadData = async () => {
50
49
  if (!selectedModel) {
51
50
  message.warning("请先选择一个数据模型");
52
51
  return;
@@ -55,67 +54,68 @@ export default function SdkDemo() {
55
54
  setLoading(true);
56
55
 
57
56
  try {
58
- // 1. 直接通过模型名访问 - 最优雅的方式
59
- const response = await lovrabetClient.models[selectedModel].getList({
57
+ // 使用 filter 接口进行查询
58
+ const response = await lovrabetClient.models[selectedModel].filter({
60
59
  currentPage: 1,
61
60
  pageSize: 10,
62
61
  });
63
62
 
64
- processResponse(response, "语法糖模式调用成功!");
63
+ processResponse(response, "查询成功!");
65
64
  } catch (error: any) {
66
- handleError(error, "语法糖模式");
65
+ handleError(error, "查询");
67
66
  } finally {
68
67
  setLoading(false);
69
68
  }
70
69
  };
71
70
 
72
71
  /**
73
- * 正常调用模式 - 编程式调用方式
72
+ * 处理响应数据
74
73
  */
75
- const loadDataWithNormalMode = async () => {
76
- if (!selectedModel) {
77
- message.warning("请先选择一个数据模型");
78
- return;
79
- }
80
-
81
- setLoading(true);
82
-
74
+ const processResponse = (response: any, successMessage: string) => {
83
75
  try {
84
- // 1. 先获取模型实例
85
- const model = lovrabetClient.getModel(selectedModel);
76
+ // filter 接口返回的数据结构
77
+ const tableData = response?.tableData || response?.data || [];
78
+
79
+ // 确保 tableData 是数组
80
+ if (!Array.isArray(tableData)) {
81
+ console.error("返回的数据不是数组格式:", tableData);
82
+ message.error("返回数据格式错误,请检查 API 响应");
83
+ return;
84
+ }
86
85
 
87
- // 2. 调用模型方法
88
- const response = await model.getList({
89
- currentPage: 1,
90
- pageSize: 10,
91
- });
86
+ setData(tableData);
87
+
88
+ // 优先使用 tableColumns 配置
89
+ if (response?.tableColumns && Array.isArray(response.tableColumns)) {
90
+ // 如果有 tableColumns,优先使用它
91
+ const tableColumns = response.tableColumns.map((column: any) => ({
92
+ title:
93
+ column.title || column.dataIndex || column.key || String(column),
94
+ dataIndex: column.dataIndex || column.key || String(column),
95
+ key: column.dataIndex || column.key || String(column),
96
+ }));
97
+ setColumns(tableColumns);
98
+ } else if (tableData.length > 0) {
99
+ // 如果没有 tableColumns,从第一条数据中提取字段名作为列
100
+ const firstRow = tableData[0];
101
+ if (firstRow && typeof firstRow === "object") {
102
+ const tableColumns = Object.keys(firstRow).map((key) => ({
103
+ title: key,
104
+ dataIndex: key,
105
+ key: key,
106
+ }));
107
+ setColumns(tableColumns);
108
+ }
109
+ } else {
110
+ // 如果没有数据也没有列定义,清空列
111
+ setColumns([]);
112
+ }
92
113
 
93
- processResponse(response, "正常模式调用成功!");
114
+ message.success(successMessage);
94
115
  } catch (error: any) {
95
- handleError(error, "正常模式");
96
- } finally {
97
- setLoading(false);
98
- }
99
- };
100
-
101
- /**
102
- * 处理响应数据
103
- */
104
- const processResponse = (response: any, successMessage: string) => {
105
- // 处理返回的数据
106
- setData(response.tableData || []);
107
-
108
- // 动态生成表格列
109
- if (response.tableColumns) {
110
- const tableColumns = response.tableColumns.map((column: any) => ({
111
- title: column.title || column.dataIndex,
112
- dataIndex: column.dataIndex,
113
- key: column.dataIndex,
114
- }));
115
- setColumns(tableColumns);
116
+ console.error("处理响应数据失败:", error);
117
+ message.error(`处理数据失败: ${error.message}`);
116
118
  }
117
-
118
- message.success(successMessage);
119
119
  };
120
120
 
121
121
  /**
@@ -157,9 +157,9 @@ export default function SdkDemo() {
157
157
  /**
158
158
  * 处理错误
159
159
  */
160
- const handleError = (error: any, mode: string) => {
161
- console.error(`${mode}加载失败:`, error);
162
- message.error(`${mode}加载失败: ${error.message}`);
160
+ const handleError = (error: any, action: string) => {
161
+ console.error(`${action}失败:`, error);
162
+ message.error(`${action}失败: ${error.message}`);
163
163
  };
164
164
 
165
165
  return (
@@ -170,7 +170,8 @@ export default function SdkDemo() {
170
170
  </Title>
171
171
 
172
172
  <Paragraph style={{ color: "#666", marginBottom: 24 }}>
173
- 演示 Lovrabet SDK 的两种调用方式。对比体验语法糖模式和正常模式的差异。
173
+ 演示 Lovrabet SDK 的 <Text strong>filter</Text> 接口使用方法。filter
174
+ 接口支持复杂条件查询、字段选择、多字段排序等功能。
174
175
  <br />
175
176
  <strong>注意:</strong>代码示例中的 "Requirements"
176
177
  是假设已经存在的数据模型名称,实际使用时请根据下拉框中的可用模型进行选择。
@@ -192,84 +193,61 @@ export default function SdkDemo() {
192
193
  <Button
193
194
  type="primary"
194
195
  loading={loading}
195
- onClick={loadDataWithSyntaxSugar}
196
+ onClick={loadData}
196
197
  icon={<ApiOutlined />}
197
198
  disabled={!selectedModel}
198
199
  >
199
- 🍬 语法糖模式查询
200
- </Button>
201
- <Button
202
- loading={loading}
203
- onClick={loadDataWithNormalMode}
204
- icon={<ApiOutlined />}
205
- disabled={!selectedModel}
206
- >
207
- 🔧 正常模式查询
200
+ 查询数据
208
201
  </Button>
209
202
  </Space>
210
203
  </Card>
211
204
 
212
205
  {/* 代码示例 */}
213
- <Card title="两种调用方式对比" size="small" style={{ marginBottom: 16 }}>
214
- <div style={{ display: "flex", gap: "16px" }}>
215
- {/* 语法糖模式 */}
216
- <div style={{ flex: 1 }}>
217
- <div
218
- style={{
219
- fontWeight: "bold",
220
- marginBottom: "8px",
221
- color: "#1890ff",
222
- }}
223
- >
224
- 🍬 语法糖模式(推荐)
225
- </div>
226
- <pre
227
- style={{
228
- background: "#f0f8ff",
229
- padding: "12px",
230
- borderRadius: "4px",
231
- margin: 0,
232
- fontSize: "13px",
233
- border: "1px solid #1890ff",
234
- }}
235
- >
236
- {`// 一行代码搞定!
206
+ <Card title="代码示例" size="small" style={{ marginBottom: 16 }}>
207
+ <pre
208
+ style={{
209
+ background: "#f0f8ff",
210
+ padding: "16px",
211
+ borderRadius: "4px",
212
+ margin: 0,
213
+ fontSize: "13px",
214
+ border: "1px solid #1890ff",
215
+ overflow: "auto",
216
+ }}
217
+ >
218
+ {`// 基础查询(仅分页)
237
219
  const response = await lovrabetClient
238
- .models.${selectedModel || "Requirements"}.getList({
220
+ .models.${selectedModel || "Requirements"}.filter({
239
221
  currentPage: 1,
240
222
  pageSize: 10
241
- });`}
242
- </pre>
243
- </div>
223
+ });
244
224
 
245
- {/* 正常模式 */}
246
- <div style={{ flex: 1 }}>
247
- <div
248
- style={{ fontWeight: "bold", marginBottom: "8px", color: "#666" }}
249
- >
250
- 🔧 正常模式
251
- </div>
252
- <pre
253
- style={{
254
- background: "#f5f5f5",
255
- padding: "12px",
256
- borderRadius: "4px",
257
- margin: 0,
258
- fontSize: "13px",
259
- border: "1px solid #d9d9d9",
260
- }}
261
- >
262
- {`// 分步骤调用
263
- const model = lovrabetClient
264
- .getModel('${selectedModel || "Requirements"}');
265
-
266
- const response = await model.getList({
267
- currentPage: 1,
268
- pageSize: 10
269
- });`}
270
- </pre>
271
- </div>
272
- </div>
225
+ // 完整查询示例(所有参数均为可选,根据实际字段使用)
226
+ const response = await lovrabetClient
227
+ .models.${selectedModel || "Requirements"}.filter({
228
+ // where: 条件查询(可选)
229
+ // where: {
230
+ // age: { $gte: 18 },
231
+ // status: { $eq: 'active' }
232
+ // },
233
+
234
+ // select: 字段选择(可选)
235
+ // select: ['id', 'name', 'age'],
236
+
237
+ // orderBy: 排序(可选)
238
+ // orderBy: [{ createTime: 'desc' }],
239
+
240
+ // 分页参数(必需)
241
+ currentPage: 1,
242
+ pageSize: 10
243
+ });
244
+
245
+ // 其他可用参数(仅示例,以实际字段为准):
246
+ // - where: 支持 $eq, $ne, $gte, $lte, $in, $contain, $startWith, $endWith 等操作符
247
+ // - where: 支持 $and, $or 逻辑组合
248
+ // - select: 数组形式,指定返回的字段
249
+ // - orderBy: 数组形式,支持多字段排序 [{ field1: 'desc' }, { field2: 'asc' }]`}
250
+ </pre>
273
251
  </Card>
274
252
 
275
253
  {/* 数据表格 */}
@@ -400,6 +378,23 @@ const options = await lovrabetClient
400
378
  </pre>
401
379
  </Card>
402
380
  )}
381
+
382
+ {/* API 参考文档 */}
383
+ <Card size="small" style={{ marginTop: 24, background: "#f5f5f5" }}>
384
+ <Paragraph style={{ margin: 0, textAlign: "center" }}>
385
+ <Text type="secondary">
386
+ API 详细参考使用手册:{" "}
387
+ <a
388
+ href="https://open.lovrabet.com/docs/category/lovrabet-node-sdk/api-usage"
389
+ target="_blank"
390
+ rel="noopener noreferrer"
391
+ style={{ color: "#1890ff" }}
392
+ >
393
+ https://open.lovrabet.com/docs/category/lovrabet-node-sdk/api-usage
394
+ </a>
395
+ </Text>
396
+ </Paragraph>
397
+ </Card>
403
398
  </div>
404
399
  );
405
400
  }