customer-service.vue 2.7 KB

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