Files
MBTI_wang/miniprogram/utils/resultProfileGate.js
卡若 ce55c48c64 feat: 同步今日小程序与后台迭代版本
集中提交今日 API、管理端、小程序与部署文档调整,确保 Gitea 主分支与本地最新开发版本一致。

Made-with: Cursor
2026-04-20 11:07:55 +08:00

58 lines
1.7 KiB
JavaScript
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.

/**
* 结果页门禁:非分享落地且资料未齐(手机+头像+昵称)时展示约 30% 预览
*/
const { needsResultProfileGate } = require('./phoneAuth.js')
/** @param {WechatMiniprogram.Page.TrivialInstance} page */
function setProfileGateOnPage(page) {
const fromShare = !!(page.data && page.data.fromShare)
const gate = needsResultProfileGate(fromShare)
page.setData({ profileGate: gate })
}
/**
* 截取约 ratio 比例的纯文本(最少 minChars尾部省略号
* @param {string} str
* @param {number} ratio 0~1
* @param {number} minChars
*/
function slicePreviewText(str, ratio, minChars) {
const s = (str && String(str).trim()) || ''
const r = typeof ratio === 'number' && ratio > 0 && ratio < 1 ? ratio : 0.3
const minC = minChars != null ? minChars : 36
if (!s) return ''
const n = Math.max(minC, Math.floor(s.length * r))
return s.length <= n ? s : s.slice(0, n) + '…'
}
/**
* @param {string[]} list
* @param {number} ratio
*/
function slicePreviewList(list, ratio) {
const arr = Array.isArray(list) ? list : []
const r = typeof ratio === 'number' && ratio > 0 && ratio < 1 ? ratio : 0.3
if (!arr.length) return []
const take = Math.max(1, Math.ceil(arr.length * r))
return arr.slice(0, take)
}
function openTimelineShareHint() {
try {
wx.showShareMenu({ withShareTicket: true, menus: ['shareAppMessage', 'shareTimeline'] })
} catch (e) {}
wx.showModal({
title: '分享到朋友圈',
content: '已为你打开分享能力:请先点右上角「···」,选择「分享到朋友圈」。好友点链接即可测试。',
showCancel: false,
confirmText: '知道了'
})
}
module.exports = {
setProfileGateOnPage,
slicePreviewText,
slicePreviewList,
openTimelineShareHint
}