mirror of
https://gitee.com/ShopeX/ECShopX_mobile-frontend
synced 2026-08-08 13:25:31 +08:00
Merge branch 'hotfix/4.2.2' into 'main'
fix(custom): set default language See merge request ecshopx/ecshopx-vshop!147
This commit is contained in:
1
.env
1
.env
@@ -13,3 +13,4 @@ APP_IMAGE_CDN=
|
||||
APP_DIANWU_URL=
|
||||
APP_MERCHANT_URL=
|
||||
APP_ADAPAY=
|
||||
APP_I18N_ORIGIN_LANG=
|
||||
|
||||
124
config/dev.js
124
config/dev.js
@@ -1,130 +1,8 @@
|
||||
// 处理 ECONNRESET 错误,避免进程崩溃
|
||||
// 这个错误通常发生在 webpack watch 模式下连接被重置时
|
||||
if (!process.listenerCount('uncaughtException')) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
if (err.code === 'ECONNRESET' || err.message?.includes('ECONNRESET')) {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', err.message)
|
||||
return
|
||||
}
|
||||
throw err
|
||||
})
|
||||
}
|
||||
|
||||
if (!process.listenerCount('unhandledRejection')) {
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
if (reason && typeof reason === 'object' && 'code' in reason && reason.code === 'ECONNRESET') {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', reason.message || reason)
|
||||
return
|
||||
}
|
||||
console.error('未处理的 Promise 拒绝:', reason)
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
NODE_ENV: '"development"'
|
||||
},
|
||||
defineConstants: {},
|
||||
weapp: {},
|
||||
h5: {
|
||||
devServer: {
|
||||
// 处理连接重置错误,避免进程崩溃
|
||||
client: {
|
||||
overlay: {
|
||||
errors: true,
|
||||
warnings: false
|
||||
}
|
||||
}
|
||||
},
|
||||
webpackChain: (chain, webpack) => {
|
||||
// 添加错误处理插件
|
||||
chain.plugin('handle-errors').use(
|
||||
class {
|
||||
apply(compiler) {
|
||||
compiler.hooks.afterPlugins.tap('HandleErrors', () => {
|
||||
// 在插件初始化后设置错误处理
|
||||
if (!process.listenerCount('uncaughtException')) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
if (err.code === 'ECONNRESET' || err.message?.includes('ECONNRESET')) {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', err.message)
|
||||
return
|
||||
}
|
||||
throw err
|
||||
})
|
||||
}
|
||||
if (!process.listenerCount('unhandledRejection')) {
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
if (
|
||||
reason &&
|
||||
typeof reason === 'object' &&
|
||||
'code' in reason &&
|
||||
reason.code === 'ECONNRESET'
|
||||
) {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', reason.message || reason)
|
||||
return
|
||||
}
|
||||
console.error('未处理的 Promise 拒绝:', reason)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
},
|
||||
mini: {
|
||||
webpackChain: (chain, webpack) => {
|
||||
chain.merge({
|
||||
plugin: {
|
||||
install: {
|
||||
plugin: require('terser-webpack-plugin'),
|
||||
args: [
|
||||
{
|
||||
terserOptions: {
|
||||
compress: true, // 默认使用terser压缩
|
||||
// mangle: false,
|
||||
keep_classnames: true, // 不改变class名称
|
||||
keep_fnames: true // 不改变函数名称
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 添加错误处理插件
|
||||
chain.plugin('handle-errors').use(
|
||||
class {
|
||||
apply(compiler) {
|
||||
compiler.hooks.done.tap('HandleErrors', () => {
|
||||
// 在编译完成后设置错误处理
|
||||
if (!process.listenerCount('uncaughtException')) {
|
||||
process.on('uncaughtException', (err) => {
|
||||
if (err.code === 'ECONNRESET' || err.message?.includes('ECONNRESET')) {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', err.message)
|
||||
return
|
||||
}
|
||||
throw err
|
||||
})
|
||||
}
|
||||
if (!process.listenerCount('unhandledRejection')) {
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
if (
|
||||
reason &&
|
||||
typeof reason === 'object' &&
|
||||
'code' in reason &&
|
||||
reason.code === 'ECONNRESET'
|
||||
) {
|
||||
console.warn('⚠️ 连接重置错误已忽略:', reason.message || reason)
|
||||
return
|
||||
}
|
||||
console.error('未处理的 Promise 拒绝:', reason)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
h5: {}
|
||||
}
|
||||
|
||||
@@ -127,6 +127,7 @@ function App({ children }) {
|
||||
}
|
||||
getSystemConfig()
|
||||
})
|
||||
|
||||
//分包异步加载语言包
|
||||
if (process.env.TARO_ENV === 'weapp') {
|
||||
__non_webpack_require__ &&
|
||||
|
||||
@@ -122,7 +122,9 @@ class Lang {
|
||||
// 从本地存储中获取通用语言,如果不存在则使用空字符串
|
||||
const commonLang = withStorageCommonLang ? globalThis._localStorage.getItem('') : ''
|
||||
// 从本地存储中获取当前语言,如果不存在则使用源语言
|
||||
const baseLang = withStorageLang ? globalThis._localStorage.getItem('lang') : 'en'
|
||||
const baseLang = withStorageLang
|
||||
? globalThis._localStorage.getItem('lang')
|
||||
: process.env.APP_I18N_ORIGIN_LANG
|
||||
const lang = commonLang ? commonLang : baseLang
|
||||
// 如果本地存储中没有语言设置,则使用环境变量中的默认语言
|
||||
if (!globalThis._localStorage.getItem('lang')) {
|
||||
|
||||
@@ -103,7 +103,11 @@ const withStorageCommonLang =
|
||||
// 从本地存储中获取通用语言,如果不存在则使用空字符串
|
||||
const commonLang = withStorageCommonLang ? globalThis.localStorage.getItem('') : ''
|
||||
// 从本地存储中获取当前语言,如果不存在则使用源语言
|
||||
const baseLang = withStorageLang ? globalThis.localStorage.getItem('lang') : 'en'
|
||||
const baseLang = withStorageLang
|
||||
? globalThis.localStorage.getItem('lang')
|
||||
: process.env.APP_I18N_ORIGIN_LANG
|
||||
|
||||
debugger
|
||||
const lang = commonLang ? commonLang : baseLang
|
||||
// 根据当前语言设置翻译函数的语言包
|
||||
globalThis.$t.locale(globalThis.langMap[lang], 'lang')
|
||||
|
||||
Reference in New Issue
Block a user