提交 3c47420f 编写于 作者: D DCloud_LXH

feat(i18n): h5 titleNView buttons text

上级 2b84f65d
...@@ -8,6 +8,7 @@ export function initNavigationBarI18n( ...@@ -8,6 +8,7 @@ export function initNavigationBarI18n(
return defineI18nProperties(navigationBar, [ return defineI18nProperties(navigationBar, [
['titleText'], ['titleText'],
['searchInput', 'placeholder'], ['searchInput', 'placeholder'],
['buttons', 'text'],
]) as [boolean, boolean] ]) as [boolean, boolean]
} }
} }
......
...@@ -31,9 +31,18 @@ export function formatI18n(message: string) { ...@@ -31,9 +31,18 @@ export function formatI18n(message: string) {
function resolveJsonObj( function resolveJsonObj(
jsonObj: Record<string, any> | undefined, jsonObj: Record<string, any> | undefined,
names: string[] names: string[]
): Record<string, any> | undefined { ): Record<string, any> | Array<Record<string, any>> | undefined {
if (names.length === 1) { if (names.length === 1) {
if (jsonObj) { if (jsonObj) {
const _isI18nStr = (value: any) =>
isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)
const _name = names[0]
if (
Array.isArray(jsonObj) &&
jsonObj.some((item) => _isI18nStr(item[_name]))
) {
return jsonObj
}
const value = jsonObj[names[0]] const value = jsonObj[names[0]]
if (isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) { if (isString(value) && isI18nStr(value, I18N_JSON_DELIMITERS)) {
return jsonObj return jsonObj
...@@ -58,15 +67,21 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) { ...@@ -58,15 +67,21 @@ export function defineI18nProperty(obj: Record<string, any>, names: string[]) {
return false return false
} }
const prop = names[names.length - 1] const prop = names[names.length - 1]
let value = jsonObj[prop] if (Array.isArray(jsonObj)) {
Object.defineProperty(jsonObj, prop, { jsonObj
get() { .filter((item) => isI18nStr(item[prop], I18N_JSON_DELIMITERS))
return formatI18n(value) .forEach((item) => defineI18nProperty(item, [prop]))
}, } else {
set(v) { let value = jsonObj[prop]
value = v Object.defineProperty(jsonObj, prop, {
}, get() {
}) return formatI18n(value)
},
set(v) {
value = v
},
})
}
return true return true
} }
......
...@@ -363,27 +363,39 @@ function usePageHeadButton( ...@@ -363,27 +363,39 @@ function usePageHeadButton(
if (btn.fontFamily) { if (btn.fontFamily) {
iconStyle.fontFamily = btn.fontFamily iconStyle.fontFamily = btn.fontFamily
} }
return { return new Proxy(
btnClass: { {
// 类似这样的大量重复的字符串,会在gzip时压缩大小,无需在代码层考虑优化相同字符串 btnClass: {
'uni-page-head-btn': true, // 类似这样的大量重复的字符串,会在gzip时压缩大小,无需在代码层考虑优化相同字符串
'uni-page-head-btn-red-dot': !!(btn.redDot || btn.badgeText), 'uni-page-head-btn': true,
'uni-page-head-btn-select': !!btn.select, 'uni-page-head-btn-red-dot': !!(btn.redDot || btn.badgeText),
}, 'uni-page-head-btn-select': !!btn.select,
btnStyle: { },
backgroundColor: isTransparent ? btn.background : 'transparent', btnStyle: {
width: btn.width, backgroundColor: isTransparent ? btn.background : 'transparent',
}, width: btn.width,
btnText: },
btn.fontSrc && btn.fontFamily ? btn.text.replace('\\u', '&#x') : btn.text, btnText: '',
btnIconPath: ICON_PATHS[btn.type], btnIconPath: ICON_PATHS[btn.type],
badgeText: btn.badgeText, badgeText: btn.badgeText,
iconStyle, iconStyle,
onClick() { onClick() {
invokeHook(pageId, ON_NAVIGATION_BAR_BUTTON_TAP, extend({ index }, btn)) invokeHook(pageId, ON_NAVIGATION_BAR_BUTTON_TAP, extend({ index }, btn))
},
btnSelect: btn.select,
}, },
btnSelect: btn.select, {
} get(target, key, receiver) {
if (['btnText'].includes(key as string)) {
return btn.fontSrc && btn.fontFamily
? btn.text.replace('\\u', '&#x')
: btn.text
} else {
return Reflect.get(target, key, receiver)
}
},
}
)
} }
type PageHeadSearchInput = ReturnType<typeof usePageHeadSearchInput> type PageHeadSearchInput = ReturnType<typeof usePageHeadSearchInput>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册