stellar-ui-v2 1.35.3

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 (141) hide show
  1. package/common/css/common.scss +61 -0
  2. package/components/ste-animate/README.md +117 -0
  3. package/components/ste-animate/animate.scss +247 -0
  4. package/components/ste-animate/ste-animate.vue +200 -0
  5. package/components/ste-badge/README.md +171 -0
  6. package/components/ste-badge/ste-badge.vue +238 -0
  7. package/components/ste-barcode/README.md +36 -0
  8. package/components/ste-barcode/encode2.js +317 -0
  9. package/components/ste-barcode/ste-barcode.vue +213 -0
  10. package/components/ste-button/README.md +129 -0
  11. package/components/ste-button/ste-button.vue +345 -0
  12. package/components/ste-calendar/README.md +304 -0
  13. package/components/ste-calendar/self-date.js +119 -0
  14. package/components/ste-calendar/ste-calendar.vue +578 -0
  15. package/components/ste-checkbox/README.md +297 -0
  16. package/components/ste-checkbox/ste-checkbox.vue +305 -0
  17. package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
  18. package/components/ste-code-input/README.md +67 -0
  19. package/components/ste-code-input/ste-code-input.vue +302 -0
  20. package/components/ste-date-picker/README.md +135 -0
  21. package/components/ste-date-picker/ste-date-picker.vue +407 -0
  22. package/components/ste-drag/README.md +103 -0
  23. package/components/ste-drag/ste-drag.vue +203 -0
  24. package/components/ste-dropdown-menu/README.md +358 -0
  25. package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
  26. package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
  27. package/components/ste-icon/README.md +90 -0
  28. package/components/ste-icon/iconfont.css +8 -0
  29. package/components/ste-icon/ste-icon.vue +147 -0
  30. package/components/ste-image/README.md +154 -0
  31. package/components/ste-image/ste-image.vue +218 -0
  32. package/components/ste-index-item/ste-index-item.vue +96 -0
  33. package/components/ste-index-list/README.md +153 -0
  34. package/components/ste-index-list/ste-index-list.vue +128 -0
  35. package/components/ste-input/README.md +146 -0
  36. package/components/ste-input/ste-input.vue +480 -0
  37. package/components/ste-loading/README.md +81 -0
  38. package/components/ste-loading/ste-loading.vue +166 -0
  39. package/components/ste-media-preview/README.md +243 -0
  40. package/components/ste-media-preview/TouchScaleing.js +102 -0
  41. package/components/ste-media-preview/ste-media-preview.vue +267 -0
  42. package/components/ste-message-box/README.md +217 -0
  43. package/components/ste-message-box/ste-message-box.js +72 -0
  44. package/components/ste-message-box/ste-message-box.vue +380 -0
  45. package/components/ste-notice-bar/README.md +129 -0
  46. package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
  47. package/components/ste-number-keyboard/README.md +246 -0
  48. package/components/ste-number-keyboard/keyboard.vue +140 -0
  49. package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
  50. package/components/ste-picker/ste-picker.vue +258 -0
  51. package/components/ste-popup/README.md +148 -0
  52. package/components/ste-popup/ste-popup.vue +337 -0
  53. package/components/ste-price/README.md +129 -0
  54. package/components/ste-price/ste-price.vue +258 -0
  55. package/components/ste-progress/README.md +87 -0
  56. package/components/ste-progress/ste-progress.vue +200 -0
  57. package/components/ste-qrcode/README.md +50 -0
  58. package/components/ste-qrcode/ste-qrcode.vue +164 -0
  59. package/components/ste-qrcode/uqrcode.js +34 -0
  60. package/components/ste-radio/README.md +286 -0
  61. package/components/ste-radio/ste-radio.vue +293 -0
  62. package/components/ste-radio-group/ste-radio-group.vue +128 -0
  63. package/components/ste-rate/README.md +115 -0
  64. package/components/ste-rate/ste-rate.vue +202 -0
  65. package/components/ste-read-more/README.md +111 -0
  66. package/components/ste-read-more/ste-read-more.vue +133 -0
  67. package/components/ste-rich-text/README.md +31 -0
  68. package/components/ste-rich-text/ste-rich-text.vue +70 -0
  69. package/components/ste-scroll-to/README.md +68 -0
  70. package/components/ste-scroll-to/mixin.js +173 -0
  71. package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
  72. package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
  73. package/components/ste-search/README.md +262 -0
  74. package/components/ste-search/ste-search.vue +547 -0
  75. package/components/ste-select/README.md +434 -0
  76. package/components/ste-select/datapager.vue +62 -0
  77. package/components/ste-select/datetime.vue +106 -0
  78. package/components/ste-select/defaultDate.js +142 -0
  79. package/components/ste-select/ste-select.vue +843 -0
  80. package/components/ste-signature/README.md +105 -0
  81. package/components/ste-signature/ste-signature.vue +220 -0
  82. package/components/ste-slider/README.md +165 -0
  83. package/components/ste-slider/ste-slider.vue +544 -0
  84. package/components/ste-step/ste-step.vue +264 -0
  85. package/components/ste-stepper/README.md +170 -0
  86. package/components/ste-stepper/ste-stepper.vue +373 -0
  87. package/components/ste-steps/README.md +132 -0
  88. package/components/ste-steps/ste-steps.vue +65 -0
  89. package/components/ste-sticky/README.md +52 -0
  90. package/components/ste-sticky/ste-sticky.vue +127 -0
  91. package/components/ste-swipe-action/README.md +197 -0
  92. package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
  93. package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
  94. package/components/ste-swiper/README.md +173 -0
  95. package/components/ste-swiper/ste-swiper.vue +462 -0
  96. package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
  97. package/components/ste-switch/README.md +110 -0
  98. package/components/ste-switch/ste-switch.vue +144 -0
  99. package/components/ste-tab/ste-tab.vue +87 -0
  100. package/components/ste-table/README.md +785 -0
  101. package/components/ste-table/common.js +8 -0
  102. package/components/ste-table/ste-table.vue +666 -0
  103. package/components/ste-table/utils.js +20 -0
  104. package/components/ste-table-column/checkbox-icon.vue +65 -0
  105. package/components/ste-table-column/common.scss +65 -0
  106. package/components/ste-table-column/radio-icon.vue +110 -0
  107. package/components/ste-table-column/ste-table-column.vue +255 -0
  108. package/components/ste-table-column/sub-table.vue +116 -0
  109. package/components/ste-table-column/table-popover.vue +204 -0
  110. package/components/ste-table-column/var.scss +1 -0
  111. package/components/ste-tabs/README.md +475 -0
  112. package/components/ste-tabs/props.js +212 -0
  113. package/components/ste-tabs/ste-tabs.vue +758 -0
  114. package/components/ste-text/README.md +66 -0
  115. package/components/ste-text/ste-text.vue +72 -0
  116. package/components/ste-toast/README.md +243 -0
  117. package/components/ste-toast/ste-toast.js +69 -0
  118. package/components/ste-toast/ste-toast.vue +231 -0
  119. package/components/ste-touch-swipe/README.md +104 -0
  120. package/components/ste-touch-swipe/TouchEvent.js +72 -0
  121. package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
  122. package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
  123. package/components/ste-tour/README.md +194 -0
  124. package/components/ste-tour/ste-tour.vue +355 -0
  125. package/components/ste-tree/README.md +240 -0
  126. package/components/ste-tree/ste-tree.vue +350 -0
  127. package/components/ste-upload/README.md +276 -0
  128. package/components/ste-upload/ReadFile.js +229 -0
  129. package/components/ste-upload/ste-upload.vue +526 -0
  130. package/components/ste-video/README.md +60 -0
  131. package/components/ste-video/props.js +149 -0
  132. package/components/ste-video/ste-video.vue +647 -0
  133. package/config/color.js +22 -0
  134. package/index.js +2 -0
  135. package/package.json +19 -0
  136. package/utils/Color.js +66 -0
  137. package/utils/System.js +110 -0
  138. package/utils/dayjs.min.js +1 -0
  139. package/utils/mixin.js +67 -0
  140. package/utils/store.js +7 -0
  141. package/utils/utils.js +604 -0
@@ -0,0 +1,8 @@
1
+ export const DEFAULT_SUM_TEXT = '合计';
2
+
3
+ export const selectionColorConfig = {
4
+ main: '#3491FA',
5
+ unSelected: '#BBBBBB',
6
+ disabled: '#E6E6E6',
7
+ readonly: 'rgba(52, 145, 250, 0.4)'
8
+ }
@@ -0,0 +1,666 @@
1
+ <template>
2
+ <view class="ste-table-root" :class="[cmpRootClass]" :style="[cmpRootStyle]">
3
+ <view class="ste-table-content">
4
+ <view class="fixed-placeholder" v-if="fixed || height || height > 0 || maxHeight || maxHeight > 0" />
5
+ <view
6
+ class="ste-table-header"
7
+ :class="[getHeaderRowClass()]"
8
+ :style="[getHeaderRowStyle()]"
9
+ v-if="showHeader"
10
+ >
11
+ <view
12
+ class="ste-table-cell"
13
+ :class="[getHeaderCellClass(column, columnIndex)]"
14
+ :style="[getHeaderCellStyle(column, columnIndex), getHeaderCellStyle(column, columnIndex, true)]"
15
+ v-for="(column, columnIndex) in columns"
16
+ :key="column.prop"
17
+ @click="headerClick(column, $event)"
18
+ >
19
+ <view class="cell-box" v-if="column.type == 'checkbox'">
20
+ <ste-icon
21
+ code="&#xe6ae;"
22
+ :color="selectionIconColor.disabled || selectionColor.disabled"
23
+ :size="checkIconSize"
24
+ v-if="canCheckStates.length === 0"
25
+ />
26
+ <template v-else>
27
+ <ste-icon
28
+ code="&#xe6ac;"
29
+ :color="selectionIconColor.main || selectionColor.main"
30
+ :size="checkIconSize"
31
+ v-if="checkAllState == 'all'"
32
+ @click="changeCheckAll"
33
+ />
34
+ <ste-icon
35
+ code="&#xe6ad;"
36
+ :color="selectionIconColor.main || selectionColor.main"
37
+ :size="checkIconSize"
38
+ v-else-if="checkAllState == 'indeterminate'"
39
+ @click="changeCheckAll"
40
+ />
41
+ <ste-icon
42
+ code="&#xe6af;"
43
+ :color="selectionIconColor.unSelected || selectionColor.unSelected"
44
+ :size="checkIconSize"
45
+ v-else
46
+ @click="changeCheckAll"
47
+ />
48
+ </template>
49
+ </view>
50
+ <view class="cell-box" :class="column.label ? '' : 'no-value'" v-else>
51
+ {{ column.label || '-' }}
52
+ </view>
53
+ </view>
54
+ </view>
55
+ <template v-if="height || height > 0">
56
+ <scroll-view scroll-y class="ste-table-scroll" @scrolltolower="handleScrollToLower">
57
+ <view class="ste-table-body">
58
+ <view
59
+ class="ste-table-row"
60
+ :class="[getRowClass(row, rowIndex)]"
61
+ :style="[getRowStyle(row, rowIndex)]"
62
+ v-for="(row, rowIndex) in tableData"
63
+ :key="rowIndex"
64
+ @click="rowClick(row, $event)"
65
+ >
66
+ <slot :row="row"></slot>
67
+ </view>
68
+ <view class="ste-table-row sum" v-if="showSummary">
69
+ <view
70
+ class="ste-table-cell"
71
+ v-for="(column, index) in columns"
72
+ :key="index"
73
+ :class="[getHeaderCellClass(column)]"
74
+ >
75
+ <view class="cell-box">
76
+ <view v-if="index === 0" class="sum-header">{{ sumText }}</view>
77
+ <view v-else>
78
+ {{ sumData[index] || '-' }}
79
+ </view>
80
+ </view>
81
+ </view>
82
+ </view>
83
+ </view>
84
+ </scroll-view>
85
+ </template>
86
+ <template v-else>
87
+ <view class="ste-table-body">
88
+ <view
89
+ class="ste-table-row"
90
+ :class="[getRowClass(row, rowIndex)]"
91
+ :style="[getRowStyle(row, rowIndex)]"
92
+ v-for="(row, rowIndex) in tableData"
93
+ :key="rowIndex"
94
+ @click="rowClick(row, $event)"
95
+ >
96
+ <slot :row="row"></slot>
97
+ </view>
98
+ <view class="ste-table-row sum" v-if="showSummary">
99
+ <view
100
+ class="ste-table-cell"
101
+ v-for="(column, index) in columns"
102
+ :key="index"
103
+ :class="[getHeaderCellClass(column)]"
104
+ >
105
+ <view class="cell-box">
106
+ <view v-if="index === 0" class="sum-header">{{ sumText }}</view>
107
+ <view v-else>
108
+ {{ sumData[index] || '-' }}
109
+ </view>
110
+ </view>
111
+ </view>
112
+ </view>
113
+ </view>
114
+ </template>
115
+ </view>
116
+ </view>
117
+ </template>
118
+
119
+ <script>
120
+ import utils from '../../utils/utils.js';
121
+ import useColor from '../../config/color.js';
122
+ let color = useColor();
123
+ import { parentMixin } from '../../utils/mixin.js';
124
+ import { getStyleOrClass } from './utils';
125
+ import { DEFAULT_SUM_TEXT, selectionColorConfig } from './common';
126
+ /**
127
+ * ste-table 表格
128
+ * @description 表格。
129
+ * @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-table
130
+ * @property {Array} data 表格数据,默认 []
131
+ * @property {Boolean} fixed 表头是否定位为fixed ,默认 false
132
+ * @property {Number|String} offsetTop 定位fixed时top的距离 默认 0
133
+ * @property {Boolean} border 是否带有纵向边框,默认 false
134
+ * @property {Boolean} stripe 是否斑马纹 ,默认 true
135
+ * @property {String} emptyText 空数据时显示的文本内容,也可以通过 slot="empty" 设置 默认 '暂无数据'
136
+ * @property {Boolean} showSummary 是否在表尾显示合计行 ,默认 false
137
+ * @property {String} sumText,合计行第一列的文本,默认 '合计'
138
+ * @property {Function} summaryMethod 自定义的合计计算方法,默认 null
139
+ * @property {Function} selectable 仅对 type=checkbox 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选,默认 null
140
+ * @property {Function} readable 仅对 type=checkbox 的列有效,类型为 Function,Function 的返回值用来决定这一行的 CheckBox 是否可以勾选,默认 null
141
+ * @property {Function} formatter 格式化单元格方法,需要配合TableColumn中的customKey属性
142
+ * @property {Function} header 格式化表头内容的方法,同formatter属性,需要定义customKey属性
143
+ * @property {Function|String} headerRowClassName 表头行的 className 的回调方法,也可以使用字符串为所有表头行设置一个固定的 className
144
+ * @property {Function|String} headerRowStyle 表头行的 style 的回调方法,也可以使用一个固定的 Object 为所有表头行设置一样的 Style
145
+ * @property {Function|String} headerCellClassName 表头单元格的 className 的回调方法,也可以使用字符串为所有表头单元格设置一个固定的 className
146
+ * @property {Function|String} headerCellStyle 表头单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有表头单元格设置一样的 Style
147
+ * @property {Function|String} rowClassName 行的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className
148
+ * @property {Function|String} rowStyle 行的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style
149
+ * @property {Function|String} cellClassName 单元格的 className 的回调方法,也可以使用字符串为所有行设置一个固定的 className
150
+ * @property {Function|String} cellStyle 单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有行设置一样的 Style
151
+ * @property {Boolean} highlightCurrentRow 是否要高亮当前行
152
+ * @property {Boolean} highlightSelectionRow 是否要高亮复选框选中行(仅针对开启 checkbox 有效)
153
+ * @property {Boolean} showHeader 是否显示表头
154
+ * @property {Number|String} height 表格高度
155
+ * @property {Number|String} maxHeight 表格最大高度
156
+ * @property {Object} selectionIconColor 配置选择项图标色
157
+ * @property {Boolean} isPopover 是否为超出单元格时气泡显示内容
158
+ * @event {Function} select 当用户手动勾选数据行的 Checkbox 时触发的事件
159
+ * @event {Function} selectAll 当用户手动勾选全选 Checkbox 时触发的事件
160
+ * @event {Function} cellClick 当某个单元格被点击时会触发该事件
161
+ * @event {Function} rowClick 当某一行被点击时会触发该事件
162
+ * @event {Function} headerClick 当某一列的表头被点击时会触发该事件
163
+ */
164
+ export default {
165
+ group: '展示组件',
166
+ title: 'Table 表格',
167
+ name: 'ste-table',
168
+ mixins: [parentMixin('ste-table')],
169
+ props: {
170
+ data: {
171
+ type: [Array, null],
172
+ default: () => [],
173
+ },
174
+ sticky: [Boolean, null],
175
+ offsetTop: {
176
+ type: [Number, String, null],
177
+ default: 0,
178
+ },
179
+ border: [Boolean, null],
180
+ stripe: {
181
+ type: [Boolean, null],
182
+ default: true,
183
+ },
184
+ emptyText: [String, null],
185
+ // 表尾显示合计行
186
+ showSummary: [Boolean, null],
187
+ sumText: {
188
+ type: [String, null],
189
+ default: DEFAULT_SUM_TEXT,
190
+ },
191
+ summaryMethod: {
192
+ type: [Function, null],
193
+ default: null,
194
+ },
195
+ selectable: {
196
+ type: [Function, null],
197
+ default: null,
198
+ },
199
+ readable: {
200
+ type: [Function, null],
201
+ default: null,
202
+ },
203
+ fixed: Boolean,
204
+ formatter: {
205
+ type: [Function, null],
206
+ default: null,
207
+ },
208
+ header: {
209
+ type: [Function, null, String],
210
+ default: null,
211
+ },
212
+ height: [Number, String, null],
213
+ headerRowClassName: [String, Function, null],
214
+ headerRowStyle: [Object, Function, null],
215
+ headerCellClassName: [String, Function, null],
216
+ headerCellStyle: [Object, Function, null],
217
+ rowClassName: [String, Function, null],
218
+ rowStyle: [Object, Function, null],
219
+ cellClassName: [String, Function, null],
220
+ cellStyle: [Object, Function, null],
221
+ highlightCurrentRow: [Boolean, null],
222
+ highlightSelectionRow: [Boolean, null],
223
+ showHeader: {
224
+ type: [Boolean, null],
225
+ default: true,
226
+ },
227
+ maxHeight: [Number, String, null],
228
+ selectionIconColor: {
229
+ type: [Object, null],
230
+ default: () => selectionColorConfig,
231
+ },
232
+ isPopover: [Boolean, null],
233
+ },
234
+ data() {
235
+ return {
236
+ tableData: [],
237
+ columns: [],
238
+ sumData: [],
239
+ currentRow: null,
240
+ // column组件中的选中状态
241
+ checkStatesSet: new Set(),
242
+ checkStates: [],
243
+ canCheckStates: [],
244
+ checkAllState: 'none', // none 未选中、indeterminate 半选中、all 全选中
245
+ selectType: '', // 表格选中的类型 checkbox(多选) 或 radio(单选)
246
+ checkIconSize: 36,
247
+ selectionColor: selectionColorConfig,
248
+ };
249
+ },
250
+ computed: {
251
+ cmpRootStyle() {
252
+ let style = {
253
+ '--offset-top': this.offsetTop,
254
+ '--table-height': utils.addUnit(this.height),
255
+ '--table-max-height': utils.addUnit(this.maxHeight),
256
+ '--ste-theme-color': utils.Color.hex2rgba(color.getColor().steThemeColor, 0.05),
257
+ };
258
+ return style;
259
+ },
260
+ cmpRootClass() {
261
+ let classArr = [];
262
+ if (this.fixed) {
263
+ classArr.push('fixed');
264
+ }
265
+ if (this.border) {
266
+ classArr.push('border');
267
+ }
268
+ if (this.stripe) {
269
+ classArr.push('stripe');
270
+ }
271
+ if (this.height || this.height > 0) {
272
+ classArr.push('scroll-table');
273
+ }
274
+ return classArr.join(' ');
275
+ },
276
+ },
277
+ created() {},
278
+ mounted() {},
279
+ watch: {
280
+ children: {
281
+ handler(val) {
282
+ this.initRowData();
283
+ this.initColumns(val);
284
+ },
285
+ immediate: true,
286
+ },
287
+ data: {
288
+ handler(val) {
289
+ this.tableData = val;
290
+ this.initRowData();
291
+ this.calcSum();
292
+ this.initSelection();
293
+ },
294
+ immediate: true,
295
+ },
296
+ },
297
+ methods: {
298
+ initSpanNum() {
299
+ const rows = this.tableData.length;
300
+ const cols = this.columnChilds.length / rows;
301
+ this.columnChilds.forEach((e, i) => {
302
+ let rowSpan = 1;
303
+ let colSpan = 1;
304
+ const rowIndex = Math.floor(i / cols);
305
+ const colIndex = i % cols;
306
+ const fn = this.spanMethod;
307
+ if (typeof fn === 'function') {
308
+ const result = fn(null, null, rowIndex, colIndex);
309
+ if (Array.isArray(result)) {
310
+ rowSpan = result[0];
311
+ colSpan = result[1];
312
+ } else if (typeof result === 'object') {
313
+ rowSpan = result.rowSpan;
314
+ colSpan = result.colSpan;
315
+ }
316
+ }
317
+ e.rowSpan = rowSpan;
318
+ e.colSpan = colSpan;
319
+ });
320
+ },
321
+ // 给子组件的row中赋值
322
+ initRowData() {
323
+ const rowNums = this.tableData.length; // 有多少行
324
+ const colNums = this.children.length / rowNums; // 有多少列
325
+
326
+ this.children.forEach((child, index) => {
327
+ const rowIndex = Math.floor(index / colNums); // 计算出当前元素属于哪一行
328
+ const colIndex = index % colNums; // 计算出当前元素属于哪一列
329
+ const row = this.tableData[rowIndex];
330
+ child.row = { ...row, rowIndex, colIndex };
331
+ });
332
+ },
333
+ initColumns(childs) {
334
+ if (!childs || childs.length <= 0) return;
335
+ let all = childs
336
+ .filter((node) => node.$options && node.$options.name === 'ste-table-column')
337
+ .map((node) => {
338
+ let obj = node.$options.propsData;
339
+ obj._uid = node._uid;
340
+ return obj;
341
+ });
342
+ const result = [];
343
+ const partSize = Math.ceil(all.length / this.tableData.length);
344
+ for (let i = 0; i < partSize; i++) {
345
+ result.push(all[i]);
346
+ }
347
+
348
+ this.columns = result.map((e) => {
349
+ if (!e.label && this.header && typeof this.header === 'function') {
350
+ e.label = this.header(e, this.tableData);
351
+ }
352
+ return e;
353
+ });
354
+
355
+ this.calcSum();
356
+ this.loadSelectType();
357
+ this.loadCanCheckArr();
358
+ },
359
+ // 重新计算选择项
360
+ initSelection() {
361
+ this.loadCanCheckArr();
362
+ this.checkStates = this.checkStates.filter((e) => this.canCheckStates.indexOf(e) > -1);
363
+ this.calcAllState();
364
+ },
365
+ // 获取当前表格选中类型(单选或多选)
366
+ loadSelectType() {
367
+ this.columns.forEach((e) => {
368
+ if (e.type) {
369
+ this.selectType = e.type;
370
+ return;
371
+ }
372
+ });
373
+ },
374
+ // 根据传入的selectable方法获取所有可选择的行
375
+ loadCanCheckArr() {
376
+ let tmp = [];
377
+ this.tableData.forEach((e, index) => {
378
+ let selectFlag = this.selectable ? this.selectable(e, index) : true;
379
+ let readonlyFlag = this.readable ? !this.readable(e, index) : true;
380
+
381
+ if (selectFlag && readonlyFlag) {
382
+ tmp.push(index);
383
+ }
384
+ });
385
+ this.canCheckStates = tmp;
386
+ },
387
+ // 更改表头选中项的状态
388
+ changeCheckAll() {
389
+ if (this.checkAllState !== 'all') {
390
+ this.$emit(
391
+ 'selectAll',
392
+ this.canCheckStates.map((e) => this.tableData[e])
393
+ );
394
+ } else {
395
+ this.$emit('selectAll', []);
396
+ }
397
+ this.toggleAllSelection();
398
+ },
399
+ // column组件更改Check状态
400
+ handleCheck(row, isEmit = true) {
401
+ let rowIndex = row.rowIndex;
402
+ let state = !this.checkStatesSet.has(rowIndex);
403
+ if (this.selectType === 'radio') {
404
+ this.checkStatesSet = new Set();
405
+ this.checkStatesSet.add(rowIndex);
406
+ } else {
407
+ if (state) {
408
+ this.checkStatesSet.add(rowIndex);
409
+ } else {
410
+ this.checkStatesSet.delete(rowIndex);
411
+ }
412
+ }
413
+ this.checkStates = Array.from(this.checkStatesSet);
414
+
415
+ isEmit && this.$emit('select', this.getSelection(), row);
416
+ // this.currentRow = row;
417
+
418
+ this.calcAllState();
419
+ this.$forceUpdate();
420
+ },
421
+ calcAllState() {
422
+ // 处理当前全选框的状态
423
+ if (this.checkStates.length > 0) {
424
+ if (this.canCheckStates.length === this.checkStates.length) {
425
+ this.checkAllState = 'all';
426
+ } else {
427
+ this.checkAllState = 'indeterminate';
428
+ }
429
+ } else {
430
+ this.checkAllState = 'none';
431
+ }
432
+ },
433
+ // 计算合计项
434
+ calcSum() {
435
+ if (!this.summaryMethod) return;
436
+ this.sumData = this.summaryMethod({ columns: this.columns, data: this.tableData });
437
+ },
438
+ cellClick(row, column, event) {
439
+ this.$emit('cellClick', row, column, event);
440
+ },
441
+ rowClick(row, event) {
442
+ this.currentRow = row;
443
+ this.$emit('rowClick', row, event);
444
+ },
445
+ headerClick(column, event) {
446
+ this.$emit('headerClick', column, event);
447
+ },
448
+ handleScrollToLower() {
449
+ this.$emit('scrollToLower');
450
+ },
451
+ // ***自定义class和style相关***
452
+ getHeaderRowClass() {
453
+ const classes = [getStyleOrClass(this.headerRowClassName, null, false)];
454
+ return classes.join(' ');
455
+ },
456
+ getHeaderRowStyle() {
457
+ return getStyleOrClass(this.headerRowStyle);
458
+ },
459
+ getHeaderCellClass(column, columnIndex) {
460
+ let classArr = [];
461
+ if (column.headerAlign && column.headerAlign !== 'left') {
462
+ classArr.push('align-' + column.headerAlign);
463
+ } else if (column.align && column.align !== 'left') {
464
+ classArr.push('align-' + column.align);
465
+ }
466
+
467
+ classArr.push(getStyleOrClass(this.headerCellClassName, { columnIndex, column }, false));
468
+ return classArr.join(' ');
469
+ },
470
+ getHeaderCellStyle(column, columnIndex, isProp = false) {
471
+ if (!isProp) {
472
+ let style = {};
473
+ if (column.width) {
474
+ // style.width = utils.addUnit(column.width);
475
+ // style.flexBasis = utils.addUnit(column.width);
476
+ style.flex = `0 1 ${utils.addUnit(column.width)}`;
477
+ }
478
+ if (column.minWidth) {
479
+ style.minWidth = utils.addUnit(column.minWidth);
480
+ }
481
+ return style;
482
+ } else {
483
+ return getStyleOrClass(this.headerCellStyle, { columnIndex, column });
484
+ }
485
+ },
486
+ getRowClass(row, rowIndex) {
487
+ const classArr = [`row-${rowIndex}`];
488
+ if (this.highlightCurrentRow && utils.deepEqual(row, this.currentRow, ['rowIndex', 'colIndex'])) {
489
+ classArr.push('current-row');
490
+ }
491
+ if (this.highlightSelectionRow && this.checkStatesSet.has(rowIndex)) {
492
+ classArr.push('selection-row');
493
+ }
494
+
495
+ classArr.push(getStyleOrClass(this.rowClassName, { row, rowIndex }, false));
496
+ return classArr.join(' ');
497
+ },
498
+ getRowStyle(row, rowIndex) {
499
+ return getStyleOrClass(this.rowStyle, { row, rowIndex });
500
+ },
501
+ // ***Table Methods 方法***
502
+ // 获取当前选择的数据
503
+ getSelection() {
504
+ return this.checkStates.map((e) => this.tableData[e]);
505
+ },
506
+ // 清空选择项
507
+ clearSelection() {
508
+ this.checkStatesSet.clear();
509
+ this.checkStates = Array.from(this.checkStatesSet);
510
+ this.checkAllState = 'none';
511
+ },
512
+ // 切换某行的选中状态
513
+ toggleRowSelection(row, isTriggerSelectEvent = true) {
514
+ this.$nextTick(() => {
515
+ let index = this.tableData.findIndex((e) => utils.deepEqual(row, e, ['rowIndex', 'colIndex']));
516
+ if (this.canCheckStates.indexOf(index) <= -1) return;
517
+ row.rowIndex = index;
518
+ this.handleCheck(row, isTriggerSelectEvent);
519
+ });
520
+ },
521
+ // 切换全选的状态
522
+ toggleAllSelection() {
523
+ if (this.checkAllState === 'all') {
524
+ this.clearSelection();
525
+ } else {
526
+ this.canCheckStates.forEach((e) => {
527
+ this.checkStatesSet.add(e);
528
+ });
529
+ this.checkStates = Array.from(this.checkStatesSet);
530
+ this.checkAllState = 'all';
531
+ }
532
+ },
533
+ },
534
+ };
535
+ </script>
536
+
537
+ <style lang="scss">
538
+ $default-border: 2rpx solid #ebebeb;
539
+
540
+ .ste-table-root {
541
+ width: 100%;
542
+
543
+ &.scroll-table {
544
+ position: relative;
545
+
546
+ .ste-table-content {
547
+ .ste-table-header {
548
+ position: absolute;
549
+ top: 0;
550
+ }
551
+ .ste-table-scroll {
552
+ height: calc(var(--table-height) - 80rpx);
553
+ max-height: calc(var(--table-max-height) - 80rpx);
554
+ }
555
+ }
556
+ }
557
+
558
+ &.fixed {
559
+ .ste-table-content {
560
+ .ste-table-header {
561
+ position: fixed;
562
+ top: var(--offset-top);
563
+ z-index: 101;
564
+ }
565
+ }
566
+ }
567
+ &.border {
568
+ .ste-table-cell {
569
+ border-right: $default-border;
570
+ }
571
+
572
+ .ste-table-content {
573
+ border-left: $default-border;
574
+ }
575
+ }
576
+
577
+ &.stripe {
578
+ .ste-table-body {
579
+ .ste-table-row:nth-child(even) {
580
+ background-color: #f8f8f8; /* 偶数行背景颜色 */
581
+ }
582
+ }
583
+ }
584
+
585
+ .ste-table-content {
586
+ width: 100%;
587
+ // display: table;
588
+ // border-collapse: collapse;
589
+ // table-layout: fixed;
590
+ .fixed-placeholder {
591
+ width: 100%;
592
+ height: 80rpx;
593
+ }
594
+ .ste-table-header {
595
+ width: 100%;
596
+ // display: table-row;
597
+ display: flex;
598
+ justify-content: space-between;
599
+ background-color: var(--ste-theme-color);
600
+
601
+ .ste-table-cell {
602
+ background-color: var(--ste-theme-color);
603
+ font-weight: bold;
604
+ font-size: 28rpx;
605
+ border-top: $default-border;
606
+ // flex: 1;
607
+ // box-sizing: border-box;
608
+
609
+ .cell-box.no-value {
610
+ color: transparent;
611
+ }
612
+ }
613
+ }
614
+
615
+ .ste-table-cell {
616
+ // display: table-cell;
617
+ flex: 1;
618
+ // box-sizing: border-box;
619
+ border-bottom: $default-border;
620
+
621
+ padding: 0 32rpx;
622
+ height: 80rpx;
623
+ font-size: 24rpx;
624
+ overflow-x: hidden;
625
+ .cell-box {
626
+ height: 100%;
627
+ display: flex;
628
+ align-items: center;
629
+ width: 100%;
630
+ }
631
+
632
+ &.align-center {
633
+ .cell-box {
634
+ justify-content: center;
635
+ }
636
+ }
637
+
638
+ &.align-right {
639
+ .cell-box {
640
+ justify-content: flex-end;
641
+ }
642
+ }
643
+ }
644
+
645
+ .ste-table-body {
646
+ // display: table-row-group;
647
+ width: 100%;
648
+ .ste-table-row {
649
+ // display: table-row;
650
+ display: flex;
651
+ justify-content: space-between;
652
+ &.current-row {
653
+ background-color: #ecf5ff;
654
+ }
655
+ &.selection-row {
656
+ background-color: #ecf5ff;
657
+ }
658
+ }
659
+ }
660
+ }
661
+
662
+ scoped-slots-default {
663
+ display: contents;
664
+ }
665
+ }
666
+ </style>
@@ -0,0 +1,20 @@
1
+ function getStyleOrClass(fun, params, isStyle = true) {
2
+ if (isStyle) {
3
+ if (typeof fun === 'function') {
4
+ return fun.call(null, params);
5
+ } else {
6
+ return fun;
7
+ }
8
+ } else {
9
+ if (typeof fun === 'string') {
10
+ return fun;
11
+ } else if (typeof fun === 'function') {
12
+ return fun.call(null, params)
13
+ }
14
+ }
15
+
16
+ }
17
+
18
+ export {
19
+ getStyleOrClass
20
+ }