fix: improve error handling and enhance setting management

- Updated error handling in GetSetting to use errors.Is for better clarity when checking for no documents.
- Refactored setting retrieval in the Vuex store to ensure a default value is set if the retrieved setting is empty.
- Adjusted API calls in the store to wrap payloads in a data object for consistency.
- Cleaned up SystemDetail.vue by removing unnecessary navigation actions for a more streamlined UI.
- Enhanced conditional rendering in SystemDetailTabDependency to ensure form value checks are safe.
- Replaced el-input with cl-edit-input in SystemDetailTabCustomize for improved input handling and added change event for saving.
This commit is contained in:
Marvin Zhang
2025-04-17 14:50:59 +08:00
parent e0649dc91f
commit 336ca5770b
5 changed files with 13 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package controllers
import (
"errors"
"github.com/crawlab-team/crawlab/core/models/models"
"github.com/crawlab-team/crawlab/core/models/service"
"github.com/gin-gonic/gin"
@@ -16,7 +17,7 @@ func GetSetting(_ *gin.Context, params *GetSettingParams) (response *Response[mo
// setting
s, err := service.NewModelService[models.Setting]().GetOne(bson.M{"key": params.Key}, nil)
if err != nil {
if err == mongo.ErrNoDocuments {
if errors.Is(err, mongo.ErrNoDocuments) {
return GetDataResponse(models.Setting{})
}
return GetErrorResponse[models.Setting](err)

View File

@@ -34,8 +34,12 @@ const actions = {
{ key }: { key: string }
) => {
const res = await get(`/settings/${key}`);
const resData = res.data || getDefaultSetting(key);
commit('setSetting', { key, value: resData });
const setting = res.data || getDefaultSetting(key);
if (!setting.value) {
setting.value = {};
}
console.debug(setting)
commit('setSetting', { key, value: setting });
},
saveSetting: async (
_: StoreActionContext<SystemStoreState>,
@@ -48,9 +52,9 @@ const actions = {
}
) => {
if (!value._id) {
await post(`/settings/${key}`, value);
await post(`/settings/${key}`, {data: value});
} else {
await put(`/settings/${key}`, value);
await put(`/settings/${key}`, {data: value});
}
},
} as SystemStoreActions;

View File

@@ -59,13 +59,6 @@ defineOptions({ name: 'ClSystemDetail' });
<template>
<div class="system-detail">
<cl-nav-actions>
<cl-nav-action-group-detail-common
:show-back-button="false"
:show-save-button="true"
@save="onSave"
/>
</cl-nav-actions>
<div class="system-detail-content-wrapper">
<el-menu
:default-active="activeItemKey"

View File

@@ -94,10 +94,11 @@ defineOptions({ name: 'ClSystemDetailTabCustomize' });
prop="custom_title"
:required="form.value.show_custom_title"
>
<el-input
<cl-edit-input
v-model="form.value.custom_title"
:disabled="!form.value.show_custom_title"
:placeholder="t('views.system.customize.customTitle')"
@change="onSave"
/>
</cl-form-item>

View File

@@ -43,7 +43,7 @@ defineOptions({ name: 'ClSystemDetailTabDependency' });
</script>
<template>
<cl-form v-if="form" ref="formRef" :model="form.value" label-width="200px">
<cl-form v-if="form?.value" ref="formRef" :model="form.value" label-width="200px">
<cl-form-item
:span="4"
:label="t('views.system.dependency.autoInstall')"