From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- uview-ui/components/u-top-tips/u-top-tips.vue | 121 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 121 insertions(+), 0 deletions(-) diff --git a/uview-ui/components/u-top-tips/u-top-tips.vue b/uview-ui/components/u-top-tips/u-top-tips.vue new file mode 100644 index 0000000..98d58df --- /dev/null +++ b/uview-ui/components/u-top-tips/u-top-tips.vue @@ -0,0 +1,121 @@ +<template> + <view class="u-tips" :class="['u-' + type, isShow ? 'u-tip-show' : '']" :style="{ + top: navbarHeight + 'px', + zIndex: uZIndex + }">{{ title }}</view> +</template> + +<script> + /** + * topTips 椤堕儴鎻愮ず + * @description 璇ョ粍浠朵竴鑸敤浜庨〉闈㈤《閮ㄥ悜涓嬫粦鍑轰竴涓彁绀猴紝灏斿悗鑷姩鏀惰捣鐨勫満鏅�� + * @tutorial https://www.uviewui.com/components/topTips.html + * @property {String Number} navbar-height 瀵艰埅鏍忛珮搴�(鍖呭惈鐘舵�佹爮楂樺害鍦ㄥ唴)锛屽崟浣峆X + * @property {String Number} z-index z-index鍊硷紙榛樿975锛� + * @example <u-top-tips ref="uTips"></u-top-tips> + */ + export default { + name: "u-top-tips", + props: { + // 瀵艰埅鏍忛珮搴︼紝鐢ㄤ簬鎻愮ず鐨勫垵濮嬪寲 + navbarHeight: { + type: [Number, String], + // #ifndef H5 + default: 0, + // #endif + // #ifdef H5 + default: 44, + // #endif + }, + // z-index鍊� + zIndex: { + type: [Number, String], + default: '' + } + }, + data() { + return { + timer: null, // 瀹氭椂鍣� + isShow: false, // 鏄惁鏄剧ず娑堟伅缁勪欢 + title: '', // 缁勪欢涓樉绀虹殑娑堟伅鍐呭 + type: 'primary', // 娑堟伅鐨勭被鍨嬶紙棰滆壊涓嶅悓锛夛紝primary锛宻uccess锛宔rror锛寃arning锛宨nfo + duration: 2000, // 缁勪欢鏄剧ず鐨勬椂闂达紝鍗曚綅涓烘绉� + }; + }, + computed: { + uZIndex() { + return this.zIndex ? this.zIndex : this.$u.zIndex.topTips; + } + }, + methods: { + show(config = {}) { + // 鍏堟竻闄ゅ畾鏃跺櫒锛堝彲鑳芥槸涓婁竴娆″畾涔夌殑锛岄渶瑕佹竻闄や簡鍐嶅紑濮嬫柊鐨勶級 + clearTimeout(this.timer); + // 鏃堕棿锛屽唴瀹癸紝绫诲瀷涓婚(type)绛夊弬鏁� + if (config.duration) this.duration = config.duration; + if (config.type) this.type = config.type; + this.title = config.title; + this.isShow = true; + // 鍊掕鏃� + this.timer = setTimeout(() => { + this.isShow = false; + clearTimeout(this.timer); + this.timer = null; + }, this.duration); + } + } + }; +</script> + +<style lang="scss" scoped> + @import "../../libs/css/style.components.scss"; + + view { + box-sizing: border-box; + } + + // 椤堕儴寮瑰嚭绫诲瀷鏍峰紡 + .u-tips { + width: 100%; + position: fixed; + z-index: 1; + padding: 20rpx 30rpx; + color: #FFFFFF; + font-size: 28rpx; + left: 0; + right: 0; + @include vue-flex; + align-items: center; + justify-content: center; + opacity: 0; + // 姝ゅ涓烘渶鏍稿績鐐癸紝translateY(-100%)鎰忓懗鐫�灏嗗叾浠嶻杞撮殣钘忥紙闅愯棌鍒伴《閮�(h5)鎴栬�呰瀵艰埅鏍�(app)涓嬮潰锛� + transform: translateY(-100%); + transition: all 0.35s linear; + } + + .u-tip-show { + transform: translateY(0); + opacity: 1; + z-index: 99; + } + + .u-primary { + background: $u-type-primary; + } + + .u-success { + background: $u-type-success; + } + + .u-warning { + background: $u-type-warning; + } + + .u-error { + background: $u-type-error; + } + + .u-info { + background: $u-type-info; + } +</style> -- Gitblit v1.9.3