feat(系统设置): lisence鉴定指令和全局状态
This commit is contained in:
parent
88f41220c8
commit
75797d1f6e
|
@ -1,8 +1,10 @@
|
|||
import { App } from 'vue';
|
||||
import permission from './permission';
|
||||
import validateLicense from './validateLicense';
|
||||
|
||||
export default {
|
||||
install(Vue: App) {
|
||||
Vue.directive('permission', permission);
|
||||
Vue.directive('xpack', validateLicense);
|
||||
},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
import useLicenseStore from '@/store/modules/setting/license';
|
||||
|
||||
/**
|
||||
* 权限指令,TODO:校验license
|
||||
* @param el dom 节点
|
||||
*/
|
||||
|
||||
function checkHasLicense(el: HTMLElement) {
|
||||
const licenseStore = useLicenseStore();
|
||||
const isValid = licenseStore.hasLicense();
|
||||
|
||||
if (!isValid && el.parentNode) {
|
||||
el.parentNode.removeChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
mounted(el: HTMLElement) {
|
||||
checkHasLicense(el);
|
||||
},
|
||||
updated(el: HTMLElement) {
|
||||
checkHasLicense(el);
|
||||
},
|
||||
};
|
|
@ -8,6 +8,6 @@ export interface License {
|
|||
}
|
||||
|
||||
export interface LicenseInfo {
|
||||
status?: string;
|
||||
license?: License;
|
||||
status: string;
|
||||
license: License;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
import { defineStore } from 'pinia';
|
||||
|
||||
const LicenseKey = 'License_Key';
|
||||
|
||||
const useLicenseStore = defineStore('userGroup', {
|
||||
state: (): { status: string | null } => ({
|
||||
status: '',
|
||||
}),
|
||||
actions: {
|
||||
setLicenseStatus(status: string) {
|
||||
this.$state.status = status;
|
||||
localStorage.setItem(LicenseKey, status);
|
||||
},
|
||||
removeLicenseStatus() {
|
||||
localStorage.removeItem(LicenseKey);
|
||||
},
|
||||
getLicenseStatus() {
|
||||
this.status = localStorage.getItem(LicenseKey);
|
||||
return this.status;
|
||||
},
|
||||
hasLicense() {
|
||||
this.getLicenseStatus();
|
||||
return this.status && this.status === 'valid';
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default useLicenseStore;
|
|
@ -1,8 +1,10 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { login as userLogin, logout as userLogout } from '@/api/modules/user';
|
||||
import { getLicenseInfo } from '@/api/modules/setting/authorizedManagement';
|
||||
import { setToken, clearToken } from '@/utils/auth';
|
||||
import { removeRouteListener } from '@/utils/route-listener';
|
||||
import useAppStore from '../app';
|
||||
import useLicenseStore from '../setting/license';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
|
||||
import type { LoginData } from '@/models/user';
|
||||
|
@ -64,6 +66,7 @@ const useUserStore = defineStore('user', {
|
|||
appStore.setCurrentOrgId(res.lastOrganizationId || '');
|
||||
}
|
||||
this.setInfo(res);
|
||||
this.getValidateLicense();
|
||||
} catch (err) {
|
||||
clearToken();
|
||||
throw err;
|
||||
|
@ -72,9 +75,11 @@ const useUserStore = defineStore('user', {
|
|||
// 登出回调
|
||||
logoutCallBack() {
|
||||
const appStore = useAppStore();
|
||||
const licenseStore = useLicenseStore();
|
||||
this.resetInfo();
|
||||
clearToken();
|
||||
removeRouteListener();
|
||||
licenseStore.removeLicenseStatus();
|
||||
appStore.clearServerMenu();
|
||||
appStore.hideLoading();
|
||||
},
|
||||
|
@ -89,6 +94,22 @@ const useUserStore = defineStore('user', {
|
|||
this.logoutCallBack();
|
||||
}
|
||||
},
|
||||
// license校验
|
||||
async getValidateLicense() {
|
||||
try {
|
||||
const licenseStore = useLicenseStore();
|
||||
const result = await getLicenseInfo();
|
||||
if (!result || !result.status || !result.license || !result.license.count) {
|
||||
return;
|
||||
}
|
||||
licenseStore.setLicenseStatus(result.status);
|
||||
if (result.status !== 'valid') {
|
||||
localStorage.setItem('setShowLicenseCountWarning', 'false');
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -12,46 +12,46 @@
|
|||
<li>
|
||||
<span>{{ t('system.authorized.customerName') }}</span>
|
||||
<div>
|
||||
<span>{{ licenseInfo.license?.corporation }}</span>
|
||||
<span>{{ licenseInfo?.license?.corporation }}</span>
|
||||
</div>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.authorizationTime') }}</span>
|
||||
<div
|
||||
><span>{{ licenseInfo.license?.expired }}</span></div
|
||||
><span>{{ licenseInfo?.license?.expired }}</span></div
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.productName') }}</span>
|
||||
<div
|
||||
><span>{{ licenseInfo.license?.product }}</span></div
|
||||
><span>{{ licenseInfo?.license?.product }}</span></div
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.productionVersion') }}</span>
|
||||
<div
|
||||
><span>{{ licenseInfo.license?.edition }}</span></div
|
||||
><span>{{ licenseInfo?.license?.edition }}</span></div
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.authorizedVersion') }}</span>
|
||||
<div>
|
||||
<span>{{ licenseInfo.license?.licenseVersion }}</span></div
|
||||
<span>{{ licenseInfo?.license?.licenseVersion }}</span></div
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.authorizationsCount') }}</span>
|
||||
<div
|
||||
><span>{{ licenseInfo.license?.count }}</span></div
|
||||
><span>{{ licenseInfo?.license?.count }}</span></div
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<span>{{ t('system.authorized.authorizationStatus') }}</span>
|
||||
<div
|
||||
><span>{{
|
||||
licenseInfo.status === 'valid'
|
||||
licenseInfo?.status === 'valid'
|
||||
? t('system.authorized.valid')
|
||||
: licenseInfo.status === 'expired'
|
||||
: licenseInfo?.status === 'expired'
|
||||
? t('system.authorized.invalid')
|
||||
: t('system.authorized.failure')
|
||||
}}</span></div
|
||||
|
@ -114,12 +114,14 @@
|
|||
import MsUpload from '@/components/pure/ms-upload/index.vue';
|
||||
import { FormInstance, Message, ValidatedError } from '@arco-design/web-vue';
|
||||
import MsButton from '@/components/pure/ms-button/index.vue';
|
||||
import useLicenseStore from '@/store/modules/setting/license';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
|
||||
const { t } = useI18n();
|
||||
const licenseStore = useLicenseStore();
|
||||
|
||||
const loading = ref<boolean>(false);
|
||||
const licenseInfo = ref<LicenseInfo>({});
|
||||
const licenseInfo = ref<LicenseInfo>();
|
||||
const authorizedForm = reactive<any>({
|
||||
licenseCode: '',
|
||||
});
|
||||
|
@ -130,6 +132,7 @@
|
|||
try {
|
||||
const result = await getLicenseInfo();
|
||||
licenseInfo.value = result;
|
||||
licenseStore.setLicenseStatus(licenseInfo.value?.status);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
} finally {
|
||||
|
|
Loading…
Reference in New Issue