@kyfe/ks-query-table 0.0.21 → 0.0.22
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/.bitmap +38 -0
- package/.editorconfig +5 -0
- package/.env.dev +2 -0
- package/.env.gray +2 -0
- package/.env.prod +2 -0
- package/.env.stg +3 -0
- package/.env.uat +2 -0
- package/.eslintignore +1 -0
- package/.eslintrc.js +25 -0
- package/.gitmodules +4 -0
- package/.prettierrc +11 -0
- package/README.md +15 -0
- package/babel.config.js +10 -0
- package/build-apm.sh +9 -0
- package/build.sh +16 -0
- package/config/index.js +20 -0
- package/jsconfig.json +7 -0
- package/kuasheng-sdk/index.js +80 -0
- package/kuasheng-sdk/lib/assets.js +304 -0
- package/kuasheng-sdk/lib/context.js +199 -0
- package/kuasheng-sdk/lib/layout.js +346 -0
- package/kuasheng-sdk/lib/location.js +46 -0
- package/kuasheng-sdk/lib/media.js +342 -0
- package/kuasheng-sdk/lib/navigation.js +30 -0
- package/kuasheng-sdk/lib/request.js +76 -0
- package/kuasheng-sdk/lib/system.js +190 -0
- package/kuasheng-sdk/lib/userinfo.js +98 -0
- package/kuasheng-sdk/util/check.js +102 -0
- package/kuasheng-sdk/util/config.js +47 -0
- package/kuasheng-sdk/util/device.js +25 -0
- package/kuasheng-sdk/util/error.js +19 -0
- package/kuasheng-sdk/util/funtional.js +153 -0
- package/kuasheng-sdk/util/mixin.js +36 -0
- package/kuasheng-sdk/util/requestUtil.js +41 -0
- package/kuasheng-sdk/util/response.js +33 -0
- package/kuasheng-sdk/util/warn.js +35 -0
- package/kuasheng-ui/CHANGELOG.md +9 -0
- package/kuasheng-ui/components/card.vue +57 -0
- package/kuasheng-ui/components/ks-area-select/README.md +43 -0
- package/kuasheng-ui/components/ks-area-select/area-picker.vue +554 -0
- package/kuasheng-ui/components/ks-area-select/area-search.vue +363 -0
- package/kuasheng-ui/components/ks-area-select/areas-pop.vue +56 -0
- package/kuasheng-ui/components/ks-area-select/common.js +183 -0
- package/kuasheng-ui/components/ks-area-select/index.vue +355 -0
- package/kuasheng-ui/components/ks-area-select/mixins.js +216 -0
- package/kuasheng-ui/components/ks-area-single-select/README.md +50 -0
- package/kuasheng-ui/components/ks-area-single-select/hot-city.js +45 -0
- package/kuasheng-ui/components/ks-area-single-select/index.vue +324 -0
- package/kuasheng-ui/components/ks-calendar/index.vue +269 -0
- package/kuasheng-ui/components/ks-call-phone/call-tips.vue +70 -0
- package/kuasheng-ui/components/ks-call-phone/call.vue +178 -0
- package/kuasheng-ui/components/ks-call-phone/index.js +48 -0
- package/kuasheng-ui/components/ks-call-phone/index.vue +131 -0
- 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 +23 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-bottom.vue +123 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-dropdown.vue +80 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-right.vue +87 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker-top.vue +88 -0
- package/kuasheng-ui/components/ks-date-picker/date-picker.js +15 -0
- package/kuasheng-ui/components/ks-date-picker/date-range-select.vue +92 -0
- package/kuasheng-ui/components/ks-date-picker/date-select.vue +65 -0
- package/kuasheng-ui/components/ks-date-picker/date-week-month.vue +131 -0
- package/kuasheng-ui/components/ks-date-picker/index.js +12 -0
- package/kuasheng-ui/components/ks-date-picker/mixin.js +92 -0
- package/kuasheng-ui/components/ks-date-picker/month-range-select.vue +129 -0
- package/kuasheng-ui/components/ks-date-picker/month-select.vue +85 -0
- package/kuasheng-ui/components/ks-date-picker/quarter-select.vue +94 -0
- package/kuasheng-ui/components/ks-date-picker/style.less +121 -0
- package/kuasheng-ui/components/ks-date-picker/utils.js +109 -0
- package/kuasheng-ui/components/ks-date-picker/week-select.vue +99 -0
- package/kuasheng-ui/components/ks-decrypt/index.vue +159 -0
- package/kuasheng-ui/components/ks-employee/README.md +78 -0
- package/kuasheng-ui/components/ks-employee/employee-input.vue +173 -0
- package/kuasheng-ui/components/ks-employee/employee-list.vue +662 -0
- package/kuasheng-ui/components/ks-employee/employee-popup.vue +197 -0
- package/kuasheng-ui/components/ks-employee/employee-search.vue +250 -0
- package/kuasheng-ui/components/ks-employee/employee-selected.vue +173 -0
- package/kuasheng-ui/components/ks-employee/index.js +17 -0
- package/kuasheng-ui/components/ks-employee/package-lock.json +5 -0
- package/kuasheng-ui/components/ks-employee/package.json +15 -0
- package/kuasheng-ui/components/ks-employee/yarn.lock +4 -0
- package/kuasheng-ui/components/ks-field-money/index.js +8 -0
- package/kuasheng-ui/components/ks-field-money/index.vue +212 -0
- package/kuasheng-ui/components/ks-field-money/package.json +11 -0
- package/kuasheng-ui/components/ks-field-money/utils.js +65 -0
- 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 +131 -0
- package/kuasheng-ui/components/ks-history-search/history-list.vue +188 -0
- package/kuasheng-ui/components/ks-history-search/img/delete.png +0 -0
- package/kuasheng-ui/components/ks-history-search/index.js +9 -0
- package/kuasheng-ui/components/ks-history-search/index.vue +125 -0
- package/kuasheng-ui/components/ks-history-search/package-lock.json +5 -0
- package/kuasheng-ui/components/ks-history-search/package.json +15 -0
- package/kuasheng-ui/components/ks-history-search/utils.js +35 -0
- package/kuasheng-ui/components/ks-input-search/index.vue +106 -0
- package/kuasheng-ui/components/ks-list/index.vue +75 -0
- package/kuasheng-ui/components/ks-loading/index.js +16 -0
- package/kuasheng-ui/components/ks-month/index.vue +47 -0
- package/kuasheng-ui/components/ks-month/package.json +3 -0
- package/kuasheng-ui/components/ks-month/range.vue +172 -0
- package/kuasheng-ui/components/ks-month/single.vue +136 -0
- package/kuasheng-ui/components/ks-month/style.less +125 -0
- package/kuasheng-ui/components/ks-month/utils.js +35 -0
- package/kuasheng-ui/components/ks-nav/index.vue +264 -0
- package/kuasheng-ui/components/ks-nav-bar.js +35 -0
- package/kuasheng-ui/components/ks-org/ks-org-tree.vue +247 -0
- package/kuasheng-ui/components/ks-org/ks-popup-tree.vue +154 -0
- package/kuasheng-ui/components/ks-org/ks-tree-input.vue +240 -0
- package/kuasheng-ui/components/ks-org/ks-tree-node.vue +94 -0
- package/kuasheng-ui/components/ks-org/ks-tree.vue +229 -0
- package/kuasheng-ui/components/ks-org/utils.js +54 -0
- package/kuasheng-ui/components/ks-popover/index.vue +457 -0
- package/kuasheng-ui/components/ks-popover/mixin.js +28 -0
- package/kuasheng-ui/components/ks-popover/utils.js +60 -0
- package/kuasheng-ui/components/ks-pull-refresh/index.vue +43 -0
- package/kuasheng-ui/components/ks-quarter/index.vue +256 -0
- package/kuasheng-ui/components/ks-table/README.md +103 -0
- package/kuasheng-ui/components/ks-table/cell.vue +31 -0
- package/kuasheng-ui/components/ks-table/index.js +8 -0
- package/kuasheng-ui/components/ks-table/index.less +486 -0
- package/kuasheng-ui/components/ks-table/index.vue +1088 -0
- package/kuasheng-ui/components/ks-table/package.json +12 -0
- package/kuasheng-ui/components/ks-table/release.md +7 -0
- package/kuasheng-ui/components/ks-toast.js +35 -0
- package/kuasheng-ui/components/ks-upload/index.vue +174 -0
- package/kuasheng-ui/components/ks-user-access.vue +229 -0
- package/kuasheng-ui/components/no-data/README.md +45 -0
- package/kuasheng-ui/components/no-data/image.js +1 -0
- package/kuasheng-ui/components/no-data/index.vue +83 -0
- package/kuasheng-ui/components/notice-bar.vue +16 -0
- package/kuasheng-ui/components/steps.js +11 -0
- package/kuasheng-ui/components/tabs.vue +40 -0
- package/kuasheng-ui/index.js +239 -0
- package/kuasheng-ui/patch/datetime-picker/datetimePicker.md +0 -0
- package/kuasheng-ui/patch/datetime-picker/index.js +46 -0
- package/kuasheng-ui/patch/datetime-picker/utils.js +78 -0
- package/kuasheng-ui/patch/field/field.md +1 -0
- package/kuasheng-ui/patch/field/index.js +122 -0
- package/kuasheng-ui/patch/field/utils.js +36 -0
- package/kuasheng-ui/patch/form/form.md +7 -0
- package/kuasheng-ui/patch/form/index.js +106 -0
- package/kuasheng-ui/patch/index.js +12 -0
- package/kuasheng-ui/patch/pagination/index.js +78 -0
- package/kuasheng-ui/style/animation-ui.less +31 -0
- 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 +1 -0
- package/kuasheng-ui/style/images/success.svg +1 -0
- package/kuasheng-ui/style/index.less +6 -0
- package/kuasheng-ui/style/kuasheng-ui.less +207 -0
- package/kuasheng-ui/style/reset-vant.less +307 -0
- package/kuasheng-ui/style/vant-var.less +138 -0
- package/kuasheng-ui/utils/apis.js +17 -0
- package/kuasheng-ui/utils/axios-adapter.js +47 -0
- package/kuasheng-ui/utils/bem.js +39 -0
- package/kuasheng-ui/utils/bus.js +97 -0
- package/kuasheng-ui/utils/common.js +88 -0
- package/kuasheng-ui/utils/decrypt/config.js +12 -0
- package/kuasheng-ui/utils/decrypt/decrypt-api.js +139 -0
- package/kuasheng-ui/utils/decrypt/index.js +6 -0
- package/kuasheng-ui/utils/decrypt/mask.js +36 -0
- package/kuasheng-ui/utils/decrypt/virtual.js +44 -0
- package/kuasheng-ui/utils/directive.js +57 -0
- package/kuasheng-ui/utils/directive.md +23 -0
- package/kuasheng-ui/utils/drcheck-plugin.js +219 -0
- package/kuasheng-ui/utils/error-plugin.js +88 -0
- package/kuasheng-ui/utils/filter.js +149 -0
- package/kuasheng-ui/utils/http-interceptors.js +18 -0
- package/kuasheng-ui/utils/http.js +140 -0
- package/kuasheng-ui/utils/index.js +5 -0
- package/kuasheng-ui/utils/init-event.js +20 -0
- package/kuasheng-ui/utils/log.js +309 -0
- package/kuasheng-ui/utils/token.js +9 -0
- package/kuasheng-ui/utils/type.js +45 -0
- package/kuasheng-ui/utils/validate.js +20 -0
- package/kuasheng-ui/utils/watermark.js +67 -0
- package/kuasheng-ui/version.js +1 -0
- package/ky-apm/client.js +37 -0
- package/ky-apm/customHttp.js +38 -0
- package/ky-apm/index.js +68 -0
- package/ky-apm/plugins/performance.js +84 -0
- package/ky-apm/plugins/self-error.js +26 -0
- package/ky-apm/warn-log.js +3 -0
- package/package.json +81 -10
- package/plugin/ks-chii-webpack-html/index.js +53 -0
- package/plugin/ks-chii-webpack-html/package.json +16 -0
- package/postcss.config.js +15 -0
- package/public/capsule-positon.js +50 -0
- package/public/fonts/DingTalkJinBuTi.ttf +0 -0
- package/public/framework/axios@0.19.0.min.js +9 -0
- package/public/framework/fastclick@1.0.6.min.js +1 -0
- package/public/framework/iconfont/iconfont.css +91 -0
- package/public/framework/iconfont/iconfont.js +1 -0
- package/public/framework/iconfont/iconfont.json +142 -0
- 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 +7 -0
- package/public/framework/vue-router@3.1.3.min.js +6 -0
- package/public/framework/vue@2.6.10.runtime.min.js +6 -0
- package/public/framework/vuex@3.1.1.min.js +6 -0
- package/public/index.html +260 -0
- package/public/ks@3.0.8.umd.min.js +1 -0
- package/public/ksui@4.0.27.umd.min.js +10 -0
- package/public/status-bar-preset.js +39 -0
- package/{index.js → qt-npm/index.js} +3 -3
- package/qt-npm/package.json +13 -0
- package/src/App.vue +204 -0
- package/src/README.md +15 -0
- package/src/common/README.md +94 -0
- package/src/common/http/axios-adapter.js +47 -0
- package/src/common/http/common.js +88 -0
- package/src/common/http/http-interceptors.js +18 -0
- package/src/common/http/http-lock.js +45 -0
- package/src/common/http/index.js +163 -0
- package/src/common/http/token.js +9 -0
- package/src/common/styles/font/AlibabaSans102Ver2-Md.ttf +0 -0
- package/src/common/styles/font.less +12 -0
- package/src/common/styles/variables.less +43 -0
- package/src/common/utils/index.js +1 -0
- package/src/common/utils/platform/README.md +1 -0
- package/src/common/utils/platform/android/.gitkeep +0 -0
- package/src/common/utils/platform/core/index.js +24 -0
- package/src/common/utils/platform/index.js +164 -0
- package/src/common/utils/platform/ios/.gitkeep +0 -0
- package/src/common/utils/platform/subscribe/helper.js +38 -0
- package/src/common/utils/platform/subscribe/index.js +204 -0
- package/src/common/utils/platform/subscribe/table-animation.js +75 -0
- package/src/config/index.js +31 -0
- package/src/config.js +1 -0
- package/src/main.js +73 -0
- package/src/router.js +52 -0
- package/src/view/home/config.js +101 -0
- package/src/view/home/demo1.vue +223 -0
- package/src/view/home/demo2.vue +124 -0
- package/src/view/home/demo3.vue +51 -0
- package/src/view/home/demo4.vue +140 -0
- package/src/view/home/index.vue +97 -0
- package/src/view/home/query-table/README.md +45 -0
- package/src/view/home/query-table/api/index.js +12 -0
- package/src/view/home/query-table/assets/horizontal-back.svg +1 -0
- package/src/view/home/query-table/components/pe-table/cell.js +181 -0
- package/src/view/home/query-table/components/pe-table/collapse.js +334 -0
- package/src/view/home/query-table/components/pe-table/empty.vue +48 -0
- package/src/view/home/query-table/components/pe-table/header.js +328 -0
- 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 +1 -0
- package/src/view/home/query-table/components/pe-table/images/sort.svg +1 -0
- package/src/view/home/query-table/components/pe-table/images/sorting.svg +1 -0
- package/src/view/home/query-table/components/pe-table/images/unfold.svg +1 -0
- package/src/view/home/query-table/components/pe-table/index.vue +847 -0
- package/src/view/home/query-table/components/pe-table/load-more.js +46 -0
- package/src/view/home/query-table/components/pe-table/props/index.js +193 -0
- package/src/view/home/query-table/components/pe-table/row.vue +118 -0
- package/src/view/home/query-table/components/pe-table/scrollbar.js +424 -0
- package/src/view/home/query-table/components/pe-table/stretch-damping.js +112 -0
- package/src/view/home/query-table/components/pe-table/style/cell.less +89 -0
- package/src/view/home/query-table/components/pe-table/style/empty.less +48 -0
- package/src/view/home/query-table/components/pe-table/style/header.less +141 -0
- package/src/view/home/query-table/components/pe-table/style/index.less +88 -0
- package/src/view/home/query-table/components/pe-table/style/load-more.less +61 -0
- package/src/view/home/query-table/components/pe-table/style/row.less +6 -0
- package/src/view/home/query-table/components/pe-table/table-loading.vue +120 -0
- package/src/view/home/query-table/components/pe-table/table-total.vue +57 -0
- package/src/view/home/query-table/components/pe-table/utils/animate.js +80 -0
- package/src/view/home/query-table/components/pe-table/utils/columns.js +290 -0
- package/src/view/home/query-table/components/pe-table/utils/data.js +12 -0
- package/src/view/home/query-table/components/pe-table/utils/fixed.js +69 -0
- package/src/view/home/query-table/components/pe-table/utils/formatter.js +327 -0
- package/src/view/home/query-table/components/pe-table/utils/render-cells.js +424 -0
- package/src/view/home/query-table/components/pe-table/utils/slot.js +28 -0
- package/src/view/home/query-table/components/pe-table/utils/tools.js +84 -0
- package/src/view/home/query-table/components/pe-table/utils/touch-scroll.js +417 -0
- package/src/view/home/query-table/components/query-table/index.vue +497 -0
- package/src/view/home/query-table/components/query-table/mixins/column-mixin.js +102 -0
- package/src/view/home/query-table/components/query-table/mixins/column-setting.js +143 -0
- package/src/view/home/query-table/components/query-table/mixins/data-mixin.js +519 -0
- package/src/view/home/query-table/components/query-table/mixins/pagination-mixin.js +26 -0
- package/src/view/home/query-table/components/query-table/mixins/table-fixed.js +130 -0
- package/src/view/home/query-table/components/query-table/mixins/table-horizontal.js +119 -0
- package/src/view/home/query-table/components/table-horizontal.vue +99 -0
- package/src/view/home/query-table/components/table-pagination.vue +32 -0
- package/src/view/home/query-table/components/table-settings/assets/arrpw-up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/disabled-down.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/disabled-up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/down.svg +1 -0
- package/src/view/home/query-table/components/table-settings/assets/up.svg +1 -0
- package/src/view/home/query-table/components/table-settings/index.less +294 -0
- package/src/view/home/query-table/components/table-settings/index.vue +260 -0
- package/src/view/home/query-table/components/table-settings/settings.vue +479 -0
- package/src/view/home/query-table/components/table-settings/test.js +626 -0
- 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 +124 -0
- package/src/view/home/query-table/hooks/use-cache-promise.js +27 -0
- package/src/view/home/query-table/hooks/use-column-config.js +190 -0
- package/src/view/home/query-table/hooks/use-encryption.js +0 -0
- package/src/view/home/query-table/hooks/use-generic-search.js +95 -0
- package/src/view/home/query-table/index.js +7 -0
- package/src/view/home/query-table/store/column-store.js +0 -0
- package/src/view/home/query-table/styles/table.less +24 -0
- package/src/view/home/query-table/utils/column.js +36 -0
- package/src/view/home/query-table/utils/config.js +12 -0
- package/src/view/home/query-table/utils/encryption.js +32 -0
- package/src/view/home/query-table/utils/http.js +1 -0
- package/src/view/home/query-table/utils/localStorage.js +35 -0
- package/src/view/home//351/246/226/351/241/265.md +0 -0
- package/src/web.js +99 -0
- package/vue.config.js +131 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
import isFunction from 'lodash/isFunction';
|
|
2
|
+
import isNaN from 'lodash/isNaN';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 触摸滚动处理类
|
|
6
|
+
* 实现移动端触摸滚动及惯性滚动效果
|
|
7
|
+
*/
|
|
8
|
+
export class TouchScrolling {
|
|
9
|
+
/**
|
|
10
|
+
* 构造函数
|
|
11
|
+
* @param {HTMLElement} el - 需要绑定滚动效果的目标元素
|
|
12
|
+
* @param {Object} options - 配置选项
|
|
13
|
+
* @param {boolean} options.unScrollX - 是否禁用X轴滚动
|
|
14
|
+
* @param {boolean} options.unScrollY - 是否禁用Y轴滚动
|
|
15
|
+
* @param {boolean} options.isShowHorizontal - 是否显示水平滚动条
|
|
16
|
+
* @param {Function} options.handlerTouchend - 触摸结束回调函数
|
|
17
|
+
* @param {Function} options.handlerScrollEnd - 滚动结束回调函数
|
|
18
|
+
*/
|
|
19
|
+
constructor(el, options = {}) {
|
|
20
|
+
// 参数校验
|
|
21
|
+
if (!el) throw new Error('必须提供目标元素');
|
|
22
|
+
this.timer = null
|
|
23
|
+
this.isScrolling = null
|
|
24
|
+
|
|
25
|
+
// 初始化属性
|
|
26
|
+
this.el = el; // 目标DOM元素
|
|
27
|
+
this.decelerationId = null; // 减速动画ID
|
|
28
|
+
this.touchScrollState = null; // 触摸滚动状态
|
|
29
|
+
this.lastMoveTime = 0; // 上次移动时间戳
|
|
30
|
+
this.moveThrottle = 2; // 移动事件节流时间(毫秒)
|
|
31
|
+
this.touchPosition = null;
|
|
32
|
+
|
|
33
|
+
// 配置选项处理
|
|
34
|
+
this.unScrollX = !!options.unScrollX; // X轴滚动禁用状态
|
|
35
|
+
this.unScrollY = !!options.unScrollY; // Y轴滚动禁用状态
|
|
36
|
+
this.isShowHorizontal = !!options.isShowHorizontal; // 水平滚动条显示状态
|
|
37
|
+
|
|
38
|
+
// 回调函数绑定
|
|
39
|
+
this.handlerTouchStar = isFunction(options.handlerTouchStar) ? options.handlerTouchStar : null;
|
|
40
|
+
this.handlerTouchend = isFunction(options.handlerTouchend) ? options.handlerTouchend : null;
|
|
41
|
+
this.handlerTouchmove = isFunction(options.handlerTouchmove) ? options.handlerTouchmove : null;
|
|
42
|
+
this.onScrollEnd = isFunction(options.handlerScrollEnd) ? options.handlerScrollEnd : null;
|
|
43
|
+
this.handlerBeforeAnimation = isFunction(options.handlerBeforeAnimation) ? options.handlerBeforeAnimation : null;
|
|
44
|
+
|
|
45
|
+
// 绑定事件处理函数(仅绑定一次)
|
|
46
|
+
this.boundHandlers = {
|
|
47
|
+
touchstart: this.onTouchStart.bind(this),
|
|
48
|
+
touchend: this.onTouchEnd.bind(this),
|
|
49
|
+
touchmove: this.onTouchMove.bind(this),
|
|
50
|
+
touchcancel: this.onTouchCancel.bind(this),
|
|
51
|
+
pointermove: this.onPointermove.bind(this),
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// 添加事件监听
|
|
55
|
+
this.addEventListeners();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 添加事件监听器
|
|
60
|
+
*/
|
|
61
|
+
addEventListeners() {
|
|
62
|
+
const { touchstart, touchend, touchmove, touchcancel, pointermove } = this.boundHandlers;
|
|
63
|
+
this.el.addEventListener('touchstart', touchstart);
|
|
64
|
+
this.el.addEventListener('touchend', touchend);
|
|
65
|
+
this.el.addEventListener('touchmove', touchmove);
|
|
66
|
+
this.el.addEventListener('touchcancel', touchcancel);
|
|
67
|
+
this.el.addEventListener('pointermove', pointermove);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 移除事件监听器
|
|
72
|
+
*/
|
|
73
|
+
removeEventListeners() {
|
|
74
|
+
const { touchstart, touchend, touchmove } = this.boundHandlers;
|
|
75
|
+
this.el.removeEventListener('touchstart', touchstart);
|
|
76
|
+
this.el.removeEventListener('touchend', touchend);
|
|
77
|
+
this.el.removeEventListener('touchmove', touchmove);
|
|
78
|
+
this.el.removeEventListener('pointermove', pointermove);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 确保值为有效数字
|
|
83
|
+
* @param {*} value - 需要转换的值
|
|
84
|
+
* @returns {number} - 转换后的数字
|
|
85
|
+
*/
|
|
86
|
+
ensureNumeric(value) {
|
|
87
|
+
const numericValue = Number(value);
|
|
88
|
+
return isNaN(numericValue) ? 0 : numericValue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 派发滚轮事件
|
|
93
|
+
* @param {number} deltaY - Y轴滚动量
|
|
94
|
+
* @param {number} deltaX - X轴滚动量
|
|
95
|
+
*/
|
|
96
|
+
dispatchWheelEvent(deltaY, deltaX) {
|
|
97
|
+
deltaY = this.ensureNumeric(deltaY);
|
|
98
|
+
deltaX = this.ensureNumeric(deltaX);
|
|
99
|
+
|
|
100
|
+
// 无滚动量时不派发事件
|
|
101
|
+
if (!deltaY && !deltaX) {
|
|
102
|
+
// this.handlerBeforeAnimation?.(true)
|
|
103
|
+
return
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const wheelEvent = new WheelEvent('wheel', {
|
|
107
|
+
deltaY,
|
|
108
|
+
deltaX,
|
|
109
|
+
deltaMode: 0, // 像素模式
|
|
110
|
+
bubbles: true // 允许事件冒泡
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
this.el.dispatchEvent(wheelEvent);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 设置滚动属性
|
|
118
|
+
* @param {string} key - 属性名
|
|
119
|
+
* @param {*} val - 属性值
|
|
120
|
+
*/
|
|
121
|
+
setScroll(key, val) {
|
|
122
|
+
if (Object.prototype.hasOwnProperty.call(this, key)) {
|
|
123
|
+
this[key] = !!val;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 模拟惯性减速滚动效果
|
|
129
|
+
* @param {number} decelerationId - 当前减速动画ID
|
|
130
|
+
* @param {Boolean} isYAndDownToTop - Y轴并且从下至上滚动
|
|
131
|
+
*/
|
|
132
|
+
simulateDeceleratedScrolling(decelerationId, isYAndDownToTop) {
|
|
133
|
+
// 检查是否应该继续执行
|
|
134
|
+
if (!this.touchScrollState || decelerationId !== this.decelerationId) return;
|
|
135
|
+
|
|
136
|
+
// 减速效果配置常量
|
|
137
|
+
const DECELERATION_FACTOR = 0.92; // 减速因子
|
|
138
|
+
const MIN_SPEED = 0.005; // 最小速度阈值
|
|
139
|
+
const MAX_DURATION = 1000; // 最大持续时间(毫秒)
|
|
140
|
+
const Y_BOOST = 4; // Y轴初始速度增强倍数
|
|
141
|
+
const X_BOOST = 3.5; // X轴初始速度增强倍数
|
|
142
|
+
|
|
143
|
+
// 获取当前滚动量
|
|
144
|
+
let {
|
|
145
|
+
lastDeltaY: currentDeltaY,
|
|
146
|
+
lastDeltaX: currentDeltaX
|
|
147
|
+
} = this.touchScrollState;
|
|
148
|
+
|
|
149
|
+
// 无滚动量时直接触发结束
|
|
150
|
+
if (!currentDeltaY && !currentDeltaX) {
|
|
151
|
+
// 这里是为了处理没有滚动量的情况,兜底橡皮筋回弹效果。
|
|
152
|
+
// 场景:上拉到表格外部时,有概率出现 currentDeltaY = 0 && currentDeltaX = 0 的情况。
|
|
153
|
+
this.handlerBeforeAnimation?.(true)
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// 增强初始速度
|
|
158
|
+
currentDeltaY *= Y_BOOST;
|
|
159
|
+
currentDeltaX *= X_BOOST;
|
|
160
|
+
|
|
161
|
+
// 记录初始滚动方向
|
|
162
|
+
const initialDirection = {
|
|
163
|
+
y: Math.sign(currentDeltaY),
|
|
164
|
+
x: Math.sign(currentDeltaX)
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
let lastTime = performance.now(); // 上次动画帧时间
|
|
168
|
+
let elapsedTime = 0; // 已过去的时间
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 动画帧回调函数
|
|
172
|
+
* @param {number} timestamp - 当前时间戳
|
|
173
|
+
*/
|
|
174
|
+
const step = (timestamp) => {
|
|
175
|
+
// 检查是否应该继续执行
|
|
176
|
+
if (decelerationId !== this.decelerationId) return;
|
|
177
|
+
|
|
178
|
+
// 计算时间差(限制最大帧时间)
|
|
179
|
+
const deltaTime = Math.min(timestamp - lastTime, 32);
|
|
180
|
+
lastTime = timestamp;
|
|
181
|
+
elapsedTime += deltaTime;
|
|
182
|
+
|
|
183
|
+
// 计算当前减速因子
|
|
184
|
+
const progress = Math.min(1, elapsedTime / MAX_DURATION);
|
|
185
|
+
const currentFactor = DECELERATION_FACTOR * (1 - progress * 0.3);
|
|
186
|
+
const frameFactor = Math.pow(currentFactor, deltaTime / 16);
|
|
187
|
+
|
|
188
|
+
// 应用减速效果
|
|
189
|
+
currentDeltaY *= frameFactor;
|
|
190
|
+
currentDeltaX *= frameFactor;
|
|
191
|
+
|
|
192
|
+
// 确保滚动方向一致性
|
|
193
|
+
if (Math.sign(currentDeltaY) !== 0 && Math.sign(currentDeltaY) !== initialDirection.y) {
|
|
194
|
+
currentDeltaY = 0;
|
|
195
|
+
}
|
|
196
|
+
if (Math.sign(currentDeltaX) !== 0 && Math.sign(currentDeltaX) !== initialDirection.x) {
|
|
197
|
+
currentDeltaX = 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 检查停止条件
|
|
201
|
+
const shouldStop =
|
|
202
|
+
(Math.abs(currentDeltaY) < MIN_SPEED && Math.abs(currentDeltaX) < MIN_SPEED * 2) ||
|
|
203
|
+
elapsedTime >= MAX_DURATION;
|
|
204
|
+
|
|
205
|
+
if (shouldStop) {
|
|
206
|
+
this.triggerScrollEnd(initialDirection);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const isBottom = this.handlerBeforeAnimation?.(isYAndDownToTop)
|
|
211
|
+
|
|
212
|
+
if (isBottom) return
|
|
213
|
+
|
|
214
|
+
// 派发滚轮事件并继续动画
|
|
215
|
+
this.dispatchWheelEvent(currentDeltaY, currentDeltaX);
|
|
216
|
+
requestAnimationFrame(step);
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// 启动动画
|
|
220
|
+
requestAnimationFrame(step);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* 触发滚动结束回调
|
|
225
|
+
* @param {Object|null} direction - 滚动方向对象
|
|
226
|
+
*/
|
|
227
|
+
triggerScrollEnd(direction = null) {
|
|
228
|
+
// 如果没有提供方向,则从状态中获取
|
|
229
|
+
if (!direction && this.touchScrollState) {
|
|
230
|
+
direction = {
|
|
231
|
+
y: Math.sign(this.touchScrollState.lastDeltaY),
|
|
232
|
+
x: Math.sign(this.touchScrollState.lastDeltaX)
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
// 调用滚动结束回调(如果存在)
|
|
236
|
+
this.onScrollEnd?.(direction);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 触摸开始事件处理
|
|
241
|
+
* @param {TouchEvent} event - 触摸事件对象
|
|
242
|
+
*/
|
|
243
|
+
onTouchStart(event) {
|
|
244
|
+
// 只处理单指触摸
|
|
245
|
+
if (event.touches.length !== 1) return;
|
|
246
|
+
this.touchPosition = this.el.getBoundingClientRect()
|
|
247
|
+
|
|
248
|
+
const touch = event.touches[0];
|
|
249
|
+
const now = performance.now();
|
|
250
|
+
|
|
251
|
+
// 初始化触摸状态
|
|
252
|
+
this.touchScrollState = {
|
|
253
|
+
startY: touch.clientY, // 起始Y坐标
|
|
254
|
+
lastY: touch.clientY, // 上次Y坐标
|
|
255
|
+
lastDeltaY: 0, // 上次Y轴变化量
|
|
256
|
+
startX: touch.clientX, // 起始X坐标
|
|
257
|
+
lastX: touch.clientX, // 上次X坐标
|
|
258
|
+
lastDeltaX: 0, // 上次X轴变化量
|
|
259
|
+
startTime: now, // 触摸开始时间
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// 使用时间戳作为减速动画ID
|
|
263
|
+
this.decelerationId = now;
|
|
264
|
+
this.lastMoveTime = now;
|
|
265
|
+
this.handlerTouchStar?.(event)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* 触摸取消事件处理
|
|
270
|
+
*/
|
|
271
|
+
onTouchCancel() {
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* 触摸结束事件处理
|
|
276
|
+
*/
|
|
277
|
+
onTouchEnd() {
|
|
278
|
+
// 检查是否有有效的触摸状态
|
|
279
|
+
if (!this.touchScrollState || !this.decelerationId) {
|
|
280
|
+
this.touchScrollState = null;
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// 获取触摸状态数据
|
|
285
|
+
const {
|
|
286
|
+
startY, lastY,
|
|
287
|
+
startX, lastX,
|
|
288
|
+
startTime
|
|
289
|
+
} = this.touchScrollState;
|
|
290
|
+
|
|
291
|
+
// 计算触摸持续时间和距离
|
|
292
|
+
const touchDuration = performance.now() - startTime;
|
|
293
|
+
const totalDeltaY = Math.abs(startY - lastY);
|
|
294
|
+
const totalDeltaX = Math.abs(startX - lastX);
|
|
295
|
+
const totalDistance = Math.max(totalDeltaY, totalDeltaX);
|
|
296
|
+
const speed = touchDuration > 0 ? totalDistance / touchDuration : 0;
|
|
297
|
+
|
|
298
|
+
// 处理触摸结束回调
|
|
299
|
+
const finalOffsetY = this.touchScrollState.lastDeltaY / 0.05;
|
|
300
|
+
this.handlerTouchend?.(finalOffsetY);
|
|
301
|
+
|
|
302
|
+
// 判断Y轴并且从下至上滚动
|
|
303
|
+
const isY = Math.sign(this.touchScrollState.lastDeltaX) === 0
|
|
304
|
+
const isDownToTop = lastY < startY
|
|
305
|
+
const isYAndDownToTop = isY && isDownToTop
|
|
306
|
+
// 根据速度决定是否应用惯性效果
|
|
307
|
+
const SPEED_THRESHOLD = 0.5; // 速度阈值
|
|
308
|
+
if (speed >= SPEED_THRESHOLD) {
|
|
309
|
+
this.simulateDeceleratedScrolling(this.decelerationId, isYAndDownToTop);
|
|
310
|
+
} else {
|
|
311
|
+
this.triggerScrollEnd();
|
|
312
|
+
this.handlerBeforeAnimation?.(isYAndDownToTop)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// 清除触摸状态
|
|
316
|
+
this.touchScrollState = null;
|
|
317
|
+
clearTimeout(this.timer);
|
|
318
|
+
this.timer = null;
|
|
319
|
+
if (this.isScrolling) {
|
|
320
|
+
this.handlerBeforeAnimation?.(true)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
onPointermove() {
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 触摸移动事件处理
|
|
330
|
+
* @param {TouchEvent} event - 触摸事件对象
|
|
331
|
+
*/
|
|
332
|
+
onTouchMove(event) {
|
|
333
|
+
// 只处理单指触摸且有触摸状态的情况
|
|
334
|
+
if (!this.touchScrollState || event.touches.length !== 1) return;
|
|
335
|
+
|
|
336
|
+
// 节流处理
|
|
337
|
+
const now = performance.now();
|
|
338
|
+
if (now - this.lastMoveTime < this.moveThrottle) return;
|
|
339
|
+
this.lastMoveTime = now;
|
|
340
|
+
|
|
341
|
+
// 获取当前触摸点坐标
|
|
342
|
+
const touch = event.touches[0];
|
|
343
|
+
const currentY = touch.clientY;
|
|
344
|
+
const currentX = touch.clientX;
|
|
345
|
+
|
|
346
|
+
// 计算滚动量
|
|
347
|
+
let deltaY = this.touchScrollState.lastY - currentY;
|
|
348
|
+
let deltaX = this.touchScrollState.lastX - currentX;
|
|
349
|
+
|
|
350
|
+
// 确定主要滚动方向
|
|
351
|
+
const diffY = Math.abs(this.touchScrollState.startY - currentY);
|
|
352
|
+
const diffX = Math.abs(this.touchScrollState.startX - currentX);
|
|
353
|
+
const isVerticalScroll = (diffX - diffY) <= 0;
|
|
354
|
+
|
|
355
|
+
// 应用滚动限制
|
|
356
|
+
if (isVerticalScroll) {
|
|
357
|
+
// 判断Y轴并且从下至上滚动
|
|
358
|
+
// const isY = Math.sign(this.touchScrollState.lastDeltaX) === 0
|
|
359
|
+
// const isDownToTop = this.touchScrollState.lastY < this.touchScrollState.startY
|
|
360
|
+
// const isYAndDownToTop = isY && isDownToTop
|
|
361
|
+
// this.handlerBeforeAnimation?.(true)
|
|
362
|
+
// 垂直滚动处理
|
|
363
|
+
if (this.unScrollY && !this.isShowHorizontal) {
|
|
364
|
+
this.updateTouchState(currentY, currentX, 0, 0);
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
deltaX = 0; // 垂直滚动时忽略水平移动
|
|
368
|
+
} else {
|
|
369
|
+
// 水平滚动处理
|
|
370
|
+
deltaY = 0; // 水平滚动时忽略垂直移动
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// 阻止默认行为并派发滚轮事件
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
this.dispatchWheelEvent(deltaY, deltaX);
|
|
376
|
+
this.updateTouchState(currentY, currentX, deltaY, deltaX);
|
|
377
|
+
|
|
378
|
+
// 清除之前的定时器
|
|
379
|
+
clearTimeout(this.timer);
|
|
380
|
+
this.timer = null;
|
|
381
|
+
// 标记为正在滑动
|
|
382
|
+
this.isScrolling = true;
|
|
383
|
+
// 设置新的定时器
|
|
384
|
+
this.timer = setTimeout(() => {
|
|
385
|
+
this.isScrolling = false;
|
|
386
|
+
this.touchScrollState = null;
|
|
387
|
+
this.handlerBeforeAnimation?.(true);
|
|
388
|
+
}, 150); // 150ms 内没有新的 touchmove 事件则认为停止
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* 更新触摸状态
|
|
393
|
+
* @param {number} y - 当前Y坐标
|
|
394
|
+
* @param {number} x - 当前X坐标
|
|
395
|
+
* @param {number} deltaY - Y轴滚动量
|
|
396
|
+
* @param {number} deltaX - X轴滚动量
|
|
397
|
+
*/
|
|
398
|
+
updateTouchState(y, x, deltaY, deltaX) {
|
|
399
|
+
if (!this.touchScrollState) return;
|
|
400
|
+
|
|
401
|
+
// 更新触摸状态
|
|
402
|
+
this.touchScrollState.lastY = y;
|
|
403
|
+
this.touchScrollState.lastDeltaY = deltaY;
|
|
404
|
+
this.touchScrollState.lastX = x;
|
|
405
|
+
this.touchScrollState.lastDeltaX = deltaX;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* 销毁方法,清理资源
|
|
410
|
+
*/
|
|
411
|
+
destroy() {
|
|
412
|
+
this.removeEventListeners(); // 移除事件监听
|
|
413
|
+
this.touchScrollState = null; // 清除触摸状态
|
|
414
|
+
cancelAnimationFrame(this.decelerationId); // 取消动画帧
|
|
415
|
+
this.decelerationId = null; // 清除动画ID
|
|
416
|
+
}
|
|
417
|
+
}
|