customer-service.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. let obj = {
  17. hidden: 1,
  18. sdkTemplateId:
  19. this.$route.query?.templateId ?? process.env.QIYUKF_TEMPLATE_ID,
  20. };
  21. if(this.$route.query?.isWeixin) obj.subdomain = 1
  22. return {
  23. script: [
  24. {
  25. src:
  26. 'https://qiyukf.com/script/98112bcf552907c28ee450c6a58269c3.js' +
  27. qs.stringify(
  28. obj,
  29. {
  30. addQueryPrefix: true,
  31. },
  32. ),
  33. async: true,
  34. callback: () => {
  35. // console.log(window.ysf);
  36. this.init(window.ysf);
  37. },
  38. },
  39. ],
  40. };
  41. },
  42. computed: {
  43. isAutoOpen() {
  44. return this.$route.query.autoopen === 'true';
  45. },
  46. isOnunread() {
  47. return this.$route.query.onunread === 'true';
  48. },
  49. ysfConfigData() {
  50. return [
  51. { key: 'real_name', value: this.$auth.user.username },
  52. { key: 'mobile_phone', hidden: true, value: this.$auth.user.phone },
  53. { key: 'email', value: this.$auth.user.email },
  54. {
  55. key: 'avatar',
  56. label: '头像',
  57. value:
  58. this.$auth.user.headImgFileId &&
  59. fileKeyToUrl(this.$auth.user.headImgFileId),
  60. }, // 访客头像
  61. {
  62. index: 0,
  63. key: 'account',
  64. label: '账号',
  65. value: this.$auth.user.phone,
  66. },
  67. ];
  68. },
  69. ysfConfig() {
  70. return {
  71. uid: String(this.$auth.user.id),
  72. name: this.$auth.user.username,
  73. mobile: this.$auth.user.phone,
  74. email: this.$auth.user.email,
  75. data: JSON.stringify(this.ysfConfigData),
  76. language: 'zh-cn',
  77. };
  78. },
  79. },
  80. mounted() {},
  81. methods: {
  82. async init(ysf) {
  83. this.ysf = ysf;
  84. // console.log(ysf);
  85. await new Promise((resolve, reject) => {
  86. ysf('onready', resolve);
  87. });
  88. await new Promise((resolve, reject) => {
  89. ysf('config', {
  90. ...this.ysfConfig,
  91. success: resolve,
  92. error: reject,
  93. });
  94. });
  95. if (this.isAutoOpen) {
  96. this.open();
  97. }
  98. if (this.isOnunread) {
  99. this.onunread();
  100. }
  101. },
  102. open() {
  103. const url = this.ysf('url');
  104. location.replace(url);
  105. // this.ysf('open', data);
  106. },
  107. getUnreadMsg() {
  108. const result = this.ysf('getUnreadMsg');
  109. console.log(result.total, result.type, result.message);
  110. },
  111. onunread() {
  112. this.ysf('onunread', (result) => {
  113. console.log(result.total, result.type, result.message);
  114. });
  115. },
  116. },
  117. };
  118. </script>