This commit is contained in:
hsueh chiahao
2025-10-10 14:06:20 +08:00
parent a5dead4259
commit 5fb4af26ff
17 changed files with 1381 additions and 646 deletions

79
utils/kintone-utils.js Normal file
View File

@@ -0,0 +1,79 @@
/**
* Kintone API 工具模块
* 提供与 Kintone 应用程序交互的通用工具函数
*/
/**
* 从当前 URL 中提取 Guest Space ID
* @returns {string|undefined} Guest Space ID如果未找到则为 undefined
*/
export const getGuestSpaceId = () => {
try {
const match = window.location.pathname.match(/\/guest\/([0-9]+)\//);
return match ? match[1] : undefined;
} catch (error) {
console.warn(error);
return undefined;
}
};
/**
* 从 Kintone 获取当前 APP ID
* @returns {number|null} APP ID如果没有为 null
*/
export const getAppId = () => {
try {
// TODO 在 admin 页面
if (!isGlobalKintoneExist()) {
return null;
}
const appId = kintone.app.getId();
if (!appId || isNaN(appId)) {
console.warn('Retrieved app ID is invalid:', appId);
return null;
}
return appId;
} catch (error) {
console.warn('Failed to get app ID: ', error);
return null;
}
};
export const isGlobalKintoneExist = () => {
return typeof kintone !== 'undefined' && typeof kintone.app !== 'undefined';
};
/**
* 是否在 Kintone App 中
* @returns {boolean} 是否在 App 中
*/
export const isInAppPage = () => {
return isGlobalKintoneExist() && /^\/k\/\d+/.test(window.location.pathname);
};
/**
* 是否在 Kintone App Detail 中
* @returns {boolean} 是否在 App 中
*/
export const isInDetailPage = () => {
return isGlobalKintoneExist() && /^\/k\/\d+\/show/.test(window.location.pathname);
};
/**
* 是否在 Kintone App 的 /admin 页面
* @returns {boolean} 是否在 App /admin 页面
*/
export const isInAdminPage = () => {
return !isGlobalKintoneExist() && window.location.pathname.includes('/k/admin');
};
/**
* 是否在 Kintone 的 space 页面
* @returns {boolean} 是否在 space 页面
*/
export const isInSpacePage = () => {
return isGlobalKintoneExist() && window.location.pathname.includes('/k/#/space');
};