improve UIUX

This commit is contained in:
2025-10-23 14:32:39 +08:00
parent 7a3eb40aa9
commit 8565b9513d
8 changed files with 285 additions and 98 deletions

View File

@@ -7,7 +7,7 @@ import { MobileNotification } from 'kintone-ui-component/lib/mobile/notification
export class LicenseService {
// 常量定义
private static readonly WARNING_DAYS_BEFORE_EXPIRY = 7;
private static readonly TRIAL_DATE = 1;
private static readonly TRIAL_DATE = 30;
private static PLUGIN_ID: string = '';
// ============ 基础工具函数 ============
@@ -22,7 +22,7 @@ export class LicenseService {
* 获取插件ID
*/
static getPluginId(): string {
return this.PLUGIN_ID;
return this.PLUGIN_ID || new URLSearchParams(window.location.search).get('pluginId') || '';
}
/**
@@ -122,7 +122,7 @@ export class LicenseService {
*/
static formatExpiryDate(timestamp: number): string {
if (timestamp === -1) return '永久';
return new Date(timestamp).toLocaleDateString('zh-CN');
return new Date(timestamp).toLocaleDateString(kintone.getLoginUser().language);
}
/**
@@ -132,7 +132,7 @@ export class LicenseService {
if (timestamp === -1) return Infinity;
const now = new Date().getTime();
const remainingMs = timestamp - now;
return Math.ceil(remainingMs / (24 * 60 * 60 * 1000));
return Math.floor(remainingMs / (24 * 60 * 60 * 1000));
}
/**
@@ -167,28 +167,32 @@ export class LicenseService {
warningDialogMessage?: string;
}) {
const remainingDays = this.getDaysRemaining(license.expiredTime);
const msg = remainingDays > 0 ? ` ${remainingDays} 天后` : '今天'
const defaultMessage = `您的插件许可证将在${msg}到期,请及时续期以避免服务中断。`;
if (remainingDays <= 0) {
return
}
const msg = remainingDays > 1 ? ` ${remainingDays} 天后` : (remainingDays > 0 ? '明天' : '今天')
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());
// const settings = LicenseStorage.getSettings(this.getPluginId());
// if (settings.suppressMsgTime && this.isToday(settings.suppressMsgTime)) {
// return
// }
// delete settings.suppressMsgTime
// LicenseStorage.saveSetting(settings, this.getPluginId());
if (await kintone.isMobilePage()) {
const notification = new MobileNotification({
text: message,
content: message,
});
notification.open();
} else {
const notification = new Notification({
text: message,
content: message,
type: 'info',
});
notification.open();
@@ -279,6 +283,7 @@ export class LicenseService {
private static mockCreateTrialLicense(): LicenseInfo {
const expiryDate = new Date();
expiryDate.setDate(expiryDate.getDate() + this.TRIAL_DATE);
expiryDate.setHours(23, 59, 59, 999);
return {
expiredTime: expiryDate.getTime(),