|
|
@@ -1,13 +1,18 @@
|
|
|
<template>
|
|
|
- <!-- <view class="nut-notify"> -->
|
|
|
<Transition name="toast-fade">
|
|
|
<view
|
|
|
- :class="toastBodyClass"
|
|
|
- v-show="state.mounted"
|
|
|
+ :class="[
|
|
|
+ 'popup-top',
|
|
|
+ 'round',
|
|
|
+ 'nut-notify',
|
|
|
+ `nut-notify--${type}`,
|
|
|
+ { className }
|
|
|
+ ]"
|
|
|
:style="{
|
|
|
bottom: center ? 'auto' : bottom + 'px',
|
|
|
'background-color': coverColor
|
|
|
}"
|
|
|
+ v-show="state.mounted"
|
|
|
@click="clickCover"
|
|
|
>
|
|
|
<template v-if="$slots.default">
|
|
|
@@ -19,31 +24,70 @@
|
|
|
<!-- </view> -->
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
-import { toRefs, reactive, onMounted } from 'vue';
|
|
|
+import { toRefs, reactive, onMounted, watch } from 'vue';
|
|
|
import { createComponent } from '@/utils/create';
|
|
|
import Popup from '@/packages/popup/index.vue';
|
|
|
const { componentName, create } = createComponent('notify');
|
|
|
|
|
|
export default create({
|
|
|
props: {
|
|
|
- color: String,
|
|
|
- message: [Number, String],
|
|
|
- className: null,
|
|
|
- background: String,
|
|
|
+ color: { type: String, default: '' },
|
|
|
+ msg: { type: Number, default: '' },
|
|
|
+ duration: { type: Number, default: 3000 },
|
|
|
+ className: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ background: { type: String, default: '' },
|
|
|
type: {
|
|
|
type: String,
|
|
|
default: 'danger'
|
|
|
+ },
|
|
|
+ showPopup: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
}
|
|
|
},
|
|
|
|
|
|
setup(props, { slots }) {
|
|
|
+ let timer;
|
|
|
const state = reactive({
|
|
|
mounted: false
|
|
|
});
|
|
|
onMounted(() => {
|
|
|
state.mounted = true;
|
|
|
});
|
|
|
- return { state };
|
|
|
+ const clearTimer = () => {
|
|
|
+ if (timer) {
|
|
|
+ clearTimeout(timer);
|
|
|
+ timer = null;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ const hide = () => {
|
|
|
+ state.mounted = false;
|
|
|
+ };
|
|
|
+ const show = () => {
|
|
|
+ clearTimer();
|
|
|
+ if (props.duration) {
|
|
|
+ timer = setTimeout(() => {
|
|
|
+ hide();
|
|
|
+ }, props.duration);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if (props.duration) {
|
|
|
+ show();
|
|
|
+ }
|
|
|
+
|
|
|
+ watch(
|
|
|
+ () => props.duration,
|
|
|
+ val => {
|
|
|
+ if (val) {
|
|
|
+ show();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return { state, hide };
|
|
|
}
|
|
|
});
|
|
|
</script>
|