修复:收口小程序键盘遮挡适配

This commit is contained in:
xiaowang
2026-04-22 16:53:32 +08:00
parent 1523e9d8e5
commit d535994614
12 changed files with 897 additions and 168 deletions
+42 -2
View File
@@ -8,13 +8,23 @@ const { buildProductCards } = require('../../utils/product')
const navigation = require('../../utils/navigation')
const { runWithLoading } = require('../../utils/loading')
const { CACHE_TTL } = require('../../utils/config')
const {
createKeyboardSafeData,
attachKeyboardSafe,
detachKeyboardSafe,
handleKeyboardFocus,
handleKeyboardBlur,
resetKeyboardSafe
} = require('../../utils/keyboard-safe')
const ALL_CATEGORY = '\u5168\u90e8'
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
const CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
Page({
data: {
data: Object.assign(createKeyboardSafeData({
cursorSpacing: 96
}), {
initialized: false,
loading: false,
loadingMore: false,
@@ -27,14 +37,16 @@ Page({
pageSize: 10,
total: 0,
hasMore: false
},
}),
onLoad(options) {
this.filterRequestId = 0
this.ensureKeyboardSafe()
this.bootstrapPage(options || {})
},
async onShow() {
this.ensureKeyboardSafe()
const app = getApp()
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
@@ -51,6 +63,16 @@ Page({
}
},
onHide() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
onUnload() {
resetKeyboardSafe(this)
detachKeyboardSafe(this)
},
async onPullDownRefresh() {
await this.loadProducts(true)
wx.stopPullDownRefresh()
@@ -63,6 +85,13 @@ Page({
this.loadProducts(false)
},
ensureKeyboardSafe() {
attachKeyboardSafe(this, {
cursorSpacing: 96,
spacerExtraRpx: 16
})
},
async bootstrapPage(options) {
this.setData({
loading: true
@@ -263,7 +292,16 @@ Page({
})
},
handleSearchFocus(event) {
handleKeyboardFocus(this, event)
},
handleSearchBlur() {
handleKeyboardBlur(this)
},
async handleSearchConfirm() {
resetKeyboardSafe(this)
try {
await actionGuard.run(this, 'products:search', async () => {
this.setData({
@@ -287,6 +325,7 @@ Page({
async handleSelectCategory(event) {
const category = event.currentTarget.dataset.category
resetKeyboardSafe(this)
try {
await actionGuard.run(this, `products:category:${category}`, async () => {
this.setData({
@@ -310,6 +349,7 @@ Page({
},
async handleResetFilters() {
resetKeyboardSafe(this)
try {
await actionGuard.run(this, 'products:reset', async () => {
this.setData({
+7 -2
View File
@@ -1,7 +1,7 @@
<navigation-bar title="作品库" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
<view class="page-shell product-page">
<view class="page-content product-page-content">
<view class="page-shell product-page {{keyboardVisible ? 'keyboard-active' : ''}}">
<view class="page-content product-page-content" style="{{keyboardVisible ? 'padding-bottom: ' + keyboardInsetRpx + 'rpx;' : ''}}">
<view class="sticky-filter-bar">
<view class="filter-surface">
<view class="search-row">
@@ -12,6 +12,11 @@
value="{{searchKeyword}}"
bindinput="handleSearchInput"
bindconfirm="handleSearchConfirm"
bindfocus="handleSearchFocus"
bindblur="handleSearchBlur"
data-keyboard-anchor="products-search-anchor"
adjust-position="false"
cursor-spacing="{{keyboardCursorSpacing}}"
confirm-type="search"
/>
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>