Skip to content

Commit

Permalink
feat: 完善确认框组件
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Aug 15, 2023
1 parent 44436bf commit 6f239a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 20 deletions.
41 changes: 38 additions & 3 deletions packages/fighting-design/confirm-box/src/confirm-box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { FCloseBtn } from '../../close-btn'
import { ref } from 'vue'
import { useRun } from '../../_hooks'
import { isFunction } from '../../_utils'
defineOptions({ name: 'FConfirmBox' })
Expand All @@ -14,6 +15,8 @@
/** 是否展示确认框 */
const isShow = ref(prop.show)
/** button loading */
const isLoading = ref(false)
/** 关闭确认框 */
const handelClose = (): void => {
Expand All @@ -29,6 +32,36 @@
const handleCloseEnd = (): void => {
run(prop.onClose, isShow.value)
}
/**
* 点击确认执行的回调方法
*
* @param { Object } evt 事件对象
*/
const handelConfirm = async (evt: MouseEvent): Promise<void> => {
isLoading.value = true
if (isFunction(prop.onConfirm)) {
await prop.onConfirm(evt)
}
handelClose()
}
/**
* 点击取消执行的回调方法
*
* @param { Object } evt 事件对象
*/
const handelCancel = async (evt: MouseEvent): Promise<void> => {
isLoading.value = true
if (isFunction(prop.onCancel)) {
await prop.onCancel(evt)
}
handelClose()
}
</script>

<template>
Expand All @@ -49,7 +82,7 @@
<div class="f-confirm-box__header">
<div class="f-confirm-box__title">{{ title }}</div>

<f-close-btn :on-click="handelClose" />
<f-close-btn :disabled="isLoading" :on-click="handelClose" />
</div>

<!-- 身体 -->
Expand All @@ -58,8 +91,10 @@
<!-- 底部 -->
<div class="f-confirm-box__footer">
<f-space>
<f-button :on-click="onCancel">取消</f-button>
<f-button type="primary" :on-click="onConfirm">确定</f-button>
<f-button :loading="isLoading" :on-click="handelCancel">取消</f-button>
<f-button :loading="isLoading" type="primary" :on-click="handelConfirm">
确定
</f-button>
</f-space>
</div>
</div>
Expand Down
22 changes: 5 additions & 17 deletions start/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
<script lang="ts" setup>
import { FConfirmBox } from 'fighting-design'
import { ref } from 'vue'
import Box from '../../packages/fighting-design/confirm-box/src/confirm-box.vue'
const show = ref(false)
const open = (): void => {
// show.value = true
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: () => {
console.log('点击确定')
},
onCancel: () => {
console.log('点击了取消')
},
onClose: () => {
console.log('关闭了')
},
onOpen: () => {
console.log('开启了')
return new Promise(res => {
setTimeout(() => {
res('123')
}, 2000)
})
}
})
}
</script>

<template>
<!-- <box :show="show" title="123" /> -->
<f-button :on-click="open">提示</f-button>
</template>

0 comments on commit 6f239a9

Please sign in to comment.