123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- <!-- 横幅消息提醒。故名思义,即悬浮在顶部的消息条,只有点关闭才会消失,一般用来重要的中断提醒。 -->
- <!-- 和tm-alerts有点类似,但作用不同 -->
- <template>
- <view :animation="animation" v-if="show" class="tm-banners text-size-n "
- :class="[dense===true||dense=='true'?'dense-32':'',black_tmeme?'bk':'',color_tmeme,
- outlined||outlined=='true'?'outlined':'','round-'+round,text?'text':'']"
-
- :style="widths"
- >
- <view class=" flex-start" :class="[dense===true||dense=='true'?'py-16 px-32 ':'py-32 px-32']">
- <view class="body-left ">
- <tm-icons :black="black_tmeme" :color="(text||outlined)?color_tmeme:iconColor" :dense="true" :name="leftIcon" size="32"></tm-icons>
- </view>
- <view @click="onclick" @tap="onclick" class="body-center " :class="['text-overflow-'+col]">{{label}}</view>
-
- <view @click.stop="closeview" v-if="close" class="body-right text-align-right">
- <tm-icons :black="black_tmeme" :color="(text||outlined)?color_tmeme:iconColor" :dense="true" name="icon-times" size="28"></tm-icons>
- </view>
- </view>
- </view>
- </template>
- <script>
- /**
- * 横幅消息提示框
- * @property {String | Boolean} dense = [true|false] 默认:true,是否减小边距。
- * @property {String | Boolean} outlined = [true|false] 默认:false,是否为边框样式
- * @property {String} position = [top|bottom] 默认:top,位置
- * @property {String | Boolean} text = [true|false] 默认:false,是否为文本模式,即减淡背景颜色。
- * @property {String | Array} label = [true|false] 默认:"",当为数组时,自动变成轮播信息。
- * @property {String | Boolean} black = [true|false] 默认:false,是否开启暗黑模式
- * @property {String} color = [primary|blue|red|green|yellow|orange] 默认:primary,主题颜色名称
- * @property {String} icon-color = [primary|blue|red|green|yellow|orange] 默认:primary,图标主题颜色名称
- * @property {String} left-icon = [icon-lightbulb] 默认:"icon-lightbulb",左边图标名称
- * @property {String | Boolean} ani = [true|false] 默认:false,是否禁用动画,
- * @property {String | Boolean} close = [true|false] 默认:false, 是否显示关闭图标,
- * @property { Number|String} y = [] 默认:0, 距离顶部的偏移量。
- * @property { Number|String} width = [] 默认:'90%', 宽度,数字,或者百度比。数字的单位是upx
- * @property { Number|String} col = [] 默认:1, 多行模式。默认为1行,可选最多3行。
- * @property { Number|String} round = [] 默认:2, 圆角。
- * @property {Function} click 整个组件点击事件
- * @example <tm-banners label="瞪村槈李厚厚霖无可奈何需"></tm-banners>
- */
- import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
- export default {
- components:{tmIcons},
- name:'tm-banners',
- model:{
- prop:'value',
- event:'input'
- },
- props: {
- // 是否减小边距。
- dense: {
- type: String | Boolean,
- default: true
- },
- // 是否为边框样式,
- outlined: {
- type: String | Boolean,
- default: false
- },
- // 是否为文本模式,即减淡背景颜色。
- text: {
- type: String | Boolean,
- default: false
- },
- // 当为数组时,自动变成轮播信息。
- label:{
- type:String | Array,
- default:""
- },
- // 是否开启暗黑模式
- black: {
- type: String | Boolean,
- default: null
- },
- // 主题颜色名称
- color: {
- type: String,
- default: 'primary'
- },
- iconColor:{
- type: String,
- default: 'white'
- },
- // 左边图标名称
- leftIcon: {
- type: String,
- default: 'icon-lightbulb'
- },
- //是否禁用动画,
- ani: {
- type: Boolean,
- default: false
- },
- // 是否显示关闭图标
- close: {
- type: Boolean,
- default: true
- },
- // 距离顶部的偏移量。
- y: {
- type: Number|String,
- default: 16
- },
- // 距离顶部的偏移量。
- position: {
- type: String,
- default: 'top' //top|bottom
- },
- // 宽度,数字,或者百度比。数字的单位是upx
- width: {
- type: Number|String,
- default: '90%'
- },
- // 圆角
- round: {
- type: Number|String,
- default: '3'
- },
- // 多行模式。默认为1行,可选最多3行。
- col:{
- type: Number|String,
- default: 1
- },
- // 跟随主题色的改变而改变。
- fllowTheme:{
- type:Boolean|String,
- default:true
- },
- value: {
- type: Boolean|String,
- default: true
- },
- },
- data() {
- return {
-
- animation: null,
- outid: 'alert-88',
-
- };
- },
- computed:{
- show:{
- get:function(){
- return this.value;
- },
- set:function(val){
- this.$emit('input',val)
- this.$emit('update:value',val)
- },
- },
- black_tmeme: function() {
- if (this.black !== null) return this.black;
- return this.$tm.vx.state().tmVuetify.black;
- },
- color_tmeme:function(){
- if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
- return this.$tm.vx.state().tmVuetify.color;
- }
- return this.color;
- },
- widths:function(){
- let topoffset = 0 + uni.upx2px(parseInt(this.y));
-
-
- if(isNaN(parseInt((this.width)))){
- return this.$tm.objToString({
- width:'100%',
- left:'0px',
- top:this.position=='bottom'?'inherit':`${topoffset}px`,
- bottom:this.position=='top'?'inherit':`${topoffset}px`
- });
- }
- if(String(this.width).indexOf('%')>-1||String(this.width).indexOf('vw')>-1){
-
- let num = parseFloat(this.width.replace(/(\%|vw|)/g,''));
- let blv = this.width.replace(/[\.|a-zA-Z0-9]/g,'');
-
- return this.$tm.objToString({
- width:this.width,
- left:(100-num)/2 + blv,
- top:this.position=='bottom'?'inherit':`${topoffset}px`,
- bottom:this.position=='top'?'inherit':`${topoffset}px`
- });
- }
- let sysinfo = uni.getSystemInfoSync();
- let wid = uni.upx2px(parseFloat(this.width));
- let lf = (sysinfo.windowWidth - wid) / 2;
- return this.$tm.objToString({
- width:uni.upx2px(parseFloat(this.width))+'px',
- left:lf+'px',
- top:this.position=='bottom'?'inherit':`${topoffset}px`,
- bottom:this.position=='top'?'inherit':`${topoffset}px`
- });
-
- }
- },
- mounted() {
-
-
- },
- methods: {
- onclick(e) {
- this.$emit('click', e);
- },
- closeview(e) {
- let t = this;
- var animation = uni.createAnimation({
- duration: 500,
- timingFunction: 'ease'
- });
- this.animation = animation;
- animation
- .scale(0.7, 0.7)
- .opacity(0)
- .step();
- this.outid = setTimeout(() => {
- t.show = false;
- t.animation=null;
- }, 500);
-
- }
- }
- };
- //
- </script>
- <style lang="scss" scoped>
- .tm-banners {
- width: calc(100% - 32upx);
- left: 32upx;
- &.dense-32{
- width: calc(100% - 64upx);
- }
- position: fixed;
- z-index: 500;
- // color: #fff;
- .gs {
- width: 50upx;
- min-width: 70upx;
- }
- .body-left,
- .body-right {
- @extend .gs;
- }
- .body-center {
- width: 100%;
-
- }
- }
- </style>
|