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