Browse Source

增加w-date-range模式属性

main
likunming 2 months ago
parent
commit
19d65bdc69
  1. 18
      io.sc.platform.core.frontend/src/platform/components/date/WDate.vue
  2. 55
      io.sc.platform.core.frontend/src/platform/components/date/WDateRange.vue
  3. 41
      io.sc.platform.core.frontend/src/platform/components/grid/ts/function/Criteria.ts
  4. 13
      io.sc.platform.core.frontend/src/platform/components/grid/ts/toolbar/buttons/Query.ts
  5. 1
      io.sc.platform.core.frontend/src/platform/components/workflow/WWorkflowAction.vue
  6. 1
      io.sc.platform.core.frontend/src/platform/index.ts

18
io.sc.platform.core.frontend/src/platform/components/date/WDate.vue

@ -24,8 +24,18 @@
</template>
<template v-if="!fieldMethodsClass.getReadOnly(props, modelValue)" #append>
<q-icon name="event" class="cursor-pointer">
<q-popup-proxy cover transition-show="scale" transition-hide="scale" auto-close>
<q-date v-model="modelValue" today-btn mask="YYYY-MM-DD" @update:model-value="fieldMethodsClass.updateValue"> </q-date>
<q-popup-proxy ref="proxyRef" cover transition-show="scale" transition-hide="scale">
<q-date
v-if="attrs.options"
v-model="modelValue"
:options="attrs.options"
today-btn
mask="YYYY-MM-DD"
@update:model-value="fieldMethodsClass.updateValue"
>
</q-date>
<q-date v-else v-model="modelValue" :options="attrs.options" today-btn mask="YYYY-MM-DD" @update:model-value="fieldMethodsClass.updateValue">
</q-date>
</q-popup-proxy>
</q-icon>
</template>
@ -48,6 +58,7 @@ const dateRef = ref();
const attrs = useAttrs();
const slots = useSlots();
const modelValue = defineModel<string>();
const proxyRef = ref();
interface FieldProps extends FormFieldProps {}
const props = withDefaults(defineProps<FieldProps>(), {
@ -82,6 +93,9 @@ const fieldMethodsClass = new FieldMethods();
watch(
() => modelValue.value,
(newVal, oldVal) => {
if (!Tools.isEmpty(newVal)) {
proxyRef.value.hide();
}
if (!Tools.isEmpty(newVal) && newVal !== oldVal && newVal.length > 10) {
modelValue.value = newVal?.substring(0, 10);
}

55
io.sc.platform.core.frontend/src/platform/components/date/WDateRange.vue

@ -1,5 +1,48 @@
<template>
<div v-show="fieldMethodsClass.getShow(props, modelValue)">
<template v-if="props.displayMode === 'dual'">
<w-form
ref="dateRangeRef"
v-model="modelValue"
:cols-num="2"
:fields="[
{
label: attrs.label + '(起)',
name: 'from',
type: 'w-date',
autoClose: false,
options: (date) => {
if (dateRangeRef) {
const toValue = dateRangeRef.getFieldValue('to');
if (!Tools.isEmpty(toValue)) {
return date < toValue.replace(/-/g, '/');
}
return true;
}
return true;
},
},
{
label: attrs.label + '(止)',
name: 'to',
type: 'w-date',
autoClose: false,
options: (date) => {
if (dateRangeRef) {
const fromValue = dateRangeRef.getFieldValue('from');
if (!Tools.isEmpty(fromValue)) {
return date > fromValue.replace(/-/g, '/');
}
return true;
}
return true;
},
},
]"
>
</w-form>
</template>
<template v-else>
<q-input
ref="dateRangeRef"
v-model="displayValueComputed"
@ -25,7 +68,7 @@
<template v-if="!fieldMethodsClass.getReadOnly(props, modelValue)" #append>
<q-btn v-if="!Tools.isEmpty(displayValueComputed)" flat square unelevated dense icon="cancel" @click="fieldMethodsClass.clearValue"></q-btn>
<q-icon name="event" class="cursor-pointer">
<q-popup-proxy cover transition-show="scale" transition-hide="scale">
<q-popup-proxy ref="proxyRef" cover transition-show="scale" transition-hide="scale">
<q-date v-model="modelValue" today-btn mask="YYYY-MM-DD" :range="true" @update:model-value="fieldMethodsClass.updateValue"> </q-date>
</q-popup-proxy>
</q-icon>
@ -35,6 +78,7 @@
<FormElementSlot v-else :slot-name="slotName" :slot-content="props['slot'][slotName]"></FormElementSlot>
</template>
</q-input>
</template>
</div>
</template>
@ -49,15 +93,22 @@ const dateRangeRef = ref();
const attrs = useAttrs();
const slots = useSlots();
const modelValue = defineModel<object>();
const proxyRef = ref();
interface FieldProps extends FormFieldProps {}
interface FieldProps extends FormFieldProps {
displayMode?: string;
// queryContainsEndDate?: boolean;
}
const props = withDefaults(defineProps<FieldProps>(), {
showIf: true,
// single(),dual()
displayMode: 'single',
});
class FieldMethods extends FormFieldMethods {
isTemplateSlot = this.getSlotType(slots);
slotNames = this.getSlotNames(slots, props);
updateValue = (value_) => {
proxyRef.value.hide();
if (props['onUpdateValue']) {
props['onUpdateValue']({
value: value_,

41
io.sc.platform.core.frontend/src/platform/components/grid/ts/function/Criteria.ts

@ -39,6 +39,9 @@ export class Criteria extends Base {
*/
private buildCriteria(value: any, fieldName: string) {
const queryOperator = this.queryFormFields[fieldName]['queryOperator'];
if (typeof value === 'string') {
value = value.trim();
}
if (!Tools.isEmpty(queryOperator)) {
return {
fieldName: fieldName,
@ -58,11 +61,22 @@ export class Criteria extends Base {
value: value,
};
} else if (typeof value === 'object' && this.queryFormFields[fieldName]['type'] === 'w-date-range') {
const endDateStr = value['to'];
let toValue = value['to'];
if (!Tools.isEmpty(endDateStr)) {
toValue = this.strDateAddDay(endDateStr);
}
return {
fieldName: fieldName,
operator: Constant.CRITERIA_OPERATOR.betweenInclusive,
start: value['from'],
end: value['to'],
end: toValue,
};
} else if (this.queryFormFields[fieldName]['type'] === 'w-select') {
return {
fieldName: fieldName,
operator: Constant.CRITERIA_OPERATOR.equals,
value: value,
};
} else {
return {
@ -73,6 +87,28 @@ export class Criteria extends Base {
}
}
/**
*
* @param dateStr
* @param dayNum
* @returns
*/
private strDateAddDay(dateStr: string, dayNum: number = 1) {
// 拆分日期并转为数字(月份需减1,因JS月份从0开始)
const [year, month, day] = dateStr.split('-').map(Number);
const date = new Date(year, month - 1, day);
// 核心:增加一天(自动处理跨月/年)
date.setDate(date.getDate() + dayNum);
// 格式化为YYYY-MM-DD(自动补零)
const newYear = date.getFullYear();
const newMonth = String(date.getMonth() + 1).padStart(2, '0');
const newDay = String(date.getDate()).padStart(2, '0');
return `${newYear}-${newMonth}-${newDay}`;
}
/**
* criteria URLSearchParams
* @param reqParams
@ -103,7 +139,8 @@ export class Criteria extends Base {
(!Tools.isEmpty(queryFormData[item]) && Array.isArray(queryFormData[item]) && queryFormData[item].length > 0)
) {
if (
(this.queryFormFields[item]['type'] === 'w-date-range' && !Tools.isEmpty(queryFormData[item]['from'])) ||
(this.queryFormFields[item]['type'] === 'w-date-range' &&
(!Tools.isEmpty(queryFormData[item]['from']) || !Tools.isEmpty(queryFormData[item]['to']))) ||
this.queryFormFields[item]['type'] !== 'w-date-range'
) {
// 根据数据进行operator处理

13
io.sc.platform.core.frontend/src/platform/components/grid/ts/toolbar/buttons/Query.ts

@ -1,4 +1,4 @@
import { $t } from '@/platform';
import { $t, NotifyManager } from '@/platform';
import { PropsType, TableType } from '../../index';
import { Button } from '../Button';
@ -11,8 +11,17 @@ export class Query extends Button {
this.getButtonConfig = this.getButtonConfig.bind(this);
}
click(args) {
async click(args) {
if (args.grid?.getQueryForm()) {
const formValidate = await args.grid.getQueryForm().validate();
if (formValidate) {
this.tools?.apiFM.operator.refreshGrid();
} else {
NotifyManager.error('查询表单存在不符合要求的字段');
}
} else {
this.tools?.apiFM.operator.refreshGrid();
}
}
getButtonConfig() {

1
io.sc.platform.core.frontend/src/platform/components/workflow/WWorkflowAction.vue

@ -154,6 +154,7 @@ const getSubmitData = (action, assignee = undefined) => {
const data = getData(action, assignee);
if (props.isContainsFile) {
const formData = props.formData;
formData.delete('data');
formData.append('data', JSON.stringify(data));
return formData;
} else {

1
io.sc.platform.core.frontend/src/platform/index.ts

@ -193,6 +193,7 @@ export type { CriteriaType } from './components';
export { arrayToMap, componentRegistryName } from './components';
export type { FormFieldProps } from './components';
export { FormFieldMethods } from './components';
export { FormValidators } from './components';
/**
* UI

Loading…
Cancel
Save