vxe-table 3.4.11 → 3.4.12

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.
@@ -7,18 +7,19 @@ const { getRowid } = UtilTools
7
7
 
8
8
  function insertTreeRow (_vm, newRecords, isAppend) {
9
9
  const { tableFullTreeData, afterFullData, fullDataRowIdData, fullAllDataRowIdData, treeOpts } = _vm
10
+ const { rowField, parentField, children, mapChildren } = treeOpts
10
11
  const funcName = isAppend ? 'push' : 'unshift'
11
12
  newRecords.forEach(item => {
12
- const parentRowId = item[treeOpts.parentField]
13
+ const parentRowId = item[parentField]
13
14
  const rowid = getRowid(_vm, item)
14
- const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, item => parentRowId === item[treeOpts.rowField], treeOpts) : null
15
+ const matchObj = parentRowId ? XEUtils.findTree(tableFullTreeData, item => parentRowId === item[rowField], { children: mapChildren }) : null
15
16
  if (matchObj) {
16
17
  const { item: parentRow } = matchObj
17
18
  const parentRest = fullAllDataRowIdData[getRowid(_vm, parentRow)]
18
19
  const parentLevel = parentRest ? parentRest.level : 0
19
- let parentChilds = parentRow[treeOpts.children]
20
+ let parentChilds = parentRow[children]
20
21
  if (!XEUtils.isArray(parentChilds)) {
21
- parentChilds = parentRow[treeOpts.children] = []
22
+ parentChilds = parentRow[children] = []
22
23
  }
23
24
  parentChilds[funcName](item)
24
25
  const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, items: parentChilds, parent, level: parentLevel + 1 }
@@ -59,7 +60,7 @@ export default {
59
60
  */
60
61
  _insertAt (records, row) {
61
62
  const { tableFullTreeData, mergeList, afterFullData, editStore, tableFullData, treeConfig, fullDataRowIdData, fullAllDataRowIdData, treeOpts } = this
62
- const { transform } = treeOpts
63
+ const { transform, rowField, mapChildren } = treeOpts
63
64
  if (!XEUtils.isArray(records)) {
64
65
  records = [records]
65
66
  }
@@ -98,7 +99,7 @@ export default {
98
99
  } else {
99
100
  // 如果为虚拟树
100
101
  if (treeConfig && transform) {
101
- const matchObj = XEUtils.findTree(tableFullTreeData, item => row[treeOpts.rowField] === item[treeOpts.rowField], treeOpts)
102
+ const matchObj = XEUtils.findTree(tableFullTreeData, item => row[rowField] === item[rowField], { children: mapChildren })
102
103
  if (matchObj) {
103
104
  const { parent: parentRow } = matchObj
104
105
  const parentChilds = matchObj.items
@@ -108,13 +109,13 @@ export default {
108
109
  const rowid = getRowid(this, item)
109
110
  if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
110
111
  if (item[treeOpts.parentField]) {
111
- if (parentRow && item[treeOpts.parentField] !== parentRow[treeOpts.rowField]) {
112
- UtilTools.error('vxe.error.errProp', [`${treeOpts.parentField}=${item[treeOpts.parentField]}`, `${treeOpts.parentField}=${parentRow[treeOpts.rowField]}`])
112
+ if (parentRow && item[treeOpts.parentField] !== parentRow[rowField]) {
113
+ UtilTools.error('vxe.error.errProp', [`${treeOpts.parentField}=${item[treeOpts.parentField]}`, `${treeOpts.parentField}=${parentRow[rowField]}`])
113
114
  }
114
115
  }
115
116
  }
116
117
  if (parentRow) {
117
- item[treeOpts.parentField] = parentRow[treeOpts.rowField]
118
+ item[treeOpts.parentField] = parentRow[rowField]
118
119
  }
119
120
  parentChilds.splice(matchObj.index + i, 0, item)
120
121
  const rest = { row: item, rowid, seq: -1, index: -1, _index: -1, $index: -1, items: parentChilds, parent: parentRow, level: parentLevel + 1 }
@@ -131,7 +132,15 @@ export default {
131
132
  if (treeConfig) {
132
133
  throw new Error(UtilTools.getLog('vxe.error.noTree', ['insert']))
133
134
  }
134
- const afIndex = afterFullData.indexOf(row)
135
+ let afIndex = -1
136
+ // 如果是可视索引
137
+ if (XEUtils.isNumber(row)) {
138
+ if (row < afterFullData.length) {
139
+ afIndex = row
140
+ }
141
+ } else {
142
+ afIndex = afterFullData.indexOf(row)
143
+ }
135
144
  if (afIndex === -1) {
136
145
  throw new Error(UtilTools.error('vxe.error.unableInsert'))
137
146
  }
@@ -253,7 +253,7 @@ export default {
253
253
  created () {
254
254
  const { data, formOpts, proxyOpts, proxyConfig } = this
255
255
  if (proxyConfig && (data || (proxyOpts.form && formOpts.data))) {
256
- console.error('[vxe-grid] There is a conflict between the props proxy-config and data.')
256
+ UtilTools.error('vxe.error.errConflicts', ['grid.data', 'grid.proxy-config'])
257
257
  }
258
258
 
259
259
  if (process.env.VUE_APP_VXE_TABLE_ENV === 'development') {
@@ -756,15 +756,10 @@ export default {
756
756
  return this.maxDate ? XEUtils.toStringDate(this.maxDate) : null
757
757
  },
758
758
  dateValue () {
759
- const { value, isDatePickerType, type, dateValueFormat } = this
759
+ const { value, isDatePickerType, dateValueFormat } = this
760
760
  let val = null
761
761
  if (value && isDatePickerType) {
762
- let date
763
- if (type === 'time') {
764
- date = toStringTimeDate(value)
765
- } else {
766
- date = XEUtils.toStringDate(value, dateValueFormat)
767
- }
762
+ const date = this.parseDate(value, dateValueFormat)
768
763
  if (XEUtils.isValidDate(date)) {
769
764
  val = date
770
765
  }
@@ -812,11 +807,14 @@ export default {
812
807
  }
813
808
  return ''
814
809
  },
810
+ firstDayOfWeek () {
811
+ const { startDay, startWeek } = this
812
+ return XEUtils.toNumber(XEUtils.isNumber(startDay) || XEUtils.isString(startDay) ? startDay : startWeek)
813
+ },
815
814
  weekDatas () {
816
815
  const weeks = []
817
816
  if (this.isDatePickerType) {
818
- const { startDay, startWeek } = this
819
- let sWeek = XEUtils.toNumber(XEUtils.isNumber(startDay) || XEUtils.isString(startDay) ? startDay : startWeek)
817
+ let { firstDayOfWeek: sWeek } = this
820
818
  weeks.push(sWeek)
821
819
  for (let index = 0; index < 6; index++) {
822
820
  if (sWeek >= 6) {
@@ -957,7 +955,8 @@ export default {
957
955
  return XEUtils.chunk(this.dayList, 7)
958
956
  },
959
957
  weekDates () {
960
- return this.dayDatas.map(list => {
958
+ const { dayDatas, firstDayOfWeek } = this
959
+ return dayDatas.map(list => {
961
960
  const firstItem = list[0]
962
961
  const item = {
963
962
  date: firstItem.date,
@@ -966,7 +965,7 @@ export default {
966
965
  isCurrent: false,
967
966
  isNow: false,
968
967
  isNext: false,
969
- label: XEUtils.getYearWeek(firstItem.date)
968
+ label: XEUtils.getYearWeek(firstItem.date, firstDayOfWeek)
970
969
  }
971
970
  return [item].concat(list)
972
971
  })
@@ -1045,8 +1044,10 @@ export default {
1045
1044
  this.initValue()
1046
1045
  },
1047
1046
  dateLabelFormat () {
1048
- this.dateParseValue(this.datePanelValue)
1049
- this.inputValue = this.datePanelLabel
1047
+ if (this.isDatePickerType) {
1048
+ this.dateParseValue(this.datePanelValue)
1049
+ this.inputValue = this.datePanelLabel
1050
+ }
1050
1051
  }
1051
1052
  },
1052
1053
  created () {
@@ -1266,6 +1267,13 @@ export default {
1266
1267
  }
1267
1268
  this.$emit('clear', { $panel: $refs.panel, value, $event: evnt })
1268
1269
  },
1270
+ parseDate (value, format) {
1271
+ const { type } = this
1272
+ if (type === 'time') {
1273
+ return toStringTimeDate(value)
1274
+ }
1275
+ return XEUtils.toStringDate(value, format)
1276
+ },
1269
1277
  /**
1270
1278
  * 检查初始值
1271
1279
  */
@@ -1292,7 +1300,7 @@ export default {
1292
1300
  }
1293
1301
  },
1294
1302
  afterCheckValue () {
1295
- const { type, exponential, inpReadonly, inputValue, isDatePickerType, isNumType, datetimePanelValue, dateLabelFormat, min, max } = this
1303
+ const { type, exponential, inpReadonly, inputValue, isDatePickerType, isNumType, datetimePanelValue, dateLabelFormat, min, max, firstDayOfWeek } = this
1296
1304
  if (!inpReadonly) {
1297
1305
  if (isNumType) {
1298
1306
  if (inputValue) {
@@ -1315,12 +1323,7 @@ export default {
1315
1323
  if (type === 'week' || type === 'quarter') {
1316
1324
  // 周和季度选择器不支持解析,无需处理
1317
1325
  } else {
1318
- let inpDateVal
1319
- if (type === 'time') {
1320
- inpDateVal = toStringTimeDate(inputValue)
1321
- } else {
1322
- inpDateVal = XEUtils.toStringDate(inputValue, dateLabelFormat)
1323
- }
1326
+ let inpDateVal = this.parseDate(inputValue, dateLabelFormat)
1324
1327
  if (XEUtils.isValidDate(inpDateVal)) {
1325
1328
  if (type === 'time') {
1326
1329
  inpDateVal = toStringTimeDate(inpDateVal)
@@ -1340,7 +1343,7 @@ export default {
1340
1343
  } else {
1341
1344
  isChange = true
1342
1345
  }
1343
- this.inputValue = XEUtils.toDateString(inpDateVal, dateLabelFormat)
1346
+ this.inputValue = XEUtils.toDateString(inpDateVal, dateLabelFormat, { firstDay: firstDayOfWeek })
1344
1347
  if (isChange) {
1345
1348
  this.dateChange(inpDateVal)
1346
1349
  }
@@ -1650,18 +1653,27 @@ export default {
1650
1653
  }
1651
1654
  },
1652
1655
  dateParseValue (date) {
1653
- const { type, dateLabelFormat, valueFormat } = this
1656
+ const { type, dateLabelFormat, valueFormat, firstDayOfWeek } = this
1654
1657
  let dValue = null
1655
1658
  let dLabel = ''
1656
1659
  if (date) {
1657
- if (type === 'time') {
1658
- dValue = toStringTimeDate(date)
1659
- } else {
1660
- dValue = XEUtils.toStringDate(date, valueFormat)
1661
- }
1660
+ dValue = this.parseDate(date, valueFormat)
1662
1661
  }
1663
1662
  if (XEUtils.isValidDate(dValue)) {
1664
- dLabel = XEUtils.toDateString(dValue, dateLabelFormat)
1663
+ dLabel = XEUtils.toDateString(dValue, dateLabelFormat, { firstDay: firstDayOfWeek })
1664
+ // 由于年份和第几周是冲突的行为,所以需要特殊处理,判断是否跨年
1665
+ if (dateLabelFormat && type === 'week') {
1666
+ const firstWeekDate = XEUtils.getWhatWeek(dValue, 0, firstDayOfWeek, firstDayOfWeek)
1667
+ if (firstWeekDate.getFullYear() < dValue.getFullYear()) {
1668
+ const yyIndex = dateLabelFormat.indexOf('yyyy')
1669
+ if (yyIndex > -1) {
1670
+ const yyNum = Number(dLabel.substring(yyIndex, yyIndex + 4))
1671
+ if (yyNum && !isNaN(yyNum)) {
1672
+ dLabel = dLabel.replace(`${yyNum}`, `${yyNum - 1}`)
1673
+ }
1674
+ }
1675
+ }
1676
+ }
1665
1677
  } else {
1666
1678
  dValue = null
1667
1679
  }
@@ -1669,7 +1681,7 @@ export default {
1669
1681
  this.datePanelLabel = dLabel
1670
1682
  },
1671
1683
  dateOffsetEvent (evnt) {
1672
- const { isActivated, datePanelValue, datePanelType } = this
1684
+ const { isActivated, datePanelValue, datePanelType, firstDayOfWeek } = this
1673
1685
  if (isActivated) {
1674
1686
  evnt.preventDefault()
1675
1687
  const keyCode = evnt.keyCode
@@ -1718,11 +1730,11 @@ export default {
1718
1730
  if (isLeftArrow) {
1719
1731
  offsetDay = XEUtils.getWhatDay(offsetDay, -1)
1720
1732
  } else if (isUpArrow) {
1721
- offsetDay = XEUtils.getWhatWeek(offsetDay, -1)
1733
+ offsetDay = XEUtils.getWhatWeek(offsetDay, -1, firstDayOfWeek)
1722
1734
  } else if (isRightArrow) {
1723
1735
  offsetDay = XEUtils.getWhatDay(offsetDay, 1)
1724
1736
  } else if (isDwArrow) {
1725
- offsetDay = XEUtils.getWhatWeek(offsetDay, 1)
1737
+ offsetDay = XEUtils.getWhatWeek(offsetDay, 1, firstDayOfWeek)
1726
1738
  }
1727
1739
  this.dateMoveDay(offsetDay)
1728
1740
  }
@@ -1741,16 +1753,16 @@ export default {
1741
1753
  }
1742
1754
  },
1743
1755
  dateChange (date) {
1744
- const { value, datetimePanelValue, dateValueFormat } = this
1756
+ const { value, datetimePanelValue, dateValueFormat, firstDayOfWeek } = this
1745
1757
  if (this.type === 'week') {
1746
1758
  const sWeek = XEUtils.toNumber(this.selectDay)
1747
- date = XEUtils.getWhatWeek(date, 0, sWeek)
1759
+ date = XEUtils.getWhatWeek(date, 0, sWeek, firstDayOfWeek)
1748
1760
  } else if (this.hasTime) {
1749
1761
  date.setHours(datetimePanelValue.getHours())
1750
1762
  date.setMinutes(datetimePanelValue.getMinutes())
1751
1763
  date.setSeconds(datetimePanelValue.getSeconds())
1752
1764
  }
1753
- const inpVal = XEUtils.toDateString(date, dateValueFormat)
1765
+ const inpVal = XEUtils.toDateString(date, dateValueFormat, { firstDay: firstDayOfWeek })
1754
1766
  this.dateCheckMonth(date)
1755
1767
  if (!XEUtils.isEqual(value, inpVal)) {
1756
1768
  this.emitModel(inpVal, { type: 'update' })
@@ -9,7 +9,8 @@ export default {
9
9
  title: [String, Number],
10
10
  content: [String, Number],
11
11
  disabled: Boolean,
12
- size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size }
12
+ strict: { type: Boolean, default: () => GlobalConfig.radioButton.strict },
13
+ size: { type: String, default: () => GlobalConfig.radioButton.size || GlobalConfig.size }
13
14
  },
14
15
  inject: {
15
16
  $xeradiogroup: {
@@ -23,6 +24,10 @@ export default {
23
24
  isDisabled () {
24
25
  const { $xeradiogroup } = this
25
26
  return this.disabled || ($xeradiogroup && $xeradiogroup.disabled)
27
+ },
28
+ isStrict () {
29
+ const { $xeradiogroup } = this
30
+ return $xeradiogroup ? $xeradiogroup.strict : this.strict
26
31
  }
27
32
  },
28
33
  render (h) {
@@ -49,7 +54,8 @@ export default {
49
54
  checked: $xeradiogroup ? $xeradiogroup.value === label : value === label
50
55
  },
51
56
  on: {
52
- change: this.changeEvent
57
+ change: this.changeEvent,
58
+ click: this.clickEvent
53
59
  }
54
60
  }),
55
61
  h('span', {
@@ -58,15 +64,27 @@ export default {
58
64
  ])
59
65
  },
60
66
  methods: {
67
+ handleValue (label, evnt) {
68
+ const { $xeradiogroup } = this
69
+ const params = { label, $event: evnt }
70
+ if ($xeradiogroup) {
71
+ $xeradiogroup.handleChecked(params)
72
+ } else {
73
+ this.$emit('input', label)
74
+ this.$emit('change', params)
75
+ }
76
+ },
61
77
  changeEvent (evnt) {
62
- const { $xeradiogroup, isDisabled, label } = this
78
+ const { isDisabled } = this
63
79
  if (!isDisabled) {
64
- const params = { label, $event: evnt }
65
- if ($xeradiogroup) {
66
- $xeradiogroup.handleChecked(params)
67
- } else {
68
- this.$emit('input', label)
69
- this.$emit('change', params)
80
+ this.handleValue(this.label, evnt)
81
+ }
82
+ },
83
+ clickEvent (evnt) {
84
+ const { $xeradiogroup, isDisabled, isStrict } = this
85
+ if (!isDisabled && !isStrict) {
86
+ if (this.label === ($xeradiogroup ? $xeradiogroup.value : this.value)) {
87
+ this.handleValue(null, evnt)
70
88
  }
71
89
  }
72
90
  }
@@ -6,7 +6,8 @@ export default {
6
6
  props: {
7
7
  value: [String, Number, Boolean],
8
8
  disabled: Boolean,
9
- size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size }
9
+ strict: { type: Boolean, default: () => GlobalConfig.radioGroup.strict },
10
+ size: { type: String, default: () => GlobalConfig.radioGroup.size || GlobalConfig.size }
10
11
  },
11
12
  provide () {
12
13
  return {
@@ -12,6 +12,7 @@ export default {
12
12
  content: [String, Number],
13
13
  disabled: Boolean,
14
14
  name: String,
15
+ strict: { type: Boolean, default: () => GlobalConfig.radio.strict },
15
16
  size: { type: String, default: () => GlobalConfig.radio.size || GlobalConfig.size }
16
17
  },
17
18
  inject: {
@@ -23,6 +24,10 @@ export default {
23
24
  isDisabled () {
24
25
  const { $xeradiogroup } = this
25
26
  return this.disabled || ($xeradiogroup && $xeradiogroup.disabled)
27
+ },
28
+ isStrict () {
29
+ const { $xeradiogroup } = this
30
+ return $xeradiogroup ? $xeradiogroup.strict : this.strict
26
31
  }
27
32
  },
28
33
  render (h) {
@@ -49,17 +54,8 @@ export default {
49
54
  checked: $xeradiogroup ? $xeradiogroup.value === label : value === label
50
55
  },
51
56
  on: {
52
- change: evnt => {
53
- if (!isDisabled) {
54
- const params = { label, $event: evnt }
55
- if ($xeradiogroup) {
56
- $xeradiogroup.handleChecked(params)
57
- } else {
58
- this.$emit('input', label)
59
- this.$emit('change', params)
60
- }
61
- }
62
- }
57
+ change: this.changeEvent,
58
+ click: this.clickEvent
63
59
  }
64
60
  }),
65
61
  h('span', {
@@ -71,15 +67,27 @@ export default {
71
67
  ])
72
68
  },
73
69
  methods: {
70
+ handleValue (label, evnt) {
71
+ const { $xeradiogroup } = this
72
+ const params = { label, $event: evnt }
73
+ if ($xeradiogroup) {
74
+ $xeradiogroup.handleChecked(params)
75
+ } else {
76
+ this.$emit('input', label)
77
+ this.$emit('change', params)
78
+ }
79
+ },
74
80
  changeEvent (evnt) {
75
- const { $xeradiogroup, isDisabled, label } = this
81
+ const { isDisabled } = this
76
82
  if (!isDisabled) {
77
- const params = { label, $event: evnt }
78
- if ($xeradiogroup) {
79
- $xeradiogroup.handleChecked(params)
80
- } else {
81
- this.$emit('input', label)
82
- this.$emit('change', params)
83
+ this.handleValue(this.label, evnt)
84
+ }
85
+ },
86
+ clickEvent (evnt) {
87
+ const { $xeradiogroup, isDisabled, isStrict } = this
88
+ if (!isDisabled && !isStrict) {
89
+ if (this.label === ($xeradiogroup ? $xeradiogroup.value : this.value)) {
90
+ this.handleValue(null, evnt)
83
91
  }
84
92
  }
85
93
  }
@@ -1083,20 +1083,21 @@ const Methods = {
1083
1083
  * 用于多选行,获取已选中的数据
1084
1084
  */
1085
1085
  getCheckboxRecords (isFull) {
1086
- const { tableFullData, afterFullData, treeConfig, treeOpts, checkboxOpts } = this
1086
+ const { tableFullData, afterFullData, treeConfig, treeOpts, checkboxOpts, tableFullTreeData, afterTreeFullData } = this
1087
+ const { transform, children, mapChildren } = treeOpts
1087
1088
  const { checkField: property } = checkboxOpts
1088
- const currTableData = isFull ? tableFullData : afterFullData
1089
+ const currTableData = isFull ? (transform ? tableFullTreeData : tableFullData) : (transform ? afterTreeFullData : afterFullData)
1089
1090
  let rowList = []
1090
1091
  if (property) {
1091
1092
  if (treeConfig) {
1092
- rowList = XEUtils.filterTree(currTableData, row => XEUtils.get(row, property), treeOpts)
1093
+ rowList = XEUtils.filterTree(currTableData, row => XEUtils.get(row, property), { children: transform ? mapChildren : children })
1093
1094
  } else {
1094
1095
  rowList = currTableData.filter(row => XEUtils.get(row, property))
1095
1096
  }
1096
1097
  } else {
1097
1098
  const { selection } = this
1098
1099
  if (treeConfig) {
1099
- rowList = XEUtils.filterTree(currTableData, row => selection.indexOf(row) > -1, treeOpts)
1100
+ rowList = XEUtils.filterTree(currTableData, row => selection.indexOf(row) > -1, { children: transform ? mapChildren : children })
1100
1101
  } else {
1101
1102
  rowList = currTableData.filter(row => selection.indexOf(row) > -1)
1102
1103
  }
@@ -1268,6 +1269,24 @@ const Methods = {
1268
1269
  })
1269
1270
  }
1270
1271
  },
1272
+ /**
1273
+ * 只对 tree-config 有效,获取行的父级
1274
+ */
1275
+ getParentRow (rowOrRowid) {
1276
+ const { treeConfig, fullDataRowIdData } = this
1277
+ if (rowOrRowid && treeConfig) {
1278
+ let rowid
1279
+ if (XEUtils.isString(rowOrRowid)) {
1280
+ rowid = rowOrRowid
1281
+ } else {
1282
+ rowid = getRowid(this, rowOrRowid)
1283
+ }
1284
+ if (rowid) {
1285
+ return fullDataRowIdData[rowid] ? fullDataRowIdData[rowid].parent : null
1286
+ }
1287
+ }
1288
+ return null
1289
+ },
1271
1290
  /**
1272
1291
  * 根据行的唯一主键获取行
1273
1292
  * @param {String/Number} rowid 行主键
@@ -292,7 +292,16 @@ export default {
292
292
  // transfer: false
293
293
  },
294
294
  radio: {
295
- // size: null
295
+ // size: null,
296
+ strict: true
297
+ },
298
+ radioButton: {
299
+ // size: null,
300
+ strict: true
301
+ },
302
+ radioGroup: {
303
+ // size: null,
304
+ strict: true
296
305
  },
297
306
  checkbox: {
298
307
  // size: null