Skip to content

Commit

Permalink
feat(drawer): 增加确认按钮 loading 状态及是否展示取消按钮配置项 (#455) (#467)
Browse files Browse the repository at this point in the history
* fix(drawer): 拖拽时取消浏览器默认行为

* docs(drawer): resizable描述精确化

* docs(drawer): 补充文档案例,自定义头部和页脚

* feat(drawer): 页脚操作体验优化

* feat(drawer): 增加操作按钮loading和是否展示取消的配置项

* feat(drawer): 增加是否显示底部分割线的配置项

* docs(drawer): 抽屉文档描述补充
  • Loading branch information
ocean-gao authored Sep 25, 2023
1 parent f480e13 commit 76a7af1
Show file tree
Hide file tree
Showing 9 changed files with 305 additions and 17 deletions.
30 changes: 26 additions & 4 deletions components/drawer/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ export const drawerProps = {
type: String,
default: '确定',
},
okLoading: Boolean,
cancelText: {
type: String,
default: '取消',
},
showCancel: {
type: Boolean,
default: true,
},
width: {
type: [String, Number] as PropType<string | number>,
default: 520,
Expand All @@ -69,6 +74,10 @@ export const drawerProps = {
type: Boolean,
default: false,
},
footerBorder: {
type: Boolean,
default: false,
},
getContainer: {
type: Function,
},
Expand Down Expand Up @@ -153,16 +162,28 @@ const Drawer = defineComponent({
class="btn-margin"
size="middle"
onClick={handleOk}
loading={props.okLoading}
>
{props.okText}
</FButton>
<FButton size="middle" onClick={handleCancel}>
{props.cancelText}
</FButton>
{props.showCancel && (
<FButton size="middle" onClick={handleCancel}>
{props.cancelText}
</FButton>
)}
</>
);
}
return <div class={`${prefixCls}-footer`}>{footer}</div>;
return (
<div
class={{
[`${prefixCls}-footer`]: true,
[`${prefixCls}-footer-has-border`]: props.footerBorder,
}}
>
{footer}
</div>
);
}

const drawerSize = reactive({
Expand Down Expand Up @@ -267,6 +288,7 @@ const Drawer = defineComponent({
<FScrollbar
class={`${prefixCls}-body-wrapper`}
containerClass={`${prefixCls}-body-container`}
always={true}
>
{ctx.slots.default?.()}
</FScrollbar>
Expand Down
5 changes: 4 additions & 1 deletion components/drawer/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@
}

&-footer {
padding: calc(@padding-md + @padding-xs);
padding: @padding-md calc(@padding-md + @padding-xs);
text-align: left;
.btn-margin {
margin-right: @padding-md;
}
&-has-border {
border-top: var(--f-border-width-base) var(--f-border-style-base) var(--f-border-color-split);
}
}

&-close {
Expand Down
2 changes: 2 additions & 0 deletions components/drawer/useResizable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const useResizable = (config: {
const doResize = (event: MouseEvent) => {
if (!isActive.value) return;

event.preventDefault();

// 偏移量
const offset =
(propsKey === 'width' ? event.clientX : event.clientY) - start;
Expand Down
164 changes: 164 additions & 0 deletions docs/.vitepress/components/drawer/asyncSubmit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<template>
<FForm>
<FFormItem label="是否展示取消按钮:">
<FRadioGroup
v-model="showCancel"
:options="[
{ label: '是(默认)', value: true },
{ label: '否', value: false },
]"
/>
</FFormItem>
<FFormItem label="是否显示底部分割线:">
<FRadioGroup
v-model="showFooterBorder"
:options="[
{ label: '是', value: true },
{ label: '否(默认)', value: false },
]"
/>
</FFormItem>
</FForm>

<FDivider></FDivider>

<FSpace>
<FButton @click="() => (normalShow = true)">常规</FButton>
<FButton @click="() => (customShow = true)">自定义页脚</FButton>
</FSpace>

<FDrawer
v-model:show="normalShow"
title="常规"
displayDirective="if"
:footer="true"
:footerBorder="showFooterBorder"
:okLoading="normalOkLoading"
:okText="normalOkText"
:showCancel="showCancel"
@ok="() => handleNormalOk()"
@cancel="normalShow = false"
>
<div style="height: 1000px">我是内容...</div>
<div>我是内容...</div>
<div>我是内容...</div>
</FDrawer>

<FDrawer
v-model:show="customShow"
displayDirective="if"
:footer="true"
:footerBorder="showFooterBorder"
title="自定义页脚"
>
<div style="height: 1000px">我是内容...</div>
<div>我是内容...</div>
<div>我是内容...</div>
<template #footer>
<FSpace justify="end">
<FButton
v-show="showCancel"
type="warning"
:loading="customCancelLoading"
@click="handleCustomCancel"
>
{{ customCancelText }}
</FButton>
<FButton
type="primary"
:loading="customOkLoading"
@click="handleCustomOk"
>
{{ customOkText }}
</FButton>
</FSpace>
</template>
</FDrawer>
</template>

<script>
import { ref, nextTick } from 'vue';
function sleep(time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
function useDrawer() {
const show = ref(false);
const okLoading = ref(false);
const cancelLoading = ref(false);
const okText = ref('提交更新');
const cancelText = ref('数据还原');
const handleCancel = async () => {
cancelLoading.value = true;
cancelText.value = '3s后自动关闭';
await sleep(3000);
cancelLoading.value = false;
show.value = false;
await nextTick();
cancelText.value = '数据还原';
};
const handleOk = async () => {
okLoading.value = true;
okText.value = '2s后自动关闭';
await sleep(2000);
okLoading.value = false;
show.value = false;
await nextTick();
okText.value = '提交更新';
};
return {
show,
okLoading,
cancelLoading,
handleCancel,
handleOk,
okText,
cancelText,
};
}
export default {
setup() {
const showCancel = ref(true);
const showFooterBorder = ref(true);
const {
show: normalShow,
okLoading: normalOkLoading,
handleOk: handleNormalOk,
okText: normalOkText,
} = useDrawer();
const {
show: customShow,
cancelLoading: customCancelLoading,
okLoading: customOkLoading,
handleCancel: handleCustomCancel,
handleOk: handleCustomOk,
okText: customOkText,
cancelText: customCancelText,
} = useDrawer();
return {
showFooterBorder,
normalShow,
normalOkLoading,
handleNormalOk,
normalOkText,
showCancel,
customShow,
customCancelLoading,
customOkLoading,
handleCustomCancel,
handleCustomOk,
customOkText,
customCancelText,
};
},
};
</script>
17 changes: 9 additions & 8 deletions docs/.vitepress/components/drawer/common.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<FSpace>
<FButton @click="show[0] = true">点我</FButton>
<FButton @click="show[0] = true">常规</FButton>
<FButton class="ml-10" @click="show[1] = true">没有标题</FButton>
<FButton class="ml-10" @click="show[2] = true">不显示关闭</FButton>
<FButton class="ml-10" @click="show[3] = true">没有遮罩</FButton>
<FButton class="ml-10" @click="show[4] = true">显示页脚</FButton>
<FDrawer
v-model:show="show[0]"
title="这里是标题"
title="常规"
displayDirective="if"
@ok="show[0] = false"
>
Expand All @@ -16,14 +16,14 @@
<div>我是内容...</div>
</FDrawer>
<FDrawer v-model:show="show[1]" @ok="show[1] = true">
<div>我是内容...</div>
<div>我是内容...</div>
<div>我是内容...</div>
<div>没有标题...</div>
<div>没有标题...</div>
<div>没有标题...</div>
</FDrawer>

<FDrawer
v-model:show="show[2]"
title="这里是标题"
title="不显示关闭"
:closable="false"
@ok="show[2] = false"
>
Expand All @@ -34,7 +34,7 @@

<FDrawer
v-model:show="show[3]"
title="这里是标题"
title="没有遮罩"
:mask="false"
@ok="show[3] = false"
>
Expand All @@ -44,8 +44,9 @@
</FDrawer>
<FDrawer
v-model:show="show[4]"
title="这里是标题"
title="显示页脚"
:footer="true"
displayDirective="if"
@ok="show[4] = false"
>
<div style="height: 1000px">我是内容...</div>
Expand Down
34 changes: 34 additions & 0 deletions docs/.vitepress/components/drawer/customFooter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<FSpace>
<FButton @click="show = true">自定义页脚</FButton>
<FDrawer
v-model:show="show"
title="这里是标题"
:footer="true"
displayDirective="if"
>
<div style="height: 1000px">我是内容...</div>
<div>我是内容...</div>
<div>我是内容...</div>
<template #footer>
<FSpace justify="end">
<FButton>取消</FButton>
<FButton type="primary">确认</FButton>
</FSpace>
</template>
</FDrawer>
</FSpace>
</template>

<script>
import { ref } from 'vue';
export default {
setup() {
const show = ref(false);
return {
show,
};
},
};
</script>
41 changes: 41 additions & 0 deletions docs/.vitepress/components/drawer/customTitle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<template>
<FSpace>
<FButton @click="show = true">自定义头部</FButton>
<FDrawer v-model:show="show" title="这里是标题" @ok="show = false">
<template #title>
<div class="header">
<span style="margin-right: 8px">自定义头部标题</span>
<EditOutlined />
</div>
</template>
<div>我是内容...</div>
<div>我是内容...</div>
<div>我是内容...</div>
</FDrawer>
</FSpace>
</template>

<script>
import { ref } from 'vue';
import { EditOutlined } from '@fesjs/fes-design/icon';
export default {
components: {
EditOutlined,
},
setup() {
const show = ref(false);
return {
show,
};
},
};
</script>

<style scoped>
.header {
display: flex;
flex-direction: row;
align-items: center;
}
</style>
Loading

0 comments on commit 76a7af1

Please sign in to comment.