serviceWidget.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view>
  3. <view id="_drag_button" class="drag" :style="'left: ' + left + 'px; top:' + top + 'px;'"
  4. @touchmove.stop.prevent="touchmove" @touchend="touchend" :class="{transition: isDock && !isMove }">
  5. <image src="/static/img/customerService.png" mode="" style="width: 46px;height: 56px;"
  6. @click.stop.prevent="click"></image>
  7. <view class="wechat" @click="weChatService" v-if="isDisplay">
  8. 微信客服
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'service-widget',
  16. props: {
  17. isDock: {
  18. type: Boolean,
  19. default: true
  20. },
  21. existTabBar: {
  22. type: Boolean,
  23. default: true
  24. },
  25. bottomPx: {
  26. type: Number,
  27. default: 120
  28. }
  29. },
  30. data() {
  31. return {
  32. top: 0,
  33. left: 0,
  34. width: 0,
  35. height: 0,
  36. offsetWidth: 0,
  37. offsetHeight: 0,
  38. windowWidth: 0,
  39. windowHeight: 0,
  40. isMove: true,
  41. edge: 10,
  42. text: '按钮',
  43. supportStaffUrl: '', //企业微信客服地址
  44. isDisplay: null, //企业微信客服是否展示
  45. }
  46. },
  47. mounted() {
  48. const sys = uni.getSystemInfoSync();
  49. this.windowWidth = sys.windowWidth;
  50. this.windowHeight = sys.windowHeight;
  51. // #ifdef APP-PLUS
  52. this.existTabBar && (this.windowHeight -= 50);
  53. // #endif
  54. if (sys.windowTop) {
  55. this.windowHeight += sys.windowTop;
  56. }
  57. const query = uni.createSelectorQuery().in(this);
  58. query.select('#_drag_button').boundingClientRect(data => {
  59. this.width = data.width;
  60. this.height = data.height;
  61. this.offsetWidth = data.width / 2;
  62. this.offsetHeight = data.height / 2;
  63. this.left = this.windowWidth - this.width - this.edge;
  64. if (this.bottomPx * 1 > 0) {
  65. this.top = this.windowHeight - this.height - this.bottomPx;
  66. } else {
  67. this.top = this.windowHeight - this.height - this.edge;
  68. }
  69. }).exec();
  70. //避免部分情况下图片加载延迟导致高度渲染出错
  71. setTimeout(() => {
  72. const query = uni.createSelectorQuery().in(this);
  73. query.select('#_drag_button').boundingClientRect(data => {
  74. this.width = data.width;
  75. this.height = data.height;
  76. this.offsetWidth = data.width / 2;
  77. this.offsetHeight = data.height / 2;
  78. this.left = this.windowWidth - this.width - this.edge;
  79. if (this.bottomPx * 1 > 0) {
  80. this.top = this.windowHeight - this.height - this.bottomPx;
  81. } else {
  82. this.top = this.windowHeight - this.height - this.edge;
  83. }
  84. }).exec();
  85. }, 200);
  86. this.getWechatData()
  87. },
  88. methods: {
  89. //获取企业微信客服地址,是否展示
  90. getWechatData(){
  91. this.$http.get('/sys/qy/wechat/find/picture').then(res => {
  92. this.supportStaffUrl = res.data.supportStaffUrl
  93. this.isDisplay = res.data.display
  94. })
  95. },
  96. weChat() {
  97. this.$emit('weChatClick');
  98. },
  99. click() {
  100. this.$emit('btnClick');
  101. },
  102. // touchstart(e) {
  103. // this.$emit('btnTouchstart');
  104. // },
  105. touchmove(e) {
  106. // 单指触摸
  107. if (e.touches.length !== 1) {
  108. return false;
  109. }
  110. if (!this.isMove) {
  111. this.$emit('btnTouchstart');
  112. }
  113. this.isMove = true;
  114. this.left = e.touches[0].clientX - this.offsetWidth;
  115. let clientY = e.touches[0].clientY - this.offsetHeight;
  116. // #ifdef H5
  117. clientY += this.height;
  118. // #endif
  119. let edgeBottom = this.windowHeight - this.height - this.edge;
  120. // 上下触及边界
  121. if (clientY < this.edge) {
  122. this.top = this.edge;
  123. } else if (clientY > edgeBottom) {
  124. this.top = edgeBottom;
  125. } else {
  126. this.top = clientY
  127. }
  128. },
  129. touchend(e) {
  130. if (this.isDock) {
  131. let edgeRigth = this.windowWidth - this.width - this.edge;
  132. if (this.left < this.windowWidth / 2 - this.offsetWidth) {
  133. this.left = this.edge;
  134. } else {
  135. this.left = edgeRigth;
  136. }
  137. }
  138. if (this.isMove) {
  139. this.isMove = false;
  140. this.$emit('btnTouchend');
  141. }
  142. },
  143. //点击跳转企业微信客服
  144. weChatService() {
  145. uni.share({
  146. provider: "weixin",
  147. openCustomerServiceChat: true,
  148. customerUrl: this.supportStaffUrl, //企业微信地址
  149. corpid: 'wwfe67d19509d43ec5', //企业id
  150. success: (res) => {},
  151. fail: (err) => {}
  152. });
  153. },
  154. }
  155. }
  156. </script>
  157. <style lang="scss" scoped>
  158. .drag {
  159. display: flex;
  160. flex-direction: column;
  161. justify-content: center;
  162. align-items: center;
  163. // background-color: rgba(0, 0, 0, 0.5);
  164. // box-shadow: 0 0 6upx rgba(0, 0, 0, 0.4);
  165. // color: $uni-text-color-inverse;
  166. // width: 80upx;
  167. // height: 80upx;
  168. min-width: 80rpx;
  169. min-height: 80rpx;
  170. border-radius: 50%;
  171. // font-size: $uni-font-size-sm;
  172. position: fixed;
  173. z-index: 999999;
  174. &.transition {
  175. transition: left .3s ease, top .3s ease;
  176. }
  177. .wechat {
  178. width: 55%;
  179. font-size: 30rpx;
  180. line-height: 30rpx;
  181. margin-top: 30rpx;
  182. padding: 5rpx;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. background-color: #07c160;
  187. color: #ffffff;
  188. box-sizing: border-box;
  189. border-radius: 10rpx;
  190. }
  191. }
  192. </style>