修复:收口小程序键盘遮挡适配
This commit is contained in:
@@ -4,17 +4,28 @@ const cache = require('../../utils/cache')
|
||||
const { buildProductCards } = require('../../utils/product')
|
||||
const { resolveImageList } = require('../../utils/file')
|
||||
const { DEFAULT_SHOP_IMAGE, CACHE_TTL } = require('../../utils/config')
|
||||
const {
|
||||
createKeyboardSafeData,
|
||||
attachKeyboardSafe,
|
||||
detachKeyboardSafe,
|
||||
handleKeyboardFocus,
|
||||
handleKeyboardBlur,
|
||||
resetKeyboardSafe
|
||||
} = require('../../utils/keyboard-safe')
|
||||
const productApi = require('../../api/product')
|
||||
const shopApi = require('../../api/shop')
|
||||
const userApi = require('../../api/user')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
data: Object.assign(createKeyboardSafeData({
|
||||
cursorSpacing: 96
|
||||
}), {
|
||||
initialized: false,
|
||||
loading: false,
|
||||
loadingMore: false,
|
||||
isLoggedIn: false,
|
||||
userInfo: null,
|
||||
navTitle: '游客模式',
|
||||
greeting: '欢迎来到 Yumi Nail',
|
||||
displayName: '先看看门店和作品',
|
||||
searchKeyword: '',
|
||||
@@ -25,20 +36,32 @@ Page({
|
||||
pageSize: 6,
|
||||
hasMore: false,
|
||||
popularTotal: 0
|
||||
},
|
||||
}),
|
||||
|
||||
onLoad() {
|
||||
this.homeRequestId = 0
|
||||
this.ensureKeyboardSafe()
|
||||
this.loadHomeData()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.ensureKeyboardSafe()
|
||||
this.syncUserState()
|
||||
if (this.data.initialized && this.data.isLoggedIn) {
|
||||
this.loadUserProfile()
|
||||
}
|
||||
},
|
||||
|
||||
onHide() {
|
||||
resetKeyboardSafe(this)
|
||||
detachKeyboardSafe(this)
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
resetKeyboardSafe(this)
|
||||
detachKeyboardSafe(this)
|
||||
},
|
||||
|
||||
async onPullDownRefresh() {
|
||||
cache.removeByPrefix('home:')
|
||||
await this.loadHomeData()
|
||||
@@ -52,10 +75,20 @@ Page({
|
||||
this.loadPopularProducts(false)
|
||||
},
|
||||
|
||||
ensureKeyboardSafe() {
|
||||
attachKeyboardSafe(this, {
|
||||
cursorSpacing: 96,
|
||||
spacerExtraRpx: 24
|
||||
})
|
||||
},
|
||||
|
||||
syncUserState() {
|
||||
const app = getApp()
|
||||
const userInfo = auth.getStoredUserInfo()
|
||||
const isLoggedIn = auth.isLoggedIn()
|
||||
const navTitle = userInfo && String(userInfo.shopName || '').trim()
|
||||
? String(userInfo.shopName).trim()
|
||||
: '游客模式'
|
||||
if (app) {
|
||||
app.globalData.userInfo = userInfo
|
||||
app.globalData.isLoggedIn = isLoggedIn
|
||||
@@ -64,6 +97,7 @@ Page({
|
||||
this.setData({
|
||||
isLoggedIn,
|
||||
userInfo,
|
||||
navTitle,
|
||||
greeting: isLoggedIn ? '欢迎回来' : '游客模式',
|
||||
displayName: isLoggedIn
|
||||
? ((userInfo && userInfo.nickname) || 'Yumi 用户')
|
||||
@@ -203,7 +237,16 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
handleSearchFocus(event) {
|
||||
handleKeyboardFocus(this, event)
|
||||
},
|
||||
|
||||
handleSearchBlur() {
|
||||
handleKeyboardBlur(this)
|
||||
},
|
||||
|
||||
handleSearchConfirm() {
|
||||
resetKeyboardSafe(this)
|
||||
navigation.openProducts({
|
||||
keyword: this.data.searchKeyword.trim()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user