@ithinkdt/ui 4.0.0-10 → 4.0.0-11
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/package.json +4 -7
- package/src/components/Checkboxes.jsx +128 -0
- package/src/components/DataActions.jsx +107 -0
- package/src/components/DataCustom.jsx +172 -0
- package/src/components/DataFilter.jsx +113 -0
- package/src/components/DataForm.jsx +264 -0
- package/src/components/DataLocaleInput.jsx +121 -0
- package/src/components/DataPagination.jsx +62 -0
- package/src/components/DataSelection.jsx +57 -0
- package/src/components/DataTable.jsx +243 -0
- package/src/components/Radios.jsx +120 -0
- package/src/components/UserDept.jsx +643 -0
- package/src/components/assets.jsx +274 -0
- package/src/components/index.js +11 -0
- package/src/design/Account.jsx +152 -0
- package/src/design/Appearance.jsx +89 -0
- package/src/design/Breadcrumb.jsx +67 -0
- package/src/design/Fullscreen.jsx +65 -0
- package/src/design/Language.jsx +45 -0
- package/src/design/Layout.jsx +241 -0
- package/src/design/Logo.jsx +91 -0
- package/src/design/Menu.jsx +133 -0
- package/src/design/MultiTabs.jsx +501 -0
- package/src/design/Notification.jsx +322 -0
- package/src/design/common.jsx +19 -0
- package/src/design/index.js +10 -0
- package/src/directives/index.js +2 -0
- package/src/directives/spin.js +181 -0
- package/src/directives/tooltip.jsx +121 -0
- package/src/index.js +18 -1361
- package/src/page.jsx +626 -0
- package/src/use-i18n.js +8 -0
- package/src/use-style.js +58 -0
- package/src/utils.js +20 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { toReactive, unrefElement, until } from '@vueuse/core'
|
|
2
|
+
import { NButton, NDataTable, NFlex, NIcon, NTooltip } from 'ithinkdt-ui'
|
|
3
|
+
import { Sortable } from 'sortablejs'
|
|
4
|
+
import { computed, defineComponent, inject, mergeProps, nextTick, ref, shallowRef, toValue, useTemplateRef, watch, withDirectives } from 'vue'
|
|
5
|
+
|
|
6
|
+
import { PAGE_INJECTION } from '@ithinkdt/page'
|
|
7
|
+
|
|
8
|
+
import { vTooltip } from '../directives/index.js'
|
|
9
|
+
import { useClsPrefix } from '../use-style.js'
|
|
10
|
+
|
|
11
|
+
import { IHelp } from './assets.jsx'
|
|
12
|
+
|
|
13
|
+
function _map(columns, width) {
|
|
14
|
+
return (columns ?? [])
|
|
15
|
+
.map((col) => {
|
|
16
|
+
const column = {
|
|
17
|
+
csvTitle: col.exportTitle,
|
|
18
|
+
...col,
|
|
19
|
+
title: () => {
|
|
20
|
+
const title0 = toValue(col.title)
|
|
21
|
+
const title = title0
|
|
22
|
+
? withDirectives(<span>{title0}</span>, [[vTooltip, () => toValue(col.title), undefined, { auto: true }]])
|
|
23
|
+
: title0
|
|
24
|
+
if (!col.tooltip) return title
|
|
25
|
+
return (
|
|
26
|
+
<NFlex size={3} wrap={false} inline style="max-width: 100%">
|
|
27
|
+
{title}
|
|
28
|
+
|
|
29
|
+
<NTooltip>
|
|
30
|
+
{{
|
|
31
|
+
default: toValue(col.tooltip),
|
|
32
|
+
trigger: () => (
|
|
33
|
+
<NButton text style="font-size: 1.25em; opacity: 0.8">
|
|
34
|
+
<NIcon>
|
|
35
|
+
<IHelp />
|
|
36
|
+
</NIcon>
|
|
37
|
+
</NButton>
|
|
38
|
+
),
|
|
39
|
+
}}
|
|
40
|
+
</NTooltip>
|
|
41
|
+
</NFlex>
|
|
42
|
+
)
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (column.children?.length) {
|
|
47
|
+
column.children = _map(column.children, width.value)
|
|
48
|
+
} else {
|
|
49
|
+
if (column.hidden !== true) {
|
|
50
|
+
column.width ??= 100
|
|
51
|
+
width.value += Number(column.width)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const render0 = column.render ?? (v => v)
|
|
55
|
+
if (column.ellipsis !== false) {
|
|
56
|
+
column.ellipsis = mergeProps(
|
|
57
|
+
{
|
|
58
|
+
expandTrigger: 'click',
|
|
59
|
+
lineClamp: 1,
|
|
60
|
+
tooltip: {
|
|
61
|
+
style: {
|
|
62
|
+
maxWidth: '61.8vw',
|
|
63
|
+
wordBreak: 'break-all',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
typeof column.ellipsis === 'boolean' ? {} : column.ellipsis,
|
|
68
|
+
)
|
|
69
|
+
if (column.ellipsisTooltip === true) {
|
|
70
|
+
column.ellipsisTooltip ??= render0
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Object.assign(column, {
|
|
75
|
+
resizable: column.resizable !== false,
|
|
76
|
+
sorter: column.sortable,
|
|
77
|
+
type: ['selection', 'expand'].includes(column.type) ? column.type : undefined,
|
|
78
|
+
disabled: column.selectable ? model => column.selectable(model) === false : undefined,
|
|
79
|
+
ellipsisComponent: 'performant-ellipsis',
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (column.key === '$actions') {
|
|
84
|
+
column.cellProps ??= () => {
|
|
85
|
+
return { style: { padding: '0 2px' } }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return column
|
|
90
|
+
})
|
|
91
|
+
.filter(it => it?.hidden !== true)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const DataTable = /* @__PURE__ */ defineComponent({
|
|
95
|
+
name: 'DataTable',
|
|
96
|
+
props: {
|
|
97
|
+
data: {
|
|
98
|
+
type: Array,
|
|
99
|
+
default: () => [],
|
|
100
|
+
},
|
|
101
|
+
columns: {
|
|
102
|
+
type: Array,
|
|
103
|
+
default: () => [],
|
|
104
|
+
},
|
|
105
|
+
keyField: {
|
|
106
|
+
type: String,
|
|
107
|
+
},
|
|
108
|
+
sorter: {
|
|
109
|
+
type: Object,
|
|
110
|
+
default: () => ({}),
|
|
111
|
+
},
|
|
112
|
+
selectedKeys: {
|
|
113
|
+
type: Array,
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
emits: {
|
|
117
|
+
sort: () => true,
|
|
118
|
+
select: () => true,
|
|
119
|
+
},
|
|
120
|
+
setup(props, { slots, emit, expose }) {
|
|
121
|
+
const { keyField } = inject(PAGE_INJECTION)
|
|
122
|
+
|
|
123
|
+
const clsPrefix = useClsPrefix()
|
|
124
|
+
const cls = `${clsPrefix.value}-data-table`
|
|
125
|
+
|
|
126
|
+
const tableRef = useTemplateRef('table-ref')
|
|
127
|
+
|
|
128
|
+
const handleSort = ({ sortField, sortOrder } = {}, oSort) => {
|
|
129
|
+
if (sortField == oSort?.sortField && sortOrder == oSort?.sortOrder) return
|
|
130
|
+
tableRef.value?.sort(sortField, sortOrder ? sortOrder + 'end' : false)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
watch(() => ({ ...props.sorter }), handleSort, { deep: true })
|
|
134
|
+
|
|
135
|
+
const rowKey = computed(() => {
|
|
136
|
+
const keyField0 = props.keyField || keyField || 'key'
|
|
137
|
+
return row => row[keyField0]
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const exposed = shallowRef({
|
|
141
|
+
cache: [],
|
|
142
|
+
scrollToView(...params) {
|
|
143
|
+
this.cache.push(params)
|
|
144
|
+
},
|
|
145
|
+
})
|
|
146
|
+
until(tableRef)
|
|
147
|
+
.changed()
|
|
148
|
+
.then(() => {
|
|
149
|
+
handleSort(props.sorter)
|
|
150
|
+
|
|
151
|
+
const cache = exposed.value.cache
|
|
152
|
+
exposed.value = tableRef.value
|
|
153
|
+
exposed.value.scrollToView = (key) => {
|
|
154
|
+
const index = props.data.findIndex(row => rowKey.value(row) === key)
|
|
155
|
+
if (index === -1) return
|
|
156
|
+
const row = tableRef.value.$el.querySelector(`.${cls}-row-marker:nth-child(${index + 1})`)
|
|
157
|
+
tableRef.value.scrollTo({
|
|
158
|
+
top: row.offsetTop,
|
|
159
|
+
behavior: 'smooth',
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
for (const params of cache) exposed.value.scrollToView(...params)
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
expose(toReactive(exposed))
|
|
166
|
+
|
|
167
|
+
const width = ref(0)
|
|
168
|
+
const columns = shallowRef([])
|
|
169
|
+
|
|
170
|
+
watch(() => props.columns, () => {
|
|
171
|
+
width.value = 0
|
|
172
|
+
columns.value = _map(props.columns, width)
|
|
173
|
+
}, { immediate: true, deep: 1 })
|
|
174
|
+
|
|
175
|
+
const rowClassName = computed(() => {
|
|
176
|
+
return (row, i) => {
|
|
177
|
+
const p = props.rowClassName?.(row, i) || ''
|
|
178
|
+
return p + ` ${cls}-row-marker`
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
const onUpdateSorter = (e) => {
|
|
183
|
+
if (props.sorter) {
|
|
184
|
+
const { sortField, sortOrder } = props.sorter
|
|
185
|
+
if (e?.columnKey == sortField && (e?.order ? e.order === sortOrder + 'end' : !sortOrder)) return
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
emit('sort', {
|
|
189
|
+
sortField: e?.order ? e?.columnKey : undefined,
|
|
190
|
+
sortOrder: e?.order ? e.order.replace('end', '') : undefined,
|
|
191
|
+
})
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const onUpdateCheckedRowKeys = (keys) => {
|
|
195
|
+
emit('select', keys)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return () => (
|
|
199
|
+
<NDataTable
|
|
200
|
+
class={cls}
|
|
201
|
+
data={props.data}
|
|
202
|
+
columns={columns.value}
|
|
203
|
+
rowKey={rowKey.value}
|
|
204
|
+
tableLayout="fixed"
|
|
205
|
+
ref="table-ref"
|
|
206
|
+
scrollX={width.value}
|
|
207
|
+
rowClassName={rowClassName.value}
|
|
208
|
+
checkedRowKeys={props.selectedKeys}
|
|
209
|
+
onUpdateSorter={onUpdateSorter}
|
|
210
|
+
onUpdateCheckedRowKeys={onUpdateCheckedRowKeys}
|
|
211
|
+
>
|
|
212
|
+
{slots}
|
|
213
|
+
</NDataTable>
|
|
214
|
+
)
|
|
215
|
+
},
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
export function useDataTableDrag(
|
|
219
|
+
tableRef,
|
|
220
|
+
{ data, onSort, ...options }) {
|
|
221
|
+
watch([ref(data), tableRef], async ([data, inst]) => {
|
|
222
|
+
if (data.length === 0)
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
await nextTick()
|
|
226
|
+
const tableEl = unrefElement(inst)
|
|
227
|
+
const tbodyEl = tableEl?.querySelector('.n-data-table-base-table-body .n-data-table-tbody')
|
|
228
|
+
|
|
229
|
+
if (!tbodyEl) return
|
|
230
|
+
|
|
231
|
+
const sortable = Sortable.create(tbodyEl, {
|
|
232
|
+
animation: 150,
|
|
233
|
+
...options,
|
|
234
|
+
onSort(evt) {
|
|
235
|
+
onSort({ from: evt.oldIndex, to: evt.newIndex })
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
return () => {
|
|
240
|
+
sortable.destroy()
|
|
241
|
+
}
|
|
242
|
+
}, { immediate: true })
|
|
243
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { NFlex, NRadio, NRadioButton, NRadioGroup, NTooltip } from 'ithinkdt-ui'
|
|
2
|
+
import { computed, defineComponent } from 'vue'
|
|
3
|
+
|
|
4
|
+
import { useI18n } from '../use-i18n.js'
|
|
5
|
+
|
|
6
|
+
export const NRadios = defineComponent({
|
|
7
|
+
name: 'Radios',
|
|
8
|
+
props: {
|
|
9
|
+
options: {
|
|
10
|
+
type: Array,
|
|
11
|
+
default: () => [],
|
|
12
|
+
},
|
|
13
|
+
vertical: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
default: false,
|
|
16
|
+
},
|
|
17
|
+
type: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: 'radio',
|
|
20
|
+
},
|
|
21
|
+
default: {
|
|
22
|
+
type: [Boolean, String, Object],
|
|
23
|
+
default: false,
|
|
24
|
+
},
|
|
25
|
+
padding: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: undefined,
|
|
28
|
+
},
|
|
29
|
+
labelField: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: 'label',
|
|
32
|
+
},
|
|
33
|
+
valueField: {
|
|
34
|
+
type: String,
|
|
35
|
+
default: 'value',
|
|
36
|
+
},
|
|
37
|
+
disabledField: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: 'disabled',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
setup(props) {
|
|
44
|
+
const { t } = useI18n()
|
|
45
|
+
|
|
46
|
+
const defaultLabel = computed(() => {
|
|
47
|
+
if (props.default === false) return ''
|
|
48
|
+
if (props.default === true) return t('common.all')
|
|
49
|
+
if (typeof props.default === 'string') return props.default
|
|
50
|
+
return props.default?.[props.labelField] ?? t('common.all')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const groupStyle = computed(() => props.type === 'button-primary'
|
|
54
|
+
? {
|
|
55
|
+
'--n-button-color-active': 'var(--color-primary)',
|
|
56
|
+
'--n-button-text-color-active': 'var(--color-base)',
|
|
57
|
+
}
|
|
58
|
+
: {})
|
|
59
|
+
return () => {
|
|
60
|
+
const Comp = props.type === 'button' ? NRadioButton : NRadio
|
|
61
|
+
|
|
62
|
+
const content = (
|
|
63
|
+
<>
|
|
64
|
+
{props.default
|
|
65
|
+
? (
|
|
66
|
+
|
|
67
|
+
<Comp value={typeof props.default === 'object' ? props.default?.[props.valueField] : null}>
|
|
68
|
+
{defaultLabel.value}
|
|
69
|
+
</Comp>
|
|
70
|
+
)
|
|
71
|
+
: undefined}
|
|
72
|
+
{props.options?.map((op) => {
|
|
73
|
+
const label
|
|
74
|
+
= typeof op[props.labelField] === 'string' ? op[props.labelField] : op[props.labelField]?.()
|
|
75
|
+
return (
|
|
76
|
+
<Comp
|
|
77
|
+
value={op[props.valueField]}
|
|
78
|
+
disabled={op[props.disabledField]}
|
|
79
|
+
style={
|
|
80
|
+
props.padding
|
|
81
|
+
? {
|
|
82
|
+
paddingLeft: props.padding,
|
|
83
|
+
paddingRight: props.padding,
|
|
84
|
+
}
|
|
85
|
+
: {}
|
|
86
|
+
}
|
|
87
|
+
>
|
|
88
|
+
{op.tip
|
|
89
|
+
? (
|
|
90
|
+
<NTooltip>
|
|
91
|
+
{{
|
|
92
|
+
default: () => op.tip,
|
|
93
|
+
trigger: () => label,
|
|
94
|
+
}}
|
|
95
|
+
</NTooltip>
|
|
96
|
+
)
|
|
97
|
+
: (
|
|
98
|
+
label
|
|
99
|
+
)}
|
|
100
|
+
</Comp>
|
|
101
|
+
)
|
|
102
|
+
})}
|
|
103
|
+
</>
|
|
104
|
+
)
|
|
105
|
+
return (
|
|
106
|
+
<NRadioGroup style={props.vertical ? { ...groupStyle.value, padding: '6px 0 0' } : groupStyle.value}>
|
|
107
|
+
{props.type === 'radio'
|
|
108
|
+
? (
|
|
109
|
+
<NFlex size={props.vertical ? undefined : 'small'} vertical={props.vertical}>
|
|
110
|
+
{content}
|
|
111
|
+
</NFlex>
|
|
112
|
+
)
|
|
113
|
+
: (
|
|
114
|
+
content
|
|
115
|
+
)}
|
|
116
|
+
</NRadioGroup>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
})
|