@xmszm/core 0.0.2 → 0.0.4

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 (71) hide show
  1. package/README.md +10 -1
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.mjs +1296 -1285
  4. package/dist/plugin/vite/initRouteMeta.cjs +1 -0
  5. package/dist/plugin/vite/initRouteMeta.mjs +13 -0
  6. package/dist/style.css +1 -1
  7. package/docs/.vitepress/config.mjs +10 -1
  8. package/docs/components/config-options.md +125 -0
  9. package/docs/components/dataform.md +175 -22
  10. package/docs/components/datatable.md +21 -39
  11. package/docs/components/dialog.md +155 -16
  12. package/docs/components/options.md +43 -14
  13. package/docs/components/query.md +20 -12
  14. package/docs/components/utils.md +118 -10
  15. package/docs/guide/changelog.md +81 -0
  16. package/docs/guide/config.md +241 -4
  17. package/docs/guide/quickstart.md +27 -2
  18. package/docs/index.md +1 -1
  19. package/docs/usage.md +16 -3
  20. package/examples/README.md +46 -0
  21. package/examples/index.html +14 -0
  22. package/examples/package.json +25 -0
  23. package/examples/pnpm-lock.yaml +1568 -0
  24. package/examples/pnpm-workspace.yaml +2 -0
  25. package/examples/src/AdminSystem.vue +870 -0
  26. package/examples/src/App.vue +330 -0
  27. package/examples/src/Introduction.vue +307 -0
  28. package/examples/src/main.js +22 -0
  29. package/examples/src/utils/permission.js +16 -0
  30. package/examples/src/utils/request.js +10 -0
  31. package/examples/vite.config.js +41 -0
  32. package/package.json +10 -4
  33. package/src/dialog/commonDialog.tsx +286 -0
  34. package/src/dialog/utils/{dialog.js → dialog.ts} +2 -0
  35. package/src/enum/sort.tsx +45 -0
  36. package/src/form/DataForm.vue +26 -52
  37. package/src/{index.js → index.ts} +7 -6
  38. package/src/list/{useList.jsx → useList.tsx} +49 -14
  39. package/src/options/{Options.jsx → Options.tsx} +37 -36
  40. package/src/options/defaultOptions.tsx +656 -0
  41. package/src/query/CommonQuery.vue +57 -89
  42. package/src/table/DataTable.vue +60 -94
  43. package/src/table/opr/{DataColumnCollet.jsx → DataColumnCollet.tsx} +18 -8
  44. package/src/table/opr/{useDataColumn.jsx → useDataColumn.tsx} +43 -48
  45. package/src/table/opr/{useDataColumnButton.jsx → useDataColumnButton.tsx} +13 -6
  46. package/src/table/opr/{useDataColumnPop.jsx → useDataColumnPop.tsx} +13 -5
  47. package/src/utils/{array.js → array.ts} +4 -6
  48. package/src/utils/{config.js → config.ts} +16 -2
  49. package/src/utils/{dialog.js → dialog.ts} +2 -2
  50. package/src/utils/{object.js → object.ts} +1 -0
  51. package/src/utils/{upload.js → upload.ts} +3 -3
  52. package/types/components.d.ts +402 -0
  53. package/types/index.d.ts +145 -7
  54. package/types/plugin/vite/initRouteMeta.d.ts +23 -0
  55. package/types/src.d.ts +55 -0
  56. package/types/vue-shim.d.ts +9 -0
  57. package/examples/demo.vue +0 -224
  58. package/src/dialog/commonDialog.jsx +0 -262
  59. package/src/enum/sort.jsx +0 -31
  60. package/src/options/defaultOptions.jsx +0 -580
  61. /package/src/dialog/{useCommonDialog.js → useCommonDialog.ts} +0 -0
  62. /package/src/directives/{auto-register.js → auto-register.ts} +0 -0
  63. /package/src/directives/{permission.js → permission.ts} +0 -0
  64. /package/src/enum/{options.js → options.ts} +0 -0
  65. /package/src/plugin/{index.js → index.ts} +0 -0
  66. /package/src/plugin/vite/{initRouteMeta.js → initRouteMeta.ts} +0 -0
  67. /package/src/store/utils/{index.js → index.ts} +0 -0
  68. /package/src/table/opr/{useQRCode.js → useQRCode.ts} +0 -0
  69. /package/src/table/utils/{ellipsis.js → ellipsis.ts} +0 -0
  70. /package/src/utils/{auth.js → auth.ts} +0 -0
  71. /package/src/utils/{time.js → time.ts} +0 -0
@@ -1,9 +1,11 @@
1
- <script setup lang="jsx">
1
+ <script setup lang="tsx">
2
2
  import { RefreshOutline, SearchOutline } from '@vicons/ionicons5'
3
- import { DataForm } from 'core'
4
- import { getOptions } from 'core/options/defaultOptions.jsx'
5
- import { ObjectToArray } from 'core/utils/object.js'
3
+ import type { CommonQueryProps, CommonQueryEmits, FormOption } from '../../types/components'
4
+ import DataForm from '../form/DataForm.vue'
5
+ import { getOptions } from '../options/defaultOptions'
6
+ import { ObjectToArray } from '../utils/object'
6
7
  import { computed, onMounted, onUnmounted, ref, getCurrentInstance } from 'vue'
8
+ import { NButton, NSpace } from 'naive-ui'
7
9
  import { registerDirectives } from '../directives/auto-register'
8
10
 
9
11
  // 自动注册指令
@@ -13,76 +15,47 @@ if (instance?.appContext?.app) {
13
15
  }
14
16
 
15
17
  // 防抖函数
16
- function debounce(func, delay) {
17
- let timeoutId
18
- return function (...args) {
18
+ function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void {
19
+ let timeoutId: ReturnType<typeof setTimeout> | undefined
20
+ return function (...args: Parameters<T>) {
19
21
  clearTimeout(timeoutId)
20
22
  timeoutId = setTimeout(() => {
21
23
  func.apply(this, args)
22
24
  }, delay)
23
25
  }
24
26
  }
25
- const emit = defineEmits(['update:query', 'submit', 'reset'])
26
-
27
- const props = defineProps({
28
- inlineText: {
29
- type: Boolean,
30
- default: () => true,
31
- },
32
- options: {
33
- type: Array,
34
- default: () => [],
35
- },
36
- query: {
37
- type: Object,
38
- default: () => ({}),
39
- },
40
- selectCount: {
41
- type: Number,
42
- default: () => 1,
43
- },
44
- type: {
45
- type: String,
46
- default: () => 'primary',
47
- },
48
- noButton: {
49
- type: Boolean,
50
- default: () => false,
51
- },
52
- isRead: {
53
- type: Boolean,
54
- default: () => false,
55
- },
56
- btn: {
57
- type: Array,
58
- default: () => ['reset', 'search'],
59
- },
60
- size: {
61
- type: String,
62
- default: () => 'medium',
63
- },
64
-
27
+ const emit = defineEmits<CommonQueryEmits>()
28
+
29
+ const props = withDefaults(defineProps<CommonQueryProps>(), {
30
+ inlineText: true,
31
+ options: () => [],
32
+ query: () => ({}),
33
+ selectCount: 1,
34
+ type: 'primary',
35
+ noButton: false,
36
+ isRead: false,
37
+ btn: () => ['reset', 'search'],
38
+ size: 'medium',
65
39
  })
66
40
 
67
- function onBeforeOptions(arr){
68
- return arr.map(v=>({
41
+ function onBeforeOptions(arr: FormOption[]): FormOption[] {
42
+ return arr.map((v: FormOption) => ({
69
43
  ...v,
70
- props:{
44
+ props: {
71
45
  ...v.props,
72
- ...((!v.way ||v.way==='input')? {
73
- onUpdateValue: (...v) => {
74
- v.props?.onUpdateValue?.(...v)
46
+ ...((!v.way || v.way === 'input') ? {
47
+ onUpdateValue: (...args: any[]) => {
48
+ ;(v.props as any)?.onUpdateValue?.(...args)
75
49
  debouncedSubmit()
76
50
  }
77
- }: {}),
51
+ } : {}),
78
52
  ...(v?.way === 'select' ? {
79
- onUpdateValue: (...v) => {
80
- v.props?.onUpdateValue?.(...v)
53
+ onUpdateValue: (...args: any[]) => {
54
+ ;(v.props as any)?.onUpdateValue?.(...args)
81
55
  debouncedSubmit()
82
56
  }
83
- }: {})
57
+ } : {})
84
58
  }
85
-
86
59
  }))
87
60
  }
88
61
 
@@ -115,9 +88,9 @@ const defaultOptions = getOptions(_queryOptionsKey.value)
115
88
 
116
89
  const _queryOptions = computed(() => {
117
90
  try {
118
- const arr = []
119
- for (let i = 0; i < props.options.length; i++) {
120
- const v = props.options[i]
91
+ const arr: FormOption[] = []
92
+ for (let i = 0; i < (props.options?.length || 0); i++) {
93
+ const v = props.options![i]
121
94
  if (v?.enum && !v?.options)
122
95
  v.options = ObjectToArray(v.enum)
123
96
  if (!v?.props) {
@@ -130,19 +103,21 @@ const _queryOptions = computed(() => {
130
103
  v.formItemProps = { ...defaultFormItemProps }
131
104
  }
132
105
  else {
106
+ const formItemProps = typeof v.formItemProps === 'function'
107
+ ? v.formItemProps({}, {})
108
+ : v.formItemProps
133
109
  v.formItemProps = {
134
110
  ...defaultFormItemProps,
135
- ...v.formItemProps,
136
- style: { ...defaultFormItemProps.style, ...v.formItemProps.style },
111
+ ...formItemProps,
112
+ style: { ...defaultFormItemProps.style, ...(formItemProps as any)?.style },
137
113
  }
138
114
  }
139
115
 
140
- const key = v?.key || v?.value
116
+ const key = v?.key || (v as any)?.value
141
117
  if (!key)
142
118
  throw new Error('key no set')
143
119
  arr.push({
144
120
  ...v,
145
-
146
121
  key,
147
122
  })
148
123
  }
@@ -196,35 +171,28 @@ const defaultBtn = {
196
171
  ),
197
172
  }
198
173
 
199
- function clearQuery() {
200
- props.options.forEach((v) => {
201
- const key = v?.key || v?.value
174
+ function clearQuery(): void {
175
+ props.options?.forEach((v: FormOption) => {
176
+ const key = (v?.key as string) || (v as any)?.value
202
177
  if (key) {
203
- if (v?.queryType)
204
- _query.value[v.queryType][key] = null
205
- else _query.value[key] = null
178
+ if (v?.queryType) {
179
+ if (!(_query.value as any)[v.queryType]) {
180
+ (_query.value as any)[v.queryType] = {}
181
+ }
182
+ (_query.value as any)[v.queryType][key] = null
183
+ }
184
+ else {
185
+ (_query.value as any)[key] = null
186
+ }
206
187
  }
207
188
  })
208
189
  emit('reset')
209
190
  }
210
191
 
211
192
  // 全局监听 Enter 键的方法
212
- function handleGlobalEnter(event) {
193
+ function handleGlobalEnter(event: KeyboardEvent): void {
213
194
  // 检查是否按下了 Enter 键
214
195
  if (event.key === 'Enter') {
215
- // 检查是否在输入框、选择框等表单元素中
216
- // const target = event.target
217
- // const isFormElement = target.tagName === 'INPUT' ||
218
- // target.tagName === 'SELECT' ||
219
- // target.tagName === 'TEXTAREA' ||
220
- // target.contentEditable === 'true'
221
-
222
- // if (isFormElement) {
223
- // // 阻止默认行为(如换行)
224
- // event.preventDefault()
225
- // // 触发搜索
226
-
227
- // }
228
196
  onSubmit()
229
197
  }
230
198
  }
@@ -241,7 +209,7 @@ onUnmounted(() => {
241
209
  </script>
242
210
 
243
211
  <template>
244
- <n-space
212
+ <NSpace
245
213
  :wrap-item="false"
246
214
  justify="space-between"
247
215
  align="center"
@@ -254,14 +222,14 @@ onUnmounted(() => {
254
222
  :form-props="{ showFeedback: false }"
255
223
  />
256
224
  </div>
257
- <n-space v-if="!props.noButton" align="center" :wrap="false">
225
+ <NSpace v-if="!props.noButton" align="center" :wrap="false">
258
226
  <slot name="left-btn" />
259
227
  <template v-for="(itm, idx) in props.btn" :key="idx">
260
228
  <component :is="defaultBtn?.[itm]?.()" />
261
229
  </template>
262
230
  <slot name="right-btn" />
263
- </n-space>
264
- </n-space>
231
+ </NSpace>
232
+ </NSpace>
265
233
  </template>
266
234
 
267
235
  <style scoped lang="less">
@@ -1,4 +1,5 @@
1
- <script setup lang="jsx">
1
+ <script setup lang="tsx">
2
+ import type { DataTableProps, DataTableExpose } from '../../types/components'
2
3
  import { ChevronDown, ChevronUp, Code, Funnel } from '@vicons/ionicons5'
3
4
  import { commonDialogMethod, toArray } from 'core'
4
5
  import { ellipsis } from 'core/table/utils/ellipsis'
@@ -10,77 +11,40 @@ import { useRoute } from 'vue-router'
10
11
  import FilterDialog from './FilterDialog.vue'
11
12
  import { orderEnum } from 'core'
12
13
  import { registerDirectives } from '../directives/auto-register'
13
-
14
+ import {NDataTable} from 'naive-ui'
14
15
  // 自动注册指令
15
16
  const instance = getCurrentInstance()
16
17
  if (instance?.appContext?.app) {
17
18
  registerDirectives(instance.appContext.app)
18
19
  }
19
20
 
20
- const props = defineProps({
21
- data: {
22
- type: Array,
23
- default: () => [],
24
- },
25
- pagination: {
26
- type: [Object, null],
27
- default: () => undefined,
28
- },
29
- columns: {
30
- type: Array,
31
- default: () => [
21
+ const props = withDefaults(defineProps<DataTableProps>(), {
22
+ data: () => [],
23
+ pagination: undefined,
24
+ columns: () => [
32
25
  {
33
26
  title: '测试案例',
34
27
  },
35
28
  ],
36
- },
37
- oprColumns: {
38
- type: [Object, null],
39
- default: () => null,
40
- },
41
- selectColumns: {
42
- type: [Object, null],
43
- default: () => null,
44
- },
45
- defaultColumns: {
46
- type: Array,
47
- default: () => [],
48
- },
49
- summaryColumns: {
50
- type: null,
51
- default: () => null,
52
- },
53
- emptyText: {
54
- type: String,
55
- default: () => '没有数据',
56
- },
57
- emptyIcon: {
58
- type: String,
59
- default: () => '',
60
- },
61
- isFilter: {
62
- type: Boolean,
63
- default: () => false,
64
- },
65
- isEllipsis: {
66
- type: Boolean,
67
- default: () => true,
68
- },
69
- virtual: {
70
- type: null,
71
- default: () => {},
72
- },
73
- singleColumn: {
74
- type: Boolean,
75
- default: () => false,
76
- },
29
+ oprColumns: null,
30
+ selectColumns: null,
31
+ defaultColumns: () => [],
32
+ summaryColumns: null,
33
+ emptyText: '没有数据',
34
+ emptyIcon: '',
35
+ isFilter: false,
36
+ isEllipsis: true,
37
+ virtual: () => ({}),
38
+ singleColumn: false,
77
39
  })
78
40
  const route = useRoute()
79
41
  const FilterKey = 'filter_key'
80
- const emit = defineEmits(['sorted'])
42
+ const emit = defineEmits<{
43
+ sorted: []
44
+ }>()
81
45
 
82
46
  // 安全获取路由路径,如果没有路由上下文则使用默认值
83
- const getRoutePath = () => {
47
+ const getRoutePath = (): string => {
84
48
  try {
85
49
  return route?.fullPath || route?.path || ''
86
50
  } catch {
@@ -93,12 +57,12 @@ const _data = computed(() => {
93
57
 
94
58
  return props.data
95
59
  })
96
- function setHeadFilter(val) {
60
+ function setHeadFilter(val: Record<string, any>): void {
97
61
  window.localStorage.setItem(FilterKey, JSON.stringify(val))
98
62
  }
99
63
 
100
- function getHeadFilter() {
101
- return JSON.parse(window.localStorage.getItem(FilterKey)) || {}
64
+ function getHeadFilter(): Record<string, any> {
65
+ return JSON.parse(window.localStorage.getItem(FilterKey) || '{}') || {}
102
66
  }
103
67
 
104
68
  const getFilterAll = ref(getHeadFilter())
@@ -106,14 +70,14 @@ const headDefault = ref([])
106
70
 
107
71
  const scrollX = ref(0)
108
72
 
109
- function _summary(pageData) {
73
+ function _summary(pageData: any[]): Record<string, { value: any }> | undefined {
110
74
  if (!props.summaryColumns)
111
75
  return
112
76
  return [
113
77
  props.selectColumns,
114
- ...unref(props.columns),
78
+ ...unref(props.columns || []),
115
79
  props.oprColumns,
116
- ]?.reduce((o, n) => {
80
+ ]?.reduce((o: Record<string, { value: any }>, n: any) => {
117
81
  if (n?.key)
118
82
  o[n.key] = props.summaryColumns?.(pageData)?.[n.key] || { value: null }
119
83
  else o[uniqueId('table')] = { value: null }
@@ -140,27 +104,27 @@ watch(
140
104
  },
141
105
  )
142
106
 
143
- function init() {
144
- const columns = unref(props.columns)
107
+ function init(): void {
108
+ const columns = unref(props.columns || [])
145
109
  const routePath = getRoutePath()
146
110
  headDefault.value
147
111
  = (routePath && getFilterAll.value?.[routePath])
148
- || columns?.map((v, i) => v?.key || dayjs().valueOf() + i)
112
+ || columns?.map((v: any, i: number) => v?.key || String(dayjs().valueOf() + i))
149
113
 
150
- const arr = props.isFilter
151
- ? columns.filter(item => headDefault.value?.includes(item.key))
114
+ const arr: any[] = props.isFilter
115
+ ? columns.filter((item: any) => headDefault.value?.includes(item.key))
152
116
  : [...columns]
153
117
  if (props.selectColumns)
154
118
  arr.unshift({ key: 'selectKey', ...props.selectColumns })
155
119
  if (props.oprColumns)
156
120
  arr.push(props.oprColumns)
157
121
  let scrollNum = 0
158
- _columns.value = arr.reduce((o, obj) => {
122
+ _columns.value = arr.reduce((o: any[], obj: any) => {
159
123
  if (obj?.display)
160
124
  console.log('display', obj?.display)
161
125
  if (!(obj?.display ?? true))
162
126
  return o
163
- const v = {
127
+ const v: any = {
164
128
  'align': 'center',
165
129
  'width': 120,
166
130
  ...obj,
@@ -171,7 +135,7 @@ function init() {
171
135
  ? obj?.ellipsisProp(ellipsis)
172
136
  : ellipsis
173
137
  : false,
174
- 'ellipsis-component': 'ellipsis' || 'performant-ellipsis',
138
+ 'ellipsis-component': 'ellipsis',
175
139
  'title': () => {
176
140
  const title = obj?.label || obj?.title || ''
177
141
  return (
@@ -183,8 +147,8 @@ function init() {
183
147
  }
184
148
 
185
149
  if (obj?.sorter) {
186
- v.renderSorterIcon = ({ order }) => {
187
- const { Icon, title } = orderEnum[order]
150
+ v.renderSorterIcon = ({ order }: { order: string }) => {
151
+ const { Icon, title } = orderEnum[order as keyof typeof orderEnum]
188
152
  return (
189
153
  <NTooltip>
190
154
  {{
@@ -196,14 +160,13 @@ function init() {
196
160
  }
197
161
  v.sorter = {
198
162
  multiple: 1,
199
- fn:obj.sorter
163
+ fn: obj.sorter
200
164
  }
201
165
  }
202
166
 
203
-
204
167
  scrollNum += v?.width
205
- ? Number.parseInt(v?.width)
206
- : null || v?.title?.length * v.length + 30 || 0
168
+ ? Number.parseInt(String(v?.width))
169
+ : (typeof v?.title === 'string' ? v?.title?.length * 30 : 0) || 0
207
170
 
208
171
  o.push(v)
209
172
  return o
@@ -212,7 +175,7 @@ function init() {
212
175
  console.log('计算')
213
176
  }
214
177
 
215
- function filterButton() {
178
+ function filterButton(): any {
216
179
  return (
217
180
  <NButton type="info" onClick={() => filterHandle()}>
218
181
  {{
@@ -223,13 +186,14 @@ function filterButton() {
223
186
  )
224
187
  }
225
188
 
226
- function filterHandle() {
189
+ function filterHandle(): void {
227
190
  const { cancel } = commonDialogMethod(
228
191
  {
229
192
  title: '筛选字段',
230
193
  read: true,
231
194
  options: [
232
195
  {
196
+ key: 'filter-dialog',
233
197
  render: () => (
234
198
  <FilterDialog
235
199
  style={{
@@ -237,10 +201,10 @@ function filterHandle() {
237
201
  margin: '0',
238
202
  padding: 0,
239
203
  }}
240
- filterItem={unref(props.columns)}
204
+ filterItem={unref(props.columns || [])}
241
205
  selectItem={headDefault.value}
242
206
  defaultItem={props.defaultColumns}
243
- onSubmit={(v) => {
207
+ onSubmit={(v: string[]) => {
244
208
  const routePath = getRoutePath()
245
209
  if (routePath) {
246
210
  getFilterAll.value[routePath] = v
@@ -263,32 +227,34 @@ function filterHandle() {
263
227
  )
264
228
  }
265
229
 
266
- function onSorter(e) {
230
+ function onSorter(e: any): void {
267
231
  console.log('onSorter', e)
268
232
  if (!e)
269
233
  return
270
234
  const sortArr = toArray(e)
271
235
 
272
- sortArr.forEach(v => {
236
+ sortArr.forEach((v: any) => {
273
237
  console.log('v', v)
274
238
 
275
239
  if (v?.sorter) {
276
- v?.sorter?.fn
277
- ((listQuery, pageState, key) => {
278
- orderEnum[v.order]?.fn(listQuery, key)
240
+ v?.sorter?.fn?.(
241
+ (listQuery: any, pageState: any, key: string) => {
242
+ orderEnum[v.order as keyof typeof orderEnum]?.fn(listQuery, key)
279
243
  pageState.fetchData()
280
- },{
244
+ },
245
+ {
281
246
  field: v?.columnKey,
282
- value: orderEnum[v?.order]?.value,
283
- isClick : !isProxy(v)
284
- })
247
+ value: orderEnum[v?.order as keyof typeof orderEnum]?.value,
248
+ isClick: !isProxy(v)
249
+ }
250
+ )
285
251
  }
286
252
  })
287
253
 
288
254
  emit('sorted')
289
255
  }
290
256
 
291
- defineExpose({
257
+ defineExpose<DataTableExpose>({
292
258
  filterHandle,
293
259
  filterButton,
294
260
  initColumns: init,
@@ -298,7 +264,7 @@ onMounted(() => {})
298
264
  </script>
299
265
 
300
266
  <template>
301
- <n-data-table
267
+ <NDataTable
302
268
  :data="_data"
303
269
  :columns="_columns"
304
270
  :scroll-x="scrollX"
@@ -309,7 +275,7 @@ onMounted(() => {})
309
275
  :row-props="() => ({ style: { height: '60px' } })"
310
276
  flex-height
311
277
  remote
312
- :virtual-scroll="props.virtual ?? props.data.length > 1000"
278
+ :virtual-scroll="!!(props.virtual ?? props.data.length > 1000)"
313
279
  style="flex: 1"
314
280
  @update:sorter="onSorter"
315
281
  >
@@ -319,7 +285,7 @@ onMounted(() => {})
319
285
  <n-empty>{{ emptyText }}</n-empty>
320
286
  </slot>
321
287
  </template>
322
- </n-data-table>
288
+ </NDataTable>
323
289
  </template>
324
290
 
325
291
  <style scoped lang="less">
@@ -1,12 +1,20 @@
1
1
  import { NButton, NPopover, NSpace } from 'naive-ui'
2
- import { computed, defineComponent, ref } from 'vue'
2
+ import { computed, defineComponent, ref, type VNode } from 'vue'
3
+ import type { ActionOption } from '../../../types/components'
3
4
 
4
5
  import { rowIndexKey } from './useDataColumn'
5
6
  import OprButton from './useDataColumnButton'
6
7
  import Pop from './useDataColumnPop'
7
8
 
9
+ interface Props {
10
+ options: ActionOption[]
11
+ max: number
12
+ data: any
13
+ index: number
14
+ }
15
+
8
16
  export default defineComponent(
9
- (props) => {
17
+ (props: Props) => {
10
18
  const leng = props.options.length
11
19
 
12
20
  const toggle = ref(false)
@@ -16,7 +24,7 @@ export default defineComponent(
16
24
 
17
25
  const ellipOptions = computed(() => props.options.slice(props.max))
18
26
 
19
- function renderOptions(op) {
27
+ function renderOptions(op: ActionOption[]): (VNode | undefined)[] {
20
28
  return op
21
29
  ?.map(
22
30
  (
@@ -30,20 +38,21 @@ export default defineComponent(
30
38
  },
31
39
  i,
32
40
  ) => {
33
- return isRender?.(props.data)
41
+ return (typeof isRender === 'function' ? isRender(props.data) : isRender)
34
42
  ? (
35
43
  mode === 'pop'
36
44
  ? (
37
45
  <Pop
38
46
  onClick={onClick}
39
47
  row={props.data}
48
+ index={props.index}
40
49
  action={action}
41
50
  key={rowIndexKey(props.data, props.index) + i}
42
51
  >
43
52
  <NButton
44
53
  text
45
- disabled={disabled && disabled(props.data)}
46
- type={disabled && disabled(props.data) ? 'default' : type}
54
+ disabled={typeof disabled === 'function' ? disabled(props.data) : disabled}
55
+ type={typeof disabled === 'function' && disabled(props.data) ? 'default' : type}
47
56
  {...action}
48
57
  >
49
58
  {typeof action?.label === 'function'
@@ -61,6 +70,7 @@ export default defineComponent(
61
70
  onClick,
62
71
  type,
63
72
  }}
73
+ index={props.index}
64
74
  key={rowIndexKey(props.data, props.index) + i}
65
75
  />
66
76
  )
@@ -68,7 +78,7 @@ export default defineComponent(
68
78
  : undefined
69
79
  },
70
80
  )
71
- .filter(v => v)
81
+ .filter((v): v is VNode => v !== undefined)
72
82
  }
73
83
 
74
84
  return () => (
@@ -116,7 +126,7 @@ export default defineComponent(
116
126
  },
117
127
  data: {
118
128
  type: Object,
119
- default: () => {},
129
+ default: () => ({}),
120
130
  },
121
131
  index: {
122
132
  type: Number,