el-plus-crud 0.0.85 → 0.0.87

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.
@@ -161,7 +161,7 @@ const props = withDefaults(
161
161
  )
162
162
 
163
163
  // 合并行算法
164
- const needSpanColIndex = ref([] as any[])
164
+ const needSpanCellIndex = ref([] as any[])
165
165
  const handelSpanMethod = ref(null as unknown as Function)
166
166
 
167
167
  const elPlusTableRef = ref()
@@ -223,43 +223,83 @@ const headerColumns = computed(() => {
223
223
  // 获取所有列
224
224
  const allColumn = getColumList(tempList)
225
225
  // 查询是否有合并行属性
226
- needSpanColIndex.value = []
227
- allColumn.map((item, i) => {
228
- if (item.isRowSpan) {
229
- needSpanColIndex.value.push(i)
226
+ needSpanCellIndex.value = []
227
+
228
+ const tempColList = allColumn
229
+ .map((item, i) => {
230
+ // 合并行
231
+ if (item.isRowSpan) {
232
+ needSpanCellIndex.value.push(i)
233
+ let value = undefined as any
234
+ let first = 0
235
+ let count = 1
236
+ // 这里修改data数据
237
+ tableData.value?.map((row, j) => {
238
+ if (value !== row[item.prop]) {
239
+ if (count > 1 && j > 0) {
240
+ // 这里要设置之前的数据合并行数
241
+ tableData.value[first]['rowSpan_' + i] = count
242
+ }
243
+ first = j
244
+ count = 1
245
+ value = row[item.prop]
246
+ } else {
247
+ count += 1
248
+ row['rowSpan_' + i] = 0
249
+ }
250
+ if (j === tableData.value.length - 1) {
251
+ // 这里要设置之前的数据合并行数
252
+ tableData.value[first]['rowSpan_' + i] = count
253
+ }
254
+ })
255
+ }
256
+ // 返回需要合并列的列数据
257
+ return item.isColSpan ? i : null
258
+ })
259
+ .filter((item) => item !== null) as number[]
260
+
261
+ if (tempColList.length) {
262
+ // 这里开始合并列-遍历行数据
263
+ tableData.value?.map((row, j) => {
230
264
  let value = undefined as any
231
265
  let first = 0
232
266
  let count = 1
233
- // 这里修改data数据
234
- tableData.value?.map((row, j) => {
235
- if (value !== row[item.prop]) {
236
- if (count > 1 && j > 0) {
267
+ // 遍历表头
268
+ tempColList.map((val: number, i: number) => {
269
+ // 不存在时才添加
270
+ if (!needSpanCellIndex.value.includes(val)) {
271
+ needSpanCellIndex.value.push(val)
272
+ }
273
+ // 如果值不等 或者 列序号已经中断
274
+ if (value !== row[allColumn[val].prop] || (i > 0 && val - 1 !== tempColList[i - 1])) {
275
+ if (count > 1) {
237
276
  // 这里要设置之前的数据合并行数
238
- tableData.value[first]['rowSpan_' + i] = count
277
+ row['colSpan_' + first] = count
239
278
  }
240
- first = j
279
+ first = val
241
280
  count = 1
242
- value = row[item.prop]
281
+ value = row[allColumn[val].prop]
243
282
  } else {
244
283
  count += 1
245
- row['rowSpan_' + i] = 0
284
+ row['colSpan_' + val] = 0
246
285
  }
247
- if (j === tableData.value.length - 1) {
286
+ // 如果是最后一个
287
+ if (i === tempColList.length - 1) {
248
288
  // 这里要设置之前的数据合并行数
249
- tableData.value[first]['rowSpan_' + i] = count
289
+ row['colSpan_' + first] = count
250
290
  }
251
291
  })
252
- }
253
- })
254
- if (needSpanColIndex.value.length > 0) {
292
+ })
293
+ }
294
+ if (needSpanCellIndex.value.length > 0) {
255
295
  handelSpanMethod.value = ({ row, column, columnIndex }: SpanMethodProps) => {
256
296
  let tempColumnIndex = columnIndex
257
297
  // 这里要排除默认的列
258
298
  if (props.type === 'selection') tempColumnIndex -= 1
259
299
  if (props.isIndex) tempColumnIndex -= 1
260
300
  if (useSlots().firstColumn) tempColumnIndex -= 1
261
- if (needSpanColIndex.value.includes(tempColumnIndex)) {
262
- return { rowspan: row['rowSpan_' + tempColumnIndex], colspan: 1 }
301
+ if (needSpanCellIndex.value.includes(tempColumnIndex)) {
302
+ return { rowspan: row['rowSpan_' + tempColumnIndex] ?? 1, colspan: row['colSpan_' + tempColumnIndex] ?? 1 }
263
303
  }
264
304
  }
265
305
  }
@@ -315,31 +355,6 @@ function getColumList(list: Array<any>): Array<any> {
315
355
  return tempList
316
356
  }
317
357
 
318
- /**
319
- * 获取合并行方法
320
- * @param param0
321
- */
322
- function getSpanMethod(): Function {
323
- // const
324
- return ({ row, column, rowIndex, columnIndex }: SpanMethodProps) => {
325
- if (needSpanColIndex.value.includes(columnIndex)) {
326
- }
327
- if (columnIndex === 0) {
328
- if (rowIndex % 2 === 0) {
329
- return {
330
- rowspan: 2,
331
- colspan: 1
332
- }
333
- } else {
334
- return {
335
- rowspan: 0,
336
- colspan: 0
337
- }
338
- }
339
- }
340
- }
341
- }
342
-
343
358
  /**
344
359
  * Tab切换
345
360
  * @param val
@@ -159,7 +159,12 @@ async function handelDownload({ callBack }: IBtnBack) {
159
159
  }, 1000)
160
160
  }
161
161
  }
162
- xhr.onerror = function () {
162
+ xhr.onerror = function (e: any) {
163
+ // 如果错误,则尝试直接打开链接
164
+ const aLink = document.createElement('a')
165
+ aLink.href = url
166
+ aLink.download = (props.toolbar?.export?.name || new Date().getTime()) + (props.toolbar?.export?.suffix || '.xlsx')
167
+ aLink.click()
163
168
  setTimeout(() => {
164
169
  callBack && callBack()
165
170
  }, 1000)
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "el-plus-crud",
3
- "version": "0.0.85",
3
+ "version": "0.0.87",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "el-plus-crud",
9
- "version": "0.0.85",
9
+ "version": "0.0.87",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@element-plus/icons-vue": "^2.1.0",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "el-plus-crud",
3
3
  "description": "采用Vue3 + TS,封装的element-plus数据驱动表单、列表组件",
4
4
  "author": "K.D.Jack",
5
- "version": "0.0.85",
5
+ "version": "0.0.87",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",
package/types/index.d.ts CHANGED
@@ -215,6 +215,8 @@ export interface IColumnItem extends IDescItem {
215
215
  __vif?: boolean
216
216
  // 是否合并行
217
217
  isRowSpan?: boolean
218
+ // 是否合并列
219
+ isColSpan?: boolean
218
220
  }
219
221
 
220
222
  /**