Skip to content

Commit 3da5fe7

Browse files
committed
featfix: 修复 CTreeDrop 下拉框定位错误
1 parent c316db1 commit 3da5fe7

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/
55

66
## [Unreleased]
77

8+
## [2.2.5] - 2019-12-11
9+
10+
### Added
11+
12+
### Changed
13+
14+
### Deprecated
15+
16+
### Removed
17+
18+
### Fixed
19+
20+
- 修复 `CTreeDrop` 下拉框定位不正确的问题
21+
22+
### Security
23+
824
## [2.2.4] - 2019-11-22
925

1026
### Added

examples/Drop.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
clearable
88
:cascade="false"
99
drop-placeholder="请选择"
10+
:placement="placement"
1011
:dropdown-min-width="300"
1112
dropdown-width-fixed
1213
@checked-change="handleCheckedChange"
@@ -48,6 +49,7 @@ export default {
4849
return {
4950
data,
5051
value: '2',
52+
placement: 'bottom-start',
5153
}
5254
},
5355
methods: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wsfe/ctree",
3-
"version": "2.2.4",
3+
"version": "2.2.5",
44
"main": "./dist/ctree.umd.min.js",
55
"types": "./types",
66
"description": "A vue tree component using virtual list.",

src/components/TreeDrop.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,21 @@ export default (Vue as VueConstructor<Vue & {
264264
/** 定位下拉框 */
265265
locateDropdown (): void {
266266
const referenceRect = this.$refs.reference.getBoundingClientRect()
267-
const referenceWidth = referenceRect.right - referenceRect.left
268-
const referenceHeight = referenceRect.bottom - referenceRect.top
267+
const referenceWidth = referenceRect.width
268+
const referenceHeight = referenceRect.height
269269
270270
// Set dropdown width
271271
const minWidth = `${typeof this.dropdownMinWidth === 'number' ? this.dropdownMinWidth : referenceWidth}px`
272272
this.$refs.dropdown.style.minWidth = minWidth
273273
this.$refs.dropdown.style.width = this.dropdownWidthFixed ? minWidth : 'auto'
274274
275275
const dropdownRect = this.$refs.dropdown.getBoundingClientRect()
276-
const dropdownWidth = dropdownRect.right - dropdownRect.left
277-
const dropdownHeight = dropdownRect.bottom - dropdownRect.top
276+
const dropdownStyleDeclaration = window.getComputedStyle(this.$refs.dropdown)
277+
const dropdownMarginHorizontal = parseFloat(dropdownStyleDeclaration.marginLeft) + parseFloat(dropdownStyleDeclaration.marginRight)
278+
const dropdownMarginVertical = parseFloat(dropdownStyleDeclaration.marginTop) + parseFloat(dropdownStyleDeclaration.marginBottom)
279+
const dropdownWidth = dropdownRect.width + dropdownMarginHorizontal
280+
// 0.8 这个值写在 css 里,因为有动画,所以获取到的是 scaleY 变换后的值
281+
const dropdownHeight = dropdownRect.height / 0.8 + dropdownMarginVertical
278282
let top = 0
279283
let left = 0
280284
if (this.transfer) {
@@ -302,7 +306,7 @@ export default (Vue as VueConstructor<Vue & {
302306
case 'bottom':
303307
if (this.transfer) {
304308
top = window.pageYOffset + referenceRect.bottom
305-
left = window.pageXOffset + referenceRect.right - dropdownWidth
309+
left = (window.pageXOffset + referenceRect.right - dropdownWidth) / 2
306310
} else {
307311
top = referenceHeight
308312
left = (referenceWidth - dropdownWidth) / 2
@@ -328,7 +332,7 @@ export default (Vue as VueConstructor<Vue & {
328332
case 'top':
329333
if (this.transfer) {
330334
top = window.pageYOffset + referenceRect.top - dropdownHeight
331-
left = window.pageXOffset + referenceRect.right - dropdownWidth
335+
left = (window.pageXOffset + referenceRect.right - dropdownWidth) / 2
332336
} else {
333337
top = -dropdownHeight
334338
left = (referenceWidth - dropdownWidth) / 2

0 commit comments

Comments
 (0)