uni-popup-message.vue 2.7 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2
<template>
	<view class="uni-popup-message">
3 4 5
		<view class="uni-popup-message__box fixforpc-width" :class="'uni-popup__'+type">
			<slot>
				<text class="uni-popup-message-text" :class="'uni-popup__'+type+'-text'">{{message}}</text>
DCloud_JSON's avatar
DCloud_JSON 已提交
6 7 8 9 10
			</slot>
		</view>
	</view>
</template>

11
<script>
DCloud_JSON's avatar
DCloud_JSON 已提交
12 13 14 15 16 17 18 19 20 21 22 23
	import popup from '../uni-popup/popup.js'
	/**
	 * PopUp 弹出层-消息提示
	 * @description 弹出层-消息提示
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=329
	 * @property {String} type = [success|warning|info|error] 主题样式
	 *  @value success 成功
	 * 	@value warning 提示
	 * 	@value info 消息
	 * 	@value error 错误
	 * @property {String} message 消息提示文字
	 * @property {String} duration 显示时间,设置为 0 则不会自动关闭
24
	 */
DCloud_JSON's avatar
DCloud_JSON 已提交
25 26

	export default {
27
		name: 'uniPopupMessage',
DCloud_JSON's avatar
DCloud_JSON 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
		mixins:[popup],
		props: {
			/**
			 * 主题 success/warning/info/error	  默认 success
			 */
			type: {
				type: String,
				default: 'success'
			},
			/**
			 * 消息文字
			 */
			message: {
				type: String,
				default: ''
			},
			/**
			 * 显示时间,设置为 0 则不会自动关闭
			 */
			duration: {
				type: Number,
				default: 3000
50 51 52 53
			},
			maskShow:{
				type:Boolean,
				default:false
DCloud_JSON's avatar
DCloud_JSON 已提交
54 55 56 57
			}
		},
		data() {
			return {}
58 59 60 61
		},
		created() {
			this.popup.maskShow = this.maskShow
			this.popup.messageChild = this
DCloud_JSON's avatar
DCloud_JSON 已提交
62 63
		},
		methods: {
64 65 66 67 68 69
			timerClose(){
				if(this.duration === 0) return
				clearTimeout(this.timer) 
				this.timer = setTimeout(()=>{
					this.popup.close()
				},this.duration)
DCloud_JSON's avatar
DCloud_JSON 已提交
70 71 72 73
			}
		}
	}
</script>
74
<style lang="scss" >
DCloud_JSON's avatar
DCloud_JSON 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
	.uni-popup-message {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: center;
	}

	.uni-popup-message__box {
		background-color: #e1f3d8;
		padding: 10px 15px;
		border-color: #eee;
		border-style: solid;
		border-width: 1px;
		flex: 1;
	}

	@media screen and (min-width: 500px) {
		.fixforpc-width {
			margin-top: 20px;
			border-radius: 4px;
			flex: none;
			min-width: 380px;
			/* #ifndef APP-NVUE */
			max-width: 50%;
			/* #endif */
			/* #ifdef APP-NVUE */
			max-width: 500px;
			/* #endif */
		}
	}

	.uni-popup-message-text {
		font-size: 14px;
		padding: 0;
	}

	.uni-popup__success {
		background-color: #e1f3d8;
	}

	.uni-popup__success-text {
		color: #67C23A;
	}

	.uni-popup__warn {
		background-color: #faecd8;
	}

	.uni-popup__warn-text {
		color: #E6A23C;
	}

	.uni-popup__error {
		background-color: #fde2e2;
	}

	.uni-popup__error-text {
		color: #F56C6C;
	}

	.uni-popup__info {
		background-color: #F2F6FC;
	}

	.uni-popup__info-text {
		color: #909399;
	}
</style>