fix(modal): [modal] after a pop-up window whose type is message is closed, the close event instead of the hide event is triggered issue#1384 (#1939)

* fix(modal): [modal] modify issue 1384 bug

* fix(modal): modify e2e-test
This commit is contained in:
James 2024-08-26 01:54:12 -07:00 committed by GitHub
parent 052f84a740
commit ff46d88ca6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 18 deletions

View File

@ -14,7 +14,7 @@ test('事件', async ({ page }) => {
await expect(messageModal.getByText('show 事件触发了')).toBeVisible()
await modal.getByRole('button', { name: '确定' }).click()
await expect(modal).not.toBeVisible()
await expect(messageModal.getByText('hide 事件触发了')).toBeVisible()
await expect(messageModal.getByText('show 事件触发了')).toBeVisible()
// 确认、取消事件
await demo.getByRole('button', { name: '确认、取消事件' }).click()

View File

@ -5,9 +5,22 @@
</template>
<script setup>
import { Button as TinyButton, Modal } from '@opentiny/vue'
import { Button as TinyButton, Modal, Notify } from '@opentiny/vue'
function showModal() {
Modal.message({ message: '右侧显示关闭按钮', status: 'info', messageClosable: true })
Modal.message({
message: '右侧显示关闭按钮',
status: 'info',
messageClosable: true,
events: {
close: () => {
Notify({
type: 'info',
title: '触发close回调事件',
position: 'top-right'
})
}
}
})
}
</script>

View File

@ -13,7 +13,20 @@ export default {
},
methods: {
showModal() {
Modal.message({ message: '右侧显示关闭按钮', status: 'info', messageClosable: true })
Modal.message({
message: '右侧显示关闭按钮',
status: 'info',
messageClosable: true,
events: {
close: () => {
Notify({
type: 'info',
title: '触发close回调事件',
position: 'top-right'
})
}
}
})
}
}
}

View File

@ -370,17 +370,15 @@ export const close =
if (state.visible) {
state.contentVisible = false
setTimeout(() => {
state.visible = false
let params = { type, $modal: parent }
if (events.hide) {
events.hide.call(parent, params)
let params = { type: 'close', $modal: parent }
if (events.close) {
events.close.call(parent, params)
} else {
emit('update:modelValue', false)
emit('hide', params)
emit('close', params)
}
}, 200)
}

View File

@ -30,20 +30,19 @@ export function Modal(options) {
} else {
let events = options.events || {}
let $modal
options.events = Object.assign({}, events, {
hide(params) {
events.hide && events.hide.call(this, params)
if ($modal.beforeUnmouted) {
$modal.beforeUnmouted()
}
resolve(params.type)
},
confirm(params) {
events.confirm && events.confirm.call(this, params)
},
show(params) {
events.show && events.show.call(this, params)
},
close(params) {
events.close && events.close.call(this, params)
if ($modal.beforeUnmouted) {
$modal.beforeUnmouted()
}
resolve(params.type)
}
})