fix(captain): 护栏/回复指南编辑按钮不生效

根因:
1. guardrails/guidelines 页面直接导航时 store 无助手记录,getRecord
   返回空对象导致列表为空、编辑无数据
2. storeFactoryHelper updateRecord 用 EDIT mutation(仅更新已有记录),
   store 为空时 API 返回数据被丢弃

修复:
- storeFactoryHelper: updateRecord 改用 UPSERT,确保 API 返回记录始终写入 store
- guardrails/Index.vue & guidelines/Index.vue: onMounted 时若 store 无记录
  则 dispatch captainAssistants/show 拉取单条助手数据
This commit is contained in:
Rogee
2026-08-01 16:24:09 +08:00
parent cd82d079e3
commit bb4c4bb807
3 changed files with 22 additions and 3 deletions
@@ -1,5 +1,5 @@
<script setup>
import { computed, ref } from 'vue';
import { computed, ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useAlert } from 'dashboard/composables';
@@ -30,6 +30,14 @@ const assistant = computed(() =>
store.getters['captainAssistants/getRecord'](assistantId.value)
);
// Fetch the assistant record if it's not already in the store
// (e.g. when navigating directly to this page via URL)
onMounted(() => {
if (!assistant.value?.id) {
store.dispatch('captainAssistants/show', assistantId.value);
}
});
const searchQuery = ref('');
const newInlineRule = ref('');
const newDialogRule = ref('');
@@ -1,5 +1,5 @@
<script setup>
import { computed, ref } from 'vue';
import { computed, ref, onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { useAlert } from 'dashboard/composables';
@@ -30,6 +30,14 @@ const assistant = computed(() =>
store.getters['captainAssistants/getRecord'](assistantId.value)
);
// Fetch the assistant record if it's not already in the store
// (e.g. when navigating directly to this page via URL)
onMounted(() => {
if (!assistant.value?.id) {
store.dispatch('captainAssistants/show', assistantId.value);
}
});
const searchQuery = ref('');
const newInlineRule = ref('');
const newDialogRule = ref('');
@@ -56,7 +56,10 @@ export const updateRecord =
commit(mutationTypes.SET_UI_FLAG, { updatingItem: true });
try {
const response = await API.update(id, updateObj);
commit(mutationTypes.EDIT, response.data);
// Use UPSERT instead of EDIT so that the record is added to the store
// even if it wasn't previously loaded (e.g. direct URL navigation to
// a sub-page like guardrails/guidelines without visiting the list page).
commit(mutationTypes.UPSERT, response.data);
return response.data;
} catch (error) {
return throwErrorMessage(error);