@kyfe/ks-query-table 0.0.22 → 0.0.24
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.
- package/index.js +11 -0
- package/package.json +10 -81
- package/.bitmap +0 -38
- package/.editorconfig +0 -5
- package/.env.dev +0 -2
- package/.env.gray +0 -2
- package/.env.prod +0 -2
- package/.env.stg +0 -3
- package/.env.uat +0 -2
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -25
- package/.gitmodules +0 -4
- package/.prettierrc +0 -11
- package/README.md +0 -15
- package/babel.config.js +0 -10
- package/build-apm.sh +0 -9
- package/build.sh +0 -16
- package/config/index.js +0 -20
- package/jsconfig.json +0 -7
- package/kuasheng-sdk/index.js +0 -80
- package/kuasheng-sdk/lib/assets.js +0 -304
- package/kuasheng-sdk/lib/context.js +0 -199
- package/kuasheng-sdk/lib/layout.js +0 -346
- package/kuasheng-sdk/lib/location.js +0 -46
- package/kuasheng-sdk/lib/media.js +0 -342
- package/kuasheng-sdk/lib/navigation.js +0 -30
- package/kuasheng-sdk/lib/request.js +0 -76
- package/kuasheng-sdk/lib/system.js +0 -190
- package/kuasheng-sdk/lib/userinfo.js +0 -98
- package/kuasheng-sdk/util/check.js +0 -102
- package/kuasheng-sdk/util/config.js +0 -47
- package/kuasheng-sdk/util/device.js +0 -25
- package/kuasheng-sdk/util/error.js +0 -19
- package/kuasheng-sdk/util/funtional.js +0 -153
- package/kuasheng-sdk/util/mixin.js +0 -36
- package/kuasheng-sdk/util/requestUtil.js +0 -41
- package/kuasheng-sdk/util/response.js +0 -33
- package/kuasheng-sdk/util/warn.js +0 -35
- package/kuasheng-ui/CHANGELOG.md +0 -9
- package/kuasheng-ui/components/card.vue +0 -57
- package/kuasheng-ui/components/ks-area-select/README.md +0 -43
- package/kuasheng-ui/components/ks-area-select/area-picker.vue +0 -554
- package/kuasheng-ui/components/ks-area-select/area-search.vue +0 -363
- package/kuasheng-ui/components/ks-area-select/areas-pop.vue +0 -56
- package/kuasheng-ui/components/ks-area-select/common.js +0 -183
- package/kuasheng-ui/components/ks-area-select/index.vue +0 -355
- package/kuasheng-ui/components/ks-area-select/mixins.js +0 -216
- package/kuasheng-ui/components/ks-area-single-select/README.md +0 -50
- package/kuasheng-ui/components/ks-area-single-select/hot-city.js +0 -45
- package/kuasheng-ui/components/ks-area-single-select/index.vue +0 -324
- package/kuasheng-ui/components/ks-calendar/index.vue +0 -269
- package/kuasheng-ui/components/ks-call-phone/call-tips.vue +0 -70
- package/kuasheng-ui/components/ks-call-phone/call.vue +0 -178
- package/kuasheng-ui/components/ks-call-phone/index.js +0 -48
- package/kuasheng-ui/components/ks-call-phone/index.vue +0 -131
- package/kuasheng-ui/components/ks-call-phone//345/221/274/345/217/253/347/273/204/344/273/266.md +0 -0
- package/kuasheng-ui/components/ks-date-picker/README.md +0 -23
- package/kuasheng-ui/components/ks-date-picker/date-picker-bottom.vue +0 -123
- package/kuasheng-ui/components/ks-date-picker/date-picker-dropdown.vue +0 -80
- package/kuasheng-ui/components/ks-date-picker/date-picker-right.vue +0 -87
- package/kuasheng-ui/components/ks-date-picker/date-picker-top.vue +0 -88
- package/kuasheng-ui/components/ks-date-picker/date-picker.js +0 -15
- package/kuasheng-ui/components/ks-date-picker/date-range-select.vue +0 -92
- package/kuasheng-ui/components/ks-date-picker/date-select.vue +0 -65
- package/kuasheng-ui/components/ks-date-picker/date-week-month.vue +0 -131
- package/kuasheng-ui/components/ks-date-picker/index.js +0 -12
- package/kuasheng-ui/components/ks-date-picker/mixin.js +0 -92
- package/kuasheng-ui/components/ks-date-picker/month-range-select.vue +0 -129
- package/kuasheng-ui/components/ks-date-picker/month-select.vue +0 -85
- package/kuasheng-ui/components/ks-date-picker/quarter-select.vue +0 -94
- package/kuasheng-ui/components/ks-date-picker/style.less +0 -121
- package/kuasheng-ui/components/ks-date-picker/utils.js +0 -109
- package/kuasheng-ui/components/ks-date-picker/week-select.vue +0 -99
- package/kuasheng-ui/components/ks-decrypt/index.vue +0 -159
- package/kuasheng-ui/components/ks-employee/README.md +0 -78
- package/kuasheng-ui/components/ks-employee/employee-input.vue +0 -173
- package/kuasheng-ui/components/ks-employee/employee-list.vue +0 -662
- package/kuasheng-ui/components/ks-employee/employee-popup.vue +0 -197
- package/kuasheng-ui/components/ks-employee/employee-search.vue +0 -250
- package/kuasheng-ui/components/ks-employee/employee-selected.vue +0 -173
- package/kuasheng-ui/components/ks-employee/index.js +0 -17
- package/kuasheng-ui/components/ks-employee/package-lock.json +0 -5
- package/kuasheng-ui/components/ks-employee/package.json +0 -15
- package/kuasheng-ui/components/ks-employee/yarn.lock +0 -4
- package/kuasheng-ui/components/ks-field-money/index.js +0 -8
- package/kuasheng-ui/components/ks-field-money/index.vue +0 -212
- package/kuasheng-ui/components/ks-field-money/package.json +0 -11
- package/kuasheng-ui/components/ks-field-money/utils.js +0 -65
- package/kuasheng-ui/components/ks-field-money//351/207/221/351/242/235/350/275/254/346/215/242/345/231/250.md +0 -0
- package/kuasheng-ui/components/ks-history-search/history-input.vue +0 -131
- package/kuasheng-ui/components/ks-history-search/history-list.vue +0 -188
- package/kuasheng-ui/components/ks-history-search/img/delete.png +0 -0
- package/kuasheng-ui/components/ks-history-search/index.js +0 -9
- package/kuasheng-ui/components/ks-history-search/index.vue +0 -125
- package/kuasheng-ui/components/ks-history-search/package-lock.json +0 -5
- package/kuasheng-ui/components/ks-history-search/package.json +0 -15
- package/kuasheng-ui/components/ks-history-search/utils.js +0 -35
- package/kuasheng-ui/components/ks-input-search/index.vue +0 -106
- package/kuasheng-ui/components/ks-list/index.vue +0 -75
- package/kuasheng-ui/components/ks-loading/index.js +0 -16
- package/kuasheng-ui/components/ks-month/index.vue +0 -47
- package/kuasheng-ui/components/ks-month/package.json +0 -3
- package/kuasheng-ui/components/ks-month/range.vue +0 -172
- package/kuasheng-ui/components/ks-month/single.vue +0 -136
- package/kuasheng-ui/components/ks-month/style.less +0 -125
- package/kuasheng-ui/components/ks-month/utils.js +0 -35
- package/kuasheng-ui/components/ks-nav/index.vue +0 -264
- package/kuasheng-ui/components/ks-nav-bar.js +0 -35
- package/kuasheng-ui/components/ks-org/ks-org-tree.vue +0 -247
- package/kuasheng-ui/components/ks-org/ks-popup-tree.vue +0 -154
- package/kuasheng-ui/components/ks-org/ks-tree-input.vue +0 -240
- package/kuasheng-ui/components/ks-org/ks-tree-node.vue +0 -94
- package/kuasheng-ui/components/ks-org/ks-tree.vue +0 -229
- package/kuasheng-ui/components/ks-org/utils.js +0 -54
- package/kuasheng-ui/components/ks-popover/index.vue +0 -457
- package/kuasheng-ui/components/ks-popover/mixin.js +0 -28
- package/kuasheng-ui/components/ks-popover/utils.js +0 -60
- package/kuasheng-ui/components/ks-pull-refresh/index.vue +0 -43
- package/kuasheng-ui/components/ks-quarter/index.vue +0 -256
- package/kuasheng-ui/components/ks-table/README.md +0 -103
- package/kuasheng-ui/components/ks-table/cell.vue +0 -31
- package/kuasheng-ui/components/ks-table/index.js +0 -8
- package/kuasheng-ui/components/ks-table/index.less +0 -486
- package/kuasheng-ui/components/ks-table/index.vue +0 -1088
- package/kuasheng-ui/components/ks-table/package.json +0 -12
- package/kuasheng-ui/components/ks-table/release.md +0 -7
- package/kuasheng-ui/components/ks-toast.js +0 -35
- package/kuasheng-ui/components/ks-upload/index.vue +0 -174
- package/kuasheng-ui/components/ks-user-access.vue +0 -229
- package/kuasheng-ui/components/no-data/README.md +0 -45
- package/kuasheng-ui/components/no-data/image.js +0 -1
- package/kuasheng-ui/components/no-data/index.vue +0 -83
- package/kuasheng-ui/components/notice-bar.vue +0 -16
- package/kuasheng-ui/components/steps.js +0 -11
- package/kuasheng-ui/components/tabs.vue +0 -40
- package/kuasheng-ui/index.js +0 -239
- package/kuasheng-ui/patch/datetime-picker/datetimePicker.md +0 -0
- package/kuasheng-ui/patch/datetime-picker/index.js +0 -46
- package/kuasheng-ui/patch/datetime-picker/utils.js +0 -78
- package/kuasheng-ui/patch/field/field.md +0 -1
- package/kuasheng-ui/patch/field/index.js +0 -122
- package/kuasheng-ui/patch/field/utils.js +0 -36
- package/kuasheng-ui/patch/form/form.md +0 -7
- package/kuasheng-ui/patch/form/index.js +0 -106
- package/kuasheng-ui/patch/index.js +0 -12
- package/kuasheng-ui/patch/pagination/index.js +0 -78
- package/kuasheng-ui/style/animation-ui.less +0 -31
- package/kuasheng-ui/style/font/number/font-number1.otf +0 -0
- package/kuasheng-ui/style/font/number/font-number2.ttf +0 -0
- package/kuasheng-ui/style/images/checked.svg +0 -1
- package/kuasheng-ui/style/images/success.svg +0 -1
- package/kuasheng-ui/style/index.less +0 -6
- package/kuasheng-ui/style/kuasheng-ui.less +0 -207
- package/kuasheng-ui/style/reset-vant.less +0 -307
- package/kuasheng-ui/style/vant-var.less +0 -138
- package/kuasheng-ui/utils/apis.js +0 -17
- package/kuasheng-ui/utils/axios-adapter.js +0 -47
- package/kuasheng-ui/utils/bem.js +0 -39
- package/kuasheng-ui/utils/bus.js +0 -97
- package/kuasheng-ui/utils/common.js +0 -88
- package/kuasheng-ui/utils/decrypt/config.js +0 -12
- package/kuasheng-ui/utils/decrypt/decrypt-api.js +0 -139
- package/kuasheng-ui/utils/decrypt/index.js +0 -6
- package/kuasheng-ui/utils/decrypt/mask.js +0 -36
- package/kuasheng-ui/utils/decrypt/virtual.js +0 -44
- package/kuasheng-ui/utils/directive.js +0 -57
- package/kuasheng-ui/utils/directive.md +0 -23
- package/kuasheng-ui/utils/drcheck-plugin.js +0 -219
- package/kuasheng-ui/utils/error-plugin.js +0 -88
- package/kuasheng-ui/utils/filter.js +0 -149
- package/kuasheng-ui/utils/http-interceptors.js +0 -18
- package/kuasheng-ui/utils/http.js +0 -140
- package/kuasheng-ui/utils/index.js +0 -5
- package/kuasheng-ui/utils/init-event.js +0 -20
- package/kuasheng-ui/utils/log.js +0 -309
- package/kuasheng-ui/utils/token.js +0 -9
- package/kuasheng-ui/utils/type.js +0 -45
- package/kuasheng-ui/utils/validate.js +0 -20
- package/kuasheng-ui/utils/watermark.js +0 -67
- package/kuasheng-ui/version.js +0 -1
- package/ky-apm/client.js +0 -37
- package/ky-apm/customHttp.js +0 -38
- package/ky-apm/index.js +0 -68
- package/ky-apm/plugins/performance.js +0 -84
- package/ky-apm/plugins/self-error.js +0 -26
- package/ky-apm/warn-log.js +0 -3
- package/plugin/ks-chii-webpack-html/index.js +0 -53
- package/plugin/ks-chii-webpack-html/package.json +0 -16
- package/postcss.config.js +0 -15
- package/public/capsule-positon.js +0 -50
- package/public/fonts/DingTalkJinBuTi.ttf +0 -0
- package/public/framework/axios@0.19.0.min.js +0 -9
- package/public/framework/fastclick@1.0.6.min.js +0 -1
- package/public/framework/iconfont/iconfont.css +0 -91
- package/public/framework/iconfont/iconfont.js +0 -1
- package/public/framework/iconfont/iconfont.json +0 -142
- package/public/framework/iconfont/iconfont.ttf +0 -0
- package/public/framework/iconfont/iconfont.woff +0 -0
- package/public/framework/iconfont/iconfont.woff2 +0 -0
- package/public/framework/vant@2.5.6.min.js +0 -7
- package/public/framework/vue-router@3.1.3.min.js +0 -6
- package/public/framework/vue@2.6.10.runtime.min.js +0 -6
- package/public/framework/vuex@3.1.1.min.js +0 -6
- package/public/index.html +0 -260
- package/public/ks@3.0.8.umd.min.js +0 -1
- package/public/ksui@4.0.27.umd.min.js +0 -10
- package/public/status-bar-preset.js +0 -39
- package/qt-npm/index.js +0 -11
- package/qt-npm/package.json +0 -13
- package/src/App.vue +0 -204
- package/src/README.md +0 -15
- package/src/common/README.md +0 -94
- package/src/common/http/axios-adapter.js +0 -47
- package/src/common/http/common.js +0 -88
- package/src/common/http/http-interceptors.js +0 -18
- package/src/common/http/http-lock.js +0 -45
- package/src/common/http/index.js +0 -163
- package/src/common/http/token.js +0 -9
- package/src/common/styles/font/AlibabaSans102Ver2-Md.ttf +0 -0
- package/src/common/styles/font.less +0 -12
- package/src/common/styles/variables.less +0 -43
- package/src/common/utils/index.js +0 -1
- package/src/common/utils/platform/README.md +0 -1
- package/src/common/utils/platform/android/.gitkeep +0 -0
- package/src/common/utils/platform/core/index.js +0 -24
- package/src/common/utils/platform/index.js +0 -164
- package/src/common/utils/platform/ios/.gitkeep +0 -0
- package/src/common/utils/platform/subscribe/helper.js +0 -38
- package/src/common/utils/platform/subscribe/index.js +0 -204
- package/src/common/utils/platform/subscribe/table-animation.js +0 -75
- package/src/config/index.js +0 -31
- package/src/config.js +0 -1
- package/src/main.js +0 -73
- package/src/router.js +0 -52
- package/src/view/home/config.js +0 -101
- package/src/view/home/demo1.vue +0 -223
- package/src/view/home/demo2.vue +0 -124
- package/src/view/home/demo3.vue +0 -51
- package/src/view/home/demo4.vue +0 -140
- package/src/view/home/index.vue +0 -97
- package/src/view/home/query-table/README.md +0 -45
- package/src/view/home/query-table/api/index.js +0 -12
- package/src/view/home/query-table/assets/horizontal-back.svg +0 -1
- package/src/view/home/query-table/components/pe-table/cell.js +0 -181
- package/src/view/home/query-table/components/pe-table/collapse.js +0 -334
- package/src/view/home/query-table/components/pe-table/empty.vue +0 -48
- package/src/view/home/query-table/components/pe-table/header.js +0 -328
- package/src/view/home/query-table/components/pe-table/images/abnormal.png +0 -0
- package/src/view/home/query-table/components/pe-table/images/empty.png +0 -0
- package/src/view/home/query-table/components/pe-table/images/fold.svg +0 -1
- package/src/view/home/query-table/components/pe-table/images/sort.svg +0 -1
- package/src/view/home/query-table/components/pe-table/images/sorting.svg +0 -1
- package/src/view/home/query-table/components/pe-table/images/unfold.svg +0 -1
- package/src/view/home/query-table/components/pe-table/index.vue +0 -847
- package/src/view/home/query-table/components/pe-table/load-more.js +0 -46
- package/src/view/home/query-table/components/pe-table/props/index.js +0 -193
- package/src/view/home/query-table/components/pe-table/row.vue +0 -118
- package/src/view/home/query-table/components/pe-table/scrollbar.js +0 -424
- package/src/view/home/query-table/components/pe-table/stretch-damping.js +0 -112
- package/src/view/home/query-table/components/pe-table/style/cell.less +0 -89
- package/src/view/home/query-table/components/pe-table/style/empty.less +0 -48
- package/src/view/home/query-table/components/pe-table/style/header.less +0 -141
- package/src/view/home/query-table/components/pe-table/style/index.less +0 -88
- package/src/view/home/query-table/components/pe-table/style/load-more.less +0 -61
- package/src/view/home/query-table/components/pe-table/style/row.less +0 -6
- package/src/view/home/query-table/components/pe-table/table-loading.vue +0 -120
- package/src/view/home/query-table/components/pe-table/table-total.vue +0 -57
- package/src/view/home/query-table/components/pe-table/utils/animate.js +0 -80
- package/src/view/home/query-table/components/pe-table/utils/columns.js +0 -290
- package/src/view/home/query-table/components/pe-table/utils/data.js +0 -12
- package/src/view/home/query-table/components/pe-table/utils/fixed.js +0 -69
- package/src/view/home/query-table/components/pe-table/utils/formatter.js +0 -327
- package/src/view/home/query-table/components/pe-table/utils/render-cells.js +0 -424
- package/src/view/home/query-table/components/pe-table/utils/slot.js +0 -28
- package/src/view/home/query-table/components/pe-table/utils/tools.js +0 -84
- package/src/view/home/query-table/components/pe-table/utils/touch-scroll.js +0 -417
- package/src/view/home/query-table/components/query-table/index.vue +0 -497
- package/src/view/home/query-table/components/query-table/mixins/column-mixin.js +0 -102
- package/src/view/home/query-table/components/query-table/mixins/column-setting.js +0 -143
- package/src/view/home/query-table/components/query-table/mixins/data-mixin.js +0 -519
- package/src/view/home/query-table/components/query-table/mixins/pagination-mixin.js +0 -26
- package/src/view/home/query-table/components/query-table/mixins/table-fixed.js +0 -130
- package/src/view/home/query-table/components/query-table/mixins/table-horizontal.js +0 -119
- package/src/view/home/query-table/components/table-horizontal.vue +0 -99
- package/src/view/home/query-table/components/table-pagination.vue +0 -32
- package/src/view/home/query-table/components/table-settings/assets/arrpw-up.svg +0 -1
- package/src/view/home/query-table/components/table-settings/assets/disabled-down.svg +0 -1
- package/src/view/home/query-table/components/table-settings/assets/disabled-up.svg +0 -1
- package/src/view/home/query-table/components/table-settings/assets/down.svg +0 -1
- package/src/view/home/query-table/components/table-settings/assets/up.svg +0 -1
- package/src/view/home/query-table/components/table-settings/index.less +0 -294
- package/src/view/home/query-table/components/table-settings/index.vue +0 -260
- package/src/view/home/query-table/components/table-settings/settings.vue +0 -479
- package/src/view/home/query-table/components/table-settings/test.js +0 -626
- package/src/view/home/query-table/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
- package/src/view/home/query-table/components/tooltip.js +0 -124
- package/src/view/home/query-table/hooks/use-cache-promise.js +0 -27
- package/src/view/home/query-table/hooks/use-column-config.js +0 -190
- package/src/view/home/query-table/hooks/use-encryption.js +0 -0
- package/src/view/home/query-table/hooks/use-generic-search.js +0 -95
- package/src/view/home/query-table/index.js +0 -7
- package/src/view/home/query-table/store/column-store.js +0 -0
- package/src/view/home/query-table/styles/table.less +0 -24
- package/src/view/home/query-table/utils/column.js +0 -36
- package/src/view/home/query-table/utils/config.js +0 -12
- package/src/view/home/query-table/utils/encryption.js +0 -32
- package/src/view/home/query-table/utils/http.js +0 -1
- package/src/view/home/query-table/utils/localStorage.js +0 -35
- package/src/view/home//351/246/226/351/241/265.md +0 -0
- package/src/web.js +0 -99
- package/vue.config.js +0 -131
|
@@ -1,847 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="pe-table-wrap"
|
|
3
|
-
ref="root"
|
|
4
|
-
:style="rootStyle"
|
|
5
|
-
:class="rootClassName">
|
|
6
|
-
<div ref="container"
|
|
7
|
-
class="pe-table-container">
|
|
8
|
-
<div ref="trackX"
|
|
9
|
-
class="pe-table-scrollbar_horizontal-track"
|
|
10
|
-
:style="state.trackXStyle">
|
|
11
|
-
<div ref="thumbX"
|
|
12
|
-
class="pe-table-scrollbar_horizontal-thumb"
|
|
13
|
-
:class="scrollbarClass" />
|
|
14
|
-
</div>
|
|
15
|
-
<div ref="trackY"
|
|
16
|
-
class="pe-table-scrollbar_vertical-track"
|
|
17
|
-
:style="state.trackYStyle">
|
|
18
|
-
<div ref="thumbY"
|
|
19
|
-
class="pe-table-scrollbar_vertical-thumb"
|
|
20
|
-
:class="scrollbarClass" />
|
|
21
|
-
</div>
|
|
22
|
-
<Empty v-if="isEmpty"
|
|
23
|
-
:isAbnormal="isAbnormal"
|
|
24
|
-
:headerTotalHeight="headerTotalHeight"
|
|
25
|
-
:emptyText="emptyText"
|
|
26
|
-
@abnormal="abnormal"></Empty>
|
|
27
|
-
<TableLoading v-if="isLoading"
|
|
28
|
-
:delayLoading="delayLoading"
|
|
29
|
-
:headerTotalHeight="headerTotalHeight" />
|
|
30
|
-
<TableTotal v-if="isScrollShowTotal"
|
|
31
|
-
:show="isShowTotal"
|
|
32
|
-
:totalOffset="totalOffset"
|
|
33
|
-
:endRow="state.showEndRow"
|
|
34
|
-
:total="curMaxIndexVal || total" />
|
|
35
|
-
<div ref="loadMroe"
|
|
36
|
-
class="load-more"
|
|
37
|
-
v-if="!isEmpty && !isLoading && isHasOffsetY && !isDataChange">
|
|
38
|
-
<LoadMore :isLoadFinished="isLoadFinished"
|
|
39
|
-
:loadOptions="loadOptions">
|
|
40
|
-
<slot name="loadMroe"></slot>
|
|
41
|
-
</LoadMore>
|
|
42
|
-
</div>
|
|
43
|
-
<div class="pe-table-resize_line"
|
|
44
|
-
style="display: none;">
|
|
45
|
-
<div class="pe-table-resize_line-thumb"></div>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
</template>
|
|
50
|
-
|
|
51
|
-
<script>
|
|
52
|
-
// import Vue from 'vue'
|
|
53
|
-
const Vue = window.Vue // 在此项目中,Vue使用的是public下的运行时的vue.reuntime.min.js。所以此时需要保持一致
|
|
54
|
-
import debounce from 'lodash/debounce'
|
|
55
|
-
import throttle from 'lodash/throttle'
|
|
56
|
-
import CollapseMixin from './collapse.js'
|
|
57
|
-
import Empty from './empty.vue'
|
|
58
|
-
import LoadMore from './load-more'
|
|
59
|
-
import { PE_TABLE_PROPS } from './props/index.js'
|
|
60
|
-
import Row from './row.vue'
|
|
61
|
-
import ScrollbarMixin from './scrollbar.js'
|
|
62
|
-
import TableLoading from './table-loading.vue'
|
|
63
|
-
import TableTotal from './table-total.vue'
|
|
64
|
-
import { createColumns, createFlatColumns, createRenderColumnOption } from './utils/columns.js'
|
|
65
|
-
import { createTableData } from './utils/data'
|
|
66
|
-
import { getRenderRange } from './utils/tools.js'
|
|
67
|
-
import { TouchScrolling } from './utils/touch-scroll.js'
|
|
68
|
-
const RowConstructor = Vue.extend(Row)
|
|
69
|
-
|
|
70
|
-
export default {
|
|
71
|
-
name: 'PeTable',
|
|
72
|
-
mixins: [ScrollbarMixin, CollapseMixin],
|
|
73
|
-
props: PE_TABLE_PROPS,
|
|
74
|
-
components: {
|
|
75
|
-
Empty,
|
|
76
|
-
LoadMore,
|
|
77
|
-
TableLoading,
|
|
78
|
-
TableTotal,
|
|
79
|
-
},
|
|
80
|
-
computed: {
|
|
81
|
-
headerTotalHeight() {
|
|
82
|
-
return this.maxLevel * this.$props.headerRowHeight
|
|
83
|
-
},
|
|
84
|
-
scrollbarClass() {
|
|
85
|
-
if (this.$props.autoHideScrollbars) {
|
|
86
|
-
return [this.isScrolling ? 'visible' : 'hidden']
|
|
87
|
-
} else {
|
|
88
|
-
return ['visible']
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
rootStyle() {
|
|
92
|
-
return {
|
|
93
|
-
'--peHScrollbarSize': this.$props.hScrollbarSize + 'PX',
|
|
94
|
-
'--peVScrollbarSize': this.$props.vScrollbarSize + 'PX',
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
isEmpty() {
|
|
98
|
-
if (!Array.isArray(this.data)) return true
|
|
99
|
-
return !this.data.length && !this.isLoading
|
|
100
|
-
},
|
|
101
|
-
rootClassName() {
|
|
102
|
-
return {
|
|
103
|
-
'pe-table-scrolling__x': this.offsetX,
|
|
104
|
-
'pe-table-show-index': this.$props.showIndex,
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
isHasOffsetY() {
|
|
108
|
-
return this.offsetY > 0
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
// 数据必须存在唯一值 默认为id.否则渲染出现问题。。。不存在就生成 默认使用索引值
|
|
112
|
-
watch: {
|
|
113
|
-
width() {
|
|
114
|
-
this.changeSize()
|
|
115
|
-
},
|
|
116
|
-
height() {
|
|
117
|
-
this.changeSize()
|
|
118
|
-
},
|
|
119
|
-
scrollX(val) {
|
|
120
|
-
this.touchScroll.setScroll('unScrollX', !val)
|
|
121
|
-
},
|
|
122
|
-
scrollY(val) {
|
|
123
|
-
this.touchScroll.setScroll('unScrollY', !val)
|
|
124
|
-
},
|
|
125
|
-
isShowHorizontal(val) {
|
|
126
|
-
this.touchScroll.setScroll('isShowHorizontal', val)
|
|
127
|
-
},
|
|
128
|
-
columns: {
|
|
129
|
-
immediate: true,
|
|
130
|
-
deep: true,
|
|
131
|
-
handler() {
|
|
132
|
-
this.flatColumns()
|
|
133
|
-
this.updateColumns()
|
|
134
|
-
this.updateTableData()
|
|
135
|
-
this.$nextTick(() => {
|
|
136
|
-
this.createHeader()
|
|
137
|
-
this.renderViewportCells()
|
|
138
|
-
if (this.isUpdateOffset) {
|
|
139
|
-
this.scrollToLeft()
|
|
140
|
-
this.scrollToTop()
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
data: {
|
|
146
|
-
handler() {
|
|
147
|
-
this.updateRender()
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
headerTotalHeight() {
|
|
151
|
-
this.$nextTick(() => {
|
|
152
|
-
this.refreshThumb()
|
|
153
|
-
})
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
data() {
|
|
157
|
-
this.rowComponentMap = {}
|
|
158
|
-
return {
|
|
159
|
-
state: {
|
|
160
|
-
endRow: 0, // 可视区域内渲染的结束行
|
|
161
|
-
startRow: 0, // 可视区域的开始行
|
|
162
|
-
showEndRow: 0, // 用户可见的最后一行
|
|
163
|
-
rowOffset: 0, // 偏移量
|
|
164
|
-
|
|
165
|
-
startCell: 0, // 可视区域的开始单元格
|
|
166
|
-
endCell: 0, // 可是区域内的结束单元格
|
|
167
|
-
|
|
168
|
-
scrollableHeight: 0, // 纵向滚动条高度
|
|
169
|
-
tableHeight: 0, // 表格高度
|
|
170
|
-
thumbOffsetY: 0, // 纵向滚动条偏移值
|
|
171
|
-
thumbSizeY: 0,
|
|
172
|
-
trackYStyle: {
|
|
173
|
-
// 纵向滚动条的样式
|
|
174
|
-
right: 0,
|
|
175
|
-
opacity: 1,
|
|
176
|
-
},
|
|
177
|
-
trackXStyle: {
|
|
178
|
-
opacity: 1,
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
scrollableWidth: 0, // 横向滚动条宽度
|
|
182
|
-
tableWidth: 0, // 表格宽度
|
|
183
|
-
thumbOffsetX: 0,
|
|
184
|
-
thumbSizeX: 0,
|
|
185
|
-
|
|
186
|
-
rowsPerViewport: 0, // 缓冲区的行
|
|
187
|
-
},
|
|
188
|
-
viewportWidth: window.innerWidth, // 可视区域宽度
|
|
189
|
-
// 可视区域高度
|
|
190
|
-
viewportHeight: window.innerHeight - this.$props.columns.length * this.$props.rowHeight,
|
|
191
|
-
offsetY: 0, // 纵向偏移值
|
|
192
|
-
offsetX: 0, // 水平偏移值
|
|
193
|
-
// windowHeight: window.innerHeight, //
|
|
194
|
-
// windowWidth: window.innerWidth,
|
|
195
|
-
mainColumns: [], // 所有列配置,包含左侧固定列
|
|
196
|
-
renderCellsColumns: [], // 表体单元格渲染的列集合
|
|
197
|
-
maxLevel: 1, // 最大层级,存在多级表头时则是children的递归集合
|
|
198
|
-
tableData: [], // 表格数据,仅存在渲染的列的数据
|
|
199
|
-
|
|
200
|
-
// 排序相关参数
|
|
201
|
-
sortMap: {
|
|
202
|
-
order: undefined, // 排序方式
|
|
203
|
-
key: undefined, // 排序的列的key
|
|
204
|
-
column: undefined, // 排序的列
|
|
205
|
-
},
|
|
206
|
-
collapsedMap: {},
|
|
207
|
-
visibility: true,
|
|
208
|
-
activate: false,
|
|
209
|
-
loadMoreHeight: 0,
|
|
210
|
-
isShowTotal: false,
|
|
211
|
-
timerMore: null,
|
|
212
|
-
isDataChange: false // 数据正在变化
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
mounted() {
|
|
216
|
-
this.init()
|
|
217
|
-
},
|
|
218
|
-
beforeDestroy() {
|
|
219
|
-
if (this.resizeObserver) {
|
|
220
|
-
this.resizeObserver.disconnect()
|
|
221
|
-
this.resizeObserver = null
|
|
222
|
-
}
|
|
223
|
-
// window.removeEventListener('resize', this.throttleHandleResize)
|
|
224
|
-
},
|
|
225
|
-
activated() {
|
|
226
|
-
/*
|
|
227
|
-
释放掉,存在一个页面多个表格,路由回来A表格从新被activate挂起,handleVisibility没有走,
|
|
228
|
-
B表格这时候也会被activate = true给锁死,导致没办法更新白屏问题,比如一个页面存在tabs的场景
|
|
229
|
-
*/
|
|
230
|
-
const isVisible = this.isVisible()
|
|
231
|
-
if (isVisible) {
|
|
232
|
-
this.activate = true
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
methods: {
|
|
236
|
-
init() {
|
|
237
|
-
let $container = this.$refs.container
|
|
238
|
-
this.changeSize()
|
|
239
|
-
this.resizeObserver = new ResizeObserver(this.handleVisibility)
|
|
240
|
-
this.resizeObserver.observe($container)
|
|
241
|
-
this.scrollbar = this.$refs.scrollbar
|
|
242
|
-
this.touchScroll = new TouchScrolling($container, {
|
|
243
|
-
unScrollY: !this.scrollY,
|
|
244
|
-
unScrollX: !this.scrollX,
|
|
245
|
-
isShowHorizontal: this.isShowHorizontal,
|
|
246
|
-
handlerTouchStar: () => {
|
|
247
|
-
this.$emit('scrollTouchstar', {
|
|
248
|
-
scrollTop: this.offsetY,
|
|
249
|
-
})
|
|
250
|
-
},
|
|
251
|
-
handlerTouchend: finaloffsetY => {
|
|
252
|
-
// 因为当刻所获取的offsetY 并不准确, 前后多的行数数据作为冗余值提前加载
|
|
253
|
-
const rowHeight = this.$props.rowHeight
|
|
254
|
-
let startRow = Math.floor((this.offsetY + finaloffsetY) / rowHeight)
|
|
255
|
-
const numRows = this.tableData.length
|
|
256
|
-
const rowsPerViewport = this.state.rowsPerViewport
|
|
257
|
-
const endRow = Math.min(startRow + rowsPerViewport * 2, numRows)
|
|
258
|
-
// 把其实行设置为当前行,前后多的行数数据作为冗余值提前加载
|
|
259
|
-
startRow = Math.floor(this.offsetY / rowHeight)
|
|
260
|
-
this.$emit('scrollTouchend', {
|
|
261
|
-
startRow,
|
|
262
|
-
endRow,
|
|
263
|
-
rowsPerViewport,
|
|
264
|
-
})
|
|
265
|
-
},
|
|
266
|
-
handlerTouchmove: () => {},
|
|
267
|
-
handlerScrollEnd: parmas => {
|
|
268
|
-
if (!this.$props.isSorbentColumm) return
|
|
269
|
-
if (parmas.y === 0) {
|
|
270
|
-
const state = this.getState()
|
|
271
|
-
const scrollX = this.offsetX
|
|
272
|
-
const width = this.getViewportWidth()
|
|
273
|
-
if (Math.abs(state.tableWidth - width - scrollX) < 2) {
|
|
274
|
-
return
|
|
275
|
-
}
|
|
276
|
-
const fixedList = this.mainColumns.filter(col => col.fixed === 'left' || col.fixed)
|
|
277
|
-
const fixedWidth = fixedList.reduce((acc, col) => acc + col.width, 0) // 计算左边固定距离
|
|
278
|
-
// 非固定和非group的列
|
|
279
|
-
const noFixedAndParentsColums = this.mainColumns.filter(item => item.children.length === 0 && !item.fixed)
|
|
280
|
-
for (let i = 0; i < noFixedAndParentsColums.length - 1; i++) {
|
|
281
|
-
const beginOffsetX = noFixedAndParentsColums[i].offsetX - fixedWidth
|
|
282
|
-
const endOffsetX = noFixedAndParentsColums[i + 1].offsetX - fixedWidth
|
|
283
|
-
// 滚动距离在滑动距离之内,离哪个近,则吸附相近的列
|
|
284
|
-
if (beginOffsetX <= scrollX && scrollX <= endOffsetX) {
|
|
285
|
-
const isNextColumn = endOffsetX - scrollX < scrollX - beginOffsetX
|
|
286
|
-
const scrollToColumnKey = noFixedAndParentsColums[isNextColumn ? i + 1 : i].key
|
|
287
|
-
this.scrollToColumn(scrollToColumnKey, 0, 300)
|
|
288
|
-
break
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
handlerBeforeAnimation: isYAndDownToTop => {
|
|
294
|
-
const isBottom = this.offsetY + this.viewportHeight > this.state.tableHeight
|
|
295
|
-
if (isYAndDownToTop && isBottom) {
|
|
296
|
-
this.scrollHiddenMore()
|
|
297
|
-
}
|
|
298
|
-
return isBottom
|
|
299
|
-
},
|
|
300
|
-
})
|
|
301
|
-
this.renderViewportRows()
|
|
302
|
-
this.createHeader()
|
|
303
|
-
},
|
|
304
|
-
updateRender() {
|
|
305
|
-
// if (this.columns && !this.mainColumns.length) {
|
|
306
|
-
// }
|
|
307
|
-
// this.updateTableData()
|
|
308
|
-
// this.curMaxIndexVal = this.tableData.length
|
|
309
|
-
// this.updateColumnsIndexWidth()
|
|
310
|
-
// this.$nextTick(() => {
|
|
311
|
-
// // 数据变化之后,y轴归零
|
|
312
|
-
// if (this.$props.autoResetScrollTop) {
|
|
313
|
-
// // 重置滚动位置
|
|
314
|
-
// this.scrollToTop()
|
|
315
|
-
// } else {
|
|
316
|
-
// this.renderViewportRows()
|
|
317
|
-
// }
|
|
318
|
-
// // 滚动条发生改变
|
|
319
|
-
// this.refreshThumb()
|
|
320
|
-
// })
|
|
321
|
-
this.isDataChange = true
|
|
322
|
-
this.updateTableData()
|
|
323
|
-
this.curMaxIndexVal = this.tableData.length
|
|
324
|
-
this.updateColumnsIndexWidth()
|
|
325
|
-
// 数据变化之后,y轴归零
|
|
326
|
-
// todo 外部主动调用回到顶部?
|
|
327
|
-
// if (this.$props.autoResetScrollTop) {
|
|
328
|
-
// // 重置滚动位置
|
|
329
|
-
// this.scrollToTop()
|
|
330
|
-
// } else {
|
|
331
|
-
this.renderViewportRows()
|
|
332
|
-
// }
|
|
333
|
-
this.$nextTick(() => {
|
|
334
|
-
// 滚动条发生改变
|
|
335
|
-
this.refreshThumb()
|
|
336
|
-
this.renderViewportCells()
|
|
337
|
-
this.scrollHiddenMoreIfNeeded(true, 0)
|
|
338
|
-
this.isDataChange = false
|
|
339
|
-
})
|
|
340
|
-
},
|
|
341
|
-
flatColumns() {
|
|
342
|
-
const { collapsedMap, visibleFlatColumns } = createFlatColumns({
|
|
343
|
-
columns: this.columns,
|
|
344
|
-
rowCellRender: this.$props.rowCellRender,
|
|
345
|
-
headerCellRender: this.$props.headerCellRender,
|
|
346
|
-
showIndex: this.$props.showIndex,
|
|
347
|
-
})
|
|
348
|
-
this.collapsedMap = collapsedMap
|
|
349
|
-
this.visibleFlatColumns = visibleFlatColumns
|
|
350
|
-
},
|
|
351
|
-
updateColumnsIndexWidth() {
|
|
352
|
-
const indexCol = String(this.curMaxIndexVal).length * 10
|
|
353
|
-
const indexColumn = this.mainColumns.find(column => column.key === '$index')
|
|
354
|
-
if (indexColumn && indexColumn.width !== indexCol) {
|
|
355
|
-
this.updateColumns()
|
|
356
|
-
}
|
|
357
|
-
},
|
|
358
|
-
updateColumns() {
|
|
359
|
-
const { columns, maxLevel } = createColumns({
|
|
360
|
-
visibleFlatColumns: this.visibleFlatColumns,
|
|
361
|
-
collapsedMap: this.collapsedMap,
|
|
362
|
-
rowKey: this.$props.rowKey,
|
|
363
|
-
headerRowHeight: this.$props.headerRowHeight,
|
|
364
|
-
curMaxIndexVal: this.curMaxIndexVal,
|
|
365
|
-
})
|
|
366
|
-
this.maxLevel = maxLevel
|
|
367
|
-
this.mainColumns = columns
|
|
368
|
-
// this.collapseKeysMap = collapseKeysMap
|
|
369
|
-
},
|
|
370
|
-
updateTableData() {
|
|
371
|
-
const params = {
|
|
372
|
-
data: this.$props.data,
|
|
373
|
-
columns: this.visibleFlatColumns,
|
|
374
|
-
rowKey: this.$props.rowKey,
|
|
375
|
-
pageForIndex: this.pageForIndex,
|
|
376
|
-
showPage: this.showPage
|
|
377
|
-
}
|
|
378
|
-
this.tableData = createTableData(params, this.$props.indexFormat)
|
|
379
|
-
},
|
|
380
|
-
isVisible() {
|
|
381
|
-
const status = this.$el && this.$el.checkVisibility && this.$el.checkVisibility()
|
|
382
|
-
return status === undefined ? this.$el.offsetParent !== null : status
|
|
383
|
-
},
|
|
384
|
-
handleVisibility() {
|
|
385
|
-
// 在A页面切换到B页面,B页面这时候属于一个激活状态,不需要重新计算
|
|
386
|
-
if (this.activate) {
|
|
387
|
-
this.activate = false
|
|
388
|
-
return
|
|
389
|
-
}
|
|
390
|
-
const isVisible = this.isVisible()
|
|
391
|
-
if (!isVisible) {
|
|
392
|
-
this.visibility = false
|
|
393
|
-
}
|
|
394
|
-
if (this.visibility === false && isVisible) {
|
|
395
|
-
this.visibility = true
|
|
396
|
-
this.onResize()
|
|
397
|
-
}
|
|
398
|
-
},
|
|
399
|
-
changeSize() {
|
|
400
|
-
// 表格被隐藏。不应该被计算
|
|
401
|
-
const isVisible = this.isVisible()
|
|
402
|
-
if (!isVisible) {
|
|
403
|
-
this.visibility = false
|
|
404
|
-
return
|
|
405
|
-
}
|
|
406
|
-
const width = this.getViewportWidth()
|
|
407
|
-
const height = this.getViewportHeight()
|
|
408
|
-
this.viewportWidth = width
|
|
409
|
-
this.viewportHeight = height
|
|
410
|
-
this.$refs.container.style.width = width + 'PX'
|
|
411
|
-
this.$refs.container.style.height = height + 'PX'
|
|
412
|
-
this.$refs.root.style.width = width + 'PX'
|
|
413
|
-
this.$refs.root.style.height = height + 'PX'
|
|
414
|
-
this.$nextTick(() => {
|
|
415
|
-
this.renderViewportRows()
|
|
416
|
-
this.renderViewportCells()
|
|
417
|
-
this.refreshThumb()
|
|
418
|
-
})
|
|
419
|
-
},
|
|
420
|
-
// 修改 getViewportHeight 方法
|
|
421
|
-
getViewportHeight() {
|
|
422
|
-
// 计算实际内容高度
|
|
423
|
-
const contentHeight = this.$props.rowHeight * this.tableData.length + this.headerTotalHeight
|
|
424
|
-
// 如果有设置最大高度,取较小值
|
|
425
|
-
if (this.$props.maxHeight) {
|
|
426
|
-
return Math.min(contentHeight, parseInt(this.$props.maxHeight))
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// 原有逻辑保持不变
|
|
430
|
-
if (this.$props.height) {
|
|
431
|
-
return parseInt(this.$props.height)
|
|
432
|
-
}
|
|
433
|
-
return this.$refs.container.clientHeight
|
|
434
|
-
},
|
|
435
|
-
getViewportWidth() {
|
|
436
|
-
if (this.$props.width) {
|
|
437
|
-
return parseInt(this.$props.width)
|
|
438
|
-
}
|
|
439
|
-
return this.$refs.container.clientWidth
|
|
440
|
-
},
|
|
441
|
-
getState() {
|
|
442
|
-
const numRows = this.tableData.length
|
|
443
|
-
// 增加行渲染的冗余,保证触底时的效果
|
|
444
|
-
const rowsPerViewport = Math.ceil((this.viewportHeight - this.headerTotalHeight) / this.$props.rowHeight) + 1
|
|
445
|
-
const tableHeight = numRows * this.$props.rowHeight + this.headerTotalHeight
|
|
446
|
-
const mainColumns = this.mainColumns
|
|
447
|
-
const { tableWidth, renderCellsColumns, renderCellsColumnsWidths } = createRenderColumnOption({
|
|
448
|
-
mainColumns,
|
|
449
|
-
maxLevel: this.maxLevel,
|
|
450
|
-
headerRowHeight: this.$props.headerRowHeight,
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
// 为什么这里还需要再算一次?因为如果直接把父节点的子节点都塞进去,那么子节点就会全部渲染,子节点个数得不到渲染。
|
|
454
|
-
// 所以这里还需要再算一次。
|
|
455
|
-
const { startIndex: startCell, endIndex: endCell } = getRenderRange(this.offsetX, this.viewportWidth, renderCellsColumnsWidths)
|
|
456
|
-
this.renderCellsColumns = renderCellsColumns
|
|
457
|
-
|
|
458
|
-
const startRow = Math.floor(this.offsetY / this.$props.rowHeight)
|
|
459
|
-
const endRow = Math.min(startRow + rowsPerViewport, numRows)
|
|
460
|
-
// const showRowsPerViewport = Math.max(0, rowsPerViewport - 1)
|
|
461
|
-
// const showEndRow = Math.min(startRow + showRowsPerViewport, numRows)
|
|
462
|
-
const tableHeightNoHeader = this.offsetY + this.viewportHeight - this.headerTotalHeight
|
|
463
|
-
// const showEndRow = Math.min(Math.ceil(tableHeightNoHeader / this.$props.rowHeight ), numRows)
|
|
464
|
-
const showEndRow = Math.min(Math.floor((tableHeightNoHeader + this.$props.rowHeight / 2) / this.$props.rowHeight), numRows)
|
|
465
|
-
const rowOffset = -Math.floor(this.offsetY % this.$props.rowHeight)
|
|
466
|
-
|
|
467
|
-
// 滚动条的计算逻辑
|
|
468
|
-
const scrollableHeight = Math.max(tableHeight - this.viewportHeight, 0)
|
|
469
|
-
const scrollThumbYPct = tableHeight === 0 ? 1 : 0.97 * Math.sqrt(this.viewportHeight / tableHeight) + 0.03
|
|
470
|
-
const thumbSizeY = Math.round(Math.max(Math.min(scrollThumbYPct * this.viewportHeight, this.viewportHeight), 0))
|
|
471
|
-
let thumbOffsetY
|
|
472
|
-
if (scrollableHeight === 0) {
|
|
473
|
-
thumbOffsetY = 0
|
|
474
|
-
} else {
|
|
475
|
-
thumbOffsetY = (this.offsetY / scrollableHeight) * this.viewportHeight - thumbSizeY * (this.offsetY / scrollableHeight)
|
|
476
|
-
}
|
|
477
|
-
const scrollableWidth = Math.max(tableWidth - this.viewportWidth, 0)
|
|
478
|
-
const scrollThumbXPct = tableWidth === 0 ? 100 : this.viewportWidth / tableWidth
|
|
479
|
-
const thumbSizeX = Math.round(Math.max(Math.min(scrollThumbXPct * this.viewportWidth, this.viewportWidth), 30))
|
|
480
|
-
const thumbOffsetX = (this.offsetX / scrollableWidth) * this.viewportWidth - thumbSizeX * (this.offsetX / scrollableWidth)
|
|
481
|
-
const trackYStyle = {
|
|
482
|
-
right: Math.max(0, this.viewportWidth - tableWidth) + 'px',
|
|
483
|
-
opacity: tableHeight > this.viewportHeight ? 1 : 0,
|
|
484
|
-
}
|
|
485
|
-
const trackXStyle = {
|
|
486
|
-
opacity: tableWidth > this.viewportWidth && numRows ? 1 : 0,
|
|
487
|
-
}
|
|
488
|
-
if (this.state != null) {
|
|
489
|
-
this.state.showEndRow = showEndRow
|
|
490
|
-
this.state.endRow = endRow
|
|
491
|
-
this.state.startRow = startRow
|
|
492
|
-
this.state.rowOffset = rowOffset + this.headerTotalHeight
|
|
493
|
-
|
|
494
|
-
this.state.startCell = startCell
|
|
495
|
-
this.state.endCell = endCell
|
|
496
|
-
|
|
497
|
-
this.state.scrollableHeight = scrollableHeight
|
|
498
|
-
this.state.tableHeight = tableHeight
|
|
499
|
-
this.state.thumbOffsetY = thumbOffsetY
|
|
500
|
-
this.state.thumbSizeY = thumbSizeY
|
|
501
|
-
|
|
502
|
-
this.state.scrollableWidth = scrollableWidth
|
|
503
|
-
this.state.tableWidth = tableWidth
|
|
504
|
-
this.state.thumbOffsetX = thumbOffsetX
|
|
505
|
-
this.state.thumbSizeX = thumbSizeX
|
|
506
|
-
this.state.trackYStyle = trackYStyle
|
|
507
|
-
this.state.trackXStyle = trackXStyle
|
|
508
|
-
|
|
509
|
-
this.state.rowsPerViewport = rowsPerViewport
|
|
510
|
-
return this.state
|
|
511
|
-
}
|
|
512
|
-
const state = {
|
|
513
|
-
showEndRow,
|
|
514
|
-
endRow,
|
|
515
|
-
startRow,
|
|
516
|
-
rowOffset,
|
|
517
|
-
|
|
518
|
-
startCell,
|
|
519
|
-
endCell,
|
|
520
|
-
|
|
521
|
-
scrollableHeight,
|
|
522
|
-
tableHeight,
|
|
523
|
-
thumbOffsetY,
|
|
524
|
-
thumbSizeY,
|
|
525
|
-
|
|
526
|
-
scrollableWidth,
|
|
527
|
-
tableWidth,
|
|
528
|
-
thumbOffsetX,
|
|
529
|
-
thumbSizeX,
|
|
530
|
-
|
|
531
|
-
rowsPerViewport,
|
|
532
|
-
trackYStyle,
|
|
533
|
-
trackXStyle,
|
|
534
|
-
}
|
|
535
|
-
this.state = state
|
|
536
|
-
return state
|
|
537
|
-
},
|
|
538
|
-
throttleHandleResize: throttle(function () {
|
|
539
|
-
this.onResize()
|
|
540
|
-
}, 30),
|
|
541
|
-
onResize() {
|
|
542
|
-
this.changeSize()
|
|
543
|
-
this.setScrollOffsetY(this.offsetY)
|
|
544
|
-
this.setScrollOffsetX(this.offsetX)
|
|
545
|
-
},
|
|
546
|
-
setScrollToLoadMore() {
|
|
547
|
-
const { scrollableHeight } = this.state
|
|
548
|
-
// 开启了加载更多并且再接近最后一屏进行位置的设置,并回调加载更多函数
|
|
549
|
-
// 有表格高度,并且非加载完成,且滚动到需要触发的距离
|
|
550
|
-
if (this.enableLoadMore && !this.isLoadFinished && scrollableHeight - this.offsetY <= this.loadOptions.offset) {
|
|
551
|
-
// console.log('触发 loadMore, 距离底部距离:', scrollableHeight - this.offsetY)
|
|
552
|
-
this.callbackLoadMore()
|
|
553
|
-
}
|
|
554
|
-
this.setLoadMroeOffset()
|
|
555
|
-
},
|
|
556
|
-
// 设置加载更多组件的位置
|
|
557
|
-
async setLoadMroeOffset() {
|
|
558
|
-
const { startRow, rowsPerViewport, rowOffset } = this.state
|
|
559
|
-
// 为了减少过度计算,判断在末屏才进行计算
|
|
560
|
-
let dataCount = this.data.length
|
|
561
|
-
let offset = -9999
|
|
562
|
-
if (startRow >= dataCount - rowsPerViewport) {
|
|
563
|
-
this.getLoadmoreHeight()
|
|
564
|
-
// 把加载更多当作最后一行计算起始位置
|
|
565
|
-
offset = rowOffset + (dataCount - startRow) * this.$props.rowHeight
|
|
566
|
-
} else {
|
|
567
|
-
offset = -9999
|
|
568
|
-
}
|
|
569
|
-
await this.$nextTick()
|
|
570
|
-
let $loadMore = this.$refs.loadMroe
|
|
571
|
-
if ($loadMore) {
|
|
572
|
-
$loadMore.style.transform = `translateY(${offset}px)`
|
|
573
|
-
}
|
|
574
|
-
},
|
|
575
|
-
// 获取该组件高度
|
|
576
|
-
getLoadmoreHeight() {
|
|
577
|
-
if (!this.loadMoreHeight && this.$refs.loadMroe) {
|
|
578
|
-
this.loadMoreHeight = this.$refs.loadMroe.offsetHeight || 0
|
|
579
|
-
}
|
|
580
|
-
},
|
|
581
|
-
callbackLoadMore: throttle(function () {
|
|
582
|
-
this.$emit('loadMore')
|
|
583
|
-
}, 100),
|
|
584
|
-
clearSortMap() {
|
|
585
|
-
this.sortMap = {
|
|
586
|
-
order: undefined, // 排序方式
|
|
587
|
-
key: undefined, // 排序的列的key
|
|
588
|
-
column: undefined, // 排序的列
|
|
589
|
-
}
|
|
590
|
-
},
|
|
591
|
-
renderViewportRows() {
|
|
592
|
-
if (!this.sortMap.order && this.defaultSort.order) {
|
|
593
|
-
this.sortMap.order = this.defaultSort.order
|
|
594
|
-
this.sortMap.key = this.defaultSort.key
|
|
595
|
-
}
|
|
596
|
-
// 获取渲染需要的对象
|
|
597
|
-
const state = this.getState()
|
|
598
|
-
// 渲染对象集合以id为key
|
|
599
|
-
const renderRows = {}
|
|
600
|
-
// rowsArr 只有在$props.data 在watch监听发生变更时,才会更新,遇到单元格渲染异常时,优先考虑此变量异常
|
|
601
|
-
const rowsArr = this.tableData
|
|
602
|
-
// 当前渲染的行
|
|
603
|
-
for (let i = state.startRow; i < state.endRow; i++) {
|
|
604
|
-
const rowId = rowsArr[i][this.$props.rowKey]
|
|
605
|
-
renderRows[rowId] = true
|
|
606
|
-
}
|
|
607
|
-
// 需要移出的行
|
|
608
|
-
const removeRows = []
|
|
609
|
-
// 遍历复用的组件对象
|
|
610
|
-
for (const id in this.rowComponentMap) {
|
|
611
|
-
// 存在与渲染的,跳过
|
|
612
|
-
if (id in renderRows) {
|
|
613
|
-
continue
|
|
614
|
-
}
|
|
615
|
-
// 否则记录在需要移出的行
|
|
616
|
-
const rowComponent = this.rowComponentMap[id]
|
|
617
|
-
removeRows.push(rowComponent)
|
|
618
|
-
}
|
|
619
|
-
const columns = this.renderCellsColumns || []
|
|
620
|
-
for (let i = state.startRow; i < state.endRow; i++) {
|
|
621
|
-
let row = rowsArr[i]
|
|
622
|
-
let originRowData = this.$props.data[i]
|
|
623
|
-
// 行数据不存在跳过
|
|
624
|
-
if (row == null) {
|
|
625
|
-
// eslint-disable-next-line
|
|
626
|
-
console.error('cannot find row', i)
|
|
627
|
-
continue
|
|
628
|
-
}
|
|
629
|
-
const rowId = row[this.$props.rowKey]
|
|
630
|
-
const cells = columns.reduce((obj, col, index) => {
|
|
631
|
-
obj[index] = {
|
|
632
|
-
[col.key]: originRowData[col.key],
|
|
633
|
-
id: `${rowId}_${i}_${col.key}_ ${index}`,
|
|
634
|
-
}
|
|
635
|
-
if (col.key === '$index') {
|
|
636
|
-
obj[index][col.key] = row[col.key]
|
|
637
|
-
}
|
|
638
|
-
return obj
|
|
639
|
-
}, [])
|
|
640
|
-
// 每一行的行高之间的偏移值
|
|
641
|
-
const offset = state.rowOffset + (i - state.startRow) * this.$props.rowHeight
|
|
642
|
-
const rowParams = {
|
|
643
|
-
rowIndex: i,
|
|
644
|
-
id: rowId, // 行数据中的唯一值
|
|
645
|
-
cells, // 行内的列的数据集合
|
|
646
|
-
rowData: row, // 行数据
|
|
647
|
-
offset, // 偏移量。这里是等高。暂不支持动态
|
|
648
|
-
rowHeight: this.$props.rowHeight, // 行高
|
|
649
|
-
type: 'row', // 行组件类型。渲染表头行和表体行
|
|
650
|
-
columns,
|
|
651
|
-
originRowData,
|
|
652
|
-
}
|
|
653
|
-
// 是否为已存在的的行组件
|
|
654
|
-
const existingRow = this.rowComponentMap[rowId]
|
|
655
|
-
// 存在直接改偏移值
|
|
656
|
-
if (existingRow != null) {
|
|
657
|
-
existingRow.reuse(rowParams)
|
|
658
|
-
existingRow.renderCells()
|
|
659
|
-
continue
|
|
660
|
-
}
|
|
661
|
-
// 需要移除的行数据。但是此处可复用行组件。
|
|
662
|
-
const reuseRow = removeRows.pop()
|
|
663
|
-
if (reuseRow != null) {
|
|
664
|
-
// 每个行组件都存在id属性。id的值为行数据必须唯一,为了检查是否复用,更新,或删除
|
|
665
|
-
delete this.rowComponentMap[reuseRow.id]
|
|
666
|
-
reuseRow.reuse(rowParams)
|
|
667
|
-
reuseRow.renderCells()
|
|
668
|
-
this.rowComponentMap[rowId] = reuseRow
|
|
669
|
-
continue
|
|
670
|
-
}
|
|
671
|
-
// 新增的行组件
|
|
672
|
-
const rowComponent = new RowConstructor({
|
|
673
|
-
el: document.createElement('div'),
|
|
674
|
-
})
|
|
675
|
-
// 行组件设置对应的属性
|
|
676
|
-
rowComponent.grid = this // 父组件实例
|
|
677
|
-
for (let prop in rowParams) {
|
|
678
|
-
rowComponent[prop] = rowParams[prop]
|
|
679
|
-
}
|
|
680
|
-
// rowComponent.renderCells()
|
|
681
|
-
// 直接追加到容器的dom中。不走vue的虚拟dom,减少计算开销
|
|
682
|
-
this.$refs.container.appendChild(rowComponent.$el)
|
|
683
|
-
this.rowComponentMap[rowId] = rowComponent
|
|
684
|
-
}
|
|
685
|
-
// 销毁并移出不需要的行
|
|
686
|
-
for (const rowComponent of removeRows) {
|
|
687
|
-
rowComponent.destroy() // 销毁
|
|
688
|
-
delete this.rowComponentMap[rowComponent.id] // 销毁内存中的行组件
|
|
689
|
-
}
|
|
690
|
-
// 渲染行之后看是否需要处理加载更多组件的位置
|
|
691
|
-
this.setScrollToLoadMore()
|
|
692
|
-
},
|
|
693
|
-
renderViewportCells() {
|
|
694
|
-
const state = this.getState()
|
|
695
|
-
// 更新视口区域的行组件
|
|
696
|
-
for (let i = state.startRow; i < state.endRow; i++) {
|
|
697
|
-
let row = this.tableData[i]
|
|
698
|
-
const rowId = row[this.$props.rowKey]
|
|
699
|
-
let rowComponent = this.rowComponentMap[rowId]
|
|
700
|
-
if (!rowComponent) {
|
|
701
|
-
// console.error('row should exist. did you render rows first?')
|
|
702
|
-
continue
|
|
703
|
-
}
|
|
704
|
-
// 更新行内的列(单元格)组件
|
|
705
|
-
rowComponent.renderCells.call(rowComponent)
|
|
706
|
-
}
|
|
707
|
-
this.headersComponent && this.headersComponent.renderCells()
|
|
708
|
-
// for (const row of Object.values(this.headerRows)) {
|
|
709
|
-
// row.renderCells.call(row)
|
|
710
|
-
// }
|
|
711
|
-
},
|
|
712
|
-
createHeader() {
|
|
713
|
-
this.getState()
|
|
714
|
-
if (this.headersComponent) {
|
|
715
|
-
// 存在时,直接销毁头。
|
|
716
|
-
this.$refs.container.removeChild(this.headersComponent.$el)
|
|
717
|
-
this.headersComponent.$destroy()
|
|
718
|
-
}
|
|
719
|
-
let offset = 0
|
|
720
|
-
const HEADER_ID = 'inner_header_in_99999999999999' // very dumb
|
|
721
|
-
const headersComponent = new RowConstructor({
|
|
722
|
-
el: document.createElement('div'),
|
|
723
|
-
})
|
|
724
|
-
const columns = this.renderCellsColumns
|
|
725
|
-
// 行数据设置
|
|
726
|
-
headersComponent.grid = this
|
|
727
|
-
const headerParams = {
|
|
728
|
-
id: HEADER_ID,
|
|
729
|
-
rowHeight: this.headerTotalHeight,
|
|
730
|
-
cells: columns,
|
|
731
|
-
columns,
|
|
732
|
-
offset: offset,
|
|
733
|
-
type: 'header',
|
|
734
|
-
}
|
|
735
|
-
for (let prop in headerParams) {
|
|
736
|
-
headersComponent[prop] = headerParams[prop]
|
|
737
|
-
}
|
|
738
|
-
// 直接追加到容器的dom中。不走vue的虚拟dom,减少计算开销
|
|
739
|
-
this.$refs.container.appendChild(headersComponent.$el)
|
|
740
|
-
this.headersComponent = headersComponent
|
|
741
|
-
},
|
|
742
|
-
|
|
743
|
-
handleEvent(event, params) {
|
|
744
|
-
const { name, ...reset } = params
|
|
745
|
-
this.$emit(name, { event, ...reset })
|
|
746
|
-
},
|
|
747
|
-
|
|
748
|
-
// 排序操作
|
|
749
|
-
sortChange(column) {
|
|
750
|
-
const execulteHanlder = () => {
|
|
751
|
-
if (!this.sortMap.order) {
|
|
752
|
-
this.sortMap.order = 'ascending'
|
|
753
|
-
} else {
|
|
754
|
-
this.sortMap.order = this.sortMap.order === 'ascending' ? 'descending' : 'ascending'
|
|
755
|
-
}
|
|
756
|
-
this.sortMap.key = column.key
|
|
757
|
-
// 真实请求用的排序字段,用于实现表格列的展示字段与排序请求字段不同的场景,比如:name 字段展示的列用 code 字段进行排序;
|
|
758
|
-
// 一般情况下,表格列的展示字段与排序请求字段是一致的,此时可以直接用 sortMap.key 字段
|
|
759
|
-
this.sortMap.reqKey = (Array.isArray(column.sortKeys) && column.sortKeys[0]) || column.key
|
|
760
|
-
this.sortMap.column = column.column
|
|
761
|
-
this.$emit('sort-change', {
|
|
762
|
-
order: this.sortMap.order,
|
|
763
|
-
column,
|
|
764
|
-
prop: this.sortMap.key,
|
|
765
|
-
reqProp: this.sortMap.reqKey,
|
|
766
|
-
})
|
|
767
|
-
this.renderViewportCells()
|
|
768
|
-
}
|
|
769
|
-
let fn = this.$props.beforeSort
|
|
770
|
-
if (fn && typeof fn === 'function') {
|
|
771
|
-
const beforeSort = fn({
|
|
772
|
-
column,
|
|
773
|
-
order: this.sortMap.order,
|
|
774
|
-
prop: column.key,
|
|
775
|
-
})
|
|
776
|
-
if (beforeSort && beforeSort.then) {
|
|
777
|
-
beforeSort.then(allow => {
|
|
778
|
-
allow !== false && execulteHanlder()
|
|
779
|
-
})
|
|
780
|
-
} else {
|
|
781
|
-
beforeSort !== false && execulteHanlder()
|
|
782
|
-
}
|
|
783
|
-
} else {
|
|
784
|
-
execulteHanlder()
|
|
785
|
-
}
|
|
786
|
-
},
|
|
787
|
-
// 排序相关操作
|
|
788
|
-
clearSort() {
|
|
789
|
-
this.$emit('sort-change', {})
|
|
790
|
-
},
|
|
791
|
-
// 断网
|
|
792
|
-
abnormal() {
|
|
793
|
-
this.$emit('abnormal')
|
|
794
|
-
},
|
|
795
|
-
showTotalView() {
|
|
796
|
-
const { showEndRow = 0, rowsPerViewport = 0 } = this.state
|
|
797
|
-
if (showEndRow > rowsPerViewport) {
|
|
798
|
-
this.isShowTotal = true
|
|
799
|
-
setTimeout(() => {
|
|
800
|
-
this.hiddenTotalView()
|
|
801
|
-
}, 1000)
|
|
802
|
-
}
|
|
803
|
-
},
|
|
804
|
-
hiddenTotalView: debounce(function () {
|
|
805
|
-
this.isShowTotal = false
|
|
806
|
-
}, 1000),
|
|
807
|
-
scrollHiddenMore(duration = 300) {
|
|
808
|
-
if (this.isLoadingMore) return
|
|
809
|
-
if (this.timerMore) {
|
|
810
|
-
this.timerMore = null
|
|
811
|
-
clearTimeout(this.timerMore)
|
|
812
|
-
}
|
|
813
|
-
this.timerMore = setTimeout(async() => {
|
|
814
|
-
const numRows = this.tableData.length
|
|
815
|
-
this.scrollToRow(numRows - 1, 0, duration)
|
|
816
|
-
await this.$nextTick()
|
|
817
|
-
this.renderViewportCells()
|
|
818
|
-
}, 0)
|
|
819
|
-
},
|
|
820
|
-
scrollHiddenMoreIfNeeded(isYAndDownToTop = true, duration) {
|
|
821
|
-
const isBottom = this.offsetY + this.viewportHeight > this.state.tableHeight
|
|
822
|
-
if (isYAndDownToTop && isBottom) {
|
|
823
|
-
this.scrollHiddenMore(duration)
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
cellResize({ columnKey, width } = {}) {
|
|
827
|
-
const column = this.visibleFlatColumns.find(col => col.key === columnKey)
|
|
828
|
-
column.width = width
|
|
829
|
-
|
|
830
|
-
this.updateColumns()
|
|
831
|
-
this.createHeader()
|
|
832
|
-
this.changeSize()
|
|
833
|
-
this.setScrollOffsetY(this.offsetY)
|
|
834
|
-
this.setScrollOffsetX(this.offsetX)
|
|
835
|
-
|
|
836
|
-
this.$emit('cell-resize', {
|
|
837
|
-
column,
|
|
838
|
-
width,
|
|
839
|
-
})
|
|
840
|
-
},
|
|
841
|
-
},
|
|
842
|
-
}
|
|
843
|
-
</script>
|
|
844
|
-
|
|
845
|
-
<style lang="less" scoped>
|
|
846
|
-
@import url('./style/index.less');
|
|
847
|
-
</style>
|