refactoring

This commit is contained in:
2025-10-17 14:34:26 +08:00
parent 8e40f9f0e6
commit 7ddaeb4bf8
16 changed files with 339 additions and 265 deletions

View File

@@ -1,35 +1,52 @@
import type { Setting } from '@/types/model';
import type { Setting } from '@/types';
import { KintoneRestAPIClient } from '@kintone/rest-api-client';
import { MobileButton } from 'kintone-ui-component/lib/mobile/button';
(function (PLUGIN_ID) {
kintone.events.on('mobile.app.record.index.show', () => {
// App id
const appId = kintone.mobile.app.getId()?.toString();
if (!appId) return;
// 获取当前应用ID
const appIdNum = kintone.mobile.app.getId();
if (!appIdNum) {
return;
};
const appId = appIdNum.toString();
// get setting
// 从插件配置中读取设置信息
const setting: Setting = kintone.plugin.app.getConfig(PLUGIN_ID);
// header space
// 检查按钮是否已存在,防止翻页时重复添加
const btnId = 'template-btn-id';
if (document.getElementById(btnId)) {
return;
};
// 获取 Header 容器元素
const headerSpace = kintone.mobile.app.getHeaderSpaceElement();
if (!headerSpace) {
throw new Error('このページではヘッダー要素が利用できません。');
}
const btnId = 'template-btn-id';
// ボタン追加
if (document.getElementById(btnId)) return;
const button = new Kucs[KUC_VERSION].MobileButton({
// 创建按钮
const button = new MobileButton({
text: setting.buttonName,
type: 'submit',
id: btnId,
});
const client = new KintoneRestAPIClient();
button.addEventListener('click', async () => {
const { plugins } = await client.app.getPlugins({
app: appId
})
alert(setting.message + "\n--------\n【Plugins】 " + plugins.map(p => p.name).join('、'));
try {
// 测试 KintoneRestAPIClient显示所有已启用的插件名
const client = new KintoneRestAPIClient();
const { plugins } = await client.app.getPlugins({
app: appId,
});
const pluginsInfo = plugins.map((p) => p.name).join('、');
const message = setting.message + '\n--------\n【Plugins】 ' + pluginsInfo;
alert(message);
} catch (error) {
console.error('Failed to fetch plugins:', error);
}
});
headerSpace.appendChild(button);
});