Commit 10229d1c by 陈岩

feat: 解决门店热力、区域热力国际化问题

1 parent 2e65e839
// 国际化配置文件
const messages = {
zh_CN: {
heatMap: {
loading: '加载中...',
loadingForbidClick: '加载中...',
noFloorPlan: '未找到门店平面图',
noHeatData: '无热力数据',
getHeatMapDataFailed: '获取热力图数据失败',
loadSuccess: '加载成功'
},
areaHeat: {
getAreaDataFailed: '获取区域数据失败'
}
},
zh_TW: {
heatMap: {
loading: '載入中...',
loadingForbidClick: '載入中...',
noFloorPlan: '未找到門店平面圖',
noHeatData: '無熱力數據',
getHeatMapDataFailed: '獲取熱力圖數據失敗',
loadSuccess: '載入成功'
},
areaHeat: {
getAreaDataFailed: '獲取區域數據失敗'
}
},
en_US: {
heatMap: {
loading: 'Loading...',
loadingForbidClick: 'Loading...',
noFloorPlan: 'Store floor plan not found',
noHeatData: 'No heat map data',
getHeatMapDataFailed: 'Failed to get heat map data',
loadSuccess: 'Load successful'
},
areaHeat: {
getAreaDataFailed: 'Failed to get area data'
}
},
ja_JP: {
heatMap: {
loading: '読み込み中...',
loadingForbidClick: '読み込み中...',
noFloorPlan: '店舗の平面図が見つかりません',
noHeatData: '熱マップデータがありません',
getHeatMapDataFailed: '熱マップデータの取得に失敗しました',
loadSuccess: '読み込み成功'
},
areaHeat: {
getAreaDataFailed: 'エリアデータの取得に失敗しました'
}
}
};
// 获取语言文本
export function getI18nText(lang, key) {
// 默认使用中文
const currentLang = lang || 'zh_CN';
// 分割key,例如 'heatMap.loading' => ['heatMap', 'loading']
const keys = key.split('.');
// 获取对应语言的文本
let text = messages[currentLang];
for (const k of keys) {
if (text && text[k]) {
text = text[k];
} else {
// 如果找不到对应的文本,返回中文默认值
let defaultText = messages['zh_CN'];
for (const dk of keys) {
if (defaultText && defaultText[dk]) {
defaultText = defaultText[dk];
} else {
return key; // 如果默认值也找不到,返回key本身
}
}
return defaultText;
}
}
return text;
}
export default messages;
\ No newline at end of file
......@@ -23,6 +23,7 @@ import { watch, ref } from "vue";
import { useRoute } from "vue-router";
import { Toast } from "vant";
import heatmap from "@/api/heatMap";
import { getI18nText } from "@/utils/i18n.js";
const $route = useRoute();
......@@ -103,7 +104,7 @@ const getGateStatistics = async () => {
console.log(domHeight);
}
} catch (error) {
console.error("获取区域数据失败:", error);
console.error(getI18nText(currentLang.value, 'areaHeat.getAreaDataFailed'), error);
}
};
......@@ -327,16 +328,21 @@ function formatSecondsMin(val) {
return parseInt(val / 60) + "m";
}
const serverIp = ref('')
const currentLang = ref('zh_CN') // 默认语言
watch(
() => $route.query,
async (newVal) => {
const { token, mallId, startDate: sDate, endDate: eDate, key, serverIp: httpsIp } = newVal;
const { token, mallId, startDate: sDate, endDate: eDate, key, serverIp: httpsIp, lang } = newVal;
serverIp.value = httpsIp || 'https://store.keliuyun.com'
currentLang.value = lang || 'zh_CN'
if (token) {
window.localStorage.setItem("atoken", token);
}
if (currentLang.value) {
window.localStorage.setItem("lang", currentLang.value);
}
startDate.value = sDate || new Date().toISOString().split("T")[0];
endDate.value = eDate || new Date().toISOString().split("T")[0];
if (mallId) {
......@@ -345,7 +351,7 @@ watch(
storeId.value = mallId;
const url = await getFloorImage();
if (!url) {
Toast.fail("未找到门店平面图");
Toast.fail(getI18nText(currentLang.value, 'heatMap.noFloorPlan'));
return false;
}
floorImage.value = `${serverIp.value}/images/${url}`;
......
......@@ -18,6 +18,7 @@ import { Toast } from "vant";
import heatmap from "@/api/heatmap"; // 假设你的API文件路径
import { heatmapFactory } from "@/utils/heatmap.js";
import { getI18nText } from "@/utils/i18n.js";
let map = null; // 地图对象
const $route = useRoute();
......@@ -47,7 +48,7 @@ const getChannelList = async (mallId) => {
channelList: channelList.value,
});
} else {
Toast.fail("无热力数据");
Toast(getI18nText(currentLang.value, 'heatMap.noHeatData'));
}
} else {
console.error("Failed to fetch channel list:", data.message);
......@@ -81,7 +82,7 @@ const getHeatMapData = async (params) => {
dealHeatData();
});
} else {
Toast.fail("获取热力图数据失败");
Toast(getI18nText(currentLang.value, 'heatMap.getHeatMapDataFailed'));
}
} catch (error) {
console.error("Error fetching heat map data:", error);
......@@ -217,6 +218,7 @@ function dealHeatData() {
}
uni.postMessage({
type: "loadSuccess",
message: getI18nText(currentLang.value, 'heatMap.loadSuccess')
});
} catch (error) {
console.error("Error in dealHeatData:", error);
......@@ -247,11 +249,14 @@ function numFormat(val) {
}
const serverIp = ref("");
const currentLang = ref("zh_CN"); // 默认语言
watch(
() => $route.query,
async (newVal) => {
const { token, mallId, startDate: sDate, endDate: eDate, level, serverIp: httpsIp } = newVal;
const { token, mallId, startDate: sDate, endDate: eDate, level, serverIp: httpsIp, lang } = newVal;
serverIp.value = httpsIp || 'https://store.keliuyun.com'
currentLang.value = lang || 'zh_CN'; // 设置当前语言
if (token) {
window.localStorage.setItem("atoken", token);
......@@ -261,14 +266,14 @@ watch(
if (mallId) {
timeLevel.value = level || "rt"; // 默认实时
Toast.loading({
message: "加载中...",
message: getI18nText(currentLang.value, 'heatMap.loading'),
forbidClick: true,
duration: 0,
});
storeId.value = mallId;
const url = await getFloorImage();
if (!url) {
Toast.fail("未找到门店平面图");
Toast(getI18nText(currentLang.value, 'heatMap.noFloorPlan'));
return false;
}
floorImage.value = `${serverIp.value}/images/${url}`;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!