ui更新
This commit is contained in:
@@ -0,0 +1,182 @@
|
||||
<template>
|
||||
<un-pages
|
||||
:show-nav-bar="true"
|
||||
nav-bar-title="创建家庭"
|
||||
:show-back="true"
|
||||
>
|
||||
<view class="page-content">
|
||||
<view class="form-section">
|
||||
<view class="section-title">家庭名称</view>
|
||||
<view class="input-wrapper">
|
||||
<input
|
||||
v-model="familyName"
|
||||
placeholder="请输入家庭名称"
|
||||
placeholder-style="color: #ccc"
|
||||
maxlength="20"
|
||||
/>
|
||||
<text class="char-count">{{ familyName.length }}/20</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="tips-section">
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">创建后您将成为家主,可以管理家庭成员</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">每个用户只能创建或加入一个家庭</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">创建家庭后,家庭成员可以查看和记录家庭账单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="submit-section">
|
||||
<button class="submit-btn" @tap="handleCreate" :loading="loading">
|
||||
创建家庭
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</un-pages>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
familyName: '',
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async handleCreate() {
|
||||
if (!this.familyName.trim()) {
|
||||
uni.showToast({
|
||||
title: '请输入家庭名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
const res = await this.$store.dispatch('family/createFamily', this.familyName.trim())
|
||||
if (res.code === 200) {
|
||||
uni.showToast({
|
||||
title: '创建成功',
|
||||
icon: 'success'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.message || '创建失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('创建家庭失败', error)
|
||||
uni.showToast({
|
||||
title: '创建失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-content {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
position: relative;
|
||||
|
||||
input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.char-count {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: -30rpx;
|
||||
font-size: 22rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips-section {
|
||||
background: rgba(102, 126, 234, 0.05);
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
.tip-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
uni-icons {
|
||||
margin-right: 12rpx;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.submit-section {
|
||||
margin-top: 60rpx;
|
||||
|
||||
.submit-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 50rpx;
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 8rpx 24rpx rgba(102, 126, 234, 0.3);
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,588 @@
|
||||
<template>
|
||||
<un-pages
|
||||
:show-nav-bar="true"
|
||||
nav-bar-title="家庭管理"
|
||||
:show-back="true"
|
||||
>
|
||||
<view class="page-content">
|
||||
<view v-if="loading" class="loading-state">
|
||||
<uni-load-more status="loading"></uni-load-more>
|
||||
</view>
|
||||
|
||||
<!-- 已加入家庭 -->
|
||||
<view v-else-if="hasFamily" class="family-container">
|
||||
<!-- 家庭信息卡片 -->
|
||||
<view class="family-card">
|
||||
<view class="family-header">
|
||||
<view class="family-icon">
|
||||
<text>🏠</text>
|
||||
</view>
|
||||
<view class="family-info">
|
||||
<text class="family-name">{{ familyInfo.name }}</text>
|
||||
<text class="family-role" v-if="isOwner">我是家主</text>
|
||||
<text class="family-role" v-else>家庭成员</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 家庭邀请码(仅家主可见) -->
|
||||
<view v-if="isOwner" class="invite-section">
|
||||
<view class="invite-info">
|
||||
<text class="invite-label">家庭邀请码</text>
|
||||
<view class="invite-code-wrapper">
|
||||
<text class="invite-code">{{ inviteCode || '加载中...' }}</text>
|
||||
<view class="copy-btn" @tap="copyInviteCode">
|
||||
<uni-icons type="copy" size="16" color="#667eea"></uni-icons>
|
||||
<text>复制</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<button class="regenerate-btn" @tap="regenerateInviteCode" :loading="regenerating">
|
||||
重新生成邀请码
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 家庭成员列表 -->
|
||||
<view class="members-section">
|
||||
<view class="section-header">
|
||||
<text class="section-title">家庭成员</text>
|
||||
<text class="member-count">{{ memberList.length }}人</text>
|
||||
</view>
|
||||
|
||||
<view class="member-list">
|
||||
<view class="member-item" v-for="member in memberList" :key="member.id">
|
||||
<view class="member-avatar">
|
||||
<text>{{ member.name ? member.name.charAt(0) : 'U' }}</text>
|
||||
</view>
|
||||
<view class="member-info">
|
||||
<text class="member-name">{{ member.name || member.username }}</text>
|
||||
<text class="member-role" v-if="member.is_owner">家主</text>
|
||||
</view>
|
||||
<!-- 移除成员按钮(仅家主可见) -->
|
||||
<view v-if="isOwner && !member.is_owner" class="remove-btn" @tap="removeMember(member)">
|
||||
<uni-icons type="clear" size="20" color="#FF6B6B"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 转让家主(仅家主可见) -->
|
||||
<view v-if="isOwner && memberList.length > 1" class="action-btn">
|
||||
<button class="secondary-btn" @tap="transferOwner">
|
||||
转让家主
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出家庭按钮 -->
|
||||
<view class="action-btn">
|
||||
<button class="exit-btn" @tap="confirmLeaveFamily">
|
||||
退出家庭
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 未加入家庭 -->
|
||||
<view v-else class="no-family-container">
|
||||
<view class="no-family-icon">
|
||||
<text>🏠</text>
|
||||
</view>
|
||||
<text class="no-family-title">您还未加入任何家庭</text>
|
||||
<text class="no-family-desc">创建或加入家庭,与家人一起记账</text>
|
||||
|
||||
<view class="action-buttons">
|
||||
<button class="primary-btn" @tap="goToCreate">
|
||||
<uni-icons type="plus" size="20" color="#fff"></uni-icons>
|
||||
<text>创建家庭</text>
|
||||
</button>
|
||||
<button class="secondary-btn" @tap="goToJoin">
|
||||
<uni-icons type="personadd" size="20" color="#667eea"></uni-icons>
|
||||
<text>加入家庭</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</un-pages>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
familyInfo: {},
|
||||
inviteCode: '',
|
||||
regenerating: false,
|
||||
memberList: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
hasFamily() {
|
||||
if (!this.$store || !this.$store.getters) {
|
||||
return false
|
||||
}
|
||||
return this.$store.getters['family/hasFamily'] || false
|
||||
},
|
||||
isOwner() {
|
||||
if (!this.$store || !this.$store.state || !this.$store.state.family) {
|
||||
return false
|
||||
}
|
||||
return this.$store.state.family.isOwner || false
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.loadFamilyData()
|
||||
},
|
||||
onShow() {
|
||||
// 从其他页面返回时刷新数据
|
||||
this.loadFamilyData()
|
||||
},
|
||||
methods: {
|
||||
async loadFamilyData() {
|
||||
if (!this.hasFamily) {
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
try {
|
||||
// 获取家庭信息
|
||||
const familyRes = await this.$api.family.info.get()
|
||||
if (familyRes.code === 200) {
|
||||
this.familyInfo = familyRes.data
|
||||
this.$store.commit('family/setFamilyInfo', familyRes.data)
|
||||
}
|
||||
|
||||
// 获取邀请码(仅家主)
|
||||
if (this.isOwner) {
|
||||
const codeRes = await this.$api.family.inviteCode.get()
|
||||
if (codeRes.code === 200) {
|
||||
this.inviteCode = codeRes.data.invite_code
|
||||
}
|
||||
}
|
||||
|
||||
// 获取家庭成员列表
|
||||
const membersRes = await this.$api.family.members.get()
|
||||
if (membersRes.code === 200) {
|
||||
this.memberList = membersRes.data || []
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载家庭数据失败', error)
|
||||
uni.showToast({
|
||||
title: '加载失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
copyInviteCode() {
|
||||
uni.setClipboardData({
|
||||
data: this.inviteCode,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
title: '邀请码已复制',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
async regenerateInviteCode() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '重新生成邀请码后,旧的邀请码将失效,确定要重新生成吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
this.regenerating = true
|
||||
try {
|
||||
const res = await this.$api.family.regenerateInviteCode.post()
|
||||
if (res.code === 200) {
|
||||
this.inviteCode = res.data.invite_code
|
||||
uni.showToast({
|
||||
title: '邀请码已更新',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('重新生成邀请码失败', error)
|
||||
uni.showToast({
|
||||
title: '操作失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.regenerating = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
removeMember(member) {
|
||||
uni.showModal({
|
||||
title: '确认移除',
|
||||
content: `确定要将 ${member.name || member.username} 移出家庭吗?`,
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
const result = await this.$api.family.removeMember.post({
|
||||
user_id: member.id
|
||||
})
|
||||
if (result.code === 200) {
|
||||
uni.showToast({
|
||||
title: '移除成功',
|
||||
icon: 'success'
|
||||
})
|
||||
this.loadFamilyData()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('移除成员失败', error)
|
||||
uni.showToast({
|
||||
title: '操作失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
transferOwner() {
|
||||
// TODO: 实现转让家主功能
|
||||
uni.showToast({
|
||||
title: '功能开发中',
|
||||
icon: 'none'
|
||||
})
|
||||
},
|
||||
confirmLeaveFamily() {
|
||||
uni.showModal({
|
||||
title: '确认退出',
|
||||
content: '退出家庭后,您将无法查看和记录家庭账单,确定要退出吗?',
|
||||
success: async (res) => {
|
||||
if (res.confirm) {
|
||||
try {
|
||||
const result = await this.$store.dispatch('family/leaveFamily')
|
||||
if (result.code === 200) {
|
||||
uni.showToast({
|
||||
title: '已退出家庭',
|
||||
icon: 'success'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('退出家庭失败', error)
|
||||
uni.showToast({
|
||||
title: '操作失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
goToCreate() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/family/create'
|
||||
})
|
||||
},
|
||||
goToJoin() {
|
||||
uni.navigateTo({
|
||||
url: '/pages/family/join'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-content {
|
||||
padding: 30rpx;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.loading-state {
|
||||
padding: 120rpx 0;
|
||||
}
|
||||
|
||||
.no-family-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 120rpx 0;
|
||||
|
||||
.no-family-icon {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 40rpx;
|
||||
box-shadow: 0 8rpx 24rpx rgba(102, 126, 234, 0.3);
|
||||
|
||||
text {
|
||||
font-size: 80rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.no-family-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.no-family-desc {
|
||||
font-size: 26rpx;
|
||||
color: #999;
|
||||
margin-bottom: 60rpx;
|
||||
}
|
||||
|
||||
.action-buttons {
|
||||
width: 100%;
|
||||
padding: 0 40rpx;
|
||||
|
||||
button {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.family-container {
|
||||
.family-card {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 40rpx 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.family-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
.family-icon {
|
||||
width: 100rpx;
|
||||
height: 100rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 20rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 24rpx;
|
||||
|
||||
text {
|
||||
font-size: 50rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.family-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.family-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.family-role {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.invite-section {
|
||||
border-top: 2rpx solid #f5f5f5;
|
||||
padding-top: 30rpx;
|
||||
|
||||
.invite-info {
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
.invite-label {
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
margin-bottom: 16rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.invite-code-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background: #f8f8f8;
|
||||
border-radius: 12rpx;
|
||||
padding: 20rpx 24rpx;
|
||||
|
||||
.invite-code {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
letter-spacing: 4rpx;
|
||||
}
|
||||
|
||||
.copy-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10rpx 20rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 50rpx;
|
||||
|
||||
text {
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
margin-left: 6rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.regenerate-btn {
|
||||
width: 100%;
|
||||
height: 70rpx;
|
||||
line-height: 70rpx;
|
||||
font-size: 26rpx;
|
||||
background: #f8f8f8;
|
||||
color: #666;
|
||||
border: none;
|
||||
border-radius: 50rpx;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.members-section {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.member-count {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
}
|
||||
|
||||
.member-list {
|
||||
.member-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 24rpx 0;
|
||||
border-bottom: 2rpx solid #f5f5f5;
|
||||
|
||||
&:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.member-avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 20rpx;
|
||||
|
||||
text {
|
||||
font-size: 32rpx;
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
|
||||
.member-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.member-name {
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
font-weight: bold;
|
||||
margin-right: 16rpx;
|
||||
}
|
||||
|
||||
.member-role {
|
||||
font-size: 22rpx;
|
||||
color: #667eea;
|
||||
background: rgba(102, 126, 234, 0.1);
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 20rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.remove-btn {
|
||||
padding: 10rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.action-btn {
|
||||
margin-bottom: 30rpx;
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
border-radius: 50rpx;
|
||||
font-size: 28rpx;
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.primary-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
box-shadow: 0 8rpx 24rpx rgba(102, 126, 234, 0.3);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
uni-icons {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.secondary-btn {
|
||||
background: #f8f8f8;
|
||||
color: #667eea;
|
||||
border: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
uni-icons {
|
||||
margin-right: 10rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.exit-btn {
|
||||
background: #fff;
|
||||
color: #FF6B6B;
|
||||
border: 2rpx solid #FF6B6B;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,180 @@
|
||||
<template>
|
||||
<un-pages
|
||||
:show-nav-bar="true"
|
||||
nav-bar-title="加入家庭"
|
||||
:show-back="true"
|
||||
>
|
||||
<view class="page-content">
|
||||
<view class="form-section">
|
||||
<view class="section-title">家庭邀请码</view>
|
||||
<view class="input-wrapper">
|
||||
<input
|
||||
v-model="inviteCode"
|
||||
placeholder="请输入家庭邀请码"
|
||||
placeholder-style="color: #ccc"
|
||||
maxlength="10"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="tips-section">
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">邀请码由家庭家主提供</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">每个用户只能加入一个家庭</text>
|
||||
</view>
|
||||
<view class="tip-item">
|
||||
<uni-icons type="info" size="18" color="#667eea"></uni-icons>
|
||||
<text class="tip-text">加入家庭后,可以查看和记录家庭账单</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="submit-section">
|
||||
<button class="submit-btn" @tap="handleJoin" :loading="loading">
|
||||
加入家庭
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</un-pages>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
inviteCode: '',
|
||||
loading: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async handleJoin() {
|
||||
if (!this.inviteCode.trim()) {
|
||||
uni.showToast({
|
||||
title: '请输入邀请码',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (this.inviteCode.trim().length !== 10) {
|
||||
uni.showToast({
|
||||
title: '邀请码格式不正确',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
|
||||
try {
|
||||
const res = await this.$store.dispatch('family/joinFamily', this.inviteCode.trim())
|
||||
if (res.code === 200) {
|
||||
uni.showToast({
|
||||
title: '加入成功',
|
||||
icon: 'success'
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1500)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.message || '加入失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加入家庭失败', error)
|
||||
uni.showToast({
|
||||
title: '加入失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page-content {
|
||||
padding: 30rpx;
|
||||
}
|
||||
|
||||
.form-section {
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 30rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.05);
|
||||
|
||||
.section-title {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.input-wrapper {
|
||||
input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
font-size: 28rpx;
|
||||
color: #333;
|
||||
padding: 0;
|
||||
letter-spacing: 4rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tips-section {
|
||||
background: rgba(102, 126, 234, 0.05);
|
||||
border-radius: 20rpx;
|
||||
padding: 30rpx;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
.tip-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 20rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
uni-icons {
|
||||
margin-right: 12rpx;
|
||||
margin-top: 4rpx;
|
||||
}
|
||||
|
||||
.tip-text {
|
||||
flex: 1;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
line-height: 1.6;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.submit-section {
|
||||
margin-top: 60rpx;
|
||||
|
||||
.submit-btn {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: 50rpx;
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
box-shadow: 0 8rpx 24rpx rgba(102, 126, 234, 0.3);
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user