|
|
|
|
@@ -1,30 +1,39 @@
|
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<kuc-combobox :value="optionValue" :items="options" @change="updateValue" :disabled="disabled" />
|
|
|
|
|
<div style="display: flex">
|
|
|
|
|
<kuc-combobox
|
|
|
|
|
:value="optionValue"
|
|
|
|
|
:items="options"
|
|
|
|
|
@change.stop="updateFuncValue"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:className="shortConditionClass"
|
|
|
|
|
:key="time"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div v-if="!optionValue">
|
|
|
|
|
<kuc-datetime-picker v-if="time" :value="dateTimeValue" @change="updateValue" :disabled="disabled" />
|
|
|
|
|
<kuc-date-picker v-else :value="dateTimeValue" @change="updateValue" :disabled="disabled" />
|
|
|
|
|
</div>
|
|
|
|
|
<template v-if="isInput">
|
|
|
|
|
<kuc-datetime-picker v-if="time" :value="dateTimeValue" @change.stop="updateValue" :disabled="disabled" />
|
|
|
|
|
<kuc-date-picker v-else :value="dateTimeValue" @change.stop="updateValue" :disabled="disabled" />
|
|
|
|
|
</template>
|
|
|
|
|
<kuc-combobox
|
|
|
|
|
v-else-if="isWeek"
|
|
|
|
|
:items="weekOptions"
|
|
|
|
|
:value="inputValue"
|
|
|
|
|
@change="updateValue"
|
|
|
|
|
@change.stop="updateValue"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:className="weekClassName"
|
|
|
|
|
/>
|
|
|
|
|
<kuc-combobox
|
|
|
|
|
v-else-if="isMonth"
|
|
|
|
|
:items="monthOptions"
|
|
|
|
|
:value="inputValue"
|
|
|
|
|
@change="updateValue"
|
|
|
|
|
@change.stop="updateValue"
|
|
|
|
|
:disabled="disabled"
|
|
|
|
|
:className="monthClassName"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { getComponent, getDateFuncList } from '@/js/conditions';
|
|
|
|
|
import { dateFuncList, dateFuncMap, getComponent, getDateFuncList, type DateFuncKey } from '@/js/conditions';
|
|
|
|
|
import { getFieldObj, search } from '@/js/helper';
|
|
|
|
|
import type { CachedSelectedAppData, WhereCondition } from '@/types/model';
|
|
|
|
|
import type { KucEvent } from '@/types/my-kintone';
|
|
|
|
|
@@ -37,34 +46,66 @@ const props = defineProps<{
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
// const regex = /^(?<func>\w+)\((?<val>.+)\)$|^(?<val>\d+)$/;
|
|
|
|
|
const dateTimeValue = ref('');
|
|
|
|
|
const inputValue = ref('');
|
|
|
|
|
const optionValue = ref('');
|
|
|
|
|
|
|
|
|
|
const isInput = computed(() => optionValue.value === dateFuncMap[''].value);
|
|
|
|
|
const isWeek = computed(() => optionValue.value?.indexOf('WEEK') >= 0);
|
|
|
|
|
const isMonth = computed(() => optionValue.value?.indexOf('MONTH') >= 0);
|
|
|
|
|
const isFromToday = computed(() => optionValue.value?.indexOf('FROM_TODAY') >= 0);
|
|
|
|
|
const weekClassName = computed(() => {
|
|
|
|
|
if (isWeek.value) {
|
|
|
|
|
return inputValue.value === DEFAULT_WEEK_MONTH ? 'week-all-combobox' : 'week-combobox';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
});
|
|
|
|
|
const monthClassName = computed(() => {
|
|
|
|
|
if (isMonth.value) {
|
|
|
|
|
return inputValue.value === DEFAULT_WEEK_MONTH ? 'month-all-combobox' : 'month-combobox';
|
|
|
|
|
}
|
|
|
|
|
return '';
|
|
|
|
|
});
|
|
|
|
|
const shortConditionClass = computed(() => {
|
|
|
|
|
return optionValue.value !== dateFuncMap[''].value &&
|
|
|
|
|
optionValue.value !== dateFuncMap['FROM_TODAY'].value &&
|
|
|
|
|
optionValue.value !== dateFuncMap['NOW'].value
|
|
|
|
|
? 'short datetime-condition-combobox'
|
|
|
|
|
: 'datetime-condition-combobox';
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const regex = /^(?<func>\w+)\((?<val>.*)\)$/;
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.value,
|
|
|
|
|
() => {
|
|
|
|
|
// const match = props.value.match(regex);
|
|
|
|
|
// const func = match?.groups?.func || '';
|
|
|
|
|
// optionValue.value = func;
|
|
|
|
|
if (props.value === '') {
|
|
|
|
|
// select default one when empty
|
|
|
|
|
optionValue.value = dateFuncMap[''].value;
|
|
|
|
|
inputValue.value = '';
|
|
|
|
|
dateTimeValue.value = '';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// const value = match?.groups?.val || '';
|
|
|
|
|
// inputValue.value = '';
|
|
|
|
|
// dateTimeValue.value = '';
|
|
|
|
|
console.log(props.value, props.value.match(regex));
|
|
|
|
|
const match = props.value.match(regex);
|
|
|
|
|
|
|
|
|
|
// if (!optionValue.value) {
|
|
|
|
|
// dateTimeValue.value = value;
|
|
|
|
|
// } else if (isWeek.value || isMonth.value) {
|
|
|
|
|
// inputValue.value = value;
|
|
|
|
|
// } else if (isFromToday.value) {
|
|
|
|
|
// // inputValue.value = value;
|
|
|
|
|
// // dateTimeValue.value = func;
|
|
|
|
|
// }
|
|
|
|
|
optionValue.value = dateFuncMap[(match?.groups?.func || '') as DateFuncKey].value;
|
|
|
|
|
|
|
|
|
|
const value = match?.groups?.val || (props.value.includes("%") ? '' : props.value);
|
|
|
|
|
|
|
|
|
|
inputValue.value = '';
|
|
|
|
|
dateTimeValue.value = '';
|
|
|
|
|
|
|
|
|
|
if (isInput.value) {
|
|
|
|
|
dateTimeValue.value = value;
|
|
|
|
|
} else if (isWeek.value || isMonth.value) {
|
|
|
|
|
inputValue.value = value || DEFAULT_WEEK_MONTH;
|
|
|
|
|
} else if (isFromToday.value) {
|
|
|
|
|
// inputValue.value = value;
|
|
|
|
|
// dateTimeValue.value = func;
|
|
|
|
|
}
|
|
|
|
|
console.log(optionValue.value, dateTimeValue.value, inputValue.value);
|
|
|
|
|
},
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
);
|
|
|
|
|
@@ -80,13 +121,26 @@ const emit = defineEmits<{
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const updateValue = (event: KucEvent<ComboboxChangeEventDetail>) => {
|
|
|
|
|
emit('change', { detail: { value: buildResult() } });
|
|
|
|
|
emit('change', { detail: { value: buildResult({ value: event.detail.value }) } });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function buildResult() {
|
|
|
|
|
return '';
|
|
|
|
|
const updateFuncValue = (event: KucEvent<ComboboxChangeEventDetail>) => {
|
|
|
|
|
inputValue.value = '';
|
|
|
|
|
dateTimeValue.value = '';
|
|
|
|
|
emit('change', { detail: { value: buildResult({ func: event.detail.value }) } });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function buildResult({ func = optionValue.value, value }: { func?: string; value?: string }) {
|
|
|
|
|
let val = value || dateTimeValue.value;
|
|
|
|
|
if (isWeek.value || isMonth.value) {
|
|
|
|
|
val = value || inputValue.value;
|
|
|
|
|
val = val === DEFAULT_WEEK_MONTH ? '' : val;
|
|
|
|
|
}
|
|
|
|
|
return func.replace('%s', val || '');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DEFAULT_WEEK_MONTH = '_';
|
|
|
|
|
|
|
|
|
|
const fromOptions = [
|
|
|
|
|
{ label: '日', value: 'DAYS' },
|
|
|
|
|
{ label: '周', value: 'WEEKS' },
|
|
|
|
|
@@ -95,7 +149,7 @@ const fromOptions = [
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const weekOptions = [
|
|
|
|
|
{ label: 'すべての曜日', value: '' },
|
|
|
|
|
{ label: 'すべての曜日', value: '_' },
|
|
|
|
|
{ label: '日', value: 'SUNDAY' },
|
|
|
|
|
{ label: '月', value: 'MONDAY' },
|
|
|
|
|
{ label: '火', value: 'TUESDAY' },
|
|
|
|
|
@@ -105,7 +159,7 @@ const weekOptions = [
|
|
|
|
|
{ label: '土', value: 'SATURDAY' },
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const monthOptions = [{ label: 'すべて', value: '' }];
|
|
|
|
|
const monthOptions = [{ label: 'すべて', value: '_' }];
|
|
|
|
|
for (let i = 1; i <= 31; i++) {
|
|
|
|
|
monthOptions.push({ label: i.toString() + '日', value: i.toString() });
|
|
|
|
|
}
|
|
|
|
|
|