mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 19:40:53 +08:00
feat: optimize settings management and admin functionality
- Add system log cleanup functionality with batch processing - Optimize v2_settings table performance by unifying value storage - Add comprehensive client support list for one-click subscription - Fix QR code subscription links for specific node types - Fix route addition issues in admin management panel - Enhance admin system controller with log management APIs
This commit is contained in:
@@ -9,29 +9,60 @@ class Setting extends Model
|
||||
protected $table = 'v2_settings';
|
||||
protected $guarded = [];
|
||||
protected $casts = [
|
||||
'key' => 'string',
|
||||
'name' => 'string',
|
||||
'value' => 'string',
|
||||
];
|
||||
|
||||
public function getValueAttribute($value)
|
||||
/**
|
||||
* 获取实际内容值
|
||||
*/
|
||||
public function getContentValue()
|
||||
{
|
||||
if ($value === null) {
|
||||
$rawValue = $this->attributes['value'] ?? null;
|
||||
|
||||
if ($rawValue === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
// 如果已经是数组,直接返回
|
||||
if (is_array($rawValue)) {
|
||||
return $rawValue;
|
||||
}
|
||||
|
||||
if (is_numeric($value) && !preg_match('/[^\d.]/', $value)) {
|
||||
return $value;
|
||||
// 如果是数字字符串,返回原值
|
||||
if (is_numeric($rawValue) && !preg_match('/[^\d.]/', $rawValue)) {
|
||||
return $rawValue;
|
||||
}
|
||||
|
||||
$decodedValue = json_decode($value, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $decodedValue;
|
||||
// 尝试解析 JSON
|
||||
if (is_string($rawValue)) {
|
||||
$decodedValue = json_decode($rawValue, true);
|
||||
if (json_last_error() === JSON_ERROR_NONE) {
|
||||
return $decodedValue;
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $rawValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 兼容性:保持原有的 value 访问器
|
||||
*/
|
||||
public function getValueAttribute($value)
|
||||
{
|
||||
return $this->getContentValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建或更新设置项
|
||||
*/
|
||||
public static function createOrUpdate(string $name, $value): self
|
||||
{
|
||||
$processedValue = is_array($value) ? json_encode($value) : $value;
|
||||
|
||||
return self::updateOrCreate(
|
||||
['name' => $name],
|
||||
['value' => $processedValue]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user