customer-service.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template lang="">
  2. <div></div>
  3. </template>
  4. <script>
  5. export default {
  6. head() {
  7. return {
  8. script: [
  9. {
  10. src: 'https://qiyukf.com/script/98112bcf552907c28ee450c6a58269c3.js',
  11. async: true,
  12. callback: () => {
  13. // console.log(window.ysf);
  14. this.init(window.ysf);
  15. },
  16. },
  17. ],
  18. };
  19. },
  20. computed: {
  21. isAutoOpen() {
  22. return this.$route.query.autoopen === 'true';
  23. },
  24. isOnunread() {
  25. return this.$route.query.onunread === 'true';
  26. },
  27. },
  28. mounted() {},
  29. methods: {
  30. async init(ysf) {
  31. this.ysf = ysf;
  32. // console.log(ysf);
  33. await new Promise((resolve, reject) => {
  34. ysf('onready', resolve);
  35. });
  36. await new Promise((resolve, reject) => {
  37. ysf('config', {
  38. uid: String(this.$auth.user.id),
  39. name: this.$auth.user.userName,
  40. mobile: this.$auth.user.phone,
  41. email: this.$auth.user.email,
  42. data: JSON.stringify([
  43. { key: 'real_name', value: this.$auth.user.userName },
  44. { key: 'mobile_phone', hidden: true, value: this.$auth.user.phone },
  45. { key: 'email', value: this.$auth.user.email },
  46. // {
  47. // key: 'avatar',
  48. // label: '头像',
  49. // value:
  50. // 'https://ysf.qiyukf.net/operation/080659b993a45dd546fbd71efd5ef000',
  51. // }, // 访客头像
  52. {
  53. index: 0,
  54. key: 'account',
  55. label: '账号',
  56. value: this.$auth.user.phone,
  57. // href: 'http://example.domain/user/zhangsan',
  58. },
  59. // { index: 1, key: 'sex', label: '性别', value: '先生' },
  60. // {
  61. // index: 5,
  62. // key: 'reg_date',
  63. // label: '注册日期',
  64. // value: '2015-11-16',
  65. // },
  66. // {
  67. // index: 6,
  68. // key: 'last_login',
  69. // label: '上次登录时间',
  70. // value: '2015-12-22 15:38:54',
  71. // },
  72. ]),
  73. language: 'zh-cn',
  74. success: resolve,
  75. error: reject,
  76. });
  77. });
  78. if (this.isAutoOpen) {
  79. this.open();
  80. }
  81. if (this.isOnunread) {
  82. this.onunread();
  83. }
  84. },
  85. open(data) {
  86. this.ysf('open', data);
  87. },
  88. getUnreadMsg() {
  89. const result = this.ysf('getUnreadMsg');
  90. console.log(result.total, result.type, result.message);
  91. },
  92. onunread() {
  93. this.ysf('onunread', (result) => {
  94. console.log(result.total, result.type, result.message);
  95. });
  96. },
  97. },
  98. };
  99. </script>