提交 3919afc3 作者: 施汉文

feat(game+report): 新增举报申请缓存

上级 b07fdcfa
......@@ -16,6 +16,7 @@ const state = {
chatUserInfo: {}, // 当前选中的用户的详情
viewLoading:false, // 查看用户详情的时候 加载状态
taskDetails: {}, // 任务详情
reportDrawerCache: null, // 举报抽屉表单缓存:关闭抽屉时用户选择保存则存储表单数据,下次打开时恢复
// 任务数据
taskData: {
user_task: 0,
......@@ -47,6 +48,14 @@ const mutations = {
set_taskDetails(state, data) {
state.taskDetails = data
},
// 举报抽屉缓存:保存表单数据
set_reportDrawerCache(state, data) {
state.reportDrawerCache = data
},
// 举报抽屉缓存:清除
clear_reportDrawerCache(state) {
state.reportDrawerCache = null
},
// 设置任务数据
set_taskData(state, data) {
state.taskData = {
......
......@@ -344,19 +344,32 @@
cp_role_id_loading: false,
serverNameList: [],
searchUserOption: [],
eco_user_list: [] // 生态运营人员列表
eco_user_list: [], // 生态运营人员列表
initialFormSnapshot: '' // 举报抽屉缓存:打开时快照,用于关闭时对比是否有修改
}
},
watch: {
show(newVal, oldVal) {
if (newVal) {
console.log('显示弹窗')
}
// 重新提交:抽屉再次打开时重新拉取生态运营(组件未销毁、仅 show 切换的场景)
if (newVal === true && oldVal === false && this.reportInfo && this.reportInfo.id) {
// 举报抽屉缓存:组件由父级 :show.sync 常驻挂载,mounted 仅首次执行,
// 故「重置/恢复缓存/快照基线」必须放 show 的 false→true 跳变(不能放 mounted)。
if (newVal === true && oldVal === false) {
if (this.reportInfo && this.reportInfo.id) {
// 编辑/重新提交态:mounted 已回填表单,此处仅重新拉取生态运营
this.$nextTick(() => {
this.refreshEcoUserForResubmit()
})
} else {
// 新建态:先重置为默认空表单(常驻组件不会自动清空),再恢复 vuex 缓存
this.reportForm = this.getDefaultReportForm()
const cache = this.$store.state.game.reportDrawerCache
if (cache) {
this.reportForm = this.$clone(cache)
}
}
// 举报抽屉缓存:建立初始快照基线(回填/恢复落定后),关闭时据此判断是否有未提交修改
this.$nextTick(() => {
this.initialFormSnapshot = JSON.stringify(this.reportForm)
})
}
},
/**
......@@ -417,6 +430,30 @@
},
methods: {
/**
* 举报抽屉缓存:新建态的默认空表单。
* 组件由父级 :show.sync 常驻挂载(非 v-if 销毁重建),打开时据此重置,
* 以保证「不保存关闭 / 提交成功」后下次打开为空表单。
*/
getDefaultReportForm() {
return {
main_game_id: '',
report_role_id_type: 'cp_role_id',
role_id_type: 'cp_role_id',
cp_role_id: [],
role_id: [],
role_name: [],
server_name: [],
violation_type: '',
report_cp_role_id: '',
report_role_id: '',
report_role_name: '',
report_server_name: '',
eco_user: '',
is_negotiation: '',
remark: ''
}
},
/**
* 从举报详情中取字段,兼容下划线 / 驼峰(列表接口字段名可能不一致)
*/
pickReportInfoField(info, snakeKey, camelKey) {
......@@ -750,7 +787,25 @@
})
},
close() {
// 举报抽屉缓存:关闭时检测是否有未提交的修改
const hasChanges = JSON.stringify(this.reportForm) !== this.initialFormSnapshot
if (hasChanges) {
this.$confirm('是否保存当前输入?', '提示', {
confirmButtonText: '保存',
cancelButtonText: '不保存',
type: 'warning'
}).then(() => {
// 举报抽屉缓存:用户选择保存,存入 vuex
this.$store.commit('game/set_reportDrawerCache', this.$clone(this.reportForm))
this.$emit('update:show', false)
}).catch(() => {
// 举报抽屉缓存:用户选择不保存,清除缓存
this.$store.commit('game/clear_reportDrawerCache')
this.$emit('update:show', false)
})
} else {
this.$emit('update:show', false)
}
},
async submit() {
console.log(this.userInfo, 'reportForm')
......@@ -799,7 +854,9 @@
this.loading = false
if (res.status_code === 1) {
this.$message.success('提交成功')
this.close()
// 举报抽屉缓存:提交成功后清除缓存,并直接关闭(不走 close 的未保存确认逻辑)
this.$store.commit('game/clear_reportDrawerCache')
this.$emit('update:show', false)
if (this.reportInfo && this.reportInfo.id) {
this.$emit('updateReportList')
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论