@hoenergy/hoenergy-template-pc 1.1.3 → 1.1.5

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 (98) hide show
  1. package/package.json +7 -5
  2. package/src/components/Business/dataEntry/modalSearchTable/index.ts +62 -57
  3. package/src/components/Business/dataEntry/modalSearchTable/index.vue +6 -56
  4. package/src/components/Business/dataEntry/modalSearchTable/preview.vue +6 -6
  5. package/src/components/Business/dataEntry/modalTableSelect/hooks/useModalTableSelect.ts +2 -1
  6. package/src/components/Business/dataEntry/modalTableSelect/index.ts +87 -76
  7. package/src/components/Business/dataEntry/modalTableSelect/index.vue +7 -57
  8. package/src/components/Business/dataEntry/modalTableSelect/preview.vue +5 -4
  9. package/src/components/data/table/FormaxTable/src/Table.vue +0 -1
  10. package/src/components/general/modal/FormaxModal/src/basicModal.vue +3 -5
  11. package/src/index.ts +17 -5
  12. package/vite.config.ts +3 -0
  13. package/dist/components/Business/dataEntry/FormaxEleTimePicker/index.d.ts +0 -5
  14. package/dist/components/Business/dataEntry/FormaxEleTimePicker/index.vue.d.ts +0 -9
  15. package/dist/components/Business/dataEntry/modalSearchTable/hooks/useModalSearchTable.d.ts +0 -18
  16. package/dist/components/Business/dataEntry/modalSearchTable/index.d.ts +0 -6
  17. package/dist/components/Business/dataEntry/modalSearchTable/index.vue.d.ts +0 -41
  18. package/dist/components/Business/dataEntry/modalTableSelect/hooks/useModalTableSelect.d.ts +0 -18
  19. package/dist/components/Business/dataEntry/modalTableSelect/index.d.ts +0 -6
  20. package/dist/components/Business/dataEntry/modalTableSelect/index.vue.d.ts +0 -42
  21. package/dist/components/charts/chart/FormaxChart/getSize.d.ts +0 -5
  22. package/dist/components/charts/chart/FormaxChart/index.d.ts +0 -5
  23. package/dist/components/charts/chart/FormaxChart/index.vue.d.ts +0 -37
  24. package/dist/components/charts/chartCard/FormaxChartCard/index.d.ts +0 -5
  25. package/dist/components/charts/chartCard/FormaxChartCard/index.vue.d.ts +0 -71
  26. package/dist/components/data/form/searchForm/index.d.ts +0 -8
  27. package/dist/components/data/form/searchForm/src/BasicForm.vue.d.ts +0 -202
  28. package/dist/components/data/form/searchForm/src/helper.d.ts +0 -10
  29. package/dist/components/data/form/searchForm/src/hooks/helper.d.ts +0 -8
  30. package/dist/components/data/form/searchForm/src/hooks/useForm.d.ts +0 -5
  31. package/dist/components/data/form/searchForm/src/hooks/useFormContext.d.ts +0 -2
  32. package/dist/components/data/form/searchForm/src/hooks/useFormEvents.d.ts +0 -23
  33. package/dist/components/data/form/searchForm/src/hooks/useFormValues.d.ts +0 -12
  34. package/dist/components/data/form/searchForm/src/icon.d.ts +0 -208
  35. package/dist/components/data/form/searchForm/src/props.d.ts +0 -73
  36. package/dist/components/data/form/searchForm/src/types/form.d.ts +0 -60
  37. package/dist/components/data/form/searchForm/src/types/index.d.ts +0 -1
  38. package/dist/components/data/form/searchForm/src/utils/index.d.ts +0 -17
  39. package/dist/components/data/form/searchForm/src/utils/is.d.ts +0 -59
  40. package/dist/components/data/form/searchForm/src/utils/propTypes.d.ts +0 -9
  41. package/dist/components/data/table/FormaxTable/index.d.ts +0 -7
  42. package/dist/components/data/table/FormaxTable/src/BasicTable.d.ts +0 -6
  43. package/dist/components/data/table/FormaxTable/src/Table.vue.d.ts +0 -99
  44. package/dist/components/data/table/FormaxTable/src/components/settings/ColumnSetting.vue.d.ts +0 -31
  45. package/dist/components/data/table/FormaxTable/src/const.d.ts +0 -9
  46. package/dist/components/data/table/FormaxTable/src/hooks/useColumns.d.ts +0 -10
  47. package/dist/components/data/table/FormaxTable/src/hooks/useDataSource.d.ts +0 -20
  48. package/dist/components/data/table/FormaxTable/src/hooks/useLoading.d.ts +0 -6
  49. package/dist/components/data/table/FormaxTable/src/hooks/usePagination.d.ts +0 -10
  50. package/dist/components/data/table/FormaxTable/src/hooks/useTableContext.d.ts +0 -13
  51. package/dist/components/data/table/FormaxTable/src/props.d.ts +0 -1
  52. package/dist/components/data/table/FormaxTable/src/types/componentType.d.ts +0 -1
  53. package/dist/components/data/table/FormaxTable/src/types/pagination.d.ts +0 -10
  54. package/dist/components/data/table/FormaxTable/src/types/table.d.ts +0 -36
  55. package/dist/components/data/table/FormaxTable/src/types/tableAction.d.ts +0 -23
  56. package/dist/components/data/table/FormaxTable/src/utils.d.ts +0 -11
  57. package/dist/components/general/button/FormaxButton/index.d.ts +0 -2
  58. package/dist/components/general/calendar/FormaxCalendar/index.d.ts +0 -5
  59. package/dist/components/general/calendar/FormaxCalendar/index.vue.d.ts +0 -8362
  60. package/dist/components/general/card/FormaxCard/index.d.ts +0 -5
  61. package/dist/components/general/card/FormaxCard/index.vue.d.ts +0 -17
  62. package/dist/components/general/icon/FormaxIcon/index.d.ts +0 -5
  63. package/dist/components/general/icon/FormaxIcon/index.vue.d.ts +0 -15
  64. package/dist/components/general/iconSelect/FormaxIconSelect/icons.d.ts +0 -1
  65. package/dist/components/general/iconSelect/FormaxIconSelect/index.d.ts +0 -5
  66. package/dist/components/general/iconSelect/FormaxIconSelect/index.vue.d.ts +0 -16
  67. package/dist/components/general/infoCard/FormaxInfoCard/index.d.ts +0 -5
  68. package/dist/components/general/infoCard/FormaxInfoCard/index.vue.d.ts +0 -43
  69. package/dist/components/general/loading/FormaxLoading/index.d.ts +0 -5
  70. package/dist/components/general/loading/FormaxLoading/index.vue.d.ts +0 -43
  71. package/dist/components/general/map/MapPoint/index.d.ts +0 -5
  72. package/dist/components/general/map/MapPoint/index.vue.d.ts +0 -33
  73. package/dist/components/general/modal/FormaxModal/index.d.ts +0 -7
  74. package/dist/components/general/modal/FormaxModal/src/basicModal.vue.d.ts +0 -28
  75. package/dist/components/general/modal/FormaxModal/src/hooks/helper.d.ts +0 -8
  76. package/dist/components/general/modal/FormaxModal/src/hooks/useModal.d.ts +0 -2
  77. package/dist/components/general/modal/FormaxModal/src/props.d.ts +0 -1
  78. package/dist/components/general/modal/FormaxModal/src/type/index.d.ts +0 -16
  79. package/dist/components/general/modal/FormaxModal/src/utils/Drag.d.ts +0 -2
  80. package/dist/components/general/modal/FormaxModal/src/utils/index.d.ts +0 -17
  81. package/dist/components/general/modal/FormaxModal/src/utils/is.d.ts +0 -59
  82. package/dist/components/general/title/FormaxTitle/index.d.ts +0 -5
  83. package/dist/components/general/title/FormaxTitle/index.vue.d.ts +0 -50
  84. package/dist/components/general/viewer/FormaxFileViewer/index.d.ts +0 -5
  85. package/dist/components/general/viewer/FormaxFileViewer/index.vue.d.ts +0 -19
  86. package/dist/components/globalConfig/ConfigProvider/FormaxConfigProvider/index.d.ts +0 -5
  87. package/dist/components/globalConfig/ConfigProvider/FormaxConfigProvider/index.vue.d.ts +0 -25
  88. package/dist/directives/formaxLoading.d.ts +0 -19
  89. package/dist/docs/DocPage.vue.d.ts +0 -7
  90. package/dist/docs/index.d.ts +0 -2
  91. package/dist/hook/useLocale.hook.d.ts +0 -12
  92. package/dist/hook/useTheme.hook.d.ts +0 -22
  93. package/dist/index.d.ts +0 -85
  94. package/dist/index.js +0 -865
  95. package/dist/index.mjs +0 -186314
  96. package/dist/mock.d.ts +0 -13
  97. package/dist/style.css +0 -1
  98. package/dist/types.d.ts +0 -54
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "@hoenergy/hoenergy-template-pc",
3
- "version": "1.1.3",
3
+ "type": "module",
4
+ "version": "1.1.5",
4
5
  "description": "A cross-compatible Vue component library with metadata extraction",
5
6
  "publishConfig": {
6
7
  "access": "public"
7
8
  },
8
- "main": "dist/index.js",
9
- "module": "dist/index.js",
10
- "types": "dist/index.d.ts",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.mjs",
11
+ "types": "./dist/index.d.ts",
11
12
  "unpkg": "dist/index.global.js",
12
13
  "exports": {
13
14
  ".": {
14
15
  "import": "./dist/index.mjs",
15
- "require": "./dist/index.js"
16
+ "require": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
16
18
  }
17
19
  },
18
20
  "scripts": {
@@ -13,11 +13,6 @@ const meta: ComponentMeta = {
13
13
  description:
14
14
  '集成搜索表单与数据表格的弹框组件,默认单选;可配置多选;回显只需传 rowKey 的值(或数组)。',
15
15
  props: {
16
- visible: {
17
- type: 'boolean',
18
- default: false,
19
- description: '弹窗显示开关',
20
- },
21
16
  title: {
22
17
  type: 'string',
23
18
  default: '选择数据',
@@ -33,11 +28,7 @@ const meta: ComponentMeta = {
33
28
  default: 80,
34
29
  description: '搜索表单标签宽度,透传给 FormaxForm',
35
30
  },
36
- schemas: {
37
- type: 'array',
38
- default: [],
39
- description: '搜索条件表单配置,参照 FormaxForm.schemas',
40
- },
31
+
41
32
  columns: {
42
33
  type: 'array',
43
34
  default: [],
@@ -71,16 +62,6 @@ const meta: ComponentMeta = {
71
62
  },
72
63
  },
73
64
  events: [
74
- {
75
- name: 'update:visible',
76
- description: '弹窗显示状态变化时触发',
77
- payload: 'visible: boolean',
78
- },
79
- {
80
- name: 'update:modelValue',
81
- description: '点击确认按钮时触发,用于回写已选 id',
82
- payload: 'value: any | any[]',
83
- },
84
65
  {
85
66
  name: 'confirm',
86
67
  description: '点击确认按钮时触发,返回已选中行数据列表',
@@ -110,63 +91,87 @@ const meta: ComponentMeta = {
110
91
  slots: [],
111
92
  methods: [],
112
93
  usage: `<template>
113
- <div style="padding: 16px;">
114
- <n-button type="primary" @click="openModal">打开弹窗</n-button>
115
- <ModalSearchTable
116
- :visible="visible"
117
- @update:visible="val => (visible = val)"
118
- v-model:modelValue="userId"
119
- :schemas="schemas"
120
- :columns="columns"
121
- :request="fetchTableData"
122
- row-key="id"
123
- label-field="name"
124
- title="选择用户"
125
- @register="register"
126
- />
127
- </div>
94
+ <div style="padding: 16px;">
95
+ <n-space>
96
+ <n-button type="primary" @click="openModal">打开弹窗</n-button>
97
+ <div>已选 id:{{ userId }}</div>
98
+ </n-space>
99
+ <ModalSearchTable v-model:modelValue="userId" :schemas="schemas" :columns="columns" :request="fetchTableData"
100
+ row-key="id" label-field="name" @register="register" :multiple="true" @confirm="handleConfirm" />
101
+ </div>
128
102
  </template>
129
103
 
130
104
  <script setup lang="ts">
131
105
  import { ref } from 'vue'
106
+ import { NButton, NSpace } from 'naive-ui'
132
107
  import { ModalSearchTable, useModalSearchTable } from './index'
133
108
 
134
109
  const visible = ref(false)
135
- const userId = ref<number | null>(null)
110
+ const userId = ref<number[]>([2])
136
111
 
137
112
  const schemas = ref([
138
- { field: 'name', label: '姓名', component: 'NInput' },
113
+ {
114
+ field: 'name',
115
+ label: '姓名',
116
+ component: 'NInput',
117
+ },
139
118
  ])
140
119
 
141
120
  const columns = ref([
142
- { title: 'ID', key: 'id', width: 80 },
143
- { title: '姓名', key: 'name' },
121
+ { title: 'ID', key: 'id', width: 80 },
122
+ { title: '姓名', key: 'name' },
144
123
  ])
145
124
 
146
125
  const allData = [
147
- { id: 1, name: '张三' },
148
- { id: 2, name: '李四' },
149
- { id: 3, name: '王五' },
126
+ { id: 1, name: '张三' },
127
+ { id: 2, name: '李四' },
128
+ { id: 3, name: '王五' },
150
129
  ]
151
-
130
+ function handleConfirm(selectedMap: any) {
131
+ if (selectedMap.length === 0) return
132
+ userId.value = selectedMap?.map((item: any) => item.id) || []
133
+ closeModal()
134
+ }
152
135
  async function fetchTableData(params: Record<string, any>) {
153
- const pageNum = params.pageNum || 1
154
- const pageSize = params.pageSize || 10
155
- const { name } = params
156
- let list = allData
157
- if (name) list = list.filter((item) => item.name.includes(name))
158
- const total = list.length
159
- const start = (pageNum - 1) * pageSize
160
- const end = start + pageSize
161
- const pageList = list.slice(start, end)
162
- const pages = Math.ceil(total / pageSize)
163
- return { pageNum, pageSize, pages, total, list: pageList }
136
+ const pageNum = params.pageNum || 1
137
+ const pageSize = params.pageSize || 10
138
+ const { name } = params
139
+ let list = allData
140
+ if (name) {
141
+ list = list.filter((item) => item.name.includes(name))
142
+ }
143
+ const total = list.length
144
+ const start = (pageNum - 1) * pageSize
145
+ const end = start + pageSize
146
+ const pageList = list.slice(start, end)
147
+ const pages = Math.ceil(total / pageSize)
148
+ return {
149
+ pageNum,
150
+ pageSize,
151
+ pages,
152
+ total,
153
+ list: pageList,
154
+ }
164
155
  }
165
156
 
166
- const [register, { openModal }] = useModalSearchTable({
167
- modalProps: { title: '选择用户', width: 920 },
157
+ const [register, { openModal, closeModal }] = useModalSearchTable({
158
+ modalProps: {
159
+ title: '选择用户',
160
+ width: 920,
161
+ },
162
+ formProps: {
163
+ gridProps: {
164
+ cols: '3 s:3 m:3 l:3 xl:3 2xl:3',
165
+ responsive: 'screen',
166
+ collapsed: false,
167
+ collapsedRows: 10
168
+ },
169
+ labelWidth: 50,
170
+ schemas,
171
+ },
168
172
  })
169
- </script>`,
173
+ </script>
174
+ `,
170
175
  previewPath: 'Business/dataEntry/modalSearchTable/preview.vue',
171
176
  package: 'business',
172
177
  category: 'dataEntry',
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <FormaxModal :width="modalWidth" :title="modalTitle" v-bind="modalBindProps" @register="handleModalRegister"
3
- @on-ok="handleOk" @on-close="handleClose" v-if="innerVisible">
3
+ @on-ok="handleOk">
4
4
  <div class="w-full">
5
5
  <FormaxForm id="basicForm" :label-width="labelWidth" :schemas="schemas" :show-advanced-button="false"
6
6
  @register="handleFormRegister" @submit="handleFormSubmit" @reset="handleFormReset" />
@@ -20,10 +20,8 @@ import { FormaxFormComponent as FormaxForm } from '../../../data/form/searchForm
20
20
  import { FormaxTableComponent as FormaxTable } from '../../../data/table/FormaxTable'
21
21
  import { NRadio } from 'naive-ui'
22
22
  import { $at } from 'i18n-auto-extractor';
23
- import { useMessage } from 'naive-ui'
24
- let message = useMessage()
23
+
25
24
  interface Props {
26
- visible: boolean
27
25
  title?: string
28
26
  width?: number | string
29
27
  labelWidth?: number | string
@@ -38,7 +36,6 @@ interface Props {
38
36
  }
39
37
 
40
38
  const props = withDefaults(defineProps<Props>(), {
41
- visible: false,
42
39
  title: $at('选择数据'),
43
40
  width: 1120,
44
41
  labelWidth: 80,
@@ -47,13 +44,11 @@ const props = withDefaults(defineProps<Props>(), {
47
44
  })
48
45
 
49
46
  const emit = defineEmits<{
50
- (e: 'update:visible', value: boolean): void
51
47
  (e: 'confirm', value: any[]): void
52
48
  (e: 'submit', value: Record<string, any>): void
53
49
  (e: 'reset', value: Record<string, any>): void
54
50
  (e: 'form-register', value: any): void
55
51
  (e: 'register', value: any): void
56
- (e: 'update:modelValue', value: any): void
57
52
  }>()
58
53
 
59
54
  const [modalRegister, { openModal: openInnerModal, closeModal: closeInnerModal, setSubLoading, setProps: setInnerModalProps }] = useModal({
@@ -123,48 +118,22 @@ function handleModalRegister(methods: any) {
123
118
  if (pendingModalPropsRef.value) {
124
119
  setInnerModalProps(getDynamicProps(pendingModalPropsRef.value))
125
120
  }
126
- if (props.visible) {
127
- innerVisible.value = true
128
- syncFromModel()
129
- openInnerModal()
130
- }
121
+
131
122
  }
132
123
 
133
124
  const tableRef = ref<any>()
134
125
  const searchValues = ref<Record<string, any>>({})
135
126
  const selectedMap = ref(new Map<any, any>())
136
127
  const checkedRowKeys = ref<any[]>([])
137
- const innerVisible = ref(false)
138
128
 
139
- watch(
140
- () => props.visible,
141
- (val) => {
142
- innerVisible.value = !!val
143
- },
144
- { immediate: true },
145
- )
146
129
 
147
- watch(
148
- () => innerVisible.value,
149
- (val) => {
150
- if (!modalReadyRef.value) return
151
- if (val) {
152
- syncFromModel()
153
- openInnerModal()
154
- } else {
155
- closeInnerModal()
156
- resetInner()
157
- }
158
- },
159
- { immediate: true },
160
- )
130
+
131
+
161
132
 
162
133
  watch(
163
134
  () => [props.modelValue, props.multiple],
164
135
  () => {
165
- if (innerVisible.value) {
166
- syncFromModel()
167
- }
136
+ syncFromModel()
168
137
  },
169
138
  { deep: true, immediate: true },
170
139
  )
@@ -362,40 +331,21 @@ function handleCheckedRowKeys(keys: any[]) {
362
331
  }
363
332
 
364
333
  function handleOk() {
365
- setSubLoading(true)
366
334
  const rows = Array.from(selectedMap.value.values())
367
- if (!rows.length) {
368
- message.warning($at('请选择至少一条数据'))
369
- return
370
- }
371
- const values = rows.map((row) => getRowKeyValue(row)).filter((v) => v !== undefined)
372
- emit('update:modelValue', props.multiple ? values : (values[0] ?? null))
373
335
  emit('confirm', rows)
374
336
  setSubLoading(false)
375
- innerVisible.value = false
376
- emit('update:visible', false)
377
337
  }
378
-
379
- function handleClose() {
380
- innerVisible.value = false
381
- emit('update:visible', false)
382
- }
383
-
384
338
  const modalSearchTableMethods = {
385
339
  openModal: () => {
386
340
  syncFromModel()
387
- innerVisible.value = true
388
341
  if (modalReadyRef.value) {
389
342
  openInnerModal()
390
343
  }
391
- emit('update:visible', true)
392
344
  },
393
345
  closeModal: () => {
394
- innerVisible.value = false
395
346
  if (modalReadyRef.value) {
396
347
  closeInnerModal()
397
348
  }
398
- emit('update:visible', false)
399
349
  },
400
350
  setModalProps: (val: any) => {
401
351
  pendingModalPropsRef.value = val
@@ -4,9 +4,8 @@
4
4
  <n-button type="primary" @click="openModal">打开弹窗</n-button>
5
5
  <div>已选 id:{{ userId }}</div>
6
6
  </n-space>
7
- <ModalSearchTable :visible="visible" @update:visible="val => (visible = val)" v-model:modelValue="userId"
8
- :schemas="schemas" :columns="columns" :request="fetchTableData" row-key="id" label-field="name"
9
- @register="register" :multiple="true" @confirm="handleConfirm" />
7
+ <ModalSearchTable v-model:modelValue="userId" :schemas="schemas" :columns="columns" :request="fetchTableData"
8
+ row-key="id" label-field="name" @register="register" :multiple="true" @confirm="handleConfirm" />
10
9
  </div>
11
10
  </template>
12
11
 
@@ -36,9 +35,10 @@ const allData = [
36
35
  { id: 2, name: '李四' },
37
36
  { id: 3, name: '王五' },
38
37
  ]
39
- function handleConfirm(selectedMap: Map<any, any>) {
40
- if (!selectedMap.size || selectedMap.length === 0) return
38
+ function handleConfirm(selectedMap: any) {
39
+ if (selectedMap.length === 0) return
41
40
  userId.value = selectedMap?.map((item: any) => item.id) || []
41
+ closeModal()
42
42
  }
43
43
  async function fetchTableData(params: Record<string, any>) {
44
44
  const pageNum = params.pageNum || 1
@@ -62,7 +62,7 @@ async function fetchTableData(params: Record<string, any>) {
62
62
  }
63
63
  }
64
64
 
65
- const [register, { openModal }] = useModalSearchTable({
65
+ const [register, { openModal, closeModal }] = useModalSearchTable({
66
66
  modalProps: {
67
67
  title: '选择用户',
68
68
  width: 920,
@@ -22,6 +22,7 @@ export function useModalTableSelect(options?: {
22
22
 
23
23
  const getInstance = () => {
24
24
  const instance = unref(modalRef)
25
+
25
26
  if (!instance) {
26
27
  console.error('useModalTableSelect instance is undefined!')
27
28
  }
@@ -46,7 +47,7 @@ export function useModalTableSelect(options?: {
46
47
  {
47
48
  immediate: true,
48
49
  deep: true,
49
- },
50
+ }
50
51
  )
51
52
  }
52
53
 
@@ -13,11 +13,6 @@ const meta: ComponentMeta = {
13
13
  description:
14
14
  '集成搜索表单与数据表格的弹框选择组件,支持多选并回传结果,支持传 rowKey 数组回显。',
15
15
  props: {
16
- visible: {
17
- type: 'boolean',
18
- default: false,
19
- description: '弹窗显示开关',
20
- },
21
16
  title: {
22
17
  type: 'string',
23
18
  default: '选择数据',
@@ -33,11 +28,7 @@ const meta: ComponentMeta = {
33
28
  default: 80,
34
29
  description: '搜索表单标签宽度,透传给 FormaxForm',
35
30
  },
36
- schemas: {
37
- type: 'array',
38
- default: [],
39
- description: '搜索条件表单配置,参照 FormaxForm.schemas',
40
- },
31
+
41
32
  columns: {
42
33
  type: 'array',
43
34
  default: [],
@@ -76,21 +67,11 @@ const meta: ComponentMeta = {
76
67
  },
77
68
  },
78
69
  events: [
79
- {
80
- name: 'update:visible',
81
- description: '弹窗显示状态变化时触发',
82
- payload: 'visible: boolean',
83
- },
84
70
  {
85
71
  name: 'confirm',
86
72
  description: '点击确认按钮时触发,返回已选中数据列表',
87
73
  payload: 'rows: any[]',
88
74
  },
89
- {
90
- name: 'update:modelValue',
91
- description: '勾选变化/确认时触发,用于回写已选 rowKey 数组',
92
- payload: 'value: any[]',
93
- },
94
75
  {
95
76
  name: 'submit',
96
77
  description: '搜索表单提交时触发',
@@ -120,83 +101,113 @@ const meta: ComponentMeta = {
120
101
  ],
121
102
  methods: [],
122
103
  usage: `<template>
123
- <div style="padding: 16px;">
124
- <n-button type="primary" @click="visible = true">选择数据</n-button>
125
- <ModalTableSelect
126
- :visible="visible"
127
- @update:visible="val => visible = val"
128
- v-model:modelValue="selectedIds"
129
- :schemas="schemas"
130
- :columns="columns"
131
- :request="fetchTableData"
132
- row-key="id"
133
- title="选择用户"
134
- @confirm="handleConfirm"
135
- />
136
- </div>
104
+ <div style="padding: 16px;">
105
+ <n-space>
106
+ <n-button type="primary" @click="openEmpty">打开选择弹窗</n-button>
107
+ <n-button type="primary" @click="openWithEcho">打开并回显(2,4)</n-button>
108
+ <div>已选 id:{{ selectedIds }}</div>
109
+ </n-space>
110
+ <ModalTableSelect v-model:modelValue="selectedIds" :columns="columns" :request="fetchTableData" row-key="id"
111
+ label-field="name" :selected-column-keys="['id', 'name']" @register="register" @confirm="handleConfirm" />
112
+ </div>
137
113
  </template>
138
114
 
139
115
  <script setup lang="ts">
140
116
  import { ref } from 'vue'
141
- import ModalTableSelect from './index.vue'
117
+ import { ModalTableSelect, useModalTableSelect } from './index'
118
+ import { NButton, NSpace } from 'naive-ui'
142
119
 
143
120
  const visible = ref(false)
144
- const selectedIds = ref<number[]>([2])
121
+ const selectedIds = ref<number[]>([])
145
122
 
146
123
  const schemas = ref([
147
- { field: 'name', label: '姓名', component: 'NInput' },
148
- {
149
- field: 'status',
150
- label: '状态',
151
- component: 'NSelect',
152
- componentProps: {
153
- options: [
154
- { label: '启用', value: 'enable' },
155
- { label: '停用', value: 'disable' },
156
- ],
124
+ {
125
+ field: 'name',
126
+ label: '姓名',
127
+ component: 'NInput',
128
+ },
129
+ {
130
+ field: 'status',
131
+ label: '状态',
132
+ component: 'NSelect',
133
+ componentProps: {
134
+ options: [
135
+ { label: '启用', value: 'enable' },
136
+ { label: '停用', value: 'disable' },
137
+ ],
138
+ },
157
139
  },
158
- },
159
140
  ])
160
141
 
142
+ const [register, { openModal, closeModal }] = useModalTableSelect({
143
+ formProps: {
144
+ gridProps: {
145
+ cols: '3 s:3 m:3 l:3 xl:3 2xl:3',
146
+ responsive: 'screen',
147
+ collapsed: false,
148
+ collapsedRows: 10
149
+ },
150
+ labelWidth: 50,
151
+ schemas,
152
+ },
153
+ modalProps: {
154
+ title: '选择用户',
155
+ width: 1220,
156
+ }
157
+ })
158
+
161
159
  const columns = ref([
162
- { title: 'ID', key: 'id', width: 80 },
163
- { title: '姓名', key: 'name' },
164
- { title: '状态', key: 'status' },
160
+ { title: 'ID', key: 'id', width: 80 },
161
+ { title: '姓名', key: 'name' },
162
+ { title: '状态', key: 'status' },
165
163
  ])
166
164
 
167
165
  const allData = [
168
- { id: 1, name: '张三', status: 'enable' },
169
- { id: 2, name: '李四', status: 'disable' },
170
- { id: 3, name: '王五', status: 'enable' },
166
+ { id: 1, name: '张三', status: 'enable' },
167
+ { id: 2, name: '李四', status: 'disable' },
168
+ { id: 3, name: '王五', status: 'enable' },
169
+ { id: 4, name: '赵六', status: 'enable' },
171
170
  ]
172
171
 
173
172
  async function fetchTableData(params: Record<string, any>) {
174
- const pageNum = params.pageNum || 1
175
- const pageSize = params.pageSize || 10
176
- const { name, status } = params
177
- let list = allData
178
- if (name) {
179
- list = list.filter((item) => item.name.includes(name))
180
- }
181
- if (status) {
182
- list = list.filter((item) => item.status === status)
183
- }
184
- const total = list.length
185
- const start = (pageNum - 1) * pageSize
186
- const end = start + pageSize
187
- const pageList = list.slice(start, end)
188
- const pages = Math.ceil(total / pageSize)
189
- return {
190
- pageNum,
191
- pageSize,
192
- pages,
193
- total,
194
- list: pageList,
195
- }
173
+ const pageNum = params.pageNum || 1
174
+ const pageSize = params.pageSize || 10
175
+ const { name, status } = params
176
+ let list = allData
177
+ if (name) {
178
+ list = list.filter((item) => item.name.includes(name))
179
+ }
180
+ if (status) {
181
+ list = list.filter((item) => item.status === status)
182
+ }
183
+ const total = list.length
184
+ const start = (pageNum - 1) * pageSize
185
+ const end = start + pageSize
186
+ const pageList = list.slice(start, end)
187
+ const pages = Math.ceil(total / pageSize)
188
+ return {
189
+ pageNum,
190
+ pageSize,
191
+ pages,
192
+ total,
193
+ list: pageList,
194
+ }
196
195
  }
197
196
 
198
197
  function handleConfirm(list: any[]) {
199
- console.log('selected rows', list)
198
+ console.log('已选中数据', list)
199
+ closeModal()
200
+ }
201
+
202
+ function openEmpty() {
203
+ selectedIds.value = []
204
+ visible.value = true
205
+ openModal()
206
+ }
207
+
208
+ function openWithEcho() {
209
+ selectedIds.value = [2, 4]
210
+ openModal()
200
211
  }
201
212
  </script>`,
202
213
  previewPath: 'Business/dataEntry/modalTableSelect/preview.vue',