@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.
Files changed (310) hide show
  1. package/.bitmap +38 -0
  2. package/.editorconfig +5 -0
  3. package/.env.dev +2 -0
  4. package/.env.gray +2 -0
  5. package/.env.prod +2 -0
  6. package/.env.stg +3 -0
  7. package/.env.uat +2 -0
  8. package/.eslintignore +1 -0
  9. package/.eslintrc.js +25 -0
  10. package/.gitmodules +4 -0
  11. package/.prettierrc +11 -0
  12. package/README.md +15 -0
  13. package/babel.config.js +10 -0
  14. package/build-apm.sh +9 -0
  15. package/build.sh +16 -0
  16. package/config/index.js +20 -0
  17. package/jsconfig.json +7 -0
  18. package/kuasheng-sdk/index.js +80 -0
  19. package/kuasheng-sdk/lib/assets.js +304 -0
  20. package/kuasheng-sdk/lib/context.js +199 -0
  21. package/kuasheng-sdk/lib/layout.js +346 -0
  22. package/kuasheng-sdk/lib/location.js +46 -0
  23. package/kuasheng-sdk/lib/media.js +342 -0
  24. package/kuasheng-sdk/lib/navigation.js +30 -0
  25. package/kuasheng-sdk/lib/request.js +76 -0
  26. package/kuasheng-sdk/lib/system.js +190 -0
  27. package/kuasheng-sdk/lib/userinfo.js +98 -0
  28. package/kuasheng-sdk/util/check.js +102 -0
  29. package/kuasheng-sdk/util/config.js +47 -0
  30. package/kuasheng-sdk/util/device.js +25 -0
  31. package/kuasheng-sdk/util/error.js +19 -0
  32. package/kuasheng-sdk/util/funtional.js +153 -0
  33. package/kuasheng-sdk/util/mixin.js +36 -0
  34. package/kuasheng-sdk/util/requestUtil.js +41 -0
  35. package/kuasheng-sdk/util/response.js +33 -0
  36. package/kuasheng-sdk/util/warn.js +35 -0
  37. package/kuasheng-ui/CHANGELOG.md +9 -0
  38. package/kuasheng-ui/components/card.vue +57 -0
  39. package/kuasheng-ui/components/ks-area-select/README.md +43 -0
  40. package/kuasheng-ui/components/ks-area-select/area-picker.vue +554 -0
  41. package/kuasheng-ui/components/ks-area-select/area-search.vue +363 -0
  42. package/kuasheng-ui/components/ks-area-select/areas-pop.vue +56 -0
  43. package/kuasheng-ui/components/ks-area-select/common.js +183 -0
  44. package/kuasheng-ui/components/ks-area-select/index.vue +355 -0
  45. package/kuasheng-ui/components/ks-area-select/mixins.js +216 -0
  46. package/kuasheng-ui/components/ks-area-single-select/README.md +50 -0
  47. package/kuasheng-ui/components/ks-area-single-select/hot-city.js +45 -0
  48. package/kuasheng-ui/components/ks-area-single-select/index.vue +324 -0
  49. package/kuasheng-ui/components/ks-calendar/index.vue +269 -0
  50. package/kuasheng-ui/components/ks-call-phone/call-tips.vue +70 -0
  51. package/kuasheng-ui/components/ks-call-phone/call.vue +178 -0
  52. package/kuasheng-ui/components/ks-call-phone/index.js +48 -0
  53. package/kuasheng-ui/components/ks-call-phone/index.vue +131 -0
  54. package/kuasheng-ui/components/ks-call-phone//345/221/274/345/217/253/347/273/204/344/273/266.md +0 -0
  55. package/kuasheng-ui/components/ks-date-picker/README.md +23 -0
  56. package/kuasheng-ui/components/ks-date-picker/date-picker-bottom.vue +123 -0
  57. package/kuasheng-ui/components/ks-date-picker/date-picker-dropdown.vue +80 -0
  58. package/kuasheng-ui/components/ks-date-picker/date-picker-right.vue +87 -0
  59. package/kuasheng-ui/components/ks-date-picker/date-picker-top.vue +88 -0
  60. package/kuasheng-ui/components/ks-date-picker/date-picker.js +15 -0
  61. package/kuasheng-ui/components/ks-date-picker/date-range-select.vue +92 -0
  62. package/kuasheng-ui/components/ks-date-picker/date-select.vue +65 -0
  63. package/kuasheng-ui/components/ks-date-picker/date-week-month.vue +131 -0
  64. package/kuasheng-ui/components/ks-date-picker/index.js +12 -0
  65. package/kuasheng-ui/components/ks-date-picker/mixin.js +92 -0
  66. package/kuasheng-ui/components/ks-date-picker/month-range-select.vue +129 -0
  67. package/kuasheng-ui/components/ks-date-picker/month-select.vue +85 -0
  68. package/kuasheng-ui/components/ks-date-picker/quarter-select.vue +94 -0
  69. package/kuasheng-ui/components/ks-date-picker/style.less +121 -0
  70. package/kuasheng-ui/components/ks-date-picker/utils.js +109 -0
  71. package/kuasheng-ui/components/ks-date-picker/week-select.vue +99 -0
  72. package/kuasheng-ui/components/ks-decrypt/index.vue +159 -0
  73. package/kuasheng-ui/components/ks-employee/README.md +78 -0
  74. package/kuasheng-ui/components/ks-employee/employee-input.vue +173 -0
  75. package/kuasheng-ui/components/ks-employee/employee-list.vue +662 -0
  76. package/kuasheng-ui/components/ks-employee/employee-popup.vue +197 -0
  77. package/kuasheng-ui/components/ks-employee/employee-search.vue +250 -0
  78. package/kuasheng-ui/components/ks-employee/employee-selected.vue +173 -0
  79. package/kuasheng-ui/components/ks-employee/index.js +17 -0
  80. package/kuasheng-ui/components/ks-employee/package-lock.json +5 -0
  81. package/kuasheng-ui/components/ks-employee/package.json +15 -0
  82. package/kuasheng-ui/components/ks-employee/yarn.lock +4 -0
  83. package/kuasheng-ui/components/ks-field-money/index.js +8 -0
  84. package/kuasheng-ui/components/ks-field-money/index.vue +212 -0
  85. package/kuasheng-ui/components/ks-field-money/package.json +11 -0
  86. package/kuasheng-ui/components/ks-field-money/utils.js +65 -0
  87. 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
  88. package/kuasheng-ui/components/ks-history-search/history-input.vue +131 -0
  89. package/kuasheng-ui/components/ks-history-search/history-list.vue +188 -0
  90. package/kuasheng-ui/components/ks-history-search/img/delete.png +0 -0
  91. package/kuasheng-ui/components/ks-history-search/index.js +9 -0
  92. package/kuasheng-ui/components/ks-history-search/index.vue +125 -0
  93. package/kuasheng-ui/components/ks-history-search/package-lock.json +5 -0
  94. package/kuasheng-ui/components/ks-history-search/package.json +15 -0
  95. package/kuasheng-ui/components/ks-history-search/utils.js +35 -0
  96. package/kuasheng-ui/components/ks-input-search/index.vue +106 -0
  97. package/kuasheng-ui/components/ks-list/index.vue +75 -0
  98. package/kuasheng-ui/components/ks-loading/index.js +16 -0
  99. package/kuasheng-ui/components/ks-month/index.vue +47 -0
  100. package/kuasheng-ui/components/ks-month/package.json +3 -0
  101. package/kuasheng-ui/components/ks-month/range.vue +172 -0
  102. package/kuasheng-ui/components/ks-month/single.vue +136 -0
  103. package/kuasheng-ui/components/ks-month/style.less +125 -0
  104. package/kuasheng-ui/components/ks-month/utils.js +35 -0
  105. package/kuasheng-ui/components/ks-nav/index.vue +264 -0
  106. package/kuasheng-ui/components/ks-nav-bar.js +35 -0
  107. package/kuasheng-ui/components/ks-org/ks-org-tree.vue +247 -0
  108. package/kuasheng-ui/components/ks-org/ks-popup-tree.vue +154 -0
  109. package/kuasheng-ui/components/ks-org/ks-tree-input.vue +240 -0
  110. package/kuasheng-ui/components/ks-org/ks-tree-node.vue +94 -0
  111. package/kuasheng-ui/components/ks-org/ks-tree.vue +229 -0
  112. package/kuasheng-ui/components/ks-org/utils.js +54 -0
  113. package/kuasheng-ui/components/ks-popover/index.vue +457 -0
  114. package/kuasheng-ui/components/ks-popover/mixin.js +28 -0
  115. package/kuasheng-ui/components/ks-popover/utils.js +60 -0
  116. package/kuasheng-ui/components/ks-pull-refresh/index.vue +43 -0
  117. package/kuasheng-ui/components/ks-quarter/index.vue +256 -0
  118. package/kuasheng-ui/components/ks-table/README.md +103 -0
  119. package/kuasheng-ui/components/ks-table/cell.vue +31 -0
  120. package/kuasheng-ui/components/ks-table/index.js +8 -0
  121. package/kuasheng-ui/components/ks-table/index.less +486 -0
  122. package/kuasheng-ui/components/ks-table/index.vue +1088 -0
  123. package/kuasheng-ui/components/ks-table/package.json +12 -0
  124. package/kuasheng-ui/components/ks-table/release.md +7 -0
  125. package/kuasheng-ui/components/ks-toast.js +35 -0
  126. package/kuasheng-ui/components/ks-upload/index.vue +174 -0
  127. package/kuasheng-ui/components/ks-user-access.vue +229 -0
  128. package/kuasheng-ui/components/no-data/README.md +45 -0
  129. package/kuasheng-ui/components/no-data/image.js +1 -0
  130. package/kuasheng-ui/components/no-data/index.vue +83 -0
  131. package/kuasheng-ui/components/notice-bar.vue +16 -0
  132. package/kuasheng-ui/components/steps.js +11 -0
  133. package/kuasheng-ui/components/tabs.vue +40 -0
  134. package/kuasheng-ui/index.js +239 -0
  135. package/kuasheng-ui/patch/datetime-picker/datetimePicker.md +0 -0
  136. package/kuasheng-ui/patch/datetime-picker/index.js +46 -0
  137. package/kuasheng-ui/patch/datetime-picker/utils.js +78 -0
  138. package/kuasheng-ui/patch/field/field.md +1 -0
  139. package/kuasheng-ui/patch/field/index.js +122 -0
  140. package/kuasheng-ui/patch/field/utils.js +36 -0
  141. package/kuasheng-ui/patch/form/form.md +7 -0
  142. package/kuasheng-ui/patch/form/index.js +106 -0
  143. package/kuasheng-ui/patch/index.js +12 -0
  144. package/kuasheng-ui/patch/pagination/index.js +78 -0
  145. package/kuasheng-ui/style/animation-ui.less +31 -0
  146. package/kuasheng-ui/style/font/number/font-number1.otf +0 -0
  147. package/kuasheng-ui/style/font/number/font-number2.ttf +0 -0
  148. package/kuasheng-ui/style/images/checked.svg +1 -0
  149. package/kuasheng-ui/style/images/success.svg +1 -0
  150. package/kuasheng-ui/style/index.less +6 -0
  151. package/kuasheng-ui/style/kuasheng-ui.less +207 -0
  152. package/kuasheng-ui/style/reset-vant.less +307 -0
  153. package/kuasheng-ui/style/vant-var.less +138 -0
  154. package/kuasheng-ui/utils/apis.js +17 -0
  155. package/kuasheng-ui/utils/axios-adapter.js +47 -0
  156. package/kuasheng-ui/utils/bem.js +39 -0
  157. package/kuasheng-ui/utils/bus.js +97 -0
  158. package/kuasheng-ui/utils/common.js +88 -0
  159. package/kuasheng-ui/utils/decrypt/config.js +12 -0
  160. package/kuasheng-ui/utils/decrypt/decrypt-api.js +139 -0
  161. package/kuasheng-ui/utils/decrypt/index.js +6 -0
  162. package/kuasheng-ui/utils/decrypt/mask.js +36 -0
  163. package/kuasheng-ui/utils/decrypt/virtual.js +44 -0
  164. package/kuasheng-ui/utils/directive.js +57 -0
  165. package/kuasheng-ui/utils/directive.md +23 -0
  166. package/kuasheng-ui/utils/drcheck-plugin.js +219 -0
  167. package/kuasheng-ui/utils/error-plugin.js +88 -0
  168. package/kuasheng-ui/utils/filter.js +149 -0
  169. package/kuasheng-ui/utils/http-interceptors.js +18 -0
  170. package/kuasheng-ui/utils/http.js +140 -0
  171. package/kuasheng-ui/utils/index.js +5 -0
  172. package/kuasheng-ui/utils/init-event.js +20 -0
  173. package/kuasheng-ui/utils/log.js +309 -0
  174. package/kuasheng-ui/utils/token.js +9 -0
  175. package/kuasheng-ui/utils/type.js +45 -0
  176. package/kuasheng-ui/utils/validate.js +20 -0
  177. package/kuasheng-ui/utils/watermark.js +67 -0
  178. package/kuasheng-ui/version.js +1 -0
  179. package/ky-apm/client.js +37 -0
  180. package/ky-apm/customHttp.js +38 -0
  181. package/ky-apm/index.js +68 -0
  182. package/ky-apm/plugins/performance.js +84 -0
  183. package/ky-apm/plugins/self-error.js +26 -0
  184. package/ky-apm/warn-log.js +3 -0
  185. package/package.json +81 -10
  186. package/plugin/ks-chii-webpack-html/index.js +53 -0
  187. package/plugin/ks-chii-webpack-html/package.json +16 -0
  188. package/postcss.config.js +15 -0
  189. package/public/capsule-positon.js +50 -0
  190. package/public/fonts/DingTalkJinBuTi.ttf +0 -0
  191. package/public/framework/axios@0.19.0.min.js +9 -0
  192. package/public/framework/fastclick@1.0.6.min.js +1 -0
  193. package/public/framework/iconfont/iconfont.css +91 -0
  194. package/public/framework/iconfont/iconfont.js +1 -0
  195. package/public/framework/iconfont/iconfont.json +142 -0
  196. package/public/framework/iconfont/iconfont.ttf +0 -0
  197. package/public/framework/iconfont/iconfont.woff +0 -0
  198. package/public/framework/iconfont/iconfont.woff2 +0 -0
  199. package/public/framework/vant@2.5.6.min.js +7 -0
  200. package/public/framework/vue-router@3.1.3.min.js +6 -0
  201. package/public/framework/vue@2.6.10.runtime.min.js +6 -0
  202. package/public/framework/vuex@3.1.1.min.js +6 -0
  203. package/public/index.html +260 -0
  204. package/public/ks@3.0.8.umd.min.js +1 -0
  205. package/public/ksui@4.0.27.umd.min.js +10 -0
  206. package/public/status-bar-preset.js +39 -0
  207. package/{index.js → qt-npm/index.js} +3 -3
  208. package/qt-npm/package.json +13 -0
  209. package/src/App.vue +204 -0
  210. package/src/README.md +15 -0
  211. package/src/common/README.md +94 -0
  212. package/src/common/http/axios-adapter.js +47 -0
  213. package/src/common/http/common.js +88 -0
  214. package/src/common/http/http-interceptors.js +18 -0
  215. package/src/common/http/http-lock.js +45 -0
  216. package/src/common/http/index.js +163 -0
  217. package/src/common/http/token.js +9 -0
  218. package/src/common/styles/font/AlibabaSans102Ver2-Md.ttf +0 -0
  219. package/src/common/styles/font.less +12 -0
  220. package/src/common/styles/variables.less +43 -0
  221. package/src/common/utils/index.js +1 -0
  222. package/src/common/utils/platform/README.md +1 -0
  223. package/src/common/utils/platform/android/.gitkeep +0 -0
  224. package/src/common/utils/platform/core/index.js +24 -0
  225. package/src/common/utils/platform/index.js +164 -0
  226. package/src/common/utils/platform/ios/.gitkeep +0 -0
  227. package/src/common/utils/platform/subscribe/helper.js +38 -0
  228. package/src/common/utils/platform/subscribe/index.js +204 -0
  229. package/src/common/utils/platform/subscribe/table-animation.js +75 -0
  230. package/src/config/index.js +31 -0
  231. package/src/config.js +1 -0
  232. package/src/main.js +73 -0
  233. package/src/router.js +52 -0
  234. package/src/view/home/config.js +101 -0
  235. package/src/view/home/demo1.vue +223 -0
  236. package/src/view/home/demo2.vue +124 -0
  237. package/src/view/home/demo3.vue +51 -0
  238. package/src/view/home/demo4.vue +140 -0
  239. package/src/view/home/index.vue +97 -0
  240. package/src/view/home/query-table/README.md +45 -0
  241. package/src/view/home/query-table/api/index.js +12 -0
  242. package/src/view/home/query-table/assets/horizontal-back.svg +1 -0
  243. package/src/view/home/query-table/components/pe-table/cell.js +181 -0
  244. package/src/view/home/query-table/components/pe-table/collapse.js +334 -0
  245. package/src/view/home/query-table/components/pe-table/empty.vue +48 -0
  246. package/src/view/home/query-table/components/pe-table/header.js +328 -0
  247. package/src/view/home/query-table/components/pe-table/images/abnormal.png +0 -0
  248. package/src/view/home/query-table/components/pe-table/images/empty.png +0 -0
  249. package/src/view/home/query-table/components/pe-table/images/fold.svg +1 -0
  250. package/src/view/home/query-table/components/pe-table/images/sort.svg +1 -0
  251. package/src/view/home/query-table/components/pe-table/images/sorting.svg +1 -0
  252. package/src/view/home/query-table/components/pe-table/images/unfold.svg +1 -0
  253. package/src/view/home/query-table/components/pe-table/index.vue +847 -0
  254. package/src/view/home/query-table/components/pe-table/load-more.js +46 -0
  255. package/src/view/home/query-table/components/pe-table/props/index.js +193 -0
  256. package/src/view/home/query-table/components/pe-table/row.vue +118 -0
  257. package/src/view/home/query-table/components/pe-table/scrollbar.js +424 -0
  258. package/src/view/home/query-table/components/pe-table/stretch-damping.js +112 -0
  259. package/src/view/home/query-table/components/pe-table/style/cell.less +89 -0
  260. package/src/view/home/query-table/components/pe-table/style/empty.less +48 -0
  261. package/src/view/home/query-table/components/pe-table/style/header.less +141 -0
  262. package/src/view/home/query-table/components/pe-table/style/index.less +88 -0
  263. package/src/view/home/query-table/components/pe-table/style/load-more.less +61 -0
  264. package/src/view/home/query-table/components/pe-table/style/row.less +6 -0
  265. package/src/view/home/query-table/components/pe-table/table-loading.vue +120 -0
  266. package/src/view/home/query-table/components/pe-table/table-total.vue +57 -0
  267. package/src/view/home/query-table/components/pe-table/utils/animate.js +80 -0
  268. package/src/view/home/query-table/components/pe-table/utils/columns.js +290 -0
  269. package/src/view/home/query-table/components/pe-table/utils/data.js +12 -0
  270. package/src/view/home/query-table/components/pe-table/utils/fixed.js +69 -0
  271. package/src/view/home/query-table/components/pe-table/utils/formatter.js +327 -0
  272. package/src/view/home/query-table/components/pe-table/utils/render-cells.js +424 -0
  273. package/src/view/home/query-table/components/pe-table/utils/slot.js +28 -0
  274. package/src/view/home/query-table/components/pe-table/utils/tools.js +84 -0
  275. package/src/view/home/query-table/components/pe-table/utils/touch-scroll.js +417 -0
  276. package/src/view/home/query-table/components/query-table/index.vue +497 -0
  277. package/src/view/home/query-table/components/query-table/mixins/column-mixin.js +102 -0
  278. package/src/view/home/query-table/components/query-table/mixins/column-setting.js +143 -0
  279. package/src/view/home/query-table/components/query-table/mixins/data-mixin.js +519 -0
  280. package/src/view/home/query-table/components/query-table/mixins/pagination-mixin.js +26 -0
  281. package/src/view/home/query-table/components/query-table/mixins/table-fixed.js +130 -0
  282. package/src/view/home/query-table/components/query-table/mixins/table-horizontal.js +119 -0
  283. package/src/view/home/query-table/components/table-horizontal.vue +99 -0
  284. package/src/view/home/query-table/components/table-pagination.vue +32 -0
  285. package/src/view/home/query-table/components/table-settings/assets/arrpw-up.svg +1 -0
  286. package/src/view/home/query-table/components/table-settings/assets/disabled-down.svg +1 -0
  287. package/src/view/home/query-table/components/table-settings/assets/disabled-up.svg +1 -0
  288. package/src/view/home/query-table/components/table-settings/assets/down.svg +1 -0
  289. package/src/view/home/query-table/components/table-settings/assets/up.svg +1 -0
  290. package/src/view/home/query-table/components/table-settings/index.less +294 -0
  291. package/src/view/home/query-table/components/table-settings/index.vue +260 -0
  292. package/src/view/home/query-table/components/table-settings/settings.vue +479 -0
  293. package/src/view/home/query-table/components/table-settings/test.js +626 -0
  294. package/src/view/home/query-table/components/table-settings//344/270/252/346/200/247/350/256/276/347/275/256.md +0 -0
  295. package/src/view/home/query-table/components/tooltip.js +124 -0
  296. package/src/view/home/query-table/hooks/use-cache-promise.js +27 -0
  297. package/src/view/home/query-table/hooks/use-column-config.js +190 -0
  298. package/src/view/home/query-table/hooks/use-encryption.js +0 -0
  299. package/src/view/home/query-table/hooks/use-generic-search.js +95 -0
  300. package/src/view/home/query-table/index.js +7 -0
  301. package/src/view/home/query-table/store/column-store.js +0 -0
  302. package/src/view/home/query-table/styles/table.less +24 -0
  303. package/src/view/home/query-table/utils/column.js +36 -0
  304. package/src/view/home/query-table/utils/config.js +12 -0
  305. package/src/view/home/query-table/utils/encryption.js +32 -0
  306. package/src/view/home/query-table/utils/http.js +1 -0
  307. package/src/view/home/query-table/utils/localStorage.js +35 -0
  308. package/src/view/home//351/246/226/351/241/265.md +0 -0
  309. package/src/web.js +99 -0
  310. package/vue.config.js +131 -0
@@ -0,0 +1,847 @@
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>