VciTable.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import VciScroll from "../other/VciScroll.vue";
  2. import { toVh } from "../../../../other/adapt";
  3. import VciCell from "./VciCell.vue";
  4. import VciEmpty from "../other/VciEmpty.vue";
  5. import { isFoundationType } from "@vci/helper/src/object";
  6. function getValueFromObjectByProp(object, prop) {
  7. const propArray = (prop || "").split(".");
  8. if(isFoundationType(object)) return null;
  9. else {
  10. const p1 = object[propArray[0]];
  11. if(propArray.length <= 1) return p1;
  12. else {
  13. let targetObject = p1;
  14. for (let i = 1; i < propArray.length; i++) {
  15. if(isFoundationType(targetObject)) {
  16. targetObject = "undefined";
  17. break;
  18. }
  19. targetObject = targetObject[propArray[i]];
  20. }
  21. return targetObject;
  22. }
  23. }
  24. }
  25. export default {
  26. functional: true,
  27. name: "VciTable",
  28. props: {
  29. list: {
  30. type: Array,
  31. default: null
  32. },
  33. heightRow: {
  34. type: Number,
  35. default: 28
  36. },
  37. heightRowHeader: {
  38. type: Number,
  39. default: null
  40. },
  41. scrollTheme: {
  42. type: String,
  43. default: "#fff"
  44. },
  45. scrollThemeEnd: {
  46. type: String,
  47. default: "#fff"
  48. }
  49. },
  50. render(h, context) {
  51. const columns = (context.children || []).filter(vn => vn.data.isVciColumn);
  52. const list = context.props.list;
  53. const isEmpty = !(list && list.length);
  54. const heightHeader = toVh(context.props.heightRowHeader || context.props.heightRow);
  55. return h(
  56. "div",
  57. {
  58. class: ["VciTable vci-h-100", context.data.staticClass]
  59. },
  60. [
  61. h(
  62. "div",
  63. {
  64. class: "vt-header",
  65. style: {
  66. height: heightHeader
  67. }
  68. },
  69. [
  70. h(
  71. VciScroll,
  72. {
  73. props: {
  74. visibleHorizontalBar: false
  75. },
  76. ref: "headerScroll"
  77. },
  78. [
  79. h(
  80. "div",
  81. {
  82. class: "vt-tr vci-flex-rml",
  83. style: {
  84. height: heightHeader
  85. }
  86. },
  87. columns.map(vn => {
  88. const props = vn.data.props;
  89. return h(
  90. VciCell,
  91. {
  92. props: {
  93. ...props,
  94. isHeader: true,
  95. value: props.name
  96. }
  97. }
  98. );
  99. })
  100. )
  101. ]
  102. )
  103. ]
  104. ),
  105. h(
  106. "div",
  107. {
  108. class: "vt-body",
  109. style: { height: `calc(100% - ${heightHeader})` }
  110. },
  111. [
  112. h(
  113. VciScroll,
  114. {
  115. ref: "bodyScroll",
  116. props: {
  117. theme: context.props.scrollTheme,
  118. themeEnd: context.props.scrollThemeEnd
  119. },
  120. on: {
  121. scroll(e) {
  122. context.parent.$refs.headerScroll.scrollLeft(e.left);
  123. }
  124. }
  125. },
  126. isEmpty ?
  127. [
  128. h(
  129. VciEmpty,
  130. {
  131. class: "vci-flex-rcm",
  132. style: {
  133. paddingTop: "4vh"
  134. },
  135. props: { text: "暂无数据" }
  136. }
  137. )
  138. ]
  139. : list.map((item, i) => h(
  140. "div",
  141. {
  142. class: ["vt-tr vci-flex-rml", i % 2 === 0 ? "vtr-even" : "vtr-odd"]
  143. },
  144. columns.map((vn, iv) => {
  145. const props = vn.data.props;
  146. return h(
  147. VciCell,
  148. {
  149. props: {
  150. ...props,
  151. height: props.height ? props.height : context.props.heightRow,
  152. isLastColumn: iv === columns.length - 1,
  153. value: props.isOrderNumber ? (i + 1) : getValueFromObjectByProp(item, props.prop),
  154. item
  155. },
  156. scopedSlots: vn.data.scopedSlots
  157. }
  158. );
  159. })
  160. ))
  161. )
  162. ]
  163. )
  164. ]
  165. );
  166. }
  167. };