diff --git a/vue-project/my-kintone-plugin/components.d.ts b/vue-project/my-kintone-plugin/components.d.ts
index fb726aa..19c9f84 100644
--- a/vue-project/my-kintone-plugin/components.d.ts
+++ b/vue-project/my-kintone-plugin/components.d.ts
@@ -17,5 +17,6 @@ declare module 'vue' {
PluginTableArea: typeof import('./src/components/basic/PluginTableArea.vue')['default']
PluginTableConditionRow: typeof import('./src/components/basic/PluginTableConditionRow.vue')['default']
PluginTableConnectRow: typeof import('./src/components/basic/PluginTableConnectRow.vue')['default']
+ TableCombobox: typeof import('./src/components/basic/TableCombobox.vue')['default']
}
}
diff --git a/vue-project/my-kintone-plugin/src/components/Config.vue b/vue-project/my-kintone-plugin/src/components/Config.vue
index 154ca55..3a5c1cb 100644
--- a/vue-project/my-kintone-plugin/src/components/Config.vue
+++ b/vue-project/my-kintone-plugin/src/components/Config.vue
@@ -18,9 +18,9 @@
diff --git a/vue-project/my-kintone-plugin/src/js/helper.ts b/vue-project/my-kintone-plugin/src/js/helper.ts
index 22efbe1..4c3f092 100644
--- a/vue-project/my-kintone-plugin/src/js/helper.ts
+++ b/vue-project/my-kintone-plugin/src/js/helper.ts
@@ -1,6 +1,6 @@
-import type { JoinTable } from '@/types/model';
+import type { FieldsInfo, JoinTable } from '@/types/model';
import type { KucDropdownItem } from '@/types/my-kintone';
-import { client, isType, type App, type Properties, type OneOf } from './kintone-rest-api-client';
+import { client, isType, type OneOf, type App, type Layout } from './kintone-rest-api-client';
export const condition = {
unset: '',
@@ -18,50 +18,87 @@ export function createEmptyJoinTable(id = Number(new Date())) {
}
export function resetTable(table: JoinTable) {
+ table.table = '';
table.whereConditions = [{ field: '', condition: condition.unset, data: '' }];
table.onConditions = [{ leftField: '', rightField: '' }];
table.fieldsMapping = [{ leftField: '', rightField: '' }];
}
+export const EMPTY_OPTION = {
+ value: "",
+ label: "--------",
+} as KucDropdownItem;
+
const LIMIT = 100; // 每次请求的最大应用数量
-let allAppsCache: KucDropdownItem[] = [];
-let allFieldsCache: Properties = {};
-export const fetchApps = async (offset = 0, _apps: KucDropdownItem[] = []): Promise => {
- if (allAppsCache.length) return allAppsCache;
+export const loadApps = async (offset = 0, _apps: KucDropdownItem[] = []): Promise => {
const { apps } = await client.app.getApps({ limit: LIMIT, offset });
const allApps: KucDropdownItem[] = [
..._apps,
...apps.map((app: App) => ({ value: app.appId, label: app.name + '(ID: ' + app.appId + ')' })),
];
if (apps.length === LIMIT) {
- return fetchApps(offset + LIMIT, allApps);
+ return loadApps(offset + LIMIT, allApps);
}
- allAppsCache = allApps.sort((a, b) => Number(b.value) - Number(a.value));
+ allApps.sort((a, b) => Number(b.value) - Number(a.value));
+ allApps.unshift(EMPTY_OPTION);
return allApps;
};
-export const fetchFields = async (appId: string, filter: OneOf['type']) => {
- let properties = allFieldsCache;
- if (!allFieldsCache.length) {
- properties = (await client.app.getFormFields({ app: appId })).properties;
- allFieldsCache = properties;
+export const loadAppFieldsAndLayout = async (appId: string | number = kintone.app.getId() as number) => {
+ return {
+ fields: (await client.app.getFormFields({ app: appId })).properties,
+ layout: (await client.app.getFormLayout({ app: appId })).layout,
+ } as FieldsInfo;
+};
+
+export const getFieldsDropdownItems = (
+ { fields, layout }: FieldsInfo,
+ subTable?: string,
+ filterType?: OneOf['type'],
+) => {
+ let fieldOrder: string[];
+ if (subTable) {
+ const subTableFields = layout.find((each) => each.type === 'SUBTABLE' && each.code === subTable) as any;
+ fieldOrder = subTableFields?.fields.map((field: { code: string }) => field.code) || [];
+ } else {
+ fieldOrder = extractNoSubTableFields(layout);
}
- const labels = Object.keys(properties).reduce((acc, fieldCode) => {
- const field = properties[fieldCode];
- if (filter && !isType[filter](field)) return acc;
+ return fieldOrder.reduce((acc, fieldCode) => {
+ const field = fields[fieldCode];
+ if (filterType && !isType[filterType](field)) return acc;
acc.push({
value: fieldCode,
label: field.label + '(FC: ' + fieldCode + ')',
});
return acc;
- }, [] as KucDropdownItem[]);
- return labels;
+ }, [EMPTY_OPTION]);
};
-export const getField = (fieldCode: string) => {
- const field = allFieldsCache[fieldCode];
- if (isType.SUBTABLE(field)) {
- console.log(field.fields);
- }
- return field;
+export const getTableFieldsDropdownItems = ({ fields }: FieldsInfo, filterType?: OneOf['type']) => {
+ return Object.keys(fields).reduce((acc, fieldCode) => {
+ const field = fields[fieldCode];
+ if (filterType && !isType[filterType](field)) return acc;
+ acc.push({
+ value: fieldCode,
+ label: field.label + '(FC: ' + fieldCode + ')',
+ });
+ return acc;
+ }, [EMPTY_OPTION]);
};
+
+const extractNoSubTableFields = (layout: Layout) => {
+ return layout.reduce((acc, each) => {
+ if (each.type === 'SUBTABLE') {
+ return acc;
+ } else if (each.type === 'ROW') {
+ acc.push(...each.fields.map((field: any) => field.code));
+ } else if (each.type === 'GROUP') {
+ acc.push(...extractNoSubTableFields(each.layout));
+ }
+ return acc;
+ }, [] as string[]);
+};
+
+// if (isType.SUBTABLE(field)) {
+// console.log(field.fields);
+// }
diff --git a/vue-project/my-kintone-plugin/src/js/kintone-rest-api-client.ts b/vue-project/my-kintone-plugin/src/js/kintone-rest-api-client.ts
index 8e11435..cf59117 100644
--- a/vue-project/my-kintone-plugin/src/js/kintone-rest-api-client.ts
+++ b/vue-project/my-kintone-plugin/src/js/kintone-rest-api-client.ts
@@ -8,6 +8,7 @@ export type App = {
};
export type Properties = Awaited>['properties'];
+export type Layout = Awaited>['layout'];
export type OneOf = Properties[string];
const typeNames = [
diff --git a/vue-project/my-kintone-plugin/src/types/model.d.ts b/vue-project/my-kintone-plugin/src/types/model.d.ts
index 035dab3..7ac164a 100644
--- a/vue-project/my-kintone-plugin/src/types/model.d.ts
+++ b/vue-project/my-kintone-plugin/src/types/model.d.ts
@@ -1,4 +1,7 @@
+import { Layout } from './../js/kintone-rest-api-client';
+import type { Layout } from '@/js/kintone-rest-api-client';
import { condition } from './helper';
+import type { KucDropdownItem } from './my-kintone';
export interface FieldsJoinMapping {
leftField: string;
@@ -24,4 +27,20 @@ export interface JoinTable {
export interface SavedData {
buttonName: string;
joinTables: JoinTable[];
-}
\ No newline at end of file
+}
+
+export interface FieldsInfo {
+ fields: Properties;
+ layout: Layout;
+}
+
+export interface CachedData {
+ apps: KucDropdownItem[],
+ currentAppFields: FieldsInfo,
+}
+
+export interface CachedSelectedAppData {
+ appFields: FieldsInfo,
+ loading: boolean,
+ table: JoinTable,
+}
diff --git a/vue-project/my-kintone-plugin/vite.config.ts b/vue-project/my-kintone-plugin/vite.config.ts
index 7c734d5..68449d1 100644
--- a/vue-project/my-kintone-plugin/vite.config.ts
+++ b/vue-project/my-kintone-plugin/vite.config.ts
@@ -66,6 +66,7 @@ export default defineConfig({
},
},
build: {
+ sourcemap: 'inline',
rollupOptions: {
input: {
config: path.resolve(__dirname, 'index.html'),