Bootbox 现已不推荐使用

你好 Tim,
这是替代方案,请注意这里的内容需要放在组件中的初始化 JS 文件里。你可以在这里看到一个简单的完整组件结构示例。

import { withPluginApi } from "discourse/lib/plugin-api";
import { getOwner } from "discourse-common/lib/get-owner";
import { schedule } from "@ember/runloop";
import { htmlSafe } from "@ember/template";

export default {
  name: "tester-initializer",

  initialize() {
    withPluginApi("0.8", (api) => {
      const currentUser = api.getCurrentUser();

      if (currentUser) {
        const userGroups = currentUser.groups.map((group) => group.name);
        let showPopup = false;

        switch (true) {
          case userGroups.includes("admins"):
            showPopup = true;
            break;
        }

        if (!showPopup) {
          return;
        }

        const alertHeading = "哦不!";
        const alertBody =
          '您的帐户目前受到限制,您不再可以访问有价值的资源。 \u003ca href="https://meta.discourse.org"\u003e点击这里\u003c/a\u003e 获取更多信息。';

        schedule("afterRender", () => {
          // 需要延迟,以便对话框服务已加载
          const dialog = getOwner(this).lookup("service:dialog");
          dialog.alert({
            message: htmlSafe(alertBody),
            title: alertHeading,
          });
        });
      }
    });
  },
};

希望这有帮助。

3 个赞