feat(event): 添加酒局编辑删除功能并优化状态管理
- 移除 UniAppWebSocket 类实现,使用独立的 websocket 模块 - 添加 UpdateEvent 和 DeleteEvent API 接口 - 在 EventCard 组件中添加发起人管理操作按钮 - 实现酒局状态数字枚举到字符串的映射转换 - 在 circle 页面集成编辑删除事件处理 - 重构 event-create 页面支持编辑模式 - 在 event-detail 页面添加发起人操作区域 - 实现删除确认对话框和页面返回刷新逻辑
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
<view class="create-back" @click="goBack">
|
||||
<text class="create-back-icon">‹</text>
|
||||
</view>
|
||||
<text class="create-nav-title">发起酒局</text>
|
||||
<text class="create-nav-title">{{ isEdit ? '编辑酒局' : '发起酒局' }}</text>
|
||||
<view class="create-nav-ph"></view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -98,9 +98,9 @@
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 发布按钮 -->
|
||||
<!-- 发布/保存按钮 -->
|
||||
<button class="create-submit" :class="{ disabled: !canSubmit }" @click="handleSubmit">
|
||||
发布酒局
|
||||
{{ isEdit ? '保存修改' : '发布酒局' }}
|
||||
</button>
|
||||
</view>
|
||||
</scroll-view>
|
||||
@@ -108,7 +108,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { CreateEvent } from '../../common/api'
|
||||
import { CreateEvent, UpdateEvent, GetEventDetail } from '../../common/api'
|
||||
import themeMixin from '../../common/theme-mixin'
|
||||
|
||||
export default {
|
||||
@@ -132,12 +132,24 @@ export default {
|
||||
maxPeople: 6,
|
||||
note: ''
|
||||
},
|
||||
submitting: false
|
||||
submitting: false,
|
||||
// 编辑模式:携带酒局ID时进入编辑态
|
||||
editId: '',
|
||||
loadingDetail: false
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
if (options && options.id) {
|
||||
this.editId = options.id
|
||||
this.loadEventDetail()
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isEdit() {
|
||||
return !!this.editId
|
||||
},
|
||||
canSubmit() {
|
||||
return this.form.title.trim() && this.form.date && this.form.time && this.form.location.trim() && !this.submitting
|
||||
return this.form.title.trim() && this.form.date && this.form.time && this.form.location.trim() && !this.submitting && !this.loadingDetail
|
||||
},
|
||||
locationMarkers() {
|
||||
if (!this.form.latitude) return []
|
||||
@@ -155,6 +167,35 @@ export default {
|
||||
goBack() {
|
||||
uni.navigateBack()
|
||||
},
|
||||
/** 编辑模式:拉取酒局详情回填表单 */
|
||||
async loadEventDetail() {
|
||||
this.loadingDetail = true
|
||||
try {
|
||||
const res = await GetEventDetail({ eventId: this.editId })
|
||||
const evt = res.data || {}
|
||||
this.form.title = evt.title || ''
|
||||
// 后端 time 格式如 "2026-08-08 20:00:00",拆分为日期/时间两个选择器字段
|
||||
const timeStr = String(evt.time || '')
|
||||
const m = timeStr.match(/^(\d{4}-\d{2}-\d{2})[ T]?(\d{2}:\d{2})?/)
|
||||
if (m) {
|
||||
this.form.date = m[1]
|
||||
this.form.time = m[2] || ''
|
||||
}
|
||||
this.form.location = evt.location || ''
|
||||
this.form.address = evt.address || ''
|
||||
// 兼容顶层字段与 geo 对象两种返回
|
||||
const geo = evt.geo || {}
|
||||
this.form.latitude = evt.latitude != null ? evt.latitude : (geo.latitude != null ? geo.latitude : null)
|
||||
this.form.longitude = evt.longitude != null ? evt.longitude : (geo.longitude != null ? geo.longitude : null)
|
||||
this.form.maxPeople = Number(evt.maxPeople) || this.form.maxPeople
|
||||
this.form.note = evt.note || ''
|
||||
} catch (e) {
|
||||
// 加载失败时返回上一页,避免空表单误改
|
||||
uni.showToast({ title: '加载酒局失败', icon: 'none' })
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
}
|
||||
this.loadingDetail = false
|
||||
},
|
||||
onDateChange(e) {
|
||||
this.form.date = e.detail.value
|
||||
},
|
||||
@@ -201,18 +242,24 @@ export default {
|
||||
async handleSubmit() {
|
||||
if (!this.canSubmit) return
|
||||
this.submitting = true
|
||||
const payload = {
|
||||
title: this.form.title,
|
||||
time: `${this.form.date} ${this.form.time}:00`,
|
||||
location: this.form.location,
|
||||
address: this.form.address,
|
||||
latitude: this.form.latitude,
|
||||
longitude: this.form.longitude,
|
||||
maxPeople: this.form.maxPeople,
|
||||
note: this.form.note
|
||||
}
|
||||
try {
|
||||
await CreateEvent({
|
||||
title: this.form.title,
|
||||
time: `${this.form.date} ${this.form.time}:00`,
|
||||
location: this.form.location,
|
||||
address: this.form.address,
|
||||
latitude: this.form.latitude,
|
||||
longitude: this.form.longitude,
|
||||
maxPeople: this.form.maxPeople,
|
||||
note: this.form.note
|
||||
})
|
||||
uni.showToast({ title: '酒局已发布 🎉', icon: 'none' })
|
||||
if (this.isEdit) {
|
||||
await UpdateEvent({ eventId: this.editId, ...payload })
|
||||
uni.showToast({ title: '修改已保存 ✅', icon: 'none' })
|
||||
} else {
|
||||
await CreateEvent(payload)
|
||||
uni.showToast({ title: '酒局已发布 🎉', icon: 'none' })
|
||||
}
|
||||
setTimeout(() => uni.navigateBack(), 800)
|
||||
} catch (e) {
|
||||
// 全局拦截器已弹出错误提示
|
||||
|
||||
Reference in New Issue
Block a user