mixin.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import sharebywx from "../function/wxshare.js"
  2. module.exports = {
  3. ...sharebywx.sharebywx,
  4. data() {
  5. return {
  6. tmVueTifly_pages: '',
  7. }
  8. },
  9. created() {
  10. this.setVueTiflyThemeBlack();
  11. },
  12. onShow() {
  13. let urls = getCurrentPages();
  14. if(urls.length>0){
  15. let url = urls[urls.length-1].$page.fullPath
  16. if(url[0]!='/') url = '/'+url;
  17. url = url.split('?')[0];
  18. uni.$tm.vx.commit('setPageNow', url)
  19. }
  20. this.setVueTiflyThemeBlack();
  21. },
  22. onLoad() {
  23. // this.$tm.vx.commit('setWxShare',{title:'hhhhh'})
  24. },
  25. methods: {
  26. setVueTiflyThemeBlack() {
  27. let vueTifly_black = this.$tm.vx.state().tmVuetify.black
  28. if (vueTifly_black === true) {
  29. uni.setTabBarStyle({
  30. backgroundColor: "#1B1B1B"
  31. })
  32. } else {
  33. uni.setTabBarStyle({
  34. backgroundColor: "#FFFFFF"
  35. })
  36. }
  37. },
  38. // ...mapMutations(['setTmVuetifyColor', 'setTmVuetifyBlack']),
  39. // 检测提供的字符串是否是颜色值还是颜色主题。true,表示颜色主题名称。否则为false.
  40. $TestColor(color) {
  41. if (typeof color !== 'string') return false;
  42. if (color.indexOf('rgb') > -1 || color.indexOf('rgba') > -1 || color.indexOf('#') > -1) {
  43. return {
  44. theme: false,
  45. color: color
  46. };
  47. } else {
  48. return {
  49. theme: true,
  50. color: color
  51. };
  52. }
  53. },
  54. // 检查给定的值。如果是带有vw,vh,rem,em,upx,rpx,%则返回.如果是px,或者45数字,则转换为upx单位的数值。
  55. $TestUnit(n) {
  56. if (typeof n !== 'string' && typeof n !== 'number') return 0;
  57. if (typeof n === 'number') return {
  58. type: 'number',
  59. value: uni.upx2px(n)
  60. };
  61. let reg = /(vw|vh|rem|em|\%|upx|rpx|auto|px)/g;
  62. if (reg.test(n)) {
  63. return {
  64. type: 'string',
  65. value: n
  66. };
  67. }
  68. let num = parseFloat(n);
  69. if (isNaN(n)) return 0;
  70. return {
  71. type: 'number',
  72. value: uni.upx2px(n)
  73. };
  74. },
  75. $Querey(clsaaName, t, ycnum = 50,isAll) {
  76. return new Promise((rs, rj) => {
  77. if(isAll==true){
  78. // #ifdef APP-VUE || APP-PLUS
  79. ycnum = 60
  80. uni.$tm.sleep(ycnum).then(r=>{
  81. uni.createSelectorQuery().in(t ? t : this).select(clsaaName)
  82. .boundingClientRect().exec(
  83. function(res) {
  84. rs(res)
  85. })
  86. })
  87. // #endif
  88. // #ifdef MP
  89. uni.$tm.sleep(ycnum).then(r=>{
  90. uni.createSelectorQuery().in(t ? t : this).selectAll(clsaaName)
  91. .boundingClientRect().exec(
  92. function(res) {
  93. rs(res)
  94. })
  95. })
  96. // #endif
  97. // #ifdef H5
  98. uni.createSelectorQuery().in(t ? t : this).selectAll(clsaaName)
  99. .boundingClientRect().exec(
  100. function(res) {
  101. rs(res)
  102. })
  103. // #endif
  104. }else{
  105. // #ifdef APP-VUE || APP-PLUS
  106. ycnum = 60
  107. uni.$tm.sleep(ycnum).then(r=>{
  108. uni.createSelectorQuery().in(t ? t : this).select(clsaaName)
  109. .boundingClientRect().exec(
  110. function(res) {
  111. rs(res)
  112. })
  113. })
  114. // #endif
  115. // #ifdef MP
  116. uni.$tm.sleep(ycnum).then(r=>{
  117. uni.createSelectorQuery().in(t ? t : this).select(clsaaName)
  118. .boundingClientRect().exec(
  119. function(res) {
  120. rs(res)
  121. })
  122. })
  123. // #endif
  124. // #ifdef H5
  125. uni.createSelectorQuery().in(t ? t : this).select(clsaaName)
  126. .boundingClientRect().exec(
  127. function(res) {
  128. rs(res)
  129. })
  130. // #endif
  131. }
  132. // console.log(ycnum);
  133. })
  134. }
  135. },
  136. onPageScroll(e) {
  137. /**
  138. * 此全局注册用于在组件顶部,监听下拉状况以解决渐变透明的功能。
  139. * 组件:tm-menubars能用到。
  140. */
  141. uni.$emit('onPageScroll', e)
  142. },
  143. onReachBottom() {
  144. },
  145. beforeDestroy() {
  146. }
  147. }