tm-alerts.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <!-- 提示框 -->
  3. <view :animation="animation" v-if="show" @click="onclick" @tap="onclick" class="tm-alerts text-size-n "
  4. :class="[color_tmeme,(outlined||outlined=='true')?'outlined':'','round-'+round,black_tmeme?'bk':'',
  5. text=='true'||text?'text':'',
  6. `mx-${margin[0]} my-${margin[1]} shadow-${color_tmeme}-${shadow}`
  7. ]"
  8. >
  9. <view class=" flex-start" :class="[dense===true||dense=='true'?'py-16 px-32':'py-32 px-32']">
  10. <view v-if="leftIcon&&leftIcon!='true'" class="body-left ">
  11. <tm-icons :color="(text||outlined)?color_tmeme:iconColor" :dense="true" :name="leftIcon" size="32"></tm-icons>
  12. </view>
  13. <view v-if="valueType===true" @click.stop="openUrl(label)" class="body-center text-overflow">{{label[rangKey]?label[rangKey]:label}}</view>
  14. <view v-if="valueType===false" class="tm--alerts--id body-center" :style="{height:sliderwidth.height}">
  15. <swiper v-if="sliderwidth.width" :vertical="vertical" :style="{height:sliderwidth.height,width:sliderwidth.width}" :interval="interval_vs" circular autoplay :duration="duration_vs" >
  16. <swiper-item @click.stop="openUrl(item)" v-for="(item,index) in label" :key="index" class="body-center text-overflow" style="line-height: 50upx;" :style="{height:sliderwidth.height}">
  17. {{item[rangKey]?item[rangKey]:item}}
  18. </swiper-item>
  19. </swiper>
  20. </view>
  21. <view v-if="url && !close" class="body-right text-align-right">
  22. <tm-icons :color="(text||outlined)?color_tmeme:iconColor" :dense="true" :name="rightIcon" size="28"></tm-icons>
  23. </view>
  24. <view v-if="close" class="body-right text-align-right">
  25. <tm-icons @click="closeview" :color="(text||outlined)?color_tmeme:iconColor" :dense="true" name="icon-times" size="28"></tm-icons>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. /**
  32. * 消息提示框
  33. * @property {String | Boolean} dense = [true|false] 默认:true,是否减小边距。
  34. * @property {Array} margin = [] 默认:[32,24],边距。
  35. * @property {String|Number} shadow = [] 默认:6,投影
  36. * @property {String|Number} round = [] 默认:4,圆角
  37. * @property {String|Number} duration = [] 默认:500,轮播速度。
  38. * @property {String|Number} interval = [] 默认:1500,轮播间隙。
  39. * @property {String | Boolean} outlined = [true|false] 默认:false,是否为边框样式
  40. * @property {String | Boolean} text = [true|false] 默认:false,是否为文本模式,即减淡背景颜色。
  41. * @property {String | Array} label = [true|false] 默认:"",当为数组时,自动变成轮播信息。
  42. * @property {String | Boolean} black = [true|false] 默认:false,是否开启暗黑模式
  43. * @property {String} color = [] 默认:primary,主题颜色名称
  44. * @property {String} icon-color = [] 默认:white,图标的主题颜色名称
  45. * @property {Boolean} url = [true|false] 默认:false,是否显示打开链接图标
  46. * @property {String} left-icon = [] 默认:"icon-lightbulb",左边图标名称
  47. * @property {String} right-icon = [] 默认:"icon-angle-right",右边图标名称
  48. * @property {String} rang-key = [] 默认:"text",当label娄数组时需要提供此值。
  49. * @property {String | Boolean} ani = [true|false] 默认:false,是否禁用动画,
  50. * @property {String | Boolean} vertical = [true|false] 默认:false,是否是纵向。
  51. * @property {String | Boolean} close = [true|false] 默认:false, 是否显示关闭图标,
  52. * @property {Function} click 整个组件点击事件
  53. * @example <tm-alerts label="9"></tm-alerts>
  54. */
  55. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  56. export default {
  57. components:{tmIcons},
  58. name:"tm-alerts",
  59. model:{
  60. prop:'value',
  61. event:'input'
  62. },
  63. props: {
  64. // 是否减小边距。
  65. dense: {
  66. type: String | Boolean,
  67. default: true
  68. },
  69. // 是否为边框样式,
  70. outlined: {
  71. type: String | Boolean,
  72. default: false
  73. },
  74. // 边距。
  75. margin: {
  76. type: Array,
  77. default: ()=>{
  78. return [32,24];
  79. }
  80. },
  81. shadow: {
  82. type: String|Number,
  83. default: 4
  84. },
  85. round: {
  86. type: String|Number,
  87. default: 3
  88. },
  89. // 是否为文本模式,即减淡背景颜色。
  90. text: {
  91. type: String | Boolean,
  92. default: false
  93. },
  94. // 当为数组时,自动变成轮播信息。
  95. label:{
  96. type:String | Array,
  97. default:""
  98. },
  99. // 当label娄数组时需要提供此值。
  100. rangKey:{
  101. type:String,
  102. default:"text"
  103. },
  104. // 是否开启暗黑模式
  105. black: {
  106. type: String | Boolean,
  107. default: null
  108. },
  109. // 主题颜色名称
  110. color: {
  111. type: String,
  112. default: 'primary'
  113. },
  114. // 图标主题颜色名称
  115. iconColor: {
  116. type: String,
  117. default: 'white'
  118. },
  119. // 是否显示为打开链接的消息提醒。
  120. url: {
  121. type: Boolean,
  122. default: false
  123. },
  124. // 左边图标名称
  125. leftIcon: {
  126. type: String,
  127. default: 'icon-lightbulb'
  128. },
  129. // 右边图标名称
  130. rightIcon: {
  131. type: String,
  132. default: 'icon-angle-right'
  133. },
  134. //是否禁用动画,
  135. ani: {
  136. type: Boolean,
  137. default: false
  138. },
  139. // 是否显示关闭图标
  140. close: {
  141. type: Boolean,
  142. default: false
  143. },
  144. // 跟随主题色的改变而改变。
  145. fllowTheme:{
  146. type:Boolean|String,
  147. default:true
  148. },
  149. duration:{
  150. type:Number,
  151. default:1000
  152. },
  153. vertical:{
  154. type:Boolean,
  155. default:false
  156. },
  157. //间隔,单位ms
  158. interval:{
  159. type:Number,
  160. default:1500
  161. },
  162. value: {
  163. type: Boolean|String,
  164. default: true
  165. },
  166. },
  167. data() {
  168. return {
  169. animation: null,
  170. outid: 'alert-88',
  171. sliderwidth:{height:0,width:0},
  172. };
  173. },
  174. computed:{
  175. // valueType:true,//默认是string.
  176. valueType:function(){
  177. if(Array.isArray(this.label)){
  178. return false;
  179. }
  180. return true;
  181. },
  182. black_tmeme: function() {
  183. if (this.black !== null) return this.black;
  184. return this.$tm.vx.state().tmVuetify.black;
  185. },
  186. color_tmeme:function(){
  187. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  188. return this.$tm.vx.state().tmVuetify.color;
  189. }
  190. return this.color;
  191. },
  192. duration_vs:function () {
  193. return this.duration;
  194. },
  195. interval_vs:function () {
  196. return this.interval;
  197. },
  198. show:{
  199. get:function(){
  200. return this.value;
  201. },
  202. set:function(val){
  203. this.$emit('input',val)
  204. this.$emit('update:value',val)
  205. },
  206. },
  207. },
  208. mounted() {
  209. let t= this;
  210. this.$Querey('.tm--alerts--id',this,50).then(res=>{
  211. let wh = res[0];
  212. t.sliderwidth = {
  213. height:uni.upx2px(50)+'px',width:(wh.width||0)+'px'
  214. }
  215. }).catch(e=>{})
  216. },
  217. methods: {
  218. onclick(e) {
  219. this.$emit('click', e);
  220. },
  221. openUrl(e) {
  222. this.$emit('click', e);
  223. if(typeof e !== 'object' || !e['url']) return;
  224. let urls = getCurrentPages();
  225. let url = e.url;
  226. if (urls.length >= 5) {
  227. uni.redirectTo({
  228. url:url,
  229. fail: e => {
  230. console.error(e);
  231. }
  232. });
  233. } else {
  234. uni.navigateTo({
  235. url: url,
  236. fail: e => {
  237. console.error(e);
  238. }
  239. });
  240. }
  241. },
  242. closeview(e) {
  243. let t = this;
  244. var animation = uni.createAnimation({
  245. duration: 500,
  246. timingFunction: 'ease'
  247. });
  248. this.animation = animation;
  249. animation
  250. .scale(0.7, 0.7)
  251. .opacity(0)
  252. .step();
  253. this.outid = setTimeout(() => {
  254. t.show = false;
  255. t.animation = null;
  256. }, 500);
  257. }
  258. }
  259. };
  260. </script>
  261. <style lang="scss" scoped>
  262. .tm-alerts {
  263. .gs {
  264. width: 50upx;
  265. min-width: 70upx;
  266. }
  267. .body-left,
  268. .body-right {
  269. @extend .gs;
  270. }
  271. .body-center {
  272. width: 100%;
  273. }
  274. }
  275. </style>