devfab 1.0.0 → 1.2.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 +200 -57
- package/dist/common/models.esm.js +3 -0
- package/dist/common/models.js +3 -0
- package/dist/common/utils.esm.js +1 -0
- package/dist/common/utils.js +1 -0
- package/dist/index.esm.js +3 -1
- package/dist/index.js +3 -1
- package/dist/index.umd.js +3 -1
- package/lib/devfab.js +482 -436
- package/lib/devfab.min.js +3 -1
- package/lib/requirejs.js +2473 -2472
- package/package.json +78 -78
package/README.md
CHANGED
|
@@ -4,6 +4,42 @@
|
|
|
4
4
|
|
|
5
5
|
链路:后端按 `billno` 下发视图元数据 JSON → `builder.render(meta)` 渲染成组件树 → 各 adapter 把第三方控件包成「受模型驱动、状态可被外部 `setState` / `getState` 读写」的受控组件。
|
|
6
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
|
+
|
|
7
43
|
## 安装
|
|
8
44
|
|
|
9
45
|
```bash
|
|
@@ -12,74 +48,158 @@ npm install devfab
|
|
|
12
48
|
|
|
13
49
|
外部依赖由宿主提供,不打进产物(见 `peerDependencies`):
|
|
14
50
|
|
|
15
|
-
- React 侧:`react` / `react-dom` / `classnames`
|
|
51
|
+
- React 侧:`react` >= 16 / `react-dom` >= 16 / `classnames`
|
|
16
52
|
- Vue 侧:`vue` >= 3(**仅支持 Vue 3**,适配层使用 `defineComponent` / `reactive` / `h`)
|
|
53
|
+
- `antd` 在构建配置里被列为 React 产物的 `external`,但未写进 `peerDependencies`,宿主需自行保证存在
|
|
17
54
|
|
|
18
55
|
## 开发与构建
|
|
19
56
|
|
|
20
|
-
源码为纯 JavaScript(`.js` / `.jsx`),不含 TypeScript,也不产出类型声明。
|
|
21
|
-
|
|
22
57
|
| 命令 | 说明 |
|
|
23
58
|
| --- | --- |
|
|
24
|
-
| `npm run dev` | 清理后以 development
|
|
25
|
-
| `npm run build` | 清理 →
|
|
26
|
-
| `npm run smoke` |
|
|
27
|
-
| `npm run lint` / `npm run
|
|
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。
|
|
28
71
|
|
|
29
72
|
## 产物清单
|
|
30
73
|
|
|
31
74
|
| 路径 | 格式 | 说明 |
|
|
32
75
|
| --- | --- | --- |
|
|
33
|
-
| `lib/devfab.js` | UMD | 核心运行时,`<script>` 引入后挂到 `window.devfab
|
|
34
|
-
| `lib/devfab.min.js` | UMD |
|
|
35
|
-
| `lib/requirejs.js` | — | vendored RequireJS,挂 `window.require` / `window.define` |
|
|
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` |
|
|
36
79
|
| `dist/index.js` `.esm.js` `.umd.js` | CJS / ESM / UMD | 核心包入口,对应 `package.json` 的 `main` / `module` / `umd` |
|
|
37
|
-
| `dist/react/**` | CJS
|
|
38
|
-
| `dist/vue/vue3-adapter.js` `.esm.js` | CJS / ESM | Vue 3 适配层,由宿主显式 import
|
|
39
|
-
|
|
40
|
-
|
|
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 | 工具层单独入口 |
|
|
41
84
|
|
|
42
85
|
## 运行时契约
|
|
43
86
|
|
|
44
|
-
React /
|
|
45
|
-
|
|
46
|
-
```js
|
|
47
|
-
// 方式一:包引入,会自动挂载 window.devfab
|
|
48
|
-
import devfab from 'devfab'
|
|
87
|
+
React 适配层从**全局**读取运行时:`src/react/adapter/**` 里直接使用裸标识符 `devfab.builder`、`devfab.utils.models`,编译后原样保留,运行时解析到 `window.devfab`。因此宿主必须先准备好全局运行时,再加载适配层组件:
|
|
49
88
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
89
|
+
```html
|
|
90
|
+
<script src="..../lib/requirejs.js"></script>
|
|
91
|
+
<script src="..../lib/devfab.js"></script>
|
|
53
92
|
```
|
|
54
93
|
|
|
55
|
-
|
|
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` 提供两个入口,用于按元数据批量造模型:
|
|
56
141
|
|
|
57
142
|
```js
|
|
58
|
-
import
|
|
143
|
+
import { createViewModel, initViewModel } from 'devfab/dist/common/models'
|
|
59
144
|
|
|
60
|
-
|
|
61
|
-
|
|
145
|
+
// 返回 VM 类,可自行 new + init
|
|
146
|
+
const VM = createViewModel(meta, params)
|
|
147
|
+
// 直接返回实例:内部已执行 init(meta.models, meta)
|
|
148
|
+
const vm = initViewModel(meta, params)
|
|
62
149
|
```
|
|
63
150
|
|
|
64
|
-
|
|
151
|
+
`params` 可配置:`domainKeyField` / `billNoField` / `modelNameField`(默认 `domainKey` / `billNo` / `modelName`)、`enableExtendjs`(是否加载扩展脚本)、`require`(覆盖 require 实现)、`createModelFactory`(自定义控件类型的模型映射)、`onBeforeCreateModel`(造模型前的钩子)。
|
|
65
152
|
|
|
66
|
-
`
|
|
153
|
+
创建后 `initData()` → `initExtendJs()` 会加载 `${billno}_VM.Extend.js` 并执行其 `doAction('init', vm)`;无论成功失败都会抛出 `extendReady` 事件,宿主可监听它作为「渲染就绪」信号。
|
|
67
154
|
|
|
68
|
-
|
|
155
|
+
## `builder` —— 组件注册与渲染
|
|
156
|
+
|
|
157
|
+
`_utils/builder.js` 是模块级单例(`isInit` / `components` / `renderFactory` 都在模块作用域),一个页面只能存在一份。
|
|
158
|
+
|
|
159
|
+
| 方法 | 说明 |
|
|
69
160
|
| --- | --- |
|
|
70
|
-
| `
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `
|
|
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 展开。组件未注册时只打印告警,不抛错。
|
|
74
169
|
|
|
75
|
-
## React
|
|
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
|
+
用法示意:
|
|
76
196
|
|
|
77
197
|
```jsx
|
|
78
198
|
import React from 'react'
|
|
79
|
-
import
|
|
80
|
-
import
|
|
199
|
+
import { adapter } from 'devfab/dist/react'
|
|
200
|
+
import Input from 'antd/lib/input'
|
|
81
201
|
|
|
82
|
-
const {
|
|
202
|
+
const { ModelAdapter, PageModelAdapter } = adapter
|
|
83
203
|
|
|
84
204
|
// 1. 注册控件:把元数据里的 component 名映射到实际组件
|
|
85
205
|
builder.initComponent({
|
|
@@ -88,38 +208,30 @@ builder.initComponent({
|
|
|
88
208
|
|
|
89
209
|
// 2. 告诉 builder 如何把节点变成 React 元素(必须由宿主提供)
|
|
90
210
|
builder.initRenderFactory(({ node, props }) =>
|
|
91
|
-
React.createElement(node.component || 'div', { key:
|
|
211
|
+
React.createElement(node.component || 'div', { key: props.key, ...props }, node.children)
|
|
92
212
|
)
|
|
93
213
|
|
|
94
214
|
// 3. 用后端下发的元数据渲染
|
|
95
215
|
const nodes = builder.render(meta)
|
|
96
216
|
```
|
|
97
217
|
|
|
98
|
-
`
|
|
218
|
+
> 组件里出现的全局 `devfab` 由宿主的 `<script>`(或引入 `devfab` 后自行赋值)提供,见「运行时契约」。
|
|
99
219
|
|
|
100
|
-
|
|
101
|
-
- 控件的 `setState('value', v)` 会回写模型值;
|
|
102
|
-
- 组件以 `name` 登记进 `vm`,父级 `vm.getData()` 才能收集到这个字段;
|
|
103
|
-
- 传 `ctrlName` 可做定向通知,只推给指定控件。
|
|
220
|
+
## Vue 3 适配层
|
|
104
221
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
```js
|
|
108
|
-
import { defineClassComponent, defineFunctionComponent } from 'devfab/dist/vue/vue3-adapter'
|
|
109
|
-
// 只提供 CJS / ESM,模块引用即可;不产出 UMD,也不会挂到 window
|
|
110
|
-
```
|
|
222
|
+
入口 `src/vue/vue-adapter/index.js`,产物 `dist/vue/vue3-adapter.{js,esm.js}`,由宿主显式 `import` / `require`,不产出 UMD、不挂全局。两个入口函数分别对应 React 的两种组件心智模型:
|
|
111
223
|
|
|
112
|
-
class
|
|
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`。
|
|
113
225
|
|
|
114
226
|
```js
|
|
227
|
+
import { defineClassComponent } from 'devfab/dist/vue/vue3-adapter'
|
|
228
|
+
|
|
115
229
|
export default defineClassComponent(
|
|
116
230
|
class Counter {
|
|
117
231
|
state = { n: 0 }
|
|
118
|
-
|
|
119
232
|
componentDidMount() {
|
|
120
233
|
console.log(this.$el)
|
|
121
234
|
}
|
|
122
|
-
|
|
123
235
|
render(h) {
|
|
124
236
|
return h('div', { onClick: () => this.setState({ n: this.state.n + 1 }) }, String(this.state.n))
|
|
125
237
|
}
|
|
@@ -127,7 +239,7 @@ export default defineClassComponent(
|
|
|
127
239
|
)
|
|
128
240
|
```
|
|
129
241
|
|
|
130
|
-
|
|
242
|
+
**`defineFunctionComponent(fn, options)`** —— 用函数组件 + Hooks 写组件,`h` 由第三个参数注入,Hooks 按索引复用状态。
|
|
131
243
|
|
|
132
244
|
```js
|
|
133
245
|
import { defineFunctionComponent, useState } from 'devfab/dist/vue/vue3-adapter'
|
|
@@ -140,8 +252,39 @@ export default defineFunctionComponent((props, ctx, h) => {
|
|
|
140
252
|
|
|
141
253
|
可用 Hooks:`useState`、`useRef`、`useMemo`、`useCallback`、`useEffect`、`useLayoutEffect`、`useReducer`、`useContext`、`useProvide`。
|
|
142
254
|
|
|
143
|
-
|
|
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
|
|
144
289
|
|
|
145
|
-
|
|
146
|
-
- 工程为纯 JavaScript,不产出类型声明;宿主若需要类型提示,请自行声明或依赖 `JSDoc`。
|
|
147
|
-
- `builder` 是模块级单例(`isInit` / `components` / `renderFactory` 均在模块作用域),一个页面只能存在一份运行时,微前端或多实例场景需要额外隔离。
|
|
290
|
+
Apache License 2.0,见 [LICENSE](./LICENSE)。
|
|
@@ -0,0 +1,3 @@
|
|
|
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,n,r,i,o){try{var s=e[i](o),u=s.value}catch(e){return void a(e)}s.done?t(u):Promise.resolve(u).then(n,r)}function a(e){return function(){var a=this,n=arguments;return new Promise(function(r,i){var o=e.apply(a,n);function s(e){t(o,r,i,s,u,"next",e)}function u(e){t(o,r,i,s,u,"throw",e)}s(void 0)})}}function n(e,t,a){return t=u(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,c()?Reflect.construct(t,a||[],u(e).constructor):t.apply(e,a))}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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,m(n.key),n)}}function o(e,t,a){return t&&i(e.prototype,t),a&&i(e,a),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t,a){return(t=m(t))in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function l(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&&y(e,t)}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function d(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 f(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?d(Object(a),!0).forEach(function(t){s(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):d(Object(a)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}function h(e,t){if(null==e)return{};var a,n,r=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 i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],-1===t.indexOf(a)&&{}.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}function v(){
|
|
2
|
+
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
+
var e,t,a="function"==typeof Symbol?Symbol:{},n=a.iterator||"@@iterator",r=a.toStringTag||"@@toStringTag";function i(a,n,r,i){var u=n&&n.prototype instanceof s?n:s,l=Object.create(u.prototype);return g(l,"_invoke",function(a,n,r){var i,s,u,l=0,c=r||[],d=!1,f={p:0,n:0,v:e,a:h,f:h.bind(e,4),d:function(t,a){return i=t,s=0,u=e,f.n=a,o}};function h(a,n){for(s=a,u=n,t=0;!d&&l&&!r&&t<c.length;t++){var r,i=c[t],h=f.p,v=i[2];a>3?(r=v===n)&&(u=i[(s=i[4])?5:(s=3,3)],i[4]=i[5]=e):i[0]<=h&&((r=a<2&&h<i[1])?(s=0,f.v=n,f.n=i[1]):h<v&&(r=a<3||i[0]>n||n>v)&&(i[4]=a,i[5]=n,f.n=v,s=0))}if(r||a>1)return o;throw d=!0,n}return function(r,c,v){if(l>1)throw TypeError("Generator is already running");for(d&&1===c&&h(c,v),s=c,u=v;(t=s<2?e:u)||!d;){i||(s?s<3?(s>1&&(f.n=-1),h(s,u)):f.n=u:f.v=u);try{if(l=2,i){if(s||(r="next"),t=i[r]){if(!(t=t.call(i,u)))throw TypeError("iterator result is not an object");if(!t.done)return t;u=t.value,s<2&&(s=0)}else 1===s&&(t=i.return)&&t.call(i),s<2&&(u=TypeError("The iterator does not provide a '"+r+"' method"),s=1);i=e}else if((t=(d=f.n<0)?u:a.call(n,f))!==o)break}catch(t){i=e,s=1,u=t}finally{l=1}}return{value:t,done:d}}}(a,r,i),!0),l}var o={};function s(){}function u(){}function l(){}t=Object.getPrototypeOf;var c=[][n]?t(t([][n]())):(g(t={},n,function(){return this}),t),d=l.prototype=s.prototype=Object.create(c);function f(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,g(e,r,"GeneratorFunction")),e.prototype=Object.create(d),e}return u.prototype=l,g(d,"constructor",l),g(l,"constructor",u),u.displayName="GeneratorFunction",g(l,r,"GeneratorFunction"),g(d),g(d,r,"Generator"),g(d,n,function(){return this}),g(d,"toString",function(){return"[object Generator]"}),(v=function(){return{w:i,m:f}})()}function g(e,t,a,n){var r=Object.defineProperty;try{r({},"",{})}catch(e){r=0}g=function(e,t,a,n){function i(t,a){g(e,t,function(e){return this._invoke(t,a,e)})}t?r?r(e,t,{value:a,enumerable:!n,configurable:!n,writable:!n}):e[t]=a:(i("next",0),i("throw",1),i("return",2))},g(e,t,a,n)}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function p(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,r,i,o,s=[],u=!0,l=!1;try{if(i=(a=a.call(e)).next,0===t){if(Object(a)!==a)return;u=!1}else for(;!(u=(n=i.call(a)).done)&&(s.push(n.value),s.length!==t);u=!0);}catch(e){l=!0,r=e}finally{try{if(!u&&null!=a.return&&(o=a.return(),Object(o)!==o))return}finally{if(l)throw r}}return s}}(e,t)||k(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 w(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)||k(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 m(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 S(e){return S="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},S(e)}function k(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 x=function(){return o(function e(t){r(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]}}])}(),b=function(){return o(function e(t){r(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 r=this.events.get(e),i=this.firstevents.get(e);if(!r&&!i)return!0;var o=!0;return[].concat(w(i||[]),w(r||[])).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),r=null==n?void 0:n.findIndex(function(e){return e.callback===t});-1!==r&&(null==n||n.splice(r,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,r=this,i=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||r,s);else try{a=n.callback.apply(n.context||r,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==i||i(s)):r._asyncExecute(e,l.slice(t+1),{resolve:i,reject:o,args:s})}})):(u=!1!==a&&u,t===l.length-1&&(u?null==i||i(s):null==o||o()))},f=0;f<l.length&&0!==(n=d(f));f++)if(n)return n.v;return u}},{key:"_asyncPromiseExecute",value:function(e,t,a,n){var r=this.events.get(e),i=this.firstevents.get(e);if(!((Array.isArray(r)?r.length:r)||(Array.isArray(i)?i.length:i)))return null==t?void 0:t();var o=[].concat(w(i||[]),w(r||[]));return this._asyncExecute(e,o,{resolve:t,reject:a,args:n})}},{key:"promiseExecute",value:function(e,t){var a=this,n=e,r=1;if("boolean"==typeof e&&(n=t,r=2),n){for(var i=arguments.length,o=new Array(i>2?i-2:0),s=2;s<i;s++)o[s-2]=arguments[s];var u=2===r?o:[t].concat(o);if(u.length){var l,c=u.length-1,d=u[c];if("function"!=typeof d){if("object"!==S(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 f=this.execute.apply(this,u);if(f instanceof Promise){var h=this;f.then(function(){for(var e=arguments.length,t=new Array(e),a=0;a<e;a++)t[a]=arguments[a];d.apply(h,t)},function(){l&&"function"==typeof l&&l()})}else if(!f)return void(l&&"function"==typeof l&&l())}}}},{key:"clearEvents",value:function(){this.events.clear(),this.firstevents.clear()}}])}();function R(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("&"),r=0,i=n.length;r<i;r++){var o=n[r]||"";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 C(e,t){if(!t)return e;var a=[],n=new R(e);for(var r in t)n.get(r)||a.push("".concat(r,"=").concat(t[r]));if(!a.length)return e;var i=a.join("&");return e.indexOf("?")>=0?"".concat(e,"&").concat(i):"".concat(e,"?").concat(i)}String.prototype.equalsIgnoreCase=function(e){return null!=e&&this.toLowerCase()===e.toLowerCase()};var I=["onBeforeRequest","_onAfterRequest"],P=["_onBeforeRequest","onAfterRequest"];var D={_xhrs:[],_jsonps:{index:0},doRequest:function(e){var t=e||{},a=t.onBeforeRequest;t._onAfterRequest;var n,r=h(t,I),i=r.method||"GET",o=r.url;try{null!=r&&r.requestHeaders&&(n=r.requestHeaders,r.requestHeaders=void 0,delete r.requestHeaders)}catch(e){console.log('[ajax]: [doRequest]: options["requestHeaders"] ERR : ',e)}try{r.params&&r.params.requestHeaders&&(n=r.params.requestHeaders,r.params.requestHeaders=void 0,delete r.params.requestHeaders)}catch(e){console.log('[ajax]: [doRequest]: options.params["requestHeaders"] ERR : ',e)}var s=null;if(i.equalsIgnoreCase("get")||i.equalsIgnoreCase("delete")?o=C(o,r.params):(i.equalsIgnoreCase("post")||i.equalsIgnoreCase("put"))&&(s=JSON.stringify(r.params)),r.jsonp)return this.getJsonp(o,r.callback);var u=this.getXMLHttpRequest();if(u){var l;if(u.open(i,o,!1!==r.async),r.timeout&&(u.timeout=r.timeout,u.setRequestHeader("timeout",r.timeout),u.ontimeout=function(){D.onerror(this,r,"timeout")}),r.contentType){if(u.setRequestHeader("Content-Type",r.contentType),r.contentType.indexOf("x-www-form-urlencoded")>=0)s=null===(l=new URLSearchParams(r.params))||void 0===l?void 0:l.toString()}else r.dateType?s=r.params:u.setRequestHeader("Content-Type","application/json;charset=utf-8");r.domainKey&&u.setRequestHeader("Domain-Key",r.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==r||!r.hasOwnProperty("withCredentials")||r.withCredentials;try{u.send(s)}catch(e){return{error:"NetWorkError",options:r}}if(!1===r.async)return null==a||a(r),this.onreadystatechange(u,r);u.onreadystatechange=function(){D.onreadystatechange(this,r)},null==a||a(r)}},beforeReadystatechange:function(e,t,a){null==a||a()},onreadystatechange:function(e,t){var a=t||{};a._onBeforeRequest;var n=a.onAfterRequest,r=h(a,P);if(4===e.readyState){if(null==n||n(),200===e.status){var i;try{if("blob"===r.responseType){var o=function(e){var t=e.xhr.getAllResponseHeaders(),a={};return t.split("\r\n").map(function(e){var t=p(e.split(": "),2),n=t[0],r=t[1];a[n]=r}),a}({xhr:e});i={code:e.status,data:{data:e.response,headers:o}}}else i=JSON.parse(e.responseText)}catch(t){D.onerror(e,r,e.responseText)}if(!1===r.async)return e.isBusy=!1,r.precallback&&r.precallback(i),D.processAjaxResult(i,!1,null,null,r,e);D.processAjaxResult(i,r.async,r.callback,r.context,r,e),r.precallback&&r.precallback(i)}else if(0===e.status)D.onerror(e,r,"网络连接已断开,请检查设备网络状态后重试");else if(502===e.status||504===e.status)D.onerror(e,r,"服务出错了,请稍后再试");else{if(401!==e.status){var s={};try{s=JSON.parse(e.responseText)}catch(t){s={code:e.status,message:e.responseText}}return D.onerror(e,r,s)}D.onerror(e,r,"登录信息失效,请重新登录或联系技术人员")}e.isBusy=!1}},onerror:function(e,t,a){var n="[ajax]: [onerror]: 接口返回错误 \n [状态码]: ".concat(e.status," \n [错误信息]: ").concat(("object"===S(a)?JSON.stringify(a):a)||"空"," \n [请求地址]: ").concat(t.url," \n [浏览器Token]: ").concat(document.cookie);console.log("Error.E01000",n);var r="object"===S(a)?a:{code:500,message:a};t.precallback&&t.precallback(r)},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++,r=document.createElement("script");this._jsonps[n]=function(e){try{t(e)}finally{document.body.removeChild(r)}},a+=-1===a.indexOf("?")?"?":"&callback=cb.rest.AjaxRequestManager._jsonps."+n,r.src=a,document.body.appendChild(r)},processAjaxResult:function(e,t,a,n,r,i){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 j(e,t){this.init&&this.init(e),this.queryParams=t}j.create=function(e,t){return new j(e,t)},j.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)},j.prototype.Do=function(e,t,a,n,r){var i,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!==(i=u.options)&&void 0!==i&&i.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=C(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=r||d.context||this):d.params=t,a&&(d.callback=a,d.context=r||d.context||this),!1===n&&(d.async=!1),this.ajax(c,d)}},j.prototype.ajax=function(e,t){return function(e,t){return t.url=e,D.doRequest(t)}(e,t)};var E=function(){return o(function e(t){r(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 x,this._data.events=new b}},{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 x,events:new b}}},{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,r=this._get_data("components")||[];if(!r.length)return r;var i=[];if(a){var o=r.find(function(e){return e.ctrlName===a});o&&!this.notifyComponent(o,e,t)&&i.push(o)}else r.forEach(function(a){n.notifyComponent(a,e,t)||i.push(a)});return i.length?i: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 r="set".concat(e.charAt(0).toUpperCase()).concat(e.slice(1)),i=this.doPropertyChange(r,t,a);if(i){var o={};o[e]=t,i.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,r=this.getValue();if(e!==r){var i={value:e,oldValue:r},o=this._get_data("forceFireEvent");t||o?this.promiseExecute("beforeValueChange",i,[function(){n._set_data("value",e,!0),n._applyState("value",e,a),n.execute("afterValueChange",i)},function(){n._set_data("value",r,!0),n._applyState("value",r,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),r=1;r<a;r++)n[r-1]=arguments[r];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,r=new Array(n>2?n-2:0),i=2;i<n;i++)r[i-2]=arguments[i];(a=this._get_data("events")).promiseExecute.apply(a,[e,t].concat(r))}},{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 j)){var t,a=this._get_data("__requestHeaders__");for(var n in e){var r,i,o;if(a&&(null===(r=e[n])||void 0===r||null===(r=r.options)||void 0===r||!r.requestHeaders))null!==(o=e[n])&&void 0!==o&&o.options||(e[n].options={}),e[n].options.requestHeaders=a;null!==(i=this.getProxy())&&void 0!==i&&i[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",j.create(f(f({},(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")}}])}(),O=function(){function e(){return r(this,e),n(this,e,arguments)}return l(e,E),o(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)}}])}(),q=function(){function e(t){return r(this,e),n(this,e,[t])}return l(e,E),o(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)}}])}(),M="",A="Insert",F="Update",N="Delete",T=Array.isArray,K=function(e){return null==e||""===e},V=function(e){return!e||0===Object.keys(e).length};function H(e){if(T(e))return e.map(H);if(e instanceof Date)return new Date(e.getTime());if(e&&"object"===S(e)){var t={};for(var a in e)t[a]=H(e[a]);return t}return e}function U(e){var t={};return(T(e)?e:Object.keys(e||{}).map(function(t){var a;return f(f({},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]=f(f({},e),{},{field:n,fieldName:e.fieldName||n,cCaption:e.cCaption||n,index:void 0===e.index?a:e.index})}}),t}function B(){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 r=e[a];null!=r&&""!==r?e[t]=String(r):(n+=1,e[t]="rowId_".concat(n))}}),this._set_data("rowIdSeq",n),e}function L(e,t,a){var n=this;this.promiseExecute("beforeQuery",{proxyConfig:e,queryParams:t},function(){var r=n,i=n.setProxy({queryData:e}),o={page:{pageSize:n.getPageSize(),pageIndex:n.getPageIndex()}},s=Object.assign(o,t);n.setCache("proxyCache",{proxyConfig:e,params:s}),n.getRootParent();if(!1!==n.execute("beforeQueryData",s)){var u=_.cloneDeep(s);i.queryData(u,function(e,t,n,r){if(!e){this._set_data("dataSourceMode","remote");var i=function(e){if(!e)return[];if(T(e))return e;if(T(e.data))return e.data;if(T(e.records))return e.records;if(T(e.list))return e.list;if(T(e.rows))return e.rows;var t=e.data&&"object"===S(e.data)?e.data:e.result;return T(t)?t:t&&"object"===S(t)&&(t.records||t.list||t.rows||t.data)||[]}(t=Object.assign({},t));null==a||a.call(this,i)}},r)}})}function z(e){if(this.execute("beforeSetDataSource",e)){var t=this._get_data("rowKeyField"),a={};e.forEach(function(e){a[e[t]]=e}),this._set_data("keyMap",a),this._set_data("dataSource",e,!0),this.doPropertyChange("setDataSource"),this.execute("afterSetDataSource",e)}}var G=function(){function e(){var t,a=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,e);var i=f(f({},{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}),a);T(i.dataSource)||(i.dataSource=[]),T(i.rows)||(i.rows=[]);var o=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=f({},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}(a);i.proxyConfig=o,i.dataSourceMode=a.dataSourceMode||(o.load?"remote":"local");var u=a.cData||(T(a.data)?a.data:null);return s(t=n(this,e,[i]),"modelType","GridModel"),t.initPageInfo(a.cPage||a.page),t.initColumns(i.columns),t.initRowState(),t.afterInit(),u&&t.setDataSource(u),t}return l(e,E),o(e,[{key:"afterInit",value:function(){"single"===this._get_data("parentRelation")&&this._set_data("defaultSelectedRowIndexes",!0)}},{key:"initColumns",value:function(e){var t=U(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=f({},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",(T(t)?t:[]).map(function(t){return(null==t?void 0:t[e.getStatusFlag()])||M}),!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 f(f({},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?T(e)?e:[e]:Object.getOwnPropertyNames(t)).forEach(function(e){t[e]&&(a[e]=f(f({},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?f(f({},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",U(e))}},{key:"setColumnMode",value:function(e){this._set_data("columnMode","remote"===e?"remote":"local",!0)}},{key:"addColumns",value:function(e){var t=U(e);this._applyState("columns",f(f({},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,r=this.getRowKey(e);return r?((null===(n=this._get_data("cellState"))||void 0===n||null===(n=n[r])||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 f(f({},e),{},{cellName:e.cellName||e.columnName})}))}},{key:"setColumnValue",value:function(e,t,a){var n=this._get_data("columns")||{};n[e]&&this._applyState("columns",f(f({},n),{},s({},e,f(f({},n[e]),{},s({},t,a)))))}},{key:"setDataSource",value:function(e){var t=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;if("local"===this._get_data("dataSourceMode")){z(cb.utils.isArray(e)?e:[])}else{if(!this.execute("beforeProxyLoad",a))return;this._get_data("pageInfo").pageIndex=1,this._set_data("proxyConfig",e),this._set_data("queryParams",a),this._set_data("loadDataCallback",n),L.call(this,e,a,function(e){z.call(t,e),null==n||n.call(t)})}}},{key:"reload",value:function(){var e=this;this.getProxy();var t=this._get_data("proxyConfig"),a=this._get_data("queryParams"),n=this._get_data("loadDataCallback");L.call(this,t,a,function(t){z.call(e,t),null==n||n.call(e)})}},{key:"getDataSource",value:function(){return this._get_data("dataSource")||[]}},{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]!==N}),!1)}},{key:"getRows",value:function(e){var t=this._get_data("rows")||[];return!1===e?t:t.map(function(e){return H(e)})}},{key:"collectRows",value:function(e,t){var a=this._get_data("columns")||{},n=this.getStatusFlag(),r=this.getSelectedFlag();return(e||[]).map(function(e){var i={};for(var o in e){var s;t&&o===n||(t||o!==r)&&!1!==(null===(s=a[o])||void 0===s?void 0:s.needCollect)&&(i[o]=e[o])}return i})}},{key:"getShowRows",value:function(e){return(e||this._get_data("rows")||[]).map(function(e){return f({},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:H(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():T(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(T(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 r=n[t];if(r!==a){var i={rowIndex:e,rowId:n[this.getIdFlag()],cellName:t,value:a,oldValue:r};this.execute("beforeCellValueChange",i)&&(n[t]=i.value,this.markRowState(e,F),this.execute("afterCellValueChange",i),this.doPropertyChange("setCellValue",i))}}}},{key:"setCellValues",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];T(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,r=this.getRowKey(e),i=r?null===(n=this._get_data("cellState"))||void 0===n||null===(n=n[r])||void 0===n?void 0:n[t]:null;if(i)return i[a]}},{key:"setCellState",value:function(e,t,a,n){var r,i=null===(r=this._get_data("rows"))||void 0===r||null===(r=r[e])||void 0===r?void 0:r[this.getIdFlag()],o=i||e;if(!K(o)){var u=this.getCellState(e,t,a);if(u!==n){var l={rowIndex:e,rowId:i,cellName:t,propertyName:a,value:n,oldValue:u};if(this.execute("beforeCellStateChange",l)){var c=f({},this._get_data("cellState")||{});c[o]=f({},c[o]||{}),c[o][t]=f(f({},c[o][t]||{}),{},s({},a,n)),this._applyState("cellState",c),this.execute("afterCellStateChange",l)}}}}},{key:"setCellStates",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];T(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")||[],r=n.indexOf(a);return r>-1?r: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=w(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!==A&&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,F)}},{key:"getRowState",value:function(e,t){var a,n=this.getRowKey(e),r=n?null===(a=this._get_data("rowState"))||void 0===a?void 0:a[n]:null;if(r&&t)return r[t]}},{key:"setRowState",value:function(e,t,a){var n,r=null===(n=this._get_data("rows"))||void 0===n?void 0:n[e];if(r&&t){var i=this.getRowKey(e),o=this.getRowState(e,t);if(o!==a){var u={rowIndex:e,rowId:r[this.getIdFlag()],propertyName:t,value:a,oldValue:o};if(this.execute("beforeRowStateChange",u)){var l=f({},this._get_data("rowState")||{});l[i]=f(f({},l[i]||{}),{},s({},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]:[];T(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")||[],r=[];return a.forEach(function(e,a){var i=n[a];if(i){var o=H(e);o[t.getStatusFlag()]=i,r.push(o)}}),r.length?r: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:H(this._get_data("dataSource")||[]),rowsDataState:w(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",w(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")||[],r=Math.min(n.length,Math.max(0,void 0===e?n.length:e)),i={index:r,row:f({},t),isCopy:a};if(this.execute("beforeInsertRow",i)){var o=i.row;delete o[this.getIdFlag()],B.call(this,[o]);var s=this._get_data("dataSource")||[],u=r<n.length?this.getDataSourceIndexByRow(r):s.length;s.splice(u<0?s.length:u,0,o);var l=w(this._get_data("rowsDataState")||[]);return l.splice(u<0?l.length:u,0,A),n.splice(r,0,o),this._set_data("rowsDataState",l,!0),this.setRows(n),this.execute("afterInsertRow",f(f({},i),{},{rowIndex:r})),o}}},{key:"insertRows",value:function(e){var t=this,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],n=[];return(T(a)?a:[a]).forEach(function(a,r){n.push(t.insertRow(e+r,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,F),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=(T(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 r=this._get_data("dataSource")||[],i=w(this._get_data("rowsDataState")||[]),o=new Set,s=new Set;n.forEach(function(e){var a=r.indexOf(e);if(!(a<0)){var n=e[t.getIdFlag()];o.add(n),i[a]===A&&s.add(n)}});var u=[],l=[];r.forEach(function(e,a){var n=e[t.getIdFlag()];if(!o.has(n))return u.push(e),void l.push(i[a]);s.has(n)||(u.push(e),l.push(N))}),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(f(f({},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}):T(e)?e:[e];n=n.filter(function(e){return e>=0&&e<a.getRowsCount()});var r=this._get_data("rows")||[],i=this.getSelectedFlag(),o=n.filter(function(e){return!r[e][i]});if(o.length){var s={rowIndexes:o,rows:o.map(function(e){return r[e]})};this.execute("beforeSelect",s)&&(o.forEach(function(e){r[e][i]=!0,a.cacheSelectedRow(r[e],!0)}),this.flushSelection())}else!0===t&&this.flushSelection()}}},{key:"unselect",value:function(e){var t=this;if(null!=e){var a=T(e)?e:[e],n=this._get_data("rows")||[],r=this.getSelectedFlag(),i=a.filter(function(e){var t;return null===(t=n[e])||void 0===t?void 0:t[r]});i.length&&this.execute("beforeUnselect",i)&&(i.forEach(function(e){n[e][r]=!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=T(t)?t:[],n=this.getRowKeyField(),r=new Set(a.map(function(e){var t;return String(null!==(t=null==e?void 0:e[n])&&void 0!==t?t:e)})),i=this._get_data("rows")||[],o=this.getSelectedFlag();i.forEach(function(t){var a=r.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(T(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=T(e)?e:[e],r=this._get_data("rows")||[],i=[];n.forEach(function(e){var t=r.findIndex(function(t){return String(t[a])===String(e)});t>-1&&i.push(t)}),i.length&&(t?this.select(i):this.unselect(i))}},{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}),r=f({},this._get_data("selectedRowsMap")||{});t&&n.push(a),t?r[a]=e:delete r[a],this._set_data("selectedKeys",n,!0),this._set_data("selectedRowsMap",r,!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(f(f({},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(f(f({},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(f(f({},this.getPageInfo()),{},{pageSize:Math.max(-1,e),pageIndex:1}),{refresh:t})}},{key:"setRecordCount",value:function(e){this.applyPageInfo(f(f({},this.getPageInfo()),{},{recordCount:e||0}))}},{key:"applyPageInfo",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=f({},e||{}),n=-1===a.pageSize?-1:a.pageSize||20,r=a.recordCount||0,i=r>0;return a.pageSize=n,a.recordCount=r,a.pageCount=n>0?Math.max(1,Math.ceil(r/n)):1,a.pageIndex=n>0?Math.max(1,i?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,r):r,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,r=(a-1)*n;this.setRows(e.slice(r,r+n))}else this.setRows(e)}},{key:"setRows",value:function(e){var t=T(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")||{},r=t?this.getRowsByIndexes(t):this.getRows(),i=[];r.forEach(function(e,t){for(var r in n){var o=n[r];if(a.isRequiredColumn(o)){var s=e[r];if(K(s)||T(s)&&!s.length||V(s)){var u=o.cShowCaption||o.cCaption||o.cCaption||o.title||r;i.push({rowIndex:t,rowId:e[a.getIdFlag()],cellName:r,message:"".concat(u,"不能为空")}),a.setCellState(t,r,"msg","不能为空")}}}}),this._set_data("validateErrors",i);var o=i.length?i[0].message:"";return this.doPropertyChange("validate",{type:i.length?"error":"",message:o,errors:i}),this.execute("afterValidate",{valid:!i.length,errors:i}),!i.length}}])}(),X=function(){function e(){return r(this,e),n(this,e,arguments)}return l(e,E),o(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 E&&(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,r=e.get(t);r instanceof E&&!1!==r._get_data("needCollect")&&(a[t]=null===(n=r.getData)||void 0===n?void 0:n.call(r))}),a}},{key:"getAllData",value:function(e){var t=this,a=this._get_data("propertyNames")||[],n={};return a.forEach(function(a){var r,i=t.get(a);if(i instanceof E&&!1!==i._get_data("needCollect")&&(!e||!i._get_data("isGrid"))){var o=null===(r=i.getData)||void 0===r?void 0:r.call(i);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,r=t.get(a);r instanceof E&&!1!==r._get_data("needClear")&&(null===(n=r.clear)||void 0===n||n.call(r,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 r=this._get_data("propertyNames"),i=0,o=r.length;i<o;i++){if((a=this.get(r[i]))instanceof G||"GridModel"==a.modelType)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 r=this.get(e[a]);(r instanceof G||"GridModel"==r.modelType)&&t.push(r)}return t}}])}();function J(e){var t=this;window&&window.__debugger_initExtendJs;var a=e.requirejs,n=e.extendFilePath,r=e.pageKey,i=e.enableExtendJs,o=void 0===i||i,s=e.extendJsPath,u=void 0===s?"_VM.Extend.js":s;if(o){var l="".concat(r).concat(u),c=[l];if("function"!=typeof a.require)return console.warn("requirejs.js 未加载,跳过扩展脚本:".concat(l)),void t.execute("extendReady",t);a.require(n,c,function(e,a){if(e&&e.doAction)try{e.doAction("init",t),a&&a.doAction("init",t)}catch(e){console.error("扩展脚本异常:",e)}else console.error("".concat(l,"扩展文件extend.*.min.js文件加载失败 或 未注册扩展脚本"));t.execute("extendReady",t)},function(e){console.warn("未找到扩展脚本:".concat(l,"错误信息:"),e),t.execute("extendReady",t)})}else t.execute("extendReady",t)}var Y=function(){var e=a(v().m(function e(t,n,r){var i,o,s,u;return v().w(function(e){for(;;)switch(e.n){case 0:if(s=t.extscripturls,u=void 0===s?[]:s,u=(u=(n.getCache("localDynamicScripts")||[]).concat(u)).concat(window.__devfab__EXT_BILL_SCRIPTS__||[]),null!==(i=n.getParams())&&void 0!==i&&i.initVMExtUrls&&(u=u.concat([n.getParams().initVMExtUrls])),null===(o=u)||void 0===o||!o.length){e.n=2;break}return u=w(new Set(u)),e.n=1,Promise.all(u.map(function(){var e=a(v().m(function e(t){return v().w(function(e){for(;;)if(0===e.n)return e.a(2,t)},e)}));return function(t){return e.apply(this,arguments)}}()));case 1:u=e.v;case 2:return t.extscripturls=u,e.a(2,new Promise(function(e,a){Q(t,n,r,function(){e(!0)})}))}},e)}));return function(t,a,n){return e.apply(this,arguments)}}();function Q(e,t,a,n){var r=e.extscripturls,i=void 0===r?[]:r;if(null!=i&&i.length)try{var o,s=null==a||null===(o=a.requirejs)||void 0===o?void 0:o.requireInner;if("function"!=typeof s)return console.warn("requirejs.js 未加载,跳过客开扩展脚本"),void(null==n||n(e,t));s(i,function(){var a=!0;if(arguments.length){for(var r=0,i=arguments.length;r<i;r++){var o=r<0||arguments.length<=r?void 0:arguments[r];o?o.doAction("init",t):a=!1}a&&(null==n||n(e,t))}else a=!1;a||console.log("[error] [extendjs] 租户级扩展脚本有语法错误,请修改正确后刷新浏览器重试!")},function(a){null==n||n(e,t)})}catch(a){null==n||n(e,t)}else null==n||n(e,t)}function W(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=t.extendFilePathField,i=void 0===a?"domainKey":a,s=t.pageKeyField,u=void 0===s?"billNo":s,c=t.modelNameField,d=void 0===c?"cName":c,h=e[i]||"",v=e[u]||"",g=function(){function e(){return r(this,e),n(this,e,arguments)}return l(e,X),o(e,[{key:"init",value:function(e,t){var a=this.createModels(e,t);this.setData(a),this.setDirty(!1)}},{key:"createModels",value:function(e,a){var n={};return(Array.isArray(e)?e:[]).forEach(function(e){var r,i,o=null==t||null===(r=t.createModelFactory)||void 0===r?void 0:r.call(t,e);o||(o=function(e){var t;"input"===e.cControlType.toLowerCase()&&(t=new q(e));return t}(e));var s={model:o,field:e,meta:a};null==t||null===(i=t.onBeforeCreateModel)||void 0===i||i.call(t,s),n[e[d]]=s.model}),n}},{key:"initData",value:function(){J.call(this,f(f({},t),{},{extendFilePath:h,pageKey:v}))}}])}();return g.prototype.modelType="ViewModel",g}function $(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2?arguments[2]:void 0;null!=t&&t.requirejs||(t.requirejs=window.__devfab);var r=function(e,t){var a=new(W(e,t));return a.init(e.models,e),a}(e,t);return r.on("destroyVM",function(){var e,t;null===(e=r)||void 0===e||null===(t=e.destroyVM)||void 0===t||t.call(e),r=null}),r.on("extendReady",a(v().m(function a(){var i;return v().w(function(a){for(;;)switch(a.n){case 0:return(i=[]).push(Y(e,r,t)),a.n=1,Promise.all(i);case 1:null==n||n(r,e);case 2:return a.a(2)}},a)}))),r.initData(),r}var Z={BaseModel:E,FilterModel:O,SimpleModel:q,GridModel:G,ViewModel:X,initViewModel:$};export{E as BaseModel,O as FilterModel,G as GridModel,q as SimpleModel,X as ViewModel,Z as default,$ as initViewModel};
|