PageHelpTable.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <vxe-grid v-bind="tableGridComputed" :ref="setMainTableRef">
  3. </vxe-grid>
  4. <!-- <vxe-table-->
  5. <!-- :data="data"-->
  6. <!-- :ref="setMainTableRef"-->
  7. <!-- border-->
  8. <!-- :export-config="{}"-->
  9. <!-- height="auto"-->
  10. <!-- auto-resize-->
  11. <!-- sync-resize-->
  12. <!-- :column-config="{resizable: true}"-->
  13. <!-- style="{width: 100%}"-->
  14. <!-- :row-config="{height: 48 , isCurrent: true,isHover:true, useKey: true} "-->
  15. <!-- :scroll-x="{enabled: false}"-->
  16. <!-- :scroll-y="{gt: 0 ,enabled: true}"-->
  17. <!-- show-overflow-->
  18. <!-- v-bind="tableBind"-->
  19. <!-- >-->
  20. <!-- <VxeColumn-->
  21. <!-- v-for="(item,index) in props.columns"-->
  22. <!-- v-bind="columnBind(item)"-->
  23. <!-- >-->
  24. <!-- <template-->
  25. <!-- #header-->
  26. <!-- v-if="props.store.props.isEditor">-->
  27. <!-- <el-input-->
  28. <!-- v-model="columns[index].title"-->
  29. <!-- @focus="handleFocus(columns?.[index].field)"-->
  30. <!-- />-->
  31. <!-- </template>-->
  32. <!-- <template-->
  33. <!-- #default="{row , $rowIndex}"-->
  34. <!-- v-if="item!.func && item!.func.default"-->
  35. <!-- >-->
  36. <!-- <Component-->
  37. <!-- :is="handleTableColumnDefault?.(row, $rowIndex, item)"-->
  38. <!-- />-->
  39. <!-- </template>-->
  40. <!-- </VxeColumn>-->
  41. <!-- </vxe-table>-->
  42. </template>
  43. <script setup lang="tsx">
  44. import {ComputedRef} from "vue";
  45. import {PageHelpTableName, PageStore} from "@/views/data-base/page-editor-help-v2/page-help-v2";
  46. import XEUtils from "xe-utils";
  47. import {VxeGridProps} from 'vxe-table'
  48. import {VxeGridPropTypes,} from "vxe-pc-ui/types/components/grid";
  49. import {ElInput} from 'element-plus'
  50. const props = defineProps<{
  51. data: any[];
  52. columns: any[];
  53. store: PageStore,
  54. tableRefName: PageHelpTableName,
  55. tableBind: any,
  56. getSlotsData: (code: string) => any
  57. }>()
  58. function handleSlots(slots, tmp) {
  59. for (let key in slots) {
  60. tmp.slots[key] = ({row, rowIndex}) => {
  61. const code = slots[key]
  62. return props.getSlotsData(row, rowIndex, code)
  63. }
  64. }
  65. }
  66. // @ts-ignore
  67. const columnBindComputed: ComputedRef<VxeGridPropTypes.Columns> = computed(() => {
  68. // @ts-ignore
  69. return XEUtils.eachAndReturnList(props!.columns, (item, index) => {
  70. const {func, slots, ...temp} = item
  71. let tmp: any = {...temp, slots: {}}
  72. if (props.store?.props.isEditor) {
  73. tmp.slots.header = () => {
  74. return <ElInput
  75. modelValue={props?.columns[index]?.title}
  76. onUpdate:modelValue={(value) => {
  77. props.columns[index].title = value
  78. }}
  79. onFocus={() => handleFocus(props.columns?.[index].field)}
  80. />
  81. }
  82. }
  83. handleSlots(slots, tmp)
  84. return tmp
  85. });
  86. })
  87. // @ts-ignore
  88. const tableGridComputed: ComputedRef<VxeGridProps> = computed(() => {
  89. console.log(columnBindComputed.value)
  90. return {
  91. data: props.data,
  92. columns: columnBindComputed.value,
  93. expandConfig: {},
  94. height: 'auto',
  95. autoResize: true,
  96. syncResize: false,
  97. columnConfig: {resizable: true},
  98. style: {
  99. width: '100%',
  100. },
  101. rowConfig: {height: 48, isCurrent: true, isHover: true, useKey: true},
  102. scrollX: {enabled: false},
  103. scrollY: {gt: 0, enabled: true},
  104. showOverflow: true,
  105. ...props.tableBind
  106. }
  107. })
  108. function setMainTableRef(el: any) {
  109. if (typeof props.store !== 'undefined') {
  110. props.store[props.tableRefName].value = el
  111. }
  112. }
  113. function handleFocus(field: string) {
  114. if (typeof props.store !== 'undefined') {
  115. props.store!.mainTableRef.value.scrollToColumn(field)
  116. }
  117. }
  118. </script>