feat: add MBTI tag functionality to user profile
- Introduced a new MBTI tag in the user profile section, displaying the user's MBTI type or a default label if not available. - Implemented navigation to a mini program for MBTI testing, ensuring user phone number is included if logged in. - Enhanced styling for the MBTI tag to improve visibility and user interaction. Made-with: Cursor
This commit is contained in:
@@ -10,6 +10,11 @@ const { trackClick } = require('../../utils/trackClick')
|
||||
const { cleanSingleLineField } = require('../../utils/contentParser.js')
|
||||
const { navigateMpPath } = require('../../utils/mpNavigate.js')
|
||||
const { isSafeImageSrc } = require('../../utils/imageUrl.js')
|
||||
const { appendQueryToPath, ensureLoggedInUserPhone } = require('../../utils/linkedMiniprogramNavigate.js')
|
||||
|
||||
/** MBTI 测试小程序(写死;须与 app.json navigateToMiniProgramAppIdList 一致) */
|
||||
const MBTI_MP_APP_ID = 'wx3d15ed02e98b04e3'
|
||||
const MBTI_MP_PATH = 'pages/index/index'
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -95,6 +100,8 @@ Page({
|
||||
mpUiVipLabelGuest: '成为会员',
|
||||
mpUiReadStatLabel: '已读章节',
|
||||
mpUiRecentTitle: '最近阅读',
|
||||
/** 资料区 MBTI 标签文案:已测为四字母大写,未测为「MBTI」 */
|
||||
mbtiTagText: '',
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -147,6 +154,12 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
_formatMbtiTagText(user) {
|
||||
const raw = String(user && user.mbti != null ? user.mbti : '').trim()
|
||||
if (!raw) return 'MBTI'
|
||||
return raw.toUpperCase()
|
||||
},
|
||||
|
||||
async _refreshMyAvatarDisplay(safeUser) {
|
||||
if (!safeUser || !app.globalData.isLoggedIn) return
|
||||
try {
|
||||
@@ -198,6 +211,7 @@ Page({
|
||||
isLoggedIn: true,
|
||||
userInfo: safeUser,
|
||||
profileAvatarDisplay: '',
|
||||
mbtiTagText: this._formatMbtiTagText(safeUser),
|
||||
userIdShort,
|
||||
userWechat,
|
||||
readCount: 0,
|
||||
@@ -227,6 +241,7 @@ Page({
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
profileAvatarDisplay: '',
|
||||
mbtiTagText: '',
|
||||
userIdShort: '',
|
||||
readCount: guestReadCount,
|
||||
readCountText: formatStatNum(guestReadCount),
|
||||
@@ -1065,6 +1080,26 @@ Page({
|
||||
wx.navigateTo({ url: `/pages/member-detail/member-detail?id=${encodeURIComponent(uid)}` })
|
||||
},
|
||||
|
||||
/** MBTI 测试小程序:写死 appId + path,path 上带 phone(有则传,与阅读页一致) */
|
||||
async onMbtiTagTap() {
|
||||
trackClick('my', 'btn_click', 'MBTI标签')
|
||||
if (!this.data.isLoggedIn) {
|
||||
this.showLogin()
|
||||
return
|
||||
}
|
||||
const phone = await ensureLoggedInUserPhone()
|
||||
let path = MBTI_MP_PATH.trim().replace(/^\/+/, '')
|
||||
if (phone) path = appendQueryToPath(path, 'phone', phone)
|
||||
wx.navigateToMiniProgram({
|
||||
appId: MBTI_MP_APP_ID,
|
||||
path,
|
||||
envVersion: 'release',
|
||||
fail: (err) => {
|
||||
wx.showToast({ title: err.errMsg || '跳转失败', icon: 'none' })
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
goToProfileEdit() {
|
||||
trackClick('my', 'nav_click', '资料编辑')
|
||||
if (!this.data.isLoggedIn) { this.showLogin(); return }
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
<view class="profile-actions-row profile-actions-under-name" wx:if="{{!auditMode}}">
|
||||
<view class="profile-action-btn" catchtap="goToMySuperCard">{{mpUiCardLabel}}</view>
|
||||
<view class="profile-action-btn" catchtap="goToVip">{{isVip ? mpUiVipLabelVip : mpUiVipLabelGuest}}</view>
|
||||
<view class="profile-mbti-tag" catchtap="onMbtiTagTap">{{mbtiTagText}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="profile-settings-hit" catchtap="goToProfileEdit" hover-class="profile-settings-hit-active" aria-label="编辑资料">
|
||||
|
||||
@@ -105,6 +105,26 @@
|
||||
font-size: 24rpx; font-weight: 500; border-radius: 40rpx; white-space: nowrap; flex-shrink: 0;
|
||||
}
|
||||
.profile-action-btn:active { opacity: 0.75; }
|
||||
/* MBTI:高亮胶囊(实心青渐变 + 白字 + 外发光),与描边按钮区分 */
|
||||
.profile-mbti-tag {
|
||||
padding: 12rpx 26rpx;
|
||||
border-radius: 40rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.06em;
|
||||
color: #fff;
|
||||
background: linear-gradient(135deg, #5eead4 0%, #4FD1C5 45%, #2dd4bf 100%);
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.35);
|
||||
box-shadow:
|
||||
0 4rpx 16rpx rgba(79, 209, 197, 0.45),
|
||||
0 0 0 1rpx rgba(79, 209, 197, 0.25) inset;
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.profile-mbti-tag:active {
|
||||
opacity: 0.88;
|
||||
transform: scale(0.98);
|
||||
}
|
||||
.user-wechat { font-size: 26rpx; color: #6B7280; }
|
||||
.super-card-entry {
|
||||
position: relative;
|
||||
|
||||
Reference in New Issue
Block a user