Salesforce - 在跳转到某个页面时最小化chatbot图标

我们可以使用 aura+lwc的方法来实现, 将aura和chatbot放到同一个page上,在aura在检测到url发生变化时,向messageChannel中存储数据,lwc进行捕捉调用Minimized的方法即可

code
aura.cmp
<aura:component implements="forceCommunity:availableForAllPageTypes,flexipage:availableForAllPageTypes"> <aura:handler event="forceCommunity:routeChange" action="{!c.handleRouteChange}"/> <lightning:messageChannel type="test_Minimized__c" aura:id="test_Minimized__c"/> </aura:component>
aura.controller
({ handleRouteChange : function(component, event, helper) { console.log(window.location.href); let urlJson = window.location.href; if (urlJson.includes('/s/test') ){ var payload = { isMinimizedChat: true }; component.find("test_Minimized__c").publish(payload); } } });
lwc html
<template> <!-- <img src="path_to_your_logo" alt="My Logo"></img> --> <h2 aria-live="polite"> {text} </h2> <button onclick={minimize} aria-live="off" id="miniId"> <lightning-icon icon-name="utility:minimize_window"></lightning-icon> </button> <button onclick={close} aria-live="off"> <lightning-icon icon-name="utility:close"></lightning-icon> </button> </template>

lwc js
``import { wire } from ‘lwc’;
import BaseChatHeader from ‘lightningsnapin/baseChatHeader’;
import { subscribe, MessageContext } from ‘lightning/messageService’;
import MinizedChannel from ‘@salesforce/messageChannel/test_Minimized__c’;

export default class Etp_ChatHeader extends BaseChatHeader {
@wire(MessageContext)
messageContext;
subscription = null;

// Encapsulate logic for Lightning message service subscribe and unsubsubscribe
subscribeToMessageChannelMinizied() {
    if (!this.subscription) {
        this.subscription = subscribe(
            this.messageContext,
            MinizedChannel,
            (message) => this.handleMessage(message),
            // { scope: APPLICATION_SCOPE }
        );
    }
} 
// Handler for message received by component
handleMessage(message) {
    console.log('url has been changed');
    this.minimize();
}
/**
 * Text to display in h2 element.
 * @type {string}
*/
text;

/**
 * Set handlers for events from the sidebar.
 */
connectedCallback() {
    this.subscribeToMessageChannelMinizied();
}

setText(str) {
    if (typeof str !== "string") {
        throw new Error("Expected text value to be a `String` but received: " + str + ".");
    }
    this.text = str;
}

}
``

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值