当前位置: 首页 > article >正文

【ICE】飞冰项目中根据不同域名设置不同的网站logo

文章目录

    • 官网介绍
    • 代码实现

官网介绍

  • 你可以在 src/app.tsx 中使用 defineMiniappConfig 导出 miniappLifecycles 来进行原生应用的生命周期事件注册:
import { defineMiniappConfig } from '@ice/plugin-miniapp/runtime';

export const miniappLifecycles = defineMiniappConfig(() => {
  return {
    onLaunch(options) {
      console.log('on launch', options);
    },
    onShow(options) {
      console.log('on show', options);
    }
  };
});

代码实现

  • onLaunch事件中可以动态设置网站logo
import logo from '@/assets/logo.png';
import NiceModal from '@ebay/nice-modal-react';
import { ConfigProvider, Skeleton } from 'antd';
import zhCN from 'antd/lib/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import relativeTime from 'dayjs/plugin/relativeTime';
import { IAppConfig, config, runApp } from 'ice';
import { NoAuth } from './components/NoAuth';
import './override-antd.less';
import NotFoundPage from './pages/NotFound';
import { createInterceptor } from './services/errorhandler';

/** 配置 dayjs */
dayjs.locale('zh-cn');
dayjs.extend(relativeTime);

/** 配置 icejs */
console.log('运行时 config', config);
const appConfig: IAppConfig = {
  app: {
    rootId: 'app-container',
    addProvider({ children }) {
      return (
        <ConfigProvider locale={zhCN}>
          <NiceModal.Provider>{children}</NiceModal.Provider>
        </ConfigProvider>
      );
    },
    onLaunch(options) {
      function setFavicon(href) {
        var link: any = document.querySelector("link[rel~='icon']");
        link.href = href;
      }
      // 根据不同的域名设置不同的favicon
      if (window.location.hostname.startsWith('liuxing')) {
        setFavicon(logo);
      }
    },
  },
  auth: {
    NoAuthFallback: <NoAuth />,
  },
  request: [
    {
      withCredentials: true,
      baseURL: `${config.baseURL}/api`,
      headers: {
        'X-Requested-With': 'XMLHttpRequest',
      },
      interceptors: createInterceptor(),
    },
  ],
  router: {
    type: 'hash',
    modifyRoutes: (routes) => {
      const addNotFoundRoute = (routes) => {
        if (Array.isArray(routes)) {
          routes.push({
            path: '*',
            component: NotFoundPage,
          });
        }
        for (const r of routes) {
          if (Array.isArray(r.children)) {
            addNotFoundRoute(r.children);
          }
        }
      };
      addNotFoundRoute(routes);

      return routes;
    },
    fallback: (
      <div>
        <Skeleton active paragraph={{ rows: 50 }} title />
      </div>
    ),
  },
};

runApp(appConfig);


http://www.kler.cn/a/560577.html

相关文章:

  • Python Django系列—入门实例(二)
  • 全面解析 Node-RED:功能、Docker 部署与实战示例
  • 伪404兼容huawei生效显示404
  • windows server 2016 安装 sqlserver2016数据库
  • GCC编译器(含预处理/编译/汇编/链接四阶段详解)
  • Visual Studio 安装全攻略
  • flutter Column嵌套ListView高度自适应问题
  • MySQL的InnoDB引擎中的聚簇索引和非聚簇索引有什么区别?
  • 如何用HBase轻松管理海量数据?
  • 蓝桥杯备赛-迷宫-BFS
  • leetcode_二叉树 543.二叉树的直径
  • GreatSQL修改配置文件参数无法生效
  • jvm调试和查看工具
  • 与go比肩的FastAPI,如何快速入门
  • Java 大视界 -- 深入剖析 Java 大数据实时 ETL 中的数据质量保障策略(97)
  • go实现敏感词过滤
  • 我与Linux的爱恋:了解信号量+共享内存+消息队列的应用
  • 【quicker】调节PPT指定字号字体大小/快速调节WPS的PPT字体大小
  • 专用奶泡棒芯片SOC,WD8001
  • 计算机毕业设计SpringBoot+Vue.js足球青训俱乐部管理系统(源码+文档+PPT+讲解)