feat: update agreements and refine miniapp layouts and integrations

This commit is contained in:
zhouzhibo committed 2026-10-21 20:33:50 +08:00
1 parent 38fc4187ea
commit 7871114c50
26 files changed
+2018 -120

No files matched your search

+18 -4
View File
@@ -10,6 +10,18 @@ function render(env, sheet = false) {
const exports = {}, updates = [], media = []
let index = 0
const source = fs.readFileSync(path.join(__dirname, '../src/pages/profile-edit/index.tsx'), 'utf8')
const parsed = ts.createSourceFile('profile-edit.tsx', source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX)
const stateNames = []
const collectStateNames = node => {
if (ts.isVariableDeclaration(node) && ts.isArrayBindingPattern(node.name)
&& node.initializer && ts.isCallExpression(node.initializer) && node.initializer.expression.getText(parsed) === 'useState') {
stateNames.push(node.name.elements[0].name.getText(parsed))
}
ts.forEachChild(node, collectStateNames)
}
collectStateNames(parsed)
const avatarSheetIndex = stateNames.indexOf('avatarSheetOpen')
assert.notEqual(avatarSheetIndex, -1)
vm.runInNewContext(ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS,
target: ts.ScriptTarget.ES2019, jsx: ts.JsxEmit.ReactJSX } }).outputText, {
exports, process: { env: { TARO_ENV: env } }, require: id => {
@@ -19,10 +31,11 @@ function render(env, sheet = false) {
let value = typeof initial === 'function' ? initial() : initial
if (value === null || (value && typeof value === 'object' && 'nickname' in value)) value = profile
if (initial === true) value = false
if (current === 5) value = sheet // avatarSheetOpen
if (current === avatarSheetIndex) value = sheet
return [value, next => updates.push([current, next])]
} }
if (id === '@tarojs/taro') return { useRouter: () => ({ params: {} }), default: {
getWindowInfo: () => ({ statusBarHeight: 44, safeArea: { top: 44 } }),
chooseMedia: async options => { media.push(options); return { tempFiles: [{ tempFilePath: 'temp:album', size: 10 }] } }, showToast: () => {}
} }
if (id === '@tarojs/components') return { View: 'View', Text: 'Text', Button: 'Button', Input: 'Input', Picker: 'Picker' }
@@ -40,7 +53,8 @@ function render(env, sheet = false) {
if (Array.isArray(node)) return node.flatMap(collect)
return [node, ...collect(node.props?.children)]
}
return { nodes: collect(exports.default()), updates, media }
return { nodes: collect(exports.default()), updates, media,
avatarSheetUpdates: () => updates.filter(([index]) => index === avatarSheetIndex).map(([, value]) => value) }
}
test('微信端头像本身直接绑定官方chooseAvatar,不再弹自定义菜单', () => {
@@ -53,7 +67,7 @@ test('微信端头像本身直接绑定官方chooseAvatar,不再弹自定义
button.props.onChooseAvatar({ detail: { avatarUrl: 'temp:wechat-avatar' } })
assert.equal(h.media.length, 0)
assert.ok(h.updates.some(([, value]) => value === 'temp:wechat-avatar'))
assert.ok(h.updates.some(([index, value]) => index === 5 && value === false))
assert.ok(h.avatarSheetUpdates().includes(false))
})
test('H5保留相册拍照菜单,不伪造微信官方头像选择能力', async () => {
@@ -62,7 +76,7 @@ test('H5保留相册拍照菜单,不伪造微信官方头像选择能力', asy
assert.equal(button.props.openType, undefined)
assert.equal(button.props.onChooseAvatar, undefined)
button.props.onClick()
assert.ok(h.updates.some(([index, value]) => index === 5 && value === true))
assert.ok(h.avatarSheetUpdates().includes(true))
const opened = render('h5', true)
const album = opened.nodes.find(node => node.props?.children === '从相册选择')
await album.props.onClick()