@weitutech/by-components 1.1.46 → 1.1.48

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.
@@ -60752,8 +60752,8 @@ var component = normalizeComponent(
60752
60752
  )
60753
60753
 
60754
60754
  /* harmony default export */ var pager = (component.exports);
60755
- ;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"268ca57a-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-82.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/table/index.vue?vue&type=template&id=849a6584
60756
- var tablevue_type_template_id_849a6584_render = function render() {
60755
+ ;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"268ca57a-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-82.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/table/index.vue?vue&type=template&id=edc3cbea
60756
+ var tablevue_type_template_id_edc3cbea_render = function render() {
60757
60757
  var _vm = this,
60758
60758
  _c = _vm._self._c;
60759
60759
  return _c('div', [_c('vxe-grid', _vm._g(_vm._b({
@@ -60827,7 +60827,7 @@ var tablevue_type_template_id_849a6584_render = function render() {
60827
60827
  }
60828
60828
  }) : _vm._e()], 1);
60829
60829
  };
60830
- var tablevue_type_template_id_849a6584_staticRenderFns = [];
60830
+ var tablevue_type_template_id_edc3cbea_staticRenderFns = [];
60831
60831
 
60832
60832
  // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.push.js
60833
60833
  var es_array_push = __webpack_require__(4114);
@@ -61779,6 +61779,7 @@ var custom_column_component = normalizeComponent(
61779
61779
  * @property {Object} sortConfig - 排序配置
61780
61780
  * @property {boolean} sortConfig.remote - 是否远程排序
61781
61781
  * @property {string} sortConfig.trigger - 排序触发方式
61782
+ * @property {boolean} sortConfig.frontendSort - 是否启用前端排序
61782
61783
  * @property {Array} copyFields - 可复制字段列表
61783
61784
  * @property {string} emptyText - 空数据提示文本
61784
61785
  * @property {Object} loadingConfig - 加载配置
@@ -61816,6 +61817,11 @@ var custom_column_component = normalizeComponent(
61816
61817
  tempColumns: [],
61817
61818
  // 存储所有数据(用于前端分页)
61818
61819
  allData: [],
61820
+ // 排序状态
61821
+ sortState: {
61822
+ field: null,
61823
+ order: null
61824
+ },
61819
61825
  tableLoading: false
61820
61826
  };
61821
61827
  },
@@ -61845,10 +61851,14 @@ var custom_column_component = normalizeComponent(
61845
61851
  top: 0,
61846
61852
  left: 0
61847
61853
  });
61848
- const tableData = this.$refs.xGrid.getTableData().fullData;
61849
- if (tableData && tableData.length > 0) {
61850
- this.$refs.xGrid.scrollToRow(tableData[0]);
61851
- }
61854
+ }
61855
+ // 数据变化后恢复排序高亮
61856
+ if (this.sortState.field && this.sortState.order && this.$refs.xGrid) {
61857
+ setTimeout(() => {
61858
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
61859
+ silent: true
61860
+ });
61861
+ }, 100);
61852
61862
  }
61853
61863
  }, 0);
61854
61864
  });
@@ -61858,7 +61868,7 @@ var custom_column_component = normalizeComponent(
61858
61868
  },
61859
61869
  computed: {
61860
61870
  options() {
61861
- var _others$pagerConfig;
61871
+ var _others$pagerConfig, _others$sortConfig, _others$pagerConfig2, _others$pagerConfig3, _others$sortConfig2;
61862
61872
  const {
61863
61873
  customColumnConfig,
61864
61874
  columns,
@@ -61874,17 +61884,30 @@ var custom_column_component = normalizeComponent(
61874
61884
 
61875
61885
  // 处理前端分页
61876
61886
  let data = others.data || [];
61877
- if ((_others$pagerConfig = others.pagerConfig) !== null && _others$pagerConfig !== void 0 && _others$pagerConfig.frontendPagination) {
61887
+ if ((_others$pagerConfig = others.pagerConfig) !== null && _others$pagerConfig !== void 0 && _others$pagerConfig.frontendPagination || (_others$sortConfig = others.sortConfig) !== null && _others$sortConfig !== void 0 && _others$sortConfig.frontendSort) {
61878
61888
  // 保存完整数据
61879
61889
  this.allData = [...data];
61890
+ }
61891
+ if ((_others$pagerConfig2 = others.pagerConfig) !== null && _others$pagerConfig2 !== void 0 && _others$pagerConfig2.frontendPagination) {
61892
+ // 截取当前页数据
61880
61893
  data = this.spliteListData(this.allData, others.pagerConfig.currentPage, others.pagerConfig.pageSize);
61881
61894
  }
61882
61895
 
61883
61896
  // 移除 others 中的 data,避免覆盖
61884
61897
  const {
61885
61898
  data: _,
61886
- ...restOthers
61899
+ sortConfig,
61900
+ ...otherConfigs
61887
61901
  } = others;
61902
+ const userSeqConfig = this.gridOptions.seqConfig || {};
61903
+ const specialFirstRow = this.specialFirstRow(this.allData);
61904
+
61905
+ // 序号
61906
+ const defaultSeqMethod = ({
61907
+ rowIndex
61908
+ }) => {
61909
+ return specialFirstRow ? rowIndex : rowIndex + 1;
61910
+ };
61888
61911
  return {
61889
61912
  border: true,
61890
61913
  resizable: true,
@@ -61892,7 +61915,7 @@ var custom_column_component = normalizeComponent(
61892
61915
  height: 550,
61893
61916
  align: 'left',
61894
61917
  copyFields: [],
61895
- pagerConfig: others.pagerConfig,
61918
+ // pagerConfig: pagerConfig,
61896
61919
  emptyText: '暂无数据',
61897
61920
  loading: this.tableLoading,
61898
61921
  loadingConfig: {
@@ -61910,11 +61933,18 @@ var custom_column_component = normalizeComponent(
61910
61933
  ...this.gridOptions.rowConfig
61911
61934
  },
61912
61935
  sortConfig: {
61913
- remote: true,
61936
+ ...sortConfig,
61937
+ // 只在前端排序/分页时强制 remote: true
61938
+ // 其他情况保持外部配置
61939
+ remote: (_others$pagerConfig3 = others.pagerConfig) !== null && _others$pagerConfig3 !== void 0 && _others$pagerConfig3.frontendPagination || (_others$sortConfig2 = others.sortConfig) !== null && _others$sortConfig2 !== void 0 && _others$sortConfig2.frontendSort ? true : sortConfig === null || sortConfig === void 0 ? void 0 : sortConfig.remote,
61914
61940
  trigger: 'cell',
61915
61941
  ...this.gridOptions.sortConfig
61916
61942
  },
61917
- ...restOthers
61943
+ seqConfig: {
61944
+ ...userSeqConfig,
61945
+ seqMethod: userSeqConfig.seqMethod || defaultSeqMethod
61946
+ },
61947
+ ...otherConfigs
61918
61948
  };
61919
61949
  },
61920
61950
  // 插槽集合
@@ -61929,7 +61959,11 @@ var custom_column_component = normalizeComponent(
61929
61959
  eventListeners() {
61930
61960
  const listeners = {};
61931
61961
  this.events.forEach(eventName => {
61932
- listeners[eventName] = event => this.$emit(eventName, event);
61962
+ if (eventName === 'sort-change') {
61963
+ listeners[eventName] = event => this.handleSortChange(event);
61964
+ } else {
61965
+ listeners[eventName] = event => this.$emit(eventName, event);
61966
+ }
61933
61967
  });
61934
61968
  return listeners;
61935
61969
  }
@@ -61961,21 +61995,31 @@ var custom_column_component = normalizeComponent(
61961
61995
  this.$refs.xGrid.reloadColumn(this.originColumns);
61962
61996
  }
61963
61997
  },
61998
+ /**
61999
+ * 分页变化
62000
+ * @param values 分页参数
62001
+ */
61964
62002
  pageChange(values) {
61965
62003
  var _this$gridOptions$pag;
61966
62004
  // 前端分页
61967
62005
  if ((_this$gridOptions$pag = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag !== void 0 && _this$gridOptions$pag.frontendPagination) {
61968
- this.tableLoading = true;
61969
62006
  setTimeout(() => {
61970
62007
  const newData = this.spliteListData(this.allData, values.page, values.limit);
61971
62008
  this.$refs.xGrid.reloadData(newData);
62009
+ this.$nextTick(() => {
62010
+ // 分页后恢复排序高亮
62011
+ if (this.sortState.field && this.sortState.order && this.$refs.xGrid) {
62012
+ setTimeout(() => {
62013
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
62014
+ silent: true
62015
+ });
62016
+ }, 100);
62017
+ }
62018
+ });
61972
62019
  setTimeout(() => {
61973
62020
  if (this.$refs.xGrid) {
61974
62021
  this.$refs.xGrid.scrollTo(0, 0);
61975
62022
  }
61976
- setTimeout(() => {
61977
- this.tableLoading = false;
61978
- }, 0);
61979
62023
  }, 0);
61980
62024
  }, 0);
61981
62025
  } else {
@@ -61986,35 +62030,6 @@ var custom_column_component = normalizeComponent(
61986
62030
  this.$emit('page-change', values);
61987
62031
  }
61988
62032
  },
61989
- // 前端分页 - 截取当前页展示数据
61990
- spliteListData(allData, currentPage, pageSize) {
61991
- if (!Array.isArray(allData) || allData.length === 0) {
61992
- return [];
61993
- }
61994
-
61995
- // 检查第一条数据是否需要特殊处理
61996
- const firstRow = allData[0];
61997
- const specialFirstRow = firstRow && typeof firstRow === 'object' && isNullValue(firstRow.id) ? firstRow : null;
61998
-
61999
- // 获取实际需要分页的数据(排除特殊的第一条)
62000
- const normalData = specialFirstRow ? allData.slice(1) : allData;
62001
- const start = (currentPage - 1) * pageSize;
62002
- const end = start + pageSize;
62003
-
62004
- // 更新分页配置
62005
- this.gridOptions.pagerConfig.currentPage = currentPage;
62006
- this.gridOptions.pagerConfig.pageSize = pageSize;
62007
- this.gridOptions.pagerConfig.total = allData.length;
62008
-
62009
- // 获取当前页数据
62010
- let currentPageData = normalData.slice(start, end);
62011
-
62012
- // 如果有特殊的第一条数据,添加到当前页数据的开头
62013
- if (specialFirstRow) {
62014
- currentPageData = [specialFirstRow, ...currentPageData];
62015
- }
62016
- return currentPageData;
62017
- },
62018
62033
  copy(text) {
62019
62034
  const oInput = document.createElement('input');
62020
62035
  oInput.value = text;
@@ -62108,6 +62123,165 @@ var custom_column_component = normalizeComponent(
62108
62123
  // 关闭自定义表头弹框
62109
62124
  closeCustomColumnDialog() {
62110
62125
  this.customTableVisible = false;
62126
+ },
62127
+ /**
62128
+ * 获取特殊的第一条数据
62129
+ * @param allData 数据
62130
+ * @returns 特殊的第一条数据
62131
+ */
62132
+ specialFirstRow(allData) {
62133
+ const firstRow = allData && allData[0];
62134
+ return firstRow && typeof firstRow === 'object' && isNullValue(firstRow.id) ? firstRow : null;
62135
+ },
62136
+ /**
62137
+ * 获取当前页显示数据
62138
+ * 1、前端分页:获取当前页截取后并排序后的数据
62139
+ * 2、虚拟滚动+前端排序:获取排序后的全部数据
62140
+ * @param allData
62141
+ * @param currentPage
62142
+ * @param pageSize
62143
+ */
62144
+ spliteListData(allData, currentPage, pageSize) {
62145
+ if (!Array.isArray(allData) || allData.length === 0) {
62146
+ return [];
62147
+ }
62148
+
62149
+ // 检查第一条数据是否需要特殊处理 (如果未分页,则返回排序后的全部)
62150
+ const specialFirstRow = this.specialFirstRow(allData);
62151
+
62152
+ // 获取实际需要分页的数据(排除特殊的第一条)
62153
+ let normalData = specialFirstRow ? allData.slice(1) : allData;
62154
+
62155
+ // 如果有排序状态,先对数据进行排序
62156
+ if (this.sortState.field && this.sortState.order) {
62157
+ normalData = this.sortData(normalData, this.sortState.field, this.sortState.order);
62158
+ }
62159
+ let currentPageData = [];
62160
+ if (currentPage && pageSize) {
62161
+ const start = (currentPage - 1) * pageSize;
62162
+ const end = start + pageSize;
62163
+
62164
+ // 更新分页配置
62165
+ this.gridOptions.pagerConfig.currentPage = currentPage;
62166
+ this.gridOptions.pagerConfig.pageSize = pageSize;
62167
+ this.gridOptions.pagerConfig.total = allData.length;
62168
+
62169
+ // 获取当前页数据
62170
+ currentPageData = normalData.slice(start, end);
62171
+ } else {
62172
+ currentPageData = normalData;
62173
+ }
62174
+
62175
+ // 如果有特殊的第一条数据,添加到当前页数据的开头
62176
+ if (specialFirstRow) {
62177
+ currentPageData = [specialFirstRow, ...currentPageData];
62178
+ }
62179
+ return currentPageData;
62180
+ },
62181
+ /**
62182
+ * 排序数据
62183
+ * @param data 数据
62184
+ * @param field 字段
62185
+ * @param order 排序方式
62186
+ */
62187
+ sortData(data, field, order) {
62188
+ if (!field || !order) return data;
62189
+ return [...data].sort((a, b) => {
62190
+ let aValue = a[field];
62191
+ let bValue = b[field];
62192
+
62193
+ // 处理null和undefined值
62194
+ if (aValue === null || aValue === undefined) aValue = '';
62195
+ if (bValue === null || bValue === undefined) bValue = '';
62196
+
62197
+ // 数字类型排序
62198
+ if (typeof aValue === 'number' && typeof bValue === 'number') {
62199
+ return order === 'asc' ? aValue - bValue : bValue - aValue;
62200
+ }
62201
+
62202
+ // 字符串类型排序
62203
+ const aStr = String(aValue).toLowerCase();
62204
+ const bStr = String(bValue).toLowerCase();
62205
+ const isPercentA = typeof aValue === 'string' && aValue.trim().endsWith('%') && !isNaN(aValue.trim().slice(0, -1));
62206
+ const isPercentB = typeof bValue === 'string' && bValue.trim().endsWith('%') && !isNaN(bValue.trim().slice(0, -1));
62207
+ if (isPercentA && isPercentB) {
62208
+ // 百分比字符串,去掉%后转数字比较
62209
+ const numA = parseFloat(aValue);
62210
+ const numB = parseFloat(bValue);
62211
+ return order === 'asc' ? numA - numB : numB - numA;
62212
+ }
62213
+ const isANum = !isNaN(aStr) && aStr.trim() !== '';
62214
+ const isBNum = !isNaN(bStr) && bStr.trim() !== '';
62215
+ if (isANum && isBNum) {
62216
+ // 都是数字字符串,按数字比较
62217
+ return order === 'asc' ? Number(aStr) - Number(bStr) : Number(bStr) - Number(aStr);
62218
+ } else {
62219
+ // 普通字符串比较
62220
+ return order === 'asc' ? aStr.localeCompare(bStr) : bStr.localeCompare(aStr);
62221
+ }
62222
+ });
62223
+ },
62224
+ /**
62225
+ * 处理排序变化
62226
+ * @param event
62227
+ */
62228
+ handleSortChange(event) {
62229
+ var _this$gridOptions$pag2, _this$gridOptions$sor;
62230
+ const {
62231
+ property,
62232
+ order
62233
+ } = event;
62234
+ const shouldHandleSort = ((_this$gridOptions$pag2 = this.gridOptions.pagerConfig) === null || _this$gridOptions$pag2 === void 0 ? void 0 : _this$gridOptions$pag2.frontendPagination) || ((_this$gridOptions$sor = this.gridOptions.sortConfig) === null || _this$gridOptions$sor === void 0 ? void 0 : _this$gridOptions$sor.frontendSort);
62235
+ if (shouldHandleSort) {
62236
+ var _this$gridOptions$pag3, _this$gridOptions$pag4;
62237
+ this.sortState.field = property;
62238
+ this.sortState.order = order;
62239
+ const newData = this.spliteListData(this.allData, (_this$gridOptions$pag3 = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag3 !== void 0 && _this$gridOptions$pag3.frontendPagination ? this.gridOptions.pagerConfig.currentPage : null, (_this$gridOptions$pag4 = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag4 !== void 0 && _this$gridOptions$pag4.frontendPagination ? this.gridOptions.pagerConfig.pageSize : null);
62240
+ if (this.$refs.xGrid) {
62241
+ this.$refs.xGrid.reloadData(newData);
62242
+ this.$nextTick(() => {
62243
+ if (property && order) {
62244
+ setTimeout(() => {
62245
+ // 只高亮箭头,表格内部不排序(因为数据已经排序好)
62246
+ this.$refs.xGrid.sort(property, order, {
62247
+ silent: true
62248
+ });
62249
+ }, 100);
62250
+ }
62251
+ setTimeout(() => {
62252
+ var _this$gridOptions$pag5;
62253
+ if ((_this$gridOptions$pag5 = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag5 !== void 0 && _this$gridOptions$pag5.frontendPagination && this.$refs.xGrid) {
62254
+ // 前端分页时,排序状态变化,回到第一页
62255
+ const currentPage = this.gridOptions.pagerConfig.currentPage;
62256
+ if (currentPage !== 1) {
62257
+ // 触发分页事件回到第一页
62258
+ this.pageChange({
62259
+ page: 1,
62260
+ limit: this.gridOptions.pagerConfig.pageSize
62261
+ });
62262
+ } else {
62263
+ // 已经在第一页,直接滚动到顶部
62264
+ this.$refs.xGrid.scrollTo(0, 0);
62265
+ }
62266
+ }
62267
+ }, 0);
62268
+ });
62269
+ }
62270
+ }
62271
+ this.$emit('sort-change', event);
62272
+ },
62273
+ /**
62274
+ * 重置排序状态
62275
+ */
62276
+ resetSortState() {
62277
+ // 重置排序状态
62278
+ this.sortState.field = null;
62279
+ this.sortState.order = null;
62280
+ setTimeout(() => {
62281
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
62282
+ silent: true
62283
+ });
62284
+ }, 100);
62111
62285
  }
62112
62286
  }
62113
62287
  });
@@ -62123,8 +62297,8 @@ var custom_column_component = normalizeComponent(
62123
62297
  ;
62124
62298
  var table_component = normalizeComponent(
62125
62299
  components_tablevue_type_script_lang_js,
62126
- tablevue_type_template_id_849a6584_render,
62127
- tablevue_type_template_id_849a6584_staticRenderFns,
62300
+ tablevue_type_template_id_edc3cbea_render,
62301
+ tablevue_type_template_id_edc3cbea_staticRenderFns,
62128
62302
  false,
62129
62303
  null,
62130
62304
  null,