Files
2025-09-29 02:10:32 +08:00

26 lines
673 B
XML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// format.wxs (新版:使用 switch 语句,更清晰)
/**
* 根据传入的 gender 整数,返回对应的文本
* @param {number} genderCode - 0, 1, 或 2
* @returns {string} - '未设置', '男', 或 '女'
*/
function formatGender(genderCode) {
// 直接对传入的整数进行判断
switch (genderCode) {
case 0:
return '未设置';
case 1:
return '男';
case 2:
return '女';
default:
// 如果传入的不是 0, 1, 2, 或者为 null/undefined则返回默认值
return '未设置';
}
}
// 将 formatGender 函数导出,以便 WXML 文件可以使用
module.exports = {
formatGender: formatGender
};