tm-banners.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <!-- 横幅消息提醒。故名思义,即悬浮在顶部的消息条,只有点关闭才会消失,一般用来重要的中断提醒。 -->
  2. <!-- 和tm-alerts有点类似,但作用不同 -->
  3. <template>
  4. <view :animation="animation" v-if="show" class="tm-banners text-size-n "
  5. :class="[dense===true||dense=='true'?'dense-32':'',black_tmeme?'bk':'',color_tmeme,
  6. outlined||outlined=='true'?'outlined':'','round-'+round,text?'text':'']"
  7. :style="widths"
  8. >
  9. <view class=" flex-start" :class="[dense===true||dense=='true'?'py-16 px-32 ':'py-32 px-32']">
  10. <view class="body-left ">
  11. <tm-icons :black="black_tmeme" :color="(text||outlined)?color_tmeme:iconColor" :dense="true" :name="leftIcon" size="32"></tm-icons>
  12. </view>
  13. <view @click="onclick" @tap="onclick" class="body-center " :class="['text-overflow-'+col]">{{label}}</view>
  14. <view @click.stop="closeview" v-if="close" class="body-right text-align-right">
  15. <tm-icons :black="black_tmeme" :color="(text||outlined)?color_tmeme:iconColor" :dense="true" name="icon-times" size="28"></tm-icons>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. /**
  22. * 横幅消息提示框
  23. * @property {String | Boolean} dense = [true|false] 默认:true,是否减小边距。
  24. * @property {String | Boolean} outlined = [true|false] 默认:false,是否为边框样式
  25. * @property {String} position = [top|bottom] 默认:top,位置
  26. * @property {String | Boolean} text = [true|false] 默认:false,是否为文本模式,即减淡背景颜色。
  27. * @property {String | Array} label = [true|false] 默认:"",当为数组时,自动变成轮播信息。
  28. * @property {String | Boolean} black = [true|false] 默认:false,是否开启暗黑模式
  29. * @property {String} color = [primary|blue|red|green|yellow|orange] 默认:primary,主题颜色名称
  30. * @property {String} icon-color = [primary|blue|red|green|yellow|orange] 默认:primary,图标主题颜色名称
  31. * @property {String} left-icon = [icon-lightbulb] 默认:"icon-lightbulb",左边图标名称
  32. * @property {String | Boolean} ani = [true|false] 默认:false,是否禁用动画,
  33. * @property {String | Boolean} close = [true|false] 默认:false, 是否显示关闭图标,
  34. * @property { Number|String} y = [] 默认:0, 距离顶部的偏移量。
  35. * @property { Number|String} width = [] 默认:'90%', 宽度,数字,或者百度比。数字的单位是upx
  36. * @property { Number|String} col = [] 默认:1, 多行模式。默认为1行,可选最多3行。
  37. * @property { Number|String} round = [] 默认:2, 圆角。
  38. * @property {Function} click 整个组件点击事件
  39. * @example <tm-banners label="瞪村槈李厚厚霖无可奈何需"></tm-banners>
  40. */
  41. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  42. export default {
  43. components:{tmIcons},
  44. name:'tm-banners',
  45. model:{
  46. prop:'value',
  47. event:'input'
  48. },
  49. props: {
  50. // 是否减小边距。
  51. dense: {
  52. type: String | Boolean,
  53. default: true
  54. },
  55. // 是否为边框样式,
  56. outlined: {
  57. type: String | Boolean,
  58. default: false
  59. },
  60. // 是否为文本模式,即减淡背景颜色。
  61. text: {
  62. type: String | Boolean,
  63. default: false
  64. },
  65. // 当为数组时,自动变成轮播信息。
  66. label:{
  67. type:String | Array,
  68. default:""
  69. },
  70. // 是否开启暗黑模式
  71. black: {
  72. type: String | Boolean,
  73. default: null
  74. },
  75. // 主题颜色名称
  76. color: {
  77. type: String,
  78. default: 'primary'
  79. },
  80. iconColor:{
  81. type: String,
  82. default: 'white'
  83. },
  84. // 左边图标名称
  85. leftIcon: {
  86. type: String,
  87. default: 'icon-lightbulb'
  88. },
  89. //是否禁用动画,
  90. ani: {
  91. type: Boolean,
  92. default: false
  93. },
  94. // 是否显示关闭图标
  95. close: {
  96. type: Boolean,
  97. default: true
  98. },
  99. // 距离顶部的偏移量。
  100. y: {
  101. type: Number|String,
  102. default: 16
  103. },
  104. // 距离顶部的偏移量。
  105. position: {
  106. type: String,
  107. default: 'top' //top|bottom
  108. },
  109. // 宽度,数字,或者百度比。数字的单位是upx
  110. width: {
  111. type: Number|String,
  112. default: '90%'
  113. },
  114. // 圆角
  115. round: {
  116. type: Number|String,
  117. default: '3'
  118. },
  119. // 多行模式。默认为1行,可选最多3行。
  120. col:{
  121. type: Number|String,
  122. default: 1
  123. },
  124. // 跟随主题色的改变而改变。
  125. fllowTheme:{
  126. type:Boolean|String,
  127. default:true
  128. },
  129. value: {
  130. type: Boolean|String,
  131. default: true
  132. },
  133. },
  134. data() {
  135. return {
  136. animation: null,
  137. outid: 'alert-88',
  138. };
  139. },
  140. computed:{
  141. show:{
  142. get:function(){
  143. return this.value;
  144. },
  145. set:function(val){
  146. this.$emit('input',val)
  147. this.$emit('update:value',val)
  148. },
  149. },
  150. black_tmeme: function() {
  151. if (this.black !== null) return this.black;
  152. return this.$tm.vx.state().tmVuetify.black;
  153. },
  154. color_tmeme:function(){
  155. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  156. return this.$tm.vx.state().tmVuetify.color;
  157. }
  158. return this.color;
  159. },
  160. widths:function(){
  161. let topoffset = 0 + uni.upx2px(parseInt(this.y));
  162. if(isNaN(parseInt((this.width)))){
  163. return this.$tm.objToString({
  164. width:'100%',
  165. left:'0px',
  166. top:this.position=='bottom'?'inherit':`${topoffset}px`,
  167. bottom:this.position=='top'?'inherit':`${topoffset}px`
  168. });
  169. }
  170. if(String(this.width).indexOf('%')>-1||String(this.width).indexOf('vw')>-1){
  171. let num = parseFloat(this.width.replace(/(\%|vw|)/g,''));
  172. let blv = this.width.replace(/[\.|a-zA-Z0-9]/g,'');
  173. return this.$tm.objToString({
  174. width:this.width,
  175. left:(100-num)/2 + blv,
  176. top:this.position=='bottom'?'inherit':`${topoffset}px`,
  177. bottom:this.position=='top'?'inherit':`${topoffset}px`
  178. });
  179. }
  180. let sysinfo = uni.getSystemInfoSync();
  181. let wid = uni.upx2px(parseFloat(this.width));
  182. let lf = (sysinfo.windowWidth - wid) / 2;
  183. return this.$tm.objToString({
  184. width:uni.upx2px(parseFloat(this.width))+'px',
  185. left:lf+'px',
  186. top:this.position=='bottom'?'inherit':`${topoffset}px`,
  187. bottom:this.position=='top'?'inherit':`${topoffset}px`
  188. });
  189. }
  190. },
  191. mounted() {
  192. },
  193. methods: {
  194. onclick(e) {
  195. this.$emit('click', e);
  196. },
  197. closeview(e) {
  198. let t = this;
  199. var animation = uni.createAnimation({
  200. duration: 500,
  201. timingFunction: 'ease'
  202. });
  203. this.animation = animation;
  204. animation
  205. .scale(0.7, 0.7)
  206. .opacity(0)
  207. .step();
  208. this.outid = setTimeout(() => {
  209. t.show = false;
  210. t.animation=null;
  211. }, 500);
  212. }
  213. }
  214. };
  215. //
  216. </script>
  217. <style lang="scss" scoped>
  218. .tm-banners {
  219. width: calc(100% - 32upx);
  220. left: 32upx;
  221. &.dense-32{
  222. width: calc(100% - 64upx);
  223. }
  224. position: fixed;
  225. z-index: 500;
  226. // color: #fff;
  227. .gs {
  228. width: 50upx;
  229. min-width: 70upx;
  230. }
  231. .body-left,
  232. .body-right {
  233. @extend .gs;
  234. }
  235. .body-center {
  236. width: 100%;
  237. }
  238. }
  239. </style>