接口域名拆分文件
This commit is contained in:
@@ -11,5 +11,9 @@ export default {
|
||||
// 正式
|
||||
// baseUrl: "https://tcapp.tripellet.com/api/app/",
|
||||
|
||||
baseUrl: "https://tcapidemo.tripodeck.com",
|
||||
// 2.0
|
||||
// 测试
|
||||
// baseUrl: "https://tcapidemo.tripodeck.com",
|
||||
// 正式
|
||||
baseUrl: "https://tcapi.tripodeck.com",
|
||||
};
|
||||
|
@@ -1,165 +1,164 @@
|
||||
import Vue from 'vue'
|
||||
import Vue from "vue";
|
||||
// 引入语言包,注意路径
|
||||
import enMessage from './en.js';
|
||||
import jpMessage from './jp.js';
|
||||
import koMessage from './ko.js';
|
||||
import enMessage from "./en.js";
|
||||
import jpMessage from "./jp.js";
|
||||
import koMessage from "./ko.js";
|
||||
// VueI18n
|
||||
import VueI18n from '@/common/i18n/vue-i18n.min.js'
|
||||
import Request from '@/common/http/luch-request/index'
|
||||
import config from "@/common/config"
|
||||
const http = new Request()
|
||||
import VueI18n from "@/common/i18n/vue-i18n.min.js";
|
||||
import Request from "@/common/http/luch-request/index";
|
||||
import config from "@/common/config";
|
||||
const http = new Request();
|
||||
http.setConfig((conf) => {
|
||||
/* 设置全局配置 */
|
||||
conf.baseURL = config.baseUrl
|
||||
conf.header = {
|
||||
...conf.header,
|
||||
}
|
||||
return conf
|
||||
})
|
||||
/* 设置全局配置 */
|
||||
conf.baseURL = config.baseUrl;
|
||||
conf.header = {
|
||||
...conf.header,
|
||||
};
|
||||
return conf;
|
||||
});
|
||||
// VueI18n
|
||||
Vue.use(VueI18n)
|
||||
Vue.use(VueI18n);
|
||||
// 网络加载国际化译文
|
||||
// 系统支持的语言
|
||||
const supportLans = [{
|
||||
value: 'zh',
|
||||
label: '中文'
|
||||
},
|
||||
{
|
||||
value: 'en',
|
||||
label: 'English'
|
||||
},
|
||||
{
|
||||
value: 'ja',
|
||||
label: '日本語'
|
||||
},
|
||||
{
|
||||
value: 'ko',
|
||||
label: '한국어'
|
||||
},
|
||||
{
|
||||
value: 'zh_tw',
|
||||
label: '繁體中文'
|
||||
}
|
||||
]
|
||||
const supportLans = [
|
||||
{
|
||||
value: "zh",
|
||||
label: "中文",
|
||||
},
|
||||
{
|
||||
value: "en",
|
||||
label: "English",
|
||||
},
|
||||
{
|
||||
value: "ja",
|
||||
label: "日本語",
|
||||
},
|
||||
{
|
||||
value: "ko",
|
||||
label: "한국어",
|
||||
},
|
||||
{
|
||||
value: "zh_tw",
|
||||
label: "繁體中文",
|
||||
},
|
||||
];
|
||||
|
||||
// 语言包
|
||||
const messages = {
|
||||
zh: {
|
||||
// 'APP概要':'APP概要'
|
||||
},
|
||||
en: {},
|
||||
ja: {},
|
||||
ko: {}
|
||||
}
|
||||
zh: {
|
||||
// 'APP概要':'APP概要'
|
||||
},
|
||||
en: {},
|
||||
ja: {},
|
||||
ko: {},
|
||||
};
|
||||
|
||||
// 获取租户支持的语言
|
||||
export function getSupportLanOptions() {
|
||||
const cookieSupportLans = uni.getStorageSync('language_info').value
|
||||
if (cookieSupportLans && cookieSupportLans.length > 0) {
|
||||
const supportLanOptions = []
|
||||
for (let i = 0; i < supportLans.length; i++) {
|
||||
if (cookieSupportLans.indexOf(supportLans[i].value) !== -1) {
|
||||
supportLanOptions.push(supportLans[i])
|
||||
}
|
||||
}
|
||||
return supportLanOptions
|
||||
}
|
||||
return supportLans
|
||||
const cookieSupportLans = uni.getStorageSync("language_info").value;
|
||||
if (cookieSupportLans && cookieSupportLans.length > 0) {
|
||||
const supportLanOptions = [];
|
||||
for (let i = 0; i < supportLans.length; i++) {
|
||||
if (cookieSupportLans.indexOf(supportLans[i].value) !== -1) {
|
||||
supportLanOptions.push(supportLans[i]);
|
||||
}
|
||||
}
|
||||
return supportLanOptions;
|
||||
}
|
||||
return supportLans;
|
||||
}
|
||||
|
||||
// 获取默认语言
|
||||
export function getDefaultLan() {
|
||||
const cookieDefaultLan = uni.getStorageSync('language_info').value
|
||||
if (cookieDefaultLan) return cookieDefaultLan
|
||||
return 'zh'
|
||||
const cookieDefaultLan = uni.getStorageSync("language_info").value;
|
||||
if (cookieDefaultLan) return cookieDefaultLan;
|
||||
return "zh";
|
||||
}
|
||||
|
||||
// 获取当前用户选择的语言
|
||||
export function getLanguage() {
|
||||
const chooseLanguage = uni.getStorageSync('language_info').value
|
||||
if (chooseLanguage) return chooseLanguage
|
||||
// if has not choose language
|
||||
// const language = (navigator.language || navigator.browserLanguage).toLowerCase()
|
||||
// const locales = Object.keys(messages)
|
||||
// for (const locale of locales) {
|
||||
// if (language.indexOf(locale) > -1) {
|
||||
// return locale
|
||||
// }
|
||||
// }
|
||||
return 'zh'
|
||||
const chooseLanguage = uni.getStorageSync("language_info").value;
|
||||
if (chooseLanguage) return chooseLanguage;
|
||||
// if has not choose language
|
||||
// const language = (navigator.language || navigator.browserLanguage).toLowerCase()
|
||||
// const locales = Object.keys(messages)
|
||||
// for (const locale of locales) {
|
||||
// if (language.indexOf(locale) > -1) {
|
||||
// return locale
|
||||
// }
|
||||
// }
|
||||
return "zh";
|
||||
}
|
||||
|
||||
// 重新加载国际化
|
||||
export async function reloadMessage() {
|
||||
const dict = await loadDict()
|
||||
uni.setStorageSync('dict', dict)
|
||||
for (var lanObj of supportLans) {
|
||||
if(lanObj.value === 'zh') {
|
||||
regMessage(lanObj.value, dict.en)
|
||||
}else {
|
||||
regMessage(lanObj.value, dict[lanObj.value])
|
||||
}
|
||||
|
||||
}
|
||||
return messages
|
||||
const dict = await loadDict();
|
||||
console.log("多语言接口", dict);
|
||||
if (dict.status != 1) return;
|
||||
|
||||
console.log("lenmgth有的", data.length);
|
||||
if (dict.data.length != 0) {
|
||||
uni.setStorageSync("dict", dict.data);
|
||||
}
|
||||
regMessage(language_info.value, dict.data);
|
||||
}
|
||||
|
||||
// 注册语言包
|
||||
export async function regMessage(lan, lanDict) {
|
||||
if (!lan || !lanDict) {
|
||||
return
|
||||
}
|
||||
if (lan === 'zh') {
|
||||
for(var key in lanDict) {
|
||||
messages['zh'][key] = key
|
||||
}
|
||||
// messages['zh'] = {
|
||||
// ...lanDict
|
||||
// }
|
||||
} else if (lan === 'en') {
|
||||
messages['en'] = {
|
||||
...lanDict
|
||||
}
|
||||
} else if (lan === 'ja') {
|
||||
messages['ja'] = {
|
||||
...lanDict
|
||||
}
|
||||
} else if (lan === 'ko') {
|
||||
messages['ko'] = {
|
||||
...lanDict
|
||||
}
|
||||
}else if (lan === 'ko') {
|
||||
messages['ko'] = {
|
||||
...lanDict
|
||||
}
|
||||
}else if (lan === 'zh_tw') {
|
||||
messages['zh_tw'] = {
|
||||
...lanDict
|
||||
}
|
||||
}
|
||||
if (!lan || !lanDict) {
|
||||
return;
|
||||
}
|
||||
if (lan === "zh") {
|
||||
for (var key in lanDict) {
|
||||
messages["zh"][key] = key;
|
||||
}
|
||||
// messages['zh'] = {
|
||||
// ...lanDict
|
||||
// }
|
||||
} else if (lan === "en") {
|
||||
messages["en"] = {
|
||||
...lanDict,
|
||||
};
|
||||
} else if (lan === "ja") {
|
||||
messages["ja"] = {
|
||||
...lanDict,
|
||||
};
|
||||
} else if (lan === "ko") {
|
||||
messages["ko"] = {
|
||||
...lanDict,
|
||||
};
|
||||
} else if (lan === "ko") {
|
||||
messages["ko"] = {
|
||||
...lanDict,
|
||||
};
|
||||
} else if (lan === "zh_tw") {
|
||||
messages["zh_tw"] = {
|
||||
...lanDict,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 网络加载国际化译文
|
||||
export async function loadDict() {
|
||||
uni.removeStorageSync('dict')
|
||||
const url = `customer/lans`
|
||||
try {
|
||||
return http.get(url).then(res => res.data)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return {}
|
||||
}
|
||||
uni.removeStorageSync("dict");
|
||||
const url = `customer/lans`;
|
||||
try {
|
||||
return http.get(url).then((res) => res.data);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
reloadMessage()
|
||||
reloadMessage();
|
||||
const i18n = new VueI18n({
|
||||
// set locale
|
||||
// options: en | zh | ja
|
||||
locale: getLanguage(),
|
||||
// locale: 'zh',
|
||||
// set locale messages
|
||||
messages,
|
||||
// 屏蔽console的warn
|
||||
silentTranslationWarn: true
|
||||
})
|
||||
// set locale
|
||||
// options: en | zh | ja
|
||||
locale: getLanguage(),
|
||||
// locale: 'zh',
|
||||
// set locale messages
|
||||
messages,
|
||||
// 屏蔽console的warn
|
||||
silentTranslationWarn: true,
|
||||
});
|
||||
|
||||
export default i18n
|
||||
export default i18n;
|
||||
|
@@ -1,14 +1,15 @@
|
||||
import config from "@/common/config";
|
||||
|
||||
//1、首先创建一个工具包utils
|
||||
//2、创建一个api.js文件
|
||||
|
||||
//3、编写api.js内容:
|
||||
//创建一个常量 conset BASE_URL作为默认url地址
|
||||
const BEST_URL = "https://tcapidemo.tripodeck.com";
|
||||
export const myRequest = (option) => {
|
||||
//将封装好的函数导入出去
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: BEST_URL + option.url, //传入url地址
|
||||
url: config.baseUrl + option.url, //传入url地址
|
||||
data: option.data || {}, //请求数据
|
||||
method: option.method || "GET", //请求方法
|
||||
header: option.header || {
|
||||
|
Reference in New Issue
Block a user