| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <template>
- <view style="height: 100vh;" class="hhh">
- <chat @queryCallback="queryCallback" @openWebview="handleOpenWebview" @openMiniProgram="handleOpenMiniProgram" >
- </chat>
- <!-- <m-tabbar fixed fill current="2" :tabbar="tabbar"></m-tabbar> -->
- </view>
- </template>
- <script>
- import TabbarConfig from '@/config/tabbar.js'
- import {
- mapState,
- mapMutations
- } from 'vuex';
- import {
- getOpenId
- } from '@/api/user.js'
- export default {
- data() {
- return {
- tabbar: TabbarConfig,
- openId: ''
- }
- },
- computed: {
- ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
- },
- methods: {
- inst() {
- let that = this
- var plugin = requirePlugin("chatbot");
- plugin.init({
- appid: "s2y2Lv65jK14ksQwYWa0WmMGqddGn4", //微信对话开放平台小程序插件appid
- openid: that.openId, // 小程序用户的openid,必填项
- userHeader: that.userInfo.avatar, // 用户头像,不传会弹出登录框
- userName: that.userInfo.nickname, // 用户昵称,不传会弹出登录框
- anonymous: false, // 是否允许匿名用户登录,版本1.2.9后生效, 默认为false,设为true时,未传递userName、userHeader两个字段时将弹出登录框
- // guideList: ['你好', '如何退款', '订单查询'], // 底部快捷提问
- // guideCardHeight: 0,
- success: () => {
- console.log( '成功');
- }, //非必填
- fail: (error) => {
- console.log('失败:',error);
- }, //非必填
- });
- // uni.navigateTo({
- // url:'plugin://chatbot/chat'
- // })
- },
- getUserInfo() {
- getOpenId().then(res => {
- this.openId = res.data.open_id
- this.inst()
- })
- },
- // 机器人问答回调
- queryCallback(e) {
- console.log('用户提问回调', e.detail)
- },
- // 机器人回复中点击H5链接
- handleOpenWebview(e) {
- const url = encodeURIComponent(e.detail.weburl)
- uni.navigateTo({
- url: `/pages/index/webview?targetUrl=${url}`
- })
- },
- // 机器人回复跳转其他小程序
- handleOpenMiniProgram(e) {
- const {
- appid,
- pagepath
- } = e.detail
- uni.navigateToMiniProgram({
- appId: appid,
- path: pagepath
- })
- }
- },
- onShow() {
- let that = this
- wx.login({
- success(res) {
- console.log(res,'wxlogin');
- that.getUserInfo()
- }
- })
- },
- onReady() {
- // this.getUserInfo()
- // getOpenId
- }
- }
- </script>
- <style lang="scss" scoped>
- .hhh {
- height: calc(100vh - 44px);
- }
- </style>
|