devfab 1.0.0 → 1.1.0
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 +290 -147
- package/dist/common/models.esm.js +1 -0
- package/dist/common/models.js +1 -0
- package/dist/common/utils.esm.js +1 -0
- package/dist/common/utils.js +1 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.umd.js +1 -1
- package/lib/devfab.js +92 -80
- package/lib/devfab.min.js +1 -1
- package/lib/requirejs.js +2473 -2472
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,147 +1,290 @@
|
|
|
1
|
-
# devfab
|
|
2
|
-
|
|
3
|
-
低代码「开发者工厂」的浏览器运行时库。
|
|
4
|
-
|
|
5
|
-
链路:后端按 `billno` 下发视图元数据 JSON → `builder.render(meta)` 渲染成组件树 → 各 adapter 把第三方控件包成「受模型驱动、状态可被外部 `setState` / `getState` 读写」的受控组件。
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
`
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1
|
+
# devfab
|
|
2
|
+
|
|
3
|
+
低代码「开发者工厂」的浏览器运行时库。
|
|
4
|
+
|
|
5
|
+
链路:后端按 `billno` 下发视图元数据 JSON → `builder.render(meta)` 渲染成组件树 → 各 adapter 把第三方控件包成「受模型驱动、状态可被外部 `setState` / `getState` 读写」的受控组件。
|
|
6
|
+
|
|
7
|
+
- 源码纯 JavaScript(`.js` / `.jsx`),无 TypeScript、不产出类型声明
|
|
8
|
+
- React 与 Vue 3 双适配层,共用一个与框架无关的模型层(`BaseModel` 体系)
|
|
9
|
+
- 通过 RequireJS 加载领域扩展脚本,实现「元数据 + 扩展脚本」的二次开发模式
|
|
10
|
+
|
|
11
|
+
## 目录结构
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
src/
|
|
15
|
+
├── index.js 包入口:组装 builder / models / utils
|
|
16
|
+
├── _models/ 模型层(与框架无关)
|
|
17
|
+
│ ├── BaseModel.js 状态容器基类:_data 读写、状态推送、事件、缓存、代理
|
|
18
|
+
│ ├── SimpleModel.js 单字段受控模型
|
|
19
|
+
│ ├── ViewModel.js 页面级容器:子模型登记与数据收集
|
|
20
|
+
│ ├── FilterModel.js 筛选条件容器
|
|
21
|
+
│ ├── GridModel.js 表格模型(两层数据 / 行状态 / 分页 / 选中 / 校验)
|
|
22
|
+
│ └── index.js 模型工厂 createViewModel / initViewModel
|
|
23
|
+
├── _utils/
|
|
24
|
+
│ ├── builder.js 组件注册表 + 渲染工厂(模块级单例)
|
|
25
|
+
│ ├── event.js 事件总线(同步 execute + 异步 promiseExecute)
|
|
26
|
+
│ ├── cache.js 键值缓存
|
|
27
|
+
│ ├── dynamicProxy.js 把接口配置映射成可调用的方法
|
|
28
|
+
│ ├── ajax.js XHR / JSONP 请求封装
|
|
29
|
+
│ └── string.js URL 拼接、QueryString、uid 生成、base64
|
|
30
|
+
├── _lib/requirejs.js vendored RequireJS 2.3.2 + 扩展脚本适配层
|
|
31
|
+
├── react/
|
|
32
|
+
│ ├── index.js React 适配层入口
|
|
33
|
+
│ └── adapter/
|
|
34
|
+
│ ├── common/ refAdapter / labelAdapter / loadMetaAdapter / dataSourceAdapter / modalAdapter
|
|
35
|
+
│ └── model/ modelAdapter / pageAdapter / dataSourceAdapter / filterAdapter
|
|
36
|
+
└── vue/
|
|
37
|
+
├── index.js Vue 适配层占位(未参与构建)
|
|
38
|
+
└── vue-adapter/ Vue 3 适配层:class-adapter / function-adapter
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`dist/` 与 `lib/` 是构建产物,已移出版本控制,不要手改;改完源码重新构建。
|
|
42
|
+
|
|
43
|
+
## 安装
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm install devfab
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
外部依赖由宿主提供,不打进产物(见 `peerDependencies`):
|
|
50
|
+
|
|
51
|
+
- React 侧:`react` >= 16 / `react-dom` >= 16 / `classnames`
|
|
52
|
+
- Vue 侧:`vue` >= 3(**仅支持 Vue 3**,适配层使用 `defineComponent` / `reactive` / `h`)
|
|
53
|
+
- `antd` 在构建配置里被列为 React 产物的 `external`,但未写进 `peerDependencies`,宿主需自行保证存在
|
|
54
|
+
|
|
55
|
+
## 开发与构建
|
|
56
|
+
|
|
57
|
+
| 命令 | 说明 |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `npm run dev` | 清理后以 development 模式构建(产物不压缩,便于调试) |
|
|
60
|
+
| `npm run build` | 清理 → 生产构建(压缩产物) |
|
|
61
|
+
| `npm run smoke` | 产物冒烟测试(零依赖脚本,需先 `npm run build`) |
|
|
62
|
+
| `npm run lint` / `npm run lint:fix` | ESLint 检查 / 自动修复 |
|
|
63
|
+
| `npm run format` / `npm run format:check` | Prettier 格式化 / 校验 |
|
|
64
|
+
| `npm run clean` | 删除 `dist` 与 `lib` |
|
|
65
|
+
|
|
66
|
+
构建用 Rollup 多入口配置(`rollup.config.js`),每个入口产出 CJS / ESM(部分含 UMD)。几处需要注意的编译边界:
|
|
67
|
+
|
|
68
|
+
- React 侧 JSX 走 `@babel/preset-react`(编译成 `createElement`);Vue 侧 JSX 走 `@vue/babel-plugin-jsx`(编译成 `createVNode`)。两套 babel 配置不能混用。
|
|
69
|
+
- `resolve.extensions` 显式加入了 `.jsx` —— 适配层文件名是 `.jsx`,但内部 import 不带扩展名。
|
|
70
|
+
- `babelHelpers: 'bundled'` 内联 helper,避免 `preserveModules` 产物在 CJS 里 `require` ESM 版 `@babel/runtime` helper。
|
|
71
|
+
|
|
72
|
+
## 产物清单
|
|
73
|
+
|
|
74
|
+
| 路径 | 格式 | 说明 |
|
|
75
|
+
| --- | --- | --- |
|
|
76
|
+
| `lib/devfab.js` | UMD | 核心运行时,`<script>` 引入后挂到 `window.devfab`;始终不压缩,便于排查 |
|
|
77
|
+
| `lib/devfab.min.js` | UMD | 压缩版,任何构建模式都产出 |
|
|
78
|
+
| `lib/requirejs.js` | — | vendored RequireJS,挂 `window.require` / `window.define` 与 `window.__devfab` |
|
|
79
|
+
| `dist/index.js` `.esm.js` `.umd.js` | CJS / ESM / UMD | 核心包入口,对应 `package.json` 的 `main` / `module` / `umd` |
|
|
80
|
+
| `dist/react/**` | CJS(`preserveModules`,保留 `src/react` 目录结构) | React 适配层 |
|
|
81
|
+
| `dist/vue/vue3-adapter.js` `.esm.js` | CJS / ESM | Vue 3 适配层,由宿主显式 import,不产出 UMD、不挂全局 |
|
|
82
|
+
| `dist/common/models.js` `.esm.js` | CJS / ESM | 模型层单独入口,可脱离框架使用 |
|
|
83
|
+
| `dist/common/utils.js` `.esm.js` | CJS / ESM | 工具层单独入口 |
|
|
84
|
+
|
|
85
|
+
## 运行时契约
|
|
86
|
+
|
|
87
|
+
React 适配层从**全局**读取运行时:`src/react/adapter/**` 里直接使用裸标识符 `devfab.builder`、`devfab.utils.models`,编译后原样保留,运行时解析到 `window.devfab`。因此宿主必须先准备好全局运行时,再加载适配层组件:
|
|
88
|
+
|
|
89
|
+
```html
|
|
90
|
+
<script src="..../lib/requirejs.js"></script>
|
|
91
|
+
<script src="..../lib/devfab.js"></script>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 模型层
|
|
95
|
+
|
|
96
|
+
### `BaseModel` —— 状态容器基类
|
|
97
|
+
|
|
98
|
+
所有模型共享的底座,数据统一放在 `_data` 里(`_set_data` / `_get_data` / `_del_data` / `_cls_data`)。
|
|
99
|
+
|
|
100
|
+
| 分组 | 方法 |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| 取值 | `getValue` / `getData` / `get(name)` / `getState(name, ctrlName)` |
|
|
103
|
+
| 赋值 | `setValue(value, fireEvent, ctrlName)` / `setState(name, value, ctrlName)` / `setVisible` / `setDisabled` |
|
|
104
|
+
| 控件登记 | `addComponent(component, ctrlName)` / `removeComponent` / `doPropertyChange` |
|
|
105
|
+
| 父子关系 | `setParent` / `getParent` / `getRootParent` / `setName` / `getName` |
|
|
106
|
+
| 脏检查 | `setDirty` / `getDirtyData(necessary)` / `clear(useDefault)` |
|
|
107
|
+
| 事件 | `on` / `onFirst` / `un` / `hasEvent` / `execute` / `fireEvent` / `promiseExecute` |
|
|
108
|
+
| 缓存 | `setCache` / `getCache` / `clearCache` |
|
|
109
|
+
| 请求代理 | `setProxy(config)` / `getProxy()` |
|
|
110
|
+
|
|
111
|
+
状态推送的核心是 `_applyState(name, value, ctrlName)`:优先调用控件的 `setXxx`(如 `setValue`),控件没实现就退回 `setState({ [name]: value })`。传 `ctrlName` 可定向通知,只推给匹配的控件。
|
|
112
|
+
|
|
113
|
+
`setValue` 支持事件拦截:传 `fireEvent`(或模型上标记 `forceFireEvent`)时走 `promiseExecute('beforeValueChange', ...)`,先跑 `beforeValueChange` 监听,通过后才写入并触发 `afterValueChange`,任一步返回 `false` 则回滚成旧值。
|
|
114
|
+
|
|
115
|
+
### 四个具体模型
|
|
116
|
+
|
|
117
|
+
| 类 | 职责 |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `SimpleModel` | 单字段受控模型,补充 `setReadonly` / `getReadonly` |
|
|
120
|
+
| `ViewModel` | 页面级容器:`addProperty` 登记子模型,`getData` / `getAllData(withOutGrid)` 收集数据,`getGridModel` / `getGridModels` 定位子表格,`loadData` 批量灌数据 |
|
|
121
|
+
| `FilterModel` | 筛选条件容器:`mounted` 按 `conditions` 初始化条件模型,`getParams` 收集条件,`search()` 触发查询事件 |
|
|
122
|
+
| `GridModel` | 表格模型,见下 |
|
|
123
|
+
|
|
124
|
+
### `GridModel`
|
|
125
|
+
|
|
126
|
+
参照中台 `mdf-cube/src/models/GridModel.js` 重写,把它的约定搬进 devfab 的 ui-model 体系(文件头注释里有完整对照说明):
|
|
127
|
+
|
|
128
|
+
- 两层数据:`dataSource`(全量)+ `rows`(当前展示行,本地模式下是 `dataSource` 的分页切片)
|
|
129
|
+
- 行状态与数据同序:`rowsDataState[i]` 对应 `dataSource[i]`,取值见 `DataStates`(`''` / `Insert` / `Update` / `Delete`)
|
|
130
|
+
- 内部字段:`_id` / `_selected` / `_status`
|
|
131
|
+
- 列是 **object map**(key = `field`)而非数组,渲染 vxe-grid 时用 `getColumnList()` 转数组
|
|
132
|
+
- 分页状态叫 `pageInfo`(`pageIndex` / `pageSize` / `pageCount` / `recordCount`),`pageSize = -1` 表示不分页
|
|
133
|
+
- 选中分两层:当前页 `_selected` 标记 + 跨页选中缓存
|
|
134
|
+
- 提供 `insertRow` / `appendRow` / `updateRow` / `deleteRows` / `clear`、`getDirtyData` / `backupState` / `restoreState`、`getCellValue` / `setCellValue` / `setCellState`、`validate` 等
|
|
135
|
+
|
|
136
|
+
与中台实现的有意差异:取数直接用 `proxyConfig.load`(兼容旧的 `dataSource: fn` / `cUrl`);`setRows` 推原始行对象而非 `getShowRows()` 展示副本(否则选中回灌与单元格编辑会落到副本上);未移植中台的行模型(editRowModel / ReferModel / 特征 / 孙表)。
|
|
137
|
+
|
|
138
|
+
### 模型工厂
|
|
139
|
+
|
|
140
|
+
`_models/index.js` 提供两个入口,用于按元数据批量造模型:
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
import { createViewModel, initViewModel } from 'devfab/dist/common/models'
|
|
144
|
+
|
|
145
|
+
// 返回 VM 类,可自行 new + init
|
|
146
|
+
const VM = createViewModel(meta, params)
|
|
147
|
+
// 直接返回实例:内部已执行 init(meta.models, meta)
|
|
148
|
+
const vm = initViewModel(meta, params)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
`params` 可配置:`domainKeyField` / `billNoField` / `modelNameField`(默认 `domainKey` / `billNo` / `modelName`)、`enableExtendjs`(是否加载扩展脚本)、`require`(覆盖 require 实现)、`createModelFactory`(自定义控件类型的模型映射)、`onBeforeCreateModel`(造模型前的钩子)。
|
|
152
|
+
|
|
153
|
+
创建后 `initData()` → `initExtendJs()` 会加载 `${billno}_VM.Extend.js` 并执行其 `doAction('init', vm)`;无论成功失败都会抛出 `extendReady` 事件,宿主可监听它作为「渲染就绪」信号。
|
|
154
|
+
|
|
155
|
+
## `builder` —— 组件注册与渲染
|
|
156
|
+
|
|
157
|
+
`_utils/builder.js` 是模块级单例(`isInit` / `components` / `renderFactory` 都在模块作用域),一个页面只能存在一份。
|
|
158
|
+
|
|
159
|
+
| 方法 | 说明 |
|
|
160
|
+
| --- | --- |
|
|
161
|
+
| `init(fn)` | 只执行一次的初始化钩子 |
|
|
162
|
+
| `initComponent(name, comp)` / `initComponent({ Name: comp })` | 注册组件,支持单个或对象批量;重名只告警不覆盖 |
|
|
163
|
+
| `getComponent` / `hasComponent` / `getComponents` | 读取注册表 |
|
|
164
|
+
| `initRenderFactory(fn)` | 注入「元数据节点 → 框架元素」的转换函数,**必须由宿主提供** |
|
|
165
|
+
| `render(config, extraConfig)` | 按元数据数组递归渲染,返回节点数组 |
|
|
166
|
+
| `clear()` | 清空注册表、渲染工厂与初始化标记 |
|
|
167
|
+
|
|
168
|
+
`render` 的渲染优先级:节点自带的 `render({ node, props })` > 全局 `renderFactory({ node, props })` > 直接返回 `{ component, children, ...props }`。`extraConfig.props` 会作为默认 props 展开。组件未注册时只打印告警,不抛错。
|
|
169
|
+
|
|
170
|
+
## React 适配层
|
|
171
|
+
|
|
172
|
+
所有 adapter 都是高阶组件:`Adapter(Com) => 包装后的组件`。
|
|
173
|
+
|
|
174
|
+
### `common/`
|
|
175
|
+
|
|
176
|
+
| 文件 | 作用 |
|
|
177
|
+
| --- | --- |
|
|
178
|
+
| `refAdapter.jsx` | 受控壳:维护 `value` / `disabled` / `visible` / `readOnly` / `required` 状态,`visible === false` 时不渲染;通过 `useImperativeHandle` 暴露 `setState`(兼容 `setState(obj)` 与 `setState(key, val)`)与 `getState`。`readonly` 会归一化成控件惯用的 `readOnly` |
|
|
179
|
+
| `labelAdapter.jsx` | 给控件套 `label` 外壳(`mini-control-block` 结构),`required` 时加必输样式 |
|
|
180
|
+
| `loadMetaAdapter.jsx` | 挂载时调 `getViewMeta(billno)` 拉视图元数据,加载完成前渲染占位,完成后把元数据作为 props 铺给内层组件 |
|
|
181
|
+
| `dataSourceAdapter.jsx` | 取数壳:调 `props.api.list` 拉数据,并 `setData` / `setLoading` 到内层组件;暴露 `loadData` 命令式方法。同文件里的 `TableAdapter` 未导出 |
|
|
182
|
+
| `modalAdapter.jsx` | 把组件包进 Modal(`visible` → `open`、关闭时回调 `onClose`)。**当前未被 `adapter/index.js` 导出** |
|
|
183
|
+
|
|
184
|
+
### `model/`
|
|
185
|
+
|
|
186
|
+
| 导出 | 作用 |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `ModelAdapter(Com)` | 控件接入模型层。挂载时按 props 造 `SimpleModel`,以 `name` 登记进 `vm`(走 `addProperty`,父级 `getData()` 才收得到),并把控件实例交给模型托管;卸载时反注册 |
|
|
189
|
+
| `PageModelAdapter(Com)` | 页面外壳:创建根 `ViewModel` 并以 `vm` / `builder` 两个 prop 注入内层组件 |
|
|
190
|
+
| `ExtendjsAdapter(Com)` | 加载 `extendjs` 扩展脚本(默认延迟 300ms,可被 `extendDelay` 覆盖),加载完成前渲染 loading;`devfab.require` 不可用时直接跳过,避免页面卡死 |
|
|
191
|
+
| `BillAdapter(Com)` / `BillListAdapter(Com)` | 单据 / 列表外壳:把单据的 `vm` 挂到根 `vm` 上(key 为 `billno`),触发 `afterMount` / `afterUnMount`;列表额外把 `filterModel` 的 `search` 事件接到 `vm.execute('loadData', params)` |
|
|
192
|
+
| `DataSourceModelAdapter(Com)` | 把 `vm` 的 `loadData` 事件接到取数壳,并从 `parentModel` 合并 `api.bill` 配置 |
|
|
193
|
+
| `FilterAdapter(Com)` | 创建 `FilterModel`,向内层注入 `onSearch` 与 `renderCondition`(用 `builder.render` 渲染单个条件) |
|
|
194
|
+
|
|
195
|
+
用法示意:
|
|
196
|
+
|
|
197
|
+
```jsx
|
|
198
|
+
import React from 'react'
|
|
199
|
+
import { adapter } from 'devfab/dist/react'
|
|
200
|
+
import Input from 'antd/lib/input'
|
|
201
|
+
|
|
202
|
+
const { ModelAdapter, PageModelAdapter } = adapter
|
|
203
|
+
|
|
204
|
+
// 1. 注册控件:把元数据里的 component 名映射到实际组件
|
|
205
|
+
builder.initComponent({
|
|
206
|
+
Input: ModelAdapter(Input),
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
// 2. 告诉 builder 如何把节点变成 React 元素(必须由宿主提供)
|
|
210
|
+
builder.initRenderFactory(({ node, props }) =>
|
|
211
|
+
React.createElement(node.component || 'div', { key: props.key, ...props }, node.children)
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
// 3. 用后端下发的元数据渲染
|
|
215
|
+
const nodes = builder.render(meta)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
> 组件里出现的全局 `devfab` 由宿主的 `<script>`(或引入 `devfab` 后自行赋值)提供,见「运行时契约」。
|
|
219
|
+
|
|
220
|
+
## Vue 3 适配层
|
|
221
|
+
|
|
222
|
+
入口 `src/vue/vue-adapter/index.js`,产物 `dist/vue/vue3-adapter.{js,esm.js}`,由宿主显式 `import` / `require`,不产出 UMD、不挂全局。两个入口函数分别对应 React 的两种组件心智模型:
|
|
223
|
+
|
|
224
|
+
**`defineClassComponent(Class, options)`** —— 用 class 写组件。`this` 由 Proxy 包装,`this.$el` / `this.$refs` / `this.$nextTick` / `this.$forceUpdate` 在 `render` 与所有钩子里行为一致;同时提供 `this.setState` / `this.forceUpdate`。生命周期桥接:`componentWillMount` / `componentDidMount` / `componentWillReceiveProps`(浅比较 props)/ `componentDidUpdate` / `componentWillUnmount` / `componentDidUnmount` / `componentDidCatch`。可选基类 `VueComponent` 负责存好 `props` / `context`。
|
|
225
|
+
|
|
226
|
+
```js
|
|
227
|
+
import { defineClassComponent } from 'devfab/dist/vue/vue3-adapter'
|
|
228
|
+
|
|
229
|
+
export default defineClassComponent(
|
|
230
|
+
class Counter {
|
|
231
|
+
state = { n: 0 }
|
|
232
|
+
componentDidMount() {
|
|
233
|
+
console.log(this.$el)
|
|
234
|
+
}
|
|
235
|
+
render(h) {
|
|
236
|
+
return h('div', { onClick: () => this.setState({ n: this.state.n + 1 }) }, String(this.state.n))
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
**`defineFunctionComponent(fn, options)`** —— 用函数组件 + Hooks 写组件,`h` 由第三个参数注入,Hooks 按索引复用状态。
|
|
243
|
+
|
|
244
|
+
```js
|
|
245
|
+
import { defineFunctionComponent, useState } from 'devfab/dist/vue/vue3-adapter'
|
|
246
|
+
|
|
247
|
+
export default defineFunctionComponent((props, ctx, h) => {
|
|
248
|
+
const [n, setN] = useState(0)
|
|
249
|
+
return h('div', { onClick: () => setN(n.value + 1) }, String(n.value))
|
|
250
|
+
})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
可用 Hooks:`useState`、`useRef`、`useMemo`、`useCallback`、`useEffect`、`useLayoutEffect`、`useReducer`、`useContext`、`useProvide`。
|
|
254
|
+
|
|
255
|
+
Hooks 依赖索引存储,必须**无条件、按固定顺序**调用。非生产环境下内置了一道校验:索引位置上的 Hook 类型变了、或本次与上次调用的 Hook 数量不一致,都会 `console.error` 提示。
|
|
256
|
+
|
|
257
|
+
## 扩展脚本机制(`_lib/requirejs.js`)
|
|
258
|
+
|
|
259
|
+
vendored 的 RequireJS 2.3.2 之上挂了一层本地适配,暴露到 `window.__devfab`:
|
|
260
|
+
|
|
261
|
+
| 成员 | 说明 |
|
|
262
|
+
| --- | --- |
|
|
263
|
+
| `__devfab.require(domain, deps, callback, errback)` | 扩展脚本加载入口,支持 `require(deps, cb, err)` 与 `require(domain, deps, cb, err)` 两种签名 |
|
|
264
|
+
| `__devfab.define` | 扩展脚本注册入口 |
|
|
265
|
+
| `__devfab.requireInner` / `defineInner` | 原生 RequireJS 实现,绕过适配层 |
|
|
266
|
+
|
|
267
|
+
另外定制了 `req.createNode`:URL 以 `.css` 结尾时创建 `<link>` 而不是 `<script>`,扩展脚本可以顺带带样式。模型层默认从 `window.__devfab.require` 取加载器(见 `_models/index.js`)。
|
|
268
|
+
|
|
269
|
+
## 已知约束与当前实现状态
|
|
270
|
+
|
|
271
|
+
### 设计约束
|
|
272
|
+
|
|
273
|
+
- Vue 适配层仅支持 Vue 3,产物文件名带 `vue3` 即用于标明这条边界;兼容 Vue 2 需另写适配层。
|
|
274
|
+
- 纯 JavaScript 工程,不产出类型声明。
|
|
275
|
+
- `builder` 是模块级单例,微前端或多实例场景需要额外隔离。
|
|
276
|
+
- React 适配层依赖全局 `devfab`,不支持「多份运行时共存」。
|
|
277
|
+
|
|
278
|
+
### 待收敛项(写 README 时已核实,非推测)
|
|
279
|
+
|
|
280
|
+
- **包入口与适配层约定的运行时形状不一致**:`src/index.js` 导出的 default 是 `{ utils: { builder, cache, event }, common: {...} }`,而 React 适配层读的是 `devfab.builder`、`devfab.utils.models`,`scripts/smoke.js` 还要求 `hasRuntime()` / `getRuntime()` 与挂载 `window.devfab` 的行为。这些在源码里都**尚未实现**,因此当前构建产物跑 `npm run smoke` 会失败。
|
|
281
|
+
- **`ExtendjsAdapter` 调用的 `getRuntime()` 未定义**(`_utils/index.js` 与 `src` 全局都没有),走到扩展脚本分支会直接 `ReferenceError`。
|
|
282
|
+
- **`GridModel` 存在从原实现带过来的未定义引用**:`setCachePaginationRowData`、`resetSelected`、`createDefaults`、以及全局 `cb`、`_`(lodash)。涉及 `setDataSource` / `showPage` 等取数与分页路径。
|
|
283
|
+
- **`src/vue/index.js` 目前不被任何入口引用**,`vue-adapter` 由 `src/vue/vue-adapter/index.js` 单独作为构建入口,前者只是占位。
|
|
284
|
+
- **`adapter/index.js` 未导出 `ModalAdapter`**,`common/dataSourceAdapter.jsx` 里的 `TableAdapter` 也未导出且含 `debugger` 语句。
|
|
285
|
+
- `npm run lint` 当前不通过(约 200+ error),主要是 `react/prop-types` 与 `react/display-name`,也有上面列的 `no-undef`。
|
|
286
|
+
- `package.json` 的 `license` 写的是 `ISC`,而 `LICENSE` 文件是 Apache License 2.0。
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
Apache License 2.0,见 [LICENSE](./LICENSE)。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var a=0,n=Array(t);a<t;a++)n[a]=e[a];return n}function t(e,t,a){return t=o(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,u()?Reflect.construct(t,a||[],o(e).constructor):t.apply(e,a))}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var a=0;a<t.length;a++){var n=t[a];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,v(n.key),n)}}function i(e,t,a){return t&&n(e.prototype,t),a&&n(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}function r(e,t,a){return(t=v(t))in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function o(e){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},o(e)}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}function l(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,n)}return a}function c(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?l(Object(a),!0).forEach(function(t){r(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):l(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}function d(e,t){if(null==e)return{};var a,n,i=function(e,t){if(null==e)return{};var a={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;a[n]=e[n]}return a}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(n=0;n<r.length;n++)a=r[n],-1===t.indexOf(a)&&{}.propertyIsEnumerable.call(e,a)&&(i[a]=e[a])}return i}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var a=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=a){var n,i,r,o,s=[],u=!0,l=!1;try{if(r=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;u=!1}else for(;!(u=(n=r.call(a)).done)&&(s.push(n.value),s.length!==t);u=!0);}catch(e){l=!0,i=e}finally{try{if(!u&&null!=a.return&&(o=a.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}(e,t)||p(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(t)||p(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var a=e[Symbol.toPrimitive];if(void 0!==a){var n=a.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function p(t,a){if(t){if("string"==typeof t)return e(t,a);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,a):void 0}}var w=function(){return i(function e(t){a(this,e),this._init(t)},[{key:"_init",value:function(e){this.cache=Object.assign({},e)}},{key:"set",value:function(e,t){this.cache[e]=t}},{key:"get",value:function(e){var t;return null===(t=this.cache)||void 0===t?void 0:t[e]}},{key:"clear",value:function(e){delete this.cache[e]}}])}(),m=function(){return i(function e(t){a(this,e),this._init(t)},[{key:"_init",value:function(e){var t;this.__ASYNC_EXECUTE__=null===(t=null==e?void 0:e.__ASYNC_EXECUTE__)||void 0===t||t,this.events=new Map,this.firstevents=new Map}},{key:"on",value:function(e,t,a){var n=this.events.get(e);Array.isArray(n)||(n=[]),n.push({callback:t,context:a}),this.events.set(e,n)}},{key:"onFirst",value:function(e,t,a){var n=this.firstevents.get(e);Array.isArray(n)||(n=[]),n.splice(0,0,{callback:t,context:a}),this.firstevents.set(e,n)}},{key:"execute",value:function(e){for(var t=arguments.length,a=new Array(t>1?t-1:0),n=1;n<t;n++)a[n-1]=arguments[n];var i=this.events.get(e),r=this.firstevents.get(e);if(!i&&!r)return!0;var o=!0;return[].concat(g(r||[]),g(i||[])).forEach(function(e){if(!1!==o){var t=e.callback.apply(e.context||void 0,a);o=!1!==t&&o}}),o}},{key:"un",value:function(e,t){this._unEvents(e,t,this.events),this._unEvents(e,t,this.firstevents)}},{key:"_unEvents",value:function(e,t,a){if(e&&a.has(e))if(t){var n=a.get(e),i=null==n?void 0:n.findIndex(function(e){return e.callback===t});-1!==i&&(null==n||n.splice(i,1))}else a.delete(e)}},{key:"hasEvent",value:function(e){var t,a;return e?((null===(t=this.events.get(e))||void 0===t?void 0:t.length)||0)+((null===(a=this.firstevents.get(e))||void 0===a?void 0:a.length)||0):0}},{key:"fireEvent",value:function(e,t){this.execute("before".concat(e),t)&&(this.execute(e,t),this.execute("after".concat(e),t))}},{key:"_asyncExecute",value:function(e,t,a){for(var n,i=this,r=a.resolve,o=a.reject,s=a.args,u=!0,l=t||[],c=!1,d=function(t){var a,n=l[t];if(!1===u)return 0;if(c)return{v:void 0};if("development"===process.env.nodeEnv)a=n.callback.apply(n.context||i,s);else try{a=n.callback.apply(n.context||i,s)}catch(e){throw e.isAddedMsg||(e.message="(领域扩展事件执行失败,请打开控制台查看详细错误信息并修复):".concat(e.message)),e.isAddedMsg=!0,e}a instanceof Promise?(c=!0,(u=a).callbacks&&u.callbacks.push({reject:function(){u.reject(),t===l.length-1&&(null==o||o())},resolve:function(a){t===l.length-1?(s.length>1&&(s[0]=a),null==r||r(s)):i._asyncExecute(e,l.slice(t+1),{resolve:r,reject:o,args:s})}})):(u=!1!==a&&u,t===l.length-1&&(u?null==r||r(s):null==o||o()))},h=0;h<l.length&&0!==(n=d(h));h++)if(n)return n.v;return u}},{key:"_asyncPromiseExecute",value:function(e,t,a,n){var i=this.events.get(e),r=this.firstevents.get(e);if(!((Array.isArray(i)?i.length:i)||(Array.isArray(r)?r.length:r)))return null==t?void 0:t();var o=[].concat(g(r||[]),g(i||[]));return this._asyncExecute(e,o,{resolve:t,reject:a,args:n})}},{key:"promiseExecute",value:function(e,t){var a=this,n=e,i=1;if("boolean"==typeof e&&(n=t,i=2),n){for(var r=arguments.length,o=new Array(r>2?r-2:0),s=2;s<r;s++)o[s-2]=arguments[s];var u=2===i?o:[t].concat(o);if(u.length){var l,c=u.length-1,d=u[c];if("function"!=typeof d){if("object"!==y(d)||!d[0]||"function"!=typeof d[0]||!d[1]||"function"!=typeof d[1])return;l=d[1],d=d[0]}if(this.__ASYNC_EXECUTE__)return this._asyncPromiseExecute(n,function(e){d.apply(a,e)},function(){l&&"function"==typeof l&&l()},u);u.splice(c,1),u.unshift(n);var h=this.execute.apply(this,u);if(h instanceof Promise){var f=this;h.then(function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];d.apply(f,t)},function(){l&&"function"==typeof l&&l()})}else if(!h)return void(l&&"function"==typeof l&&l())}}}},{key:"clearEvents",value:function(){this.events.clear(),this.firstevents.clear()}}])}();function S(e){this.pathname="",this.query={};var t=e;this.init=function(){t||(t=location.search);var e=t.indexOf("?"),a=t.indexOf("#");if(e>=0){if(this.pathname=t.substr(0,e),(t=a<0?t.substr(e+1):t.substring(e+1,a)).length>0)for(var n=(t=t.replace(/\+/g," ")).split("&"),i=0,r=n.length;i<r;i++){var o=n[i]||"";if(o){var s=o.indexOf("="),u="",l="";s<0?l=u=window.decode(o):(u=window.decode(o.substr(0,s)),l=window.decode(o.substr(s+1))),this.query[u]=l}}}else this.pathname=t},this.set=function(e,t){this.query[e]=t},this.get=function(e){return this.query[e]},this.del=function(e){delete this.query[e]},this.has=function(e){return null!=this.query[e]},this.toStr=function(){var e=["?"];for(var t in this.query)e.push(encodeURIComponent(t)),e.push("="),e.push(encodeURIComponent(this.query[t])),e.push("&");return 1===e.length?"":(e.splice(e.length-1,1),e.join(""))},this.init()}function k(e,t){if(!t)return e;var a=[],n=new S(e);for(var i in t)n.get(i)||a.push("".concat(i,"=").concat(t[i]));if(!a.length)return e;var r=a.join("&");return e.indexOf("?")>=0?"".concat(e,"&").concat(r):"".concat(e,"?").concat(r)}String.prototype.equalsIgnoreCase=function(e){return null!=e&&this.toLowerCase()===e.toLowerCase()};var x=["onBeforeRequest","_onAfterRequest"],R=["_onBeforeRequest","onAfterRequest"];var b={_xhrs:[],_jsonps:{index:0},doRequest:function(e){var t=e||{},a=t.onBeforeRequest;t._onAfterRequest;var n,i=d(t,x),r=i.method||"GET",o=i.url;try{null!=i&&i.requestHeaders&&(n=i.requestHeaders,i.requestHeaders=void 0,delete i.requestHeaders)}catch(e){console.log('[ajax]: [doRequest]: options["requestHeaders"] ERR : ',e)}try{i.params&&i.params.requestHeaders&&(n=i.params.requestHeaders,i.params.requestHeaders=void 0,delete i.params.requestHeaders)}catch(e){console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ',e)}var s=null;if(r.equalsIgnoreCase("get")||r.equalsIgnoreCase("delete")?o=k(o,i.params):(r.equalsIgnoreCase("post")||r.equalsIgnoreCase("put"))&&(s=JSON.stringify(i.params)),i.jsonp)return this.getJsonp(o,i.callback);var u=this.getXMLHttpRequest();if(u){var l;if(u.open(r,o,!1!==i.async),i.timeout&&(u.timeout=i.timeout,u.setRequestHeader("timeout",i.timeout),u.ontimeout=function(){b.onerror(this,i,"timeout")}),i.contentType){if(u.setRequestHeader("Content-Type",i.contentType),i.contentType.indexOf("x-www-form-urlencoded")>=0)s=null===(l=new URLSearchParams(i.params))||void 0===l?void 0:l.toString()}else i.dateType?s=i.params:u.setRequestHeader("Content-Type","application/json;charset=utf-8");i.domainKey&&u.setRequestHeader("Domain-Key",i.domainKey);try{if(n&&"[object Object]"===Object.prototype.toString.call(n))for(var c in n)u.setRequestHeader(c,n[c])}catch(e){console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ',e)}u.withCredentials=null==i||!i.hasOwnProperty("withCredentials")||i.withCredentials;try{u.send(s)}catch(e){return{error:"NetWorkError",options:i}}if(!1===i.async)return null==a||a(i),this.onreadystatechange(u,i);u.onreadystatechange=function(){b.onreadystatechange(this,i)},null==a||a(i)}},beforeReadystatechange:function(e,t,a){null==a||a()},onreadystatechange:function(e,t){var a=t||{};a._onBeforeRequest;var n=a.onAfterRequest,i=d(a,R);if(4===e.readyState){if(null==n||n(),200===e.status){var r;try{if("blob"===i.responseType){var o=function(e){var t=e.xhr.getAllResponseHeaders(),a={};return t.split("\r\n").map(function(e){var t=f(e.split(": "),2),n=t[0],i=t[1];a[n]=i}),a}({xhr:e});r={code:e.status,data:{data:e.response,headers:o}}}else r=JSON.parse(e.responseText)}catch(t){b.onerror(e,i,e.responseText)}if(!1===i.async)return e.isBusy=!1,i.precallback&&i.precallback(r),b.processAjaxResult(r,!1,null,null,i,e);b.processAjaxResult(r,i.async,i.callback,i.context,i,e),i.precallback&&i.precallback(r)}else if(0===e.status)b.onerror(e,i,"网络连接已断开,请检查设备网络状态后重试");else if(502===e.status||504===e.status)b.onerror(e,i,"服务出错了,请稍后再试");else{if(401!==e.status){var s={};try{s=JSON.parse(e.responseText)}catch(t){s={code:e.status,message:e.responseText}}return b.onerror(e,i,s)}b.onerror(e,i,"登录信息失效,请重新登录或联系技术人员")}e.isBusy=!1}},onerror:function(e,t,a){var n="[ajax]: [onerror]: 接口返回错误 \n [状态码]: ".concat(e.status," \n [错误信息]: ").concat(("object"===y(a)?JSON.stringify(a):a)||"空"," \n [请求地址]: ").concat(t.url," \n [浏览器Token]: ").concat(document.cookie);console.log("Error.E01000",n);var i="object"===y(a)?a:{code:500,message:a};t.precallback&&t.precallback(i)},getXMLHttpRequest:function(){return this.createXMLHttpRequest()},createXMLHttpRequest:function(){return window.XMLHttpRequest?new XMLHttpRequest:window.ActiveXObject?new window.ActiveXObject("Microsoft.XMLHTTP"):null},getJsonp:function(e,t){var a=e,n="callback"+this._jsonps.index++,i=document.createElement("script");this._jsonps[n]=function(e){try{t(e)}finally{document.body.removeChild(i)}},a+=-1===a.indexOf("?")?"?":"&callback=cb.rest.AjaxRequestManager._jsonps."+n,i.src=a,document.body.appendChild(i)},processAjaxResult:function(e,t,a,n,i,r){if(e){if(!e.code)return!1===t?e:void(a&&a.call(n,null,e));if(200==e.code){if(!1===t)return{result:e.data};a&&a.call(n,null,e.data,e.message,e.errorDetail,e.code,e.displayCode&&e)}else{if(!1===t)return{error:e};a&&a.call(n,e)}}}};function C(e,t){this.init&&this.init(e),this.queryParams=t}C.create=function(e,t){return new C(e,t)},C.prototype.init=function(e){if(e)for(var t in this.config=e,this.config)this[t]=function(e){return function(t,a,n){return this.Do(e,t,a,null,n)}}(t),this["".concat(t,"Sync")]=function(e){return function(t){return this.Do(e,t,null,!1)}}(t)},C.prototype.Do=function(e,t,a,n,i){var r,o,s;if(this.config&&this.config[e]&&this.config[e].url){var u=this.config[e],l=u.url;this.queryParams||(this.queryParams={}),null!==(r=u.options)&&void 0!==r&&r.proxyServiceCode&&(this.queryParams.serviceCode=u.options.proxyServiceCode),null!==(o=u.options)&&void 0!==o&&o.billnum&&(this.queryParams.billnum=u.options.billnum),null!==(s=this.queryParams)&&void 0!==s&&s.serviceCode&&(l=k(l,this.queryParams));var c=l,d=Object.assign({},u.options);return d.method=u.method||"GET","function"==typeof t?(d.callback=t,d.context=i||d.context||this):d.params=t,a&&(d.callback=a,d.context=i||d.context||this),!1===n&&(d.async=!1),this.ajax(c,d)}},C.prototype.ajax=function(e,t){return function(e,t){return t.url=e,b.doRequest(t)}(e,t)};var I=function(){return i(function e(t){a(this,e),this._init(t)},[{key:"_init",value:function(e){this._data={};var t=[];if(e)for(var a in e)t.push(a);Object.assign(this._data,{components:[],propertyNames:t},e),this._data.cache=new w,this._data.events=new m}},{key:"_del_data",value:function(e){e&&delete this._data[e]}},{key:"_cls_data",value:function(){this._data.cache.clear(),this._data.events.clear(),this._data={components:[],propertyNames:[],cache:new w,events:new m}}},{key:"_set_data",value:function(e,t,a){if(e){if(a){var n=this._data.propertyNames||[];n.indexOf(e)<0&&n.push(e)}this._data[e]=t}}},{key:"_get_data",value:function(e){if(e)return this._data[e]}},{key:"getData",value:function(){return this._get_data("value")}},{key:"getState",value:function(e,t){var a;if(!t)return this._get_data(e);var n=(this._get_data("components")||[]).find(function(e){return e.ctrlName===t});return n?null===(a=n.getState)||void 0===a?void 0:a.call(n,e):this._get_data(e)}},{key:"setState",value:function(e,t,a){a||this._set_data(e,t,!0);var n={};n[e]=t,this.doPropertyChange("setState",n,a)}},{key:"doPropertyChange",value:function(e,t,a){var n=this,i=this._get_data("components")||[];if(!i.length)return i;var r=[];if(a){var o=i.find(function(e){return e.ctrlName===a});o&&!this.notifyComponent(o,e,t)&&r.push(o)}else i.forEach(function(a){n.notifyComponent(a,e,t)||r.push(a)});return r.length?r:void 0}},{key:"notifyComponent",value:function(e,t,a){return"function"==typeof e[t]&&(this.viewUpdater(e,t,a),!0)}},{key:"viewUpdater",value:function(e,t,a){if("setState"===t)e[t](a);else{var n=this.getCache("name");e[t](a,n)}}},{key:"get",value:function(e){return this._get_data(e)}},{key:"addComponent",value:function(e,t){if(e){t&&!e.ctrlName&&(e.ctrlName=t);var a=this._get_data("components")||[];a.indexOf(e)>=0||a.push(e)}}},{key:"removeComponent",value:function(e){var t=this._get_data("components")||[],a=t.indexOf(e);a<0||t.splice(a,1)}},{key:"_applyState",value:function(e,t,a){var n=this;a||this._set_data(e,t,!0);var i="set".concat(e.charAt(0).toUpperCase()).concat(e.slice(1)),r=this.doPropertyChange(i,t,a);if(r){var o={};o[e]=t,r.forEach(function(e){n.notifyComponent(e,"setState",o)})}}},{key:"getVisible",value:function(e){return this.getState("visible",e)}},{key:"setVisible",value:function(e,t){this._applyState("visible",e,t)}},{key:"getValue",value:function(){return this.getData()}},{key:"setValue",value:function(e,t,a){var n=this,i=this.getValue();if(e!==i){var r={value:e,oldValue:i},o=this._get_data("forceFireEvent");t||o?this.promiseExecute("beforeValueChange",r,[function(){n._set_data("value",e,!0),n._applyState("value",e,a),n.execute("afterValueChange",r)},function(){n._set_data("value",i,!0),n._applyState("value",i,a)}]):(this._set_data("value",e,!0),this._applyState("value",e,a))}}},{key:"getDisabled",value:function(e){return this.getState("disabled",e)}},{key:"setDisabled",value:function(e,t){this._applyState("disabled",e,t)}},{key:"setParent",value:function(e){this.setCache("parent",e)}},{key:"getParent",value:function(){return this.getCache("parent")}},{key:"getRootParent",value:function(){for(var e=this.getParent();null!==(t=e)&&void 0!==t&&t.getParent();){var t;e=e.getParent()}return e}},{key:"setName",value:function(e){this.setCache("name",e)}},{key:"getName",value:function(){return this.getCache("name")}},{key:"setDirty",value:function(e){e?this._set_data("isDirty",!0):(this._del_data("isDirty"),this._set_data("originalData",this.getData()))}},{key:"getDirtyData",value:function(e){var t=this.getData();return!1!==e&&this._get_data("isDirty")||t!==this._get_data("originalData")?t:void 0}},{key:"clear",value:function(e){void 0===e?this._set_data("value",this._get_data("cDefaultValue")):e||this._set_data("value",void 0),this._del_data("isDirty"),this._del_data("checking"),this._del_data("checkMsg")}},{key:"on",value:function(e,t,a){this._get_data("events").on(e,t,a)}},{key:"onFirst",value:function(e,t,a){this._get_data("events").onFirst(e,t,a)}},{key:"execute",value:function(e){for(var t,a=arguments.length,n=new Array(a>1?a-1:0),i=1;i<a;i++)n[i-1]=arguments[i];return(t=this._get_data("events")).execute.apply(t,[e].concat(n))}},{key:"un",value:function(e,t){this._get_data("events").un(e,t)}},{key:"hasEvent",value:function(e){return this._get_data("events").hasEvent(e)}},{key:"fireEvent",value:function(e,t){this._get_data("events").fireEvent(e,t)}},{key:"promiseExecute",value:function(e,t){for(var a,n=arguments.length,i=new Array(n>2?n-2:0),r=2;r<n;r++)i[r-2]=arguments[r];(a=this._get_data("events")).promiseExecute.apply(a,[e,t].concat(i))}},{key:"setCache",value:function(e,t){this._get_data("cache").set(e,t)}},{key:"getCache",value:function(e){return this._get_data("cache").get(e)}},{key:"clearCache",value:function(e){this._get_data("cache").clear(e)}},{key:"setProxy",value:function(e){if(!(e instanceof C)){var t,a=this._get_data("__requestHeaders__");for(var n in e){var i,r,o;if(a&&(null===(i=e[n])||void 0===i||null===(i=i.options)||void 0===i||!i.requestHeaders))null!==(o=e[n])&&void 0!==o&&o.options||(e[n].options={}),e[n].options.requestHeaders=a;null!==(r=this.getProxy())&&void 0!==r&&r[n]&&console.warn("[baseModel.prototype.setProxy]: Proxy ".concat(n," already exists on the model. Please change the name of ").concat(n," and try again"))}return this._set_data("proxy",C.create(c(c({},(null===(t=this.getProxy())||void 0===t?void 0:t.config)||{}),e))),this.getProxy()}this._set_data("proxy",e)}},{key:"getProxy",value:function(){return this._get_data("proxy")}}])}(),P=function(){function e(){return a(this,e),t(this,e,arguments)}return s(e,I),i(e,[{key:"mounted",value:function(){var e=this,t=this.get("conditions"),a={};t.forEach(function(t){e.get(t.name),a[t.name]=t.defaultValue}),this._set_data("params",a)}},{key:"unmounted",value:function(){this._set_data("params",{}),this._set_data("conditions",[])}},{key:"getParams",value:function(){var e=this,t={};return this.get("conditions").forEach(function(a){var n=e.get(a.name);t[a.name]=null==n?void 0:n.getValue()}),this._set_data("params",t),t}},{key:"search",value:function(){var e=this.getParams();this.execute("search",e)}}])}(),D=function(){function e(n){return a(this,e),t(this,e,[n])}return s(e,I),i(e,[{key:"getDisabled",value:function(){return this.getState("disabled")}},{key:"setDisabled",value:function(e){return this.setState("disabled",!!e)}},{key:"getReadonly",value:function(){return this.getState("readonly")}},{key:"setReadonly",value:function(e){this.setState("readonly",!!e)}}])}(),E="",O="Insert",q="Update",j="Delete",M=Array.isArray,A=function(e){return null==e||""===e},F=function(e){return!e||0===Object.keys(e).length};function N(e){if(M(e))return e.map(N);if(e instanceof Date)return new Date(e.getTime());if(e&&"object"===y(e)){var t={};for(var a in e)t[a]=N(e[a]);return t}return e}function K(e){var t={};return(M(e)?e:Object.keys(e||{}).map(function(t){var a;return c(c({},e[t]||{}),{},{field:(null===(a=e[t])||void 0===a?void 0:a.field)||t})})).forEach(function(e,a){if(e){var n=e.field||e.cCaption||e.cFieldName||"col_".concat(a);t[n]=c(c({},e),{},{field:n,fieldName:e.fieldName||n,cCaption:e.cCaption||n,index:void 0===e.index?a:e.index})}}),t}function T(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=this.getIdFlag(),a=this.getRowKeyField(),n=this._get_data("rowIdSeq")||0;return e.forEach(function(e){if(e&&void 0===e[t]){var i=e[a];null!=i&&""!==i?e[t]=String(i):(n+=1,e[t]="rowId_".concat(n))}}),this._set_data("rowIdSeq",n),e}var V=function(e,t,a,n,i,r,o){var s=this;this.promiseExecute("beforeBatchModifyPull",function(){var r=s.setProxy({queryData:e}),o={page:{pageSize:s.getPageSize(),pageIndex:s.getPageIndex()}};o.page.pageSize||(s.setPageSize(10),o.page.pageSize=10);var u=s._get_data("bLoadPagination");u||i||(o.page.totalCount=1);var l=s._get_data("delayLoadPageInfo");u&&l&&(n&&s.setState("showDelayPagination",!0),o.page.totalCount=1);var c=Object.assign(o,t);s.setCache("proxyCache",{proxyConfig:e,params:c});var d=0,h={},f=s.getRootParent(),g=s,v=(new Date).valueOf();c.queryId=v;if(!1!==f.execute("beforeQueryData",c)){g.setCache("lastGridFilterCondition",JSON.stringify(null==c?void 0:c.condition));var y=_.cloneDeep(c);if(r.queryData(y,function(e,t,r,o){var s,c;if(setTimeout(function(){g.clearCache("isGridInLoading")},0),null==f||f.clearCache("lazySearch"),e)return this.setState("showDelayPagination",!1),void this.clearCache("setPageIndexFromBack");t=t||{},this._set_data("dataSourceMode","remote"),n&&u&&l&&(d++,t=Object.assign(h,t));var v=Array.isArray(t.recordList)?t.recordList:[];if(u&&l&&2!==d||!a||a.call(this,t,r,o),this.getCache("setPageIndexFromBack"),this.clearCache("setPageIndexFromBack"),this.execute("beforeSetDataSource",v)){var y=this._get_data("rowKeyField"),_={};v.forEach(function(e){_[e[y]]=e}),this._set_data("keyMap",_),n||!1!==this._get_data("override")?(this._set_data("dataSource",v,!0),this.doPropertyChange("resetCellStatus"),this._set_data("cellState",{},!0),this._set_data("rowState",{},!0)):this._set_data("dataSource",this._get_data("dataSource").concat(v),!0),this.setCache("currentGridData",v),v.length&&T.call(this,v),this.initRowState(),setCachePaginationRowData.call(this,v),this._get_data("sortParams");var p=this._get_data("colFilterParams");this.showRows(null,!cb.utils.isEmptyObject(p));var w=this._get_data("pageInfo");u&&!l&&(this._get_data("bLoadPagination")||i)?(w={pageSize:t.pageSize,pageIndex:t.pageIndex,pageCount:t.pageCount,recordCount:t.recordCount},this.setPageInfo(w)):(w.pageIndex=t.pageIndex,w.from="showPageInner",this.setPageInfo(w)),resetSelected.call(this),"splitview"!==(null===(s=this.getParent)||void 0===s||null===(s=s.call(this))||void 0===s||null===(c=s.getParams)||void 0===c||null===(c=c.call(s))||void 0===c?void 0:c.templateType)&&this._set_data("focusedRowIndex",-1);for(var m=arguments.length,S=new Array(m>4?m-4:0),k=4;k<m;k++)S[k-4]=arguments[k];this.execute("afterSetDataSource",v,t.viewmodel,null==S?void 0:S[1])}},s),n&&u&&l){var p=JSON.parse(JSON.stringify(e));p.options||(p.options={}),p.options.mask=!1;H.call(s,p,c,function(e){!function(e){d++,Object.assign(h,e),2===d&&a&&a.call(s,h)}(e)})}}})};function H(e,t,a){this.setCache("queryPageCountLoading",!0);var n=this.setProxy({queryPageCount:c({},e)}),i=Object.assign(!0,t,{page:{totalCount:-1}});this.__queryPageCountRequestId||(this.__queryPageCountRequestId=0),this.__queryPageCountRequestId++;n.queryPageCount(i,function(e,t,n){if(this.__queryPageCountRequestId===e)if(this.setCache("queryPageCountLoading",!1),this.setState("showDelayPagination",!1),t){var i=this._get_data("pageInfo");i&&this.setPageInfo(i)}else{var r={beginPageIndex:(n=n||{}).beginPageIndex,endPageIndex:n.endPageIndex,pageSize:n.pageSize,pageIndex:n.pageIndex,pageCount:n.pageCount,recordCount:n.recordCount};a&&a.call(this,r),this.setPageInfo(r),this.execute("afterQueryPageInfo",n)}}.bind(this,this.__queryPageCountRequestId),this)}var B=function(){function e(){var n,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};a(this,e);var r=c(c({},{columns:{},dataSource:[],rows:[],readOnly:!0,dataSourceMode:"local",columnMode:"local",editMode:"cell",cellState:{},rowState:{},showCheckBox:!0,multiple:!0,showRowNo:!0,pagination:!0,pageInfo:{pageIndex:1,pageSize:20,pageCount:0},innerUsedAttrs:{id:"_id",selected:"_selected",status:"_status"},multiRowModel:!1,editRowModels:{},loading:!1,params:{},originalKeyMap:{},defaultRowDatas:new Map}),i);M(r.dataSource)||(r.dataSource=[]),M(r.rows)||(r.rows=[]);var o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=c({},e.proxyConfig||{});return"function"==typeof e.dataSource&&(t.load=t.load||e.dataSource),"string"==typeof e.cUrl&&(t.load=t.load||e.cUrl),t.load||"string"!=typeof e.url||(t.load=e.url),t}(i);r.proxyConfig=o,r.dataSourceMode=i.dataSourceMode||(o.load?"remote":"local");var s=i.cData||(M(i.data)?i.data:null);return(n=t(this,e,[r])).initPageInfo(i.cPage||i.page),n.initColumns(r.columns),n.initRowState(),n.afterInit(),s&&n.setDataSource(s),n}return s(e,I),i(e,[{key:"afterInit",value:function(){"single"===this._get_data("parentRelation")&&this._set_data("defaultSelectedRowIndexes",!0)}},{key:"initColumns",value:function(e){var t=K(e);return this._set_data("columns",t,!0),t}},{key:"initPageInfo",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=c({},this.getPageInfo());t.pageIndex=e.pageNo||e.pageIndex||t.pageIndex||1,t.pageSize=e.pageSize||t.pageSize||20,!1===this.get("pagination")&&(t.pageSize=-1),this.applyPageInfo(t)}},{key:"initRowState",value:function(){var e=this,t=this._get_data("dataSource");this._set_data("rowsDataState",(M(t)?t:[]).map(function(t){return(null==t?void 0:t[e.getStatusFlag()])||E}),!0)}},{key:"getInnerUsedAttrs",value:function(){return this._get_data("innerUsedAttrs")}},{key:"getIdFlag",value:function(){return this.getInnerUsedAttrs().id}},{key:"getSelectedFlag",value:function(){return this.getInnerUsedAttrs().selected}},{key:"getStatusFlag",value:function(){return this.getInnerUsedAttrs().status}},{key:"getRowKeyField",value:function(){return this._get_data("rowKeyField")||"id"}},{key:"getProxyConfig",value:function(){return this._get_data("proxyConfig")||{}}},{key:"isRemote",value:function(){return"remote"===this._get_data("dataSourceMode")}},{key:"isPagination",value:function(){return!!this.get("pagination")&&-1!==this.getPageSize()}},{key:"getReadOnly",value:function(){return!!this._get_data("readOnly")}},{key:"setReadOnly",value:function(e){this._applyState("readOnly",!!e)}},{key:"getParams",value:function(){return c(c({},this.get("cParams")||{}),this._get_data("params")||{})}},{key:"setParams",value:function(e){this._set_data("params",e||{})}},{key:"setMeta",value:function(e){this._set_data("meta",e)}},{key:"getColumns",value:function(e){var t=this._get_data("columns")||{},a={};return(e?M(e)?e:[e]:Object.getOwnPropertyNames(t)).forEach(function(e){t[e]&&(a[e]=c(c({},t[e]),{},{fieldName:t[e].fieldName||e}))}),a}},{key:"getColumn",value:function(e){var t,a=null===(t=this._get_data("columns"))||void 0===t?void 0:t[e];return a?c(c({},a),{},{fieldName:a.fieldName||e}):void 0}},{key:"hasColumn",value:function(e){return!!(this._get_data("columns")||{})[e]}},{key:"getColumnList",value:function(e){var t=this.getColumns(e);return Object.keys(t).sort(function(e,a){return(t[e].index||0)-(t[a].index||0)}).map(function(e){return t[e]})}},{key:"getVisibleColumns",value:function(e){return this.getColumnList(e).filter(function(e){return!0!==e.bHidden&&!1!==e.bShowIt})}},{key:"setColumns",value:function(e){e&&this._applyState("columns",K(e))}},{key:"setColumnMode",value:function(e){this._set_data("columnMode","remote"===e?"remote":"local",!0)}},{key:"addColumns",value:function(e){var t=K(e);this._applyState("columns",c(c({},this._get_data("columns")||{}),t))}},{key:"resetColumns",value:function(e){this.setColumns(e||this.get("cColumns"))}},{key:"getColumnState",value:function(e,t,a){var n,i=this.getRowKey(e);return i?((null===(n=this._get_data("cellState"))||void 0===n||null===(n=n[i])||void 0===n?void 0:n[t])||{})[a]:void 0}},{key:"setColumnState",value:function(e,t,a,n){this.setCellState(e,t,a,n)}},{key:"setColumnStates",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.setCellStates(e.map(function(e){return c(c({},e),{},{cellName:e.cellName||e.columnName})}))}},{key:"setColumnValue",value:function(e,t,a){var n=this._get_data("columns")||{};n[e]&&this._applyState("columns",c(c({},n),{},r({},e,c(c({},n[e]),{},r({},t,a)))))}},{key:"load",value:function(e,t,a){this.setProxy({load:e}).load(t,function(e,t){e?cb.utils.alert(e,"error"):(t.schema&&(this._set_data("columnMode","remote"),this.setColumns(t.schema)),this.setDataSource(t.data),a&&a.call(this))},this)}},{key:"refresh",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.hasEvent("refresh")?this.execute("refresh",e):this.fetch({body:e})}},{key:"loadData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.refresh(e)}},{key:"queryData",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.refresh(e)}},{key:"getDataSource",value:function(){var e=this._get_data("dataSource")||[];if(!this.hasDeletedRow())return e;var t=this._get_data("rowsDataState")||[];return e.filter(function(e,a){return t[a]!==j})}},{key:"getRealData",value:function(){return this.getDataSource()}},{key:"getRealRows",value:function(){return this._get_data("rows")||[]}},{key:"getRowsCount",value:function(){return(this._get_data("rows")||[]).length}},{key:"getDataSourceCount",value:function(){return(this._get_data("dataSource")||[]).length}},{key:"hasDeletedRow",value:function(){return(this._get_data("rowsDataState")||[]).some(function(e){return e===j})}},{key:"getData",value:function(e,t){var a=e||t?this._get_data("rows"):this._get_data("dataSource");return this.collectRows(a,e)}},{key:"getAllData",value:function(){return this.getData(!0)}},{key:"getPageData",value:function(){return this.getData(!0)}},{key:"getEffeData",value:function(){var e=this._get_data("dataSource")||[],t=this._get_data("rowsDataState")||[];return this.collectRows(e.filter(function(e,a){return t[a]!==j}),!1)}},{key:"getRows",value:function(e){var t=this._get_data("rows")||[];return!1===e?t:t.map(function(e){return N(e)})}},{key:"collectRows",value:function(e,t){var a=this._get_data("columns")||{},n=this.getStatusFlag(),i=this.getSelectedFlag();return(e||[]).map(function(e){var r={};for(var o in e){var s;t&&o===n||(t||o!==i)&&!1!==(null===(s=a[o])||void 0===s?void 0:s.needCollect)&&(r[o]=e[o])}return r})}},{key:"getShowRows",value:function(e){return(e||this._get_data("rows")||[]).map(function(e){return c({},e)})}},{key:"getRow",value:function(e,t){var a,n=null===(a=this._get_data("rows"))||void 0===a?void 0:a[e];if(n)return!1===t?n:N(n)}},{key:"getRowIndex",value:function(e){if(!e)return-1;var t=this._get_data("rows")||[],a=this.getRowKeyField();return void 0!==e[a]?t.findIndex(function(t){return t[a]===e[a]}):t.indexOf(e)}},{key:"getRowIndexByRowId",value:function(e){var t=this;return(this._get_data("rows")||[]).findIndex(function(a){return(null==a?void 0:a[t.getIdFlag()])===e})}},{key:"getDataSourceIndexByRowId",value:function(e){var t=this;return(this._get_data("dataSource")||[]).findIndex(function(a){return(null==a?void 0:a[t.getIdFlag()])===e})}},{key:"getRowKey",value:function(e){var t,a;return null!==(t=null===(a=this._get_data("rows"))||void 0===a||null===(a=a[e])||void 0===a?void 0:a[this.getIdFlag()])&&void 0!==t?t:e}},{key:"getRowKeys",value:function(e){var t=void 0===e?this.getRows():M(e)?e:[e],a=this.getRowKeyField();return t.filter(function(e){return e&&void 0!==e[a]}).map(function(e){return e[a]})}},{key:"getRowsByIndexes",value:function(e){var t=this._get_data("rows")||[];return(M(e)?e:[e]).map(function(e){return t[e]}).filter(Boolean)}},{key:"getCellValue",value:function(e,t){var a,n=e>=0?null===(a=this._get_data("rows"))||void 0===a?void 0:a[e]:null;if(n&&t)return n[t]}},{key:"setCellValue",value:function(e,t,a){var n=(this._get_data("rows")||[])[e];if(n&&t){var i=n[t];if(i!==a){var r={rowIndex:e,rowId:n[this.getIdFlag()],cellName:t,value:a,oldValue:i};this.execute("beforeCellValueChange",r)&&(n[t]=r.value,this.markRowState(e,q),this.execute("afterCellValueChange",r),this.doPropertyChange("setCellValue",r))}}}},{key:"setCellValues",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];M(t)&&t.forEach(function(t){return e.setCellValue(t.rowIndex,t.cellName||t.field,t.value)})}},{key:"getCellState",value:function(e,t,a){var n,i=this.getRowKey(e),r=i?null===(n=this._get_data("cellState"))||void 0===n||null===(n=n[i])||void 0===n?void 0:n[t]:null;if(r)return r[a]}},{key:"setCellState",value:function(e,t,a,n){var i,o=null===(i=this._get_data("rows"))||void 0===i||null===(i=i[e])||void 0===i?void 0:i[this.getIdFlag()],s=o||e;if(!A(s)){var u=this.getCellState(e,t,a);if(u!==n){var l={rowIndex:e,rowId:o,cellName:t,propertyName:a,value:n,oldValue:u};if(this.execute("beforeCellStateChange",l)){var d=c({},this._get_data("cellState")||{});d[s]=c({},d[s]||{}),d[s][t]=c(c({},d[s][t]||{}),{},r({},a,n)),this._applyState("cellState",d),this.execute("afterCellStateChange",l)}}}}},{key:"setCellStates",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];M(t)&&t.forEach(function(t){return e.setCellState(t.rowIndex,t.cellName,t.propertyName||t.name,t.value)})}},{key:"getRowDataState",value:function(e){var t,a=this.getDataSourceIndexByRow(e);return null===(t=this._get_data("rowsDataState"))||void 0===t?void 0:t[a]}},{key:"getDataSourceIndexByRow",value:function(e){var t=this,a=(this._get_data("rows")||[])[e];if(!a)return-1;var n=this._get_data("dataSource")||[],i=n.indexOf(a);return i>-1?i:n.findIndex(function(e){return(null==e?void 0:e[t.getIdFlag()])===(null==a?void 0:a[t.getIdFlag()])})}},{key:"setRowDataState",value:function(e,t){var a=this.getDataSourceIndexByRow(e);if(!(a<0)){var n=g(this._get_data("rowsDataState")||[]);n[a]=t,this._set_data("rowsDataState",n,!0)}}},{key:"markRowState",value:function(e,t){var a=this.getRowDataState(e);a!==O&&a!==t&&this.setRowDataState(e,t)}},{key:"markRowUpdate",value:function(e){var t="number"==typeof e?e:this.getRowIndex(e);t<0||this.markRowState(t,q)}},{key:"getRowState",value:function(e,t){var a,n=this.getRowKey(e),i=n?null===(a=this._get_data("rowState"))||void 0===a?void 0:a[n]:null;if(i&&t)return i[t]}},{key:"setRowState",value:function(e,t,a){var n,i=null===(n=this._get_data("rows"))||void 0===n?void 0:n[e];if(i&&t){var o=this.getRowKey(e),s=this.getRowState(e,t);if(s!==a){var u={rowIndex:e,rowId:i[this.getIdFlag()],propertyName:t,value:a,oldValue:s};if(this.execute("beforeRowStateChange",u)){var l=c({},this._get_data("rowState")||{});l[o]=c(c({},l[o]||{}),{},r({},t,a)),this._applyState("rowState",l),this.execute("afterRowStateChange",u)}}}}},{key:"setRowStates",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];M(t)&&t.forEach(function(t){return e.setRowState(t.rowIndex,t.propertyName||t.name,t.value)})}},{key:"getDirtyData",value:function(e){var t=this,a=this._get_data("dataSource")||[],n=this._get_data("rowsDataState")||[],i=[];return a.forEach(function(e,a){var r=n[a];if(r){var o=N(e);o[t.getStatusFlag()]=r,i.push(o)}}),i.length?i:void 0}},{key:"getDirtyRowIndexes",value:function(){var e=this;return(this._get_data("rows")||[]).map(function(e,t){return t}).filter(function(t){return!!e.getRowDataState(t)})}},{key:"isDirty",value:function(){return!!this.getDirtyData()}},{key:"backupState",value:function(){this._set_data("backupData",{dataSource:N(this._get_data("dataSource")||[]),rowsDataState:g(this._get_data("rowsDataState")||[])})}},{key:"restoreState",value:function(){var e=this._get_data("backupData");e&&(this._set_data("dataSource",e.dataSource,!0),this._set_data("rowsDataState",g(e.rowsDataState),!0),this.showPage())}},{key:"insertRow",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>3?arguments[3]:void 0,n=this._get_data("rows")||[],i=Math.min(n.length,Math.max(0,void 0===e?n.length:e)),r={index:i,row:c({},t),isCopy:a};if(this.execute("beforeInsertRow",r)){var o=r.row;delete o[this.getIdFlag()],T.call(this,[o]);var s=this._get_data("dataSource")||[],u=i<n.length?this.getDataSourceIndexByRow(i):s.length;s.splice(u<0?s.length:u,0,o);var l=g(this._get_data("rowsDataState")||[]);return l.splice(u<0?l.length:u,0,O),n.splice(i,0,o),this._set_data("rowsDataState",l,!0),this.setRows(n),this.execute("afterInsertRow",c(c({},r),{},{rowIndex:i})),o}}},{key:"insertRows",value:function(e){var t=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=[];return(M(a)?a:[a]).forEach(function(a,i){n.push(t.insertRow(e+i,a))}),n}},{key:"appendRow",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return this.insertRow(this.getRowsCount(),e)}},{key:"updateRow",value:function(e){var t,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=null===(t=this._get_data("rows"))||void 0===t?void 0:t[e];n&&this.execute("beforeUpdateRow",{index:e,row:a})&&(Object.assign(n,a),this.markRowState(e,q),this.setRows(this._get_data("rows")),this.execute("afterUpdateRow",{index:e,row:n}))}},{key:"updateRows",value:function(){var e=this;(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).forEach(function(t){var a;return e.updateRow(null!==(a=t.rowIndex)&&void 0!==a?a:t.index,t.rowData||t.row)})}},{key:"deleteRows",value:function(e){var t=this,a=(M(e)?e:[e]).filter(function(e){return e>=0&&e<t.getRowsCount()}).sort(function(e,t){return e-t});if(a.length){var n=this.getRowsByIndexes(a);if(this.execute("beforeDeleteRows",n,a)){var i=this._get_data("dataSource")||[],r=g(this._get_data("rowsDataState")||[]),o=new Set,s=new Set;n.forEach(function(e){var a=i.indexOf(e);if(!(a<0)){var n=e[t.getIdFlag()];o.add(n),r[a]===O&&s.add(n)}});var u=[],l=[];i.forEach(function(e,a){var n=e[t.getIdFlag()];if(!o.has(n))return u.push(e),void l.push(r[a]);s.has(n)||(u.push(e),l.push(j))}),this._set_data("dataSource",u,!0),this._set_data("rowsDataState",l,!0),this.showPage(),this.execute("afterDeleteRows",{rowIndexes:a,rows:n})}}}},{key:"deleteAllRows",value:function(){this.deleteRows(this.getRows().map(function(e,t){return t}))}},{key:"clear",value:function(){this._set_data("dataSource",[],!0),this._set_data("rows",[],!0),this._set_data("rowsDataState",[],!0),this.clearSelection(),this.applyPageInfo(c(c({},this.getPageInfo()),{},{recordCount:0,pageIndex:1})),this.setDataSourceView()}},{key:"select",value:function(e,t){var a=this;if(null!=e||!0===t){!0===t&&this.unselectAll({silent:!0});var n=!0===t?this.getRows().map(function(e,t){return t}):M(e)?e:[e];n=n.filter(function(e){return e>=0&&e<a.getRowsCount()});var i=this._get_data("rows")||[],r=this.getSelectedFlag(),o=n.filter(function(e){return!i[e][r]});if(o.length){var s={rowIndexes:o,rows:o.map(function(e){return i[e]})};this.execute("beforeSelect",s)&&(o.forEach(function(e){i[e][r]=!0,a.cacheSelectedRow(i[e],!0)}),this.flushSelection())}else!0===t&&this.flushSelection()}}},{key:"unselect",value:function(e){var t=this;if(null!=e){var a=M(e)?e:[e],n=this._get_data("rows")||[],i=this.getSelectedFlag(),r=a.filter(function(e){var t;return null===(t=n[e])||void 0===t?void 0:t[i]});r.length&&this.execute("beforeUnselect",r)&&(r.forEach(function(e){n[e][i]=!1,t.cacheSelectedRow(n[e],!1)}),this.flushSelection())}}},{key:"selectAll",value:function(){var e=this,t=this._get_data("rows")||[],a=this.getSelectedFlag();t.forEach(function(t){t[a]=!0,e.cacheSelectedRow(t,!0)}),this.flushSelection()}},{key:"unselectAll",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},a=this.getSelectedFlag();((t.onlyPage?this._get_data("rows"):this._get_data("dataSource"))||[]).forEach(function(e){e[a]=!1}),t.onlyPage?(this._get_data("rows")||[]).forEach(function(t){return e.cacheSelectedRow(t,!1)}):(this._set_data("selectedKeys",[],!0),this._set_data("selectedRowsMap",{},!0),this._set_data("selectedKeysSet",new Set,!0)),t.silent||this.flushSelection()}},{key:"clearSelection",value:function(){this.unselectAll()}},{key:"setSelectedRows",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],a=M(t)?t:[],n=this.getRowKeyField(),i=new Set(a.map(function(e){var t;return String(null!==(t=null==e?void 0:e[n])&&void 0!==t?t:e)})),r=this._get_data("rows")||[],o=this.getSelectedFlag();r.forEach(function(t){var a=i.has(String(t[n]));a!==!!t[o]&&(t[o]=a,e.cacheSelectedRow(t,a))}),this.flushSelection()}},{key:"setSelection",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.unselectAll({silent:!0}),this.setSelectedRows(e)}},{key:"getSelectedRows",value:function(e){var t=this._get_data("rows")||[],a=this.getSelectedFlag(),n=e&&new Set(M(e)?e:[e]);return t.filter(function(e,t){return e[a]&&(!n||n.has(t))})}},{key:"getSelectedRowIndexes",value:function(){var e=this._get_data("rows")||[],t=this.getSelectedFlag(),a=[];return e.forEach(function(e,n){e[t]&&a.push(n)}),a}},{key:"getSelectedKeys",value:function(){return this._get_data("selectedKeys")||[]}},{key:"getAllCacheSelectedRows",value:function(){var e=this._get_data("selectedKeys")||[],t=this._get_data("selectedRowsMap")||{};return e.map(function(e){return t[e]}).filter(Boolean)}},{key:"selectByKeys",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],a=this.getRowKeyField(),n=M(e)?e:[e],i=this._get_data("rows")||[],r=[];n.forEach(function(e){var t=i.findIndex(function(t){return String(t[a])===String(e)});t>-1&&r.push(t)}),r.length&&(t?this.select(r):this.unselect(r))}},{key:"getSelectedNodes",value:function(){return this.getAllCacheSelectedRows()}},{key:"cacheSelectedRow",value:function(e,t){var a=String(null==e?void 0:e[this.getRowKeyField()]),n=(this._get_data("selectedKeys")||[]).filter(function(e){return e!==a}),i=c({},this._get_data("selectedRowsMap")||{});t&&n.push(a),t?i[a]=e:delete i[a],this._set_data("selectedKeys",n,!0),this._set_data("selectedRowsMap",i,!0),this._set_data("selectedKeysSet",new Set(n),!0)}},{key:"flushSelection",value:function(){this._applyState("selectedRows",this.getSelectedRows()),this.execute("selectionChange",{value:this.getSelectedRows(),keys:this.getSelectedKeys(),indexes:this.getSelectedRowIndexes()})}},{key:"restoreSelectedFlags",value:function(){if(this.get("cacheSelectedRows")){var e=this._get_data("selectedKeysSet")||new Set;if(e.size){var t=this.getRowKeyField(),a=this.getSelectedFlag();(this.getRows()||[]).forEach(function(n){n[a]=e.has(String(n[t]))})}}}},{key:"setPagination",value:function(e){this._applyState("pagination",!!e),this.showPage()}},{key:"getPageInfo",value:function(){return this._get_data("pageInfo")||createDefaults().pageInfo}},{key:"getPageIndex",value:function(){return this.getPageInfo().pageIndex}},{key:"getPageSize",value:function(){return this.getPageInfo().pageSize}},{key:"getTotalCount",value:function(){return this.getPageInfo().recordCount}},{key:"setPageInfo",value:function(e){this.applyPageInfo(c(c({},this.getPageInfo()),e),{refresh:!0})}},{key:"setPageIndex",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"number"==typeof e&&this.applyPageInfo(c(c({},this.getPageInfo()),{},{pageIndex:Math.max(1,e)}),{refresh:t})}},{key:"setPageSize",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];"number"==typeof e&&this.applyPageInfo(c(c({},this.getPageInfo()),{},{pageSize:Math.max(-1,e),pageIndex:1}),{refresh:t})}},{key:"setRecordCount",value:function(e){this.applyPageInfo(c(c({},this.getPageInfo()),{},{recordCount:e||0}))}},{key:"applyPageInfo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=c({},e||{}),n=-1===a.pageSize?-1:a.pageSize||20,i=a.recordCount||0,r=i>0;return a.pageSize=n,a.recordCount=i,a.pageCount=n>0?Math.max(1,Math.ceil(i/n)):1,a.pageIndex=n>0?Math.max(1,r?Math.min(a.pageIndex||1,a.pageCount):a.pageIndex||1):1,a.beginPageIndex=n>0?(a.pageIndex-1)*n+1:1,a.endPageIndex=n>0?Math.min(a.pageIndex*n,i):i,this._set_data("pageInfo",a,!0),t.silent||(this._applyState("pageInfo",a),this.isRemote()||this.showPage(),t.refresh&&this.isRemote()&&this.refresh()),a}},{key:"showPage",value:function(){var e=this._get_data("dataSource")||[];if(!this.isRemote()&&this.isPagination()){var t=this.getPageInfo(),a=t.pageIndex,n=t.pageSize,i=(a-1)*n;this.setRows(e.slice(i,i+n))}else this.setRows(e)}},{key:"setDataSource",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>2?arguments[2]:void 0;if("local"===this._get_data("dataSourceMode")){var n=cb.utils.isArray(e)?e:[];if(!this.execute("beforeSetDataSource",n))return;var i=this._get_data("rowKeyField"),r={};n.forEach(function(e){r[e[i]]=e}),this._set_data("keyMap",r),this._set_data("dataSource",n,!0),this.getCache("grandson"),n.length&&T.call(this,n),this.initRowState(),setCachePaginationRowData.call(this,n),this.doPropertyChange("resetCellStatus"),this._set_data("rowState",{},!0),this.doPropertyChange("setDataSource",this.getShowRows()),this._set_data("delayInsertRows",[]),this._get_data("isSorting")&&this._set_data("isSorting",!1),this.execute("afterSetDataSource",n)}else{if(!this.execute("beforeProxyLoad",t))return;this._get_data("pageInfo").pageIndex=1;this._set_data("proxyConfig",e),this._set_data("queryParams",t),this._set_data("callback",a),V.call(this,e,t,a,!0,!0)}}},{key:"setRows",value:function(e){var t=M(e)?e:[];this._set_data("rows",t,!0),this.setRowsIdMap(),this._applyState("data",t)}},{key:"setDataSourceView",value:function(){this._applyState("data",this._get_data("rows")||[])}},{key:"setRowsIdMap",value:function(){var e=this,t={};(this._get_data("rows")||[]).forEach(function(a){void 0!==(null==a?void 0:a[e.getIdFlag()])&&(t[a[e.getIdFlag()]]=a)}),this._set_data("rowsIdMap",t)}},{key:"getRowIdMap",value:function(){return this._get_data("rowsIdMap")||{}}},{key:"validate",value:function(e,t){var a=this;if(e)return this.doPropertyChange("validate",{type:"",message:"",errors:[]}),this._set_data("validateErrors",[]),!1;this.deleteNotModifiedRows();var n=this._get_data("columns")||{},i=t?this.getRowsByIndexes(t):this.getRows(),r=[];i.forEach(function(e,t){for(var i in n){var o=n[i];if(a.isRequiredColumn(o)){var s=e[i];if(A(s)||M(s)&&!s.length||F(s)){var u=o.cShowCaption||o.cCaption||o.cCaption||o.title||i;r.push({rowIndex:t,rowId:e[a.getIdFlag()],cellName:i,message:"".concat(u,"不能为空")}),a.setCellState(t,i,"msg","不能为空")}}}}),this._set_data("validateErrors",r);var o=r.length?r[0].message:"";return this.doPropertyChange("validate",{type:r.length?"error":"",message:o,errors:r}),this.execute("afterValidate",{valid:!r.length,errors:r}),!r.length}}])}(),z=function(){function e(){return a(this,e),t(this,e,arguments)}return s(e,I),i(e,[{key:"getParams",value:function(){return this._get_data("params")}},{key:"setParams",value:function(e){this._set_data("params",e,!0)}},{key:"set",value:function(e,t){t instanceof I&&(t.setParent(this),t.setName(e)),this._set_data(e,t,!0)}},{key:"setData",value:function(e){for(var t in e)this.addProperty(t,e[t])}},{key:"addProperty",value:function(e,t){var a=this.get(e);null!=a&&a.setData?a.setData(t):this.set(e,t)}},{key:"getData",value:function(){var e=this,t=this._get_data("propertyNames")||[],a={};return t.forEach(function(t){var n,i=e.get(t);i instanceof I&&!1!==i._get_data("needCollect")&&(a[t]=null===(n=i.getData)||void 0===n?void 0:n.call(i))}),a}},{key:"getAllData",value:function(e){var t=this,a=this._get_data("propertyNames")||[],n={};return a.forEach(function(a){var i,r=t.get(a);if(r instanceof I&&!1!==r._get_data("needCollect")&&(!e||!r._get_data("isGrid"))){var o=null===(i=r.getData)||void 0===i?void 0:i.call(r);void 0!==o&&(n[a]=o)}}),n}},{key:"removeProperty",value:function(e){var t=this._get_data("propertyNames")||[],a=t.indexOf(e);-1!==a&&t.splice(a,1),this._del_data(e)}},{key:"loadData",value:function(e){this.setCache("isLoadData",!0),this.clear(),this.setData(e),this.setDirty(!1),this.setCache("isLoadData",!1)}},{key:"clear",value:function(e){var t=this;(this._get_data("propertyNames")||[]).forEach(function(a){var n,i=t.get(a);i instanceof I&&!1!==i._get_data("needClear")&&(null===(n=i.clear)||void 0===n||n.call(i,e))})}},{key:"setDirty",value:function(e){e?this._set_data("isDirty",!0):(this._del_data("isDirty"),this._set_data("originalData",this.getData()))}},{key:"getGridModel",value:function(e){var t;if(e)return this.get(e);var a=this._get_data("gridModel");if(a)return a;var n=null===(t=this.getParams())||void 0===t?void 0:t.masterGridModelName;if(n)return this.get(n);for(var i=this._get_data("propertyNames"),r=0,o=i.length;r<o;r++){if((a=this.get(i[r]))instanceof B)return this._set_data("gridModel",a),a}}},{key:"getGridModels",value:function(){for(var e=this._get_data("propertyNames"),t=[],a=0,n=e.length;a<n;a++){var i=this.get(e[a]);i instanceof B&&t.push(i)}return t}}])}();function L(e,n){var r,o=null===(r=window.__devfab)||void 0===r?void 0:r.require,u=n||{},l=u.domainKeyField,c=void 0===l?"domainKey":l,d=u.billNoField,h=void 0===d?"billNo":d,f=u.modelNameField,g=void 0===f?"modelName":f,v=u.enableExtendjs,y=void 0===v||v;null!=n&&n.require&&(o=null==n?void 0:n.require);var _=e[c]||"",p=e[h],w=function(){function e(){return a(this,e),t(this,e,arguments)}return s(e,z),i(e,[{key:"init",value:function(e,t){var a=this.createModels(e,t);this.setData(a),this.setDirty(!1)}},{key:"createModels",value:function(e,t){var a={};return(Array.isArray(e)?e:[]).forEach(function(e){var i,r,o=null==n||null===(i=n.createModelFactory)||void 0===i?void 0:i.call(n,e);o||(o=function(e){var t;"input"===e.cControlType.toLowerCase()&&(t=new D(e));return t}(e));var s={model:o,field:e,meta:t};null==n||null===(r=n.onBeforeCreateModel)||void 0===r||r.call(n,s),a[e[g]]=s.model}),a}},{key:"initData",value:function(){this.initExtendJs()}},{key:"initExtendJs",value:function(){window&&window.__debugger_initExtendJs;var e=this;if(y){var t="".concat(p,"_VM.Extend.js"),a=[t];if("function"!=typeof o)return console.warn("requirejs.js 未加载,跳过扩展脚本:".concat(t)),void e.execute("extendReady",e);o(_,a,function(a,n){if(a&&a.doAction)try{a.doAction("init",e),n&&n.doAction("init",e)}catch(e){console.error("扩展脚本异常:",e)}else console.error("".concat(t,"扩展文件extend.*.min.js文件加载失败 或 未注册扩展脚本"));e.execute("extendReady",e)},function(a){console.warn("未找到扩展脚本:".concat(t,"错误信息:"),a),e.execute("extendReady",e)})}else e.execute("extendReady",e)}}])}();return w.prototype.modelType="ViewModel",w}function U(e,t){var a=new(L(e,t));return a.init(e.models,e),a}var J={BaseModel:I,FilterModel:P,SimpleModel:D,GridModel:B,ViewModel:z,createViewModel:L,initViewModel:U};export{I as BaseModel,P as FilterModel,B as GridModel,D as SimpleModel,z as ViewModel,L as createViewModel,J as default,U as initViewModel};
|