refactoring
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user