From c4999c480491dd0986e72ddb1cc16e56e332109f Mon Sep 17 00:00:00 2001 From: xuejiahao Date: Mon, 3 Nov 2025 15:46:06 +0800 Subject: [PATCH] fix format --- src/js/desktop.ts | 96 +++++++++++++++++++++++------------------------ src/js/mobile.ts | 88 +++++++++++++++++++++---------------------- 2 files changed, 90 insertions(+), 94 deletions(-) diff --git a/src/js/desktop.ts b/src/js/desktop.ts index c102caa..5ddec37 100644 --- a/src/js/desktop.ts +++ b/src/js/desktop.ts @@ -7,55 +7,53 @@ import { Button } from 'kintone-ui-component/lib/button'; (function (PLUGIN_ID) { kintone.events.on('app.record.index.show', async () => { // 授权了才能使用 - LicenseService.loadPluginIfAuthorized(PLUGIN_ID, - async () => { - // 获取当前应用ID - const appIdNum = kintone.app.getId(); - if (!appIdNum) { - return; + LicenseService.loadPluginIfAuthorized(PLUGIN_ID, async () => { + // 获取当前应用ID + const appIdNum = kintone.app.getId(); + if (!appIdNum) { + return; + } + const appId = appIdNum.toString(); + + // 从插件配置中读取设置信息 + const setting: Setting = kintone.plugin.app.getConfig(PLUGIN_ID); + + // 检查按钮是否已存在,防止翻页时重复添加 + const btnId = 'template-btn-id'; + if (document.getElementById(btnId)) { + return; + } + + // 测试 i18n + const { t } = i18n.global; + + // 获取 Header 容器元素 + const headerSpace = kintone.app.getHeaderMenuSpaceElement(); + if (!headerSpace) { + throw new Error(t('error.noAreaError')); + } + + // 创建按钮 + const button = new Button({ + text: setting.buttonName, + type: 'submit', + id: btnId, + }); + button.addEventListener('click', async () => { + try { + // 测试 KintoneRestAPIClient,显示所有已启用的插件名 + const { plugins } = await client.app.getPlugins({ + app: appId, + }); + const pluginsInfo = plugins.map((p) => p.name).join('、'); + + const message = t('hello') + '\n' + setting.message + '\n--------\n【Plugins】 ' + pluginsInfo; + alert(message); + } catch (error) { + console.error('Failed to fetch plugins:', error); } - const appId = appIdNum.toString(); - - // 从插件配置中读取设置信息 - const setting: Setting = kintone.plugin.app.getConfig(PLUGIN_ID); - - // 检查按钮是否已存在,防止翻页时重复添加 - const btnId = 'template-btn-id'; - if (document.getElementById(btnId)) { - return; - } - - // 测试 i18n - const { t } = i18n.global; - - // 获取 Header 容器元素 - const headerSpace = kintone.app.getHeaderMenuSpaceElement(); - if (!headerSpace) { - throw new Error(t('error.noAreaError')); - } - - // 创建按钮 - const button = new Button({ - text: setting.buttonName, - type: 'submit', - id: btnId, - }); - button.addEventListener('click', async () => { - try { - // 测试 KintoneRestAPIClient,显示所有已启用的插件名 - const { plugins } = await client.app.getPlugins({ - app: appId, - }); - const pluginsInfo = plugins.map((p) => p.name).join('、'); - - const message = t('hello') + '\n' + setting.message + '\n--------\n【Plugins】 ' + pluginsInfo; - alert(message); - } catch (error) { - console.error('Failed to fetch plugins:', error); - } - }); - headerSpace.appendChild(button); - }, - ); + }); + headerSpace.appendChild(button); + }); }); })(kintone.$PLUGIN_ID); diff --git a/src/js/mobile.ts b/src/js/mobile.ts index 8e25121..a5ead44 100644 --- a/src/js/mobile.ts +++ b/src/js/mobile.ts @@ -7,55 +7,53 @@ import { MobileButton } from 'kintone-ui-component/lib/mobile/button'; (function (PLUGIN_ID) { kintone.events.on('mobile.app.record.index.show', () => { // 授权了才能使用 - LicenseService.loadPluginIfAuthorized(PLUGIN_ID, - async () => { - // 获取当前应用ID - const appIdNum = kintone.mobile.app.getId(); - if (!appIdNum) { - return; - }; - const appId = appIdNum.toString(); + LicenseService.loadPluginIfAuthorized(PLUGIN_ID, async () => { + // 获取当前应用ID + const appIdNum = kintone.mobile.app.getId(); + if (!appIdNum) { + return; + }; + const appId = appIdNum.toString(); - // 从插件配置中读取设置信息 - const setting: Setting = kintone.plugin.app.getConfig(PLUGIN_ID); + // 从插件配置中读取设置信息 + const setting: Setting = kintone.plugin.app.getConfig(PLUGIN_ID); - // 检查按钮是否已存在,防止翻页时重复添加 - const btnId = 'template-btn-id'; - if (document.getElementById(btnId)) { - return; - }; + // 检查按钮是否已存在,防止翻页时重复添加 + const btnId = 'template-btn-id'; + if (document.getElementById(btnId)) { + return; + }; - // 测试 i18n - const { t } = i18n.global; + // 测试 i18n + const { t } = i18n.global; - // 获取 Header 容器元素 - const headerSpace = kintone.mobile.app.getHeaderSpaceElement(); - if (!headerSpace) { - throw new Error(t('error.noAreaError')); + // 获取 Header 容器元素 + const headerSpace = kintone.mobile.app.getHeaderSpaceElement(); + if (!headerSpace) { + throw new Error(t('error.noAreaError')); + } + + // 创建按钮 + const button = new MobileButton({ + text: setting.buttonName, + type: 'submit', + id: btnId, + }); + button.addEventListener('click', async () => { + try { + // 测试 KintoneRestAPIClient,显示所有已启用的插件名 + const { plugins } = await client.app.getPlugins({ + app: appId, + }); + const pluginsInfo = plugins.map((p) => p.name).join('、'); + + const message = t('hello') + "\n" + setting.message + '\n--------\n【Plugins】 ' + pluginsInfo; + alert(message); + } catch (error) { + console.error('Failed to fetch plugins:', error); } - - // 创建按钮 - const button = new MobileButton({ - text: setting.buttonName, - type: 'submit', - id: btnId, - }); - button.addEventListener('click', async () => { - try { - // 测试 KintoneRestAPIClient,显示所有已启用的插件名 - const { plugins } = await client.app.getPlugins({ - app: appId, - }); - const pluginsInfo = plugins.map((p) => p.name).join('、'); - - const message = t('hello') + "\n" + setting.message + '\n--------\n【Plugins】 ' + pluginsInfo; - alert(message); - } catch (error) { - console.error('Failed to fetch plugins:', error); - } - }); - headerSpace.appendChild(button); - }, - ); + }); + headerSpace.appendChild(button); + }); }); })(kintone.$PLUGIN_ID); \ No newline at end of file