diff --git a/vue-project/my-kintone-plugin/components.d.ts b/vue-project/my-kintone-plugin/components.d.ts
index 19c9f84..7455103 100644
--- a/vue-project/my-kintone-plugin/components.d.ts
+++ b/vue-project/my-kintone-plugin/components.d.ts
@@ -17,6 +17,7 @@ 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']
+ TableCombobox: typeof import('./src/components/basic/condition/TableCombobox.vue')['default']
+ TableInput: typeof import('./src/components/basic/condition/TableInput.vue')['default']
}
}
diff --git a/vue-project/my-kintone-plugin/env.d.ts b/vue-project/my-kintone-plugin/env.d.ts
index 1a06ebe..528bb9b 100644
--- a/vue-project/my-kintone-plugin/env.d.ts
+++ b/vue-project/my-kintone-plugin/env.d.ts
@@ -1,2 +1,8 @@
///
-///
\ No newline at end of file
+///
+
+declare module '*.vue' {
+ import { DefineComponent } from 'vue';
+ const component: DefineComponent<{}, {}, any>;
+ export default component;
+}
diff --git a/vue-project/my-kintone-plugin/src/components/Config.vue b/vue-project/my-kintone-plugin/src/components/Config.vue
index 3a5c1cb..70c1be0 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/components/basic/PluginTableConnectRow.vue b/vue-project/my-kintone-plugin/src/components/basic/PluginTableConnectRow.vue
index 91fa0d3..309294a 100644
--- a/vue-project/my-kintone-plugin/src/components/basic/PluginTableConnectRow.vue
+++ b/vue-project/my-kintone-plugin/src/components/basic/PluginTableConnectRow.vue
@@ -1,21 +1,18 @@
-
+
diff --git a/vue-project/my-kintone-plugin/src/components/basic/TableCombobox.vue b/vue-project/my-kintone-plugin/src/components/basic/condition/TableCombobox.vue
similarity index 100%
rename from vue-project/my-kintone-plugin/src/components/basic/TableCombobox.vue
rename to vue-project/my-kintone-plugin/src/components/basic/condition/TableCombobox.vue
diff --git a/vue-project/my-kintone-plugin/src/components/basic/condition/TableInput.vue b/vue-project/my-kintone-plugin/src/components/basic/condition/TableInput.vue
new file mode 100644
index 0000000..3437caf
--- /dev/null
+++ b/vue-project/my-kintone-plugin/src/components/basic/condition/TableInput.vue
@@ -0,0 +1,22 @@
+
+
+
+
+
diff --git a/vue-project/my-kintone-plugin/src/js/conditions.ts b/vue-project/my-kintone-plugin/src/js/conditions.ts
new file mode 100644
index 0000000..a2e592a
--- /dev/null
+++ b/vue-project/my-kintone-plugin/src/js/conditions.ts
@@ -0,0 +1,38 @@
+import TableCombobox from '@/components/basic/condition/TableCombobox.vue';
+import TableInput from '@/components/basic/condition/TableInput.vue';
+
+const component = {
+ '': undefined,
+ input: TableInput,
+ select: TableCombobox,
+};
+export type ComponentType = keyof typeof component;
+
+export type ConditionValue = '' | 'eq' | 'ne';
+
+type ConditionItem = {
+ value: ConditionValue;
+ label: string;
+ type: ComponentType;
+ func: (a: string, b: string) => boolean;
+};
+
+export const conditionList: ConditionItem[] = [
+ { value: '', label: '--------', type: '', func: (a: string, b: string) => true },
+ { value: 'eq', label: '=(等しい)', type: 'input', func: (a: string, b: string) => a === b },
+ { value: 'ne', label: '≠ (等しくない)', type: 'input', func: (a: string, b: string) => a !== b },
+];
+
+// type ConditionItem = (typeof conditionList)[number];
+
+export const conditionMap: Record = conditionList.reduce(
+ (map, item) => {
+ map[item.value] = item;
+ return map;
+ },
+ {} as Record,
+);
+
+export const getComponent = (value: ConditionValue) => {
+ return component[conditionMap[value].type];
+};
diff --git a/vue-project/my-kintone-plugin/src/js/helper.ts b/vue-project/my-kintone-plugin/src/js/helper.ts
index 4c3f092..6647644 100644
--- a/vue-project/my-kintone-plugin/src/js/helper.ts
+++ b/vue-project/my-kintone-plugin/src/js/helper.ts
@@ -1,38 +1,37 @@
-import type { FieldsInfo, JoinTable } from '@/types/model';
-import type { KucDropdownItem } from '@/types/my-kintone';
+import type { FieldsInfo, JoinTable, WhereCondition } from '@/types/model';
import { client, isType, type OneOf, type App, type Layout } from './kintone-rest-api-client';
+import type { DropdownItem } from 'kintone-ui-component';
+
+
+export const EMPTY_OPTION = {
+ value: '',
+ label: '--------',
+} as DropdownItem;
+
+export const getEmptyWhereCondition = () => ({ field: '', condition: '', data: '' } as WhereCondition);
+export const getEmptyOnCondition = () => ({ leftField: '', rightField: '' });
+export const getEmptyFieldsMapping = () => ({ leftField: '', rightField: '' });
-export const condition = {
- unset: '',
- eq: '=',
-};
export function createEmptyJoinTable(id = Number(new Date())) {
- return {
- id,
- app: '',
- table: '',
- onConditions: [{ leftField: '', rightField: '' }],
- fieldsMapping: [{ leftField: '', rightField: '' }],
- whereConditions: [{ field: '', condition: condition.unset, data: '' }],
- } as JoinTable;
+ return resetTable({ id, app: '' } as JoinTable);
}
export function resetTable(table: JoinTable) {
table.table = '';
- table.whereConditions = [{ field: '', condition: condition.unset, data: '' }];
- table.onConditions = [{ leftField: '', rightField: '' }];
- table.fieldsMapping = [{ leftField: '', rightField: '' }];
+ return resetConditions(table);
}
-export const EMPTY_OPTION = {
- value: "",
- label: "--------",
-} as KucDropdownItem;
+export function resetConditions(table: JoinTable) {
+ table.onConditions = [getEmptyOnCondition()];
+ table.fieldsMapping = [getEmptyFieldsMapping()];
+ table.whereConditions = [getEmptyWhereCondition()];
+ return table;
+}
const LIMIT = 100; // 每次请求的最大应用数量
-export const loadApps = async (offset = 0, _apps: KucDropdownItem[] = []): Promise => {
+export const loadApps = async (offset = 0, _apps: DropdownItem[] = []): Promise => {
const { apps } = await client.app.getApps({ limit: LIMIT, offset });
- const allApps: KucDropdownItem[] = [
+ const allApps: DropdownItem[] = [
..._apps,
...apps.map((app: App) => ({ value: app.appId, label: app.name + '(ID: ' + app.appId + ')' })),
];
@@ -53,37 +52,47 @@ export const loadAppFieldsAndLayout = async (appId: string | number = kintone.ap
export const getFieldsDropdownItems = (
{ fields, layout }: FieldsInfo,
- subTable?: string,
+ subTableCode?: string,
filterType?: OneOf['type'],
) => {
+ // get used field codes
let fieldOrder: string[];
- if (subTable) {
- const subTableFields = layout.find((each) => each.type === 'SUBTABLE' && each.code === subTable) as any;
+ let fieldMap = fields;
+ if (subTableCode) {
+ const subTableFields = layout.find((each) => each.type === 'SUBTABLE' && each.code === subTableCode) as any;
fieldOrder = subTableFields?.fields.map((field: { code: string }) => field.code) || [];
+ fieldMap = fieldMap[subTableCode].fields;
} else {
fieldOrder = extractNoSubTableFields(layout);
}
- 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;
- }, [EMPTY_OPTION]);
+ // create labels
+ return fieldOrder.reduce(
+ (acc, fieldCode) => {
+ const field = fieldMap[fieldCode];
+ if (!fieldCode || filterType && !isType[filterType](field)) return acc;
+ acc.push({
+ value: fieldCode,
+ label: field.label + '(FC: ' + fieldCode + ')',
+ });
+ return acc;
+ },
+ [EMPTY_OPTION],
+ );
};
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]);
+ 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) => {
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 7ac164a..c5cd67c 100644
--- a/vue-project/my-kintone-plugin/src/types/model.d.ts
+++ b/vue-project/my-kintone-plugin/src/types/model.d.ts
@@ -1,7 +1,6 @@
-import { Layout } from './../js/kintone-rest-api-client';
+import type { ConditionValue } from '@/js/conditions';
import type { Layout } from '@/js/kintone-rest-api-client';
-import { condition } from './helper';
-import type { KucDropdownItem } from './my-kintone';
+import type { DropdownItem } from 'kintone-ui-component';
export interface FieldsJoinMapping {
leftField: string;
@@ -10,7 +9,7 @@ export interface FieldsJoinMapping {
export interface WhereCondition {
field: string;
- condition: (typeof condition)[keyof typeof condition];
+ condition: ConditionValue;
data: string;
}
@@ -35,7 +34,7 @@ export interface FieldsInfo {
}
export interface CachedData {
- apps: KucDropdownItem[],
+ apps: DropdownItem[],
currentAppFields: FieldsInfo,
}
diff --git a/vue-project/my-kintone-plugin/src/types/my-kintone.d.ts b/vue-project/my-kintone-plugin/src/types/my-kintone.d.ts
index 1c0d110..7e32aee 100644
--- a/vue-project/my-kintone-plugin/src/types/my-kintone.d.ts
+++ b/vue-project/my-kintone-plugin/src/types/my-kintone.d.ts
@@ -1,15 +1,3 @@
-// 组件相关
-export interface KucDropdownItem {
- label: string;
- value: string;
- disabled?: boolean;
-}
-
-export interface KucSpinnerEl {
- open: function;
- close: function;
-}
-
export interface KucEvent {
detail: {
value: string;