fix i18n
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import type { LicenseInfo, LicenseCheckResult } from '@/types/license';
|
||||
import i18n from '@/i18n';
|
||||
import { LicenseStorage } from '@/utils/LicenseStorage';
|
||||
import { PermissionService } from '@/utils/permissions';
|
||||
import { Notification } from 'kintone-ui-component/lib/notification';
|
||||
import { MobileNotification } from 'kintone-ui-component/lib/mobile/notification';
|
||||
|
||||
const { t: $t } = i18n.global;
|
||||
|
||||
export class LicenseService {
|
||||
// 常量定义
|
||||
private static readonly WARNING_DAYS_BEFORE_EXPIRY = 7;
|
||||
@@ -98,7 +101,7 @@ export class LicenseService {
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error('Remote license check failed:', error);
|
||||
console.error($t('license.error.fetchFailed', { e: error }));
|
||||
return {
|
||||
isLicenseValid: true,
|
||||
};
|
||||
@@ -121,7 +124,7 @@ export class LicenseService {
|
||||
* 格式化到期时间
|
||||
*/
|
||||
static formatExpiryDate(timestamp: number): string {
|
||||
if (timestamp === -1) return '永久';
|
||||
if (timestamp === -1) return $t('license.status.permanent');
|
||||
return new Date(timestamp).toLocaleDateString(kintone.getLoginUser().language);
|
||||
}
|
||||
|
||||
@@ -135,56 +138,26 @@ export class LicenseService {
|
||||
return Math.floor(remainingMs / (24 * 60 * 60 * 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取许可证显示信息
|
||||
*/
|
||||
static getLicenseDisplayInfo(license: any) {
|
||||
if (!license) return null;
|
||||
|
||||
return {
|
||||
domain: this.getDomain(),
|
||||
plugin: this.getPluginId(),
|
||||
expiryDate: this.formatExpiryDate(license.expiredTime)
|
||||
};
|
||||
}
|
||||
|
||||
// ============ UI显示函数 ============
|
||||
|
||||
/**
|
||||
* 显示到期弹框
|
||||
*/
|
||||
static showExpiryModal(licenseInfo: any, options?: {
|
||||
expiryDialogTitle?: string;
|
||||
expiryDialogMessage?: string;
|
||||
}) {
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示到期警告通知
|
||||
*/
|
||||
static async showExpiryWarning(license: any, options?: {
|
||||
warningDialogMessage?: string;
|
||||
}) {
|
||||
const remainingDays = this.getDaysRemaining(license.expiredTime);
|
||||
if (remainingDays <= 0) {
|
||||
return
|
||||
}
|
||||
const msg = remainingDays > 1 ? ` ${remainingDays} 天后` : (remainingDays > 0 ? '明天' : '今天')
|
||||
static async showNotification(license: LicenseInfo | undefined, isWarning: boolean) {
|
||||
let message;
|
||||
const link = `https://alicorn.cybozu.com/k/admin/app/${kintone.app.getId()}/plugin/config?pluginId=${this.getPluginId()}`
|
||||
const defaultMessage = `您的插件将在${msg}试用结束<br>如需使用请进入<a class="notification-link" href="${link}">「プラグインの設定」</a>查看详情。`;
|
||||
|
||||
// 使用自定义消息或默认消息
|
||||
const message = options?.warningDialogMessage || defaultMessage;
|
||||
|
||||
// 检查是否已设置不再提醒
|
||||
// const settings = LicenseStorage.getSettings(this.getPluginId());
|
||||
// if (settings.suppressMsgTime && this.isToday(settings.suppressMsgTime)) {
|
||||
// return
|
||||
// }
|
||||
// delete settings.suppressMsgTime
|
||||
// LicenseStorage.saveSetting(settings, this.getPluginId());
|
||||
|
||||
if (isWarning) {
|
||||
// 尚未到期
|
||||
const remainingDays = this.getDaysRemaining(license!.expiredTime);
|
||||
if (remainingDays < 0) {
|
||||
return
|
||||
}
|
||||
const days = $t('license.notification.days', remainingDays)
|
||||
message = $t('license.notification.warning', { plugin: this.getPluginId(), link, days });
|
||||
} else {
|
||||
// 既に期限切れ
|
||||
message = $t('license.notification.expired', { plugin: this.getPluginId(), link });
|
||||
}
|
||||
if (await kintone.isMobilePage()) {
|
||||
const notification = new MobileNotification({
|
||||
content: message,
|
||||
@@ -193,7 +166,7 @@ export class LicenseService {
|
||||
} else {
|
||||
const notification = new Notification({
|
||||
content: message,
|
||||
type: 'info',
|
||||
type: isWarning ? 'info' : 'danger',
|
||||
});
|
||||
notification.open();
|
||||
}
|
||||
@@ -207,11 +180,6 @@ export class LicenseService {
|
||||
static async loadPluginIfAuthorized(
|
||||
pluginId: string,
|
||||
callback: () => void | Promise<void>,
|
||||
options?: {
|
||||
expiryDialogTitle?: string;
|
||||
expiryDialogMessage?: string;
|
||||
warningDialogMessage?: string;
|
||||
}
|
||||
) {
|
||||
this.PLUGIN_ID = pluginId;
|
||||
try {
|
||||
@@ -222,18 +190,14 @@ export class LicenseService {
|
||||
const permissions = await PermissionService.checkPermissions();
|
||||
const isManager = permissions.canManagePlugins;
|
||||
|
||||
// 许可证无效的情况
|
||||
// 许可证无效的情况,直接返回不加载
|
||||
if (!licenseCheck.isLicenseValid) {
|
||||
if (!isManager) {
|
||||
// 普通用户静默输出
|
||||
console.warn('License check failed, plugin functionality disabled');
|
||||
console.warn($t('license.status.expiredDisplay'));
|
||||
} else {
|
||||
// 管理员可以看到过期弹框
|
||||
alert('许可证无效')
|
||||
// this.showExpiryModal(this.getLicenseDisplayInfo(license.license), {
|
||||
// expiryDialogTitle: options?.expiryDialogTitle,
|
||||
// expiryDialogMessage: options?.expiryDialogMessage
|
||||
// });
|
||||
this.showNotification(licenseCheck.license, false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -244,16 +208,14 @@ export class LicenseService {
|
||||
!licenseCheck.license.isPaid &&
|
||||
this.isExpiringSoon(licenseCheck.license.expiredTime)) {
|
||||
// 管理员可以看到过期弹框
|
||||
this.showExpiryWarning(licenseCheck.license, {
|
||||
warningDialogMessage: options?.warningDialogMessage
|
||||
});
|
||||
this.showNotification(licenseCheck.license, true);
|
||||
}
|
||||
|
||||
// 许可证有效,可以加载插件功能
|
||||
await callback();
|
||||
|
||||
} catch (error) {
|
||||
console.error('License check failed, plugin functionality disabled:', error);
|
||||
console.warn($t('license.error.checkFailed'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user