Skip to content

Commit

Permalink
feat: add close
Browse files Browse the repository at this point in the history
  • Loading branch information
unliar committed Jul 8, 2021
1 parent f4d40ce commit 9d96828
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
37 changes: 35 additions & 2 deletions src/components/common/Message/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const props = defineProps({
*/
duration: {
type: Number,
default: 3, //
default: 30, //
validator: (v: number) => {
return +v > 0;
},
Expand Down Expand Up @@ -80,4 +80,37 @@ onBeforeUnmount(() => {
});
</script>

<style scoped></style>
<style scoped>
.message-box {
position: fixed;
left: 50%;
top: 20px;
transform: translateX(-50%);
transition: opacity 0.3s, transform 0.4s, top 0.4s;
overflow: hidden;
display: flex;
align-items: center;
background: #909399;
}
p {
margin: 0;
}
.message-box--info {
background: #909399;
}
.message-box--warn {
background: #f6a23c;
}
.message-box--error {
background: #f56c6c;
}
.message-box--success {
background: #67c23a;
}
.message-fade-enter-from,
.message-fade-leave-to {
opacity: 0;
transform: translate(-50%, -100%);
}
</style>
7 changes: 6 additions & 1 deletion src/components/common/Message/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import Ins from "./index.vue";
import type { MessageInstance, Options } from "./type";
const Message: MessageInstance = (opt?: Options) => {
const cfg = opt || {};
const ContainerClassName = "happy__message";
const c = document.querySelector(`.${ContainerClassName}`);
if (c) {
document.body.removeChild(c);
}
const vm = createVNode(Ins, { ...cfg });
const container = document.createElement("div");
container.className = "happy__message";
container.className = ContainerClassName;
render(vm, container);
document.body.appendChild(container);
};
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/Message/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export type Options = {
content: string; // 文字类型
isHTML?: boolean; // 是否是html
duration?: number; // 显示时长
onClose: () => void; // 关闭时的调用
onClose?: () => void; // 关闭时的调用
type?: MessageType;
};
5 changes: 4 additions & 1 deletion src/views/home/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ const getList = (req: API.ARTICLE.GetArticleListRequest) => {
};
onMounted(async () => {
M();
M({
content: "222",
type: "error",
});
await getList(props.query ?? {});
});
</script>
Expand Down

0 comments on commit 9d96828

Please sign in to comment.