Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dcxy-manage-shell
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姜雷
dcxy-manage-shell
Commits
99c60db1
Commit
99c60db1
authored
May 08, 2019
by
姜雷
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改用户信息弹窗的zindex层级和普通弹窗一致
parent
49b07d64
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
425 additions
and
0 deletions
+425
-0
UserDialog.vue
src/components/Dialog/UserDialog.vue
+2
-0
index.js
src/components/Popup/index.js
+226
-0
popup-manager.js
src/components/Popup/popup-manager.js
+197
-0
No files found.
src/components/Dialog/UserDialog.vue
View file @
99c60db1
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
<
script
>
<
script
>
import
{
Dialog
}
from
'element-ui'
;
import
{
Dialog
}
from
'element-ui'
;
import
Popup
from
'../Popup'
;
export
default
{
export
default
{
name
:
'user-dialog-inner'
,
name
:
'user-dialog-inner'
,
...
@@ -65,6 +66,7 @@ export default {
...
@@ -65,6 +66,7 @@ export default {
default
:
false
,
default
:
false
,
},
},
},
},
mixins
:
[
Popup
],
// mounted() {
// mounted() {
// let dialogWidth = 0;
// let dialogWidth = 0;
// console.log(this.$refs.userContent.$el.offsetWidth);
// console.log(this.$refs.userContent.$el.offsetWidth);
...
...
src/components/Popup/index.js
0 → 100644
View file @
99c60db1
import
Vue
from
'vue'
;
import
merge
from
'element-ui/src/utils/merge'
;
import
PopupManager
from
'./popup-manager'
;
import
getScrollBarWidth
from
'element-ui/src/utils/scrollbar-width'
;
import
{
getStyle
,
addClass
,
removeClass
,
hasClass
}
from
'element-ui/src/utils/dom'
;
let
idSeed
=
1
;
let
scrollBarWidth
;
const
getDOM
=
function
(
dom
)
{
if
(
dom
.
nodeType
===
3
)
{
dom
=
dom
.
nextElementSibling
||
dom
.
nextSibling
;
getDOM
(
dom
);
}
return
dom
;
};
export
default
{
props
:
{
visible
:
{
type
:
Boolean
,
default
:
false
},
openDelay
:
{},
closeDelay
:
{},
zIndex
:
{},
modal
:
{
type
:
Boolean
,
default
:
false
},
modalFade
:
{
type
:
Boolean
,
default
:
true
},
modalClass
:
{},
modalAppendToBody
:
{
type
:
Boolean
,
default
:
false
},
lockScroll
:
{
type
:
Boolean
,
default
:
true
},
closeOnPressEscape
:
{
type
:
Boolean
,
default
:
false
},
closeOnClickModal
:
{
type
:
Boolean
,
default
:
false
}
},
beforeMount
()
{
this
.
_popupId
=
'popup-'
+
idSeed
++
;
PopupManager
.
register
(
this
.
_popupId
,
this
);
},
beforeDestroy
()
{
PopupManager
.
deregister
(
this
.
_popupId
);
PopupManager
.
closeModal
(
this
.
_popupId
);
this
.
restoreBodyStyle
();
},
data
()
{
return
{
opened
:
false
,
bodyPaddingRight
:
null
,
computedBodyPaddingRight
:
0
,
withoutHiddenClass
:
true
,
rendered
:
false
};
},
watch
:
{
visible
(
val
)
{
if
(
val
)
{
if
(
this
.
_opening
)
return
;
if
(
!
this
.
rendered
)
{
this
.
rendered
=
true
;
Vue
.
nextTick
(()
=>
{
this
.
open
();
});
}
else
{
this
.
open
();
}
}
else
{
this
.
close
();
}
}
},
methods
:
{
open
(
options
)
{
if
(
!
this
.
rendered
)
{
this
.
rendered
=
true
;
}
const
props
=
merge
({},
this
.
$props
||
this
,
options
);
if
(
this
.
_closeTimer
)
{
clearTimeout
(
this
.
_closeTimer
);
this
.
_closeTimer
=
null
;
}
clearTimeout
(
this
.
_openTimer
);
const
openDelay
=
Number
(
props
.
openDelay
);
if
(
openDelay
>
0
)
{
this
.
_openTimer
=
setTimeout
(()
=>
{
this
.
_openTimer
=
null
;
this
.
doOpen
(
props
);
},
openDelay
);
}
else
{
this
.
doOpen
(
props
);
}
},
doOpen
(
props
)
{
if
(
this
.
$isServer
)
return
;
if
(
this
.
willOpen
&&
!
this
.
willOpen
())
return
;
if
(
this
.
opened
)
return
;
this
.
_opening
=
true
;
const
dom
=
getDOM
(
this
.
$el
);
const
modal
=
props
.
modal
;
const
zIndex
=
props
.
zIndex
;
if
(
zIndex
)
{
PopupManager
.
zIndex
=
zIndex
;
}
if
(
modal
)
{
if
(
this
.
_closing
)
{
PopupManager
.
closeModal
(
this
.
_popupId
);
this
.
_closing
=
false
;
}
PopupManager
.
openModal
(
this
.
_popupId
,
PopupManager
.
nextZIndex
(),
this
.
modalAppendToBody
?
undefined
:
dom
,
props
.
modalClass
,
props
.
modalFade
);
if
(
props
.
lockScroll
)
{
this
.
withoutHiddenClass
=
!
hasClass
(
document
.
body
,
'el-popup-parent--hidden'
);
if
(
this
.
withoutHiddenClass
)
{
this
.
bodyPaddingRight
=
document
.
body
.
style
.
paddingRight
;
this
.
computedBodyPaddingRight
=
parseInt
(
getStyle
(
document
.
body
,
'paddingRight'
),
10
);
}
scrollBarWidth
=
getScrollBarWidth
();
let
bodyHasOverflow
=
document
.
documentElement
.
clientHeight
<
document
.
body
.
scrollHeight
;
let
bodyOverflowY
=
getStyle
(
document
.
body
,
'overflowY'
);
if
(
scrollBarWidth
>
0
&&
(
bodyHasOverflow
||
bodyOverflowY
===
'scroll'
)
&&
this
.
withoutHiddenClass
)
{
document
.
body
.
style
.
paddingRight
=
this
.
computedBodyPaddingRight
+
scrollBarWidth
+
'px'
;
}
addClass
(
document
.
body
,
'el-popup-parent--hidden'
);
}
}
if
(
getComputedStyle
(
dom
).
position
===
'static'
)
{
dom
.
style
.
position
=
'absolute'
;
}
dom
.
style
.
zIndex
=
PopupManager
.
nextZIndex
();
this
.
opened
=
true
;
this
.
onOpen
&&
this
.
onOpen
();
this
.
doAfterOpen
();
},
doAfterOpen
()
{
this
.
_opening
=
false
;
},
close
()
{
if
(
this
.
willClose
&&
!
this
.
willClose
())
return
;
if
(
this
.
_openTimer
!==
null
)
{
clearTimeout
(
this
.
_openTimer
);
this
.
_openTimer
=
null
;
}
clearTimeout
(
this
.
_closeTimer
);
const
closeDelay
=
Number
(
this
.
closeDelay
);
if
(
closeDelay
>
0
)
{
this
.
_closeTimer
=
setTimeout
(()
=>
{
this
.
_closeTimer
=
null
;
this
.
doClose
();
},
closeDelay
);
}
else
{
this
.
doClose
();
}
},
doClose
()
{
this
.
_closing
=
true
;
this
.
onClose
&&
this
.
onClose
();
if
(
this
.
lockScroll
)
{
setTimeout
(
this
.
restoreBodyStyle
,
200
);
}
this
.
opened
=
false
;
this
.
doAfterClose
();
},
doAfterClose
()
{
PopupManager
.
closeModal
(
this
.
_popupId
);
this
.
_closing
=
false
;
},
restoreBodyStyle
()
{
if
(
this
.
modal
&&
this
.
withoutHiddenClass
)
{
document
.
body
.
style
.
paddingRight
=
this
.
bodyPaddingRight
;
removeClass
(
document
.
body
,
'el-popup-parent--hidden'
);
}
this
.
withoutHiddenClass
=
true
;
}
}
};
export
{
PopupManager
};
src/components/Popup/popup-manager.js
0 → 100644
View file @
99c60db1
import
Vue
from
'vue'
;
import
{
addClass
,
removeClass
}
from
'element-ui/src/utils/dom'
;
let
hasModal
=
false
;
let
hasInitZIndex
=
false
;
let
zIndex
=
1010
;
const
getModal
=
function
()
{
if
(
Vue
.
prototype
.
$isServer
)
return
;
let
modalDom
=
PopupManager
.
modalDom
;
if
(
modalDom
)
{
hasModal
=
true
;
}
else
{
hasModal
=
false
;
modalDom
=
document
.
createElement
(
'div'
);
PopupManager
.
modalDom
=
modalDom
;
modalDom
.
addEventListener
(
'touchmove'
,
function
(
event
)
{
event
.
preventDefault
();
event
.
stopPropagation
();
});
modalDom
.
addEventListener
(
'click'
,
function
()
{
PopupManager
.
doOnModalClick
&&
PopupManager
.
doOnModalClick
();
});
}
return
modalDom
;
};
const
instances
=
{};
const
PopupManager
=
{
modalFade
:
true
,
getInstance
:
function
(
id
)
{
return
instances
[
id
];
},
register
:
function
(
id
,
instance
)
{
if
(
id
&&
instance
)
{
instances
[
id
]
=
instance
;
}
},
deregister
:
function
(
id
)
{
if
(
id
)
{
instances
[
id
]
=
null
;
delete
instances
[
id
];
}
},
nextZIndex
:
function
()
{
return
PopupManager
.
zIndex
++
;
},
modalStack
:
[],
doOnModalClick
:
function
()
{
const
topItem
=
PopupManager
.
modalStack
[
PopupManager
.
modalStack
.
length
-
1
];
if
(
!
topItem
)
return
;
const
instance
=
PopupManager
.
getInstance
(
topItem
.
id
);
if
(
instance
&&
instance
.
closeOnClickModal
)
{
instance
.
close
();
}
},
openModal
:
function
(
id
,
zIndex
,
dom
,
modalClass
,
modalFade
)
{
if
(
Vue
.
prototype
.
$isServer
)
return
;
if
(
!
id
||
zIndex
===
undefined
)
return
;
this
.
modalFade
=
modalFade
;
const
modalStack
=
this
.
modalStack
;
for
(
let
i
=
0
,
j
=
modalStack
.
length
;
i
<
j
;
i
++
)
{
const
item
=
modalStack
[
i
];
if
(
item
.
id
===
id
)
{
return
;
}
}
const
modalDom
=
getModal
();
addClass
(
modalDom
,
'v-modal'
);
if
(
this
.
modalFade
&&
!
hasModal
)
{
addClass
(
modalDom
,
'v-modal-enter'
);
}
if
(
modalClass
)
{
let
classArr
=
modalClass
.
trim
().
split
(
/
\s
+/
);
classArr
.
forEach
(
item
=>
addClass
(
modalDom
,
item
));
}
setTimeout
(()
=>
{
removeClass
(
modalDom
,
'v-modal-enter'
);
},
200
);
if
(
dom
&&
dom
.
parentNode
&&
dom
.
parentNode
.
nodeType
!==
11
)
{
dom
.
parentNode
.
appendChild
(
modalDom
);
}
else
{
document
.
body
.
appendChild
(
modalDom
);
}
if
(
zIndex
)
{
modalDom
.
style
.
zIndex
=
zIndex
;
}
modalDom
.
tabIndex
=
0
;
modalDom
.
style
.
display
=
''
;
this
.
modalStack
.
push
({
id
:
id
,
zIndex
:
zIndex
,
modalClass
:
modalClass
});
},
closeModal
:
function
(
id
)
{
const
modalStack
=
this
.
modalStack
;
const
modalDom
=
getModal
();
if
(
modalStack
.
length
>
0
)
{
const
topItem
=
modalStack
[
modalStack
.
length
-
1
];
if
(
topItem
.
id
===
id
)
{
if
(
topItem
.
modalClass
)
{
let
classArr
=
topItem
.
modalClass
.
trim
().
split
(
/
\s
+/
);
classArr
.
forEach
(
item
=>
removeClass
(
modalDom
,
item
));
}
modalStack
.
pop
();
if
(
modalStack
.
length
>
0
)
{
modalDom
.
style
.
zIndex
=
modalStack
[
modalStack
.
length
-
1
].
zIndex
;
}
}
else
{
for
(
let
i
=
modalStack
.
length
-
1
;
i
>=
0
;
i
--
)
{
if
(
modalStack
[
i
].
id
===
id
)
{
modalStack
.
splice
(
i
,
1
);
break
;
}
}
}
}
if
(
modalStack
.
length
===
0
)
{
if
(
this
.
modalFade
)
{
addClass
(
modalDom
,
'v-modal-leave'
);
}
setTimeout
(()
=>
{
if
(
modalStack
.
length
===
0
)
{
if
(
modalDom
.
parentNode
)
modalDom
.
parentNode
.
removeChild
(
modalDom
);
modalDom
.
style
.
display
=
'none'
;
PopupManager
.
modalDom
=
undefined
;
}
removeClass
(
modalDom
,
'v-modal-leave'
);
},
200
);
}
},
};
Object
.
defineProperty
(
PopupManager
,
'zIndex'
,
{
configurable
:
true
,
get
()
{
if
(
!
hasInitZIndex
)
{
zIndex
=
zIndex
;
hasInitZIndex
=
true
;
}
return
zIndex
;
},
set
(
value
)
{
zIndex
=
value
;
},
});
const
getTopPopup
=
function
()
{
if
(
Vue
.
prototype
.
$isServer
)
return
;
if
(
PopupManager
.
modalStack
.
length
>
0
)
{
const
topPopup
=
PopupManager
.
modalStack
[
PopupManager
.
modalStack
.
length
-
1
];
if
(
!
topPopup
)
return
;
const
instance
=
PopupManager
.
getInstance
(
topPopup
.
id
);
return
instance
;
}
};
if
(
!
Vue
.
prototype
.
$isServer
)
{
// handle `esc` key when the popup is shown
window
.
addEventListener
(
'keydown'
,
function
(
event
)
{
if
(
event
.
keyCode
===
27
)
{
const
topPopup
=
getTopPopup
();
if
(
topPopup
&&
topPopup
.
closeOnPressEscape
)
{
topPopup
.
handleClose
?
topPopup
.
handleClose
()
:
topPopup
.
handleAction
?
topPopup
.
handleAction
(
'cancel'
)
:
topPopup
.
close
();
}
}
});
}
export
default
PopupManager
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment