serviceWidget.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.isDisplay = res.data.display
  93. })
  94. },
  95. weChat() {
  96. this.$emit('weChatClick');
  97. },
  98. click() {
  99. this.$emit('btnClick');
  100. },
  101. // touchstart(e) {
  102. // this.$emit('btnTouchstart');
  103. // },
  104. touchmove(e) {
  105. // 单指触摸
  106. if (e.touches.length !== 1) {
  107. return false;
  108. }
  109. if (!this.isMove) {
  110. this.$emit('btnTouchstart');
  111. }
  112. this.isMove = true;
  113. this.left = e.touches[0].clientX - this.offsetWidth;
  114. let clientY = e.touches[0].clientY - this.offsetHeight;
  115. // #ifdef H5
  116. clientY += this.height;
  117. // #endif
  118. let edgeBottom = this.windowHeight - this.height - this.edge;
  119. // 上下触及边界
  120. if (clientY < this.edge) {
  121. this.top = this.edge;
  122. } else if (clientY > edgeBottom) {
  123. this.top = edgeBottom;
  124. } else {
  125. this.top = clientY
  126. }
  127. },
  128. touchend(e) {
  129. if (this.isDock) {
  130. let edgeRigth = this.windowWidth - this.width - this.edge;
  131. if (this.left < this.windowWidth / 2 - this.offsetWidth) {
  132. this.left = this.edge;
  133. } else {
  134. this.left = edgeRigth;
  135. }
  136. }
  137. if (this.isMove) {
  138. this.isMove = false;
  139. this.$emit('btnTouchend');
  140. }
  141. },
  142. //点击跳转企业微信客服
  143. weChatService() {
  144. this.$http.post('/sys/qy/wechat/find/wechatCustomer').then(res => {
  145. this.supportStaffUrl = res.msg;
  146. this.share();
  147. })
  148. },
  149. share() {
  150. uni.share({
  151. provider: "weixin",
  152. openCustomerServiceChat: true,
  153. customerUrl: this.supportStaffUrl, //企业微信地址
  154. corpid: 'wwfe67d19509d43ec5', //企业id
  155. success: (res) => {},
  156. fail: (err) => {}
  157. });
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .drag {
  164. display: flex;
  165. flex-direction: column;
  166. justify-content: center;
  167. align-items: center;
  168. // background-color: rgba(0, 0, 0, 0.5);
  169. // box-shadow: 0 0 6upx rgba(0, 0, 0, 0.4);
  170. // color: $uni-text-color-inverse;
  171. // width: 80upx;
  172. // height: 80upx;
  173. min-width: 80rpx;
  174. min-height: 80rpx;
  175. border-radius: 50%;
  176. // font-size: $uni-font-size-sm;
  177. position: fixed;
  178. z-index: 999999;
  179. &.transition {
  180. transition: left .3s ease, top .3s ease;
  181. }
  182. .wechat {
  183. width: 60%;
  184. font-size: 30rpx;
  185. line-height: 30rpx;
  186. margin-top: 30rpx;
  187. padding: 5rpx;
  188. display: flex;
  189. justify-content: center;
  190. align-items: center;
  191. background-color: #07c160;
  192. color: #ffffff;
  193. box-sizing: border-box;
  194. border-radius: 10rpx;
  195. }
  196. }
  197. </style>