From c38a4ffea962c14135249a68a59daad0755945c6 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Sat, 27 Dec 2025 10:33:42 +0000 Subject: [PATCH] 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 --- web/src/components/related-field-editor.vue | 40 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/web/src/components/related-field-editor.vue b/web/src/components/related-field-editor.vue index 8e3d356..e8cfbea 100644 --- a/web/src/components/related-field-editor.vue +++ b/web/src/components/related-field-editor.vue @@ -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; } - 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(); }, }