mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-18 12:34:25 +08:00
refactor(confirm): support modal transform origin
This commit is contained in:
parent
96fd16957c
commit
a8d62d0296
@ -27,13 +27,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleConfirm () {
|
handleConfirm (e) {
|
||||||
const confirmInstance = this.$NModal.confirm({
|
const confirmInstance = this.$NModal.confirm({
|
||||||
title: 'Confirm',
|
title: 'Confirm',
|
||||||
content: 'Are u sure to ...?',
|
content: 'Are u sure to ...?',
|
||||||
okText: 'Yes', // 自定义ok按钮文字 error和success也可以使用
|
okText: 'Yes', // 自定义ok按钮文字 error和success也可以使用
|
||||||
cancelText: 'No', // 自定义取消按钮文字
|
cancelText: 'No', // 自定义取消按钮文字
|
||||||
|
activateEvent: e,
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
console.log('click on ok', confirmInstance)
|
console.log('click on ok', confirmInstance)
|
||||||
this.$NMessage.info('will be ok in 3 seconds')
|
this.$NMessage.info('will be ok in 3 seconds')
|
||||||
|
@ -33,13 +33,13 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleConfirm () {
|
handleConfirm (e) {
|
||||||
const confirmInstance = this.$NModal.confirm({
|
const confirmInstance = this.$NModal.confirm({
|
||||||
title: 'Confirm',
|
title: 'Confirm',
|
||||||
content: '<b>Are u sure to ...?',
|
content: '<b>Are u sure to ...?',
|
||||||
|
activateEvent: e,
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
console.log('click on ok', confirmInstance)
|
console.log('click on ok', confirmInstance)
|
||||||
|
|
||||||
this.$NMessage.success('sure')
|
this.$NMessage.success('sure')
|
||||||
},
|
},
|
||||||
onCancel: () => {
|
onCancel: () => {
|
||||||
@ -47,10 +47,11 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleSuccess () {
|
handleSuccess (e) {
|
||||||
const confirmInstance = this.$NModal.success({
|
const confirmInstance = this.$NModal.success({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
content: 'Premium designed icons for use in web, iOS, Android, and desktop apps. Support for SVG and web font. Completely open source, MIT licensed and built by the Ionic Framework team.',
|
content: 'Premium designed icons for use in web, iOS, Android, and desktop apps. Support for SVG and web font. Completely open source, MIT licensed and built by the Ionic Framework team.',
|
||||||
|
activateEvent: e,
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
console.log('click on ok', confirmInstance)
|
console.log('click on ok', confirmInstance)
|
||||||
|
|
||||||
@ -58,13 +59,13 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleError () {
|
handleError (e) {
|
||||||
const confirmInstance = this.$NModal.error({
|
const confirmInstance = this.$NModal.error({
|
||||||
title: 'Error',
|
title: 'Error',
|
||||||
content: '<b>这是一个测试?</b>hhahhaahahhahahsdiusah ashdusadu asdsadsadsadsadsa',
|
content: '<b>这是一个测试?</b>hhahhaahahhahahsdiusah ashdusadu asdsadsadsadsadsa',
|
||||||
|
activateEvent: e,
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
console.log('click on ok', confirmInstance)
|
console.log('click on ok', confirmInstance)
|
||||||
|
|
||||||
this.$NMessage.success('I know..')
|
this.$NMessage.success('I know..')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<n-modal
|
<n-modal
|
||||||
v-model="isActive"
|
v-model="isActive"
|
||||||
|
:activate-event="activateEvent"
|
||||||
@toggle="toggle"
|
@toggle="toggle"
|
||||||
>
|
>
|
||||||
<!-- <transition name="n-modal-content--transition"> -->
|
<!-- <transition name="n-modal-content--transition"> -->
|
||||||
@ -16,7 +17,6 @@
|
|||||||
/>
|
/>
|
||||||
{{ title }}
|
{{ title }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<n-icon
|
<n-icon
|
||||||
type="md-close"
|
type="md-close"
|
||||||
size="22"
|
size="22"
|
||||||
@ -74,6 +74,7 @@ export default {
|
|||||||
type: 'error',
|
type: 'error',
|
||||||
title: 'title',
|
title: 'title',
|
||||||
loading: null,
|
loading: null,
|
||||||
|
activateEvent: null,
|
||||||
onCancel: () => {},
|
onCancel: () => {},
|
||||||
onOk: () => {}
|
onOk: () => {}
|
||||||
}
|
}
|
||||||
@ -111,15 +112,6 @@ export default {
|
|||||||
this.onOk()
|
this.onOk()
|
||||||
if (this.loading !== true) { this.isActive = false }
|
if (this.loading !== true) { this.isActive = false }
|
||||||
}
|
}
|
||||||
// updateData (data) {
|
|
||||||
// Object.keys(data).forEach((key) => {
|
|
||||||
// this[key] = data[key]
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import NScrollbar from '../../Scrollbar'
|
import NScrollbar from '../../Scrollbar'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
NScrollbar
|
NScrollbar
|
||||||
@ -35,6 +36,12 @@ export default {
|
|||||||
active: {
|
active: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
activateEvent: {
|
||||||
|
validator (e) {
|
||||||
|
return e instanceof MouseEvent
|
||||||
|
},
|
||||||
|
default: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
@ -67,21 +74,40 @@ export default {
|
|||||||
// console.log('afterEnter', this.$refs.scrollbar.enableScrollbar())
|
// console.log('afterEnter', this.$refs.scrollbar.enableScrollbar())
|
||||||
},
|
},
|
||||||
updateTransformOrigin () {
|
updateTransformOrigin () {
|
||||||
|
if (
|
||||||
|
(!this.$parent.$refs.activator ||
|
||||||
|
!this.$parent.$refs.activator.childElementCount) &&
|
||||||
|
!this.activateEvent
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const scrollTop = this.$refs.scrollbar.containerScrollTop
|
const scrollTop = this.$refs.scrollbar.containerScrollTop
|
||||||
console.log(scrollTop)
|
|
||||||
const {
|
const {
|
||||||
offsetLeft,
|
offsetLeft,
|
||||||
offsetTop
|
offsetTop
|
||||||
} = this.$refs.contentInner
|
} = this.$refs.contentInner
|
||||||
const {
|
if (
|
||||||
left: activatorLeft,
|
this.$parent.$refs.activator &&
|
||||||
top: activatorTop,
|
this.$parent.$refs.activator.childElementCount
|
||||||
width: activatorWidth
|
) {
|
||||||
} = this.$parent.$refs.activator.getBoundingClientRect()
|
const {
|
||||||
const transformOriginX = -(offsetLeft - activatorLeft - activatorWidth / 2)
|
left: activatorLeft,
|
||||||
const transformOriginY = -(offsetTop - activatorTop - scrollTop - activatorTop / 2)
|
top: activatorTop,
|
||||||
this.$refs.contentInner.style.transformOrigin = `${transformOriginX}px ${transformOriginY}px`
|
width: activatorWidth,
|
||||||
console.log(this.$refs.contentInner.style.transformOrigin)
|
height: activatorHeight
|
||||||
|
} = this.$parent.$refs.activator.getBoundingClientRect()
|
||||||
|
const transformOriginX = -(offsetLeft - activatorLeft - activatorWidth / 2)
|
||||||
|
const transformOriginY = -(offsetTop - activatorTop - scrollTop - activatorHeight / 2)
|
||||||
|
this.$refs.contentInner.style.transformOrigin = `${transformOriginX}px ${transformOriginY}px`
|
||||||
|
} else {
|
||||||
|
const activatorTop = this.activateEvent.clientY
|
||||||
|
const activatorLeft = this.activateEvent.clientX
|
||||||
|
const activatorWidth = 0
|
||||||
|
const activatorHeight = 0
|
||||||
|
const transformOriginX = -(offsetLeft - activatorLeft - activatorWidth / 2)
|
||||||
|
const transformOriginY = -(offsetTop - activatorTop - scrollTop - activatorHeight / 2)
|
||||||
|
this.$refs.contentInner.style.transformOrigin = `${transformOriginX}px ${transformOriginY}px`
|
||||||
|
}
|
||||||
},
|
},
|
||||||
handleBeforeLeave () {
|
handleBeforeLeave () {
|
||||||
this.updateTransformOrigin()
|
this.updateTransformOrigin()
|
||||||
@ -127,6 +153,6 @@ export default {
|
|||||||
|
|
||||||
.n-modal-content--transition-enter, .n-modal-content--transition-leave-to {
|
.n-modal-content--transition-enter, .n-modal-content--transition-leave-to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: scale(.75);
|
transform: scale(.5);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -13,6 +13,14 @@ export default {
|
|||||||
detachable,
|
detachable,
|
||||||
zindexable
|
zindexable
|
||||||
],
|
],
|
||||||
|
props: {
|
||||||
|
activateEvent: {
|
||||||
|
validator (e) {
|
||||||
|
return e instanceof MouseEvent
|
||||||
|
},
|
||||||
|
default: null
|
||||||
|
}
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
mousedownTarget: null
|
mousedownTarget: null
|
||||||
@ -38,7 +46,7 @@ export default {
|
|||||||
h(NModalContent,
|
h(NModalContent,
|
||||||
{
|
{
|
||||||
ref: 'content',
|
ref: 'content',
|
||||||
props: { active: this.active },
|
props: { active: this.active, activateEvent: this.activateEvent },
|
||||||
on: {
|
on: {
|
||||||
mousedown: (e) => {
|
mousedown: (e) => {
|
||||||
this.mousedownTarget = e.target
|
this.mousedownTarget = e.target
|
||||||
|
20
packages/utils/traceClickEvent.js
Normal file
20
packages/utils/traceClickEvent.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* This file is currently of no use
|
||||||
|
*/
|
||||||
|
|
||||||
|
let memorizedClickEvent = null
|
||||||
|
|
||||||
|
class ClickTracer {
|
||||||
|
constructor () {
|
||||||
|
window.removeEventListener('click', ClickTracer.traceClickEvent, true)
|
||||||
|
window.addEventListener('click', ClickTracer.traceClickEvent, true)
|
||||||
|
}
|
||||||
|
static traceClickEvent (e) {
|
||||||
|
memorizedClickEvent = e
|
||||||
|
}
|
||||||
|
get memorizedClickEvent () {
|
||||||
|
return memorizedClickEvent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new ClickTracer()
|
Loading…
Reference in New Issue
Block a user