Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dialog.notify修改 #764

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 97 additions & 98 deletions example/routers/dialog.vue
Original file line number Diff line number Diff line change
@@ -1,113 +1,112 @@
<template>
<yd-layout title="Dialog">
<yd-layout title="Dialog">
<yd-button-group>
<yd-button @click.native="openConfrim" size="large">Confirm</yd-button>

<yd-button-group>
<yd-button @click.native="openCustomConfrim" size="large">Confirm->Custom</yd-button>

<yd-button @click.native="openConfrim" size="large">Confirm</yd-button>
<yd-button @click.native="openAlert" size="large" type="hollow">Alert</yd-button>

<yd-button @click.native="openCustomConfrim" size="large">Confirm->Custom</yd-button>
<yd-button @click.native="toastSuccess" size="large" type="danger">Toast->Success</yd-button>

<yd-button @click.native="openAlert" size="large" type="hollow">Alert</yd-button>
<yd-button @click.native="toastError" size="large" type="danger">Toast->Error</yd-button>

<yd-button @click.native="toastSuccess" size="large" type="danger">Toast->Success</yd-button>
<yd-button @click.native="toastNone" size="large" type="danger">Toast->None</yd-button>

<yd-button @click.native="toastError" size="large" type="danger">Toast->Error</yd-button>
<yd-button @click.native="openLoading" size="large" type="hollow">Loading</yd-button>

<yd-button @click.native="toastNone" size="large" type="danger">Toast->None</yd-button>

<yd-button @click.native="openLoading" size="large" type="hollow">Loading</yd-button>

<yd-button @click.native="openNotify" size="large" type="hollow">Notify</yd-button>

</yd-button-group>

</yd-layout>
<yd-button @click.native="openNotify" size="large" type="hollow">Notify</yd-button>
</yd-button-group>
</yd-layout>
</template>

<script type="text/babel">
export default {
methods: {
openConfrim() {
this.$dialog.confirm({
title: '选填标题',
mes: '我有一个小毛驴我从来也不骑!',
opts: () => {
this.$dialog.toast({mes: '你点了确定', timeout: 1000});
}
});
},
openCustomConfrim() {
this.$dialog.confirm({
title: '选填标题',
mes: '我有一个小毛驴我从来也不骑!',
opts: [
{
txt: '取消',
color: false,
callback: () => {
this.$dialog.toast({mes: '你点了取消', timeout: 1000});
}
},
{
txt: '犹豫一下',
stay: true,
color: '#CCC',
callback: () => {
this.$dialog.toast({mes: '别犹豫了', timeout: 1000});
}
},
{
txt: '确定',
color: true,
callback: () => {
this.$dialog.toast({mes: '你点了确定', timeout: 1000});
}
}
]
});
},
openAlert() {
this.$dialog.alert({mes: '消息一出,休想滚动屏幕[移动终端]!'});
},
toastSuccess() {
this.$dialog.toast({
mes: '保存成功',
timeout: 1500,
icon: 'success'
});
},
toastError() {
this.$dialog.toast({
mes: '保存失败',
timeout: 1500,
icon: 'error',
callback: () => {
this.$dialog.alert({mes: '给你一次重来的机会!'});
}
});
},
toastNone() {
this.$dialog.toast({
mes: '一个没有任何图标的提示!',
timeout: 1500
});
},
openLoading() {
this.$dialog.loading.open('很快加载好了');

setTimeout(() => {
this.$dialog.loading.close();
}, 2000);
},
openNotify() {
this.$dialog.notify({
mes: '5秒后自动消失,点我也可以消失!',
timeout: 5000,
callback: () => {
console.log('我走咯!');
}
});
export default {
methods: {
openConfrim() {
this.$dialog.confirm({
title: "选填标题",
mes: "我有一个小毛驴我从来也不骑!",
opts: () => {
this.$dialog.toast({ mes: "你点了确定", timeout: 1000 });
}
});
},
openCustomConfrim() {
this.$dialog.confirm({
title: "选填标题",
mes: "我有一个小毛驴我从来也不骑!",
opts: [
{
txt: "取消",
color: false,
callback: () => {
this.$dialog.toast({ mes: "你点了取消", timeout: 1000 });
}
},
{
txt: "犹豫一下",
stay: true,
color: "#CCC",
callback: () => {
this.$dialog.toast({ mes: "别犹豫了", timeout: 1000 });
}
},
{
txt: "确定",
color: true,
callback: () => {
this.$dialog.toast({ mes: "你点了确定", timeout: 1000 });
}
}
]
});
},
openAlert() {
this.$dialog.alert({ mes: "消息一出,休想滚动屏幕[移动终端]!" });
},
toastSuccess() {
this.$dialog.toast({
mes: "保存成功",
timeout: 1500,
icon: "success"
});
},
toastError() {
this.$dialog.toast({
mes: "保存失败",
timeout: 1500,
icon: "error",
callback: () => {
this.$dialog.alert({ mes: "给你一次重来的机会!" });
}
});
},
toastNone() {
this.$dialog.toast({
mes: "一个没有任何图标的提示!",
timeout: 1500
});
},
openLoading() {
this.$dialog.loading.open("很快加载好了");

setTimeout(() => {
this.$dialog.loading.close();
}, 2000);
},
openNotify() {
this.$dialog.notify({
mes: "5秒后自动消失,点我也可以消失!",
timeout: 5000,
clickCallback: () => {
console.log("我被点了,我要走!");
},
callback: () => {
console.log("我走咯!");
}
});
}
}
};
</script>
19 changes: 14 additions & 5 deletions src/components/dialog/src/notify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ const instance = new NotifyConstructor({
el: document.createElement('div')
});

const notifyClicked = function () {
clearTimeout(timer);
instance.clickNotify();
}

let timer = null;
let lock = false;

Expand All @@ -14,28 +19,32 @@ NotifyConstructor.prototype.closeNotify = function () {

setTimeout(() => {
const el = instance.$el;
el.removeEventListener("click", notifyClicked);
el.parentNode && el.parentNode.removeChild(el);
lock = false;
}, 150);

typeof this.callback === 'function' && this.callback();
};

NotifyConstructor.prototype.clickNotify = function () {
typeof this.clickCallback === 'function' && this.clickCallback();
instance.closeNotify();
};

const Notify = (options = {}) => {
instance.classes = '';
instance.mes = options.mes;
instance.timeout = ~~options.timeout || 5000;
instance.callback = options.callback;
instance.clickCallback = options.clickCallback;

if (lock)return;
if (lock) return;
lock = true;

document.body.appendChild(instance.$el);

instance.$el.addEventListener('click', () => {
clearTimeout(timer);
instance.closeNotify();
});
instance.$el.addEventListener('click', notifyClicked);

timer = setTimeout(() => {
clearTimeout(timer);
Expand Down
3 changes: 2 additions & 1 deletion src/components/dialog/src/notify/notify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
props: {
mes: String,
timeout: Number,
callback: Function
callback: Function,
clickCallback: Function
}
}
</script>