@archbiz/element-plus 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +176 -2
- package/dist/element-plus.cjs +21 -0
- package/dist/element-plus.min.js +8 -0
- package/dist/element-plus.umd.js +21 -0
- package/dist/style.css +7 -0
- package/package.json +60 -3
- package/types/ab-form/index.d.ts +22 -0
- package/types/ab-table/index.d.ts +115 -0
- package/types/ab-upload/index.d.ts +53 -0
- package/types/css.d.ts +1 -0
- package/types/index.d.ts +33 -0
- package/types/jsx.d.ts +13 -0
- package/types/purge-icons.d.ts +5 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 xaboy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @archbiz/element-plus
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Element Plus and VXE environment adapter for Archbiz. This is the application entry point: it supplies the environment-specific `abForm`, `abSearch`, and `abTable` components and installs them into a Vue application. Shared core runtime is provided by `@archbiz/core-v3`.
|
|
4
|
+
|
|
5
|
+
## Peer dependencies
|
|
6
|
+
|
|
7
|
+
The consuming application must provide Vue `^3.5.12`, Element Plus `^2.14.0`, VXE Table `^4.23.17`, and VXE PC UI `^4.20.40`. Install compatible versions alongside the adapter:
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @archbiz/element-plus 'vue@^3.5.12' 'element-plus@^2.14.0' 'vxe-table@^4.23.17' 'vxe-pc-ui@^4.20.40'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The adapter packages its styles and imported Element Plus component styles separately. Import them once in the application entry:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { setupArchbizKit } from '@archbiz/element-plus';
|
|
17
|
+
import '@archbiz/element-plus/style.css';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Element Plus JavaScript remains external and is provided by the application. VXE Table and VXE PC UI imports are external as well. Install them in the application and import their styles before using `ab-table`:
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
import VxeUI from 'vxe-pc-ui';
|
|
24
|
+
import VxeUITable from 'vxe-table';
|
|
25
|
+
import 'vxe-pc-ui/lib/style.css';
|
|
26
|
+
import 'vxe-table/lib/style.css';
|
|
27
|
+
|
|
28
|
+
app.use(VxeUI);
|
|
29
|
+
app.use(VxeUITable);
|
|
30
|
+
setupArchbizKit(app);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For titled form fields, default placeholders are generated for `input`, `inputNumber`, `textarea`, `password`, `select`, `datePicker`, and `timePicker` using the form's `zh-cn` or `en` locale. Explicit placeholders are preserved; range pickers also support `startPlaceholder` and `endPlaceholder`.
|
|
34
|
+
|
|
35
|
+
Type-based defaults can populate rule-level fields as well as props; explicit rule values take precedence. Default input children are applied only in editable forms, while supplied children are retained.
|
|
36
|
+
|
|
37
|
+
In readonly forms and table columns, `datePicker` values are formatted according to the picker type (including year, quarter, month, week and datetime). `props.format` controls the display format; date ranges use `props.rangeSeparator` or `-` by default. A rule's custom `formatter` takes precedence.
|
|
38
|
+
|
|
39
|
+
Custom rule components can read `props.abFormInject?.readonly` to render their own readonly or editable content. It reflects the current `readonly` prop of the form rendering the component, including changes after mounting; when omitted, it is `undefined`.
|
|
40
|
+
|
|
41
|
+
`timePicker` likewise displays text in readonly forms and formats table values. It supports `props.valueFormat`, `props.format`, and `props.rangeSeparator`, with a custom rule `formatter` taking precedence.
|
|
42
|
+
|
|
43
|
+
`colorPicker` shows the current color as the background in readonly forms and keeps its value visible. A custom rule `formatter` can override the readonly text.
|
|
44
|
+
|
|
45
|
+
`treeSelect` renders an editable tree select or, in readonly forms and table columns, the selected node labels. Supply tree data with `props.data`, or load it asynchronously with `options` and `optionsTo: 'props.data'`. String field mappings in `props.props` (`value`, `label`, and `children`) and `nodeKey` / `valueKey` are supported. Values are matched by type and value; unmatched values remain visible. Use a custom `formatter` for function-based field mappings or other display requirements.
|
|
46
|
+
|
|
47
|
+
`cascader` renders selected paths as text in readonly forms and table columns. Supply options with `props.options`, or asynchronously with `options` and `optionsTo: 'props.options'`. It supports field mappings, multiple selection, `emitPath`, `showAllLevels`, and `separator`; unmatched values remain visible. Use a custom `formatter` for lazy-loaded nodes not present in the options.
|
|
48
|
+
|
|
49
|
+
Set `link` on a table column or form rule to render its displayed value as a router link. A route-name string uses the current value as the `id` query; an object can map query or param keys to fields in the row/form data, and a function receives the complete row/form data and returns a Vue Router location. A custom `formatter` still controls the link text. Form links are shown only in readonly mode; `link: string[]` remains available for form field dependencies.
|
|
50
|
+
|
|
51
|
+
Search rules can map any array-valued input to separate `v-model` fields using `rangeFields`, for example `['start', 'end']` or `['projectId', 'siteId', 'blId']`. The input keeps its array internally; the external model contains the mapped fields instead. Missing array items become `null`, extra items are ignored, and clearing sets all mapped fields to `null`. On input, mapped fields are restored as an array of the configured length, or `null` when all are empty. Cascader paths omit trailing `null` values so shorter paths can be matched. Field names must be nonempty and distinct and must not conflict with other search rules or range mappings.
|
|
52
|
+
|
|
53
|
+
`inputRange` uses a two-item `modelValue` array for its minimum and maximum. Empty inputs become `null`; edited values are strings, while existing numeric values are preserved. It emits `change` with the complete range when either input commits a change. Set `props.clearable` to `false` to disable clearing (default: `true`). In `ab-search`, set `rangeFields` to map the two items to separate query fields. It renders readonly if either the form or its own `readonly` prop is true.
|
|
54
|
+
|
|
55
|
+
`timePeriod` uses a `[start, end]` model with `HH:mm` or `HH:mm:ss` values, or `null` for an unselected period. Existing values retain their seconds until changed. In `ab-search`, use `rangeFields` to map the two values to separate query fields. The slider selects in 30-minute steps within `props.startTime` and `props.endTime` (default `08:00`–`18:00`); the ordered bounds are also selectable even when the interval is not a whole number of steps. Values outside those bounds remain unchanged and visible, with a warning and slider handles limited to the bounds. `24:00` is supported, but overnight ranges are not. Empty values remain unselected until the slider is moved. It emits `change` with the selected pair when the slider change is committed and renders readonly if either the form or its own `readonly` prop is true.
|
|
56
|
+
|
|
57
|
+
### File upload
|
|
58
|
+
|
|
59
|
+
`uploadFile` binds a `string[]` of uploaded URLs. Configure the form's `idField` and, optionally, `idFieldTable`; the component observes the ID in the form model. `ab-detail` and `ab-table-detail` pass these fields through. An empty ID or `"new"` means a new record.
|
|
60
|
+
|
|
61
|
+
Configure the project's five asynchronous upload API functions once when installing the library. They should use the project's HTTP client for authentication and error handling:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { setupArchbizKit, type UploadApis } from '@archbiz/element-plus';
|
|
65
|
+
|
|
66
|
+
const uploadApis: UploadApis = {
|
|
67
|
+
upload: ({ file }) => uploadFile(file), // { data: { id, name, url, size? } }
|
|
68
|
+
list: (params) => listFiles(params), // { list: [{ id?, fileId, name, url, size?, isCover? }] }
|
|
69
|
+
attach: (params) => attachFiles(params),
|
|
70
|
+
remove: (params) => removeFile(params),
|
|
71
|
+
setCover: (recordId, isCover) => updateCover(recordId, isCover)
|
|
72
|
+
};
|
|
73
|
+
setupArchbizKit(app, { upload: uploadApis });
|
|
74
|
+
|
|
75
|
+
const rules = [
|
|
76
|
+
{
|
|
77
|
+
type: 'uploadFile',
|
|
78
|
+
field: 'attachments',
|
|
79
|
+
props: {
|
|
80
|
+
fileType: ['pdf', 'docx', 'png'],
|
|
81
|
+
fileSize: 10, // MB
|
|
82
|
+
limit: 5,
|
|
83
|
+
coverEnabled: true
|
|
84
|
+
},
|
|
85
|
+
on: { preview: ({ url, name, extension, fileId }) => openPreview({ url, name, extension, fileId }) }
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The configuration belongs to the Vue app and is shared by its upload fields. For exceptional fields, `props.apis` can override the global APIs. An upload component without either configuration reports an error.
|
|
91
|
+
|
|
92
|
+
`list` receives `{ businessType, businessCode, businessId, pageSize: 1000 }` and must return the complete business file list; it is authoritative for existing records. `attach` receives the same business fields plus `fileIds` and `isCover`; `remove` receives those business fields plus `fileId`. The project must make attachment retries idempotent and reject failed requests. `setCover` uses the business record `id`, not `fileId`. `businessType` defaults to the form's `idFieldTable` and can be overridden with the component's `idFieldTable`; set `businessCode` in component props if needed.
|
|
93
|
+
|
|
94
|
+
When an ID exists, uploaded files are associated immediately. Otherwise, they remain pending until the ID is written into the form model, then are associated in a batch. Failed association keeps the URLs and offers a retry; deleting a pending file removes it locally, and cleanup of its uploaded server file is the project's responsibility. Pending file IDs live in the component instance, so keep it mounted until association completes. Only associated images with a business record ID can be set as a cover. `autoCover` applies only when a single pending image is associated. Readonly disables upload, deletion and cover changes but preserves preview and download.
|
|
95
|
+
|
|
96
|
+
Before creating or updating a record, await `formApi.el('attachments').waitForUploads()`. After creating, write the returned ID to the model, await Vue's `nextTick()`, and then await `formApi.el('attachments').waitForAssociations()`. Both methods reject on failure; retain the created ID if association fails so it can be retried without creating a duplicate record. `ab-detail` and `ab-table-detail` do not automatically wait in their built-in save handlers, so use a custom save flow when these guarantees are required. The component also emits `error` and exposes `retryAssociations()`.
|
|
97
|
+
|
|
98
|
+
`setupArchbizKit` registers `ab-table`, and `AbTable` is also exported for local registration. The table currently supports basic columns, queries, and pagination:
|
|
99
|
+
|
|
100
|
+
```vue
|
|
101
|
+
<ab-search :rule="searchRules" v-model="query" />
|
|
102
|
+
<ab-table ref="table" v-model:query="query" :columns="columns" :query-handler="loadRows" />
|
|
103
|
+
<button @click="table?.reload()">Search</button>
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
In `ab-search`, rules with `hidden: true` appear in a separate expandable form; other rules and the search buttons remain visible. Expanding or collapsing does not change the supplied rules, and resetting resets both forms. Set `collapse` to start expanded. Both forms share the query model, but each has its own form API, so form-level dependencies and validation apply within that form.
|
|
107
|
+
|
|
108
|
+
`queryHandler` receives the current search fields plus the table's pagination fields. The default names are `pageNo`, `pageSize`, `sortFieldTable`, `sortField`, and `sortType`. Override them with `pagerConfig.pageNoField`, `pageSizeField`, `sortFieldTableField`, `sortFieldField`, and `sortTypeField`. Initial values in `query` are read once when mounted; subsequent page changes stay inside the table and override those query fields in requests without writing back to `query`. Defaults are page 1, page size 10, and empty sort fields. Page and size must be positive integers; sort values must be strings.
|
|
109
|
+
|
|
110
|
+
When `autoHeight` is enabled and a positive height is available, the calculated page size overrides the initial query's page size for the first request, matching `resize()` behavior. If no height is available, the initial query value or default is retained.
|
|
111
|
+
|
|
112
|
+
The handler may return an array or `{ data: rows, total }` / `{ list: rows, total }`, directly or in a promise. For an array, its length is used as the total; remote pagination should return `total`. `reload()` resets to page 1, while `refresh()` keeps the current page; both use the latest query. Set `:pager-enable="false"` to hide the pager. Request failures are reported through Vue's error handler and clear the loading state.
|
|
113
|
+
|
|
114
|
+
For a current-page summary, pass `footerSummary`:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const footerSummary = {
|
|
118
|
+
labelField: 'name', // column in which to show the label
|
|
119
|
+
// label: 'Subtotal', // defaults to the localized "Total"
|
|
120
|
+
fields: ['amount', 'cost', 'profit', { profitRate: ({ totals }) => (totals.amount ? ((totals.profit ?? 0) / totals.amount) * 100 : null) }]
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```vue
|
|
125
|
+
<ab-table :rule="rules" :query-handler="loadRows" :footer-summary="footerSummary" />
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
String fields sum numbers and numeric strings from the loaded page; null, undefined, and blank strings are ignored. An empty field or page displays `-`, while a genuine zero stays zero. All string fields are summed first, then callback fields run in their configured order. Each callback receives `{ rows, totals }`, where `rows` is the current page and `totals` contains the unformatted sums and earlier callback results (`number | null`). Return a finite number or `null` for no value. Callbacks are not invoked on an empty page. Invalid numeric values, duplicate fields, and invalid callback results report errors rather than silently producing a total.
|
|
129
|
+
|
|
130
|
+
Each summary value uses the matching column's formatter, including built-in number, currency and percentage formatters, with the unformatted summary row as `row`. If the regular formatter needs details that do not exist on a summary row, specify `footerFormatter` on that column; it receives `{ cellValue, row, column }`.
|
|
131
|
+
|
|
132
|
+
Sorting refreshes the current page with `sortFieldTable`, `sortField`, and `sortType`. Set `idFieldTable` as the default table name, or set a column's `sortFieldTable` (including `''` for no prefix); `false` disables sorting for that column. A column can also set `sortable: true` without a table name. The column's `sortField` overrides its `field`; camel-case names are converted to snake case. Clearing sorting uses `idFieldTable` (or `''`), `idField` (or `id`), and `desc`, as in the previous table. Set `sortable` to `false` to disable sorting across the table. `sortLocally` configures VXE's local sorting; sort changes still refresh, as in the previous table.
|
|
133
|
+
|
|
134
|
+
Set a column's `group` to a group title or an array of titles from outermost to innermost. Columns with the same group path share a header, positioned at the first matching column. `groupAlign` sets the innermost group's header alignment; if multiple columns specify it, the last one wins. Grouping updates when the rules change, and the original rules are not modified.
|
|
135
|
+
|
|
136
|
+
When a saved VXE column order conflicts with the current group hierarchy, the table ignores that order and any saved visibility overrides that would reveal initially hidden columns. Other saved settings are retained; the original stored configuration is not deleted. A warning is logged when this happens.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
const rules = [
|
|
140
|
+
{ field: 'amount', title: 'Amount', type: 'inputCurrency', group: 'Statistics' },
|
|
141
|
+
{ field: 'profit', title: 'Profit', type: 'inputCurrency', group: ['Statistics', 'Profit'] },
|
|
142
|
+
{ field: 'rate', title: 'Rate', type: 'inputPercent', group: ['Statistics', 'Profit'] }
|
|
143
|
+
];
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
An `ElRow` rule with `field: AbTableEnum.OPERATE` renders its children in each table row using the same rule renderer as `ab-form`. In `ab-table-detail`, those rules are rendered in `.ab-table-detail__header` instead of the form body. Each operation rule has its own `ab-form` instance, so an injected API belongs to that instance rather than the detail form. The `AbTableEnum.OPERATE` shorthand remains a table-only rule. Operation rules do not add an `OPERATE` field to the form data and render without a form-item label or wrapper in both locations.
|
|
147
|
+
|
|
148
|
+
For a toolbar or operation button to receive form context, set `inject: true` on the button rule. Its event handler receives the context first and the original event second; without injection it receives the event directly. The context's `api` belongs to the form rendering that button.
|
|
149
|
+
|
|
150
|
+
For UMD builds, import these packages by their root names; their browser globals are `VxeUITable` and `VxeUI`. Load `dist/style.css` separately with a stylesheet link when using UMD directly.
|
|
151
|
+
|
|
152
|
+
## Example
|
|
153
|
+
|
|
154
|
+
Run the example from the repository root:
|
|
155
|
+
|
|
156
|
+
```sh
|
|
157
|
+
npm run build
|
|
158
|
+
npm run dev:element-plus
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Open `/table.html` on the dev server to run the table example independently.
|
|
162
|
+
|
|
163
|
+
For real upload testing, create `.env.local` at the repository root:
|
|
164
|
+
|
|
165
|
+
```dotenv
|
|
166
|
+
VITE_EXAMPLE_REAL_API=true
|
|
167
|
+
VITE_EXAMPLE_API_BASE_URL=http://localhost:42600/admin-api
|
|
168
|
+
VITE_EXAMPLE_API_USERNAME=your-test-user
|
|
169
|
+
VITE_EXAMPLE_API_PASSWORD=your-test-password
|
|
170
|
+
VITE_EXAMPLE_API_TENANT_ID=1
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Restart the example server after changing the file. The file is Git-ignored and can also be used by other packages that set their Vite `envDir` to the repository root. The example logs in through `/system/auth/login` before mounting and keeps the access token in memory. **Vite exposes `VITE_` variables to the browser**: use only a test account, never deploy this configuration, and ensure the backend permits requests from the example's origin. The test login does not implement CAPTCHA or token refresh, so CAPTCHA must be disabled and the page reloaded if the token expires. If `VITE_EXAMPLE_REAL_API` is not `true`, uploads use the existing in-memory mock.
|
|
174
|
+
|
|
175
|
+
The real upload adapter in `examples/upload-api.js` uses the previous project's server-upload and file-business endpoints. Its operations modify the configured backend. The example's business list and create handler remain mocked, so use a valid test business record and connect a real create handler to test post-create association.
|
|
176
|
+
|
|
177
|
+
The example imports source code by default. To test the built package, switch the commented imports in `examples/main.js` and `examples/mock.js` to the `dist` imports, including `dist/style.css`. Rebuild after changing library source files. The package also produces CommonJS and UMD builds; see the repository README for their file names and UMD globals.
|