stk-table-vue 0.2.9 → 0.3.0

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.
@@ -1,4 +1,4 @@
1
- import { DEFAULT_COL_WIDTH } from './const';
1
+ import { DEFAULT_COL_WIDTH, STK_ID_PREFIX } from './const';
2
2
  import { Order, SortConfig, SortOption, SortState, StkTableColumn } from './types';
3
3
 
4
4
  /** 是否空值 */
@@ -182,20 +182,38 @@ export function howDeepTheHeader(arr: StkTableColumn<any>[], level = 1) {
182
182
  return Math.max(...levels);
183
183
  }
184
184
 
185
- /** 获取列宽 */
185
+ /**
186
+ * 获取列宽
187
+ *
188
+ * 关于列宽的操作往往在横向滚动中使用。既然已经有横向滚动了,则列宽会被压缩至minWidth,所以优先取minWidth
189
+ */
186
190
  export function getColWidth(col: StkTableColumn<any> | null): number {
187
- const val = col?.width ?? DEFAULT_COL_WIDTH;
191
+ const val = col?.minWidth ?? col?.width ?? DEFAULT_COL_WIDTH;
188
192
  if (typeof val === 'number') {
189
193
  return Math.floor(val);
190
194
  }
191
195
  return parseInt(val);
192
196
  }
193
197
 
194
- /** 获取列宽配置。用于支持列宽配置数字 */
195
- export function getColWidthStr(col: StkTableColumn<any> | null | undefined, key: 'width' | 'minWidth' | 'maxWidth' = 'width') {
196
- const val = col?.[key];
197
- if (typeof val === 'number') {
198
- return val + 'px';
198
+ /** 获取计算后的宽度 */
199
+ export function getCalculatedColWidth(col: StkTableColumn<any> | null) {
200
+ return col?.__WIDTH__ ?? +DEFAULT_COL_WIDTH;
201
+ }
202
+
203
+ /** number列宽+px */
204
+ export function transformWidthToStr(width?: string | number) {
205
+ if (typeof width === 'number') {
206
+ return width + 'px';
199
207
  }
200
- return val;
208
+ return width;
209
+ }
210
+
211
+ /** 创建组件唯一标识 */
212
+ export function createStkTableId() {
213
+ if (!window.__STK_TB_ID_COUNT__) {
214
+ window.__STK_TB_ID_COUNT__ = 0;
215
+ }
216
+ window.__STK_TB_ID_COUNT__ += 1;
217
+
218
+ return STK_ID_PREFIX + window.__STK_TB_ID_COUNT__.toString(36);
201
219
  }
package/src/vite-env.d.ts CHANGED
@@ -4,3 +4,7 @@ declare module '*.vue' {
4
4
  const component: DefineComponent<object, object, any>;
5
5
  export default component;
6
6
  }
7
+
8
+ interface Window {
9
+ __STK_TB_ID_COUNT__: number;
10
+ }