@svadmin/ui 0.122.0 → 0.126.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/dist/app.css +581 -4
- package/dist/app.theme.css +581 -4
- package/dist/components/AbacPolicyMatrix.svelte +356 -0
- package/dist/components/AbacPolicyMatrix.svelte.d.ts +30 -0
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/ActionPalette.svelte +272 -0
- package/dist/components/ActionPalette.svelte.d.ts +23 -0
- package/dist/components/AdminCopilotWidget.svelte +316 -0
- package/dist/components/AdminCopilotWidget.svelte.d.ts +33 -0
- package/dist/components/AnnouncementBanner.svelte +12 -1
- package/dist/components/AnnouncementBanner.svelte.d.ts +4 -0
- package/dist/components/ApiPlayground.svelte +255 -0
- package/dist/components/ApiPlayground.svelte.d.ts +24 -0
- package/dist/components/ApiSettings.svelte +1 -1
- package/dist/components/AppearanceSettings.svelte +1 -1
- package/dist/components/ApprovalChainBuilder.svelte +262 -0
- package/dist/components/ApprovalChainBuilder.svelte.d.ts +20 -0
- package/dist/components/ApprovalTimeline.svelte +8 -1
- package/dist/components/AsyncExportModal.svelte +1 -1
- package/dist/components/AudioFeedbackProvider.svelte +1 -1
- package/dist/components/AuditLogDrawer.svelte +2 -2
- package/dist/components/AuditTrailInspector.svelte +448 -0
- package/dist/components/AuditTrailInspector.svelte.d.ts +44 -0
- package/dist/components/AutoTable.svelte +20 -1
- package/dist/components/AutoTable.svelte.d.ts +2 -0
- package/dist/components/BatchEditModal.svelte +266 -0
- package/dist/components/BatchEditModal.svelte.d.ts +27 -0
- package/dist/components/BillingInvoiceDrawer.svelte +206 -0
- package/dist/components/BillingInvoiceDrawer.svelte.d.ts +30 -0
- package/dist/components/ChartAnnotationOverlay.svelte +228 -0
- package/dist/components/ChartAnnotationOverlay.svelte.d.ts +21 -0
- package/dist/components/CheckCard.svelte +1 -1
- package/dist/components/ClusterTopologyGraph.svelte +317 -0
- package/dist/components/ClusterTopologyGraph.svelte.d.ts +31 -0
- package/dist/components/ColumnHeaderFilter.svelte +6 -6
- package/dist/components/ColumnMappingTable.svelte +174 -0
- package/dist/components/ColumnMappingTable.svelte.d.ts +23 -0
- package/dist/components/ConversionFunnel.svelte +1 -1
- package/dist/components/CursorListFooter.svelte +67 -0
- package/dist/components/CursorListFooter.svelte.d.ts +17 -0
- package/dist/components/DashboardGridLayout.svelte +309 -0
- package/dist/components/DashboardGridLayout.svelte.d.ts +30 -0
- package/dist/components/DashboardLayoutStorage.svelte +278 -0
- package/dist/components/DashboardLayoutStorage.svelte.d.ts +23 -0
- package/dist/components/DataFreshnessIndicator.svelte +149 -0
- package/dist/components/DataFreshnessIndicator.svelte.d.ts +20 -0
- package/dist/components/DataImportDropzone.svelte +215 -0
- package/dist/components/DataImportDropzone.svelte.d.ts +24 -0
- package/dist/components/DataLineageGraph.svelte +203 -0
- package/dist/components/DataLineageGraph.svelte.d.ts +26 -0
- package/dist/components/DataMaskPolicyEngine.svelte +291 -0
- package/dist/components/DataMaskPolicyEngine.svelte.d.ts +25 -0
- package/dist/components/DataScopeRuleEditor.svelte +142 -0
- package/dist/components/DataScopeRuleEditor.svelte.d.ts +19 -0
- package/dist/components/DataScreenContainer.svelte +160 -0
- package/dist/components/DataScreenContainer.svelte.d.ts +15 -0
- package/dist/components/DevTools.svelte +3 -3
- package/dist/components/DualApprovalGate.svelte +132 -65
- package/dist/components/DualApprovalGate.svelte.d.ts +20 -1
- package/dist/components/EditableTable.svelte +2 -2
- package/dist/components/ElectronicSealStamp.svelte +102 -0
- package/dist/components/ElectronicSealStamp.svelte.d.ts +14 -0
- package/dist/components/EnvVariableEditor.svelte +284 -0
- package/dist/components/EnvVariableEditor.svelte.d.ts +17 -0
- package/dist/components/ExcelImportWizard.svelte +2 -2
- package/dist/components/FeatureAnnouncementModal.svelte +173 -0
- package/dist/components/FeatureAnnouncementModal.svelte.d.ts +21 -0
- package/dist/components/FieldRenderer.svelte +1 -1
- package/dist/components/FilterTagBar.svelte +210 -0
- package/dist/components/FilterTagBar.svelte.d.ts +23 -0
- package/dist/components/FormulaField.svelte +149 -0
- package/dist/components/FormulaField.svelte.d.ts +18 -0
- package/dist/components/GeoScatterMap.svelte +225 -0
- package/dist/components/GeoScatterMap.svelte.d.ts +22 -0
- package/dist/components/HmacSignatureCalculator.svelte +199 -0
- package/dist/components/HmacSignatureCalculator.svelte.d.ts +10 -0
- package/dist/components/I18nLanguagePackEditor.svelte +208 -0
- package/dist/components/I18nLanguagePackEditor.svelte.d.ts +17 -0
- package/dist/components/ImportPreviewValidator.svelte +239 -0
- package/dist/components/ImportPreviewValidator.svelte.d.ts +26 -0
- package/dist/components/ImportWizard.svelte +2 -2
- package/dist/components/IncidentWarRoomDrawer.svelte +194 -0
- package/dist/components/IncidentWarRoomDrawer.svelte.d.ts +24 -0
- package/dist/components/InputGroup.svelte +133 -0
- package/dist/components/InputGroup.svelte.d.ts +16 -0
- package/dist/components/JsonSchemaForm.svelte +4 -4
- package/dist/components/LightFilter.svelte +2 -2
- package/dist/components/ListPagination.svelte +39 -3
- package/dist/components/LiveStreamLogViewer.svelte +185 -0
- package/dist/components/LiveStreamLogViewer.svelte.d.ts +21 -0
- package/dist/components/MasterSubTableDrawer.svelte +223 -0
- package/dist/components/MasterSubTableDrawer.svelte.d.ts +25 -0
- package/dist/components/MicroAppRouteSync.svelte +185 -0
- package/dist/components/MicroAppRouteSync.svelte.d.ts +12 -0
- package/dist/components/MicroAppSandbox.svelte +200 -0
- package/dist/components/MicroAppSandbox.svelte.d.ts +16 -0
- package/dist/components/MicroAppStateBusIndicator.svelte +159 -0
- package/dist/components/MicroAppStateBusIndicator.svelte.d.ts +12 -0
- package/dist/components/MockDataInterceptor.svelte +292 -0
- package/dist/components/MockDataInterceptor.svelte.d.ts +27 -0
- package/dist/components/OmnibarCommandPalette.svelte +320 -0
- package/dist/components/OmnibarCommandPalette.svelte.d.ts +27 -0
- package/dist/components/PageSkeleton.svelte +19 -5
- package/dist/components/PageSkeleton.svelte.d.ts +5 -3
- package/dist/components/PeriodComparisonCard.svelte +142 -0
- package/dist/components/PeriodComparisonCard.svelte.d.ts +16 -0
- package/dist/components/PermissionMatrix.svelte +1 -1
- package/dist/components/PermissionSimulator.svelte +319 -0
- package/dist/components/PermissionSimulator.svelte.d.ts +34 -0
- package/dist/components/PivotMatrix.svelte +271 -0
- package/dist/components/PivotMatrix.svelte.d.ts +32 -0
- package/dist/components/PlanUsageQuotaBar.svelte +154 -0
- package/dist/components/PlanUsageQuotaBar.svelte.d.ts +26 -0
- package/dist/components/Popconfirm.svelte +20 -8
- package/dist/components/Popconfirm.svelte.d.ts +3 -1
- package/dist/components/ProSkeleton.svelte +4 -0
- package/dist/components/ProSkeleton.svelte.d.ts +2 -0
- package/dist/components/QueryAiExplainer.svelte +148 -0
- package/dist/components/QueryAiExplainer.svelte.d.ts +16 -0
- package/dist/components/QueryBuilder.svelte +456 -0
- package/dist/components/QueryBuilder.svelte.d.ts +33 -0
- package/dist/components/Rate.svelte +19 -2
- package/dist/components/Result.svelte +36 -4
- package/dist/components/Result.svelte.d.ts +4 -2
- package/dist/components/RolePermissionComparator.svelte +273 -0
- package/dist/components/RolePermissionComparator.svelte.d.ts +28 -0
- package/dist/components/RuleExpressionBuilder.svelte +380 -0
- package/dist/components/RuleExpressionBuilder.svelte.d.ts +31 -0
- package/dist/components/ScheduledJobManager.svelte +225 -0
- package/dist/components/ScheduledJobManager.svelte.d.ts +23 -0
- package/dist/components/SchemaVisualModeler.svelte +2 -2
- package/dist/components/ScreenAntiLeakGuard.svelte +88 -0
- package/dist/components/ScreenAntiLeakGuard.svelte.d.ts +12 -0
- package/dist/components/SecureDataExporter.svelte +296 -0
- package/dist/components/SecureDataExporter.svelte.d.ts +29 -0
- package/dist/components/ServerStatusGrid.svelte +179 -0
- package/dist/components/ServerStatusGrid.svelte.d.ts +21 -0
- package/dist/components/SnapshotTimelineReplay.svelte +219 -0
- package/dist/components/SnapshotTimelineReplay.svelte.d.ts +19 -0
- package/dist/components/Spin.svelte +33 -11
- package/dist/components/Spin.svelte.d.ts +7 -4
- package/dist/components/SqlConsole.svelte +247 -0
- package/dist/components/SqlConsole.svelte.d.ts +20 -0
- package/dist/components/StepWizard.svelte +1 -1
- package/dist/components/Steps.svelte +44 -3
- package/dist/components/SystemCapacityForecastCard.svelte +132 -0
- package/dist/components/SystemCapacityForecastCard.svelte.d.ts +19 -0
- package/dist/components/SystemHealthCheckDashboard.svelte +306 -0
- package/dist/components/SystemHealthCheckDashboard.svelte.d.ts +24 -0
- package/dist/components/TableAggregationFooter.svelte +173 -0
- package/dist/components/TableAggregationFooter.svelte.d.ts +22 -0
- package/dist/components/TaskCenter.svelte +37 -29
- package/dist/components/TenantContextSwitcher.svelte +314 -0
- package/dist/components/TenantContextSwitcher.svelte.d.ts +35 -0
- package/dist/components/TenantQuotasMatrix.svelte +229 -0
- package/dist/components/TenantQuotasMatrix.svelte.d.ts +22 -0
- package/dist/components/ThemeSettingsDrawer.svelte +6 -14
- package/dist/components/ThreadedCommentDrawer.svelte +246 -0
- package/dist/components/ThreadedCommentDrawer.svelte.d.ts +26 -0
- package/dist/components/TierFeatureComparison.svelte +147 -0
- package/dist/components/TierFeatureComparison.svelte.d.ts +28 -0
- package/dist/components/Timeline.svelte +12 -3
- package/dist/components/Timeline.svelte.d.ts +2 -0
- package/dist/components/TreeTransferSelect.svelte +333 -0
- package/dist/components/TreeTransferSelect.svelte.d.ts +18 -0
- package/dist/components/VirtualCardGrid.svelte +180 -0
- package/dist/components/VirtualCardGrid.svelte.d.ts +65 -0
- package/dist/components/WebhookSimulator.svelte +263 -0
- package/dist/components/WebhookSimulator.svelte.d.ts +26 -0
- package/dist/components/WidgetContainer.svelte +204 -0
- package/dist/components/WidgetContainer.svelte.d.ts +31 -0
- package/dist/components/WorkflowExecutionTracker.svelte +131 -0
- package/dist/components/WorkflowExecutionTracker.svelte.d.ts +19 -0
- package/dist/components/WorkflowGraphDesigner.svelte +202 -0
- package/dist/components/WorkflowGraphDesigner.svelte.d.ts +24 -0
- package/dist/components/WorkflowNodeInspector.svelte +217 -0
- package/dist/components/WorkflowNodeInspector.svelte.d.ts +24 -0
- package/dist/components/WorkflowStepper.svelte +1 -1
- package/dist/components/list-i18n.d.ts +7 -0
- package/dist/components/list-i18n.js +14 -0
- package/dist/components/ui/badge/badge.svelte +3 -3
- package/dist/components/ui/button/button.svelte +3 -1
- package/dist/components/ui/button/button.svelte.d.ts +1 -0
- package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
- package/dist/components/useDynamicLocale.d.svelte.ts +1 -0
- package/dist/components/useDynamicLocale.svelte.d.ts +10 -0
- package/dist/components/useDynamicLocale.svelte.js +40 -0
- package/dist/components/useFormulaEngine.d.svelte.ts +1 -0
- package/dist/components/useFormulaEngine.svelte.d.ts +9 -0
- package/dist/components/useFormulaEngine.svelte.js +209 -0
- package/dist/components/useMicroAppState.d.svelte.ts +1 -0
- package/dist/components/useMicroAppState.svelte.d.ts +17 -0
- package/dist/components/useMicroAppState.svelte.js +38 -0
- package/dist/components/useStorageCache.d.svelte.ts +1 -0
- package/dist/components/useStorageCache.svelte.d.ts +49 -0
- package/dist/components/useStorageCache.svelte.js +229 -0
- package/dist/components.css +5 -1
- package/dist/index.d.ts +75 -3
- package/dist/index.js +118 -2
- package/package.json +4 -4
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { untrack } from 'svelte';
|
|
3
|
+
import { Plus, Trash2, FolderPlus, RotateCcw, Code2, Database } from '@lucide/svelte';
|
|
4
|
+
import { cn } from '../utils.js';
|
|
5
|
+
|
|
6
|
+
export type LogicalOperator = 'AND' | 'OR';
|
|
7
|
+
export type ComparisonOperator =
|
|
8
|
+
| 'equals'
|
|
9
|
+
| 'not_equals'
|
|
10
|
+
| 'contains'
|
|
11
|
+
| 'not_contains'
|
|
12
|
+
| 'starts_with'
|
|
13
|
+
| 'ends_with'
|
|
14
|
+
| 'gt'
|
|
15
|
+
| 'gte'
|
|
16
|
+
| 'lt'
|
|
17
|
+
| 'lte'
|
|
18
|
+
| 'in'
|
|
19
|
+
| 'not_in'
|
|
20
|
+
| 'between'
|
|
21
|
+
| 'is_null'
|
|
22
|
+
| 'is_not_null';
|
|
23
|
+
|
|
24
|
+
export interface QueryField {
|
|
25
|
+
key: string;
|
|
26
|
+
label: string;
|
|
27
|
+
type: 'text' | 'number' | 'select' | 'date' | 'boolean';
|
|
28
|
+
options?: Array<{ label: string; value: string | number }> | undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface QueryRule {
|
|
32
|
+
id: string;
|
|
33
|
+
field: string;
|
|
34
|
+
operator: ComparisonOperator;
|
|
35
|
+
value: string | number | boolean | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface QueryGroup {
|
|
39
|
+
id: string;
|
|
40
|
+
operator: LogicalOperator;
|
|
41
|
+
rules: Array<QueryRule | QueryGroup>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface QueryBuilderProps {
|
|
45
|
+
fields: QueryField[];
|
|
46
|
+
initialValue?: QueryGroup | undefined;
|
|
47
|
+
maxDepth?: number | undefined;
|
|
48
|
+
readOnly?: boolean | undefined;
|
|
49
|
+
onchange?: ((value: QueryGroup) => void) | undefined;
|
|
50
|
+
class?: string | undefined;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let {
|
|
54
|
+
fields = [],
|
|
55
|
+
initialValue,
|
|
56
|
+
maxDepth = 3,
|
|
57
|
+
readOnly = false,
|
|
58
|
+
onchange,
|
|
59
|
+
class: className = '',
|
|
60
|
+
}: QueryBuilderProps = $props();
|
|
61
|
+
|
|
62
|
+
function makeId(): string {
|
|
63
|
+
return Math.random().toString(36).substring(2, 9);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function defaultRule(): QueryRule {
|
|
67
|
+
const defaultField = fields[0]?.key ?? 'id';
|
|
68
|
+
return {
|
|
69
|
+
id: makeId(),
|
|
70
|
+
field: defaultField,
|
|
71
|
+
operator: 'equals',
|
|
72
|
+
value: '',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function defaultGroup(op: LogicalOperator = 'AND'): QueryGroup {
|
|
77
|
+
return {
|
|
78
|
+
id: makeId(),
|
|
79
|
+
operator: op,
|
|
80
|
+
rules: [defaultRule()],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let rootGroup = $state<QueryGroup>(untrack(() => initialValue ?? defaultGroup('AND')));
|
|
85
|
+
let showSqlPreview = $state(false);
|
|
86
|
+
|
|
87
|
+
function isGroup(item: QueryRule | QueryGroup): item is QueryGroup {
|
|
88
|
+
return 'operator' in item && Array.isArray((item as QueryGroup).rules);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getOperatorsForType(type: QueryField['type']): Array<{ label: string; value: ComparisonOperator }> {
|
|
92
|
+
switch (type) {
|
|
93
|
+
case 'number':
|
|
94
|
+
return [
|
|
95
|
+
{ label: '等于 (=)', value: 'equals' },
|
|
96
|
+
{ label: '不等于 (!=)', value: 'not_equals' },
|
|
97
|
+
{ label: '大于 (>)', value: 'gt' },
|
|
98
|
+
{ label: '大于等于 (>=)', value: 'gte' },
|
|
99
|
+
{ label: '小于 (<)', value: 'lt' },
|
|
100
|
+
{ label: '小于等于 (<=)', value: 'lte' },
|
|
101
|
+
{ label: '为空 (IS NULL)', value: 'is_null' },
|
|
102
|
+
{ label: '非空 (IS NOT NULL)', value: 'is_not_null' },
|
|
103
|
+
];
|
|
104
|
+
case 'date':
|
|
105
|
+
return [
|
|
106
|
+
{ label: '等于', value: 'equals' },
|
|
107
|
+
{ label: '早于 (<)', value: 'lt' },
|
|
108
|
+
{ label: '晚于 (>)', value: 'gt' },
|
|
109
|
+
{ label: '为空', value: 'is_null' },
|
|
110
|
+
{ label: '非空', value: 'is_not_null' },
|
|
111
|
+
];
|
|
112
|
+
case 'select':
|
|
113
|
+
case 'boolean':
|
|
114
|
+
return [
|
|
115
|
+
{ label: '等于', value: 'equals' },
|
|
116
|
+
{ label: '不等于', value: 'not_equals' },
|
|
117
|
+
{ label: '为空', value: 'is_null' },
|
|
118
|
+
{ label: '非空', value: 'is_not_null' },
|
|
119
|
+
];
|
|
120
|
+
case 'text':
|
|
121
|
+
default:
|
|
122
|
+
return [
|
|
123
|
+
{ label: '包含', value: 'contains' },
|
|
124
|
+
{ label: '等于', value: 'equals' },
|
|
125
|
+
{ label: '不等于', value: 'not_equals' },
|
|
126
|
+
{ label: '不包含', value: 'not_contains' },
|
|
127
|
+
{ label: '开头为', value: 'starts_with' },
|
|
128
|
+
{ label: '结尾为', value: 'ends_with' },
|
|
129
|
+
{ label: '为空', value: 'is_null' },
|
|
130
|
+
{ label: '非空', value: 'is_not_null' },
|
|
131
|
+
];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function addRuleToGroup(group: QueryGroup) {
|
|
136
|
+
if (readOnly) return;
|
|
137
|
+
group.rules = [...group.rules, defaultRule()];
|
|
138
|
+
notifyChange();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function addSubGroup(group: QueryGroup, depth: number) {
|
|
142
|
+
if (readOnly || depth >= maxDepth) return;
|
|
143
|
+
group.rules = [...group.rules, defaultGroup(group.operator === 'AND' ? 'OR' : 'AND')];
|
|
144
|
+
notifyChange();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function removeRule(parentGroup: QueryGroup, ruleId: string) {
|
|
148
|
+
if (readOnly) return;
|
|
149
|
+
parentGroup.rules = parentGroup.rules.filter((r) => r.id !== ruleId);
|
|
150
|
+
if (parentGroup.rules.length === 0) {
|
|
151
|
+
parentGroup.rules = [defaultRule()];
|
|
152
|
+
}
|
|
153
|
+
notifyChange();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function resetAll() {
|
|
157
|
+
if (readOnly) return;
|
|
158
|
+
rootGroup = defaultGroup('AND');
|
|
159
|
+
notifyChange();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function notifyChange() {
|
|
163
|
+
onchange?.($state.snapshot(rootGroup));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function serializeToSql(group: QueryGroup): string {
|
|
167
|
+
const parts: string[] = [];
|
|
168
|
+
for (const rule of group.rules) {
|
|
169
|
+
if (isGroup(rule)) {
|
|
170
|
+
const sub = serializeToSql(rule);
|
|
171
|
+
if (sub) parts.push(`(${sub})`);
|
|
172
|
+
} else {
|
|
173
|
+
const val = typeof rule.value === 'string' ? `'${rule.value}'` : String(rule.value ?? '');
|
|
174
|
+
switch (rule.operator) {
|
|
175
|
+
case 'equals':
|
|
176
|
+
parts.push(`${rule.field} = ${val}`);
|
|
177
|
+
break;
|
|
178
|
+
case 'not_equals':
|
|
179
|
+
parts.push(`${rule.field} != ${val}`);
|
|
180
|
+
break;
|
|
181
|
+
case 'contains':
|
|
182
|
+
parts.push(`${rule.field} LIKE '%${rule.value}%'`);
|
|
183
|
+
break;
|
|
184
|
+
case 'starts_with':
|
|
185
|
+
parts.push(`${rule.field} LIKE '${rule.value}%'`);
|
|
186
|
+
break;
|
|
187
|
+
case 'ends_with':
|
|
188
|
+
parts.push(`${rule.field} LIKE '%${rule.value}'`);
|
|
189
|
+
break;
|
|
190
|
+
case 'gt':
|
|
191
|
+
parts.push(`${rule.field} > ${rule.value}`);
|
|
192
|
+
break;
|
|
193
|
+
case 'gte':
|
|
194
|
+
parts.push(`${rule.field} >= ${rule.value}`);
|
|
195
|
+
break;
|
|
196
|
+
case 'lt':
|
|
197
|
+
parts.push(`${rule.field} < ${rule.value}`);
|
|
198
|
+
break;
|
|
199
|
+
case 'lte':
|
|
200
|
+
parts.push(`${rule.field} <= ${rule.value}`);
|
|
201
|
+
break;
|
|
202
|
+
case 'is_null':
|
|
203
|
+
parts.push(`${rule.field} IS NULL`);
|
|
204
|
+
break;
|
|
205
|
+
case 'is_not_null':
|
|
206
|
+
parts.push(`${rule.field} IS NOT NULL`);
|
|
207
|
+
break;
|
|
208
|
+
default:
|
|
209
|
+
parts.push(`${rule.field} = ${val}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return parts.join(` ${group.operator} `);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const generatedSql = $derived(serializeToSql(rootGroup) || '1 = 1');
|
|
217
|
+
</script>
|
|
218
|
+
|
|
219
|
+
<div
|
|
220
|
+
class={cn('rounded-md border border-border bg-card p-4 text-card-foreground shadow-xs', className)}
|
|
221
|
+
data-svadmin-component="QueryBuilder"
|
|
222
|
+
>
|
|
223
|
+
<!-- Top Toolbar -->
|
|
224
|
+
<div class="flex items-center justify-between border-b border-border pb-3 mb-4 text-xs">
|
|
225
|
+
<div class="flex items-center gap-2">
|
|
226
|
+
<Database class="h-4 w-4 text-primary" />
|
|
227
|
+
<span class="font-bold text-foreground">高级多维查询构建器</span>
|
|
228
|
+
</div>
|
|
229
|
+
|
|
230
|
+
<div class="flex items-center gap-2">
|
|
231
|
+
<button
|
|
232
|
+
type="button"
|
|
233
|
+
class={cn(
|
|
234
|
+
'inline-flex items-center gap-1 rounded border px-2.5 py-1 transition-colors cursor-pointer',
|
|
235
|
+
showSqlPreview
|
|
236
|
+
? 'border-primary/40 bg-primary/10 text-primary'
|
|
237
|
+
: 'border-border bg-background text-muted-foreground hover:text-foreground'
|
|
238
|
+
)}
|
|
239
|
+
onclick={() => (showSqlPreview = !showSqlPreview)}
|
|
240
|
+
>
|
|
241
|
+
<Code2 class="h-3.5 w-3.5" />
|
|
242
|
+
<span>{showSqlPreview ? '隐藏 SQL' : '预览 SQL'}</span>
|
|
243
|
+
</button>
|
|
244
|
+
|
|
245
|
+
{#if !readOnly}
|
|
246
|
+
<button
|
|
247
|
+
type="button"
|
|
248
|
+
class="inline-flex items-center gap-1 rounded border border-border bg-background px-2.5 py-1 text-muted-foreground hover:text-foreground transition-colors cursor-pointer"
|
|
249
|
+
onclick={resetAll}
|
|
250
|
+
>
|
|
251
|
+
<RotateCcw class="h-3.5 w-3.5" />
|
|
252
|
+
<span>重置条件</span>
|
|
253
|
+
</button>
|
|
254
|
+
{/if}
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{#if showSqlPreview}
|
|
259
|
+
<div class="mb-4 rounded-md border border-border bg-muted/40 p-2.5 font-mono text-xs text-foreground">
|
|
260
|
+
<span class="text-muted-foreground select-none">WHERE </span>
|
|
261
|
+
<span class="text-primary font-medium">{generatedSql}</span>
|
|
262
|
+
</div>
|
|
263
|
+
{/if}
|
|
264
|
+
|
|
265
|
+
<!-- Recursive Query Tree (Root Group) -->
|
|
266
|
+
{#snippet renderGroup(group: QueryGroup, depth: number, parentGroup: QueryGroup | null)}
|
|
267
|
+
<div
|
|
268
|
+
class={cn(
|
|
269
|
+
'rounded-lg border p-3 space-y-3 transition-colors',
|
|
270
|
+
depth === 0 ? 'border-border bg-muted/20' : 'border-primary/20 bg-primary/5 ml-4'
|
|
271
|
+
)}
|
|
272
|
+
data-query-group={group.id}
|
|
273
|
+
>
|
|
274
|
+
<!-- Group Header with Logical Operator Toggle & Action Buttons -->
|
|
275
|
+
<div class="flex items-center justify-between gap-2">
|
|
276
|
+
<div class="flex items-center gap-2">
|
|
277
|
+
<div class="inline-flex rounded border border-border bg-background p-0.5 text-xs font-semibold">
|
|
278
|
+
<button
|
|
279
|
+
type="button"
|
|
280
|
+
class={cn(
|
|
281
|
+
'rounded px-2.5 py-0.5 transition-colors cursor-pointer',
|
|
282
|
+
group.operator === 'AND'
|
|
283
|
+
? 'bg-primary text-primary-foreground'
|
|
284
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
285
|
+
)}
|
|
286
|
+
onclick={() => {
|
|
287
|
+
if (readOnly) return;
|
|
288
|
+
group.operator = 'AND';
|
|
289
|
+
notifyChange();
|
|
290
|
+
}}
|
|
291
|
+
disabled={readOnly}
|
|
292
|
+
>
|
|
293
|
+
并且 (AND)
|
|
294
|
+
</button>
|
|
295
|
+
<button
|
|
296
|
+
type="button"
|
|
297
|
+
class={cn(
|
|
298
|
+
'rounded px-2.5 py-0.5 transition-colors cursor-pointer',
|
|
299
|
+
group.operator === 'OR'
|
|
300
|
+
? 'bg-primary text-primary-foreground'
|
|
301
|
+
: 'text-muted-foreground hover:text-foreground'
|
|
302
|
+
)}
|
|
303
|
+
onclick={() => {
|
|
304
|
+
if (readOnly) return;
|
|
305
|
+
group.operator = 'OR';
|
|
306
|
+
notifyChange();
|
|
307
|
+
}}
|
|
308
|
+
disabled={readOnly}
|
|
309
|
+
>
|
|
310
|
+
或者 (OR)
|
|
311
|
+
</button>
|
|
312
|
+
</div>
|
|
313
|
+
<span class="text-[11px] text-muted-foreground">符合以下所有条件</span>
|
|
314
|
+
</div>
|
|
315
|
+
|
|
316
|
+
{#if !readOnly}
|
|
317
|
+
<div class="flex items-center gap-1.5">
|
|
318
|
+
<button
|
|
319
|
+
type="button"
|
|
320
|
+
class="inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground hover:bg-muted transition-colors cursor-pointer"
|
|
321
|
+
onclick={() => addRuleToGroup(group)}
|
|
322
|
+
>
|
|
323
|
+
<Plus class="h-3 w-3 text-primary" />
|
|
324
|
+
<span>添加规则</span>
|
|
325
|
+
</button>
|
|
326
|
+
|
|
327
|
+
{#if depth < maxDepth}
|
|
328
|
+
<button
|
|
329
|
+
type="button"
|
|
330
|
+
class="inline-flex items-center gap-1 rounded border border-border bg-background px-2 py-1 text-xs text-foreground hover:bg-muted transition-colors cursor-pointer"
|
|
331
|
+
onclick={() => addSubGroup(group, depth + 1)}
|
|
332
|
+
>
|
|
333
|
+
<FolderPlus class="h-3 w-3 text-warning" />
|
|
334
|
+
<span>添加嵌套组</span>
|
|
335
|
+
</button>
|
|
336
|
+
{/if}
|
|
337
|
+
|
|
338
|
+
{#if parentGroup}
|
|
339
|
+
<button
|
|
340
|
+
type="button"
|
|
341
|
+
class="rounded p-1 text-destructive hover:bg-destructive/10 transition-colors cursor-pointer"
|
|
342
|
+
onclick={() => removeRule(parentGroup, group.id)}
|
|
343
|
+
aria-label="Delete group"
|
|
344
|
+
>
|
|
345
|
+
<Trash2 class="h-3.5 w-3.5" />
|
|
346
|
+
</button>
|
|
347
|
+
{/if}
|
|
348
|
+
</div>
|
|
349
|
+
{/if}
|
|
350
|
+
</div>
|
|
351
|
+
|
|
352
|
+
<!-- Group Rules / Subgroups -->
|
|
353
|
+
<div class="space-y-2 pl-2 border-l-2 border-border/80">
|
|
354
|
+
{#each group.rules as item (item.id)}
|
|
355
|
+
{#if isGroup(item)}
|
|
356
|
+
{@render renderGroup(item, depth + 1, group)}
|
|
357
|
+
{:else}
|
|
358
|
+
{@const fieldDef = fields.find((f) => f.key === item.field)}
|
|
359
|
+
{@const allowedOps = getOperatorsForType(fieldDef?.type ?? 'text')}
|
|
360
|
+
<div
|
|
361
|
+
class="flex flex-wrap items-center gap-2 rounded border border-border/60 bg-card p-2 text-xs"
|
|
362
|
+
data-query-rule={item.id}
|
|
363
|
+
>
|
|
364
|
+
<!-- Field Picker -->
|
|
365
|
+
<select data-size="compact"
|
|
366
|
+
class="svadmin-select svadmin-select--inline"
|
|
367
|
+
bind:value={item.field}
|
|
368
|
+
onchange={() => {
|
|
369
|
+
const newField = fields.find((f) => f.key === item.field);
|
|
370
|
+
item.operator = getOperatorsForType(newField?.type ?? 'text')[0]?.value ?? 'equals';
|
|
371
|
+
item.value = '';
|
|
372
|
+
notifyChange();
|
|
373
|
+
}}
|
|
374
|
+
disabled={readOnly}
|
|
375
|
+
>
|
|
376
|
+
{#each fields as field (field.key)}
|
|
377
|
+
<option value={field.key}>{field.label}</option>
|
|
378
|
+
{/each}
|
|
379
|
+
</select>
|
|
380
|
+
|
|
381
|
+
<!-- Operator Picker -->
|
|
382
|
+
<select data-size="compact"
|
|
383
|
+
class="svadmin-select svadmin-select--inline font-mono"
|
|
384
|
+
bind:value={item.operator}
|
|
385
|
+
onchange={notifyChange}
|
|
386
|
+
disabled={readOnly}
|
|
387
|
+
>
|
|
388
|
+
{#each allowedOps as op (op.value)}
|
|
389
|
+
<option value={op.value}>{op.label}</option>
|
|
390
|
+
{/each}
|
|
391
|
+
</select>
|
|
392
|
+
|
|
393
|
+
<!-- Value Input (depending on operator / field type) -->
|
|
394
|
+
{#if item.operator !== 'is_null' && item.operator !== 'is_not_null'}
|
|
395
|
+
{#if fieldDef?.type === 'select' && fieldDef.options}
|
|
396
|
+
<select data-size="compact"
|
|
397
|
+
class="svadmin-select min-w-[120px]"
|
|
398
|
+
bind:value={item.value}
|
|
399
|
+
onchange={notifyChange}
|
|
400
|
+
disabled={readOnly}
|
|
401
|
+
>
|
|
402
|
+
<option value="">请选择选项</option>
|
|
403
|
+
{#each fieldDef.options as opt (opt.value)}
|
|
404
|
+
<option value={opt.value}>{opt.label}</option>
|
|
405
|
+
{/each}
|
|
406
|
+
</select>
|
|
407
|
+
{:else if fieldDef?.type === 'number'}
|
|
408
|
+
<input
|
|
409
|
+
type="number"
|
|
410
|
+
class="rounded border border-input bg-background px-2.5 py-1 text-xs text-foreground focus:ring-1 focus:ring-primary w-28 font-mono"
|
|
411
|
+
bind:value={item.value}
|
|
412
|
+
oninput={notifyChange}
|
|
413
|
+
placeholder="输入数值"
|
|
414
|
+
disabled={readOnly}
|
|
415
|
+
/>
|
|
416
|
+
{:else if fieldDef?.type === 'date'}
|
|
417
|
+
<input
|
|
418
|
+
type="date"
|
|
419
|
+
class="rounded border border-input bg-background px-2.5 py-1 text-xs text-foreground focus:ring-1 focus:ring-primary w-36 font-mono"
|
|
420
|
+
bind:value={item.value}
|
|
421
|
+
onchange={notifyChange}
|
|
422
|
+
disabled={readOnly}
|
|
423
|
+
/>
|
|
424
|
+
{:else}
|
|
425
|
+
<input
|
|
426
|
+
type="text"
|
|
427
|
+
class="rounded border border-input bg-background px-2.5 py-1 text-xs text-foreground focus:ring-1 focus:ring-primary min-w-[160px] flex-1"
|
|
428
|
+
bind:value={item.value}
|
|
429
|
+
oninput={notifyChange}
|
|
430
|
+
placeholder="输入匹配内容..."
|
|
431
|
+
disabled={readOnly}
|
|
432
|
+
/>
|
|
433
|
+
{/if}
|
|
434
|
+
{:else}
|
|
435
|
+
<span class="text-xs font-mono text-muted-foreground italic px-2">无须传值</span>
|
|
436
|
+
{/if}
|
|
437
|
+
|
|
438
|
+
{#if !readOnly}
|
|
439
|
+
<button
|
|
440
|
+
type="button"
|
|
441
|
+
class="rounded p-1 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors ml-auto cursor-pointer"
|
|
442
|
+
onclick={() => removeRule(group, item.id)}
|
|
443
|
+
aria-label="Delete rule"
|
|
444
|
+
>
|
|
445
|
+
<Trash2 class="h-3.5 w-3.5" />
|
|
446
|
+
</button>
|
|
447
|
+
{/if}
|
|
448
|
+
</div>
|
|
449
|
+
{/if}
|
|
450
|
+
{/each}
|
|
451
|
+
</div>
|
|
452
|
+
</div>
|
|
453
|
+
{/snippet}
|
|
454
|
+
|
|
455
|
+
{@render renderGroup(rootGroup, 0, null)}
|
|
456
|
+
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type LogicalOperator = 'AND' | 'OR';
|
|
2
|
+
export type ComparisonOperator = 'equals' | 'not_equals' | 'contains' | 'not_contains' | 'starts_with' | 'ends_with' | 'gt' | 'gte' | 'lt' | 'lte' | 'in' | 'not_in' | 'between' | 'is_null' | 'is_not_null';
|
|
3
|
+
export interface QueryField {
|
|
4
|
+
key: string;
|
|
5
|
+
label: string;
|
|
6
|
+
type: 'text' | 'number' | 'select' | 'date' | 'boolean';
|
|
7
|
+
options?: Array<{
|
|
8
|
+
label: string;
|
|
9
|
+
value: string | number;
|
|
10
|
+
}> | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface QueryRule {
|
|
13
|
+
id: string;
|
|
14
|
+
field: string;
|
|
15
|
+
operator: ComparisonOperator;
|
|
16
|
+
value: string | number | boolean | null;
|
|
17
|
+
}
|
|
18
|
+
export interface QueryGroup {
|
|
19
|
+
id: string;
|
|
20
|
+
operator: LogicalOperator;
|
|
21
|
+
rules: Array<QueryRule | QueryGroup>;
|
|
22
|
+
}
|
|
23
|
+
export interface QueryBuilderProps {
|
|
24
|
+
fields: QueryField[];
|
|
25
|
+
initialValue?: QueryGroup | undefined;
|
|
26
|
+
maxDepth?: number | undefined;
|
|
27
|
+
readOnly?: boolean | undefined;
|
|
28
|
+
onchange?: ((value: QueryGroup) => void) | undefined;
|
|
29
|
+
class?: string | undefined;
|
|
30
|
+
}
|
|
31
|
+
declare const QueryBuilder: import("svelte").Component<QueryBuilderProps, {}, "">;
|
|
32
|
+
type QueryBuilder = ReturnType<typeof QueryBuilder>;
|
|
33
|
+
export default QueryBuilder;
|
|
@@ -30,13 +30,16 @@
|
|
|
30
30
|
onchange,
|
|
31
31
|
}: Props = $props();
|
|
32
32
|
|
|
33
|
+
let hoverValue = $state<number | null>(null);
|
|
33
34
|
const normalizedCount = $derived(Number.isSafeInteger(count) && count > 0 && count <= 10 ? count : 5);
|
|
34
35
|
const normalizedValue = $derived(Math.min(normalizedCount, Math.max(0, Math.round(value))));
|
|
36
|
+
const displayValue = $derived(hoverValue !== null ? hoverValue : normalizedValue);
|
|
35
37
|
|
|
36
38
|
function choose(next: number): void {
|
|
37
39
|
if (disabled) return;
|
|
38
40
|
const selected = allowClear && normalizedValue === next ? 0 : next;
|
|
39
41
|
value = selected;
|
|
42
|
+
hoverValue = null;
|
|
40
43
|
onchange?.(selected);
|
|
41
44
|
}
|
|
42
45
|
|
|
@@ -61,14 +64,17 @@
|
|
|
61
64
|
<div
|
|
62
65
|
class={cn('svadmin-rate', className)}
|
|
63
66
|
role="radiogroup"
|
|
67
|
+
tabindex={-1}
|
|
64
68
|
aria-label={ariaLabel}
|
|
65
69
|
aria-invalid={invalid || undefined}
|
|
66
70
|
aria-describedby={describedby}
|
|
67
71
|
data-invalid={invalid ? 'true' : undefined}
|
|
72
|
+
onmouseleave={() => { if (!disabled) hoverValue = null; }}
|
|
68
73
|
>
|
|
69
74
|
{#if name}<input type="hidden" {name} value={normalizedValue} required={required} {disabled} />{/if}
|
|
70
75
|
{#each Array(normalizedCount) as _, index (index)}
|
|
71
76
|
{@const rating = index + 1}
|
|
77
|
+
{@const isFilled = displayValue >= rating}
|
|
72
78
|
<button
|
|
73
79
|
type="button"
|
|
74
80
|
role="radio"
|
|
@@ -77,10 +83,12 @@
|
|
|
77
83
|
aria-disabled={disabled ? 'true' : undefined}
|
|
78
84
|
tabindex={disabled ? -1 : normalizedValue === rating || (normalizedValue === 0 && index === 0) ? 0 : -1}
|
|
79
85
|
disabled={disabled}
|
|
86
|
+
class:svadmin-rate__button--filled={isFilled}
|
|
87
|
+
onmouseenter={() => { if (!disabled) hoverValue = rating; }}
|
|
80
88
|
onclick={() => choose(rating)}
|
|
81
89
|
onkeydown={(event) => handleKeydown(event, index)}
|
|
82
90
|
>
|
|
83
|
-
<Star fill={
|
|
91
|
+
<Star fill={isFilled ? 'currentColor' : 'none'} aria-hidden="true" />
|
|
84
92
|
</button>
|
|
85
93
|
{/each}
|
|
86
94
|
</div>
|
|
@@ -105,7 +113,16 @@
|
|
|
105
113
|
cursor: pointer;
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
.svadmin-rate button
|
|
116
|
+
.svadmin-rate button {
|
|
117
|
+
transition: transform var(--svadmin-motion-fast) var(--svadmin-motion-easing), color var(--svadmin-motion-fast) var(--svadmin-motion-easing);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.svadmin-rate button:hover:not(:disabled) {
|
|
121
|
+
transform: scale(1.15);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.svadmin-rate button[aria-checked='true'],
|
|
125
|
+
.svadmin-rate button.svadmin-rate__button--filled {
|
|
109
126
|
color: var(--warning);
|
|
110
127
|
}
|
|
111
128
|
|
|
@@ -1,20 +1,52 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Snippet } from
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import {
|
|
4
|
+
CheckCircle2,
|
|
5
|
+
XCircle,
|
|
6
|
+
AlertTriangle,
|
|
7
|
+
Info,
|
|
8
|
+
ShieldAlert,
|
|
9
|
+
FileQuestion,
|
|
10
|
+
ServerCrash,
|
|
11
|
+
} from "@lucide/svelte";
|
|
12
|
+
|
|
13
|
+
export type ResultStatus = "success" | "error" | "info" | "warning" | "403" | "404" | "500";
|
|
3
14
|
|
|
4
15
|
let {
|
|
5
|
-
status =
|
|
16
|
+
status = "info",
|
|
6
17
|
title,
|
|
7
|
-
subtitle =
|
|
18
|
+
subtitle = "",
|
|
19
|
+
icon,
|
|
8
20
|
children,
|
|
9
21
|
}: {
|
|
10
|
-
status?:
|
|
22
|
+
status?: ResultStatus;
|
|
11
23
|
title: string;
|
|
12
24
|
subtitle?: string;
|
|
25
|
+
icon?: Snippet;
|
|
13
26
|
children?: Snippet;
|
|
14
27
|
} = $props();
|
|
28
|
+
|
|
29
|
+
const statusIcons = {
|
|
30
|
+
success: CheckCircle2,
|
|
31
|
+
error: XCircle,
|
|
32
|
+
info: Info,
|
|
33
|
+
warning: AlertTriangle,
|
|
34
|
+
"403": ShieldAlert,
|
|
35
|
+
"404": FileQuestion,
|
|
36
|
+
"500": ServerCrash,
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
const IconComp = $derived(statusIcons[status] ?? Info);
|
|
15
40
|
</script>
|
|
16
41
|
|
|
17
42
|
<section class="svadmin-result" data-status={status}>
|
|
43
|
+
<div class="svadmin-result__icon" aria-hidden="true">
|
|
44
|
+
{#if icon}
|
|
45
|
+
{@render icon()}
|
|
46
|
+
{:else}
|
|
47
|
+
<IconComp class="size-12" />
|
|
48
|
+
{/if}
|
|
49
|
+
</div>
|
|
18
50
|
<p class="svadmin-result__status">{status}</p>
|
|
19
51
|
<h2 class="svadmin-result__title">{title}</h2>
|
|
20
52
|
{#if subtitle}<p class="svadmin-result__subtitle">{subtitle}</p>{/if}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { Snippet } from
|
|
1
|
+
import type { Snippet } from "svelte";
|
|
2
|
+
export type ResultStatus = "success" | "error" | "info" | "warning" | "403" | "404" | "500";
|
|
2
3
|
type $$ComponentProps = {
|
|
3
|
-
status?:
|
|
4
|
+
status?: ResultStatus;
|
|
4
5
|
title: string;
|
|
5
6
|
subtitle?: string;
|
|
7
|
+
icon?: Snippet;
|
|
6
8
|
children?: Snippet;
|
|
7
9
|
};
|
|
8
10
|
declare const Result: import("svelte").Component<$$ComponentProps, {}, "">;
|