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