Browse Source

feat: 登录用cookie保存语言

igb 4 months ago
parent
commit
aa60b593fe
3 changed files with 5 additions and 9 deletions
  1. 1 2
      app/Admin/bootstrap.php
  2. 1 3
      app/Distributor/bootstrap.php
  3. 3 4
      app/helpers.php

+ 1 - 2
app/Admin/bootstrap.php

@@ -45,8 +45,7 @@ app()->singleton(Content::class, function () use ($newContent) {
 $user = Admin::guard()->check() ? Admin::user() : null;
 
 // 设置应用程序的本地化
-config(['app.locale' => Session::get('lang') ?: config('app.locale')]);
-
+config(['app.locale' => Cookie::get('lang') ?: config('app.locale')]);
 //编辑器配置
 Editor::resolving(function (Editor $editor) {
     // 设置默认配置

+ 1 - 3
app/Distributor/bootstrap.php

@@ -46,11 +46,9 @@ $user = Admin::guard()->check() ? Admin::user() : null;
 //覆盖默认配置
 config(['distributor.layout.home_url'=>getDistributorDomain()]);
 
-
-
 //// 覆盖默认配置
 //config(['admin' => user_admin_config()]);
-config(['app.locale' => Session::get('lang') ?: config('app.locale')]);
+config(['app.locale' => Cookie::get('lang') ?: config('app.locale')]);
 
 //编辑器配置
 Editor::resolving(function (Editor $editor) {

+ 3 - 4
app/helpers.php

@@ -3,6 +3,7 @@
 use Illuminate\Http\Request;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Facades\Session;
+use Illuminate\Support\Facades\Cookie;
 use Illuminate\Support\Str;
 
 if (! function_exists('user_admin_config')) {
@@ -46,7 +47,8 @@ if (! function_exists('switchLanguage')) {
             return false;
         }
 
-        Session::put('lang', $lang);
+
+        Cookie::queue('lang', $lang, 60 * 24 * 30); // 保存 30 天
 
         // 动态修改 app.locale 配置
         config(['app.locale' => $lang]);
@@ -56,8 +58,6 @@ if (! function_exists('switchLanguage')) {
 }
 
 
-
-
 if (!function_exists('getDistributor')) {
     /**
      * 获取会话中的 distributor 值
@@ -327,4 +327,3 @@ if (!function_exists('truncateString')) {
         return $string;
     }
 }
-