Răsfoiți Sursa

fix(frontend): remove dead getRelationshipTypes API after P0-001 backend removal

ContactCard/ContactImport: replace dynamic API call with hardcoded relationship
type list (family/friend/partner/colleague/other), matching backend removal of
/relationship-types endpoint and relationship_types table.
Xiaogang Liao 3 luni în urmă
părinte
comite
107e44e0c1

+ 18 - 20
cfc-frontend/components/ContactCard.vue

@@ -59,8 +59,15 @@ export default {
   data: function() {
     return {
       showInviteModal: false,
-      relationshipTypeList: [],
+      relationshipTypeList: [
+        { typeName: '家人', typeKey: 'family' },
+        { typeName: '朋友', typeKey: 'friend' },
+        { typeName: '伴侣', typeKey: 'partner' },
+        { typeName: '同事', typeKey: 'colleague' },
+        { typeName: '其他', typeKey: 'other' }
+      ],
       selectedRelationshipName: '',
+      selectedRelationshipKey: '',
       generationLevelList: ['父母(+1)', '子女(-1)', '配偶(0)', '兄弟姐妹(0)', '祖父母(+2)', '孙子女(-2)'],
       selectedGeneration: ''
     }
@@ -92,28 +99,22 @@ export default {
   methods: {
     handleInvite: function() {
       this.showInviteModal = true
-      this.loadRelationshipTypes()
-    },
-    loadRelationshipTypes: function() {
-      var that = this
-      var app = getApp()
-      if (!app || !app.globalData || !app.globalData.baseUrl) return
-      uni.request({
-        url: app.globalData.baseUrl + '/api/family/member/relationship-types',
-        method: 'POST',
-        header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
-        success: function(res) {
-          if (res.data && res.data.data) {
-            that.relationshipTypeList = res.data.data
-          }
+      // 预填联系人已有的关系类型
+      var self = this
+      this.selectedRelationshipKey = this.contact.relationshipType || 'other'
+      for (var i = 0; i < this.relationshipTypeList.length; i++) {
+        if (this.relationshipTypeList[i].typeKey === this.selectedRelationshipKey) {
+          this.selectedRelationshipName = this.relationshipTypeList[i].typeName
+          break
         }
-      })
+      }
     },
     onRelationshipChange: function(e) {
       var idx = e.detail.value
       var item = this.relationshipTypeList[idx]
       if (item) {
         this.selectedRelationshipName = item.typeName
+        this.selectedRelationshipKey = item.typeKey
       }
     },
     onGenerationChange: function(e) {
@@ -134,9 +135,6 @@ export default {
         '孙子女(-2)': 'grandchild'
       }
       var generationLevel = generationMap[this.selectedGeneration] || 'child'
-      var selectedItem = this.relationshipTypeList.filter(function(item) {
-        return item.typeName === that.selectedRelationshipName
-      })[0]
       var app = getApp()
       if (!app || !app.globalData || !app.globalData.baseUrl) return
       uni.request({
@@ -145,7 +143,7 @@ export default {
         header: { 'Authorization': 'Bearer ' + uni.getStorageSync('token') },
         data: {
           contactId: this.contact.id,
-          relationshipType: selectedItem ? selectedItem.typeKey : 'child',
+          relationshipType: this.selectedRelationshipKey || 'other',
           generationLevel: generationLevel
         },
         success: function(res) {

+ 15 - 21
cfc-frontend/components/ContactImport.vue

@@ -49,7 +49,15 @@
 </template>
 
 <script>
-import { importPhoneContact, getRelationshipTypes } from '../utils/api.js'
+import { importPhoneContact } from '../utils/api.js'
+
+var DEFAULT_RELATIONSHIP_TYPES = [
+  { value: 'family', label: '家人' },
+  { value: 'friend', label: '朋友' },
+  { value: 'partner', label: '伴侣' },
+  { value: 'colleague', label: '同事' },
+  { value: 'other', label: '其他' }
+]
 
 export default {
   props: {
@@ -58,6 +66,10 @@ export default {
     phone: { type: String, default: '' }
   },
   data: function() {
+    var defaultLabels = []
+    for (var i = 0; i < DEFAULT_RELATIONSHIP_TYPES.length; i++) {
+      defaultLabels.push(DEFAULT_RELATIONSHIP_TYPES[i].label)
+    }
     return {
       form: {
         name: '',
@@ -68,14 +80,13 @@ export default {
         birthday: '',
         bio: ''
       },
-      relationshipTypes: [],
-      typeLabels: []
+      relationshipTypes: DEFAULT_RELATIONSHIP_TYPES,
+      typeLabels: defaultLabels
     }
   },
   watch: {
     visible: function(val) {
       if (val) {
-        this.loadTypes()
         if (!this.form.name && this.name) {
           this.form.name = this.name
         }
@@ -96,23 +107,6 @@ export default {
     }
   },
   methods: {
-    loadTypes: function() {
-      var self = this
-      getRelationshipTypes().then(function(res) {
-        var labels
-        if (res.code === 200 && Array.isArray(res.data)) {
-          labels = res.data.map(function(item) {
-            return typeof item === 'string' ? item : (item.typeName || item.name || item.label || item.value || '')
-          })
-          self.relationshipTypes = res.data
-          self.typeLabels = labels
-        }
-      }).catch(function() {
-        // fallback to default type options
-        self.typeLabels = ['家人', '朋友', '伴侣', '同事', '其他']
-        self.relationshipTypes = ['family', 'friend', 'partner', 'colleague', 'other']
-      })
-    },
     chooseFromWeChat: function() {
       var self = this
       if (typeof wx !== 'undefined' && wx.chooseContact) {

+ 0 - 4
cfc-frontend/utils/api.js

@@ -341,10 +341,6 @@ export const updateFamilyMember = (data) => {
   return request('/api/family/member/update', 'POST', data)
 }
 
-export const getRelationshipTypes = () => {
-  return request('/api/family/member/relationship-types', 'POST')
-}
-
 // 任务模块
 export const createTask = (data) => {
   return request('/api/tasks', 'POST', data)