fix: license失效时删除

This commit is contained in:
chenjianxing 2021-11-24 17:14:15 +08:00 committed by jianxing
parent 373109d563
commit c8eebede55
4 changed files with 40 additions and 11 deletions

View File

@ -43,9 +43,10 @@
</template>
<script>
import {LicenseKey} from '@/common/js/constants';
import {hasLicense} from "@/common/js/utils";
import {MODULE_CHANGE, ModuleEvent} from "@/business/components/common/head/ListEvent";
import {validateAndSetLicense} from "@/business/permission";
import axios from "axios";
// const requireContext = require.context('@/business/components/xpack/', true, /router\.js$/);
// const report = requireContext.keys().map(key => requireContext(key).report);
@ -74,19 +75,27 @@ export default {
}
this.handleSelect(this.activeIndex);
}
},
created() {
},
mounted() {
if (this.$route.matched.length > 0) {
this.activeIndex = this.$route.matched[0].path;
}
let license = localStorage.getItem(LicenseKey);
if (license != "valid") {
this.isReport = false;
} else {
if (module.default) {
module.default.listModules(this);
axios.get('/license/valid').then(response => {
validateAndSetLicense(response.data.data); // listModules license, axios
if (!hasLicense()) {
this.isReport = false;
} else {
if (module.default) {
module.default.listModules(this);
}
}
}
}).catch(error => {
window.console.error(error.response || error.message);
});
this.registerEvents();
},

@ -1 +1 @@
Subproject commit 3e5bfe95c48c06c9e8c459b041befb372824d5db
Subproject commit 8a79109a23a54ea7b4f0e2860a2da06733adc076

View File

@ -3,10 +3,11 @@ import {TokenKey} from '@/common/js/constants';
import {
enableModules,
hasLicense,
hasPermissions
hasPermissions, removeLicense, saveLicense
} from "@/common/js/utils";
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css'; // progress bar style
import 'nprogress/nprogress.css';
import {baseGet} from "@/network/base-network"; // progress bar style
const whiteList = ['/login']; // no redirect whitelist
NProgress.configure({showSpinner: false}); // NProgress Configuration
@ -101,3 +102,18 @@ router.afterEach(() => {
// finish progress bar
NProgress.done();
});
export function getLicense(callback) {
return baseGet("/license/valid", data => {
validateAndSetLicense(data);
if (callback) callback();
});
}
export function validateAndSetLicense(data) {
if (data === null || data.status !== 'valid') {
removeLicense();
} else {
saveLicense(data.status);
}
}

View File

@ -152,6 +152,10 @@ export function saveLicense(data) {
localStorage.setItem(LicenseKey, data);
}
export function removeLicense() {
localStorage.removeItem(LicenseKey);
}
export function jsonToMap(jsonStr) {
let obj = JSON.parse(jsonStr);
let strMap = new Map();