fix: improve verification_model display in RelatedFieldEditor
- Add support for loading related objects from URI (backward compatibility) - Improve display_name logic to handle both full objects and URI strings - Enhance show_related_object to handle string and object types properly
This commit is contained in:
parent
73c35a4968
commit
c38a4ffea9
@ -35,6 +35,7 @@ export default {
|
||||
return {
|
||||
possible_values: [],
|
||||
filter_string: '',
|
||||
current_object: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -51,8 +52,9 @@ export default {
|
||||
return ret;
|
||||
},
|
||||
display_name() {
|
||||
console.log(this.modelValue);
|
||||
return this.show_related_object(this.modelValue);
|
||||
// Use current_object if it was loaded from URI, otherwise use modelValue (which is now a full object)
|
||||
var obj = this.current_object !== null ? this.current_object : this.modelValue;
|
||||
return this.show_related_object(obj);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
@ -64,13 +66,17 @@ export default {
|
||||
if (!v) {
|
||||
return '无';
|
||||
}
|
||||
if (this.field_schema && this.field_schema.metadata.display_field) {
|
||||
return v[this.field_schema.metadata.display_field];
|
||||
}
|
||||
if (typeof v === 'string') {
|
||||
return v;
|
||||
}
|
||||
if (this.field_schema && this.field_schema.metadata.display_field) {
|
||||
return v[this.field_schema.metadata.display_field] || v.name || v.id || v;
|
||||
}
|
||||
return v.name || v.id || v;
|
||||
},
|
||||
set_related_object(v) {
|
||||
this.$refs.modify_modal.hide();
|
||||
this.current_object = v;
|
||||
this.$emit("update:modelValue", v);
|
||||
},
|
||||
async reload() {
|
||||
@ -80,9 +86,33 @@ export default {
|
||||
var r = await this.$root.api_get_all(url);
|
||||
this.possible_values = r;
|
||||
},
|
||||
async load_current_object() {
|
||||
// Handle legacy URI string format (backward compatibility)
|
||||
if (this.modelValue && typeof this.modelValue === 'string' && this.modelValue.startsWith('/api/')) {
|
||||
try {
|
||||
var r = await this.$root.api_get(this.modelValue);
|
||||
this.current_object = r.data;
|
||||
} catch (e) {
|
||||
console.error('Failed to load related object:', e);
|
||||
this.current_object = null;
|
||||
}
|
||||
} else {
|
||||
// Full object format (current)
|
||||
this.current_object = this.modelValue;
|
||||
}
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
modelValue: {
|
||||
handler: function() {
|
||||
this.load_current_object();
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.reload();
|
||||
this.load_current_object();
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user