自定义全局首页配置

需求:

使用代码的方式创建全局首页,给移动端单独配置首页,做到PC端和移动端跳转的首页不同。

代码实现:

大概逻辑是使用SPI的方式去修改路由首页的逻辑。

  1. 判断请求是否是移动端,如果是移动端,则走自定义逻辑。
  2. 查出需要跳转的viewAction,拼出UeModule首页配置
  3. 校验是否有该viewAction的权限。
package pro.shushi.pamirs.top.api.spi;

import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pro.shushi.pamirs.boot.base.model.Action;
import pro.shushi.pamirs.boot.base.model.UeModule;
import pro.shushi.pamirs.boot.base.model.ViewAction;
import pro.shushi.pamirs.boot.web.loader.path.AccessResourceInfo;
import pro.shushi.pamirs.boot.web.manager.MetaCacheManager;
import pro.shushi.pamirs.boot.web.session.AccessResourceInfoSession;
import pro.shushi.pamirs.boot.web.spi.api.HomepageFetcherApi;
import pro.shushi.pamirs.boot.web.spi.service.DefaultHomepageFetcher;
import pro.shushi.pamirs.framework.faas.utils.ArgUtils;
import pro.shushi.pamirs.meta.annotation.fun.extern.Slf4j;
import pro.shushi.pamirs.meta.api.core.auth.AuthApi;
import pro.shushi.pamirs.meta.api.session.PamirsSession;
import pro.shushi.pamirs.meta.common.spi.SPI;
import pro.shushi.pamirs.meta.common.spi.Spider;
import pro.shushi.pamirs.meta.domain.module.ModuleDefinition;
import pro.shushi.pamirs.meta.enmu.ClientTypeEnum;

import javax.annotation.Resource;

@Component
@Order(88)
@SPI.Service
@Slf4j
public class GlobalHomePageExtension implements HomepageFetcherApi {

    @Resource
    private DefaultHomepageFetcher defaultHomepageFetcher;

    @Resource
    private MetaCacheManager metaCacheManager;
    //获取全局首页
    @Override
    public UeModule fetchGlobalHomepage() {
        UeModule fetchGlobalHomepage = defaultHomepageFetcher.fetchGlobalHomepage();
        //判断是登录平台,使用默认全局首页配置
        ClientTypeEnum clientTypeEnum = PamirsSession.getRequestVariables().getClientType();
        if (clientTypeEnum.equals(ClientTypeEnum.MOBILE)) {
            return fetchGlobalHomepage;
        }

        //配置返回首页
        ViewAction viewAction = null;
        Action action = metaCacheManager.fetchAction("workbench.WorkBenchHomePage", "homepage");
        if (action instanceof ViewAction) {
            viewAction = (ViewAction) action;
        }
        if (viewAction != null && viewAction.getName() != null && viewAction.getModel() != null) {
            ModuleDefinition moduleDefinition = PamirsSession.getContext().getModule(viewAction.getModule());
            UeModule ueModule = ArgUtils.convert(ModuleDefinition.MODEL_MODEL, UeModule.MODEL_MODEL, moduleDefinition);
            String module = viewAction.getModule();
            if (ueModule.getModule().equals(module)) {
                AccessResourceInfo backupInfo = AccessResourceInfoSession.getInfo();
                //验权
                if (Spider.getDefaultExtension(AuthApi.class).canAccessHomepage(viewAction.getModule()).getSuccess()) {
                    ueModule.setHomePageModel(viewAction.getModel());
                    ueModule.setHomePageName(viewAction.getName());
                    return ueModule;
                } else {
                    AccessResourceInfoSession.setInfo(backupInfo);
                }
            }
        }
        return fetchGlobalHomepage;
    }

    //获取应用首页
    @Override
    public Action fetchApplicationHomePage(UeModule module, String homepageModel, String homepageName) {
        return defaultHomepageFetcher.fetchApplicationHomePage(module, homepageModel, homepageName);
    }
}

效果:

我这边校验的是PC端,PC端登录之后返回的首页如下:
自定义全局首页配置

Oinone社区 作者:yexiu原创文章,如若转载,请注明出处:https://doc.oinone.top/dai-ma-shi-jian/19590.html

访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验

(0)
yexiu的头像yexiu数式员工
上一篇 2024年11月23日 上午11:27
下一篇 2024年11月26日 下午3:04

相关推荐

  • Oinone引入搜索引擎(增强模型)

    场景描述 在碰到大数据量并且需要全文检索的场景,我们在分布式架构中基本会架设ElasticSearch来作为一个常规解决方案。在oinone体系中增强模型就是应对这类场景,其背后也是整合了ElasticSearch; 使用前你应该 了解ElasticSearch,包括不限于:Index(索引)、分词、Node(节点)、Document(文档)、Shards(…

    2024年5月14日
    1.1K00
  • Oinone登录扩展:对接SSO(适应于4.7.8及之后的版本)

    适配版本 4.7.8及其之后的版本 概述 在企业内部,对于已有一套完整的登录系统(SSO)的情况下,通常会要求把所有的系统都对接到SSO中;本文主要讲解用Oinone开发的项目对接SSO的具体实现。 对接步骤 1、项目自定义实现UserCookieLogin,可参考示例说明:pro.shushi.pamirs.user.api.login.UserCooki…

    2024年4月2日
    1.0K00
  • 查询时自定义排序字段和排序规则

    指定字段排序 平台默认排序字段,参考IdModel,按创建时间和ID倒序(ordering = "createDate DESC, id DESC") 方法1:模型指定排序 模型定义增加排序字段。@Model.Advanced(ordering = "xxxxx DESC, yyyy DESC") @Model.mod…

    2024年5月25日
    85600
  • 如何使用位运算的数据字典

    场景举例 日常有很多项目,数据库中都有表示“多选状态标识”的字段。在这里用我们项目中的一个例子进行说明一下: 示例一: 表示某个商家是否支持多种会员卡打折(如有金卡、银卡、其他卡等),项目中的以往的做法是:在每条商家记录中为每种会员卡建立一个标志位字段。如图: 用多字段来表示“多选标识”存在一定的缺点:首先这种设置方式很明显不符合数据库设计第一范式,增加了数…

    2023年11月24日
    69400
  • Nacos做为注册中心:如何调用其他系统的SpringCloud服务?

    Oinone项目引入Nacos作为注册中心,调用外部的SpringCloud服务 Nacos可以做为注册中心,提供给Dubbo和SpringCloud等微服务框架使用。 目前Oinone的底层使用的是Dubbo进行微服务的默认协议调用,但是我们项目如果存在需要调用其他系统提供的SpringCloud服务,Oinone其实并没有限制大家去这么写代码。 可以参考…

    2024年6月4日
    1.2K00

发表回复

登录后才能评论