当前位置:首页 >> 网络编程

React Js 微信禁止复制链接分享禁止隐藏右上角菜单功能

废话不多说了,直接给大家贴代码了,具体代码如下所示:

/**
 * Created by wuyakun on 2017/5/23.
 */let wxUtils = {};
/**
 * 是否开启右上角Menu
 * @param open
 */
wxUtils.optionMenu = function (open = true) {
 if (open) {
  openOptionMenu();
 } else {
  disabledOptionMenu();
 }
};
/**
 * 是否禁用右上角
 */
function disabledOptionMenu() {
 if (typeof WeixinJSBridge === "undefined") {
  if (document.addEventListener) {
   document.addEventListener('WeixinJSBridgeReady', onBridgeReady(true), false);
  } else if (document.attachEvent) {
   document.attachEvent('WeixinJSBridgeReady', onBridgeReady(true));
   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(true));
  }
 } else {
  onBridgeReady(true);
 }
}
/**
 * 开启menu
 */
function openOptionMenu() {
 if (typeof WeixinJSBridge === "undefined") {
  if (document.addEventListener) {
   document.addEventListener('WeixinJSBridgeReady', onBridgeReady(false), false);
  } else if (document.attachEvent) {
   document.attachEvent('WeixinJSBridgeReady', onBridgeReady(false));
   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady(false));
  }
 } else {
  onBridgeReady(false);
 }
}
function onBridgeReady(disable = true) {
 if (typeof WeixinJSBridge !== "undefined") WeixinJSBridge.call(disable "htmlcode">
export default class BaseComponent extends React.Component {
 componentDidMount() {
  try {
   //如果存在location说明是路由Component
   if (this.props.location) {
    // 全部禁用分享,想要分享自己开
    wxUtils.optionMenu(false);
   }
  } catch (e) {
   // console.log(e);
  }
 }
}

我写在了Base里面,主要是wxUtils.optionMenu(false);这一句