diff --git a/app/controller/UploadController.php b/app/controller/UploadController.php index 3576db5..328a67d 100644 --- a/app/controller/UploadController.php +++ b/app/controller/UploadController.php @@ -11,8 +11,9 @@ use Shopwwi\WebmanFilesystem\Facade\Storage; use support\Log; use support\Request; use util\Util; +use plugin\admin\app\controller\Base; -class UploadController +class UploadController extends Base { /** diff --git a/plugin/admin/app/controller/IndexController.php b/plugin/admin/app/controller/IndexController.php index 1231acd..cf509cc 100644 --- a/plugin/admin/app/controller/IndexController.php +++ b/plugin/admin/app/controller/IndexController.php @@ -4,6 +4,7 @@ namespace plugin\admin\app\controller; use plugin\admin\app\common\Util; use plugin\admin\app\model\Option; +use plugin\admin\app\model\Rule; use plugin\admin\app\model\User; use support\exception\BusinessException; use support\Request; @@ -48,7 +49,26 @@ class IndexController $logo = $config['logo']['image'] ?? '/app/admin/admin/images/logo.png'; return raw_view('account/login',['logo'=>$logo,'title'=>$title]); } - return raw_view('index/index'); + // 获取当前语言 + $lang = session('lang', 'zh-cn'); + + // 加载语言文件 + $common_translations = include __DIR__ . "/../lang/{$lang}/common.php"; + + // 获取菜单并应用翻译 + $rules = Rule::whereIn('type', [0, 1])->orderBy('weight')->get(); + $menus = []; + foreach ($rules as $rule) { + $menu = $rule->toArray(); + $menu['title'] = $rule->getTranslatedTitle($lang); + $menus[] = $menu; + } + + return view('index/index', [ + 'lang' => $lang, + 'translations' => $common_translations, + 'menus' => $menus + ]); } /** diff --git a/plugin/admin/app/controller/LanguageController.php b/plugin/admin/app/controller/LanguageController.php new file mode 100644 index 0000000..76bf7ff --- /dev/null +++ b/plugin/admin/app/controller/LanguageController.php @@ -0,0 +1,78 @@ +post('lang'); + Log::info('Language switch request received', [ + 'lang' => $lang, + 'method' => $request->method(), + 'headers' => $request->header(), + 'input' => $request->all() + ]); + + if (!$lang) { + Log::warning('No language specified in request'); + return json(['code' => 1, 'msg' => '未指定语言']); + } + + if (!in_array($lang, ['zh-cn', 'en', 'ru', 'ar'])) { + Log::warning('Unsupported language', ['lang' => $lang]); + return json(['code' => 1, 'msg' => '不支持的语言']); + } + + // 设置语言到session + session(['lang' => $lang]); + Log::info('Language set to session', ['lang' => $lang]); + + // 获取当前页面的URL + $referer = $request->header('referer'); + if (!$referer) { + $referer = '/'; + } + Log::info('Redirect URL', ['referer' => $referer]); + + return json([ + 'code' => 0, + 'msg' => '切换成功', + 'data' => [ + 'redirect' => $referer + ] + ]); + } catch (\Exception $e) { + Log::error('Language switch error', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString() + ]); + return json([ + 'code' => 1, + 'msg' => '切换语言失败: ' . $e->getMessage() + ]); + } + } +} \ No newline at end of file diff --git a/plugin/admin/app/controller/LocationController.php b/plugin/admin/app/controller/LocationController.php index cfe8791..fcab2f1 100644 --- a/plugin/admin/app/controller/LocationController.php +++ b/plugin/admin/app/controller/LocationController.php @@ -8,6 +8,7 @@ use plugin\admin\app\model\Location; use plugin\admin\app\controller\Crud; use support\exception\BusinessException; use util\Util; +use support\Log; /** * 仓库/港口 @@ -35,7 +36,22 @@ class LocationController extends Crud */ public function index(): Response { - return view('location/index'); + // 获取当前语言 + $lang = session('lang', 'zh-cn'); + Log::info('Current language', ['lang' => $lang]); + + // 加载语言文件 + $location_translations = include __DIR__ . "/../lang/{$lang}/location.php"; + $common_translations = include __DIR__ . "/../lang/{$lang}/common.php"; + + // 合并翻译 + $translations = array_merge($location_translations, $common_translations); + Log::info('Loaded translations', ['keys' => array_keys($translations)]); + + return view('location/index', [ + 'lang' => $lang, + 'translations' => $translations + ]); } /** @@ -49,7 +65,20 @@ class LocationController extends Crud if ($request->method() === 'POST') { return parent::insert($request); } - return view('location/insert'); + // 获取当前语言 + $lang = session('lang', 'zh-cn'); + + // 加载语言文件 + $location_translations = include __DIR__ . "/../lang/{$lang}/location.php"; + $common_translations = include __DIR__ . "/../lang/{$lang}/common.php"; + + // 合并翻译 + $translations = array_merge($location_translations, $common_translations); + + return view('location/insert', [ + 'lang' => $lang, + 'translations' => $translations + ]); } /** @@ -63,7 +92,20 @@ class LocationController extends Crud if ($request->method() === 'POST') { return parent::update($request); } - return view('location/update'); + // 获取当前语言 + $lang = session('lang', 'zh-cn'); + + // 加载语言文件 + $location_translations = include __DIR__ . "/../lang/{$lang}/location.php"; + $common_translations = include __DIR__ . "/../lang/{$lang}/common.php"; + + // 合并翻译 + $translations = array_merge($location_translations, $common_translations); + + return view('location/update', [ + 'lang' => $lang, + 'translations' => $translations + ]); } /** diff --git a/plugin/admin/app/controller/RuleController.php b/plugin/admin/app/controller/RuleController.php index 9a6fbca..803ede0 100644 --- a/plugin/admin/app/controller/RuleController.php +++ b/plugin/admin/app/controller/RuleController.php @@ -67,18 +67,26 @@ class RuleController extends Crud */ function get(Request $request): Response { + // 添加调试日志 + error_log("RuleController::get called"); + $rules = $this->getRules(admin('roles')); $types = $request->get('type', '0,1'); $types = is_string($types) ? explode(',', $types) : [0, 1]; - $items = Rule::orderBy('weight', 'desc')->get()->toArray(); - + $items = Rule::orderBy('weight', 'desc')->get(); + + // 获取当前语言 + $lang = session('lang', 'zh-cn'); + $formatted_items = []; foreach ($items as $item) { - $item['pid'] = (int)$item['pid']; - $item['name'] = $item['title']; - $item['value'] = $item['id']; - $item['icon'] = $item['icon'] ? "layui-icon {$item['icon']}" : ''; - $formatted_items[] = $item; + $item_array = $item->toArray(); + $item_array['pid'] = (int)$item_array['pid']; + $item_array['name'] = $item->getTranslatedTitle($lang); + $item_array['title'] = $item->getTranslatedTitle($lang); + $item_array['value'] = $item_array['id']; + $item_array['icon'] = $item_array['icon'] ? "layui-icon {$item_array['icon']}" : ''; + $formatted_items[] = $item_array; } $tree = new Tree($formatted_items); @@ -89,6 +97,10 @@ class RuleController extends Crud } $this->removeNotContain($tree_items, 'type', $types); $menus = $this->empty_filter(Tree::arrayValues($tree_items)); + + // 添加调试日志 + error_log("RuleController::get returning menus: " . json_encode($menus)); + return $this->json(0, 'ok', $menus); } diff --git a/plugin/admin/app/controller/RuleTranslationController.php b/plugin/admin/app/controller/RuleTranslationController.php new file mode 100644 index 0000000..7976a0f --- /dev/null +++ b/plugin/admin/app/controller/RuleTranslationController.php @@ -0,0 +1,57 @@ +get('rule_id'); + $lang = $request->get('lang'); + + if (!$ruleId || !$lang) { + return json(['code' => 1, 'msg' => '参数错误']); + } + + $translation = RuleTranslation::where('rule_id', $ruleId) + ->where('lang', $lang) + ->first(); + + return json(['code' => 0, 'data' => $translation]); + } + + /** + * 保存规则的翻译 + * @param Request $request + * @return Response + */ + public function save(Request $request): Response + { + $ruleId = $request->post('rule_id'); + $lang = $request->post('lang'); + $title = $request->post('title'); + + if (!$ruleId || !$lang || !$title) { + return json(['code' => 1, 'msg' => '参数错误']); + } + + $rule = Rule::find($ruleId); + if (!$rule) { + return json(['code' => 1, 'msg' => '规则不存在']); + } + + $result = $rule->setTranslatedTitle($lang, $title); + + return json(['code' => 0, 'msg' => '保存成功']); + } +} \ No newline at end of file diff --git a/plugin/admin/app/controller/UploadController.php b/plugin/admin/app/controller/UploadController.php index 3616949..8b4a2c7 100644 --- a/plugin/admin/app/controller/UploadController.php +++ b/plugin/admin/app/controller/UploadController.php @@ -24,6 +24,12 @@ class UploadController extends Crud */ protected $model = null; + /** + * 不需要鉴权的方法 + * @var string[] + */ + protected $noNeedAuth = ['uploadImage']; + /** * 只返回当前管理员数据 * @var string diff --git a/plugin/admin/app/controller/VehicleController.php b/plugin/admin/app/controller/VehicleController.php index 5a47b48..401ad87 100644 --- a/plugin/admin/app/controller/VehicleController.php +++ b/plugin/admin/app/controller/VehicleController.php @@ -1,4 +1,5 @@ $lang, + 'translations' => $translations + ]); } /** @@ -61,10 +70,15 @@ class VehicleController extends Crud */ public function insert(Request $request): Response { - if ($request->method() === 'POST') { - return parent::insert($request); - } - return view('vehicle/insert'); + $lang = session('lang', 'zh-cn'); + $translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php'; + $common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php'; + $translations = array_merge($translations, $common); + + return view('vehicle/insert', [ + 'lang' => $lang, + 'translations' => $translations + ]); } /** @@ -75,14 +89,25 @@ class VehicleController extends Crud */ public function update(Request $request): Response { - if ($request->method() === 'POST') { - return parent::update($request); + $id = $request->input('id'); + $lang = session('lang', 'zh-cn'); + $translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php'; + $common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php'; + $translations = array_merge($translations, $common); + + $data = Vehicle::where('id', $id)->first(); + if (!$data) { + return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']); } - return view('vehicle/update'); + + return view('vehicle/update', [ + 'id' => $id, + 'data' => $data, + 'lang' => $lang, + 'translations' => $translations + ]); } - - /** * 详情 * @param Request $request @@ -91,28 +116,24 @@ class VehicleController extends Crud */ public function detail(Request $request): Response { - return view('vehicle/detail'); + $id = $request->input('id'); + $lang = session('lang', 'zh-cn'); + $translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php'; + $common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php'; + $translations = array_merge($translations, $common); + + $data = Vehicle::where('id', $id)->first(); + if (!$data) { + return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']); + } + + return view('vehicle/detail', [ + 'data' => $data, + 'lang' => $lang, + 'translations' => $translations + ]); } - /** - * 查询 - * @param Request $request - * @return Response - * @throws BusinessException - */ -/* public function list(Request $request) - { - [$where, $format, $limit, $field, $order] = $this->selectInput($request); - return json($where); - $query = $this->doSelect($where, $field, $order); - $data = $this->doFormat($query, $format, $limit); -// foreach ($data['data'] as &$value) { -// $value['locations'] = Location::find($value['locations_id'])->name; -// } -// $data = json_decode(json_encode($data), true); - return $data; - }*/ - /** * 查询后置处理,添加位置信息 * @param mixed $items @@ -129,13 +150,6 @@ class VehicleController extends Crud $fbo_location = Location::find($item->fbo_locations_id); $item->fbo_location_name = $fbo_location ? $fbo_location->name : ''; -// if(!str_starts_with($item['img_url'], 'http')){ -// $ossservice = new OssService(); -// $img_url = $ossservice->generatePrivateUrl($item['img_url'], 3600); -// $item['img_url'] = $img_url; -// } - - if(!str_starts_with($item['img_url'], 'http')){ try { $ossservice = new OssService(); diff --git a/plugin/admin/app/lang/ar/common.php b/plugin/admin/app/lang/ar/common.php new file mode 100644 index 0000000..be1480a --- /dev/null +++ b/plugin/admin/app/lang/ar/common.php @@ -0,0 +1,33 @@ + 'لوحة التحكم', + 'menu_vehicle' => 'إدارة المركبات', + 'menu_vehicle_list' => 'قائمة المركبات', + 'menu_vehicle_add' => 'إضافة مركبة', + 'menu_vehicle_edit' => 'تعديل مركبة', + 'menu_vehicle_view' => 'عرض مركبة', + + // الترويسة + 'header_welcome' => 'مرحباً', + 'header_profile' => 'الملف الشخصي', + 'header_settings' => 'الإعدادات', + 'header_logout' => 'تسجيل الخروج', + 'header_language' => 'اللغة', + + // الأزرار العامة + 'btn_save' => 'حفظ', + 'btn_cancel' => 'إلغاء', + 'btn_confirm' => 'تأكيد', + 'btn_back' => 'رجوع', + 'btn_search' => 'بحث', + 'btn_reset' => 'إعادة تعيين', + + // النصائح العامة + 'tip_loading' => 'جاري التحميل...', + 'tip_success' => 'تمت العملية بنجاح', + 'tip_error' => 'فشلت العملية', + 'tip_confirm' => 'تأكيد العملية؟', + 'tip_cancel' => 'إلغاء العملية؟', +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/ar/location.php b/plugin/admin/app/lang/ar/location.php new file mode 100644 index 0000000..a77862b --- /dev/null +++ b/plugin/admin/app/lang/ar/location.php @@ -0,0 +1,30 @@ + 'إدارة المواقع', + 'add' => 'إضافة', + 'delete' => 'حذف', + 'edit' => 'تعديل', + 'remove' => 'إزالة', + 'refresh' => 'تحديث', + 'filter' => 'تصفية', + 'print' => 'طباعة', + 'export' => 'تصدير', + 'confirm_delete' => 'هل أنت متأكد من الحذف؟', + 'operation_success' => 'تمت العملية بنجاح', + 'no_data_selected' => 'لم يتم تحديد بيانات', + 'id' => 'المعرف', + 'name' => 'اسم الميناء/المستودع', + 'name_en' => 'الاسم بالإنجليزية', + 'address' => 'العنوان', + 'area' => 'المنطقة', + 'type' => 'النوع', + 'type_port' => 'ميناء', + 'type_warehouse' => 'مستودع', + 'num' => 'عدد المركبات', + 'created_at' => 'تاريخ الإنشاء', + 'updated_at' => 'تاريخ التحديث', + 'operation' => 'عملية', + 'submit' => 'إرسال', + 'reset' => 'إعادة تعيين' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/ar/vehicle.php b/plugin/admin/app/lang/ar/vehicle.php new file mode 100644 index 0000000..8574a1a --- /dev/null +++ b/plugin/admin/app/lang/ar/vehicle.php @@ -0,0 +1,42 @@ + 'إدارة المركبات', + 'add' => 'إضافة', + 'delete' => 'حذف', + 'edit' => 'تعديل', + 'remove' => 'إزالة', + 'refresh' => 'تحديث', + 'filter' => 'تصفية', + 'print' => 'طباعة', + 'export' => 'تصدير', + 'confirm_delete' => 'هل أنت متأكد من الحذف؟', + 'operation_success' => 'تمت العملية بنجاح', + 'no_data_selected' => 'لم يتم تحديد بيانات', + 'id' => 'المعرف', + 'name' => 'اسم المركبة', + 'name_en' => 'الاسم بالإنجليزية', + 'vin' => 'رقم الهيكل', + 'status' => 'الحالة', + 'status_unknown' => 'غير معروف', + 'status_pending' => 'في انتظار الشحن', + 'status_in_transit_to_port' => 'في الطريق (إلى ميناء FBO)', + 'status_arrived_at_port' => 'وصل إلى ميناء الشحن', + 'status_in_transit_to_warehouse' => 'في الطريق (إلى مستودع الوجهة)', + 'status_arrived_at_warehouse' => 'وصل إلى المستودع', + 'status_sold' => 'تم البيع', + 'location' => 'الموقع الحالي', + 'final_location' => 'الوجهة', + 'fbo_location' => 'ميناء FBO', + 'img_url' => 'صورة المركبة', + 'created_at' => 'تاريخ الإنشاء', + 'updated_at' => 'تاريخ التحديث', + 'operation' => 'عملية', + 'submit' => 'إرسال', + 'reset' => 'إعادة تعيين', + 'detail' => 'تفاصيل', + 'upload_image' => 'تحميل صورة', + 'select_location' => 'اختر الموقع', + 'select_final_location' => 'اختر الوجهة', + 'select_fbo_location' => 'اختر ميناء FBO' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/en/common.php b/plugin/admin/app/lang/en/common.php new file mode 100644 index 0000000..c1c1b6f --- /dev/null +++ b/plugin/admin/app/lang/en/common.php @@ -0,0 +1,33 @@ + 'Dashboard', + 'menu_vehicle' => 'Vehicle Management', + 'menu_vehicle_list' => 'Vehicle List', + 'menu_vehicle_add' => 'Add Vehicle', + 'menu_vehicle_edit' => 'Edit Vehicle', + 'menu_vehicle_view' => 'View Vehicle', + + // Header + 'header_welcome' => 'Welcome', + 'header_profile' => 'Profile', + 'header_settings' => 'Settings', + 'header_logout' => 'Logout', + 'header_language' => 'Language', + + // Common Buttons + 'btn_save' => 'Save', + 'btn_cancel' => 'Cancel', + 'btn_confirm' => 'Confirm', + 'btn_back' => 'Back', + 'btn_search' => 'Search', + 'btn_reset' => 'Reset', + + // Common Tips + 'tip_loading' => 'Loading...', + 'tip_success' => 'Operation successful', + 'tip_error' => 'Operation failed', + 'tip_confirm' => 'Confirm operation?', + 'tip_cancel' => 'Cancel operation?', +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/en/location.php b/plugin/admin/app/lang/en/location.php new file mode 100644 index 0000000..284bafa --- /dev/null +++ b/plugin/admin/app/lang/en/location.php @@ -0,0 +1,30 @@ + 'Location Management', + 'add' => 'Add', + 'delete' => 'Delete', + 'edit' => 'Edit', + 'remove' => 'Remove', + 'refresh' => 'Refresh', + 'filter' => 'Filter', + 'print' => 'Print', + 'export' => 'Export', + 'confirm_delete' => 'Are you sure to delete?', + 'operation_success' => 'Operation successful', + 'no_data_selected' => 'No data selected', + 'id' => 'ID', + 'name' => 'Port/Warehouse Name', + 'name_en' => 'English Name', + 'address' => 'Address', + 'area' => 'Area', + 'type' => 'Type', + 'type_port' => 'Port', + 'type_warehouse' => 'Warehouse', + 'num' => 'Vehicle Count', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + 'operation' => 'Operation', + 'submit' => 'Submit', + 'reset' => 'Reset' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/en/vehicle.php b/plugin/admin/app/lang/en/vehicle.php new file mode 100644 index 0000000..f3b75f5 --- /dev/null +++ b/plugin/admin/app/lang/en/vehicle.php @@ -0,0 +1,46 @@ + 'Vehicle Management', + 'add' => 'Add', + 'edit' => 'Edit', + 'delete' => 'Delete', + 'remove' => 'Remove', + 'detail' => 'Detail', + 'submit' => 'Submit', + 'reset' => 'Reset', + 'operation_success' => 'Operation successful', + 'data_not_found' => 'Data not found', + 'no_data_selected' => 'No data selected', + 'confirm_delete' => 'Are you sure you want to delete?', + + 'name' => 'Name', + 'name_placeholder' => 'Please enter name', + 'name_en' => 'English Name', + 'name_en_placeholder' => 'Please enter English name', + 'vin' => 'VIN', + 'vin_placeholder' => 'Please enter VIN', + 'status' => 'Status', + 'status_placeholder' => 'Please select status', + 'status_1' => 'Normal', + 'status_0' => 'Disabled', + 'location' => 'Current Location', + 'location_placeholder' => 'Please select current location', + 'final_location' => 'Final Location', + 'final_location_placeholder' => 'Please select final location', + 'fbo_location' => 'FBO Location', + 'fbo_location_placeholder' => 'Please select FBO location', + 'img_url' => 'Image', + 'img_url_placeholder' => 'Please enter image URL', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + 'refresh' => 'Refresh', + 'filter' => 'Filter', + 'print' => 'Print', + 'export' => 'Export', + 'operation' => 'Operation', + 'upload_image' => 'Upload Image', + 'select_location' => 'Select Location', + 'select_final_location' => 'Select Destination', + 'select_fbo_location' => 'Select FBO Port' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/ru/common.php b/plugin/admin/app/lang/ru/common.php new file mode 100644 index 0000000..a3d966e --- /dev/null +++ b/plugin/admin/app/lang/ru/common.php @@ -0,0 +1,33 @@ + 'Панель управления', + 'menu_vehicle' => 'Управление автомобилями', + 'menu_vehicle_list' => 'Список автомобилей', + 'menu_vehicle_add' => 'Добавить автомобиль', + 'menu_vehicle_edit' => 'Редактировать автомобиль', + 'menu_vehicle_view' => 'Просмотр автомобиля', + + // Заголовок + 'header_welcome' => 'Добро пожаловать', + 'header_profile' => 'Профиль', + 'header_settings' => 'Настройки', + 'header_logout' => 'Выйти', + 'header_language' => 'Язык', + + // Общие кнопки + 'btn_save' => 'Сохранить', + 'btn_cancel' => 'Отмена', + 'btn_confirm' => 'Подтвердить', + 'btn_back' => 'Назад', + 'btn_search' => 'Поиск', + 'btn_reset' => 'Сбросить', + + // Общие подсказки + 'tip_loading' => 'Загрузка...', + 'tip_success' => 'Операция успешна', + 'tip_error' => 'Операция не удалась', + 'tip_confirm' => 'Подтвердить операцию?', + 'tip_cancel' => 'Отменить операцию?', +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/ru/location.php b/plugin/admin/app/lang/ru/location.php new file mode 100644 index 0000000..e3bca9f --- /dev/null +++ b/plugin/admin/app/lang/ru/location.php @@ -0,0 +1,30 @@ + 'Управление местоположениями', + 'add' => 'Добавить', + 'delete' => 'Удалить', + 'edit' => 'Редактировать', + 'remove' => 'Удалить', + 'refresh' => 'Обновить', + 'filter' => 'Фильтр', + 'print' => 'Печать', + 'export' => 'Экспорт', + 'confirm_delete' => 'Вы уверены, что хотите удалить?', + 'operation_success' => 'Операция успешна', + 'no_data_selected' => 'Данные не выбраны', + 'id' => 'ID', + 'name' => 'Название порта/склада', + 'name_en' => 'Название на английском', + 'address' => 'Адрес', + 'area' => 'Район', + 'type' => 'Тип', + 'type_port' => 'Порт', + 'type_warehouse' => 'Склад', + 'num' => 'Количество автомобилей', + 'created_at' => 'Дата создания', + 'updated_at' => 'Дата обновления', + 'operation' => 'Операция', + 'submit' => 'Отправить', + 'reset' => 'Сбросить' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/ru/vehicle.php b/plugin/admin/app/lang/ru/vehicle.php new file mode 100644 index 0000000..0311897 --- /dev/null +++ b/plugin/admin/app/lang/ru/vehicle.php @@ -0,0 +1,58 @@ + 'Управление транспортными средствами', + 'add' => 'Добавить', + 'edit' => 'Редактировать', + 'delete' => 'Удалить', + 'remove' => 'Удалить', + 'detail' => 'Детали', + 'submit' => 'Отправить', + 'reset' => 'Сбросить', + 'operation_success' => 'Операция успешна', + 'data_not_found' => 'Данные не найдены', + 'no_data_selected' => 'Данные не выбраны', + 'confirm_delete' => 'Вы уверены, что хотите удалить?', + + 'name' => 'Название', + 'name_placeholder' => 'Введите название', + 'name_en' => 'Название на английском', + 'name_en_placeholder' => 'Введите название на английском', + 'vin' => 'VIN', + 'vin_placeholder' => 'Введите VIN', + 'status' => 'Статус', + 'status_placeholder' => 'Выберите статус', + 'status_1' => 'Нормальный', + 'status_0' => 'Отключен', + 'location' => 'Текущее местоположение', + 'location_placeholder' => 'Выберите текущее местоположение', + 'final_location' => 'Конечное местоположение', + 'final_location_placeholder' => 'Выберите конечное местоположение', + 'fbo_location' => 'Местоположение FBO', + 'fbo_location_placeholder' => 'Выберите местоположение FBO', + 'img_url' => 'Изображение', + 'img_url_placeholder' => 'Введите URL изображения', + 'created_at' => 'Создано', + 'updated_at' => 'Обновлено', + 'status_unknown' => 'Неизвестно', + 'status_pending' => 'Ожидает отправки', + 'status_in_transit_to_port' => 'В пути (к порту FBO)', + 'status_arrived_at_port' => 'Прибыл в порт отправки', + 'status_in_transit_to_warehouse' => 'В пути (к складу назначения)', + 'status_arrived_at_warehouse' => 'Прибыл на склад', + 'status_sold' => 'Продан', + 'location' => 'Текущее местоположение', + 'final_location' => 'Место назначения', + 'fbo_location' => 'Порт FBO', + 'img_url' => 'Изображение транспортного средства', + 'created_at' => 'Дата создания', + 'updated_at' => 'Дата обновления', + 'operation' => 'Операция', + 'submit' => 'Отправить', + 'reset' => 'Сбросить', + 'detail' => 'Детали', + 'upload_image' => 'Загрузить изображение', + 'select_location' => 'Выбрать местоположение', + 'select_final_location' => 'Выбрать место назначения', + 'select_fbo_location' => 'Выбрать порт FBO' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/zh-cn/common.php b/plugin/admin/app/lang/zh-cn/common.php new file mode 100644 index 0000000..14f6567 --- /dev/null +++ b/plugin/admin/app/lang/zh-cn/common.php @@ -0,0 +1,33 @@ + '控制台', + 'menu_vehicle' => '车辆管理', + 'menu_vehicle_list' => '车辆列表', + 'menu_vehicle_add' => '添加车辆', + 'menu_vehicle_edit' => '编辑车辆', + 'menu_vehicle_view' => '查看车辆', + + // 页面头部 + 'header_welcome' => '欢迎', + 'header_profile' => '个人中心', + 'header_settings' => '设置', + 'header_logout' => '退出登录', + 'header_language' => '语言', + + // 通用按钮 + 'btn_save' => '保存', + 'btn_cancel' => '取消', + 'btn_confirm' => '确认', + 'btn_back' => '返回', + 'btn_search' => '搜索', + 'btn_reset' => '重置', + + // 通用提示 + 'tip_loading' => '加载中...', + 'tip_success' => '操作成功', + 'tip_error' => '操作失败', + 'tip_confirm' => '确认操作?', + 'tip_cancel' => '取消操作?', +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/zh-cn/location.php b/plugin/admin/app/lang/zh-cn/location.php new file mode 100644 index 0000000..54dd0e1 --- /dev/null +++ b/plugin/admin/app/lang/zh-cn/location.php @@ -0,0 +1,30 @@ + '位置管理', + 'add' => '新增', + 'delete' => '删除', + 'edit' => '编辑', + 'remove' => '删除', + 'refresh' => '刷新', + 'filter' => '筛选', + 'print' => '打印', + 'export' => '导出', + 'confirm_delete' => '确定删除?', + 'operation_success' => '操作成功', + 'no_data_selected' => '未选中数据', + 'id' => '唯一标识', + 'name' => '港口/仓库名称', + 'name_en' => '英文名称', + 'address' => '详细地址', + 'area' => '所在地区', + 'type' => '类型', + 'type_port' => '港口', + 'type_warehouse' => '仓库', + 'num' => '车辆数', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + 'operation' => '操作', + 'submit' => '提交', + 'reset' => '重置' +]; \ No newline at end of file diff --git a/plugin/admin/app/lang/zh-cn/vehicle.php b/plugin/admin/app/lang/zh-cn/vehicle.php new file mode 100644 index 0000000..4cf7144 --- /dev/null +++ b/plugin/admin/app/lang/zh-cn/vehicle.php @@ -0,0 +1,46 @@ + '车辆管理', + 'add' => '新增', + 'edit' => '编辑', + 'delete' => '删除', + 'remove' => '删除', + 'detail' => '详情', + 'submit' => '提交', + 'reset' => '重置', + 'operation_success' => '操作成功', + 'data_not_found' => '数据不存在', + 'no_data_selected' => '未选择数据', + 'confirm_delete' => '确定要删除吗?', + + 'name' => '名称', + 'name_placeholder' => '请输入名称', + 'name_en' => '英文名称', + 'name_en_placeholder' => '请输入英文名称', + 'vin' => 'VIN', + 'vin_placeholder' => '请输入VIN', + 'status' => '状态', + 'status_placeholder' => '请选择状态', + 'status_1' => '正常', + 'status_0' => '禁用', + 'location' => '当前位置', + 'location_placeholder' => '请选择当前位置', + 'final_location' => '最终位置', + 'final_location_placeholder' => '请选择最终位置', + 'fbo_location' => 'FBO位置', + 'fbo_location_placeholder' => '请选择FBO位置', + 'img_url' => '图片', + 'img_url_placeholder' => '请输入图片URL', + 'created_at' => '创建时间', + 'updated_at' => '更新时间', + 'refresh' => '刷新', + 'filter' => '筛选', + 'print' => '打印', + 'export' => '导出', + 'operation' => '操作', + 'upload_image' => '上传图片', + 'select_location' => '选择位置', + 'select_final_location' => '选择目的地', + 'select_fbo_location' => '选择FBO港口' +]; \ No newline at end of file diff --git a/plugin/admin/app/model/Rule.php b/plugin/admin/app/model/Rule.php index ebc7dd1..696e981 100644 --- a/plugin/admin/app/model/Rule.php +++ b/plugin/admin/app/model/Rule.php @@ -31,8 +31,33 @@ class Rule extends Base * @var string */ protected $primaryKey = 'id'; - - - - + + /** + * 获取翻译后的标题 + * @param string $lang 语言代码 + * @return string + */ + public function getTranslatedTitle($lang = null) + { + if (!$lang) { + $lang = session('lang', 'zh-cn'); + } + + $translatedTitle = RuleTranslation::getTranslatedTitle($this->id, $lang); + return $translatedTitle ?: $this->title; + } + + /** + * 设置翻译标题 + * @param string $lang 语言代码 + * @param string $title 翻译标题 + * @return bool + */ + public function setTranslatedTitle($lang, $title) + { + return RuleTranslation::updateOrCreate( + ['rule_id' => $this->id, 'lang' => $lang], + ['title' => $title] + ); + } } diff --git a/plugin/admin/app/model/RuleTranslation.php b/plugin/admin/app/model/RuleTranslation.php new file mode 100644 index 0000000..0255dea --- /dev/null +++ b/plugin/admin/app/model/RuleTranslation.php @@ -0,0 +1,45 @@ +where('lang', $lang) + ->first(); + + return $translation ? $translation->title : null; + } +} \ No newline at end of file diff --git a/plugin/admin/app/route.php b/plugin/admin/app/route.php new file mode 100644 index 0000000..561f5e8 --- /dev/null +++ b/plugin/admin/app/route.php @@ -0,0 +1,29 @@ +group(function () { + Route::get('/dashboard', function () { + return view('dashboard'); + })->name('dashboard'); +}); + +// 语言切换路由 +Route::post('/app/admin/language/switch', [PluginLanguageController::class, 'switch']); \ No newline at end of file diff --git a/plugin/admin/app/view/index/index.html b/plugin/admin/app/view/index/index.html index bffbbcd..a1c5481 100644 --- a/plugin/admin/app/view/index/index.html +++ b/plugin/admin/app/view/index/index.html @@ -1,9 +1,9 @@ - +
-