mirror of
https://gitee.com/ShopeX/ECShopX_mobile-frontend
synced 2026-08-14 17:41:45 +08:00
fix(custom): davild3
This commit is contained in:
2
.env.local
Normal file
2
.env.local
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
APP_I18N_APP_ID=769559dde46e7041
|
||||||
|
APP_I18N_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9
|
||||||
@@ -9,13 +9,6 @@ const { getEnvs, getDefineConstants, getCacheIdentifier } = require('./utils')
|
|||||||
|
|
||||||
require('dotenv-flow').config()
|
require('dotenv-flow').config()
|
||||||
|
|
||||||
// const i18nPlugin = new webpackPluginsAutoI18n.default({
|
|
||||||
// translator: new YoudaoTranslator({
|
|
||||||
// appId: '4cdb9baea8066fef',
|
|
||||||
// appKey: 'ONI6AerZnGRyDqr3w7UM730mPuF8mB3j'
|
|
||||||
// })
|
|
||||||
// })
|
|
||||||
|
|
||||||
const DIST_PATH = `dist/${process.env.TARO_ENV}`
|
const DIST_PATH = `dist/${process.env.TARO_ENV}`
|
||||||
const APP_ENVS = getEnvs()
|
const APP_ENVS = getEnvs()
|
||||||
|
|
||||||
@@ -73,8 +66,8 @@ const config = {
|
|||||||
defineConstants: getDefineConstants(CONST_ENVS),
|
defineConstants: getDefineConstants(CONST_ENVS),
|
||||||
alias: {
|
alias: {
|
||||||
'taro-ui$': 'taro-ui/lib/index',
|
'taro-ui$': 'taro-ui/lib/index',
|
||||||
'@': path.join(__dirname, '../src'),
|
'@': path.join(__dirname, '../src')
|
||||||
'@lang': path.join(__dirname, '../lang')
|
// '@lang': path.join(__dirname, '../lang')
|
||||||
// 'lodash': 'lodash-es'
|
// 'lodash': 'lodash-es'
|
||||||
},
|
},
|
||||||
copy: {
|
copy: {
|
||||||
@@ -89,28 +82,31 @@ const config = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
// i18nPlugin
|
|
||||||
// '@shopex/taro-plugin-modules',
|
// '@shopex/taro-plugin-modules',
|
||||||
// path.join(__dirname, "../src/plugin/test.js")
|
// path.join(__dirname, "../src/plugin/test.js")
|
||||||
// path.join(__dirname, "./modify-taro.js")
|
// path.join(__dirname, "./modify-taro.js")
|
||||||
],
|
],
|
||||||
|
|
||||||
mini: {
|
mini: {
|
||||||
// webpackChain(chain) {
|
webpackChain(chain) {
|
||||||
// chain.plugin('auto-i18n').use(webpackPluginsAutoI18n.default, [
|
chain.plugin('auto-i18n').use(webpackPluginsAutoI18n.default, [
|
||||||
// {
|
{
|
||||||
// rewriteConfig: false, // 是否重写配置js , 小程序需要魔改配置文件,所以不要重新生成,以现在的为准
|
rewriteConfig: false, // 是否重写配置js , 小程序需要魔改配置文件,所以不要重新生成,以现在的为准
|
||||||
// targetLangList: ['en', 'ja'], // 目标语言
|
excludedPath: [
|
||||||
// originLang: 'zh-cn', // 源语言
|
path.resolve(__dirname, './../src/lang/index.js'),
|
||||||
// translator: new YoudaoTranslator({
|
path.resolve(__dirname, './../src/lang/consts.js')
|
||||||
// appId: process.env.YD_APP_ID,
|
],
|
||||||
// appKey: process.env.YD_APP_KEY
|
globalPath: path.resolve(__dirname, './../src/subpages/i18n/lang'),
|
||||||
// }),
|
targetLangList: ['en', 'zh-tw'], // 目标语言
|
||||||
// excludedPath: ['node_modules'], // 排除目录
|
originLang: 'zh-cn', // 源语言
|
||||||
// includePath: [/src/] // 仅扫描 src 目录
|
translator: new YoudaoTranslator({
|
||||||
// }
|
appId: process.env.APP_I18N_APP_ID,
|
||||||
// ])
|
appKey: process.env.APP_I18N_APP_KEY
|
||||||
// },
|
}),
|
||||||
|
includePath: [/src/] // 仅扫描 src 目录
|
||||||
|
}
|
||||||
|
])
|
||||||
|
},
|
||||||
|
|
||||||
miniCssExtractPluginOption: {
|
miniCssExtractPluginOption: {
|
||||||
ignoreOrder: true
|
ignoreOrder: true
|
||||||
|
|||||||
18
package.json
18
package.json
@@ -8,15 +8,15 @@
|
|||||||
"clean": "rm -rf node_modules/.cache",
|
"clean": "rm -rf node_modules/.cache",
|
||||||
"release:h5": "RELEASE=h5 npm run build:h5",
|
"release:h5": "RELEASE=h5 npm run build:h5",
|
||||||
"lint": "prettier-eslint 'src/**/*.{js,jsx}' --write",
|
"lint": "prettier-eslint 'src/**/*.{js,jsx}' --write",
|
||||||
"build:weapp": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type weapp --trace-warnings",
|
"build:weapp": "taro build --type weapp --trace-warnings",
|
||||||
"build:weapp:live": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 APP_LIVE=true taro build --type weapp --trace-warnings",
|
"build:weapp:live": "cross-env APP_LIVE=true taro build --type weapp --trace-warnings",
|
||||||
"build:swan": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type swan",
|
"build:swan": "taro build --type swan",
|
||||||
"build:alipay": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type alipay",
|
"build:alipay": "taro build --type alipay",
|
||||||
"build:tt": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type tt",
|
"build:tt": "taro build --type tt",
|
||||||
"build:h5": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type h5",
|
"build:h5": "taro build --type h5",
|
||||||
"build:rn": "cross-env YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type rn",
|
"build:rn": "taro build --type rn",
|
||||||
"build:app": "cross-env TARGET=app YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type h5",
|
"build:app": "cross-env TARGET=app taro build --type h5",
|
||||||
"build:app:server": "cross-env TARGET=app SERVER=server YD_APP_ID=769559dde46e7041 YD_APP_KEY=2we6CWMpNb2a7TrCRpdE3s5MVYtcvLy9 taro build --type h5",
|
"build:app:server": "cross-env TARGET=app SERVER=server taro build --type h5",
|
||||||
"dev:weapp": "npm run build:weapp -- --watch",
|
"dev:weapp": "npm run build:weapp -- --watch",
|
||||||
"dev:weapp:live": "APP_LIVE=true npm run build:weapp -- --watch",
|
"dev:weapp:live": "APP_LIVE=true npm run build:weapp -- --watch",
|
||||||
"dev:weapp:modules": "TARO_MODULES=true npm run build:weapp -- --watch",
|
"dev:weapp:modules": "TARO_MODULES=true npm run build:weapp -- --watch",
|
||||||
|
|||||||
@@ -450,6 +450,10 @@ const config = {
|
|||||||
'add-personnel', // 添加用药人员
|
'add-personnel', // 添加用药人员
|
||||||
'prescription-information' //补充处方信息
|
'prescription-information' //补充处方信息
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
root: 'subpages/i18n',
|
||||||
|
pages: ['index']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
permission: {
|
permission: {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component, useEffect } from 'react'
|
import React, { Component, useEffect } from 'react'
|
||||||
// import '@lang/index.js' // 📍 必须在入口文件中第一行引入,文件会在运行插件时自动生成,默认位于打包配置目录同层的lang文件夹中,其中的index.js就是配置文件
|
import langObj from '@/lang/index.js' // 📍 必须在入口文件中第一行引入,文件会在运行插件时自动生成,默认位于打包配置目录同层的lang文件夹中,其中的index.js就是配置文件
|
||||||
import Taro, {
|
import Taro, {
|
||||||
getCurrentInstance,
|
getCurrentInstance,
|
||||||
getCurrentPages,
|
getCurrentPages,
|
||||||
@@ -92,6 +92,13 @@ function App({ children }) {
|
|||||||
|
|
||||||
useLaunch((options) => {
|
useLaunch((options) => {
|
||||||
console.log('useLaunch ***********', options)
|
console.log('useLaunch ***********', options)
|
||||||
|
|
||||||
|
__non_webpack_require__ &&
|
||||||
|
__non_webpack_require__('subpages/i18n/index', (res) => {
|
||||||
|
const langJSON = Taro['langJSON']
|
||||||
|
console.log('langJSON--------', langJSON)
|
||||||
|
langObj.setLanguagePackage(langJSON)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
useDidShow(async (options) => {
|
useDidShow(async (options) => {
|
||||||
|
|||||||
7
src/lang/consts.js
Normal file
7
src/lang/consts.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
const i18n = {
|
||||||
|
zhcn: '简体中文',
|
||||||
|
en: 'English',
|
||||||
|
zhtw: '繁體中文'
|
||||||
|
}
|
||||||
|
|
||||||
|
export default i18n
|
||||||
133
src/lang/index.js
Normal file
133
src/lang/index.js
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import Taro from '@tarojs/taro'
|
||||||
|
|
||||||
|
class Lang {
|
||||||
|
constructor() {
|
||||||
|
this.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
init() {
|
||||||
|
// 定义翻译函数
|
||||||
|
let $t = function (key, val, nameSpace) {
|
||||||
|
// 获取指定命名空间下的语言包
|
||||||
|
const langPackage = $t[nameSpace]
|
||||||
|
// 返回翻译结果,如果不存在则返回默认值
|
||||||
|
return (langPackage || {})[key] || val
|
||||||
|
}
|
||||||
|
// 定义简单翻译函数,直接返回传入的值
|
||||||
|
let $$t = function (val) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
globalThis.$deepScan = function (val) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
globalThis.$iS = function (val, args) {
|
||||||
|
// 如果参数不是字符串或数组,直接返回原值
|
||||||
|
if (typeof val !== 'string' || !Array.isArray(args)) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 使用更安全的正则表达式替换方式
|
||||||
|
return val.replace(/\$\{(\d+)\}/g, (match, index) => {
|
||||||
|
// 将index转换为数字
|
||||||
|
const position = parseInt(index, 10)
|
||||||
|
// 如果args[position]存在则替换,否则保留原占位符
|
||||||
|
return args[position] !== undefined ? String(args[position]) : match
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('字符串替换过程出现异常:', error)
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 定义设置语言包的方法
|
||||||
|
$t.locale = function (locale, nameSpace) {
|
||||||
|
// 将指定命名空间下的语言包设置为传入的locale
|
||||||
|
$t[nameSpace] = locale || {}
|
||||||
|
}
|
||||||
|
// 将翻译函数挂载到globalThis对象上,如果已经存在则使用已有的
|
||||||
|
globalThis.$t = globalThis.$t || $t
|
||||||
|
// 将简单翻译函数挂载到globalThis对象上
|
||||||
|
globalThis.$$t = $$t
|
||||||
|
// 定义从JSON文件中获取指定键的语言对象的方法
|
||||||
|
globalThis._getJSONKey = function (key, insertJSONObj = undefined) {
|
||||||
|
// 获取JSON对象
|
||||||
|
const JSONObj = insertJSONObj
|
||||||
|
// 初始化语言对象
|
||||||
|
const langObj = {}
|
||||||
|
// 遍历JSON对象的所有键
|
||||||
|
Object.keys(JSONObj).forEach((value) => {
|
||||||
|
// 将每个语言的对应键值添加到语言对象中
|
||||||
|
langObj[value] = JSONObj[value][key]
|
||||||
|
})
|
||||||
|
// 返回语言对象
|
||||||
|
return langObj
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setLanguagePackage(langJSON) {
|
||||||
|
const langMap = {
|
||||||
|
'en':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.en
|
||||||
|
? globalThis.lang.en
|
||||||
|
: globalThis._getJSONKey('en', langJSON),
|
||||||
|
'ja':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.ja
|
||||||
|
? globalThis.lang.ja
|
||||||
|
: globalThis._getJSONKey('ja', langJSON),
|
||||||
|
'zhcn':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.zhcn
|
||||||
|
? globalThis.lang.zhcn
|
||||||
|
: globalThis._getJSONKey('zh-cn', langJSON),
|
||||||
|
'zhtw':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.zhtw
|
||||||
|
? globalThis.lang.zhtw
|
||||||
|
: globalThis._getJSONKey('zh-tw', langJSON)
|
||||||
|
}
|
||||||
|
globalThis.langMap = langMap
|
||||||
|
// 存储语言是否存在
|
||||||
|
// 判断 globalThis.localStorage.getItem 是否为函数
|
||||||
|
const isFunction = (fn) => {
|
||||||
|
return typeof fn === 'function'
|
||||||
|
}
|
||||||
|
globalThis.localStorage = {
|
||||||
|
getItem: (key) => {
|
||||||
|
return Taro.getStorageSync(key)
|
||||||
|
},
|
||||||
|
setItem: (key, value) => {
|
||||||
|
Taro.setStorageSync(key, value)
|
||||||
|
},
|
||||||
|
removeItem: (key) => {
|
||||||
|
Taro.removeStorageSync(key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const withStorageLang =
|
||||||
|
isFunction &&
|
||||||
|
globalThis &&
|
||||||
|
globalThis.localStorage &&
|
||||||
|
isFunction(globalThis.localStorage.getItem) &&
|
||||||
|
globalThis.localStorage.getItem('lang')
|
||||||
|
const withStorageCommonLang =
|
||||||
|
isFunction &&
|
||||||
|
globalThis &&
|
||||||
|
globalThis.localStorage &&
|
||||||
|
isFunction(globalThis.localStorage.getItem) &&
|
||||||
|
globalThis.localStorage.getItem('')
|
||||||
|
// 从本地存储中获取通用语言,如果不存在则使用空字符串
|
||||||
|
const commonLang = withStorageCommonLang ? globalThis.localStorage.getItem('') : ''
|
||||||
|
// 从本地存储中获取当前语言,如果不存在则使用源语言
|
||||||
|
const baseLang = withStorageLang ? globalThis.localStorage.getItem('lang') : 'zhcn'
|
||||||
|
const lang = commonLang ? commonLang : baseLang
|
||||||
|
if (!globalThis.localStorage.getItem('lang')) {
|
||||||
|
// 设置默认语言
|
||||||
|
globalThis.localStorage.setItem('lang', 'zhcn')
|
||||||
|
}
|
||||||
|
// 根据当前语言设置翻译函数的语言包
|
||||||
|
globalThis.$t.locale(globalThis.langMap[lang], 'lang')
|
||||||
|
|
||||||
|
Taro.$changeLang = (lang) => {
|
||||||
|
globalThis.localStorage.setItem('lang', lang)
|
||||||
|
globalThis.$t.locale(globalThis.langMap[lang], 'lang')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new Lang()
|
||||||
7
src/subpages/i18n/index.js
Normal file
7
src/subpages/i18n/index.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Taro from '@tarojs/taro'
|
||||||
|
|
||||||
|
import langJSON from './lang/index.json'
|
||||||
|
|
||||||
|
Taro['langJSON'] = langJSON
|
||||||
|
|
||||||
|
export default {}
|
||||||
104
src/subpages/i18n/lang/index.js
Normal file
104
src/subpages/i18n/lang/index.js
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// 导入国际化JSON文件
|
||||||
|
import langJSON from './index.json'
|
||||||
|
|
||||||
|
;(function () {
|
||||||
|
// 定义翻译函数
|
||||||
|
let $t = function (key, val, nameSpace) {
|
||||||
|
// 获取指定命名空间下的语言包
|
||||||
|
const langPackage = $t[nameSpace]
|
||||||
|
// 返回翻译结果,如果不存在则返回默认值
|
||||||
|
return (langPackage || {})[key] || val
|
||||||
|
}
|
||||||
|
// 定义简单翻译函数,直接返回传入的值
|
||||||
|
let $$t = function (val) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
globalThis.$deepScan = function (val) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
globalThis.$iS = function (val, args) {
|
||||||
|
// 如果参数不是字符串或数组,直接返回原值
|
||||||
|
if (typeof val !== 'string' || !Array.isArray(args)) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// 使用更安全的正则表达式替换方式
|
||||||
|
return val.replace(/\$(?:\{|\{)(\d+)(?:\}|\})/g, (match, index) => {
|
||||||
|
// 将index转换为数字
|
||||||
|
const position = parseInt(index, 10)
|
||||||
|
// 如果args[position]存在则替换,否则保留原占位符
|
||||||
|
return args[position] !== undefined ? String(args[position]) : match
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('字符串替换过程出现异常:', error)
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 定义设置语言包的方法
|
||||||
|
$t.locale = function (locale, nameSpace) {
|
||||||
|
// 将指定命名空间下的语言包设置为传入的locale
|
||||||
|
$t[nameSpace] = locale || {}
|
||||||
|
}
|
||||||
|
// 将翻译函数挂载到globalThis对象上,如果已经存在则使用已有的
|
||||||
|
globalThis.$t = globalThis.$t || $t
|
||||||
|
// 将简单翻译函数挂载到globalThis对象上
|
||||||
|
globalThis.$$t = $$t
|
||||||
|
// 定义从JSON文件中获取指定键的语言对象的方法
|
||||||
|
globalThis._getJSONKey = function (key, insertJSONObj = undefined) {
|
||||||
|
// 获取JSON对象
|
||||||
|
const JSONObj = insertJSONObj
|
||||||
|
// 初始化语言对象
|
||||||
|
const langObj = {}
|
||||||
|
// 遍历JSON对象的所有键
|
||||||
|
Object.keys(JSONObj).forEach((value) => {
|
||||||
|
// 将每个语言的对应键值添加到语言对象中
|
||||||
|
langObj[value] = JSONObj[value][key]
|
||||||
|
})
|
||||||
|
// 返回语言对象
|
||||||
|
return langObj
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
// 定义语言映射对象
|
||||||
|
const langMap = {
|
||||||
|
'en':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.en
|
||||||
|
? globalThis.lang.en
|
||||||
|
: globalThis._getJSONKey('en', langJSON),
|
||||||
|
'zhtw':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.zhtw
|
||||||
|
? globalThis.lang.zhtw
|
||||||
|
: globalThis._getJSONKey('zh-tw', langJSON),
|
||||||
|
'zhcn':
|
||||||
|
globalThis && globalThis.lang && globalThis.lang.zhcn
|
||||||
|
? globalThis.lang.zhcn
|
||||||
|
: globalThis._getJSONKey('zh-cn', langJSON)
|
||||||
|
}
|
||||||
|
globalThis.langMap = langMap
|
||||||
|
// 存储语言是否存在
|
||||||
|
// 判断 globalThis.localStorage.getItem 是否为函数
|
||||||
|
const isFunction = (fn) => {
|
||||||
|
return typeof fn === 'function'
|
||||||
|
}
|
||||||
|
|
||||||
|
const withStorageLang =
|
||||||
|
isFunction &&
|
||||||
|
globalThis &&
|
||||||
|
globalThis.localStorage &&
|
||||||
|
isFunction(globalThis.localStorage.getItem) &&
|
||||||
|
globalThis.localStorage.getItem('lang')
|
||||||
|
const withStorageCommonLang =
|
||||||
|
isFunction &&
|
||||||
|
globalThis &&
|
||||||
|
globalThis.localStorage &&
|
||||||
|
isFunction(globalThis.localStorage.getItem) &&
|
||||||
|
globalThis.localStorage.getItem('')
|
||||||
|
// 从本地存储中获取通用语言,如果不存在则使用空字符串
|
||||||
|
const commonLang = withStorageCommonLang ? globalThis.localStorage.getItem('') : ''
|
||||||
|
// 从本地存储中获取当前语言,如果不存在则使用源语言
|
||||||
|
const baseLang = withStorageLang ? globalThis.localStorage.getItem('lang') : 'zhcn'
|
||||||
|
const lang = commonLang ? commonLang : baseLang
|
||||||
|
// 根据当前语言设置翻译函数的语言包
|
||||||
|
globalThis.$t.locale(globalThis.langMap[lang], 'lang')
|
||||||
|
globalThis.$changeLang = (lang) => {
|
||||||
|
globalThis.$t.locale(globalThis.langMap[lang], 'lang')
|
||||||
|
}
|
||||||
12892
src/subpages/i18n/lang/index.json
Normal file
12892
src/subpages/i18n/lang/index.json
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useRef } from 'react'
|
import React, { useEffect, useRef } from 'react'
|
||||||
import { useSelector } from 'react-redux'
|
import { useSelector, useDispatch } from 'react-redux'
|
||||||
import { useImmer } from 'use-immer'
|
import { useImmer } from 'use-immer'
|
||||||
import Taro from '@tarojs/taro'
|
import Taro from '@tarojs/taro'
|
||||||
import { AtButton } from 'taro-ui'
|
import { AtButton } from 'taro-ui'
|
||||||
@@ -10,6 +10,7 @@ import { SG_POLICY } from '@/consts'
|
|||||||
import { classNames, showToast, formatTime, isWeixin, isWeb, VERSION_SHUYUN } from '@/utils'
|
import { classNames, showToast, formatTime, isWeixin, isWeb, VERSION_SHUYUN } from '@/utils'
|
||||||
import imgUploader from '@/utils/upload'
|
import imgUploader from '@/utils/upload'
|
||||||
import { View, Input, Picker, Button } from '@tarojs/components'
|
import { View, Input, Picker, Button } from '@tarojs/components'
|
||||||
|
import i18n from '@/lang/consts'
|
||||||
import './user-info.scss'
|
import './user-info.scss'
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
@@ -18,13 +19,18 @@ const initialState = {
|
|||||||
checkboxPickerTitle: '',
|
checkboxPickerTitle: '',
|
||||||
showCheckboxPicker: false,
|
showCheckboxPicker: false,
|
||||||
checkboxKey: '',
|
checkboxKey: '',
|
||||||
checkboxList: []
|
checkboxList: [],
|
||||||
|
showSwitchLanguage: false,
|
||||||
|
selectLang: '',
|
||||||
|
languageList: []
|
||||||
}
|
}
|
||||||
|
|
||||||
function MemberUserInfo() {
|
function MemberUserInfo() {
|
||||||
const [state, setState] = useImmer(initialState)
|
const [state, setState] = useImmer(initialState)
|
||||||
const { showModal } = useModal()
|
const { showModal } = useModal()
|
||||||
const { lang } = useSelector((state) => state.user)
|
const dispatch = useDispatch()
|
||||||
|
const lang = Taro.getStorageSync('lang')
|
||||||
|
console.log('lang', lang, 'i18n', i18n)
|
||||||
const {
|
const {
|
||||||
formItems,
|
formItems,
|
||||||
formUserInfo,
|
formUserInfo,
|
||||||
@@ -89,16 +95,17 @@ function MemberUserInfo() {
|
|||||||
_formUserInfo[key] = sexType[value]
|
_formUserInfo[key] = sexType[value]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
// _formItems.push({
|
|
||||||
// key: 'language',
|
|
||||||
// name: '切换语言',
|
|
||||||
// field_type: 4,
|
|
||||||
// select: ['中文', 'english']
|
|
||||||
// })
|
|
||||||
|
|
||||||
setState((draft) => {
|
setState((draft) => {
|
||||||
draft.formItems = _formItems
|
draft.formItems = _formItems
|
||||||
draft.formUserInfo = _formUserInfo
|
draft.formUserInfo = _formUserInfo
|
||||||
|
draft.languageList = Object.keys(i18n).map((key) => {
|
||||||
|
return {
|
||||||
|
name: i18n[key],
|
||||||
|
key,
|
||||||
|
ischecked: key === lang
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,22 +288,21 @@ function MemberUserInfo() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const hanldeShowSwitchLanguage = async () => {
|
// const hanldeShowSwitchLanguage = async () => {
|
||||||
console.log('lang', lang)
|
// console.log('lang', lang)
|
||||||
const langText = lang === 'zh-cn' ? '英文' : '中文'
|
// const res = await showModal({
|
||||||
const res = await showModal({
|
// title: `提示`,
|
||||||
title: `切换语言到${langText}`,
|
// content: '请确认是否切换语言',
|
||||||
content: '切换后语言后自动重启应用',
|
// confirmText: '确定',
|
||||||
confirmText: '确定',
|
// cancelText: '取消'
|
||||||
cancelText: '取消'
|
// })
|
||||||
})
|
// if (res.confirm) {
|
||||||
if (res.confirm) {
|
// globalThis.$changeLang(lang === 'zh-cn' ? 'en' : 'zh-cn')
|
||||||
globalThis.$changeLang(lang === 'zh-cn' ? 'en' : 'zh-cn')
|
// Taro.reLaunch({
|
||||||
Taro.reLaunch({
|
// url: '/subpages/member/index'
|
||||||
url: '/subpages/member/index'
|
// })
|
||||||
})
|
// }
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
const onUploadAvatarFile = async () => {
|
const onUploadAvatarFile = async () => {
|
||||||
const { tempFiles = [] } = await Taro.chooseImage({
|
const { tempFiles = [] } = await Taro.chooseImage({
|
||||||
@@ -407,8 +413,13 @@ function MemberUserInfo() {
|
|||||||
<SpCell
|
<SpCell
|
||||||
isLink
|
isLink
|
||||||
title='切换语言'
|
title='切换语言'
|
||||||
value='切换后语言后自动重启应用'
|
value={i18n[lang]}
|
||||||
onClick={hanldeShowSwitchLanguage}
|
onClick={() => {
|
||||||
|
setState((draft) => {
|
||||||
|
draft.selectLang = lang
|
||||||
|
draft.showSwitchLanguage = true
|
||||||
|
})
|
||||||
|
}}
|
||||||
></SpCell>
|
></SpCell>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -479,6 +490,49 @@ function MemberUserInfo() {
|
|||||||
</View>
|
</View>
|
||||||
))}
|
))}
|
||||||
</SpFloatLayout>
|
</SpFloatLayout>
|
||||||
|
|
||||||
|
{/* 切换语言 */}
|
||||||
|
<SpFloatLayout
|
||||||
|
title='切换语言'
|
||||||
|
open={state.showSwitchLanguage}
|
||||||
|
onClose={() => {
|
||||||
|
setState((draft) => {
|
||||||
|
draft.showSwitchLanguage = false
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
renderFooter={
|
||||||
|
<AtButton
|
||||||
|
circle
|
||||||
|
type='primary'
|
||||||
|
onClick={() => {
|
||||||
|
// Taro.setStorageSync('lang', state.selectLang)
|
||||||
|
Taro.$changeLang(state.selectLang)
|
||||||
|
Taro.reLaunch({
|
||||||
|
url: '/subpages/member/index'
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
确定
|
||||||
|
</AtButton>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<View className='lang-list'>
|
||||||
|
{state.languageList.map((item, index) => (
|
||||||
|
<View className='lang-item' key={`lang-item__${index}`}>
|
||||||
|
<SpCheckbox
|
||||||
|
checked={item.key == state.selectLang}
|
||||||
|
onChange={(e) => {
|
||||||
|
setState((draft) => {
|
||||||
|
draft.selectLang = item.key
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
</SpCheckbox>
|
||||||
|
</View>
|
||||||
|
))}
|
||||||
|
</View>
|
||||||
|
</SpFloatLayout>
|
||||||
</SpPage>
|
</SpPage>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,30 @@
|
|||||||
.sp-page__body {
|
.sp-page__body {
|
||||||
padding: 0 0 20px 0;
|
padding: 0 0 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sp-page__footer {
|
.sp-page__footer {
|
||||||
padding: 20px 20px 0;
|
padding: 20px 20px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.block-container {
|
.block-container {
|
||||||
margin: 20px 30px;
|
margin: 20px 30px;
|
||||||
|
|
||||||
.sp-cell {
|
.sp-cell {
|
||||||
&:first-child {
|
&:first-child {
|
||||||
border-top-left-radius: 16px;
|
border-top-left-radius: 16px;
|
||||||
border-top-right-radius: 16px;
|
border-top-right-radius: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
border-bottom-left-radius: 16px;
|
border-bottom-left-radius: 16px;
|
||||||
border-bottom-right-radius: 16px;
|
border-bottom-right-radius: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sp-cell__ft {
|
.sp-cell__ft {
|
||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input-field {
|
.input-field {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
color: #666;
|
color: #666;
|
||||||
@@ -35,6 +41,7 @@
|
|||||||
border-color: transparent;
|
border-color: transparent;
|
||||||
/* #ifdef h5 */
|
/* #ifdef h5 */
|
||||||
visibility: inherit;
|
visibility: inherit;
|
||||||
|
|
||||||
/* #endif */
|
/* #endif */
|
||||||
&:after {
|
&:after {
|
||||||
border-width: 0;
|
border-width: 0;
|
||||||
@@ -44,24 +51,41 @@
|
|||||||
.input-placeholder {
|
.input-placeholder {
|
||||||
color: #a5a5a5;
|
color: #a5a5a5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.picker-value {
|
.picker-value {
|
||||||
color: #666;
|
color: #666;
|
||||||
|
|
||||||
&.disabled {
|
&.disabled {
|
||||||
color: #e4e4e4;
|
color: #e4e4e4;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.placeholder {
|
&.placeholder {
|
||||||
color: #a5a5a5;
|
color: #a5a5a5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.sp-float-layout-bd {
|
.sp-float-layout-bd {
|
||||||
max-height: 600px;
|
max-height: 600px;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.checkout-item {
|
.checkout-item {
|
||||||
margin: 24px;
|
margin: 24px;
|
||||||
|
|
||||||
.sp-checkbox-new {
|
.sp-checkbox-new {
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
// flex-direction: row-reverse;
|
// flex-direction: row-reverse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.lang-list {
|
||||||
|
padding: 20px 0;
|
||||||
|
|
||||||
|
.lang-item {
|
||||||
|
height: 64px;
|
||||||
|
padding: 0 40px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -379,7 +379,6 @@ class EntryLaunch {
|
|||||||
async postGuideUV() {
|
async postGuideUV() {
|
||||||
const routerParams =
|
const routerParams =
|
||||||
Taro.getStorageSync(SG_ROUTER_PARAMS) || Taro.getStorageSync(SG_GUIDE_PARAMS)
|
Taro.getStorageSync(SG_ROUTER_PARAMS) || Taro.getStorageSync(SG_GUIDE_PARAMS)
|
||||||
debugger
|
|
||||||
const { gu, gu_user_id } = routerParams || {}
|
const { gu, gu_user_id } = routerParams || {}
|
||||||
let work_userid = ''
|
let work_userid = ''
|
||||||
if (gu) {
|
if (gu) {
|
||||||
@@ -389,7 +388,6 @@ class EntryLaunch {
|
|||||||
work_userid = gu_user_id
|
work_userid = gu_user_id
|
||||||
}
|
}
|
||||||
if (work_userid) {
|
if (work_userid) {
|
||||||
debugger
|
|
||||||
await api.user.uniquevisito({
|
await api.user.uniquevisito({
|
||||||
work_userid
|
work_userid
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -726,7 +726,6 @@ const getCurrentShopId = () => {
|
|||||||
|
|
||||||
const getDistributorId = (_dtid) => {
|
const getDistributorId = (_dtid) => {
|
||||||
const { sys, shop } = store.getState()
|
const { sys, shop } = store.getState()
|
||||||
const { entryStoreByLBS } = sys
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
shopInfo: { distributor_id, shop_id }
|
shopInfo: { distributor_id, shop_id }
|
||||||
@@ -738,7 +737,7 @@ const getDistributorId = (_dtid) => {
|
|||||||
if (dtid) {
|
if (dtid) {
|
||||||
return dtid
|
return dtid
|
||||||
} else {
|
} else {
|
||||||
return entryStoreByLBS ? distributor_id : shop_id
|
return distributor_id
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return _dtid
|
return _dtid
|
||||||
|
|||||||
101
src/utils/log copy.js
Normal file
101
src/utils/log copy.js
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
const log = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : null // 手机端点击投诉可以在平台看到日志
|
||||||
|
|
||||||
|
const levels = {
|
||||||
|
DEBUG: 'debug', // 开发和调试阶段使用
|
||||||
|
INFO: 'info', // 记录程序正常运行情况
|
||||||
|
WARN: 'warn', // 记录程序运行出现的潜在问题
|
||||||
|
ERROR: 'error' // 程序运行过程出现严重错误
|
||||||
|
}
|
||||||
|
|
||||||
|
const prefixes = {
|
||||||
|
DEBUG: '[DEBUG]',
|
||||||
|
INFO: '[INFO]',
|
||||||
|
WARN: '[WARN]',
|
||||||
|
ERROR: '[ERROR]'
|
||||||
|
}
|
||||||
|
|
||||||
|
class Logger {
|
||||||
|
constructor(level = levels.INFO) {
|
||||||
|
this.level = level
|
||||||
|
}
|
||||||
|
|
||||||
|
setLevel(level) {
|
||||||
|
this.level = level
|
||||||
|
}
|
||||||
|
|
||||||
|
log(level, ...args) {
|
||||||
|
if (this.shouldLog(level)) {
|
||||||
|
const timestamp = new Date().toLocaleString()
|
||||||
|
const prefix = prefixes[level.toUpperCase()] || ''
|
||||||
|
const logMessage = `[${timestamp}] ${prefix} ${args.join(' ')}`
|
||||||
|
console.log(logMessage)
|
||||||
|
this.sendToRealtimeLog(level, ...args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
debug(...args) {
|
||||||
|
this.log(levels.DEBUG, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
info(...args) {
|
||||||
|
this.log(levels.INFO, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
warn(...args) {
|
||||||
|
this.log(levels.WARN, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
error(...args) {
|
||||||
|
this.log(levels.ERROR, ...args)
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldLog(level) {
|
||||||
|
const levelOrder = [levels.DEBUG, levels.INFO, levels.WARN, levels.ERROR]
|
||||||
|
return levelOrder.indexOf(level) >= levelOrder.indexOf(this.level)
|
||||||
|
}
|
||||||
|
|
||||||
|
sendToRealtimeLog(level, ...args) {
|
||||||
|
if (!log) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch (level) {
|
||||||
|
case levels.INFO:
|
||||||
|
log.info.apply(log, args)
|
||||||
|
break
|
||||||
|
case levels.WARN:
|
||||||
|
log.warn.apply(log, args)
|
||||||
|
break
|
||||||
|
case levels.ERROR:
|
||||||
|
log.error.apply(log, args)
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
log.debug ? log.debug.apply(log, args) : log.info.apply(log, args)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setFilterMsg(msg) {
|
||||||
|
if (!log || !log.setFilterMsg) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (typeof msg !== 'string') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.setFilterMsg(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
addFilterMsg(msg) {
|
||||||
|
if (!log || !log.addFilterMsg) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (typeof msg !== 'string') {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.addFilterMsg(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const logger = new Logger(levels.DEBUG) // 默认日志级别为 DEBUG
|
||||||
|
|
||||||
|
export default logger
|
||||||
|
export { levels }
|
||||||
Reference in New Issue
Block a user