需求:
使用代码的方式创建全局首页,给移动端单独配置首页,做到PC端和移动端跳转的首页不同。
代码实现:
大概逻辑是使用SPI的方式去修改路由首页的逻辑。
- 判断请求是否是移动端,如果是移动端,则走自定义逻辑。
- 查出需要跳转的viewAction,拼出UeModule首页配置
- 校验是否有该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低代码应用平台体验