index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <!-- 在线客服 -->
  3. <view v-if="!(params.type === 'chat' && !isMpWeiXin)" class="diy-service" :style="{ '--right': `${right}px`, '--bottom': `${bottom}px` }">
  4. <!-- 拨打电话 -->
  5. <block v-if="params.type === 'phone'">
  6. <view class="service-icon" @click="onMakePhoneCall">
  7. <image class="image" :src="params.image"></image>
  8. </view>
  9. </block>
  10. <!-- 在线聊天 -->
  11. <block v-else-if="params.type == 'chat'">
  12. <button open-type="contact" class="btn-normal">
  13. <view class="service-icon">
  14. <image class="image" :src="params.image"></image>
  15. </view>
  16. </button>
  17. </block>
  18. </view>
  19. </template>
  20. <script>
  21. import { rpx2px } from '@/utils/util'
  22. export default {
  23. /**
  24. * 组件的属性列表
  25. * 用于组件自定义设置
  26. */
  27. props: {
  28. itemStyle: Object,
  29. params: Object
  30. },
  31. /**
  32. * 私有数据,组件的初始数据
  33. * 可用于模版渲染
  34. */
  35. data() {
  36. return {
  37. isMpWeiXin: false,
  38. isShow: true
  39. }
  40. },
  41. computed: {
  42. right() {
  43. return rpx2px(2 * this.itemStyle.right)
  44. },
  45. bottom() {
  46. return rpx2px(2 * this.itemStyle.bottom)
  47. }
  48. },
  49. created() {
  50. // #ifdef MP-WEIXIN
  51. this.isMpWeiXin = true
  52. // #endif
  53. },
  54. /**
  55. * 组件的方法列表
  56. * 更新属性和数据的方法与更新页面数据的方法类似
  57. */
  58. methods: {
  59. /**
  60. * 点击拨打电话
  61. */
  62. onMakePhoneCall(e) {
  63. uni.makePhoneCall({
  64. phoneNumber: this.params.tel
  65. })
  66. }
  67. }
  68. }
  69. </script>
  70. <style lang="scss" scoped>
  71. .diy-service {
  72. position: fixed;
  73. z-index: 999;
  74. right: calc(var(--window-right) + var(--right));
  75. // 设置ios刘海屏底部横线安全区域
  76. bottom: calc(constant(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom));
  77. bottom: calc(env(safe-area-inset-bottom) + var(--window-bottom) + var(--bottom));
  78. .service-icon {
  79. padding: 10rpx;
  80. .image {
  81. display: block;
  82. width: 90rpx;
  83. height: 90rpx;
  84. border-radius: 50%;
  85. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  86. }
  87. }
  88. }
  89. </style>