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 5615cff commit 594be79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/components/common/Message/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@
<transition name="message-fade">
<div v-show="visible" :class="['message-box', `message-box--${type}`]">
<slot>
<p v-if="!isHTML" class="message-content">{{ message }}</p>
<p v-else v-html="message" class="message-content"></p>
<p v-if="!isHTML" class="message-content">
{{ $props.content }}
</p>
<p v-else v-html="$props.content" class="message-content"></p>
</slot>
</div>
</transition>
</template>
<script lang="ts" setup>
import { ref, onMounted, onBeforeUnmount, defineProps } from "vue";
import {
ref,
onMounted,
onBeforeUnmount,
defineProps,
getCurrentInstance,
} from "vue";
// 是否可见
const visible = ref(false);
Expand All @@ -21,6 +29,7 @@ const props = defineProps({
validator: (v: string) => {
return ["info", "warn", "error", "success"].includes(v);
},
default: "info",
},
/**
* 弹窗文本内容
Expand Down Expand Up @@ -61,7 +70,7 @@ const onOpen = () => {
onMounted(() => {
onOpen();
console.log("message box onMounted");
console.log("message box onMounted", getCurrentInstance());
});
onBeforeUnmount(() => {
if (typeof props.onClose === "function") {
Expand Down
12 changes: 10 additions & 2 deletions src/components/common/Message/instance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { createApp, getCurrentInstance } from "vue";
import Ins from "./index.vue";
import type { MessageInstance, Options } from "./type";
const Message: MessageInstance = (opt: Options) => {
console.log(opt);
const Message: MessageInstance = (opt?: Options) => {
const cfg = opt || {};
const app = createApp(Ins, { ...cfg });
const dom = document.createElement("div");
dom.className = "happy__message";
const t = app.mount(dom);
};

Message.closeAll = () => {};
Expand All @@ -12,3 +18,5 @@ Message.warn = () => {};
Message.info = () => {};

Message.error = () => {};

export default Message;
3 changes: 2 additions & 1 deletion src/views/home/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts" setup="">
import { defineProps, onMounted, reactive } from "vue";
import { useHead } from "@vueuse/head";
import M from "~/components/common/Message/instance";
import { GetArticles } from "~/api/article";
import ContentLayout from "~/components/layouts/Content/index.vue";
import DefaultLayout from "~/components/layouts/Default/index.vue";
Expand Down Expand Up @@ -39,6 +39,7 @@ const getList = (req: API.ARTICLE.GetArticleListRequest) => {
};
onMounted(async () => {
M();
await getList(props.query ?? {});
});
</script>
Expand Down

0 comments on commit 594be79

Please sign in to comment.