From cacb54851715dd7e2e34c67655e3ffc58d90b649 Mon Sep 17 00:00:00 2001 From: TianyangZhang Date: Fri, 15 May 2026 17:03:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(hrm):=20=E4=BA=BA=E5=91=98=E4=BA=A4?= =?UTF-8?q?=E6=8E=A5=E8=AF=A6=E6=83=85=E6=8A=BD=E5=B1=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=8D=E5=9B=9E=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit el-drawer 早期渲染插槽时 t_id 仍为 null,mounted() 走到 else 分支把 localMode 设成 add,后续 prop 变化 getTid 不再触发。 改用 watch t_id (immediate:true),prop 何时到位都能拉数据。 同时给 system.post.list 单独加 try/catch 并对 state_ 做空安全 访问,避免内层异常吃掉主数据赋值。 Co-Authored-By: Claude Opus 4.7 (1M context) --- src/views/hrm/empjoin_form.vue | 41 +++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/views/hrm/empjoin_form.vue b/src/views/hrm/empjoin_form.vue index 9df17526..3ac84a7f 100644 --- a/src/views/hrm/empjoin_form.vue +++ b/src/views/hrm/empjoin_form.vue @@ -188,15 +188,22 @@ export default { }) }, deep: true, + }, + t_id: { + handler(val) { + this.localMode = this.mode; + if (val) { + this.getTid(); + } else { + this.formData = { person: [] }; + this.localMode = "add"; + } + }, + immediate: true, } }, mounted() { this.getGroup(); - if (this.t_id) { - this.getTid(); - } else { - this.localMode = "add"; - } }, methods: { async getTid() { @@ -204,18 +211,22 @@ export default { let res = await this.$API.hrm.empjoin.item.req(this.t_id); // 获取岗位列表,填充 post_name if (res.person && res.person.length > 0) { - const postRes = await this.$API.system.post.list.req({ page: 0 }); - const postList = Array.isArray(postRes) ? postRes : (postRes.results || postRes.data || []); - const postMap = {}; - postList.forEach(p => { postMap[p.id] = p.name; }); - res.person.forEach(p => { - if (p.post && !p.post_name) { - p.post_name = postMap[p.post] || ''; - } - }); + try { + const postRes = await this.$API.system.post.list.req({ page: 0 }); + const postList = Array.isArray(postRes) ? postRes : (postRes.results || postRes.data || []); + const postMap = {}; + postList.forEach(p => { postMap[p.id] = p.name; }); + res.person.forEach(p => { + if (p.post && !p.post_name) { + p.post_name = postMap[p.post] || ''; + } + }); + } catch (postErr) { + console.error('获取岗位列表失败:', postErr); + } } this.formData = res; - if (res.ticket_ && res.ticket_.state_.type == 1 && res.create_by == this.$TOOL.data.get("USER_INFO").id) { + if (res.ticket_ && res.ticket_.state_ && res.ticket_.state_.type == 1 && res.create_by == this.$TOOL.data.get("USER_INFO").id) { this.localMode = "edit"; } } catch (error) {