This commit is contained in:
2026-01-18 20:17:59 +08:00
parent 7e05f5e76f
commit de9c14f070
23 changed files with 1825 additions and 71 deletions
+4 -4
View File
@@ -63,8 +63,8 @@ export default {
this.loading = true
try {
const res = await this.$store.dispatch('family/createFamily', this.familyName.trim())
if (res.code === 200) {
const res = await this.$store.dispatch('createFamily', this.familyName.trim())
if (res && res.code === 1) {
uni.showToast({
title: '创建成功',
icon: 'success'
@@ -74,14 +74,14 @@ export default {
}, 1500)
} else {
uni.showToast({
title: res.message || '创建失败',
title: res?.message || '创建失败',
icon: 'none'
})
}
} catch (error) {
console.error('创建家庭失败', error)
uni.showToast({
title: '创建失败,请重试',
title: error?.message || '创建失败,请重试',
icon: 'none'
})
} finally {
+27 -12
View File
@@ -120,7 +120,7 @@ export default {
if (!this.$store || !this.$store.getters) {
return false
}
return this.$store.getters['family/hasFamily'] || false
return this.$store.getters.hasFamily || false
},
isOwner() {
if (!this.$store || !this.$store.state || !this.$store.state.family) {
@@ -146,7 +146,7 @@ export default {
try {
// 获取家庭信息
const familyRes = await this.$api.family.info.get()
if (familyRes.code === 200) {
if (familyRes && familyRes.code === 1) {
this.familyInfo = familyRes.data
this.$store.commit('family/setFamilyInfo', familyRes.data)
}
@@ -154,14 +154,14 @@ export default {
// 获取邀请码(仅家主)
if (this.isOwner) {
const codeRes = await this.$api.family.inviteCode.get()
if (codeRes.code === 200) {
if (codeRes && codeRes.code === 1) {
this.inviteCode = codeRes.data.invite_code
}
}
// 获取家庭成员列表
const membersRes = await this.$api.family.members.get()
if (membersRes.code === 200) {
if (membersRes && membersRes.code === 1) {
this.memberList = membersRes.data || []
}
} catch (error) {
@@ -194,17 +194,22 @@ export default {
this.regenerating = true
try {
const res = await this.$api.family.regenerateInviteCode.post()
if (res.code === 200) {
if (res && res.code === 1) {
this.inviteCode = res.data.invite_code
uni.showToast({
title: '邀请码已更新',
icon: 'success'
})
} else {
uni.showToast({
title: res?.message || '操作失败',
icon: 'none'
})
}
} catch (error) {
console.error('重新生成邀请码失败', error)
uni.showToast({
title: '操作失败,请重试',
title: error?.message || '操作失败,请重试',
icon: 'none'
})
} finally {
@@ -224,17 +229,22 @@ export default {
const result = await this.$api.family.removeMember.post({
user_id: member.id
})
if (result.code === 200) {
if (result && result.code === 1) {
uni.showToast({
title: '移除成功',
icon: 'success'
})
this.loadFamilyData()
} else {
uni.showToast({
title: result?.message || '操作失败',
icon: 'none'
})
}
} catch (error) {
console.error('移除成员失败', error)
uni.showToast({
title: '操作失败,请重试',
title: error?.message || '操作失败,请重试',
icon: 'none'
})
}
@@ -255,9 +265,9 @@ export default {
content: '退出家庭后,您将无法查看和记录家庭账单,确定要退出吗?',
success: async (res) => {
if (res.confirm) {
try {
const result = await this.$store.dispatch('family/leaveFamily')
if (result.code === 200) {
try {
const result = await this.$store.dispatch('leaveFamily')
if (result && result.code === 1) {
uni.showToast({
title: '已退出家庭',
icon: 'success'
@@ -265,11 +275,16 @@ export default {
setTimeout(() => {
uni.navigateBack()
}, 1500)
} else {
uni.showToast({
title: result?.message || '操作失败',
icon: 'none'
})
}
} catch (error) {
console.error('退出家庭失败', error)
uni.showToast({
title: '操作失败,请重试',
title: error?.message || '操作失败,请重试',
icon: 'none'
})
}
+4 -4
View File
@@ -70,8 +70,8 @@ export default {
this.loading = true
try {
const res = await this.$store.dispatch('family/joinFamily', this.inviteCode.trim())
if (res.code === 200) {
const res = await this.$store.dispatch('joinFamily', this.inviteCode.trim())
if (res && res.code === 1) {
uni.showToast({
title: '加入成功',
icon: 'success'
@@ -81,14 +81,14 @@ export default {
}, 1500)
} else {
uni.showToast({
title: res.message || '加入失败',
title: res?.message || '加入失败',
icon: 'none'
})
}
} catch (error) {
console.error('加入家庭失败', error)
uni.showToast({
title: '加入失败,请重试',
title: error?.message || '加入失败,请重试',
icon: 'none'
})
} finally {