Skip to content

Commit

Permalink
docs: 更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyh2001 committed Aug 15, 2023
1 parent 5056076 commit 0d41fb6
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
English | [Chinese](https://github.com/FightingDesign/fighting-design/blob/master/CHANGELOG.md)

## 0.61.0 (2023-08-15)

- Optimize component styles for `f-drawer` and `f-dialog`
- Optimize style details for `f-radio` and `f-checkbox`
- Refactoring `f-tree` components
- Add a `f-confirm-box` component

## 0.60.0 (2023-08-04)

- Optimize the `f-radio` component styles
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

中文 | [英文](https://github.com/FightingDesign/fighting-design/blob/master/CHANGELOG.en-US.md)

## 0.61.0 (2023-08-15)

- 优化 `f-drawer` `f-dialog` 组件样式
- 优化 `f-radio``f-checkbox` 样式细节
- 重构 `f-tree` 组件
- 新增 `f-confirm-box` 组件

## 0.60.0 (2023-08-04)

Expand Down
3 changes: 2 additions & 1 deletion docs/.vitepress/config/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export const sidebar = {
{ text: 'Dialog 对话框', link: '/components/dialog' },
{ text: 'Drawer 抽屉', link: '/components/drawer' },
{ text: 'Tooltip 消息提示', link: '/components/tooltip' },
{ text: 'Swap 切换', link: '/components/swap' }
{ text: 'Swap 切换', link: '/components/swap' },
{ text: 'Confirm Box 确认框', link: '/components/confirm-box' }
]
},
{
Expand Down
7 changes: 6 additions & 1 deletion docs/.vitepress/json/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@
"title": "Avatar Group 头像组",
"rule": "avatar-groupAvatarGroup头像组",
"url": "components/avatar-group"
},
{
"title": "Confirm Box 确认框",
"rule": "confirm-boxConfirmBox确认框",
"url": "components/confirm-box"
}
]
}
}
167 changes: 167 additions & 0 deletions docs/components/confirm-box.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Confirm Box 确认框

操作之前加点料?

- [源代码](https://github.com/FightingDesign/fighting-design/tree/master/packages/fighting-design/confirm-box)
- [文档编辑](https://github.com/FightingDesign/fighting-design/blob/master/docs/components/confirm-box.md)

## 使用前

使用前,你需要先引入:

```ts
import { FConfirmBox } from 'fighting-design'
```

## 基本使用

传递一个配置对象,可打开确认框

`title``content` 配置标题和提示的内容信息

`on-confirm``on-cancel` 分别处理点击确定和点击取消的回调方法

::: demo

<template #source>
<f-button :on-click="open1">提示</f-button>
</template>

```html
<template>
<f-button :on-click="open1">提示</f-button>
</template>

<script lang="ts" setup>
import { FConfirmBox, FMessage } from 'fighting-design'
const open1 = (): void => {
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: () => {
FMessage.success('点击了确定')
},
onCancel: () => {
FMessage.danger('点击了取消')
}
})
}
</script>
```

:::

## 异步调用

`on-confirm``on-cancel` 可传入一个异步方法或者 `Promise`,那么会等待方法响应之后再关闭

在未响应期间,按钮和关闭按钮处于禁用状态

::: demo

<template #source>
<f-button :on-click="open2">提示</f-button>
</template>

```html
<template>
<f-button :on-click="open2">提示</f-button>
</template>

<script lang="ts" setup>
import { FConfirmBox, FMessage } from 'fighting-design'
const getDate = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ code: 200, res: [1, 2, 3] })
}, 2000)
})
}
const open2 = (): void => {
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: async () => {
await getDate()
FMessage.success('点击了确定')
},
onCancel: () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
FMessage.danger('点击了取消')
resolve('123')
}, 2000)
})
}
})
}
</script>
```

:::

## Attributes

| 参数 | 说明 | 类型 | 可选值 | 默认值 |
| -------------- | ---------------------- | ------------------------------------------------------------------ | ------ | ------ |
| `title` | 标题 | string | —— | —— |
| `content` | 提示内容 | string | —— | —— |
| `confirm-text` | 确认按钮文字 | string / number | —— | —— |
| `cancel-text` | 取消按钮文字 | string / number | —— | —— |
| `on-confirm` | 点击确定执行的回调方法 | <a href="/components/interface.html#handlemouse">HandleMouse</a> | —— | —— |
| `on-cancel` | 点击取消执行的回调方法 | <a href="/components/interface.html#handlemouse">HandleMouse</a> | —— | —— |
| `on-open` | 开启之后执行的回调方法 | <a href="/components/interface.html#handlechange">HandleChange</a> | —— | —— |
| `on-close` | 关闭之后执行的回调方法 | <a href="/components/interface.html#handlechange">HandleChange</a> | —— | —— |

## Contributors

<a href="https://github.com/Tyh2001" target="_blank">
<f-avatar round src="https://avatars.githubusercontent.com/u/73180970?v=4" />
</a>

<script setup lang="ts">
import { FConfirmBox, FMessage } from 'fighting-design'

const open1 = (): void => {
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: () => {
FMessage.success('点击了确定')
},
onCancel: () => {
FMessage.danger('点击了取消')
}
})
}

const getDate = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ code: 200, res: [1, 2, 3] })
}, 2000)
})
}

const open2 = (): void => {
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: async () => {
await getDate()
FMessage.success('点击了确定')
},
onCancel: () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
FMessage.danger('点击了取消')
resolve('123')
}, 2000)
})
}
})
}
</script>
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { FConfirmBox } from '../index'

describe('ConfirmBox', () => {
test('class', () => {
const wrapper = mount(FConfirmBox)
expect(wrapper.classes()).toContain('f-confirm-box')
expect(1 + 1).toBe(2)
})
})
16 changes: 8 additions & 8 deletions packages/fighting-design/confirm-box/src/confirm-box.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
const isLoading = ref(false)
/** 关闭确认框 */
const handelClose = (): void => {
const handleClose = (): void => {
isShow.value = false
}
Expand All @@ -38,29 +38,29 @@
*
* @param { Object } evt 事件对象
*/
const handelConfirm = async (evt: MouseEvent): Promise<void> => {
const handleConfirm = async (evt: MouseEvent): Promise<void> => {
isLoading.value = true
if (isFunction(prop.onConfirm)) {
await prop.onConfirm(evt)
}
handelClose()
handleClose()
}
/**
* 点击取消执行的回调方法
*
* @param { Object } evt 事件对象
*/
const handelCancel = async (evt: MouseEvent): Promise<void> => {
const handleCancel = async (evt: MouseEvent): Promise<void> => {
isLoading.value = true
if (isFunction(prop.onCancel)) {
await prop.onCancel(evt)
}
handelClose()
handleClose()
}
</script>

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

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

<!-- 身体 -->
Expand All @@ -91,10 +91,10 @@
<!-- 底部 -->
<div class="f-confirm-box__footer">
<f-space>
<f-button :loading="isLoading" :on-click="handelCancel">
<f-button :loading="isLoading" :on-click="handleCancel">
{{ cancelText || '取消' }}
</f-button>
<f-button :loading="isLoading" type="primary" :on-click="handelConfirm">
<f-button :loading="isLoading" type="primary" :on-click="handleConfirm">
{{ confirmText || '确定' }}
</f-button>
</f-space>
Expand Down
22 changes: 2 additions & 20 deletions start/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<script lang="ts" setup>
import { FConfirmBox } from 'fighting-design'
<script lang="ts" setup></script>

const open = (): void => {
FConfirmBox({
title: '标题',
content: '这是内容',
onConfirm: () => {
return new Promise(res => {
setTimeout(() => {
res('123')
}, 2000)
})
}
})
}
</script>

<template>
<f-button :on-click="open">提示</f-button>
</template>
<template></template>

0 comments on commit 0d41fb6

Please sign in to comment.