niuma-ui 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -1
- package/package.json +10 -2
- package/src/__tests__/RsButton.spec.ts +47 -0
- package/src/__tests__/RsCard.spec.ts +160 -1
- package/src/__tests__/RsConfirmDialog.spec.ts +127 -0
- package/src/__tests__/RsContextMenu.spec.ts +12 -0
- package/src/__tests__/RsDatePicker.spec.ts +21 -0
- package/src/__tests__/RsDateTimePicker.spec.ts +11 -0
- package/src/__tests__/RsDescriptions.spec.ts +50 -0
- package/src/__tests__/RsDialog.spec.ts +178 -0
- package/src/__tests__/RsDrawer.spec.ts +96 -3
- package/src/__tests__/RsDynamicTags.spec.ts +52 -0
- package/src/__tests__/RsForm.spec.ts +250 -6
- package/src/__tests__/RsFormItem.spec.ts +478 -0
- package/src/__tests__/RsFormList.spec.ts +109 -0
- package/src/__tests__/RsInput.spec.ts +108 -1
- package/src/__tests__/RsInputNumber.spec.ts +33 -0
- package/src/__tests__/RsMenu.spec.ts +406 -14
- package/src/__tests__/RsPagination.spec.ts +67 -2
- package/src/__tests__/RsSelect.spec.ts +465 -2
- package/src/__tests__/RsSwitch.spec.ts +74 -0
- package/src/__tests__/RsTable.a11y.spec.ts +83 -0
- package/src/__tests__/RsTable.dom-baseline.spec.ts +87 -0
- package/src/__tests__/RsTable.perf.spec.ts +23 -4
- package/src/__tests__/RsTable.spec.ts +63 -8
- package/src/__tests__/RsTable.ssr.spec.ts +71 -0
- package/src/__tests__/RsTable.summary.spec.ts +45 -0
- package/src/__tests__/RsTabs.spec.ts +102 -4
- package/src/__tests__/RsTimePicker.spec.ts +20 -0
- package/src/__tests__/RsTooltip.spec.ts +43 -0
- package/src/__tests__/RsUpload.spec.ts +62 -6
- package/src/__tests__/createRsDialog.spec.ts +145 -0
- package/src/__tests__/css-token.spec.ts +51 -0
- package/src/__tests__/date-picker-utils.spec.ts +49 -0
- package/src/__tests__/dialog-utils.spec.ts +43 -0
- package/src/__tests__/form-path.spec.ts +46 -0
- package/src/__tests__/form-rules.spec.ts +139 -0
- package/src/__tests__/perf-budgets.ts +32 -0
- package/src/__tests__/rs-table-api.spec.ts +206 -0
- package/src/__tests__/rs-table-compat-matrix.spec.ts +108 -0
- package/src/__tests__/rs-table-echarts-adapter.spec.ts +43 -0
- package/src/__tests__/rs-table-grid-nav.spec.ts +63 -0
- package/src/__tests__/rs-table-isolation.spec.ts +158 -0
- package/src/__tests__/split-pane-utils.spec.ts +21 -0
- package/src/__tests__/table-chart-utils.spec.ts +88 -0
- package/src/__tests__/table-summary-utils.spec.ts +62 -0
- package/src/__tests__/table-utils.spec.ts +124 -0
- package/src/__tests__/theme.spec.ts +27 -0
- package/src/__tests__/useRsTableColumnResize.spec.ts +25 -0
- package/src/__tests__/useRsTableCore.perf.spec.ts +170 -0
- package/src/components/RsAlert.vue +212 -0
- package/src/components/RsAvatar.vue +1 -1
- package/src/components/RsBadge.vue +1 -1
- package/src/components/RsBreadcrumb.vue +1 -1
- package/src/components/RsButton.vue +147 -23
- package/src/components/RsCalendarGrid.vue +3 -3
- package/src/components/RsCard.vue +204 -20
- package/src/components/RsCodeBlock.vue +4 -4
- package/src/components/RsCodeEditor.vue +8 -8
- package/src/components/RsConfirmDialog.vue +217 -30
- package/src/components/RsContextMenu.vue +57 -17
- package/src/components/RsDatePicker.vue +316 -39
- package/src/components/RsDateTimePicker.vue +27 -2
- package/src/components/RsDescriptions.vue +186 -0
- package/src/components/RsDescriptionsItem.vue +32 -0
- package/src/components/RsDialog.vue +374 -52
- package/src/components/RsDivider.vue +89 -0
- package/src/components/RsDrawer.vue +559 -34
- package/src/components/RsDropdown.vue +34 -3
- package/src/components/RsDynamicTags.vue +531 -0
- package/src/components/RsEmpty.vue +1 -1
- package/src/components/RsForm.vue +164 -8
- package/src/components/RsFormItem.vue +423 -0
- package/src/components/RsFormItemControl.vue +21 -0
- package/src/components/RsFormList.vue +117 -0
- package/src/components/RsInput.vue +491 -100
- package/src/components/RsInputNumber.vue +77 -27
- package/src/components/RsLabel.vue +20 -5
- package/src/components/RsLink.vue +1 -1
- package/src/components/RsLoadingBar.vue +151 -0
- package/src/components/RsMarkdown.vue +5 -5
- package/src/components/RsMenu.vue +74 -16
- package/src/components/RsMenuItems.vue +147 -9
- package/src/components/RsMonacoEditor.vue +9 -3
- package/src/components/RsPagination.vue +93 -14
- package/src/components/RsProseEditor.vue +3 -3
- package/src/components/RsRadio.vue +81 -0
- package/src/components/RsRadioItem.vue +156 -0
- package/src/components/RsSelect.vue +372 -642
- package/src/components/RsSidebarGroup.vue +1 -1
- package/src/components/RsSplitPane.vue +90 -1
- package/src/components/RsStatCard.vue +2 -2
- package/src/components/RsSteps.vue +2 -2
- package/src/components/RsSwitch.vue +192 -0
- package/src/components/RsTable.vue +653 -2555
- package/src/components/RsTabs.vue +422 -90
- package/src/components/RsTag.vue +191 -0
- package/src/components/RsTerminal.vue +58 -19
- package/src/components/RsTimePicker.vue +72 -9
- package/src/components/RsTimePickerColumns.vue +137 -78
- package/src/components/RsToaster.vue +64 -24
- package/src/components/RsTooltip.vue +10 -1
- package/src/components/RsTooltipProvider.vue +11 -1
- package/src/components/RsTree.vue +45 -27
- package/src/components/RsUpload.vue +147 -14
- package/src/components/RsVNodeHost.vue +20 -0
- package/src/components/button-utils.ts +39 -0
- package/src/components/context-menu-utils.ts +6 -0
- package/src/components/date-picker-utils.ts +195 -4
- package/src/components/descriptions-utils.ts +24 -0
- package/src/components/dialog-utils.ts +182 -0
- package/src/components/dialog-window.ts +74 -9
- package/src/components/drawer-utils.ts +73 -0
- package/src/components/form-item-control.ts +55 -0
- package/src/components/form-path.ts +92 -0
- package/src/components/form-rules.ts +311 -0
- package/src/components/form-utils.ts +145 -3
- package/src/components/menu-utils.ts +11 -0
- package/src/components/overlay-utils.ts +3 -0
- package/src/components/radio-utils.ts +12 -0
- package/src/components/reka.ts +5 -0
- package/src/components/select-utils.ts +285 -6
- package/src/components/split-pane-utils.ts +65 -12
- package/src/components/table/RsTableBody.vue +217 -0
- package/src/components/table/RsTableBodyRow.vue +90 -1
- package/src/components/table/RsTableColGroup.vue +41 -0
- package/src/components/table/RsTableHeader.vue +158 -0
- package/src/components/table/RsTableHeaderFilter.vue +1 -1
- package/src/components/table/RsTableSummaryRow.vue +52 -0
- package/src/components/table/rs-table-api.ts +99 -0
- package/src/components/table/rs-table-compat-matrix.ts +71 -0
- package/src/components/table/rs-table-echarts-adapter.ts +81 -0
- package/src/components/table/rs-table-feature-host.ts +178 -0
- package/src/components/table/rs-table-grid-nav.ts +122 -0
- package/src/components/table/rs-table-header-types.ts +47 -0
- package/src/components/table/rs-table-module-registry.ts +72 -0
- package/src/components/table/rs-table-props.ts +274 -0
- package/src/components/table/rs-table-view-context.ts +258 -0
- package/src/components/table/rs-table.css +85 -7
- package/src/components/table/table-chart-utils.ts +165 -0
- package/src/components/table/table-features.ts +284 -0
- package/src/components/table/table-summary-utils.ts +194 -0
- package/src/components/table-utils.ts +452 -2
- package/src/components/tabs-utils.ts +142 -2
- package/src/components/time-picker-utils.ts +76 -3
- package/src/components/upload-utils.ts +122 -0
- package/src/components/use-rs-select.ts +436 -0
- package/src/components/virtual-list-utils.ts +15 -2
- package/src/composables/assembleRsTableApi.ts +79 -0
- package/src/composables/bindRsTableViewContext.ts +269 -0
- package/src/composables/createRsDialog.ts +357 -0
- package/src/composables/createRsTableEditEmitBridge.ts +38 -0
- package/src/composables/useRsConfig.ts +10 -3
- package/src/composables/useRsI18n.ts +16 -5
- package/src/composables/useRsLoadingBar.ts +36 -0
- package/src/composables/useRsTable.ts +134 -0
- package/src/composables/useRsTableA11y.ts +52 -0
- package/src/composables/useRsTableChartBridge.ts +79 -0
- package/src/composables/useRsTableColumnLayout.ts +320 -0
- package/src/composables/useRsTableColumnResize.ts +244 -0
- package/src/composables/useRsTableColumnVirtual.ts +180 -0
- package/src/composables/useRsTableColumns.ts +200 -0
- package/src/composables/useRsTableContextMenu.ts +257 -0
- package/src/composables/useRsTableCore.ts +256 -0
- package/src/composables/useRsTableEditActions.ts +606 -0
- package/src/composables/useRsTableEditLayer.ts +251 -0
- package/src/composables/useRsTableEngine.ts +357 -0
- package/src/composables/useRsTableGridKeyboard.ts +123 -0
- package/src/composables/useRsTableHeadless.ts +137 -0
- package/src/composables/useRsTableInteraction.ts +433 -0
- package/src/composables/useRsTableScrollHost.ts +75 -0
- package/src/composables/useRsTableScrollLayout.ts +255 -0
- package/src/composables/useRsTableSelectionSource.ts +89 -0
- package/src/composables/useRsTableShell.ts +416 -0
- package/src/composables/useRsTableShellChrome.ts +170 -0
- package/src/composables/useRsTableSummary.ts +113 -0
- package/src/composables/useRsTableViewProvide.ts +263 -0
- package/src/composables/useRsTableVirtual.ts +154 -0
- package/src/composables/useRsTabsNav.ts +4 -0
- package/src/composables/useTableEdit.ts +1 -1
- package/src/index.ts +378 -10
- package/src/locale/interpolate.ts +32 -0
- package/src/locale/messages.ts +40 -0
- package/src/styles.css +365 -56
- package/src/theme/brand.example.css +24 -2
- package/src/theme/css-token.ts +107 -0
- package/src/theme/presets.ts +4 -0
- package/src/theme/types.ts +68 -0
- package/src/components/RsTableColgroup.vue +0 -17
- package/src/components/RsTableHeaderRow.vue +0 -30
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Comment, Fragment, Text, cloneVNode, isVNode, type VNode, type VNodeArrayChildren } from 'vue'
|
|
2
|
+
|
|
3
|
+
function flattenVNodes(nodes: VNodeArrayChildren, out: VNode[] = []): VNode[] {
|
|
4
|
+
for (const node of nodes) {
|
|
5
|
+
if (node == null || typeof node === 'boolean') continue
|
|
6
|
+
if (Array.isArray(node)) {
|
|
7
|
+
flattenVNodes(node, out)
|
|
8
|
+
continue
|
|
9
|
+
}
|
|
10
|
+
if (!isVNode(node)) continue
|
|
11
|
+
if (node.type === Fragment && Array.isArray(node.children)) {
|
|
12
|
+
flattenVNodes(node.children as VNodeArrayChildren, out)
|
|
13
|
+
continue
|
|
14
|
+
}
|
|
15
|
+
out.push(node)
|
|
16
|
+
}
|
|
17
|
+
return out
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function isControlVNode(node: VNode): boolean {
|
|
21
|
+
if (node.type === Comment || node.type === Text) return false
|
|
22
|
+
return true
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 把 Form.Item 的 id / aria / invalid / v-model 注入到默认插槽的第一个控件(对齐 Ant cloneElement)。
|
|
27
|
+
* 只有这个直接子节点跟 Item 的 error;子孙里的搜索框不吃 invalid。
|
|
28
|
+
* 子节点已绑定 v-model 时不覆盖(switch Y/N、select 类型映射等)。
|
|
29
|
+
*/
|
|
30
|
+
export function bindFormItemControl(
|
|
31
|
+
children: VNode[] | undefined,
|
|
32
|
+
extra: Record<string, unknown>,
|
|
33
|
+
): VNode[] | undefined {
|
|
34
|
+
if (!children?.length) return children
|
|
35
|
+
const flat = flattenVNodes(children)
|
|
36
|
+
const index = flat.findIndex(isControlVNode)
|
|
37
|
+
if (index < 0) return children
|
|
38
|
+
const target = flat[index]
|
|
39
|
+
if (!target) return children
|
|
40
|
+
const next = flat.slice()
|
|
41
|
+
next[index] = cloneVNode(target, pickControlInject(target, extra), true)
|
|
42
|
+
return next
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function pickControlInject(
|
|
46
|
+
node: VNode,
|
|
47
|
+
extra: Record<string, unknown>,
|
|
48
|
+
): Record<string, unknown> {
|
|
49
|
+
const props = node.props
|
|
50
|
+
if (!props || !('modelValue' in props || 'onUpdate:modelValue' in props)) {
|
|
51
|
+
return extra
|
|
52
|
+
}
|
|
53
|
+
const { modelValue: _model, 'onUpdate:modelValue': _update, ...rest } = extra
|
|
54
|
+
return rest
|
|
55
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** 字段路径:`'user.email'` 或 `['user', 'email']`(对齐 Ant Design NamePath) */
|
|
2
|
+
export type RsFormNamePath = string | Array<string | number>
|
|
3
|
+
|
|
4
|
+
/** 路径段是否为数组下标(Form.List 相对 name 的第一段)。 */
|
|
5
|
+
export function isIndexSegment(seg: string | number): boolean {
|
|
6
|
+
if (typeof seg === 'number') return Number.isInteger(seg) && seg >= 0
|
|
7
|
+
return /^\d+$/.test(seg)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 将 NamePath 规范为路径段。字符串按 `.` 拆分。
|
|
12
|
+
*/
|
|
13
|
+
export function normalizeNamePath(name?: RsFormNamePath | null): Array<string | number> {
|
|
14
|
+
if (name == null || name === '') return []
|
|
15
|
+
if (Array.isArray(name)) return name.filter((seg) => seg !== '')
|
|
16
|
+
return String(name)
|
|
17
|
+
.split('.')
|
|
18
|
+
.filter((seg) => seg !== '')
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 拼接多段 NamePath(List 前缀 + Item name)。
|
|
23
|
+
*/
|
|
24
|
+
export function concatNamePath(
|
|
25
|
+
...parts: Array<RsFormNamePath | undefined | null>
|
|
26
|
+
): Array<string | number> {
|
|
27
|
+
return parts.flatMap((part) => normalizeNamePath(part))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 路径转 rules / DOM 使用的稳定键。
|
|
32
|
+
*/
|
|
33
|
+
export function namePathKey(name?: RsFormNamePath | null): string {
|
|
34
|
+
return normalizeNamePath(name).map(String).join('.')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 路径是否已存在于对象树上(含值为 null / undefined 的叶子)。
|
|
39
|
+
*/
|
|
40
|
+
export function hasByNamePath(source: unknown, name?: RsFormNamePath | null): boolean {
|
|
41
|
+
const keys = normalizeNamePath(name)
|
|
42
|
+
if (!keys.length) return false
|
|
43
|
+
let current: unknown = source
|
|
44
|
+
for (const key of keys) {
|
|
45
|
+
if (current == null || typeof current !== 'object') return false
|
|
46
|
+
if (!Object.prototype.hasOwnProperty.call(current, String(key))) return false
|
|
47
|
+
current = (current as Record<string, unknown>)[String(key)]
|
|
48
|
+
}
|
|
49
|
+
return true
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 按 NamePath 读取对象字段。
|
|
54
|
+
*/
|
|
55
|
+
export function getByNamePath(source: unknown, name?: RsFormNamePath | null): unknown {
|
|
56
|
+
const keys = normalizeNamePath(name)
|
|
57
|
+
if (!keys.length) return undefined
|
|
58
|
+
let current: unknown = source
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
if (current == null || typeof current !== 'object') return undefined
|
|
61
|
+
current = (current as Record<string, unknown>)[String(key)]
|
|
62
|
+
}
|
|
63
|
+
return current
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 按 NamePath 写入对象字段。
|
|
68
|
+
* 中间缺失的容器按下一段是否为下标补 `[]` 或 `{}`,已有数组不会被覆盖成对象。
|
|
69
|
+
*/
|
|
70
|
+
export function setByNamePath(
|
|
71
|
+
target: Record<string, unknown>,
|
|
72
|
+
name: RsFormNamePath,
|
|
73
|
+
value: unknown,
|
|
74
|
+
): void {
|
|
75
|
+
const keys = normalizeNamePath(name)
|
|
76
|
+
if (!keys.length) return
|
|
77
|
+
let current: unknown = target
|
|
78
|
+
for (let i = 0; i < keys.length - 1; i += 1) {
|
|
79
|
+
if (current == null || typeof current !== 'object') return
|
|
80
|
+
const obj = current as Record<string, unknown>
|
|
81
|
+
const key = String(keys[i])
|
|
82
|
+
const nextKey = keys[i + 1]
|
|
83
|
+
let next = obj[key]
|
|
84
|
+
if (next == null || typeof next !== 'object') {
|
|
85
|
+
next = isIndexSegment(nextKey!) ? [] : {}
|
|
86
|
+
obj[key] = next
|
|
87
|
+
}
|
|
88
|
+
current = next
|
|
89
|
+
}
|
|
90
|
+
if (current == null || typeof current !== 'object') return
|
|
91
|
+
;(current as Record<string, unknown>)[String(keys[keys.length - 1])] = value
|
|
92
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { interpolateRsMessage, type RsTranslateFn } from '../locale/interpolate'
|
|
2
|
+
import { createTranslator } from '../composables/useRsI18n'
|
|
3
|
+
import { defaultLocale } from '../locale/types'
|
|
4
|
+
import type { RsFormNamePath } from './form-path'
|
|
5
|
+
import {
|
|
6
|
+
getInputRuleMessage,
|
|
7
|
+
validateInputRule,
|
|
8
|
+
type RsInputRule,
|
|
9
|
+
} from './input-rules'
|
|
10
|
+
|
|
11
|
+
/** 校验触发时机(对齐 Ant Design Form) */
|
|
12
|
+
export type RsFormRuleTrigger = 'blur' | 'change' | 'submit'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* validator 第二参:读取整表数据,供跨字段校验(B 依赖 A)。
|
|
16
|
+
*/
|
|
17
|
+
export interface RsFormValidatorContext {
|
|
18
|
+
name?: string
|
|
19
|
+
getFieldValue: (name: RsFormNamePath) => unknown
|
|
20
|
+
getFieldsValue: () => Record<string, unknown>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 单条表单规则(声明式 + 自定义校验)。
|
|
25
|
+
* 对标 Ant Design / Element Plus Form rules 的常用子集。
|
|
26
|
+
*/
|
|
27
|
+
/** 规则文案:静态字符串,或按当前值动态生成(对齐 Ant Design message 函数能力) */
|
|
28
|
+
export type RsFormRuleMessage =
|
|
29
|
+
| string
|
|
30
|
+
| ((ctx: { value: unknown; rule: RsFormRuleItem }) => string)
|
|
31
|
+
|
|
32
|
+
export interface RsFormRuleItem {
|
|
33
|
+
required?: boolean
|
|
34
|
+
/**
|
|
35
|
+
* 错误文案;未传时使用内置 i18n。
|
|
36
|
+
* 可传函数按当前值动态生成文案。
|
|
37
|
+
*/
|
|
38
|
+
message?: RsFormRuleMessage
|
|
39
|
+
/** 字符串长度下限 / 数值下限 */
|
|
40
|
+
min?: number
|
|
41
|
+
/** 字符串长度上限 / 数值上限 */
|
|
42
|
+
max?: number
|
|
43
|
+
/** 字符串精确长度 */
|
|
44
|
+
len?: number
|
|
45
|
+
pattern?: RegExp
|
|
46
|
+
/** 内置类型:email/phone 等,或 string/number/array */
|
|
47
|
+
type?: RsInputRule | 'string' | 'number' | 'array'
|
|
48
|
+
/**
|
|
49
|
+
* 自定义校验。返回 true 通过;false / 字符串为失败;支持 Promise。
|
|
50
|
+
* 第二参可读取其它字段(`getFieldValue` / `getFieldsValue`)。
|
|
51
|
+
*/
|
|
52
|
+
validator?: (
|
|
53
|
+
value: unknown,
|
|
54
|
+
ctx: RsFormValidatorContext,
|
|
55
|
+
) => boolean | string | void | Promise<boolean | string | void>
|
|
56
|
+
trigger?: RsFormRuleTrigger | RsFormRuleTrigger[]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 字段名 → 规则(单条或数组) */
|
|
60
|
+
export type RsFormRules = Record<string, RsFormRuleItem | RsFormRuleItem[]>
|
|
61
|
+
|
|
62
|
+
export interface RsFormRuleValidateResult {
|
|
63
|
+
valid: boolean
|
|
64
|
+
message?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Form.validateMessages 模板(`{label}` 插值)。
|
|
69
|
+
* 对标 Ant Design Form.validateMessages。
|
|
70
|
+
*/
|
|
71
|
+
export interface RsFormValidateMessages {
|
|
72
|
+
required?: string
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export interface RsFormFieldRulesOptions {
|
|
76
|
+
trigger?: RsFormRuleTrigger
|
|
77
|
+
t?: RsTranslateFn
|
|
78
|
+
label?: string
|
|
79
|
+
name?: string
|
|
80
|
+
validateMessages?: RsFormValidateMessages
|
|
81
|
+
getFieldValue?: (name: RsFormNamePath) => unknown
|
|
82
|
+
getFieldsValue?: () => Record<string, unknown>
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function normalizeFormRules(
|
|
86
|
+
rules?: RsFormRuleItem | RsFormRuleItem[] | null,
|
|
87
|
+
): RsFormRuleItem[] {
|
|
88
|
+
if (!rules) return []
|
|
89
|
+
return Array.isArray(rules) ? rules : [rules]
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function matchFormRuleTrigger(
|
|
93
|
+
rule: RsFormRuleItem,
|
|
94
|
+
trigger?: RsFormRuleTrigger,
|
|
95
|
+
): boolean {
|
|
96
|
+
if (!trigger || trigger === 'submit') return true
|
|
97
|
+
const ruleTrigger = rule.trigger
|
|
98
|
+
if (!ruleTrigger) return true
|
|
99
|
+
const list = Array.isArray(ruleTrigger) ? ruleTrigger : [ruleTrigger]
|
|
100
|
+
return list.includes(trigger)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isEmptyValue(value: unknown): boolean {
|
|
104
|
+
if (value == null) return true
|
|
105
|
+
if (typeof value === 'string') return value.trim() === ''
|
|
106
|
+
if (Array.isArray(value)) return value.length === 0
|
|
107
|
+
// 日期区间 { start, end }:两端皆空视为空
|
|
108
|
+
if (typeof value === 'object') {
|
|
109
|
+
const record = value as Record<string, unknown>
|
|
110
|
+
if ('start' in record || 'end' in record) {
|
|
111
|
+
return isEmptyValue(record.start) && isEmptyValue(record.end)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function valueLength(value: unknown): number | null {
|
|
118
|
+
if (typeof value === 'string') return value.trim().length
|
|
119
|
+
if (typeof value === 'number' && Number.isFinite(value)) return value
|
|
120
|
+
if (Array.isArray(value)) return value.length
|
|
121
|
+
return null
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function fail(message: string): RsFormRuleValidateResult {
|
|
125
|
+
return { valid: false, message }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 解析规则 message(字符串或函数) */
|
|
129
|
+
export function resolveRuleMessage(
|
|
130
|
+
rule: RsFormRuleItem,
|
|
131
|
+
value: unknown,
|
|
132
|
+
fallback: string,
|
|
133
|
+
): string {
|
|
134
|
+
const message = rule.message
|
|
135
|
+
if (typeof message === 'function') return message({ value, rule })
|
|
136
|
+
if (typeof message === 'string') return message
|
|
137
|
+
return fallback
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function formatInvalid(
|
|
141
|
+
rule: RsFormRuleItem,
|
|
142
|
+
value: unknown,
|
|
143
|
+
tr: RsTranslateFn,
|
|
144
|
+
): string {
|
|
145
|
+
return resolveRuleMessage(rule, value, tr('input.formatInvalid'))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** 类型规则:string/number/array 或内置 email/phone 等 */
|
|
149
|
+
function checkTypeRule(
|
|
150
|
+
value: unknown,
|
|
151
|
+
rule: RsFormRuleItem,
|
|
152
|
+
tr: RsTranslateFn,
|
|
153
|
+
): RsFormRuleValidateResult | null {
|
|
154
|
+
const type = rule.type
|
|
155
|
+
if (!type) return null
|
|
156
|
+
|
|
157
|
+
if (type === 'string' && typeof value !== 'string') {
|
|
158
|
+
return fail(formatInvalid(rule, value, tr))
|
|
159
|
+
}
|
|
160
|
+
if (type === 'number' && typeof value !== 'number') {
|
|
161
|
+
return fail(formatInvalid(rule, value, tr))
|
|
162
|
+
}
|
|
163
|
+
if (type === 'array' && !Array.isArray(value)) {
|
|
164
|
+
return fail(formatInvalid(rule, value, tr))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const isBuiltin =
|
|
168
|
+
type !== 'string' && type !== 'number' && type !== 'array'
|
|
169
|
+
if (isBuiltin && typeof value === 'string' && !validateInputRule(value, type)) {
|
|
170
|
+
return fail(
|
|
171
|
+
resolveRuleMessage(rule, value, getInputRuleMessage(type, tr)),
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return null
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function checkPatternRule(
|
|
179
|
+
value: unknown,
|
|
180
|
+
rule: RsFormRuleItem,
|
|
181
|
+
tr: RsTranslateFn,
|
|
182
|
+
): RsFormRuleValidateResult | null {
|
|
183
|
+
if (!rule.pattern || typeof value !== 'string') return null
|
|
184
|
+
if (rule.pattern.test(value)) return null
|
|
185
|
+
return fail(formatInvalid(rule, value, tr))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function checkLengthRule(
|
|
189
|
+
value: unknown,
|
|
190
|
+
rule: RsFormRuleItem,
|
|
191
|
+
tr: RsTranslateFn,
|
|
192
|
+
): RsFormRuleValidateResult | null {
|
|
193
|
+
const length = valueLength(value)
|
|
194
|
+
if (length == null) return null
|
|
195
|
+
|
|
196
|
+
if (rule.len != null && length !== rule.len) {
|
|
197
|
+
return fail(formatInvalid(rule, value, tr))
|
|
198
|
+
}
|
|
199
|
+
if (rule.min != null && length < rule.min) {
|
|
200
|
+
return fail(formatInvalid(rule, value, tr))
|
|
201
|
+
}
|
|
202
|
+
if (rule.max != null && length > rule.max) {
|
|
203
|
+
return fail(formatInvalid(rule, value, tr))
|
|
204
|
+
}
|
|
205
|
+
return null
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async function checkValidatorRule(
|
|
209
|
+
value: unknown,
|
|
210
|
+
rule: RsFormRuleItem,
|
|
211
|
+
tr: RsTranslateFn,
|
|
212
|
+
options?: RsFormFieldRulesOptions,
|
|
213
|
+
): Promise<RsFormRuleValidateResult | null> {
|
|
214
|
+
if (!rule.validator) return null
|
|
215
|
+
|
|
216
|
+
const ctx: RsFormValidatorContext = {
|
|
217
|
+
name: options?.name,
|
|
218
|
+
getFieldValue: options?.getFieldValue ?? (() => undefined),
|
|
219
|
+
getFieldsValue: options?.getFieldsValue ?? (() => ({})),
|
|
220
|
+
}
|
|
221
|
+
let result: unknown
|
|
222
|
+
try {
|
|
223
|
+
result = await rule.validator(value, ctx)
|
|
224
|
+
} catch (err) {
|
|
225
|
+
const message =
|
|
226
|
+
err instanceof Error && err.message
|
|
227
|
+
? err.message
|
|
228
|
+
: formatInvalid(rule, value, tr)
|
|
229
|
+
return fail(message)
|
|
230
|
+
}
|
|
231
|
+
if (result === true || result === undefined || result === null) return null
|
|
232
|
+
if (result === false) return fail(formatInvalid(rule, value, tr))
|
|
233
|
+
if (typeof result === 'string') return fail(result)
|
|
234
|
+
if (result instanceof Error) {
|
|
235
|
+
return fail(result.message || formatInvalid(rule, value, tr))
|
|
236
|
+
}
|
|
237
|
+
return null
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* 执行单条规则;通过返回 null,失败返回结果。
|
|
242
|
+
* 空值且非必填时跳过格式类规则。
|
|
243
|
+
*/
|
|
244
|
+
async function evaluateFormRule(
|
|
245
|
+
value: unknown,
|
|
246
|
+
rule: RsFormRuleItem,
|
|
247
|
+
tr: RsTranslateFn,
|
|
248
|
+
options?: RsFormFieldRulesOptions,
|
|
249
|
+
): Promise<RsFormRuleValidateResult | null> {
|
|
250
|
+
if (rule.required && isEmptyValue(value)) {
|
|
251
|
+
const label = options?.label?.trim()
|
|
252
|
+
const template =
|
|
253
|
+
options?.validateMessages?.required ??
|
|
254
|
+
(label ? tr('form.validate.required') : tr('input.required'))
|
|
255
|
+
const fallback = interpolateRsMessage(template, { label: label || tr('form.field') })
|
|
256
|
+
return fail(resolveRuleMessage(rule, value, fallback))
|
|
257
|
+
}
|
|
258
|
+
// 空值跳过格式类规则;自定义 validator 仍执行,以便 B 依赖 A(如 A=email 则 B 必填)
|
|
259
|
+
if (isEmptyValue(value)) {
|
|
260
|
+
return checkValidatorRule(value, rule, tr, options)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return (
|
|
264
|
+
checkTypeRule(value, rule, tr) ??
|
|
265
|
+
checkPatternRule(value, rule, tr) ??
|
|
266
|
+
checkLengthRule(value, rule, tr) ??
|
|
267
|
+
(await checkValidatorRule(value, rule, tr, options))
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* 按顺序执行字段规则,首条失败即返回。
|
|
273
|
+
*/
|
|
274
|
+
export async function runFormFieldRules(
|
|
275
|
+
value: unknown,
|
|
276
|
+
rules: RsFormRuleItem[],
|
|
277
|
+
options?: RsFormFieldRulesOptions,
|
|
278
|
+
): Promise<RsFormRuleValidateResult> {
|
|
279
|
+
const tr = options?.t ?? createTranslator(defaultLocale)
|
|
280
|
+
const trigger = options?.trigger
|
|
281
|
+
|
|
282
|
+
for (const rule of rules) {
|
|
283
|
+
if (!matchFormRuleTrigger(rule, trigger)) continue
|
|
284
|
+
const failed = await evaluateFormRule(value, rule, tr, options)
|
|
285
|
+
if (failed) return failed
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return { valid: true }
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** 将 Input 局部 props 转为规则列表,便于与 Form rules 合并 */
|
|
292
|
+
export function buildLocalInputRules(options: {
|
|
293
|
+
required?: boolean
|
|
294
|
+
rule?: RsInputRule
|
|
295
|
+
validator?: (value: string) => boolean | string
|
|
296
|
+
requiredMessage?: string
|
|
297
|
+
}): RsFormRuleItem[] {
|
|
298
|
+
const list: RsFormRuleItem[] = []
|
|
299
|
+
if (options.required) {
|
|
300
|
+
list.push({ required: true, message: options.requiredMessage })
|
|
301
|
+
}
|
|
302
|
+
if (options.rule) {
|
|
303
|
+
list.push({ type: options.rule })
|
|
304
|
+
}
|
|
305
|
+
if (options.validator) {
|
|
306
|
+
list.push({
|
|
307
|
+
validator: (value) => options.validator!(String(value ?? '')),
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
return list
|
|
311
|
+
}
|
|
@@ -7,7 +7,26 @@ import {
|
|
|
7
7
|
type ComputedRef,
|
|
8
8
|
type InjectionKey,
|
|
9
9
|
type Ref,
|
|
10
|
+
type VNodeChild,
|
|
10
11
|
} from 'vue'
|
|
12
|
+
import type { RsFormRuleItem, RsFormRuleTrigger, RsFormRules, RsFormValidateMessages } from './form-rules'
|
|
13
|
+
import { normalizeFormRules } from './form-rules'
|
|
14
|
+
import { namePathKey, type RsFormNamePath } from './form-path'
|
|
15
|
+
|
|
16
|
+
/** 自定义错误渲染上下文(Form / 字段共用) */
|
|
17
|
+
export interface RsFormErrorRenderContext {
|
|
18
|
+
name?: string
|
|
19
|
+
message: string
|
|
20
|
+
value: unknown
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 自定义错误渲染(对齐 Ant Design Form.Item help / Element #error)。
|
|
25
|
+
* 返回 VNode / 字符串;返回 null/undefined 时回退默认文案。
|
|
26
|
+
*/
|
|
27
|
+
export type RsFormErrorRender = (
|
|
28
|
+
ctx: RsFormErrorRenderContext,
|
|
29
|
+
) => VNodeChild | null | undefined
|
|
11
30
|
|
|
12
31
|
export type RsFormLabelPosition = 'top' | 'left'
|
|
13
32
|
export type RsFormLabelAlign = 'start' | 'end'
|
|
@@ -15,15 +34,33 @@ export type RsFormSize = 'ssm' | 'sm' | 'md' | 'lg'
|
|
|
15
34
|
export type RsFormGap = 'sm' | 'md' | 'lg'
|
|
16
35
|
export type RsFormMaxWidth = 'sm' | 'md' | 'lg' | 'full' | 'none'
|
|
17
36
|
|
|
37
|
+
/** Form.Item 校验态(对齐 Ant Design validateStatus) */
|
|
38
|
+
export type RsFormValidateStatus = 'success' | 'warning' | 'error' | 'validating' | ''
|
|
39
|
+
|
|
40
|
+
/** 整表校验结果(含按字段名聚合的错误) */
|
|
18
41
|
export interface RsFormValidationResult {
|
|
19
42
|
valid: boolean
|
|
43
|
+
/** 字段名 → 首条错误文案;无 name 的字段不计入 */
|
|
44
|
+
errors: Record<string, string>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface RsFormFieldValidationResult {
|
|
48
|
+
valid: boolean
|
|
49
|
+
message?: string
|
|
50
|
+
name?: string
|
|
20
51
|
}
|
|
21
52
|
|
|
22
53
|
export interface RsFormFieldExpose {
|
|
54
|
+
/** 字段名,用于匹配 Form.rules */
|
|
55
|
+
name?: string
|
|
23
56
|
getValue: () => unknown
|
|
24
57
|
setValue: (value: unknown) => void
|
|
25
|
-
validate?: (
|
|
58
|
+
validate?: (
|
|
59
|
+
trigger?: RsFormRuleTrigger,
|
|
60
|
+
) => RsFormFieldValidationResult | Promise<RsFormFieldValidationResult>
|
|
26
61
|
clearValidation?: () => void
|
|
62
|
+
/** 由 Form 或外部写入错误态 */
|
|
63
|
+
setError?: (message: string) => void
|
|
27
64
|
}
|
|
28
65
|
|
|
29
66
|
export interface RsFormContext {
|
|
@@ -32,8 +69,19 @@ export interface RsFormContext {
|
|
|
32
69
|
labelWidth: Readonly<Ref<string>>
|
|
33
70
|
labelAlign: Readonly<Ref<RsFormLabelAlign>>
|
|
34
71
|
size: Readonly<Ref<RsFormSize>>
|
|
72
|
+
/** 当前 Form 上的 rules(响应式读取) */
|
|
73
|
+
rules: Readonly<Ref<RsFormRules | undefined>>
|
|
74
|
+
getFieldRules: (name?: string) => RsFormRuleItem[]
|
|
75
|
+
/** Form 级自定义错误渲染;字段无 #error 时使用 */
|
|
76
|
+
renderError?: RsFormErrorRender
|
|
35
77
|
registerField: (id: symbol, field: RsFormFieldExpose) => void
|
|
36
78
|
unregisterField: (id: symbol) => void
|
|
79
|
+
/** 可选数据中枢(Form.model) */
|
|
80
|
+
model: Readonly<Ref<Record<string, unknown> | undefined>>
|
|
81
|
+
validateMessages: ComputedRef<RsFormValidateMessages | undefined>
|
|
82
|
+
getFieldValue: (name: RsFormNamePath) => unknown
|
|
83
|
+
setFieldValue: (name: RsFormNamePath, value: unknown) => void
|
|
84
|
+
getFieldsValue: () => Record<string, unknown>
|
|
37
85
|
}
|
|
38
86
|
|
|
39
87
|
export const RS_FORM_INJECTION_KEY: InjectionKey<RsFormContext> = Symbol('RsForm')
|
|
@@ -48,6 +96,68 @@ export function cloneFormFieldValue(value: unknown): unknown {
|
|
|
48
96
|
}
|
|
49
97
|
}
|
|
50
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Form.Item 上下文(对齐 Element `elFormItem` / Ant Design Form.Item)。
|
|
101
|
+
* invalid 只属于绑定控件:Item 通过 cloneElement 打到直接子节点,
|
|
102
|
+
* 子孙里的搜索框等应先用 isRsFormItemBoundControl 判断,不要一律跟 Item 变红。
|
|
103
|
+
*/
|
|
104
|
+
export interface RsFormItemContext {
|
|
105
|
+
name: ComputedRef<string | undefined>
|
|
106
|
+
/** 已声明 name 时 Item 拥有字段,内置控件不再向 Form 注册 */
|
|
107
|
+
ownsField: ComputedRef<boolean>
|
|
108
|
+
invalid: ComputedRef<boolean>
|
|
109
|
+
message: ComputedRef<string>
|
|
110
|
+
status: ComputedRef<RsFormValidateStatus>
|
|
111
|
+
fieldId: ComputedRef<string>
|
|
112
|
+
errorId: ComputedRef<string>
|
|
113
|
+
describedBy: ComputedRef<string | undefined>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const RS_FORM_ITEM_INJECTION_KEY: InjectionKey<RsFormItemContext> =
|
|
117
|
+
Symbol('RsFormItem')
|
|
118
|
+
|
|
119
|
+
export function provideRsFormItemContext(context: RsFormItemContext): void {
|
|
120
|
+
provide(RS_FORM_ITEM_INJECTION_KEY, context)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function useRsFormItemContext(): RsFormItemContext | null {
|
|
124
|
+
return inject(RS_FORM_ITEM_INJECTION_KEY, null)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Form.List 上下文:子 Item 的 name 会拼上 List 前缀(users + [0, 'name'] → users.0.name)。
|
|
129
|
+
*/
|
|
130
|
+
export interface RsFormListContext {
|
|
131
|
+
prefix: ComputedRef<Array<string | number>>
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Form.List 默认插槽中的一行 */
|
|
135
|
+
export interface RsFormListField {
|
|
136
|
+
/** 稳定行键,用于 v-for */
|
|
137
|
+
key: number
|
|
138
|
+
/** 当前下标,作为子 Item name 的第一段 */
|
|
139
|
+
name: number
|
|
140
|
+
index: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Form.List 增删改操作 */
|
|
144
|
+
export interface RsFormListOperations {
|
|
145
|
+
add: (defaultValue?: unknown) => void
|
|
146
|
+
remove: (index: number) => void
|
|
147
|
+
move: (from: number, to: number) => void
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export const RS_FORM_LIST_INJECTION_KEY: InjectionKey<RsFormListContext> =
|
|
151
|
+
Symbol('RsFormList')
|
|
152
|
+
|
|
153
|
+
export function provideRsFormListContext(context: RsFormListContext): void {
|
|
154
|
+
provide(RS_FORM_LIST_INJECTION_KEY, context)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function useRsFormListContext(): RsFormListContext | null {
|
|
158
|
+
return inject(RS_FORM_LIST_INJECTION_KEY, null)
|
|
159
|
+
}
|
|
160
|
+
|
|
51
161
|
export function provideRsFormContext(context: RsFormContext): void {
|
|
52
162
|
provide(RS_FORM_INJECTION_KEY, context)
|
|
53
163
|
}
|
|
@@ -56,15 +166,35 @@ export function useRsFormContext(): RsFormContext | null {
|
|
|
56
166
|
return inject(RS_FORM_INJECTION_KEY, null)
|
|
57
167
|
}
|
|
58
168
|
|
|
169
|
+
/**
|
|
170
|
+
* 是否为 Form.Item 的绑定控件(对齐 Ant Design cloneElement)。
|
|
171
|
+
* name 与 Item 相同,或 id 等于 Item 注入的 fieldId。
|
|
172
|
+
*/
|
|
173
|
+
export function isRsFormItemBoundControl(
|
|
174
|
+
item: RsFormItemContext | null | undefined,
|
|
175
|
+
control: { id?: string; name?: string },
|
|
176
|
+
): boolean {
|
|
177
|
+
if (!item?.ownsField.value) return false
|
|
178
|
+
const itemName = item.name.value
|
|
179
|
+
if (control.name && itemName && namePathKey(control.name) === itemName) return true
|
|
180
|
+
if (control.id && control.id === item.fieldId.value) return true
|
|
181
|
+
return false
|
|
182
|
+
}
|
|
183
|
+
|
|
59
184
|
export function useRsFormField(getExpose: () => RsFormFieldExpose | undefined): void {
|
|
60
185
|
const form = useRsFormContext()
|
|
186
|
+
const item = useRsFormItemContext()
|
|
61
187
|
if (!form) return
|
|
62
188
|
|
|
63
189
|
const fieldId = Symbol('rs-form-field')
|
|
64
190
|
|
|
65
191
|
onMounted(() => {
|
|
192
|
+
// Item 已按 name 注册时,内置控件只负责录入,避免重复校验
|
|
193
|
+
if (item?.ownsField.value) return
|
|
66
194
|
const expose = getExpose()
|
|
67
|
-
|
|
195
|
+
// 对齐 Ant / RHF:无 name 不进字段表,弹层搜索框不参与外层校验
|
|
196
|
+
if (!expose?.name) return
|
|
197
|
+
form.registerField(fieldId, expose)
|
|
68
198
|
})
|
|
69
199
|
|
|
70
200
|
onUnmounted(() => {
|
|
@@ -72,6 +202,18 @@ export function useRsFormField(getExpose: () => RsFormFieldExpose | undefined):
|
|
|
72
202
|
})
|
|
73
203
|
}
|
|
74
204
|
|
|
75
|
-
export function resolveRsFormSize(
|
|
205
|
+
export function resolveRsFormSize(
|
|
206
|
+
size?: RsFormSize,
|
|
207
|
+
form?: RsFormContext | null,
|
|
208
|
+
): ComputedRef<RsFormSize> {
|
|
76
209
|
return computed(() => size ?? form?.size.value ?? 'md')
|
|
77
210
|
}
|
|
211
|
+
|
|
212
|
+
/** 供 Form 内部解析某字段 rules */
|
|
213
|
+
export function resolveFieldRules(
|
|
214
|
+
rules: RsFormRules | undefined,
|
|
215
|
+
name?: string,
|
|
216
|
+
): RsFormRuleItem[] {
|
|
217
|
+
if (!name || !rules) return []
|
|
218
|
+
return normalizeFormRules(rules[name])
|
|
219
|
+
}
|
|
@@ -46,3 +46,14 @@ export function findMenuParentKeys(items: RsMenuItems, key: string): string[] {
|
|
|
46
46
|
|
|
47
47
|
return []
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
/** 判断菜单项自身或其任意后代是否匹配 key(用于父级高亮) */
|
|
51
|
+
export function menuItemContainsKey(item: RsMenuItem, key: string): boolean {
|
|
52
|
+
if (item.key === key) {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
if (!item.children?.length) {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
return item.children.some((child) => menuItemContainsKey(child, key))
|
|
59
|
+
}
|
|
@@ -12,6 +12,9 @@ export const RS_Z_PANEL = 'var(--rs-z-panel)'
|
|
|
12
12
|
/** 模态对话框 */
|
|
13
13
|
export const RS_Z_MODAL = 'var(--rs-z-modal)'
|
|
14
14
|
|
|
15
|
+
/** 顶栏加载进度条(低于 toast,避免遮挡通知) */
|
|
16
|
+
export const RS_Z_LOADING_BAR = 'var(--rs-z-loading-bar)'
|
|
17
|
+
|
|
15
18
|
/** 全局 Toast */
|
|
16
19
|
export const RS_Z_TOAST = 'var(--rs-z-toast)'
|
|
17
20
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
2
|
+
import type { RsComponentSize } from '../theme/types'
|
|
3
|
+
|
|
4
|
+
/** 单选值类型 */
|
|
5
|
+
export type RsRadioValue = string | number | boolean
|
|
6
|
+
|
|
7
|
+
/** RadioGroup 向下注入的上下文 */
|
|
8
|
+
export type RsRadioGroupContext = {
|
|
9
|
+
size: Ref<RsComponentSize>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const RS_RADIO_GROUP_KEY: InjectionKey<RsRadioGroupContext> = Symbol('rs-radio-group')
|