@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.
@@ -60742,8 +60742,8 @@ var component = normalizeComponent(
60742
60742
  )
60743
60743
 
60744
60744
  /* harmony default export */ var pager = (component.exports);
60745
- ;// ./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-40.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
60746
- var tablevue_type_template_id_849a6584_render = function render() {
60745
+ ;// ./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-40.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
60746
+ var tablevue_type_template_id_edc3cbea_render = function render() {
60747
60747
  var _vm = this,
60748
60748
  _c = _vm._self._c;
60749
60749
  return _c('div', [_c('vxe-grid', _vm._g(_vm._b({
@@ -60817,7 +60817,7 @@ var tablevue_type_template_id_849a6584_render = function render() {
60817
60817
  }
60818
60818
  }) : _vm._e()], 1);
60819
60819
  };
60820
- var tablevue_type_template_id_849a6584_staticRenderFns = [];
60820
+ var tablevue_type_template_id_edc3cbea_staticRenderFns = [];
60821
60821
 
60822
60822
  // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.push.js
60823
60823
  var es_array_push = __webpack_require__(4114);
@@ -61769,6 +61769,7 @@ var custom_column_component = normalizeComponent(
61769
61769
  * @property {Object} sortConfig - 排序配置
61770
61770
  * @property {boolean} sortConfig.remote - 是否远程排序
61771
61771
  * @property {string} sortConfig.trigger - 排序触发方式
61772
+ * @property {boolean} sortConfig.frontendSort - 是否启用前端排序
61772
61773
  * @property {Array} copyFields - 可复制字段列表
61773
61774
  * @property {string} emptyText - 空数据提示文本
61774
61775
  * @property {Object} loadingConfig - 加载配置
@@ -61806,6 +61807,11 @@ var custom_column_component = normalizeComponent(
61806
61807
  tempColumns: [],
61807
61808
  // 存储所有数据(用于前端分页)
61808
61809
  allData: [],
61810
+ // 排序状态
61811
+ sortState: {
61812
+ field: null,
61813
+ order: null
61814
+ },
61809
61815
  tableLoading: false
61810
61816
  };
61811
61817
  },
@@ -61835,10 +61841,14 @@ var custom_column_component = normalizeComponent(
61835
61841
  top: 0,
61836
61842
  left: 0
61837
61843
  });
61838
- const tableData = this.$refs.xGrid.getTableData().fullData;
61839
- if (tableData && tableData.length > 0) {
61840
- this.$refs.xGrid.scrollToRow(tableData[0]);
61841
- }
61844
+ }
61845
+ // 数据变化后恢复排序高亮
61846
+ if (this.sortState.field && this.sortState.order && this.$refs.xGrid) {
61847
+ setTimeout(() => {
61848
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
61849
+ silent: true
61850
+ });
61851
+ }, 100);
61842
61852
  }
61843
61853
  }, 0);
61844
61854
  });
@@ -61848,7 +61858,7 @@ var custom_column_component = normalizeComponent(
61848
61858
  },
61849
61859
  computed: {
61850
61860
  options() {
61851
- var _others$pagerConfig;
61861
+ var _others$pagerConfig, _others$sortConfig, _others$pagerConfig2, _others$pagerConfig3, _others$sortConfig2;
61852
61862
  const {
61853
61863
  customColumnConfig,
61854
61864
  columns,
@@ -61864,17 +61874,30 @@ var custom_column_component = normalizeComponent(
61864
61874
 
61865
61875
  // 处理前端分页
61866
61876
  let data = others.data || [];
61867
- if ((_others$pagerConfig = others.pagerConfig) !== null && _others$pagerConfig !== void 0 && _others$pagerConfig.frontendPagination) {
61877
+ 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) {
61868
61878
  // 保存完整数据
61869
61879
  this.allData = [...data];
61880
+ }
61881
+ if ((_others$pagerConfig2 = others.pagerConfig) !== null && _others$pagerConfig2 !== void 0 && _others$pagerConfig2.frontendPagination) {
61882
+ // 截取当前页数据
61870
61883
  data = this.spliteListData(this.allData, others.pagerConfig.currentPage, others.pagerConfig.pageSize);
61871
61884
  }
61872
61885
 
61873
61886
  // 移除 others 中的 data,避免覆盖
61874
61887
  const {
61875
61888
  data: _,
61876
- ...restOthers
61889
+ sortConfig,
61890
+ ...otherConfigs
61877
61891
  } = others;
61892
+ const userSeqConfig = this.gridOptions.seqConfig || {};
61893
+ const specialFirstRow = this.specialFirstRow(this.allData);
61894
+
61895
+ // 序号
61896
+ const defaultSeqMethod = ({
61897
+ rowIndex
61898
+ }) => {
61899
+ return specialFirstRow ? rowIndex : rowIndex + 1;
61900
+ };
61878
61901
  return {
61879
61902
  border: true,
61880
61903
  resizable: true,
@@ -61882,7 +61905,7 @@ var custom_column_component = normalizeComponent(
61882
61905
  height: 550,
61883
61906
  align: 'left',
61884
61907
  copyFields: [],
61885
- pagerConfig: others.pagerConfig,
61908
+ // pagerConfig: pagerConfig,
61886
61909
  emptyText: '暂无数据',
61887
61910
  loading: this.tableLoading,
61888
61911
  loadingConfig: {
@@ -61900,11 +61923,18 @@ var custom_column_component = normalizeComponent(
61900
61923
  ...this.gridOptions.rowConfig
61901
61924
  },
61902
61925
  sortConfig: {
61903
- remote: true,
61926
+ ...sortConfig,
61927
+ // 只在前端排序/分页时强制 remote: true
61928
+ // 其他情况保持外部配置
61929
+ 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,
61904
61930
  trigger: 'cell',
61905
61931
  ...this.gridOptions.sortConfig
61906
61932
  },
61907
- ...restOthers
61933
+ seqConfig: {
61934
+ ...userSeqConfig,
61935
+ seqMethod: userSeqConfig.seqMethod || defaultSeqMethod
61936
+ },
61937
+ ...otherConfigs
61908
61938
  };
61909
61939
  },
61910
61940
  // 插槽集合
@@ -61919,7 +61949,11 @@ var custom_column_component = normalizeComponent(
61919
61949
  eventListeners() {
61920
61950
  const listeners = {};
61921
61951
  this.events.forEach(eventName => {
61922
- listeners[eventName] = event => this.$emit(eventName, event);
61952
+ if (eventName === 'sort-change') {
61953
+ listeners[eventName] = event => this.handleSortChange(event);
61954
+ } else {
61955
+ listeners[eventName] = event => this.$emit(eventName, event);
61956
+ }
61923
61957
  });
61924
61958
  return listeners;
61925
61959
  }
@@ -61951,21 +61985,31 @@ var custom_column_component = normalizeComponent(
61951
61985
  this.$refs.xGrid.reloadColumn(this.originColumns);
61952
61986
  }
61953
61987
  },
61988
+ /**
61989
+ * 分页变化
61990
+ * @param values 分页参数
61991
+ */
61954
61992
  pageChange(values) {
61955
61993
  var _this$gridOptions$pag;
61956
61994
  // 前端分页
61957
61995
  if ((_this$gridOptions$pag = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag !== void 0 && _this$gridOptions$pag.frontendPagination) {
61958
- this.tableLoading = true;
61959
61996
  setTimeout(() => {
61960
61997
  const newData = this.spliteListData(this.allData, values.page, values.limit);
61961
61998
  this.$refs.xGrid.reloadData(newData);
61999
+ this.$nextTick(() => {
62000
+ // 分页后恢复排序高亮
62001
+ if (this.sortState.field && this.sortState.order && this.$refs.xGrid) {
62002
+ setTimeout(() => {
62003
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
62004
+ silent: true
62005
+ });
62006
+ }, 100);
62007
+ }
62008
+ });
61962
62009
  setTimeout(() => {
61963
62010
  if (this.$refs.xGrid) {
61964
62011
  this.$refs.xGrid.scrollTo(0, 0);
61965
62012
  }
61966
- setTimeout(() => {
61967
- this.tableLoading = false;
61968
- }, 0);
61969
62013
  }, 0);
61970
62014
  }, 0);
61971
62015
  } else {
@@ -61976,35 +62020,6 @@ var custom_column_component = normalizeComponent(
61976
62020
  this.$emit('page-change', values);
61977
62021
  }
61978
62022
  },
61979
- // 前端分页 - 截取当前页展示数据
61980
- spliteListData(allData, currentPage, pageSize) {
61981
- if (!Array.isArray(allData) || allData.length === 0) {
61982
- return [];
61983
- }
61984
-
61985
- // 检查第一条数据是否需要特殊处理
61986
- const firstRow = allData[0];
61987
- const specialFirstRow = firstRow && typeof firstRow === 'object' && isNullValue(firstRow.id) ? firstRow : null;
61988
-
61989
- // 获取实际需要分页的数据(排除特殊的第一条)
61990
- const normalData = specialFirstRow ? allData.slice(1) : allData;
61991
- const start = (currentPage - 1) * pageSize;
61992
- const end = start + pageSize;
61993
-
61994
- // 更新分页配置
61995
- this.gridOptions.pagerConfig.currentPage = currentPage;
61996
- this.gridOptions.pagerConfig.pageSize = pageSize;
61997
- this.gridOptions.pagerConfig.total = allData.length;
61998
-
61999
- // 获取当前页数据
62000
- let currentPageData = normalData.slice(start, end);
62001
-
62002
- // 如果有特殊的第一条数据,添加到当前页数据的开头
62003
- if (specialFirstRow) {
62004
- currentPageData = [specialFirstRow, ...currentPageData];
62005
- }
62006
- return currentPageData;
62007
- },
62008
62023
  copy(text) {
62009
62024
  const oInput = document.createElement('input');
62010
62025
  oInput.value = text;
@@ -62098,6 +62113,165 @@ var custom_column_component = normalizeComponent(
62098
62113
  // 关闭自定义表头弹框
62099
62114
  closeCustomColumnDialog() {
62100
62115
  this.customTableVisible = false;
62116
+ },
62117
+ /**
62118
+ * 获取特殊的第一条数据
62119
+ * @param allData 数据
62120
+ * @returns 特殊的第一条数据
62121
+ */
62122
+ specialFirstRow(allData) {
62123
+ const firstRow = allData && allData[0];
62124
+ return firstRow && typeof firstRow === 'object' && isNullValue(firstRow.id) ? firstRow : null;
62125
+ },
62126
+ /**
62127
+ * 获取当前页显示数据
62128
+ * 1、前端分页:获取当前页截取后并排序后的数据
62129
+ * 2、虚拟滚动+前端排序:获取排序后的全部数据
62130
+ * @param allData
62131
+ * @param currentPage
62132
+ * @param pageSize
62133
+ */
62134
+ spliteListData(allData, currentPage, pageSize) {
62135
+ if (!Array.isArray(allData) || allData.length === 0) {
62136
+ return [];
62137
+ }
62138
+
62139
+ // 检查第一条数据是否需要特殊处理 (如果未分页,则返回排序后的全部)
62140
+ const specialFirstRow = this.specialFirstRow(allData);
62141
+
62142
+ // 获取实际需要分页的数据(排除特殊的第一条)
62143
+ let normalData = specialFirstRow ? allData.slice(1) : allData;
62144
+
62145
+ // 如果有排序状态,先对数据进行排序
62146
+ if (this.sortState.field && this.sortState.order) {
62147
+ normalData = this.sortData(normalData, this.sortState.field, this.sortState.order);
62148
+ }
62149
+ let currentPageData = [];
62150
+ if (currentPage && pageSize) {
62151
+ const start = (currentPage - 1) * pageSize;
62152
+ const end = start + pageSize;
62153
+
62154
+ // 更新分页配置
62155
+ this.gridOptions.pagerConfig.currentPage = currentPage;
62156
+ this.gridOptions.pagerConfig.pageSize = pageSize;
62157
+ this.gridOptions.pagerConfig.total = allData.length;
62158
+
62159
+ // 获取当前页数据
62160
+ currentPageData = normalData.slice(start, end);
62161
+ } else {
62162
+ currentPageData = normalData;
62163
+ }
62164
+
62165
+ // 如果有特殊的第一条数据,添加到当前页数据的开头
62166
+ if (specialFirstRow) {
62167
+ currentPageData = [specialFirstRow, ...currentPageData];
62168
+ }
62169
+ return currentPageData;
62170
+ },
62171
+ /**
62172
+ * 排序数据
62173
+ * @param data 数据
62174
+ * @param field 字段
62175
+ * @param order 排序方式
62176
+ */
62177
+ sortData(data, field, order) {
62178
+ if (!field || !order) return data;
62179
+ return [...data].sort((a, b) => {
62180
+ let aValue = a[field];
62181
+ let bValue = b[field];
62182
+
62183
+ // 处理null和undefined值
62184
+ if (aValue === null || aValue === undefined) aValue = '';
62185
+ if (bValue === null || bValue === undefined) bValue = '';
62186
+
62187
+ // 数字类型排序
62188
+ if (typeof aValue === 'number' && typeof bValue === 'number') {
62189
+ return order === 'asc' ? aValue - bValue : bValue - aValue;
62190
+ }
62191
+
62192
+ // 字符串类型排序
62193
+ const aStr = String(aValue).toLowerCase();
62194
+ const bStr = String(bValue).toLowerCase();
62195
+ const isPercentA = typeof aValue === 'string' && aValue.trim().endsWith('%') && !isNaN(aValue.trim().slice(0, -1));
62196
+ const isPercentB = typeof bValue === 'string' && bValue.trim().endsWith('%') && !isNaN(bValue.trim().slice(0, -1));
62197
+ if (isPercentA && isPercentB) {
62198
+ // 百分比字符串,去掉%后转数字比较
62199
+ const numA = parseFloat(aValue);
62200
+ const numB = parseFloat(bValue);
62201
+ return order === 'asc' ? numA - numB : numB - numA;
62202
+ }
62203
+ const isANum = !isNaN(aStr) && aStr.trim() !== '';
62204
+ const isBNum = !isNaN(bStr) && bStr.trim() !== '';
62205
+ if (isANum && isBNum) {
62206
+ // 都是数字字符串,按数字比较
62207
+ return order === 'asc' ? Number(aStr) - Number(bStr) : Number(bStr) - Number(aStr);
62208
+ } else {
62209
+ // 普通字符串比较
62210
+ return order === 'asc' ? aStr.localeCompare(bStr) : bStr.localeCompare(aStr);
62211
+ }
62212
+ });
62213
+ },
62214
+ /**
62215
+ * 处理排序变化
62216
+ * @param event
62217
+ */
62218
+ handleSortChange(event) {
62219
+ var _this$gridOptions$pag2, _this$gridOptions$sor;
62220
+ const {
62221
+ property,
62222
+ order
62223
+ } = event;
62224
+ 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);
62225
+ if (shouldHandleSort) {
62226
+ var _this$gridOptions$pag3, _this$gridOptions$pag4;
62227
+ this.sortState.field = property;
62228
+ this.sortState.order = order;
62229
+ 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);
62230
+ if (this.$refs.xGrid) {
62231
+ this.$refs.xGrid.reloadData(newData);
62232
+ this.$nextTick(() => {
62233
+ if (property && order) {
62234
+ setTimeout(() => {
62235
+ // 只高亮箭头,表格内部不排序(因为数据已经排序好)
62236
+ this.$refs.xGrid.sort(property, order, {
62237
+ silent: true
62238
+ });
62239
+ }, 100);
62240
+ }
62241
+ setTimeout(() => {
62242
+ var _this$gridOptions$pag5;
62243
+ if ((_this$gridOptions$pag5 = this.gridOptions.pagerConfig) !== null && _this$gridOptions$pag5 !== void 0 && _this$gridOptions$pag5.frontendPagination && this.$refs.xGrid) {
62244
+ // 前端分页时,排序状态变化,回到第一页
62245
+ const currentPage = this.gridOptions.pagerConfig.currentPage;
62246
+ if (currentPage !== 1) {
62247
+ // 触发分页事件回到第一页
62248
+ this.pageChange({
62249
+ page: 1,
62250
+ limit: this.gridOptions.pagerConfig.pageSize
62251
+ });
62252
+ } else {
62253
+ // 已经在第一页,直接滚动到顶部
62254
+ this.$refs.xGrid.scrollTo(0, 0);
62255
+ }
62256
+ }
62257
+ }, 0);
62258
+ });
62259
+ }
62260
+ }
62261
+ this.$emit('sort-change', event);
62262
+ },
62263
+ /**
62264
+ * 重置排序状态
62265
+ */
62266
+ resetSortState() {
62267
+ // 重置排序状态
62268
+ this.sortState.field = null;
62269
+ this.sortState.order = null;
62270
+ setTimeout(() => {
62271
+ this.$refs.xGrid.sort(this.sortState.field, this.sortState.order, {
62272
+ silent: true
62273
+ });
62274
+ }, 100);
62101
62275
  }
62102
62276
  }
62103
62277
  });
@@ -62113,8 +62287,8 @@ var custom_column_component = normalizeComponent(
62113
62287
  ;
62114
62288
  var table_component = normalizeComponent(
62115
62289
  components_tablevue_type_script_lang_js,
62116
- tablevue_type_template_id_849a6584_render,
62117
- tablevue_type_template_id_849a6584_staticRenderFns,
62290
+ tablevue_type_template_id_edc3cbea_render,
62291
+ tablevue_type_template_id_edc3cbea_staticRenderFns,
62118
62292
  false,
62119
62293
  null,
62120
62294
  null,