tm-message.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view>
  3. <view v-if="show_dev" @click.stop.prevent="maskClick" :class="[mask?'mask':'']"
  4. class="tm-message fixed t-0 l-0 fulled fulled-height flex-center">
  5. <view class="tm-message-body round-6 pa-24 flex-center shadow-24 ">
  6. <view class=" flex-center flex-col">
  7. <view :class="[
  8. model,
  9. ]"><text class="iconfont" style="font-size: 54rpx;"
  10. :class="[ `text-${color_tmeme[model]}`,icon_dev||icon[model],black_dev?'text-white':'']"></text>
  11. </view>
  12. <view class="pt-12 text-align-center">
  13. <text class="text-size-n text-align-center "
  14. :class="[black_dev?`text-${color_tmeme[model]||color_tmeme}`+' text-white bk':`text-grey-darken-5`]">
  15. {{label_dev||label[model]}}
  16. </text>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. /**
  25. * 提示框
  26. * @property {Object} color = [] 默认对应的类型主题色
  27. * @property {Object} icon = [] 默认对应的类型图标
  28. * @property {Object} label = [] 默认对应的类型提示文字
  29. * @property {Boolean} black = [] 默认false,是否使用暗黑主题。
  30. */
  31. export default {
  32. name: 'tm-message',
  33. props: {
  34. color: {
  35. type: Object,
  36. default: () => {
  37. return {
  38. load: 'primary',
  39. error: 'red',
  40. info: 'grey-darken-4',
  41. warn: 'orange',
  42. quest: 'primary',
  43. success: 'green',
  44. disabled: 'pink',
  45. wait: 'primary',
  46. }
  47. }
  48. },
  49. icon: {
  50. type: Object,
  51. default: () => {
  52. return {
  53. load: 'icon-loading',
  54. error: 'icon-times-circle',
  55. info: 'icon-info-circle',
  56. warn: 'icon-exclamation-circle',
  57. quest: 'icon-question-circle',
  58. success: 'icon-check-circle',
  59. disabled: 'icon-ban',
  60. wait: 'icon-clock',
  61. }
  62. }
  63. },
  64. label: {
  65. type: Object,
  66. default: () => {
  67. return {
  68. load: '加载中',
  69. error: '出错啦',
  70. info: '信息提示',
  71. warn: '警告信息',
  72. quest: '似乎有问题',
  73. success: '操作成功',
  74. disabled: '禁止操作',
  75. wait: '请等待',
  76. }
  77. }
  78. },
  79. // 暗黑
  80. black: {
  81. type: Boolean | String,
  82. default: null
  83. },
  84. // 跟随主题色的改变而改变。
  85. fllowTheme: {
  86. type: Boolean | String,
  87. default: true
  88. }
  89. },
  90. computed: {
  91. black_tmeme: function() {
  92. if (this.black !== null) return this.black;
  93. return this.$tm.vx.state().tmVuetify.black;
  94. },
  95. color_tmeme: function() {
  96. if (this.$tm.vx.state().tmVuetify.color !== null && this.$tm.vx.state().tmVuetify.color && this
  97. .fllowTheme) {
  98. let cos = this.$tm.vx.state().tmVuetify.color;
  99. let co={...this.color,info:cos,quest:cos,load:cos,wait:cos};
  100. return co;
  101. }
  102. return this.color;
  103. }
  104. },
  105. data() {
  106. return {
  107. model: 'wait', //load,error,info,warn,quest,success,disabled,wait
  108. icon_dev: '',
  109. label_dev: '',
  110. timeId: 8964566588,
  111. show_dev: false,
  112. mask: false,
  113. black_dev: false,
  114. clickOverlay:false,
  115. };
  116. },
  117. destroyed(){
  118. clearTimeout(this.timeId);
  119. },
  120. methods: {
  121. async anifeed(){
  122. this.clickOverlay = true;
  123. await uni.$tm.sleep(50)
  124. this.clickOverlay = false;
  125. },
  126. //{label,model,icon,mask,wait,black}
  127. show() {
  128. let t = this;
  129. let def = {
  130. label: '',
  131. model: 'info',
  132. icon: '',
  133. mask: false,
  134. wait: 2000,
  135. black: this.black_tmeme
  136. };
  137. let arg = arguments[0] ? {
  138. ...def,
  139. ...arguments[0]
  140. } : def;
  141. const {
  142. label,
  143. model,
  144. icon,
  145. mask,
  146. wait,
  147. black
  148. } = arg;
  149. this.label_dev = label;
  150. this.model = model;
  151. this.icon_dev = icon;
  152. this.black_dev = black;
  153. this.mask = mask;
  154. clearTimeout(this.timeId);
  155. if (this.model == 'load') {
  156. this.show_dev = true;
  157. } else {
  158. this.show_dev = true;
  159. this.timeId = setTimeout(function() {
  160. t.hide();
  161. }, wait);
  162. }
  163. },
  164. async maskClick(){
  165. await this.anifeed();
  166. },
  167. hide() {
  168. this.show_dev = false;
  169. clearTimeout(this.timeId);
  170. this.mask = false;
  171. this.label_dev = '';
  172. this.model = 'info';
  173. this.model = 'info';
  174. this.icon_dev = '';
  175. this.black_dev = this.black_tmeme;
  176. },
  177. },
  178. };
  179. </script>
  180. <style lang="scss" scoped>
  181. .tm-message {
  182. z-index: 601;
  183. pointer-events: none;
  184. background-color: transparent;
  185. &.mask {
  186. backdrop-filter: blur(3px);
  187. background-color: rgba(0, 0, 0, 0.3);
  188. pointer-events: auto;
  189. }
  190. .tm-message-body {
  191. min-width: 110rpx;
  192. min-height: 120rpx;
  193. max-width: 64%;
  194. backdrop-filter: blur(10px);
  195. background-color: rgba(255, 255, 255, 0.75);
  196. &.black {
  197. background-color: rgba(0, 0, 0, 0.90) !important;
  198. }
  199. animation: outin 0.3s ease-in-out;
  200. &.clickOverlay{
  201. animation: none !important;
  202. }
  203. .load {
  204. animation: load 0.5s infinite linear;
  205. }
  206. .error {
  207. animation: error 1.5s infinite linear;
  208. }
  209. .info {
  210. animation: info 0.5s linear;
  211. }
  212. .warn {
  213. animation: warn 0.5s infinite linear;
  214. }
  215. .quest {
  216. animation: quest 1s infinite linear;
  217. }
  218. .success {
  219. animation: success 1s linear;
  220. }
  221. .disabled {
  222. animation: warn 0.5s infinite linear;
  223. }
  224. .wait {
  225. animation: wait 3.5s infinite linear;
  226. }
  227. }
  228. }
  229. @keyframes outin {
  230. 0% {
  231. transform: scale(0.64)
  232. }
  233. 25% {
  234. transform: scale(1.1)
  235. }
  236. 50% {
  237. transform: scale(0.9)
  238. }
  239. 100% {
  240. transform: scale(1)
  241. }
  242. }
  243. // wait:'primary',
  244. @keyframes wait {
  245. 0% {
  246. transform: rotate(0deg)
  247. }
  248. 100% {
  249. transform: rotate(360deg)
  250. }
  251. }
  252. @keyframes success {
  253. 0% {
  254. transform: scale(1.9)
  255. }
  256. 25% {
  257. transform: scale(0.7)
  258. }
  259. 50% {
  260. transform: scale(1)
  261. }
  262. 75% {
  263. transform: scale(0.9)
  264. }
  265. 100% {
  266. transform: scale(1)
  267. }
  268. }
  269. @keyframes quest {
  270. 0% {
  271. transform: rotate(-45deg)
  272. }
  273. 50% {
  274. transform: rotate(45deg)
  275. }
  276. 100% {
  277. transform: rotate(-45deg)
  278. }
  279. }
  280. @keyframes warn {
  281. 0% {
  282. transform: translateX(-10rpx)
  283. }
  284. 50% {
  285. transform: translateX(10rpx)
  286. }
  287. 100% {
  288. transform: translateX(-10rpx)
  289. }
  290. }
  291. @keyframes info {
  292. 0% {
  293. transform: scale(0.5)
  294. }
  295. 100% {
  296. transform: scale(1)
  297. }
  298. }
  299. @keyframes error {
  300. 0% {
  301. transform: scale(0.8)
  302. }
  303. 50% {
  304. transform: scale(1.2)
  305. }
  306. 100% {
  307. transform: scale(0.8)
  308. }
  309. }
  310. @keyframes load {
  311. 0% {
  312. transform: rotate(0deg);
  313. }
  314. 100% {
  315. transform: rotate(360deg);
  316. }
  317. }
  318. </style>