tm-helpTips.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="tm-helpTips relative d-inline-block">
  3. <view @click.stop="toogle">
  4. <slot></slot>
  5. </view>
  6. <view v-show="showMenu" class="tm-menu-block absolute" :class="[direction,mentDirection]">
  7. <view v-if="direction==='bottom'" class=" px-32" :class="[tipFangx]">
  8. <text class="iconfont icon-sort-up " style="font-size: 46upx;line-height: 0.5;margin-bottom: -4upx;"
  9. :class="[!black_tmeme?`text-${color_tmeme} text`:'',black_tmeme?'text-grey-darken-3':'']"></text>
  10. </view>
  11. <view :class="[color_tmeme,`shadow-${color_tmeme}-1`,black_tmeme?'bk':'']" class=" pa-16 round-2 text-align-left flex-top-start" >
  12. <view>
  13. <text class="text-size-s">{{label}}</text>
  14. </view>
  15. <view @click.stop="toogle" class=" text-align-center flex-shrink pl-32">
  16. <tm-icons :black="black_tmeme" :size="24" :color="iconColor" dense name="icon-times"></tm-icons>
  17. </view>
  18. </view>
  19. <view v-if="direction==='top'" class=" px-32" :class="[tipFangx]">
  20. <text class="iconfont icon-sort-down " style="font-size: 46upx;line-height: 0.5;margin-top: -4upx;"
  21. :class="[!black_tmeme?`text-${color_tmeme} text`:'',black_tmeme?'text-grey-darken-3':'']"></text>
  22. </view>
  23. </view>
  24. <tm-maskFlow :blur='false' v-model="showMenu" bgColor='none'></tm-maskFlow>
  25. </view>
  26. </template>
  27. <script>
  28. /**
  29. * 弹出菜单
  30. * @property {Boolean} black = [true|false] 默认:false,暗黑模式。
  31. * @property {Boolean} show = [true|false] 默认:false,始终显示菜单。
  32. * @property {String} icon-color = [] 默认:white,关闭图标颜色主题名称
  33. * @property {String} color = [] 默认:primary,主题背景色
  34. * @property {String} tip-direction = [left | center | right] 默认:center,指示三角形的方向
  35. * @property {String} direction = [top | bottom] 默认:bottom,弹出方向,top | bottom
  36. * @property {String} ment-direction = [left | center | right] 默认:center,弹出在父组件上的对齐方式,默认居中。可选left,right,center
  37. * @property {String} label = [] 默认:[],需要显示的内容
  38. * @property {String} rang-key = [] 默认:title,菜单列表数组对象时,需要提供key
  39. * @property {Function} change 点击列表项目时触发,返回:{index:index,value:item}
  40. * @example tm-helpTips direction="top" label="每点击一次增加一个积分哦,你知道了吗?">
  41. <tm-icons name="icon-question-circle"></tm-icons>
  42. </tm-helpTips>
  43. *
  44. */
  45. import tmIcons from "@/tm-vuetify/components/tm-icons/tm-icons.vue"
  46. import tmMaskFlow from "@/tm-vuetify/components/tm-maskFlow/tm-maskFlow.vue"
  47. export default {
  48. components:{tmIcons,tmMaskFlow},
  49. name: "tm-helpTips",
  50. props: {
  51. black: {
  52. type:Boolean | String,
  53. default:null
  54. },
  55. // 三角形的方向。left | center | right
  56. tipDirection: {
  57. type: String,
  58. default: 'center'
  59. },
  60. // 始终显示菜单
  61. show: {
  62. type: Boolean,
  63. default: false
  64. },
  65. // 关闭图标颜色主题名称
  66. iconColor: {
  67. type: String,
  68. default: 'white'
  69. },
  70. // 主题色
  71. color: {
  72. type: String,
  73. default: 'primary'
  74. },
  75. // 弹出方向,top | bottom
  76. direction: {
  77. type: String,
  78. default: 'bottom'
  79. },
  80. // 弹出在父组件上的对齐方式,默认居中。可选left,right,center
  81. mentDirection: {
  82. type: String,
  83. default: 'center'
  84. },
  85. label: {
  86. type: String,
  87. default: () => {
  88. return "";
  89. }
  90. },
  91. // 如果list提供的是对象数组,需要提供对象的key。如果是string对象,无需提供。默认title
  92. rangKey: {
  93. type: String,
  94. default: 'title'
  95. },
  96. // 跟随主题色的改变而改变。
  97. fllowTheme:{
  98. type:Boolean|String,
  99. default:true
  100. }
  101. },
  102. computed: {
  103. black_tmeme: function() {
  104. if (this.black !== null) return this.black;
  105. return this.$tm.vx.state().tmVuetify.black;
  106. },
  107. color_tmeme:function(){
  108. if(this.$tm.vx.state().tmVuetify.color!==null&&this.$tm.vx.state().tmVuetify.color && this.fllowTheme){
  109. return this.$tm.vx.state().tmVuetify.color;
  110. }
  111. return this.color;
  112. },
  113. tipFangx: function() {
  114. if (this.tipDirection === 'left') return 'flex-start ';
  115. if (this.tipDirection === 'center') return 'flex-center';
  116. if (this.tipDirection === 'right') return 'flex-end ';
  117. }
  118. },
  119. data() {
  120. return {
  121. showMenu: false,
  122. };
  123. },
  124. mounted() {
  125. this.showMenu = this.show;
  126. },
  127. methods: {
  128. toogle() {
  129. if (!this.label || this.label.length == 0) return;
  130. this.showMenu = !this.showMenu;
  131. this.$emit("update:show",this.showMenu)
  132. },
  133. open() {
  134. if (!this.label || this.label.length == 0) return;
  135. this.showMenu = true;
  136. this.$emit("update:show",true)
  137. },
  138. off() {
  139. if (!this.label || this.label.length == 0) return;
  140. this.showMenu = false;
  141. this.$emit("update:show",false)
  142. }
  143. },
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. .tm-helpTips {
  148. position: relative;
  149. text-align: center;
  150. .tm-menu-block {
  151. z-index: 502;
  152. width: 320upx;
  153. &.bottom {
  154. top: 100%;
  155. bottom: inherit;
  156. animation: roteScale 0.3s ease-in-out;
  157. }
  158. &.top {
  159. top: inherit;
  160. bottom: 100%;
  161. animation: roteScaleTop 0.3s ease-in-out;
  162. }
  163. &.center {
  164. left: calc(50% - 160upx);
  165. }
  166. &.left {
  167. left: 0upx;
  168. }
  169. &.right {
  170. right: 0upx;
  171. }
  172. }
  173. }
  174. @keyframes roteScale{
  175. 0%{
  176. transform: scale(0.9) translateY(-20rpx);
  177. opacity: 0;
  178. }
  179. 100%{
  180. transform: scale(1) translateY(0rpx);
  181. opacity: 1;
  182. }
  183. }
  184. @keyframes roteScaleTop{
  185. 0%{
  186. transform: scale(0.9) translateY(20rpx);
  187. opacity: 0;
  188. }
  189. 100%{
  190. transform: scale(1) translateY(0rpx);
  191. opacity: 1;
  192. }
  193. }
  194. </style>