@a2simcode/ui 0.0.186 → 0.0.188
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/components/buttons/src/interface.d.ts +4 -0
- package/dist/components/inject-provide.d.ts +2 -0
- package/dist/components/input/index.d.ts +3 -3
- package/dist/components/input/src/input.vue.d.ts +1 -1
- package/dist/components/input-layer/index.d.ts +3 -3
- package/dist/components/input-layer/src/input-layer.vue.d.ts +1 -1
- package/dist/components/input-map/index.d.ts +3 -3
- package/dist/components/input-map/src/input-map.vue.d.ts +1 -1
- package/dist/components/input-tag/index.d.ts +3 -3
- package/dist/components/input-tag/src/input-tag.vue.d.ts +1 -1
- package/dist/components/time/index.d.ts +3 -3
- package/dist/components/time/src/time.vue.d.ts +1 -1
- package/dist/components/upload/index.d.ts +24 -24
- package/dist/components/upload/src/list.vue.d.ts +1 -1
- package/dist/components/upload/src/upload.vue.d.ts +8 -8
- package/dist/simcode-ui.es.js +3966 -3918
- package/dist/simcode-ui.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/dist/ui.css +1 -1
- package/docs/components/input-layer.md +15 -0
- package/docs/examples/buttons/basic.vue +17 -0
- package/docs/examples/input-layer/render-vnode-page.vue +160 -0
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div style="width: 420px">
|
|
3
|
+
<j-input-layer
|
|
4
|
+
ref="inputLayerRef"
|
|
5
|
+
v-model="value"
|
|
6
|
+
placeholder="请选择用户(卡片渲染 + 分页)"
|
|
7
|
+
:columns="columns"
|
|
8
|
+
:load-layer-data="loadData"
|
|
9
|
+
:width="800"
|
|
10
|
+
:height="500"
|
|
11
|
+
value-key="id"
|
|
12
|
+
label-key="name"
|
|
13
|
+
:is-page="true"
|
|
14
|
+
:is-multi-select="true"
|
|
15
|
+
:render-v-node="renderVNode"
|
|
16
|
+
@change="handleChange"
|
|
17
|
+
/>
|
|
18
|
+
<div style="margin-top: 10px">选中值: {{ value }}</div>
|
|
19
|
+
</div>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { ref, h } from 'vue'
|
|
24
|
+
|
|
25
|
+
type UserRow = {
|
|
26
|
+
id: string
|
|
27
|
+
name: string
|
|
28
|
+
age: number
|
|
29
|
+
email: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const value = ref('')
|
|
33
|
+
const selectedIds = ref<string[]>([])
|
|
34
|
+
const inputLayerRef = ref<any>()
|
|
35
|
+
|
|
36
|
+
const handleChange = (payload: any) => {
|
|
37
|
+
const rows = Array.isArray(payload?.data) ? payload.data : []
|
|
38
|
+
selectedIds.value = rows.map((row: any) => String(row?.id ?? ''))
|
|
39
|
+
console.log(payload, 'data')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const columns = [
|
|
43
|
+
{
|
|
44
|
+
id: 'id',
|
|
45
|
+
config: {
|
|
46
|
+
label: 'ID',
|
|
47
|
+
width: 80,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'name',
|
|
52
|
+
config: {
|
|
53
|
+
label: '姓名',
|
|
54
|
+
width: 120,
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'age',
|
|
59
|
+
config: {
|
|
60
|
+
label: '年龄',
|
|
61
|
+
width: 80,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'email',
|
|
66
|
+
config: {
|
|
67
|
+
label: '邮箱',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
const allUsers: UserRow[] = Array.from({ length: 223 }).map((_, index) => {
|
|
73
|
+
const num = index + 1
|
|
74
|
+
return {
|
|
75
|
+
id: String(num),
|
|
76
|
+
name: `用户${num}`,
|
|
77
|
+
age: 18 + (num % 20),
|
|
78
|
+
email: `user${num}@example.com`,
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
const loadData = async (params: any) => {
|
|
83
|
+
const pageSize = Number(params?.pagination?.rows ?? 10)
|
|
84
|
+
const page = Number(params?.pagination?.page ?? 1)
|
|
85
|
+
const startIndex = Math.max(0, (page - 1) * pageSize)
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
rows: allUsers.slice(startIndex, startIndex + pageSize),
|
|
89
|
+
records: allUsers.length,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const toggleSelection = (row: UserRow, evt: MouseEvent) => {
|
|
94
|
+
evt.stopPropagation()
|
|
95
|
+
|
|
96
|
+
const tablePanelRef = inputLayerRef.value?.getTablePanelRef?.()
|
|
97
|
+
const currentSelection = (tablePanelRef?.getSelection?.() || []) as UserRow[]
|
|
98
|
+
const id = String(row?.id ?? '')
|
|
99
|
+
|
|
100
|
+
const exists = currentSelection.some((r) => String(r?.id ?? '') === id)
|
|
101
|
+
const nextSelection = exists
|
|
102
|
+
? currentSelection.filter((r) => String(r?.id ?? '') !== id)
|
|
103
|
+
: [...currentSelection, row]
|
|
104
|
+
|
|
105
|
+
tablePanelRef?.setSelection?.(nextSelection)
|
|
106
|
+
selectedIds.value = nextSelection.map((r) => String(r?.id ?? ''))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const renderVNode = (row: Record<string, any>) => {
|
|
110
|
+
const id = String(row.id ?? '')
|
|
111
|
+
const isActive = selectedIds.value.includes(id)
|
|
112
|
+
|
|
113
|
+
return h(
|
|
114
|
+
'div',
|
|
115
|
+
{
|
|
116
|
+
class: ['input-layer-card', isActive ? 'is-active' : ''],
|
|
117
|
+
onClick: (evt: MouseEvent) => toggleSelection(row as UserRow, evt),
|
|
118
|
+
},
|
|
119
|
+
[
|
|
120
|
+
h('div', { class: 'input-layer-card__title' }, [h('span', row.name), h('span', row.id)]),
|
|
121
|
+
h('div', { class: 'input-layer-card__meta' }, `年龄:${row.age}`),
|
|
122
|
+
h('div', { class: 'input-layer-card__meta' }, `邮箱:${row.email}`),
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<style scoped>
|
|
129
|
+
.input-layer-card {
|
|
130
|
+
padding: 12px 14px;
|
|
131
|
+
border: 1px solid var(--j-color-border);
|
|
132
|
+
border-radius: 6px;
|
|
133
|
+
background: var(--j-color-bg-container);
|
|
134
|
+
cursor: pointer;
|
|
135
|
+
transition: border-color 0.15s ease;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.input-layer-card + .input-layer-card {
|
|
139
|
+
margin-top: 10px;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.input-layer-card.is-active {
|
|
143
|
+
border-color: var(--j-color-primary);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.input-layer-card__title {
|
|
147
|
+
display: flex;
|
|
148
|
+
justify-content: space-between;
|
|
149
|
+
gap: 10px;
|
|
150
|
+
margin-bottom: 6px;
|
|
151
|
+
color: var(--j-color-text);
|
|
152
|
+
font-weight: 600;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.input-layer-card__meta {
|
|
156
|
+
line-height: 20px;
|
|
157
|
+
font-size: 12px;
|
|
158
|
+
color: var(--j-color-text-2);
|
|
159
|
+
}
|
|
160
|
+
</style>
|