customer-service.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template lang="">
  2. <div>
  3. <!-- <v-btn @click="open({ templateId: 6635862 })">双子星模板</v-btn>
  4. <v-btn @click="open({ templateId: 6634867 })">唔即云模板</v-btn> -->
  5. </div>
  6. </template>
  7. <script>
  8. import qs from 'qs';
  9. import { fileKeyToUrl } from '@/plugins/file-center.js';
  10. console.log(
  11. '🚀 ~ file: customer-service.vue ~ line 10 ~ fileKeyToUrl',
  12. fileKeyToUrl,
  13. );
  14. export default {
  15. head() {
  16. return {
  17. script: [
  18. {
  19. src:
  20. 'https://qiyukf.com/script/98112bcf552907c28ee450c6a58269c3.js' +
  21. qs.stringify(
  22. {
  23. hidden: 1,
  24. sdkTemplateId:
  25. this.$route.query?.templateId ??
  26. process.env.QIYUKF_TEMPLATE_ID,
  27. },
  28. {
  29. addQueryPrefix: true,
  30. },
  31. ),
  32. async: true,
  33. callback: () => {
  34. // console.log(window.ysf);
  35. this.init(window.ysf);
  36. },
  37. },
  38. ],
  39. };
  40. },
  41. computed: {
  42. isAutoOpen() {
  43. return this.$route.query.autoopen === 'true';
  44. },
  45. isOnunread() {
  46. return this.$route.query.onunread === 'true';
  47. },
  48. ysfConfigData() {
  49. return [
  50. { key: 'real_name', value: this.$auth.user.userName },
  51. { key: 'mobile_phone', hidden: true, value: this.$auth.user.phone },
  52. { key: 'email', value: this.$auth.user.email },
  53. {
  54. key: 'avatar',
  55. label: '头像',
  56. value:
  57. this.$auth.user.headImgFileId &&
  58. fileKeyToUrl(this.$auth.user.headImgFileId),
  59. }, // 访客头像
  60. {
  61. index: 0,
  62. key: 'account',
  63. label: '账号',
  64. value: this.$auth.user.phone,
  65. },
  66. ];
  67. },
  68. },
  69. mounted() {},
  70. methods: {
  71. async init(ysf) {
  72. this.ysf = ysf;
  73. // console.log(ysf);
  74. await new Promise((resolve, reject) => {
  75. ysf('onready', resolve);
  76. });
  77. await new Promise((resolve, reject) => {
  78. ysf('config', {
  79. uid: String(this.$auth.user.id),
  80. name: this.$auth.user.userName,
  81. mobile: this.$auth.user.phone,
  82. email: this.$auth.user.email,
  83. data: JSON.stringify([
  84. { key: 'real_name', value: this.$auth.user.userName },
  85. { key: 'mobile_phone', hidden: true, value: this.$auth.user.phone },
  86. { key: 'email', value: this.$auth.user.email },
  87. {
  88. key: 'avatar',
  89. label: '头像',
  90. value:
  91. this.$auth.user.headImgFileId &&
  92. fileKeyToUrl(this.$auth.user.headImgFileId),
  93. }, // 访客头像
  94. {
  95. index: 0,
  96. key: 'account',
  97. label: '账号',
  98. value: this.$auth.user.phone,
  99. },
  100. ]),
  101. language: 'zh-cn',
  102. success: resolve,
  103. error: reject,
  104. });
  105. });
  106. if (this.isAutoOpen) {
  107. this.open();
  108. }
  109. if (this.isOnunread) {
  110. this.onunread();
  111. }
  112. },
  113. open() {
  114. const url = this.ysf('url');
  115. location.replace(url);
  116. // this.ysf('open', data);
  117. },
  118. getUnreadMsg() {
  119. const result = this.ysf('getUnreadMsg');
  120. console.log(result.total, result.type, result.message);
  121. },
  122. onunread() {
  123. this.ysf('onunread', (result) => {
  124. console.log(result.total, result.type, result.message);
  125. });
  126. },
  127. },
  128. };
  129. </script>