feat: 使用lic结果过滤xpack插件菜单

This commit is contained in:
fit2cloud-chenyw 2021-06-01 15:20:26 +08:00
parent 89c758a50a
commit 64cac2a9b3
6 changed files with 55 additions and 21 deletions

View File

@ -23,9 +23,9 @@ public class LicenseController {
@GetMapping(value = "anonymous/license/validate")
public ResultHolder validateLicense() throws Exception {
// if (!need_validate_lic) {
// return ResultHolder.success(null);
// }
if (!need_validate_lic) {
return ResultHolder.success(null);
}
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.validateLicense();
System.out.println(new Gson().toJson(f2CLicenseResponse));
switch (f2CLicenseResponse.getStatus()) {

View File

@ -8,20 +8,16 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@Component
public class MyScanner implements BeanDefinitionRegistryPostProcessor {
@Resource
private MapperScannerConfigurer mapperScannerConfigurer;
private BeanDefinitionRegistry beanDefinitionRegistry;
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry beanDefinitionRegistry) throws BeansException {
this.beanDefinitionRegistry = beanDefinitionRegistry;
System.out.println("-----");
}
@Override
@ -30,9 +26,7 @@ public class MyScanner implements BeanDefinitionRegistryPostProcessor {
}
public void scanner() {
if (null == mapperScannerConfigurer){
mapperScannerConfigurer = SpringContextUtil.getBean(MapperScannerConfigurer.class);
}
MapperScannerConfigurer mapperScannerConfigurer = SpringContextUtil.getBean(MapperScannerConfigurer.class);
mapperScannerConfigurer.postProcessBeanDefinitionRegistry(this.beanDefinitionRegistry);
}

View File

@ -1,21 +1,51 @@
package io.dataease.plugins.util;
import io.dataease.commons.license.DefaultLicenseService;
import io.dataease.commons.license.F2CLicenseResponse;
import io.dataease.plugins.common.dto.PluginSysMenu;
import io.dataease.plugins.common.service.PluginMenuService;
import io.dataease.plugins.config.SpringContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Component
public class PluginUtils {
private static DefaultLicenseService defaultLicenseService;
@Autowired
public void setDefaultLicenseService(DefaultLicenseService defaultLicenseService) {
PluginUtils.defaultLicenseService = defaultLicenseService;
}
public static List<PluginSysMenu> pluginMenus() {
F2CLicenseResponse f2CLicenseResponse = currentLic();
if (f2CLicenseResponse.getStatus() != F2CLicenseResponse.Status.valid)
return new ArrayList<>();
Map<String, PluginMenuService> pluginMenuServiceMap = SpringContextUtil.getApplicationContext().getBeansOfType(PluginMenuService.class);
List<PluginSysMenu> menus = pluginMenuServiceMap.values().stream().flatMap(item -> item.menus().stream()).collect(Collectors.toList());
return menus;
}
public static F2CLicenseResponse currentLic() {
Environment environment = SpringContextUtil.getBean(Environment.class);
Boolean need_validate_lic = environment.getProperty("dataease.need_validate_lic", Boolean.class, true);
if (!need_validate_lic) {
F2CLicenseResponse f2CLicenseResponse = new F2CLicenseResponse();
f2CLicenseResponse.setStatus(F2CLicenseResponse.Status.valid);
return f2CLicenseResponse;
}
F2CLicenseResponse f2CLicenseResponse = defaultLicenseService.validateLicense();
return f2CLicenseResponse;
}

View File

@ -1,5 +1,5 @@
<template>
<div v-if="!licstatus" class="lic">
<div v-if="!licValidate && licStatus !== 'no_record'" class="lic">
<strong>{{ $t(licMsg) }}</strong>
</div>
</template>
@ -20,9 +20,12 @@ export default {
theme() {
return this.$store.state.settings.theme
},
licstatus() {
licValidate() {
return this.$store.state.lic.validate
},
licStatus() {
return this.$store.state.lic.licStatus || ''
},
licMsg() {
return this.$store.state.lic.licMsg ? ('license.' + this.$store.state.lic.licMsg) : null
}

View File

@ -152,12 +152,8 @@ const hasPermission = (router, user_permissions) => {
}
return true
}
const xpackMenuNames = ['system-param', 'system-plugin']
const filterLic = (router) => {
if (xpackMenuNames.some(name => name === router.name) && !store.getters.validate) {
return false
}
return true
return !router.isPlugin || store.getters.validate
}
router.afterEach(() => {
// finish progress bar

View File

@ -1,6 +1,7 @@
import { validateLic } from '@/api/system/lic'
const state = {
validate: true,
licStatus: null,
licMsg: null
}
@ -10,6 +11,9 @@ const mutations = {
},
SET_LIC_MSG: (state, msg) => {
state.licMsg = msg
},
SET_LIC_STATUS: (state, data) => {
state.licStatus = data
}
}
@ -22,8 +26,15 @@ const actions = {
return new Promise((resolve, reject) => {
validateLic().then(response => {
const { data } = response
commit('SET_VALIDATE', true)
commit('SET_LIC_MSG', null)
if (data && data.status && data.status === 'no_record') {
commit('SET_VALIDATE', false)
commit('SET_LIC_MSG', data.message)
commit('SET_LIC_STATUS', data.status)
} else {
commit('SET_VALIDATE', true)
commit('SET_LIC_MSG', null)
}
resolve(data)
}).catch(error => {
commit('SET_VALIDATE', false)