@weitutech/by-components 1.0.30 → 1.1.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.
@@ -22,7 +22,10 @@
22
22
  </template>
23
23
  </vxe-grid>
24
24
  <CustomColumn
25
- v-if="gridOptions.customColumnConfig && gridOptions.customColumnConfig.showCustomColumn"
25
+ v-if="
26
+ gridOptions.customColumnConfig &&
27
+ gridOptions.customColumnConfig.showCustomColumn
28
+ "
26
29
  ref="CustomColumnRef"
27
30
  :info-method="gridOptions.customColumnConfig.infoMethod"
28
31
  :submit-method="gridOptions.customColumnConfig.submitMethod"
@@ -35,7 +38,7 @@
35
38
  </template>
36
39
 
37
40
  <script>
38
- import CustomColumn from "../custom-column/index.vue"
41
+ import CustomColumn from '../custom-column/index.vue'
39
42
  export default {
40
43
  name: 'BYTable',
41
44
  components: {
@@ -47,8 +50,14 @@ export default {
47
50
  default: () => {}
48
51
  },
49
52
  name: {
53
+ //如果有传入name时,当表格宽度拖动时,会缓存当前表格每列的宽度,下次刷新将展示缓存宽度(⚠️注意:同一个项目中name一定不要重复)
50
54
  type: String,
51
- default: ""
55
+ default: ''
56
+ },
57
+ autoHeight: {
58
+ // 是否根据内容自动撑高
59
+ type: Boolean,
60
+ default: false
52
61
  }
53
62
  },
54
63
  data() {
@@ -57,16 +66,52 @@ export default {
57
66
  * @see https://vxetable.cn/v3.8/#/grid/api
58
67
  */
59
68
  events: [
60
- "keydown", "current-change", "radio-change", "checkbox-change", "checkbox-all",
61
- "checkbox-range-start", "checkbox-range-change", "checkbox-range-end",
62
- "cell-dblclick", "cell-menu", "cell-mouseenter", "cell-mouseleave", "cell-delete-value",
63
- "header-cell-click", "header-cell-dblclick", "header-cell-menu", "footer-cell-click",
64
- "footer-cell-dblclick", "footer-cell-menu", "clear-merge", "sort-change", "clear-sort",
65
- "filter-visible", "filter-change", "clear-filter", "toggle-row-expand",
66
- "toggle-tree-expand", "menu-click", "cell-selected", "edit-closed", "edit-activated", "edit-disabled",
67
- "valid-error", "scroll", "custom", "page-change", "form-submit", "form-submit-invalid", "form-reset",
68
- "form-collapse", "proxy-query", "proxy-delete", "proxy-save", "toolbar-button-click", "toolbar-tool-click",
69
- "zoom"
69
+ 'keydown',
70
+ 'current-change',
71
+ 'radio-change',
72
+ 'checkbox-change',
73
+ 'checkbox-all',
74
+ 'checkbox-range-start',
75
+ 'checkbox-range-change',
76
+ 'checkbox-range-end',
77
+ 'cell-dblclick',
78
+ 'cell-menu',
79
+ 'cell-mouseenter',
80
+ 'cell-mouseleave',
81
+ 'cell-delete-value',
82
+ 'header-cell-click',
83
+ 'header-cell-dblclick',
84
+ 'header-cell-menu',
85
+ 'footer-cell-click',
86
+ 'footer-cell-dblclick',
87
+ 'footer-cell-menu',
88
+ 'clear-merge',
89
+ 'sort-change',
90
+ 'clear-sort',
91
+ 'filter-visible',
92
+ 'filter-change',
93
+ 'clear-filter',
94
+ 'toggle-row-expand',
95
+ 'toggle-tree-expand',
96
+ 'menu-click',
97
+ 'cell-selected',
98
+ 'edit-closed',
99
+ 'edit-activated',
100
+ 'edit-disabled',
101
+ 'valid-error',
102
+ 'scroll',
103
+ 'custom',
104
+ 'page-change',
105
+ 'form-submit',
106
+ 'form-submit-invalid',
107
+ 'form-reset',
108
+ 'form-collapse',
109
+ 'proxy-query',
110
+ 'proxy-delete',
111
+ 'proxy-save',
112
+ 'toolbar-button-click',
113
+ 'toolbar-tool-click',
114
+ 'zoom'
70
115
  ],
71
116
  // 自定义对话框显示和隐藏控制
72
117
  customTableVisible: false
@@ -75,25 +120,32 @@ export default {
75
120
  computed: {
76
121
  options() {
77
122
  const { customColumnConfig, columns, ...others } = this.gridOptions
78
- const cols = JSON.parse(localStorage.getItem(this.name)) || undefined
79
- if (cols && this.name) {
80
- columns.forEach(item => {
81
- item.width = (cols.find(col => col.field === item.field) || {}).width || undefined
82
- })
83
- }
123
+
124
+ // 使用列宽缓存值(若有)
125
+ const newColumns = this.getColumnsData(columns)
126
+
84
127
  return {
85
128
  border: true,
86
129
  resizable: true,
87
- showOverflow: true,
130
+ /**
131
+ * 控制单元格内容的溢出显示方式
132
+ * 可选值:
133
+ * true:默认值,超出部分显示省略号(...)
134
+ * 'visible':内容完整显示,不会被截断
135
+ * 'ellipsis':显示省略号
136
+ * 'tooltip':超出部分显示省略号,鼠标悬停时显示完整内容
137
+ */
138
+ showOverflow: this.autoHeight ? 'visible' : true,
139
+ showHeaderOverflow: this.autoHeight ? 'tooltip' : true,
88
140
  height: 550,
89
- align: "left",
141
+ align: 'left',
90
142
  copyFields: [],
91
143
  pagerConfig: false,
92
- emptyText: "暂无数据",
144
+ emptyText: '暂无数据',
93
145
  loadingConfig: {
94
- text: "加载中..."
146
+ text: '加载中...'
95
147
  },
96
- columns,
148
+ columns: newColumns,
97
149
  ...others,
98
150
  resizableConfig: {
99
151
  minWidth: 50,
@@ -106,11 +158,12 @@ export default {
106
158
  },
107
159
  sortConfig: {
108
160
  remote: true,
109
- trigger: "cell",
161
+ trigger: 'cell',
110
162
  ...this.gridOptions.sortConfig
111
163
  }
112
164
  }
113
165
  },
166
+
114
167
  // 插槽集合
115
168
  slotMap() {
116
169
  const slotSet = new Set([])
@@ -127,39 +180,109 @@ export default {
127
180
  eventListeners() {
128
181
  const listeners = {}
129
182
  this.events.forEach(eventName => {
130
- listeners[eventName] = (event) => this.$emit(eventName, event)
183
+ listeners[eventName] = event => this.$emit(eventName, event)
131
184
  })
132
185
  return listeners
133
186
  }
134
187
  },
188
+
135
189
  methods: {
190
+ //获取缓存列宽,并替换列宽值
191
+ getColumnsData(columns) {
192
+ if (!this.name) {
193
+ return columns
194
+ }
195
+
196
+ const cacheColumns = JSON.parse(localStorage.getItem(this.name))
197
+ if (!cacheColumns) {
198
+ return columns
199
+ }
200
+
201
+ //比较columns和cols列宽缓存数据,如果有变动(表头有增加或删除),更新缓存
202
+ const cols = this.compareColumnsAndCols(columns, cacheColumns)
203
+
204
+ // 将缓存中的列宽,替换到columns中的列宽
205
+ if (cols && this.name) {
206
+ columns.forEach(item => {
207
+ item.width =
208
+ (cols.find(col => col.field === item.field) || {}).width ||
209
+ item.width ||
210
+ undefined
211
+ })
212
+ }
213
+
214
+ return columns
215
+ },
216
+
217
+ /**
218
+ * 更新列宽缓存
219
+ * 比较columns和cacheColumns列宽缓存数据,如果有变动(表头有增加或删除),更新缓存
220
+ * 如果columns的列在cacheColumns中不存在,则说明是新增的列,将对应的列加入到缓存中
221
+ * 如果cacheColumns的列在columns中不存在,则说明是删除的列,将对应的列从缓存中删除
222
+ * @param columns 当前表格列配置
223
+ * @param cacheColumns 缓存列配置
224
+ */
225
+ compareColumnsAndCols(columns, cacheColumns) {
226
+ if (!cacheColumns || !this.name) {
227
+ return undefined
228
+ }
229
+ // 如果columns的列在cacheColumns中不存在,则说明是新增的列,将对应的列加入到缓存中
230
+ columns.forEach(item => {
231
+ if (
232
+ item &&
233
+ item.field &&
234
+ !cacheColumns.some(col => col && col.field === item.field)
235
+ ) {
236
+ cacheColumns.push({
237
+ field: item.field,
238
+ width: item.width
239
+ })
240
+ }
241
+ })
242
+ // 如果cacheColumns的列在columns中不存在,则说明是删除的列,将对应的列从缓存中删除
243
+ const newCacheColumns = cacheColumns.filter(
244
+ item =>
245
+ item &&
246
+ item.field &&
247
+ columns.some(col => col && col.field === item.field)
248
+ )
249
+ // 更新缓存
250
+ localStorage.setItem(this.name, JSON.stringify(newCacheColumns))
251
+ return newCacheColumns
252
+ },
253
+
136
254
  handleCellClick(context) {
137
255
  if (this.options.copyFields.includes(context.column.field)) {
138
256
  const text = context.cell.outerText
139
257
  this.copy(text)
140
258
  }
141
- this.$emit("cell-click", context)
259
+ this.$emit('cell-click', context)
142
260
  },
143
261
  handleResizableChange(context) {
144
- this.$emit("resizable-change", context)
262
+ this.$emit('resizable-change', context)
145
263
  if (!this.name) return
146
264
  const collectColumn = context.$table.collectColumn
147
- console.log(collectColumn, "collectColumn")
148
- const clos = collectColumn.map(col => ({ field: col.field, width: col.renderWidth }))
265
+ console.log(collectColumn, 'collectColumn')
266
+ const clos = collectColumn
267
+ .filter(col => col.field)
268
+ .map(col => ({
269
+ field: col.field,
270
+ width: col.renderWidth
271
+ }))
149
272
  localStorage.setItem(this.name, JSON.stringify(clos))
150
273
  },
151
274
  pageChange(values) {
152
- this.$emit("page-change", values)
275
+ this.$emit('page-change', values)
153
276
  },
154
277
  copy(text) {
155
- const oInput = document.createElement("input")
278
+ const oInput = document.createElement('input')
156
279
  oInput.value = text
157
280
  document.body.appendChild(oInput)
158
281
  oInput.select() // 选择对象;
159
- document.execCommand("Copy") // 执行浏览器复制命令
282
+ document.execCommand('Copy') // 执行浏览器复制命令
160
283
  this.$message({
161
- message: "复制成功",
162
- type: "success"
284
+ message: '复制成功',
285
+ type: 'success'
163
286
  })
164
287
  oInput.remove()
165
288
  },
@@ -174,57 +297,67 @@ export default {
174
297
  const columns = []
175
298
  cols.forEach(item => {
176
299
  if (!columns.some(col => col.field === item.key) && item.type) {
177
- columns.push(
178
- {
179
- field: item.key,
180
- title: item.label,
181
- minWidth: item.minWidth || item.width,
182
- maxWidth: item.maxWidth,
183
- sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
184
- fixed: item.fixed,
185
- slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
186
- }
187
- )
300
+ columns.push({
301
+ field: item.key,
302
+ title: item.label,
303
+ minWidth: item.minWidth || item.width,
304
+ maxWidth: item.maxWidth,
305
+ sortable:
306
+ typeof item.sortable === 'undefined'
307
+ ? true
308
+ : JSON.parse(item.sortable),
309
+ fixed: item.fixed,
310
+ slots: this.gridOptions.customColumnConfig.slots.includes(item.key)
311
+ ? { default: item.key }
312
+ : undefined
313
+ })
188
314
  }
189
315
  })
190
- this.$emit("setColumn", columns)
316
+ this.$emit('setColumn', columns)
191
317
  },
192
318
  // 多层级表头
193
319
  changeTableGroupFields(cols) {
194
- const recursiveData = (cols)=> {
320
+ const recursiveData = cols => {
195
321
  const arr = []
196
- cols.forEach((item,index)=> {
197
- if(item.data && item.data.length > 0) {
322
+ cols.forEach((item, index) => {
323
+ if (item.data && item.data.length > 0) {
198
324
  arr.push({
199
325
  title: item.label,
200
326
  align: 'center',
201
327
  children: recursiveData(item.data)
202
328
  })
203
- if(index < cols.length - 1) {
329
+ if (index < cols.length - 1) {
204
330
  arr.push({
205
331
  title: '',
206
332
  width: 5,
207
333
  headerClassName: 'group-split',
208
- className: 'group-split',
334
+ className: 'group-split'
209
335
  })
210
336
  }
211
- }else {
337
+ } else {
212
338
  if (!arr.some(col => col.field === item.key) && item.type) {
213
339
  arr.push({
214
340
  field: item.key,
215
341
  title: item.label,
216
342
  minWidth: item.minWidth || item.width,
217
343
  maxWidth: item.maxWidth,
218
- sortable: typeof (item.sortable) === "undefined" ? true : JSON.parse(item.sortable),
344
+ sortable:
345
+ typeof item.sortable === 'undefined'
346
+ ? true
347
+ : JSON.parse(item.sortable),
219
348
  fixed: item.fixed,
220
- slots: this.gridOptions.customColumnConfig.slots.includes(item.key) ? { default: item.key } : undefined
349
+ slots: this.gridOptions.customColumnConfig.slots.includes(
350
+ item.key
351
+ )
352
+ ? { default: item.key }
353
+ : undefined
221
354
  })
222
355
  }
223
356
  }
224
357
  })
225
358
  return arr
226
359
  }
227
- this.$emit("setGroupColumn", recursiveData(cols))
360
+ this.$emit('setGroupColumn', recursiveData(cols))
228
361
  },
229
362
 
230
363
  // 关闭自定义表头弹框
@@ -235,6 +368,4 @@ export default {
235
368
  }
236
369
  </script>
237
370
 
238
- <style lang="scss" scoped>
239
-
240
- </style>
371
+ <style lang="scss" scoped></style>
package/src/index.js CHANGED
@@ -18,7 +18,7 @@ const components = {
18
18
  // 设置当前 z-index 起始值
19
19
  domZindex.setCurrent(99999)
20
20
 
21
- const install = (Vue) => {
21
+ const install = Vue => {
22
22
  Object.keys(components).forEach(name => {
23
23
  Vue.component(name, components[name])
24
24
  })
@@ -28,4 +28,4 @@ const install = (Vue) => {
28
28
  if (typeof window !== 'undefined' && window.Vue) {
29
29
  install(window.Vue)
30
30
  }
31
- export default {install }
31
+ export default { install }
@@ -1,4 +1,4 @@
1
- import Vue from "vue"
1
+ import Vue from 'vue'
2
2
  // import XEUtils from "xe-utils"
3
3
  import {
4
4
  // 全局实例对象
@@ -41,7 +41,7 @@ import {
41
41
  // VxeModal,
42
42
  // VxeList,
43
43
  // VxePulldown
44
- } from "vxe-table"
44
+ } from 'vxe-table'
45
45
 
46
46
  // 旧版本使用 setup({}) 或者 config({})
47
47
  // VXETable.config({
@@ -297,4 +297,4 @@ Vue.use(VxeSelect)
297
297
  // Vue.use(VxeModal)
298
298
  // Vue.use(VxeList)
299
299
  // Vue.use(VxePulldown)
300
- import "./vxeTable.scss"
300
+ import './vxeTable.scss'
@@ -49,10 +49,10 @@
49
49
  cursor: move;
50
50
  }
51
51
 
52
- .fixedClass{
53
- width:100%;
52
+ .fixedClass {
53
+ width: 100%;
54
54
  height: 2px;
55
- border-bottom:2px dashed #ccc;
55
+ border-bottom: 2px dashed #ccc;
56
56
  padding-top: 10px;
57
57
  }
58
58
 
@@ -100,10 +100,10 @@
100
100
  }
101
101
  }
102
102
 
103
- .draggable_title{
103
+ .draggable_title {
104
104
  font-size: 12px;
105
105
  font-weight: 700;
106
- margin:20px 0 ;
106
+ margin: 20px 0;
107
107
  }
108
108
 
109
109
  .left_box_body {
@@ -134,9 +134,8 @@
134
134
  overflow-y: auto;
135
135
  .checkbox_title {
136
136
  margin: 20px 0;
137
-
138
137
  }
139
- div:nth-child(1) .checkbox_title {
138
+ div:nth-child(1) .checkbox_title {
140
139
  margin-top: 8px;
141
140
  }
142
141
  }
@@ -191,4 +190,3 @@
191
190
  .cell-1 {
192
191
  flex: 1;
193
192
  }
194
-
@@ -1,6 +1,13 @@
1
- @import './pager.scss';
2
- @import './page-search.scss';
3
- @import './fold-search.scss';
4
- @import './table.scss';
5
- @import './form.scss';
6
- @import './custom-column.scss'
1
+ // @import './pager.scss';
2
+ // @import './page-search.scss';
3
+ // @import './fold-search.scss';
4
+ // @import './table.scss';
5
+ // @import './form.scss';
6
+ // @import './custom-column.scss';
7
+
8
+ @use './pager.scss';
9
+ @use './page-search.scss';
10
+ @use './fold-search.scss';
11
+ @use './table.scss';
12
+ @use './form.scss';
13
+ @use './custom-column.scss';
@@ -1,8 +1,8 @@
1
- export const deepClone = (target) => {
1
+ export const deepClone = target => {
2
2
  // 定义一个变量
3
3
  let result
4
4
  // 如果当前需要深拷贝的是一个对象的话
5
- if (typeof target === "object") {
5
+ if (typeof target === 'object') {
6
6
  // 如果是一个数组的话
7
7
  if (Array.isArray(target)) {
8
8
  result = [] // 将result赋值为一个数组,并且执行遍历
@@ -29,4 +29,4 @@ export const deepClone = (target) => {
29
29
  }
30
30
  // 返回最终结果
31
31
  return result
32
- }
32
+ }
package/.browserslistrc DELETED
@@ -1,3 +0,0 @@
1
- > 1%
2
- last 2 versions
3
- not dead
package/babel.config.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- '@vue/cli-plugin-babel/preset'
4
- ],
5
- plugins: [
6
- "@babel/plugin-proposal-optional-chaining",
7
- "@babel/plugin-proposal-nullish-coalescing-operator"
8
- ]
9
- }
package/jsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "esnext",
5
- "baseUrl": "./",
6
- "moduleResolution": "node",
7
- "paths": {
8
- "@/*": [
9
- "src/*"
10
- ]
11
- },
12
- "lib": [
13
- "esnext",
14
- "dom",
15
- "dom.iterable",
16
- "scripthost"
17
- ]
18
- }
19
- }
package/postcss.config.js DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- plugins: {
3
- // 可以根据您的需求添加具体的 PostCSS 插件
4
- // 例如 autoprefixer 用于添加浏览器前缀
5
- 'autoprefixer': {}
6
- }
7
- }
package/vue.config.js DELETED
@@ -1,7 +0,0 @@
1
- const { defineConfig } = require('@vue/cli-service')
2
-
3
- module.exports = defineConfig({
4
- transpileDependencies: true,
5
- outputDir: 'lib',
6
- productionSourceMap: false
7
- })