61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import i18n from '@/i18n';
|
||
import type { Setting } from '@/types';
|
||
import { LicenseService } from '@/services/LicenseService';
|
||
import client from '@/plugins/kintoneClient.ts'
|
||
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();
|
||
|
||
// 从插件配置中读取设置信息
|
||
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.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);
|
||
}
|
||
});
|
||
headerSpace.appendChild(button);
|
||
},
|
||
);
|
||
});
|
||
})(kintone.$PLUGIN_ID); |