# 提醒操作

系统右下角弹窗重构后已经可以直接在 WEB 端调用和实现

# 文件位置

TIP

文件位于 WEB 端 public\static\client\client_pc\notice.jskickedOff 部分

# 在 WEB 端调用

在 WEB 端中可以直接这样使用

let myNotification = new Notification("标题", {
  body: "通知正文内容",
});

myNotification.onclick = () => {
  console.log("通知被点击");
};

# WEB 端 kickedOff 方法说明

代码如下:

kickedOff(data, callback) {
  console.log("@@@@@@@@@@@@@@", "kickedOff", data);
  const App = ZxDesktop.require("App");
  const File = ZxDesktop.require("File");
  // isNotice是一个全局的变量,见上面设置
  if (isNotice) {
    // 判断数据格式是否正确
    if (!(data.title && data.body)) {
      console.error("弹窗函数未接收到参数title或body");
      return;
    }
    // 格式化消息
    let body =
      (data.name ? data.name + " - " : "") +
      (data.date ? data.date + "\n" : "") +
      data.body;
    // 消息设置
    const notification = {
      title: data.title,
      body: body,
      icon: File.pathResolve(App.getAppPath(), "assets/img/logo.png"), // 图标地址
      silent: true, // 是否有声音
    };
    // 执行弹窗
    const myNotification = new window.Notification(
      notification.title,
      notification
    );
    // 点击弹窗后触发的事件
    myNotification.onclick = () => {
      console.info("Notification clicked");
      // 消息类型判断,及脚本执行,从旧版本移植
      if (
        data.messagetype == 3 ||
        data.messagetype == 30 ||
        data.messagetype == 26 ||
        data.messagetype == 999999 ||
        data.messagetype == 31 ||
        data.messagetype == 17 ||
        data.messagetype == 36 ||
        data.messagetype == 14 ||
        data.messagelink === ""
      ) {
        return false;
      }
      App.ipcRenderer.send("penetrate", data.messagelink);
      // 添加回调
      try {
        callback && callback();
      } catch (error) {
        console.log("kickedOff方法回调有问题", callback);
      }
    };
  }
}

使用方法参考

// 飘窗弹框
ZX_CLIENT &&
  ZX_CLIENT.kickedOff(
    {
      // 标题
      title: newMessage.sendMemberName,
      // 姓名
      name: newMessage.sendMemberName,
      // 正文
      body: newMessage.content,
      // 时间
      time: newMessage.createDate,
      // 消息ID
      messageid: newMessage.messageId,
      // 消息类型
      messagetype: newMessage.messagetype,
      // 消息链接
      messagelink:
        newMessage.messagePcUrl != ""
          ? store.getters.getV5BaseURL +
            newMessage.messagePcUrl +
            "&mTicket=" +
            ZX.$store.getters.currentUserInfo.mTicket
          : "",
    },
    () => {
      // 点击飘窗回调
      store.commit("setReadedStatus", newMessage);
    }
  );