Fix: 强制Flex横排三列显示,修复GeoLite2本地库返回英文省市名改为中文翻译
This commit is contained in:
@@ -68,17 +68,42 @@ class UserController extends Controller
|
||||
$data['login_ip'] = $targetUser->login_ip; // 假设表中存在 login_ip 记录本次IP,若无则使用 last_ip 退化
|
||||
|
||||
// 解析归属地 (防崩溃处理:检查服务提供者是否已安装)
|
||||
// GeoLite2 本地 .mmdb 仅返回英文,这里使用内置翻译表转为中文
|
||||
$locationMap = [
|
||||
'China' => '中国', 'Beijing' => '北京', 'Shanghai' => '上海',
|
||||
'Tianjin' => '天津', 'Chongqing' => '重庆', 'Hebei' => '河北',
|
||||
'Shanxi' => '山西', 'Liaoning' => '辽宁', 'Jilin' => '吉林',
|
||||
'Heilongjiang' => '黑龙江', 'Jiangsu' => '江苏', 'Zhejiang' => '浙江',
|
||||
'Anhui' => '安徽', 'Fujian' => '福建', 'Jiangxi' => '江西',
|
||||
'Shandong' => '山东', 'Henan' => '河南', 'Hubei' => '湖北',
|
||||
'Hunan' => '湖南', 'Guangdong' => '广东', 'Hainan' => '海南',
|
||||
'Sichuan' => '四川', 'Guizhou' => '贵州', 'Yunnan' => '云南',
|
||||
'Shaanxi' => '陕西', 'Gansu' => '甘肃', 'Qinghai' => '青海',
|
||||
'Taiwan' => '台湾', 'Inner Mongolia' => '内蒙古', 'Guangxi' => '广西',
|
||||
'Tibet' => '西藏', 'Ningxia' => '宁夏', 'Xinjiang' => '新疆',
|
||||
'Hong Kong' => '香港', 'Macau' => '澳门',
|
||||
'United States' => '美国', 'Japan' => '日本', 'South Korea' => '韩国',
|
||||
'United Kingdom' => '英国', 'France' => '法国', 'Germany' => '德国',
|
||||
'Russia' => '俄罗斯', 'Canada' => '加拿大', 'Australia' => '澳大利亚',
|
||||
'Singapore' => '新加坡',
|
||||
];
|
||||
$tr = fn(string $name): string => $locationMap[$name] ?? $name;
|
||||
|
||||
$ipToLookup = $targetUser->login_ip ?: $targetUser->last_ip;
|
||||
if ($ipToLookup) {
|
||||
if (class_exists('\Stevebauman\Location\Facades\Location')) {
|
||||
try {
|
||||
$position = Location::get($ipToLookup);
|
||||
if ($position) {
|
||||
$isChinaOrLocal = in_array($position->countryCode ?? $position->isoCode ?? '', ['CN', 'TW', 'HK', 'MO']) || $position->countryName === 'Local';
|
||||
$data['location'] = $isChinaOrLocal ?
|
||||
trim(($position->regionName ?? '') . ' ' . ($position->cityName ?? '')) :
|
||||
($position->countryName ?? '未知区域');
|
||||
|
||||
$isChinaOrLocal = in_array($position->countryCode ?? '', ['CN', 'TW', 'HK', 'MO'])
|
||||
|| $position->countryName === 'Local';
|
||||
if ($isChinaOrLocal) {
|
||||
$region = $tr($position->regionName ?? '');
|
||||
$city = $tr($position->cityName ?? '');
|
||||
$data['location'] = trim($region . ($region !== $city ? ' ' . $city : ''));
|
||||
} else {
|
||||
$data['location'] = $tr($position->countryName ?? '未知区域');
|
||||
}
|
||||
if (empty($data['location'])) {
|
||||
$data['location'] = '未知区域';
|
||||
}
|
||||
|
||||
@@ -331,8 +331,9 @@
|
||||
</div>
|
||||
|
||||
{{-- 详细信息区 (等级高看等级低,或自己看自己时才有这些字段) --}}
|
||||
{{-- 注意:x-show 会把 display 改为 block,需要用 !important 强制横排 --}}
|
||||
<div x-show="userInfo.exp_num !== undefined"
|
||||
style="margin-top: 12px; display: flex; flex-direction: row; gap: 8px;">
|
||||
style="margin-top: 12px; display: flex !important; flex-direction: row !important; gap: 8px;">
|
||||
<!-- 经验 -->
|
||||
<div
|
||||
style="flex: 1; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 6px 0; display: flex; flex-direction: column; align-items: center; justify-content: center;">
|
||||
|
||||
Reference in New Issue
Block a user