config.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index = require('../../checkbox/index.js');
  5. var index$1 = require('../../icon/index.js');
  6. var iconsVue = require('@element-plus/icons-vue');
  7. require('../../../utils/index.js');
  8. var objects = require('../../../utils/objects.js');
  9. const defaultClassNames = {
  10. selection: "table-column--selection",
  11. expand: "table__expand-column"
  12. };
  13. const cellStarts = {
  14. default: {
  15. order: ""
  16. },
  17. selection: {
  18. width: 48,
  19. minWidth: 48,
  20. realWidth: 48,
  21. order: ""
  22. },
  23. expand: {
  24. width: 48,
  25. minWidth: 48,
  26. realWidth: 48,
  27. order: ""
  28. },
  29. index: {
  30. width: 48,
  31. minWidth: 48,
  32. realWidth: 48,
  33. order: ""
  34. }
  35. };
  36. const getDefaultClassName = (type) => {
  37. return defaultClassNames[type] || "";
  38. };
  39. const cellForced = {
  40. selection: {
  41. renderHeader({ store }) {
  42. function isDisabled() {
  43. return store.states.data.value && store.states.data.value.length === 0;
  44. }
  45. return vue.h(index.ElCheckbox, {
  46. disabled: isDisabled(),
  47. size: store.states.tableSize.value,
  48. indeterminate: store.states.selection.value.length > 0 && !store.states.isAllSelected.value,
  49. "onUpdate:modelValue": store.toggleAllSelection,
  50. modelValue: store.states.isAllSelected.value
  51. });
  52. },
  53. renderCell({
  54. row,
  55. column,
  56. store,
  57. $index
  58. }) {
  59. return vue.h(index.ElCheckbox, {
  60. disabled: column.selectable ? !column.selectable.call(null, row, $index) : false,
  61. size: store.states.tableSize.value,
  62. onChange: () => {
  63. store.commit("rowSelectedChanged", row);
  64. },
  65. onClick: (event) => event.stopPropagation(),
  66. modelValue: store.isSelected(row)
  67. });
  68. },
  69. sortable: false,
  70. resizable: false
  71. },
  72. index: {
  73. renderHeader({ column }) {
  74. return column.label || "#";
  75. },
  76. renderCell({
  77. column,
  78. $index
  79. }) {
  80. let i = $index + 1;
  81. const index = column.index;
  82. if (typeof index === "number") {
  83. i = $index + index;
  84. } else if (typeof index === "function") {
  85. i = index($index);
  86. }
  87. return vue.h("div", {}, [i]);
  88. },
  89. sortable: false
  90. },
  91. expand: {
  92. renderHeader({ column }) {
  93. return column.label || "";
  94. },
  95. renderCell({
  96. row,
  97. store,
  98. expanded
  99. }) {
  100. const { ns } = store;
  101. const classes = [ns.e("expand-icon")];
  102. if (expanded) {
  103. classes.push(ns.em("expand-icon", "expanded"));
  104. }
  105. const callback = function(e) {
  106. e.stopPropagation();
  107. store.toggleRowExpansion(row);
  108. };
  109. return vue.h("div", {
  110. class: classes,
  111. onClick: callback
  112. }, {
  113. default: () => {
  114. return [
  115. vue.h(index$1.ElIcon, null, {
  116. default: () => {
  117. return [vue.h(iconsVue.ArrowRight)];
  118. }
  119. })
  120. ];
  121. }
  122. });
  123. },
  124. sortable: false,
  125. resizable: false
  126. }
  127. };
  128. function defaultRenderCell({
  129. row,
  130. column,
  131. $index
  132. }) {
  133. var _a;
  134. const property = column.property;
  135. const value = property && objects.getProp(row, property).value;
  136. if (column && column.formatter) {
  137. return column.formatter(row, column, value, $index);
  138. }
  139. return ((_a = value == null ? void 0 : value.toString) == null ? void 0 : _a.call(value)) || "";
  140. }
  141. function treeCellPrefix({
  142. row,
  143. treeNode,
  144. store
  145. }, createPlacehoder = false) {
  146. const { ns } = store;
  147. if (!treeNode) {
  148. if (createPlacehoder) {
  149. return [
  150. vue.h("span", {
  151. class: ns.e("placeholder")
  152. })
  153. ];
  154. }
  155. return null;
  156. }
  157. const ele = [];
  158. const callback = function(e) {
  159. e.stopPropagation();
  160. if (treeNode.loading) {
  161. return;
  162. }
  163. store.loadOrToggle(row);
  164. };
  165. if (treeNode.indent) {
  166. ele.push(vue.h("span", {
  167. class: ns.e("indent"),
  168. style: { "padding-left": `${treeNode.indent}px` }
  169. }));
  170. }
  171. if (typeof treeNode.expanded === "boolean" && !treeNode.noLazyChildren) {
  172. const expandClasses = [
  173. ns.e("expand-icon"),
  174. treeNode.expanded ? ns.em("expand-icon", "expanded") : ""
  175. ];
  176. let icon = iconsVue.ArrowRight;
  177. if (treeNode.loading) {
  178. icon = iconsVue.Loading;
  179. }
  180. ele.push(vue.h("div", {
  181. class: expandClasses,
  182. onClick: callback
  183. }, {
  184. default: () => {
  185. return [
  186. vue.h(index$1.ElIcon, { class: { [ns.is("loading")]: treeNode.loading } }, {
  187. default: () => [vue.h(icon)]
  188. })
  189. ];
  190. }
  191. }));
  192. } else {
  193. ele.push(vue.h("span", {
  194. class: ns.e("placeholder")
  195. }));
  196. }
  197. return ele;
  198. }
  199. exports.cellForced = cellForced;
  200. exports.cellStarts = cellStarts;
  201. exports.defaultRenderCell = defaultRenderCell;
  202. exports.getDefaultClassName = getDefaultClassName;
  203. exports.treeCellPrefix = treeCellPrefix;
  204. //# sourceMappingURL=config.js.map