customer-service.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. ysfConfig() {
  69. return {
  70. uid: String(this.$auth.user.id),
  71. name: this.$auth.user.userName,
  72. mobile: this.$auth.user.phone,
  73. email: this.$auth.user.email,
  74. data: JSON.stringify(this.ysfConfigData),
  75. language: 'zh-cn',
  76. };
  77. },
  78. },
  79. mounted() {},
  80. methods: {
  81. async init(ysf) {
  82. this.ysf = ysf;
  83. // console.log(ysf);
  84. await new Promise((resolve, reject) => {
  85. ysf('onready', resolve);
  86. });
  87. await new Promise((resolve, reject) => {
  88. ysf('config', {
  89. ...this.ysfConfig,
  90. success: resolve,
  91. error: reject,
  92. });
  93. });
  94. if (this.isAutoOpen) {
  95. this.open();
  96. }
  97. if (this.isOnunread) {
  98. this.onunread();
  99. }
  100. },
  101. open() {
  102. const url = this.ysf('url');
  103. location.replace(url);
  104. // this.ysf('open', data);
  105. },
  106. getUnreadMsg() {
  107. const result = this.ysf('getUnreadMsg');
  108. console.log(result.total, result.type, result.message);
  109. },
  110. onunread() {
  111. this.ysf('onunread', (result) => {
  112. console.log(result.total, result.type, result.message);
  113. });
  114. },
  115. },
  116. };
  117. </script>