openxiangda 1.0.40 → 1.0.42

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/README.md CHANGED
@@ -108,6 +108,18 @@ openxiangda workspace bind --profile dev --app-type APP_XXXX
108
108
 
109
109
  表单页、流程表单页和自定义代码页都应在 `sy-lowcode-app-workspace` 中实现,由 `openxiangda workspace publish --profile <name>` 统一构建、上传 OSS 并注册到平台。`openxiangda form create`、`form publish`、`page publish` 只作为底层修复/诊断命令,不作为 AI 生成页面的主入口。
110
110
 
111
+ 运行时页面读取当前用户信息时,优先使用 `sdk.user.getCurrent<PageUserRecord>()`。用户对象会返回常规组织成员关系 `departments`,也会返回系统维护的所属单位字段 `affiliatedDepartmentId` / `affiliatedDepartment`。`departments` 表示用户真实所在的部门、班级、专业等成员关系;`affiliatedDepartment` 表示业务上用于统计、筛选和展示的归属单位,通常是学院、单位或在源单位缺失时可用的具体部门节点,不用于替代权限部门成员关系。
112
+
113
+ ```ts
114
+ import type { PageUserRecord } from "openxiangda/runtime"
115
+
116
+ const currentUser = await sdk.user.getCurrent<PageUserRecord>()
117
+ const user = currentUser.result
118
+
119
+ const affiliatedDepartmentName = user?.affiliatedDepartment?.name
120
+ const affiliatedDepartmentExternalId = user?.affiliatedDepartment?.externalId
121
+ ```
122
+
111
123
  工程化资源放在工作区 `src/resources/` 下,由 `openxiangda resource validate|plan|publish|pull` 管理。`workspace publish` 会先构建并注册 workspace 表单/页面,再执行非破坏性资源 upsert,这样菜单、权限组、流程和表单设置可以解析最新的 profile-local ID。需要删除平台中 manifest 未声明的资源时,显式传 `--prune`。连接器页面运行时通过 `sdk.connector.invoke()` / `sdk.connector.call("connector.api")` 调用平台运行时接口,第三方密钥只保存在后端连接器配置中。
112
124
 
113
125
  多表只读查询和固定口径统计优先声明 `src/resources/data-views/*.json` 数据视图,而不是在页面里手写多次单表查询再拼数据。默认数据视图是行级联表视图,适合工单+客户、订单+商品、项目+成员、报表列表、跨页面复用查询等读多写少场景;`viewType: "aggregate"` 是统计聚合视图,适合按客户、状态、月份等维度预聚合 count/sum/avg/min/max。发布时 CLI 会把 `formCode` 解析为当前 profile 的 `formUuid`,平台创建 PostgreSQL materialized view;页面通过 `sdk.dataView.query(code, params)` 查询行级视图,通过 `sdk.dataView.stats(code, params)` 查询聚合视图,也可以用 `sdk.dataSource.run()` 路由 `dataView.query` / `dataView.stats`。发布前应为常用筛选、排序、统计维度和时间桶声明 `indexes`,并确认用户能接受的刷新延迟;默认不要设置低于 5 分钟的定时刷新。数据视图只读,刷新后才反映源表变化,不适合单表 CRUD、写回源表、强实时状态、临时 BI 查询或简单 linkedForm 下拉。
package/lib/cli.js CHANGED
@@ -2310,7 +2310,7 @@ async function permission(args) {
2310
2310
  const target = getWorkspaceTarget(config, profileName, flags);
2311
2311
  const formUuid = flags['form-uuid'] || resolveOptionalFormUuid(target.bound, flags['form-code']);
2312
2312
  if (!groupCode || !name || !formUuid) {
2313
- fail('用法: openxiangda permission form-group-create <groupCode> --form-code <formCode>|--form-uuid <FORM_XXX> --name <text> --type <submit|view>');
2313
+ fail('用法: openxiangda permission form-group-create <groupCode> --form-code <formCode>|--form-uuid <FORM_XXX> --name <text> --type <submit|view> [--field-access-policy-json <file|json>]');
2314
2314
  }
2315
2315
  const data = await requestWithAuth(
2316
2316
  config,
@@ -2334,6 +2334,14 @@ async function permission(args) {
2334
2334
  ),
2335
2335
  }
2336
2336
  : {}),
2337
+ ...(flags['field-access-policy-json']
2338
+ ? {
2339
+ fieldAccessPolicy: readJsonArg(
2340
+ flags['field-access-policy-json'],
2341
+ 'field-access-policy-json'
2342
+ ),
2343
+ }
2344
+ : {}),
2337
2345
  ...(flags['data-permission-json']
2338
2346
  ? {
2339
2347
  dataPermission: readJsonArg(
@@ -458,10 +458,17 @@ Body:
458
458
  "dataScope": [{ "type": "self" }],
459
459
  "operations": ["view"],
460
460
  "fieldPermissions": [],
461
+ "fieldAccessPolicy": {
462
+ "defaultAccess": "edit",
463
+ "fields": [{ "fieldId": "internalRemark", "access": "readonly" }]
464
+ },
461
465
  "dataPermission": null
462
466
  }
463
467
  ```
464
468
 
469
+ `fieldPermissions` is only the frontend display-default state. Use
470
+ `fieldAccessPolicy` for backend-enforced field access.
471
+
465
472
  ### GET `/apps/:appType/forms/:formUuid/permission-groups/:groupId`
466
473
 
467
474
  Requires Bearer token. Returns form permission group detail.
@@ -86,20 +86,43 @@ View group:
86
86
  "fieldPermissions": [
87
87
  {
88
88
  "componentName": "Text",
89
- "fieldName": "客户名称",
90
- "label": "customerName",
89
+ "fieldName": "customerName",
90
+ "label": "客户名称",
91
91
  "value": "FORM_FILED_VIEW"
92
92
  }
93
- ]
93
+ ],
94
+ "fieldAccessPolicy": {
95
+ "defaultAccess": "edit",
96
+ "fields": [
97
+ { "fieldId": "internalRemark", "access": "readonly" },
98
+ { "fieldId": "marginAmount", "access": "hidden" }
99
+ ]
100
+ }
94
101
  }
95
102
  ```
96
103
 
97
- Field permission values:
104
+ `fieldPermissions` remains a frontend display-default setting. Do not treat it as real data
105
+ read/write permission. Real backend field access is controlled by `fieldAccessPolicy`.
106
+
107
+ Frontend display-default field permission values:
98
108
 
99
109
  - `FORM_FILED_EDIT`
100
110
  - `FORM_FILED_VIEW`
101
111
  - `FORM_FILED_HIDDEN`
102
112
 
113
+ Real field access policy:
114
+
115
+ - `defaultAccess`: one of `edit`, `readonly`, `hidden`; omitted/null policies are equivalent
116
+ to `{ "defaultAccess": "edit", "fields": [] }`.
117
+ - `fields`: exception list keyed by schema field ID, such as `textField_xxx`; only store
118
+ fields whose access differs from `defaultAccess`.
119
+ - `edit` means visible and editable.
120
+ - `readonly` means visible but not editable.
121
+ - `hidden` means not visible and not editable.
122
+ - If multiple matched view groups apply to the same user, field access merges by
123
+ `edit > readonly > hidden`.
124
+ - App administrators bypass `fieldAccessPolicy`.
125
+
103
126
  Common data scopes:
104
127
 
105
128
  - `all`
@@ -82,10 +82,15 @@ openxiangda permission form-group-create sales_limited \
82
82
  --roles sales \
83
83
  --data-scope-json data-scope.json \
84
84
  --field-permissions-json fields.json \
85
+ --field-access-policy-json field-access-policy.json \
85
86
  --data-permission-json data-permission.json \
86
87
  --profile dev
87
88
  ```
88
89
 
90
+ `fieldPermissions` is the frontend display-default state. Use `fieldAccessPolicy`
91
+ for real backend read/write field access (`edit`, `readonly`, `hidden`) with
92
+ `defaultAccess` plus field-ID exceptions.
93
+
89
94
  ## Inspection
90
95
 
91
96
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openxiangda",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "OpenXiangda CLI, workspace build tools, runtime SDK, and form components.",
5
5
  "private": false,
6
6
  "bin": {
@@ -2276,7 +2276,8 @@ var useCurrentUser = () => {
2276
2276
  isGuest,
2277
2277
  isInternalUser: !isGuest,
2278
2278
  displayName: user.name || user.username || user.id,
2279
- primaryDepartment: user.departments?.[0] || null
2279
+ primaryDepartment: user.departments?.[0] || null,
2280
+ affiliatedDepartment: user.affiliatedDepartment || null
2280
2281
  };
2281
2282
  }, [user]);
2282
2283
  };