index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view style="height: 100vh;" class="hhh">
  3. <chat @queryCallback="queryCallback" @openWebview="handleOpenWebview" @openMiniProgram="handleOpenMiniProgram" >
  4. </chat>
  5. <!-- <m-tabbar fixed fill current="2" :tabbar="tabbar"></m-tabbar> -->
  6. </view>
  7. </template>
  8. <script>
  9. import TabbarConfig from '@/config/tabbar.js'
  10. import {
  11. mapState,
  12. mapMutations
  13. } from 'vuex';
  14. import {
  15. getOpenId
  16. } from '@/api/user.js'
  17. export default {
  18. data() {
  19. return {
  20. tabbar: TabbarConfig,
  21. openId: ''
  22. }
  23. },
  24. computed: {
  25. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
  26. },
  27. methods: {
  28. inst() {
  29. let that = this
  30. var plugin = requirePlugin("chatbot");
  31. plugin.init({
  32. appid: "s2y2Lv65jK14ksQwYWa0WmMGqddGn4", //微信对话开放平台小程序插件appid
  33. openid: that.openId, // 小程序用户的openid,必填项
  34. userHeader: that.userInfo.avatar, // 用户头像,不传会弹出登录框
  35. userName: that.userInfo.nickname, // 用户昵称,不传会弹出登录框
  36. anonymous: false, // 是否允许匿名用户登录,版本1.2.9后生效, 默认为false,设为true时,未传递userName、userHeader两个字段时将弹出登录框
  37. // guideList: ['你好', '如何退款', '订单查询'], // 底部快捷提问
  38. // guideCardHeight: 0,
  39. success: () => {
  40. console.log( '成功');
  41. }, //非必填
  42. fail: (error) => {
  43. console.log('失败:',error);
  44. }, //非必填
  45. });
  46. // uni.navigateTo({
  47. // url:'plugin://chatbot/chat'
  48. // })
  49. },
  50. getUserInfo() {
  51. getOpenId().then(res => {
  52. this.openId = res.data.open_id
  53. this.inst()
  54. })
  55. },
  56. // 机器人问答回调
  57. queryCallback(e) {
  58. console.log('用户提问回调', e.detail)
  59. },
  60. // 机器人回复中点击H5链接
  61. handleOpenWebview(e) {
  62. const url = encodeURIComponent(e.detail.weburl)
  63. uni.navigateTo({
  64. url: `/pages/index/webview?targetUrl=${url}`
  65. })
  66. },
  67. // 机器人回复跳转其他小程序
  68. handleOpenMiniProgram(e) {
  69. const {
  70. appid,
  71. pagepath
  72. } = e.detail
  73. uni.navigateToMiniProgram({
  74. appId: appid,
  75. path: pagepath
  76. })
  77. }
  78. },
  79. onShow() {
  80. let that = this
  81. wx.login({
  82. success(res) {
  83. console.log(res,'wxlogin');
  84. that.getUserInfo()
  85. }
  86. })
  87. },
  88. onReady() {
  89. // this.getUserInfo()
  90. // getOpenId
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. .hhh {
  96. height: calc(100vh - 44px);
  97. }
  98. </style>