Browse Source

修复w-grid-select组件设置模型值,显示值未更新的问题。

main
likunming 6 months ago
parent
commit
5d832761f6
  1. 9
      io.sc.platform.core.frontend/src/platform/components/select/WGridSelect.vue
  2. 31
      io.sc.platform.core.frontend/src/platform/components/select/WOrgSelect.vue
  3. 31
      io.sc.platform.core.frontend/src/platform/components/select/WUserSelect.vue

9
io.sc.platform.core.frontend/src/platform/components/select/WGridSelect.vue

@ -236,7 +236,14 @@ watch(
if (Tools.isEmpty(newVal)) {
fieldMethodsClass.clearObjectValue();
} else if (newVal !== oldVal) {
setObjectValueByValue(newVal);
if (modelObjectValue.value.length > 0) {
const tempValue = modelObjectValue.value.find((item) => item.value === newVal);
if (!tempValue) {
setObjectValueByValue(newVal);
}
} else {
setObjectValueByValue(newVal);
}
}
},
);

31
io.sc.platform.core.frontend/src/platform/components/select/WOrgSelect.vue

@ -15,7 +15,6 @@
:readonly="fieldMethodsClass.getReadOnly(props, { value: modelValue, displayValue: displayValueComputed })"
:disable="fieldMethodsClass.getDisable(props, { value: modelValue, displayValue: displayValueComputed })"
:clearable="false"
@update:model-value="fieldMethodsClass.updateValue"
@focus="
() => {
textSelectRef?.blur();
@ -64,7 +63,7 @@
</template>
<script setup lang="ts">
import { ref, computed, useAttrs, onBeforeMount, toRaw } from 'vue';
import { ref, computed, useAttrs, toRaw, watch } from 'vue';
import { Tools, axios, Environment, Formater } from '@/platform';
import { FormFieldProps } from '@/platform/components/form/FormField.ts';
import { FormFieldMethods } from '../form/FormField';
@ -213,9 +212,31 @@ const rowClick = (args) => {
isShow.value = false;
};
watch(
() => modelValue.value,
(newVal, oldVal) => {
if (newVal !== oldVal) {
fieldMethodsClass.updateValue(newVal);
}
if (Tools.isEmpty(newVal)) {
fieldMethodsClass.clearObjectValue();
} else if (newVal !== oldVal) {
if (modelObjectValue.value.length > 0) {
const tempValue = modelObjectValue.value.find((item) => item.value === newVal);
if (!tempValue) {
setObjectValueByValue(newVal);
}
} else {
setObjectValueByValue(newVal);
}
}
},
);
//
const setObjectValueByValue = async (value) => {
if ((Array.isArray(value) && value.length > 0) || (typeof value === 'string' && !Tools.isEmpty(value))) {
fieldMethodsClass.clearObjectValue();
const urlSearchParams = new URLSearchParams();
urlSearchParams.append(
'criteria',
@ -231,12 +252,10 @@ const setObjectValueByValue = async (value) => {
if (resp && resp.data) {
const responseData = resp.data;
if (Array.isArray(responseData) && responseData.length > 0) {
fieldMethodsClass.clearObjectValue();
responseData.forEach((item) => {
modelObjectValue.value.push({ value: item[valueUseColumnName], displayValue: getActualDisplayValue(item) });
});
} else if (typeof responseData === 'object' && responseData.content?.length > 0) {
fieldMethodsClass.clearObjectValue();
responseData.content.forEach((item) => {
modelObjectValue.value.push({ value: item[valueUseColumnName], displayValue: getActualDisplayValue(item) });
});
@ -245,10 +264,6 @@ const setObjectValueByValue = async (value) => {
}
};
onBeforeMount(() => {
setObjectValueByValue(modelValue.value);
});
defineExpose({
validate: fieldMethodsClass.validate,
setValue: fieldMethodsClass.setValue,

31
io.sc.platform.core.frontend/src/platform/components/select/WUserSelect.vue

@ -15,7 +15,6 @@
:readonly="fieldMethodsClass.getReadOnly(props, { value: modelValue, displayValue: displayValueComputed })"
:disable="fieldMethodsClass.getDisable(props, { value: modelValue, displayValue: displayValueComputed })"
:clearable="false"
@update:model-value="fieldMethodsClass.updateValue"
@focus="
() => {
textSelectRef?.blur();
@ -85,7 +84,7 @@
</template>
<script setup lang="ts">
import { ref, computed, useAttrs, onBeforeMount, toRaw } from 'vue';
import { ref, computed, useAttrs, toRaw, watch } from 'vue';
import { Tools, axios, Environment, Formater } from '@/platform';
import { FormFieldProps } from '@/platform/components/form/FormField.ts';
import { FormFieldMethods } from '../form/FormField';
@ -258,9 +257,31 @@ const orgRowClick = (args) => {
userGridRef.value.refresh();
};
watch(
() => modelValue.value,
(newVal, oldVal) => {
if (newVal !== oldVal) {
fieldMethodsClass.updateValue(newVal);
}
if (Tools.isEmpty(newVal)) {
fieldMethodsClass.clearObjectValue();
} else if (newVal !== oldVal) {
if (modelObjectValue.value.length > 0) {
const tempValue = modelObjectValue.value.find((item) => item.value === newVal);
if (!tempValue) {
setObjectValueByValue(newVal);
}
} else {
setObjectValueByValue(newVal);
}
}
},
);
//
const setObjectValueByValue = async (value) => {
if ((Array.isArray(value) && value.length > 0) || (typeof value === 'string' && !Tools.isEmpty(value))) {
fieldMethodsClass.clearObjectValue();
const urlSearchParams = new URLSearchParams();
urlSearchParams.append(
'criteria',
@ -276,12 +297,10 @@ const setObjectValueByValue = async (value) => {
if (resp && resp.data) {
const responseData = resp.data;
if (Array.isArray(responseData) && responseData.length > 0) {
fieldMethodsClass.clearObjectValue();
responseData.forEach((item) => {
modelObjectValue.value.push({ value: item[valueUseColumnName], displayValue: getActualDisplayValue(item) });
});
} else if (typeof responseData === 'object' && responseData.content?.length > 0) {
fieldMethodsClass.clearObjectValue();
responseData.content.forEach((item) => {
modelObjectValue.value.push({ value: item[valueUseColumnName], displayValue: getActualDisplayValue(item) });
});
@ -290,10 +309,6 @@ const setObjectValueByValue = async (value) => {
}
};
onBeforeMount(() => {
setObjectValueByValue(modelValue.value);
});
defineExpose({
validate: fieldMethodsClass.validate,
setValue: fieldMethodsClass.setValue,

Loading…
Cancel
Save