@quiteer/naive-extra 0.0.1

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.
Files changed (171) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -0
  3. package/dist/components/breadcrumb/index.d.ts +0 -0
  4. package/dist/components/breadcrumb/index.vue.d.ts +3 -0
  5. package/dist/components/breadcrumb/props.d.ts +0 -0
  6. package/dist/components/button/action/index.d.ts +3 -0
  7. package/dist/components/button/action/index.vue.d.ts +118 -0
  8. package/dist/components/button/action/props.d.ts +63 -0
  9. package/dist/components/button/action/utils.d.ts +8 -0
  10. package/dist/components/button/base/index.d.ts +3 -0
  11. package/dist/components/button/base/index.vue.d.ts +36 -0
  12. package/dist/components/button/base/props.d.ts +27 -0
  13. package/dist/components/button/index.d.ts +4 -0
  14. package/dist/components/button/types.d.ts +2 -0
  15. package/dist/components/form/helper.d.ts +11 -0
  16. package/dist/components/form/index.d.ts +3 -0
  17. package/dist/components/form/index.vue.d.ts +642 -0
  18. package/dist/components/form/props.d.ts +34 -0
  19. package/dist/components/icon/IconPicker.vue.d.ts +13 -0
  20. package/dist/components/icon/iconify.d.ts +25 -0
  21. package/dist/components/icon/index.d.ts +3 -0
  22. package/dist/components/icon/index.vue.d.ts +12 -0
  23. package/dist/components/layout/const.d.ts +22 -0
  24. package/dist/components/layout/context.d.ts +77 -0
  25. package/dist/components/layout/index.d.ts +5 -0
  26. package/dist/components/layout/index.vue.d.ts +80 -0
  27. package/dist/components/layout/layout-parts/AppBreadcrumb.vue.d.ts +3 -0
  28. package/dist/components/layout/layout-parts/AppFooter.vue.d.ts +18 -0
  29. package/dist/components/layout/layout-parts/AppHeader.vue.d.ts +18 -0
  30. package/dist/components/layout/layout-parts/AppLeftLogoInfo.vue.d.ts +3 -0
  31. package/dist/components/layout/layout-parts/AppMain.vue.d.ts +18 -0
  32. package/dist/components/layout/layout-parts/AppSidebar.vue.d.ts +4067 -0
  33. package/dist/components/layout/layout-parts/LayoutTransition.vue.d.ts +58 -0
  34. package/dist/components/layout/mode.d.ts +0 -0
  35. package/dist/components/layout/props.d.ts +35 -0
  36. package/dist/components/layout/types.d.ts +59 -0
  37. package/dist/components/layout/utils.d.ts +97 -0
  38. package/dist/components/provider/index.d.ts +3 -0
  39. package/dist/components/provider/index.vue.d.ts +19 -0
  40. package/dist/components/provider/props.d.ts +33 -0
  41. package/dist/components/search-bar/index.d.ts +3 -0
  42. package/dist/components/search-bar/index.vue.d.ts +1288 -0
  43. package/dist/components/search-bar/props.d.ts +15 -0
  44. package/dist/components/table/TableSetting.vue.d.ts +15 -0
  45. package/dist/components/table/index.d.ts +4 -0
  46. package/dist/components/table/index.vue.d.ts +17246 -0
  47. package/dist/components/table/props.d.ts +26 -0
  48. package/dist/components/table/useColumn.d.ts +15 -0
  49. package/dist/components/upload/enum.d.ts +18 -0
  50. package/dist/components/upload/index.d.ts +4 -0
  51. package/dist/components/upload/index.vue.d.ts +17 -0
  52. package/dist/components/upload/props.d.ts +7 -0
  53. package/dist/const/defaults.d.ts +7 -0
  54. package/dist/const/index.d.ts +2 -0
  55. package/dist/const/types.d.ts +134 -0
  56. package/dist/context/color.d.ts +13 -0
  57. package/dist/context/common.d.ts +117 -0
  58. package/dist/context/index.d.ts +41 -0
  59. package/dist/context/layout.d.ts +52 -0
  60. package/dist/context/loading-bar.d.ts +14 -0
  61. package/dist/context/locale.d.ts +143 -0
  62. package/dist/context/menu.d.ts +212 -0
  63. package/dist/context/message.d.ts +14 -0
  64. package/dist/context/notification.d.ts +14 -0
  65. package/dist/context/table.d.ts +917 -0
  66. package/dist/context/theme.d.ts +20 -0
  67. package/dist/hooks/index.d.ts +6 -0
  68. package/dist/hooks/useAdmin.d.ts +0 -0
  69. package/dist/hooks/useForm.d.ts +54 -0
  70. package/dist/hooks/useLayout.d.ts +116 -0
  71. package/dist/hooks/useProviderContext.d.ts +17 -0
  72. package/dist/hooks/useTable.d.ts +66 -0
  73. package/dist/hooks/useThemeOverrides.d.ts +8 -0
  74. package/dist/hooks/useUpload.d.ts +22 -0
  75. package/dist/index.css +36 -0
  76. package/dist/index.d.ts +29 -0
  77. package/dist/index.js +6771 -0
  78. package/dist/share/compact.d.ts +16 -0
  79. package/dist/share/index.d.ts +2 -0
  80. package/dist/share/menu.d.ts +0 -0
  81. package/dist/share/route.d.ts +0 -0
  82. package/dist/share/slot.d.ts +6 -0
  83. package/dist/utils/form.d.ts +0 -0
  84. package/dist/utils/index.d.ts +0 -0
  85. package/dist/utils/transformRoutes.d.ts +67 -0
  86. package/dist/utils/tree.d.ts +6 -0
  87. package/package.json +53 -0
  88. package/src/auto-imports.d.ts +73 -0
  89. package/src/components/breadcrumb/index.ts +0 -0
  90. package/src/components/breadcrumb/index.vue +0 -0
  91. package/src/components/breadcrumb/props.ts +0 -0
  92. package/src/components/button/action/index.ts +4 -0
  93. package/src/components/button/action/index.vue +313 -0
  94. package/src/components/button/action/props.ts +78 -0
  95. package/src/components/button/action/utils.ts +122 -0
  96. package/src/components/button/base/index.ts +4 -0
  97. package/src/components/button/base/index.vue +156 -0
  98. package/src/components/button/base/props.ts +29 -0
  99. package/src/components/button/index.ts +4 -0
  100. package/src/components/button/types.ts +2 -0
  101. package/src/components/form/helper.ts +73 -0
  102. package/src/components/form/index.ts +5 -0
  103. package/src/components/form/index.vue +243 -0
  104. package/src/components/form/props.ts +75 -0
  105. package/src/components/icon/IconPicker.vue +255 -0
  106. package/src/components/icon/iconify.ts +80 -0
  107. package/src/components/icon/index.ts +7 -0
  108. package/src/components/icon/index.vue +23 -0
  109. package/src/components/layout/const.ts +102 -0
  110. package/src/components/layout/context.ts +189 -0
  111. package/src/components/layout/index.ts +8 -0
  112. package/src/components/layout/index.vue +64 -0
  113. package/src/components/layout/layout-parts/AppBreadcrumb.vue +108 -0
  114. package/src/components/layout/layout-parts/AppFooter.vue +26 -0
  115. package/src/components/layout/layout-parts/AppHeader.vue +112 -0
  116. package/src/components/layout/layout-parts/AppLeftLogoInfo.vue +30 -0
  117. package/src/components/layout/layout-parts/AppMain.vue +34 -0
  118. package/src/components/layout/layout-parts/AppSidebar.vue +174 -0
  119. package/src/components/layout/layout-parts/LayoutTransition.vue +366 -0
  120. package/src/components/layout/mode.ts +0 -0
  121. package/src/components/layout/props.ts +36 -0
  122. package/src/components/layout/types.ts +79 -0
  123. package/src/components/layout/utils.ts +201 -0
  124. package/src/components/provider/index.ts +5 -0
  125. package/src/components/provider/index.vue +69 -0
  126. package/src/components/provider/props.ts +45 -0
  127. package/src/components/search-bar/index.ts +5 -0
  128. package/src/components/search-bar/index.vue +282 -0
  129. package/src/components/search-bar/props.ts +26 -0
  130. package/src/components/table/TableSetting.vue +253 -0
  131. package/src/components/table/index.ts +14 -0
  132. package/src/components/table/index.vue +179 -0
  133. package/src/components/table/props.ts +29 -0
  134. package/src/components/table/useColumn.ts +104 -0
  135. package/src/components/upload/enum.ts +21 -0
  136. package/src/components/upload/index.ts +9 -0
  137. package/src/components/upload/index.vue +267 -0
  138. package/src/components/upload/props.ts +8 -0
  139. package/src/components.d.ts +154 -0
  140. package/src/const/defaults.ts +94 -0
  141. package/src/const/index.ts +2 -0
  142. package/src/const/types.ts +139 -0
  143. package/src/context/color.ts +53 -0
  144. package/src/context/common.ts +27 -0
  145. package/src/context/index.ts +141 -0
  146. package/src/context/layout.ts +34 -0
  147. package/src/context/loading-bar.ts +26 -0
  148. package/src/context/locale.ts +22 -0
  149. package/src/context/menu.ts +26 -0
  150. package/src/context/message.ts +30 -0
  151. package/src/context/notification.ts +29 -0
  152. package/src/context/table.ts +32 -0
  153. package/src/context/theme.ts +35 -0
  154. package/src/hooks/index.ts +6 -0
  155. package/src/hooks/useAdmin.ts +0 -0
  156. package/src/hooks/useForm.ts +272 -0
  157. package/src/hooks/useLayout.ts +300 -0
  158. package/src/hooks/useProviderContext.ts +47 -0
  159. package/src/hooks/useTable.ts +241 -0
  160. package/src/hooks/useThemeOverrides.ts +18 -0
  161. package/src/hooks/useUpload.ts +82 -0
  162. package/src/index.ts +59 -0
  163. package/src/share/compact.ts +35 -0
  164. package/src/share/index.ts +2 -0
  165. package/src/share/menu.ts +0 -0
  166. package/src/share/route.ts +0 -0
  167. package/src/share/slot.ts +29 -0
  168. package/src/utils/form.ts +0 -0
  169. package/src/utils/index.ts +0 -0
  170. package/src/utils/transformRoutes.ts +163 -0
  171. package/src/utils/tree.ts +31 -0
@@ -0,0 +1,253 @@
1
+ <script setup lang="ts">
2
+ import type { ExportType, Settings, TableSize } from './props'
3
+ import { VueDraggable } from 'vue-draggable-plus'
4
+ import { useColumn } from './useColumn'
5
+
6
+ const emit = defineEmits<{
7
+ realod: []
8
+ export: [type: ExportType]
9
+ }>()
10
+ const settings = defineModel<Settings>({ required: true })
11
+ const sizeOptions = [
12
+ {
13
+ type: 'menu',
14
+ label: '紧凑',
15
+ key: 'small'
16
+ },
17
+ {
18
+ type: 'menu',
19
+ label: '默认',
20
+ key: 'medium'
21
+ },
22
+ {
23
+ type: 'menu',
24
+ label: '宽松',
25
+ key: 'large'
26
+ }
27
+ ]
28
+
29
+ // 密度切换
30
+ function selectSize(e: TableSize) {
31
+ settings.value.size = e
32
+ }
33
+
34
+ const exportOptions = [
35
+ {
36
+ label: '导出原始数据',
37
+ key: 'all'
38
+ }
39
+ ]
40
+
41
+ function selectExport(e: ExportType) {
42
+ emit('export', e)
43
+ }
44
+
45
+ const data = computed({
46
+ get() {
47
+ return settings.value.columns
48
+ },
49
+ set(columns) {
50
+ settings.value.columns = columns
51
+ }
52
+ })
53
+
54
+ const {
55
+ selection,
56
+ checkAll,
57
+ checkList,
58
+ columnsList,
59
+ handleCheckAll,
60
+ handleSelection,
61
+ resetColumns,
62
+ handleChange,
63
+ fixedColumn,
64
+ draggableEnd
65
+ } = useColumn(data)
66
+
67
+ function onMove(e: any) {
68
+ if (e.draggedContext.element.draggable === false)
69
+ return false
70
+ return true
71
+ }
72
+ </script>
73
+
74
+ <template>
75
+ <NFlex :size="0" align="center">
76
+ <NTooltip trigger="hover">
77
+ <template #trigger>
78
+ <NSwitch v-model:value="settings.striped" size="small" />
79
+ </template>
80
+ 斑马纹
81
+ </NTooltip>
82
+ <NDivider vertical />
83
+ <NTooltip trigger="hover">
84
+ <template #trigger>
85
+ <NButton text type="primary">
86
+ <template #icon>
87
+ <i class="i-ant-design-reload-outlined text-5" @click="emit('realod')" />
88
+ </template>
89
+ </NButton>
90
+ </template>
91
+ 刷新
92
+ </NTooltip>
93
+ <NDivider vertical />
94
+ <!-- 密度 -->
95
+ <NTooltip trigger="hover">
96
+ <template #trigger>
97
+ <NFlex align="center">
98
+ <NDropdown v-model:value="settings.size" trigger="click" :options="sizeOptions" @select="selectSize">
99
+ <NButton text type="primary">
100
+ <template #icon>
101
+ <i class="i-mdi-arrow-expand-vertical text-5" />
102
+ </template>
103
+ </NButton>
104
+ </NDropdown>
105
+ </NFlex>
106
+ </template>
107
+ <span>密度</span>
108
+ </NTooltip>
109
+ <NDivider vertical />
110
+ <!-- 导出 -->
111
+ <NTooltip trigger="hover">
112
+ <template #trigger>
113
+ <NFlex align="center">
114
+ <NDropdown trigger="click" :options="exportOptions" @select="selectExport">
115
+ <NButton text type="primary">
116
+ <template #icon>
117
+ <i class="i-mdi-file-excel text-5" />
118
+ </template>
119
+ </NButton>
120
+ </NDropdown>
121
+ </NFlex>
122
+ </template>
123
+ <span>导出表格</span>
124
+ </NTooltip>
125
+ <NDivider vertical />
126
+ <!-- 列设置 -->
127
+ <NTooltip trigger="hover">
128
+ <template #trigger>
129
+ <NFlex align="center">
130
+ <NPopover trigger="click" :width="240" placement="bottom-end">
131
+ <template #trigger>
132
+ <NButton text type="primary">
133
+ <template #icon>
134
+ <i class="i-ic-outline-settings text-5" />
135
+ </template>
136
+ </NButton>
137
+ </template>
138
+ <template #header>
139
+ <NSpace>
140
+ <NCheckbox v-model:checked="checkAll" @update:checked="handleCheckAll">
141
+ 列展示
142
+ </NCheckbox>
143
+ <NCheckbox v-model:checked="selection" @update:checked="handleSelection">
144
+ 勾选列
145
+ </NCheckbox>
146
+ <NButton text type="info" size="small" class="mt-1" @click="resetColumns">
147
+ 重置
148
+ </NButton>
149
+ </NSpace>
150
+ </template>
151
+ <div class="table-toolbar-inner">
152
+ <NCheckboxGroup v-model:value="checkList" @update:value="handleChange">
153
+ <VueDraggable
154
+ v-model="columnsList"
155
+ :animation="300"
156
+ item-key="key"
157
+ filter=".no-draggable"
158
+ :move="onMove"
159
+ @end="draggableEnd"
160
+ >
161
+ <div
162
+ v-for="element in columnsList"
163
+ :key="element.key"
164
+ class="table-toolbar-inner-checkbox"
165
+ >
166
+ <span class="drag-icon" :class="{ 'drag-icon-hidden': element.draggable === false }">
167
+ <i class="i-nimbus-drag text-4" />
168
+ </span>
169
+ <NCheckbox :value="element.key" :label="element.title" />
170
+ <div class="fixed-item">
171
+ <NTooltip trigger="hover" placement="bottom">
172
+ <template #trigger>
173
+ <NButton text>
174
+ <template #icon>
175
+ <i
176
+ class="i-ph-caret-line-left-bold text-4"
177
+ :class="{ 'text-cyan-400 ': element.fixed === 'left' }"
178
+ @click="fixedColumn(element, 'left')"
179
+ />
180
+ </template>
181
+ </NButton>
182
+ </template>
183
+ <span>固定到左侧</span>
184
+ </NTooltip>
185
+ <NDivider vertical />
186
+ <NTooltip trigger="hover" placement="bottom">
187
+ <template #trigger>
188
+ <NButton text>
189
+ <template #icon>
190
+ <i
191
+ class="i-ph-caret-line-right-bold text-4"
192
+ :class="{ 'text-cyan-400': element.fixed === 'right' }"
193
+ @click="fixedColumn(element, 'right')"
194
+ />
195
+ </template>
196
+ </NButton>
197
+ </template>
198
+ <span>固定到右侧</span>
199
+ </NTooltip>
200
+ </div>
201
+ </div>
202
+ </VueDraggable>
203
+ </NCheckboxGroup>
204
+ </div>
205
+ </NPopover>
206
+ </NFlex>
207
+ </template>
208
+ <span>列设置</span>
209
+ </NTooltip>
210
+ </NFlex>
211
+ </template>
212
+
213
+ <style lang="scss" scoped>
214
+ .table-toolbar-right-icon {
215
+ margin-left: 12px;
216
+ font-size: 16px;
217
+ color: var(--text-color);
218
+ cursor: pointer;
219
+
220
+ :hover {
221
+ color: #1890ff;
222
+ }
223
+ }
224
+
225
+ .table-toolbar-inner {
226
+ .table-toolbar-inner-checkbox {
227
+ display: flex;
228
+ align-items: center;
229
+ padding: 5px;
230
+
231
+ &:hover {
232
+ background: var(--n-merged-td-color-hover);
233
+ }
234
+
235
+ .drag-icon {
236
+ display: inline-flex;
237
+ margin-right: 8px;
238
+ cursor: move;
239
+ &-hidden {
240
+ visibility: hidden;
241
+ cursor: default;
242
+ }
243
+ }
244
+
245
+ .fixed-item {
246
+ display: flex;
247
+ align-items: center;
248
+ justify-content: flex-end;
249
+ margin-left: auto;
250
+ }
251
+ }
252
+ }
253
+ </style>
@@ -0,0 +1,14 @@
1
+ import QuiTable from './index.vue'
2
+ import { useColumn } from './useColumn'
3
+
4
+ export { QuiTable, useColumn }
5
+
6
+ export type {
7
+ Column as TableColumn,
8
+ Columns as TableColumns,
9
+ ExportType as TableExportType,
10
+ FetchFn as TableFetchFn,
11
+ Props as TableProps,
12
+ Settings as TableSettings,
13
+ TableSize
14
+ } from './props'
@@ -0,0 +1,179 @@
1
+ <script setup lang="ts">
2
+ import type { DataTableColumn, DataTableProps, NDataTable, PaginationProps } from 'naive-ui'
3
+ import type { Props, Settings } from './props'
4
+ import { useProviderContext } from '../../hooks'
5
+ import TableSetting from './TableSetting.vue'
6
+
7
+ const props = defineProps<Props>()
8
+
9
+ const { mergedConfig } = useProviderContext()
10
+
11
+ const isHideBar = computed(() => props.hidebar ?? false)
12
+
13
+ const attrs = useAttrs() as Omit<DataTableProps, 'size' | 'striped'>
14
+
15
+ const settings = ref<Settings>({
16
+ size: props.size ?? mergedConfig.value.common?.heightMedium === '34px' ? 'medium' : 'medium', // 这里暂时用 medium,因为 common 中没有直接的 size 映射
17
+ striped: props.striped ?? mergedConfig.value.table.striped ?? true,
18
+ columns: attrs.columns!.map(item => ({
19
+ fixed: false,
20
+ ellipsis: { tooltip: true },
21
+ resizable: true,
22
+ align: 'center',
23
+ ...item
24
+ }))
25
+ })
26
+
27
+ const loading = ref(true)
28
+
29
+ const list = ref<any[]>([])
30
+
31
+ const pagination = reactive<PaginationProps>({
32
+ page: 1,
33
+ pageSize: 10,
34
+ prefix({ itemCount }) {
35
+ return `共 ${itemCount} 条`
36
+ },
37
+ showSizePicker: true,
38
+ showQuickJumper: true,
39
+ pageSizes: [10, 20, 50, 100],
40
+ onChange: (page: number) => {
41
+ pagination.page = page
42
+ fetchData()
43
+ },
44
+ onUpdatePageSize: (pageSize: number) => {
45
+ pagination.pageSize = pageSize
46
+ pagination.page = 1
47
+ fetchData()
48
+ }
49
+ })
50
+
51
+ const tableRef = ref<InstanceType<typeof NDataTable>>()
52
+
53
+ const tableProps = computed<DataTableProps>(() => {
54
+ return {
55
+ remote: true,
56
+ renderCell(v: any) {
57
+ return v ?? h(NText, { depth: 3 }, { default: () => '信息缺失' })
58
+ },
59
+ ...attrs
60
+ }
61
+ })
62
+
63
+ const fetchFn = ref(props.fetch)
64
+
65
+ async function fetchData() {
66
+ loading.value = true
67
+ const res = await fetchFn.value({
68
+ pageNum: pagination.page!,
69
+ pageSize: pagination.pageSize!
70
+ })
71
+
72
+ loading.value = false
73
+ list.value = res.list
74
+ pagination.itemCount = res.total
75
+ }
76
+
77
+ onActivated(() => {
78
+ fetchData()
79
+ })
80
+
81
+ onMounted(async () => {
82
+ fetchData()
83
+
84
+ // console.log({
85
+ // tableProps: tableProps.value,
86
+ // tableRef: tableRef.value,
87
+ // props,
88
+ // attrs
89
+ // });
90
+ })
91
+
92
+ function handleExport() {
93
+ tableRef.value?.downloadCsv({ fileName: 'data-table' })
94
+ }
95
+
96
+ // 移除显式接口,避免 dts 类型过深
97
+
98
+ defineExpose({
99
+ // 获取表格实例
100
+ getTableRef: () => tableRef.value,
101
+ // 刷新
102
+ updateTableData: (isReset = false) => {
103
+ if (isReset) {
104
+ pagination.page = 1
105
+ }
106
+ fetchData()
107
+ },
108
+ setActions<T = Record<string, any>>(columnOption: Partial<DataTableColumn<T>>) {
109
+ settings.value.columns.push({
110
+ title: '操作',
111
+ align: 'center',
112
+ fixed: 'right',
113
+ key: 'action',
114
+ ...columnOption
115
+ })
116
+ },
117
+ // 导出表格
118
+ downloadCsv: (fileName = 'data-table') => tableRef.value?.downloadCsv({ fileName }),
119
+ // 设置列
120
+ setColumns(columns: DataTableColumn[]) {
121
+ settings.value.columns = columns.map((item: any) => ({
122
+ fixed: false,
123
+ ellipsis: { tooltip: true },
124
+ resizable: true,
125
+ align: 'center',
126
+ ...item
127
+ }))
128
+ },
129
+ // 获取列
130
+ getColumns: () => settings.value.columns,
131
+ // 设置尺寸
132
+ setSize: (size: Settings['size']) => { settings.value.size = size },
133
+ // 设置斑马纹
134
+ setStriped: (striped: boolean) => { settings.value.striped = striped },
135
+ // 获取分页
136
+ getPagination: () => ({ ...pagination }),
137
+ // 设置分页(部分)
138
+ setPagination: (patch: Partial<PaginationProps>) => { Object.assign(pagination, patch) },
139
+ // 获取数据
140
+ getData: () => list.value,
141
+ // 设置数据
142
+ setData: (rows: any[]) => { list.value = rows },
143
+ // 设置 fetch 函数
144
+ setFetch: (fn: (pageInfo: { pageNum: number, pageSize: number }) => Promise<{ list: any[], total: number }>) => {
145
+ fetchFn.value = fn
146
+ },
147
+ // 获取与设置设置项
148
+ getSettings: () => settings.value,
149
+ setSettings: (patch: Partial<Settings>) => { settings.value = { ...settings.value, ...patch } }
150
+ } as any)
151
+ </script>
152
+
153
+ <template>
154
+ <NFlex vertical class="h-full flex-col-stretch">
155
+ <NFlex v-if="!isHideBar" align="center" justify="space-between">
156
+ <div>
157
+ <slot name="left" />
158
+ </div>
159
+ <NFlex align="center">
160
+ <slot name="right" />
161
+ <TableSetting v-if="!isHideBar" v-model="settings" @realod="fetchData" @export="handleExport" />
162
+ </NFlex>
163
+ </NFlex>
164
+ <NDataTable
165
+ ref="tableRef"
166
+ v-bind="tableProps"
167
+ flex-height
168
+ :size="settings.size"
169
+ :striped="settings.striped"
170
+ :columns="settings.columns"
171
+ :pagination="pagination"
172
+ :loading="loading"
173
+ :data="list"
174
+ class="flex-1-hidden"
175
+ />
176
+ </NFlex>
177
+ </template>
178
+
179
+ <style lang="scss" scoped></style>
@@ -0,0 +1,29 @@
1
+ import type { DataTableColumn, DataTableProps } from 'naive-ui'
2
+ import type { Recordable } from '../../const'
3
+
4
+ export type TableSize = 'medium' | 'small' | 'large' | undefined
5
+
6
+ export interface Props extends /* @vue-ignore */ DataTableProps {
7
+ size?: TableSize
8
+ striped?: boolean
9
+ fetch: FetchFn
10
+ hidebar?: boolean
11
+ }
12
+
13
+ export type Column = DataTableColumn<Recordable>
14
+ export type Columns = Column[]
15
+
16
+ export interface Settings {
17
+ size: TableSize
18
+ striped: boolean
19
+ columns: any[]
20
+ }
21
+
22
+ export interface FetchFn {
23
+ (pageInfo: { pageNum: number, pageSize: number }): Promise<{
24
+ list: any[]
25
+ total: number
26
+ }>
27
+ }
28
+
29
+ export type ExportType = 'all' | 'section'
@@ -0,0 +1,104 @@
1
+ import type { WritableComputedRef } from 'vue'
2
+ import { cloneDeep } from 'lodash-es'
3
+ import { reactive, ref, toRaw, toRefs } from 'vue'
4
+
5
+ export function useColumn(data: WritableComputedRef<any[]>) {
6
+ const metaColumns = ref<any[]>([])
7
+ const columnsList = ref<any[]>([])
8
+
9
+ const selectCloumn = {
10
+ type: 'selection',
11
+ key: 'selection',
12
+ fixed: 'left'
13
+ }
14
+
15
+ const state = reactive({
16
+ selection: false,
17
+ checkAll: true,
18
+ checkList: [] as any[],
19
+ defaultCheckList: [] as any[]
20
+ })
21
+
22
+ function init() {
23
+ const checkList: any = data.value.map(item => item.key)
24
+ state.checkList = checkList
25
+ state.defaultCheckList = checkList
26
+ state.selection = Boolean(data.value.find(item => item.type === 'selection'))
27
+
28
+ const newColumns = data.value.filter(
29
+ item => !['action', 'selection', 'expand'].includes(item.type) && item.title !== '操作'
30
+ )
31
+
32
+ if (!columnsList.value.length) {
33
+ columnsList.value = cloneDeep(newColumns)
34
+ metaColumns.value = cloneDeep(newColumns)
35
+ }
36
+ }
37
+
38
+ init()
39
+
40
+ function handleCheckAll(flag: boolean) {
41
+ if (flag) {
42
+ state.checkList = columnsList.value.map(item => item.key)
43
+ data.value = metaColumns.value
44
+ }
45
+ else {
46
+ state.checkList = []
47
+ data.value = []
48
+ }
49
+
50
+ handleSelection(state.selection)
51
+ }
52
+
53
+ function handleSelection(flag: boolean) {
54
+ data.value = data.value.filter(item => item.type !== 'selection')
55
+ if (flag) {
56
+ data.value.unshift(selectCloumn)
57
+ }
58
+ }
59
+
60
+ function resetColumns() {
61
+ columnsList.value = metaColumns.value
62
+ data.value = metaColumns.value
63
+ const checkList: any = data.value.map(item => item.key)
64
+ state.checkList = checkList
65
+ state.defaultCheckList = checkList
66
+
67
+ handleSelection(state.selection)
68
+ }
69
+
70
+ function handleChange() {
71
+ data.value = metaColumns.value.filter(item => state.checkList.includes(item.key))
72
+ handleSelection(state.selection)
73
+ }
74
+
75
+ // 拖拽排序
76
+ function draggableEnd() {
77
+ const newColumns = toRaw(columnsList.value)
78
+ columnsList.value = newColumns
79
+ data.value = newColumns
80
+ handleSelection(state.selection)
81
+ }
82
+
83
+ function fixedColumn(item: any, type: 'left' | 'right') {
84
+ const row = columnsList.value.find(i => item.key === i.key)
85
+ const finder = data.value.find(i => item.key === i.key)
86
+
87
+ const fixed = row.fixed === type ? false : type
88
+
89
+ row.fixed = fixed
90
+ finder.fixed = fixed
91
+ }
92
+
93
+ return {
94
+ ...toRefs(state),
95
+ init,
96
+ columnsList,
97
+ handleCheckAll,
98
+ handleSelection,
99
+ resetColumns,
100
+ handleChange,
101
+ fixedColumn,
102
+ draggableEnd
103
+ }
104
+ }
@@ -0,0 +1,21 @@
1
+ export enum AcceptType {
2
+ /**
3
+ * 图片格式:常见光栅和矢量图像
4
+ */
5
+ Image = '.jpg,.jpeg,.png,.gif,.bmp,.webp,.svg',
6
+
7
+ /**
8
+ * 视频格式:常见视频文件类型
9
+ */
10
+ Video = '.mp4,.webm,.ogg,.mov,.avi,.wmv,.flv,.mkv',
11
+
12
+ /**
13
+ * 音频格式:常见音频文件类型
14
+ */
15
+ Audio = '.mp3,.wav,.ogg,.aac,.flac,.m4a',
16
+
17
+ /**
18
+ * 文档和压缩文件:常用办公文档和压缩包
19
+ */
20
+ File = '.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf,.zip,.rar,.7z,.tar,.gz'
21
+ }
@@ -0,0 +1,9 @@
1
+ import QuiUpload from './index.vue'
2
+
3
+ export {
4
+ QuiUpload
5
+ }
6
+
7
+ export { AcceptType } from './enum'
8
+
9
+ export type { Props as UploadProps } from './props'