web-component-gallery 2.2.31 → 2.2.33

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,40 +1,42 @@
1
1
  import PropTypes from 'ant-design-vue/es/_util/vue-types'
2
2
  import Descriptions from 'ant-design-vue/es/descriptions'
3
-
4
3
  import Browse from '../browse/index.jsx'
5
4
  import { transferData } from '../../utils/Filter.js'
6
5
 
7
- const {
8
- Item: DescriptionsItem
9
- } = Descriptions
6
+ const { Item: DescriptionsItem } = Descriptions
10
7
 
11
8
  const descDefaultAttrs = {
12
9
  size: 'middle',
13
10
  bordered: true
14
- }
11
+ }
15
12
 
16
13
  const DescriptionsProps = {
17
14
  title: PropTypes.string,
18
- column: PropTypes.oneOfType([PropTypes.number, PropTypes.object]).def(3),
15
+ column: PropTypes.oneOfType([PropTypes.number, PropTypes.object]).def(4),
19
16
  descDetails: PropTypes.object,
20
17
  descSettings: PropTypes.array,
21
18
  descAttrs: PropTypes.object,
22
19
  }
23
20
 
24
21
  const renderContent = (h, item, details) => {
25
- const CustomTag = item.type === 'file' && Browse || 'span'
26
- const data =
27
- item.hasOwnProperty( 'multiProps' ) ?
28
- item.multiProps.map( propsItem => transferData(details[propsItem], 'Array') ).flat() :
29
- transferData(details[item.props], 'Array')
22
+ const CustomTag = item.type === 'file' ? Browse : 'span'
23
+ const data = item.hasOwnProperty('multiProps') ?
24
+ item.multiProps.map(propsItem => transferData(details[propsItem], 'Array')).flat() :
25
+ transferData(details[item.props], 'Array')
26
+
30
27
  const props = {
31
28
  data,
32
29
  isThumb: true,
33
30
  astrictH: 78
34
31
  }
32
+
33
+ const contentValue = item.customRender ?
34
+ item.customRender(details[item.props], details) :
35
+ details[item.props]
36
+
35
37
  return (
36
38
  <CustomTag {...{ props }}>
37
- { (item.customRender && item.customRender(details[item.props], details) || details[item.props]) ?? '暂无'}
39
+ {contentValue ?? '暂无'}
38
40
  </CustomTag>
39
41
  )
40
42
  }
@@ -42,73 +44,113 @@ const renderContent = (h, item, details) => {
42
44
  const DescriptionsList = {
43
45
  name: 'DescriptionsList',
44
46
  props: DescriptionsProps,
45
- render(h, content) {
46
- const { title, column, descAttrs, descDetails, descSettings, $slots, $scopedSlots } = this
47
- return (
48
- <div class="Descriptions" ref="Descriptions">
49
- <Descriptions
50
- title={title}
51
- column={column}
52
- {...{ attrs: { ...descDefaultAttrs, ...descAttrs } }}
53
- >
54
- {
55
- descSettings.map( (descItem, key) => {
56
- return (
57
- <DescriptionsItem
58
- key={key}
59
- span={descItem.span ?? 1}
60
- >
61
- <span slot="label">
62
- {$slots[`${descItem.props}Lable`] ?? descItem.label}
63
- </span>
64
- {
65
- $scopedSlots[`${descItem.props}`] ?
66
- $scopedSlots[`${descItem.props}`](descDetails) :
67
- renderContent(h, descItem, descDetails)
68
- }
69
- </DescriptionsItem>
70
- )
71
- } )
72
- }
73
- </Descriptions>
74
- </div>
75
- )
76
-
47
+ data() {
48
+ return {
49
+ responsiveColumn: 1
50
+ }
77
51
  },
78
52
  mounted() {
79
53
  this.setDescContentWidth()
80
54
  this.$bus.$onWindow(this, 'resize', this.setDescContentWidth)
81
55
  },
82
56
  methods: {
57
+ getCurrentColumn(width) {
58
+ if (width >= 1600) return Math.min(4, this.column)
59
+ if (width >= 992) return Math.min(3, this.column)
60
+ if (width >= 576) return Math.min(2, this.column)
61
+ return 1
62
+ },
63
+
64
+ calculateItemWidth(totalWidth, itemSpan) {
65
+ const effectiveSpan = itemSpan && this.responsiveColumn > itemSpan ? itemSpan : 1
66
+ return totalWidth * (effectiveSpan / this.responsiveColumn)
67
+ },
68
+
83
69
  setDescContentWidth() {
84
70
  const retry = () => {
85
- const elementG = this.$refs.Descriptions.querySelectorAll('.ant-descriptions-item-content')
86
- const width = document.querySelector('.ant-descriptions-view').offsetWidth
87
- const labelWidth = document.querySelector('.ant-descriptions-item-label').offsetWidth
88
- const { column, descSettings } = this
71
+ const container = this.$refs.Descriptions
72
+ if (!container) return
73
+
74
+ const viewElement = container.querySelector('.ant-descriptions-view')
75
+ if (!viewElement) return
76
+
77
+ const width = viewElement.offsetWidth
89
78
  if (width === 0) {
90
- setTimeout(retry, 100) // 重试间隔100ms
79
+ setTimeout(retry, 100)
91
80
  return
92
81
  }
93
- for (let i = 0; i < elementG.length; i++) {
94
- const contentWidth = (
95
- descSettings[i].span ?
96
- width * (descSettings[i].span / column) :
97
- width / column ) - labelWidth + 'px'
98
- const element = elementG[i]
99
- element.style = `
100
- width: ${contentWidth};
101
- min-width: ${contentWidth};
102
- max-width: ${contentWidth};
103
- `
104
- }
82
+
83
+ this.responsiveColumn = this.getCurrentColumn(width)
84
+
85
+ setTimeout(() => {
86
+ const rowElements = container.querySelectorAll('.ant-descriptions-row')
87
+ // 记录数量
88
+ let count = 0
89
+
90
+ for (let i = 0; i < rowElements.length; i++) {
91
+ const labelElements = rowElements[i].querySelectorAll('.ant-descriptions-item-label')
92
+ const contentElements = rowElements[i].querySelectorAll('.ant-descriptions-item-content')
93
+ // 计算平均宽度
94
+ const meanWidth = width / labelElements.length
95
+
96
+ for (let j = 0; j < labelElements.length; j++) {
97
+ const itemSpan = this.descSettings[count]?.span || 1
98
+ const eachWidth = width / this.responsiveColumn * itemSpan
99
+
100
+ // 设置标签固定宽度
101
+ labelElements[j].style = `
102
+ width: 160px;
103
+ min-width: 160px;
104
+ max-width: 160px;
105
+ `
106
+
107
+ // 设置内容区域默认宽度
108
+ contentElements[j].style = `
109
+ width: ${eachWidth - 160}px;
110
+ min-width: ${eachWidth - 160}px;
111
+ max-width: ${eachWidth - 160}px;
112
+ `
113
+
114
+ count++
115
+ }
116
+ }
117
+ }, 0)
118
+
105
119
  }
106
- retry() // 初始调用
120
+ retry()
107
121
  }
122
+ },
123
+ render(h) {
124
+ const { title, descAttrs, descDetails, descSettings, $slots, $scopedSlots } = this
125
+
126
+ return (
127
+ <div class="Descriptions" ref="Descriptions">
128
+ <Descriptions
129
+ title={title}
130
+ column={this.responsiveColumn}
131
+ {...{ attrs: { ...descDefaultAttrs, ...descAttrs } }}
132
+ >
133
+ {descSettings.map((descItem, key) => (
134
+ <DescriptionsItem
135
+ key={key}
136
+ span={descItem.span ?? 1}
137
+ >
138
+ <span slot="label">
139
+ {$slots[`${descItem.props}Label`] ?? descItem.label}
140
+ </span>
141
+ {$scopedSlots[descItem.props] ?
142
+ $scopedSlots[descItem.props](descDetails) :
143
+ renderContent(h, descItem, descDetails)
144
+ }
145
+ </DescriptionsItem>
146
+ ))}
147
+ </Descriptions>
148
+ </div>
149
+ )
108
150
  }
109
151
  }
110
152
 
111
- DescriptionsList.install = function (Vue) {
153
+ DescriptionsList.install = function(Vue) {
112
154
  Vue.component('DescriptionsList', DescriptionsList)
113
155
  }
114
156
 
@@ -1,10 +1,15 @@
1
-
2
1
  .Descriptions {
2
+ flex: 1;
3
+ overflow-y: auto;
4
+ .scrollbarStyle();
5
+
3
6
  .ant-descriptions-bordered {
7
+
8
+ .ant-descriptions-view > table {
9
+ table-layout: fixed;
10
+ }
11
+
4
12
  .ant-descriptions-item-label {
5
- width: 160px;
6
- min-width: 160px;
7
- max-width: 160px;
8
13
  text-align: left;
9
14
  word-wrap: break-word;
10
15
  }
@@ -14,7 +19,7 @@
14
19
 
15
20
  .Browse {
16
21
  align-items: center;
17
- .flex-layout(@flexGap: 0 @padding-lg);
22
+ .flex-layout(@flexGap: 0 @padding-lg);
18
23
 
19
24
  &__FileThumb {
20
25
  .layout(auto, 78px);
@@ -3,6 +3,8 @@
3
3
  <DatePicker
4
4
  v-model="date[0]"
5
5
  v-bind="startPickerAttrs"
6
+ :disabledDate="disabledStartDate"
7
+ :disabledTime="disabledStartTime"
6
8
  @openChange="handleStartOpenChange"
7
9
  />
8
10
  <span class="separator">~</span>
@@ -10,16 +12,19 @@
10
12
  v-model="date[1]"
11
13
  :open="endOpen"
12
14
  v-bind="endPickerAttrs"
15
+ :disabledDate="disabledEndDate"
16
+ :disabledTime="disabledEndTime"
13
17
  @openChange="handleEndOpenChange"
14
18
  />
15
19
  </div>
16
20
  </template>
21
+
17
22
  <script>
18
23
 
19
24
  const defaultConfig = {
20
- showTime: true,
21
- format: 'YYYY-MM-DD HH:mm:ss',
22
- valueFormat: 'YYYY-MM-DD HH:mm:ss'
25
+ showTime: true,
26
+ format: 'YYYY-MM-DD HH:mm:ss',
27
+ valueFormat: 'YYYY-MM-DD HH:mm:ss'
23
28
  }
24
29
 
25
30
  import moment from 'moment'
@@ -57,7 +62,7 @@ export default {
57
62
  watch: {
58
63
  value: {
59
64
  handler(newVal, oldVal) {
60
- if (newVal.toString() === oldVal.toString()) return
65
+ if (newVal.toString() === oldVal?.toString()) return
61
66
  this.date = [...newVal]
62
67
  },
63
68
  immediate: true
@@ -75,7 +80,6 @@ export default {
75
80
  return {
76
81
  ...defaultConfig,
77
82
  placeholder: '开始日期',
78
- // disabledDate: this.disabledStartDate,
79
83
  ...this.startConfig
80
84
  }
81
85
  },
@@ -84,30 +88,11 @@ export default {
84
88
  return {
85
89
  ...defaultConfig,
86
90
  placeholder: '结束日期',
87
- // disabledDate: this.disabledEndDate,
88
91
  ...this.endConfig
89
92
  }
90
93
  }
91
94
  },
92
95
  methods: {
93
- disabledStartDate(startValue) {
94
- const endValue = this.date[1]
95
- if (!startValue || !endValue) {
96
- return false
97
- }
98
- const startDate = moment(startValue, this.startPickerAttrs.valueFormat)
99
- const endDate = moment(endValue, this.endPickerAttrs.valueFormat)
100
- return startDate.valueOf() > endDate.valueOf()
101
- },
102
- disabledEndDate(endValue) {
103
- const startValue = this.date[0]
104
- if (!endValue || !startValue) {
105
- return false
106
- }
107
- const startDate = moment(startValue, this.startPickerAttrs.valueFormat)
108
- const endDate = moment(endValue, this.endPickerAttrs.valueFormat)
109
- return endDate.valueOf() < startDate.valueOf()
110
- },
111
96
  handleStartOpenChange(open) {
112
97
  if (!open) {
113
98
  this.endOpen = true
@@ -115,6 +100,83 @@ export default {
115
100
  },
116
101
  handleEndOpenChange(open) {
117
102
  this.endOpen = open
103
+ },
104
+
105
+ // 禁用开始日期
106
+ disabledStartDate(current) {
107
+ if (!this.date[1]) return false
108
+ return current && current > moment(this.date[1])
109
+ },
110
+
111
+ // 禁用开始时间
112
+ disabledStartTime(selectedTime) {
113
+ if (!this.date[1]) return {}
114
+
115
+ const endMoment = moment(this.date[1])
116
+ const currentMoment = selectedTime ? moment(selectedTime) : moment()
117
+
118
+ // 如果选择的是同一天,则限制小时、分钟、秒
119
+ if (currentMoment.isSame(endMoment, 'day')) {
120
+ return {
121
+ disabledHours: () => this.range(0, 24).slice(endMoment.hour() + 1),
122
+ disabledMinutes: (selectedHour) => {
123
+ if (selectedHour === endMoment.hour()) {
124
+ return this.range(0, 60).slice(endMoment.minute() + 1)
125
+ }
126
+ return []
127
+ },
128
+ disabledSeconds: (selectedHour, selectedMinute) => {
129
+ if (selectedHour === endMoment.hour() && selectedMinute === endMoment.minute()) {
130
+ return this.range(0, 60).slice(endMoment.second() + 1)
131
+ }
132
+ return []
133
+ }
134
+ }
135
+ }
136
+ return {}
137
+ },
138
+
139
+ // 禁用结束日期
140
+ disabledEndDate(current) {
141
+ if (!this.date[0]) return false
142
+ return current && current < moment(this.date[0]).startOf('day')
143
+ },
144
+
145
+ // 禁用结束时间
146
+ disabledEndTime(selectedTime) {
147
+ if (!this.date[0]) return {}
148
+
149
+ const startMoment = moment(this.date[0])
150
+ const currentMoment = selectedTime ? moment(selectedTime) : moment()
151
+
152
+ // 如果选择的是同一天,则限制小时、分钟、秒
153
+ if (currentMoment.isSame(startMoment, 'day')) {
154
+ return {
155
+ disabledHours: () => this.range(0, startMoment.hour()),
156
+ disabledMinutes: (selectedHour) => {
157
+ if (selectedHour === startMoment.hour()) {
158
+ return this.range(0, startMoment.minute())
159
+ }
160
+ return []
161
+ },
162
+ disabledSeconds: (selectedHour, selectedMinute) => {
163
+ if (selectedHour === startMoment.hour() && selectedMinute === startMoment.minute()) {
164
+ return this.range(0, startMoment.second())
165
+ }
166
+ return []
167
+ }
168
+ }
169
+ }
170
+ return {}
171
+ },
172
+
173
+ // 生成数字范围
174
+ range(start, end) {
175
+ const result = []
176
+ for (let i = start; i < end; i++) {
177
+ result.push(i)
178
+ }
179
+ return result
118
180
  }
119
181
  }
120
182
  }
@@ -98,6 +98,11 @@ export default {
98
98
  type: Boolean,
99
99
  default: true
100
100
  },
101
+ // 带搜索条件的失焦情况下默认清空重新请求
102
+ autoClearSearchValue: {
103
+ type: Boolean,
104
+ default: true
105
+ },
101
106
  listPageParams: Object,
102
107
  listPageHandler: Function,
103
108
 
@@ -166,7 +171,7 @@ export default {
166
171
  },
167
172
  isSelectOpen(newVal) {
168
173
  // 选择器关闭后,搜索条件存在的情况下是否清空搜索框
169
- const shouldClear = !newVal && this.searchValue && this.attrs.autoClearSearchValue
174
+ const shouldClear = !newVal && this.searchValue && this.autoClearSearchValue
170
175
  if (shouldClear) this.resetRequest()
171
176
  },
172
177
  listPageParams: {
@@ -148,6 +148,7 @@ export default {
148
148
  block: "center"
149
149
  })
150
150
  })
151
+ reject()
151
152
  })
152
153
  })
153
154
  }
@@ -24,7 +24,7 @@
24
24
  </template>
25
25
 
26
26
  <template #customRender="text, record, i, column">
27
- <slot :name="column.dataIndex" :customProps="record" :text="text" :index="i" />
27
+ <slot :name="column.dataIndex" :customProps="record" :text="text" :index="i" :column="column" />
28
28
  </template>
29
29
  </Table>
30
30
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-component-gallery",
3
- "version": "2.2.31",
3
+ "version": "2.2.33",
4
4
  "description": "基础vue、antdvue、less实现的私有组件库",
5
5
  "main": "dist/index.umd.js",
6
6
  "files": [