no message

This commit is contained in:
hellcat 2026-08-12 17:58:20 +08:00
parent 4ef0f285e7
commit f5853f780d
2 changed files with 23 additions and 11 deletions

View File

@ -239,16 +239,9 @@ public function hit(Request $oRequest)
$iId = request('id'); $iId = request('id');
$sField = request('field'); $sField = request('field');
$sFieldType = $this->aFieldTypes[$sField] ?? '';
$sHit = $this->oModel->find($iId)?->{$sField}; $sHit = $this->oModel->find($iId)?->{$sField};
if (is_array($sHit)) { if (is_array($sHit)) {
$sHit = json_encode($sHit); $sHit = json_encode($sHit, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
if ($sFieldType == 'json') {
$sHit = json_decode($sHit, true);
$sHit = json_encode($sHit, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} }
return response()->json([ return response()->json([
@ -302,6 +295,8 @@ public function detailSave(Request $oRequest)
unset($aParams['id'], $aParams['_method']); unset($aParams['id'], $aParams['_method']);
$aCasts = $oThisModel->getCasts();
foreach ($aParams as $k => &$v) { foreach ($aParams as $k => &$v) {
if (empty($v) && empty($oThisModel->{$k})) { if (empty($v) && empty($oThisModel->{$k})) {
continue; continue;
@ -309,12 +304,22 @@ public function detailSave(Request $oRequest)
if (empty($v) && $v !== 0 && $v !== '0') { if (empty($v) && $v !== 0 && $v !== '0') {
$v = ''; $v = '';
} }
$sCastType = $aCasts[$k] ?? null;
if (in_array($sCastType, ['array', 'json', 'collection'], true) && is_string($v)) {
// 如果传入的是字符串,手动解码为数组,防止 Eloquent 在 save 时二次转义
$aDecoded = json_decode($v, true);
// if (json_last_error() === JSON_ERROR_NONE && is_array($aDecoded)) {
$v = $aDecoded;
// }
}
if ($oThisModel->{$k} != $v) { if ($oThisModel->{$k} != $v) {
$oThisModel->{$k} = $v; $oThisModel->{$k} = $v;
} }
} }
$oThisModel->save(); $oThisModel->save(); // 在这里保存的aOpt如何避免被转译
$aChangeField = $oThisModel->getChanges(); $aChangeField = $oThisModel->getChanges();
@ -464,7 +469,14 @@ public function index(Request $oRequest)
$oQuery->orderBy($aOrderBy['sField'], $aOrderBy['sSort']); $oQuery->orderBy($aOrderBy['sField'], $aOrderBy['sSort']);
} }
$oPaginatedData = $oQuery->paginate($iLimit); $oPaginatedData = $oQuery->paginate($iLimit); // 倾向方案2
// $oPaginatedData->getCollection()->transform(function ($oArticle) {
// // 强制将模型属性还原为未经 Cast 处理的原始字典
// $oArticle->setRawAttributes($oArticle->getRawOriginal());
//
// return $oArticle;
// });
// tt($oPaginatedData); // tt($oPaginatedData);
// $oPaginatedData = $oQuery->paginate($iLimit, array_keys($this->aListFields)); // $oPaginatedData = $oQuery->paginate($iLimit, array_keys($this->aListFields));

View File

@ -40,7 +40,7 @@ final class CategoryBaseController extends ListController
// 'schema_pro' => 'text', // 'schema_pro' => 'text',
// 'cmd' => 'text', // 'cmd' => 'text',
// 'cmd_log' => 'text', // 'cmd_log' => 'text',
'aBanner' => 'json' // 'aBanner' => 'array'
]; ];
protected array $aOrderBy = [ protected array $aOrderBy = [