修复:收口小程序键盘遮挡适配
This commit is contained in:
@@ -5,11 +5,21 @@ const authStore = require('../../utils/auth')
|
|||||||
const actionGuard = require('../../utils/action-guard')
|
const actionGuard = require('../../utils/action-guard')
|
||||||
const navigation = require('../../utils/navigation')
|
const navigation = require('../../utils/navigation')
|
||||||
const { runWithLoading } = require('../../utils/loading')
|
const { runWithLoading } = require('../../utils/loading')
|
||||||
|
const {
|
||||||
|
createKeyboardSafeData,
|
||||||
|
attachKeyboardSafe,
|
||||||
|
detachKeyboardSafe,
|
||||||
|
handleKeyboardFocus,
|
||||||
|
handleKeyboardBlur,
|
||||||
|
resetKeyboardSafe
|
||||||
|
} = require('../../utils/keyboard-safe')
|
||||||
|
|
||||||
const phoneRegex = /^1[3-9]\d{9}$/
|
const phoneRegex = /^1[3-9]\d{9}$/
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: Object.assign(createKeyboardSafeData({
|
||||||
|
cursorSpacing: 108
|
||||||
|
}), {
|
||||||
redirect: '',
|
redirect: '',
|
||||||
activeTab: 'login',
|
activeTab: 'login',
|
||||||
loginType: 'password',
|
loginType: 'password',
|
||||||
@@ -59,9 +69,10 @@ Page({
|
|||||||
verificationCode: '',
|
verificationCode: '',
|
||||||
newPassword: ''
|
newPassword: ''
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
|
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.setData({
|
this.setData({
|
||||||
redirect: options && options.redirect ? options.redirect : '',
|
redirect: options && options.redirect ? options.redirect : '',
|
||||||
authHelperText: this.buildAuthHelperText('login', 'password')
|
authHelperText: this.buildAuthHelperText('login', 'password')
|
||||||
@@ -73,11 +84,37 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.consumePendingWechatMiniLogin()
|
this.consumePendingWechatMiniLogin()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onHide() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
|
},
|
||||||
|
|
||||||
|
onUnload() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
|
},
|
||||||
|
|
||||||
noop() {},
|
noop() {},
|
||||||
|
|
||||||
|
ensureKeyboardSafe() {
|
||||||
|
attachKeyboardSafe(this, {
|
||||||
|
cursorSpacing: 108,
|
||||||
|
spacerExtraRpx: 56
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
handleKeyboardFocus(event) {
|
||||||
|
handleKeyboardFocus(this, event)
|
||||||
|
},
|
||||||
|
|
||||||
|
handleKeyboardBlur() {
|
||||||
|
handleKeyboardBlur(this)
|
||||||
|
},
|
||||||
|
|
||||||
detectWechatMiniCapability() {
|
detectWechatMiniCapability() {
|
||||||
let supported = false
|
let supported = false
|
||||||
let disabledReason = ''
|
let disabledReason = ''
|
||||||
@@ -158,6 +195,7 @@ Page({
|
|||||||
|
|
||||||
handleTabChange(event) {
|
handleTabChange(event) {
|
||||||
const tab = event.currentTarget.dataset.tab
|
const tab = event.currentTarget.dataset.tab
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.setData({
|
this.setData({
|
||||||
activeTab: tab,
|
activeTab: tab,
|
||||||
authHelperText: this.buildAuthHelperText(tab, this.data.loginType),
|
authHelperText: this.buildAuthHelperText(tab, this.data.loginType),
|
||||||
@@ -174,6 +212,7 @@ Page({
|
|||||||
|
|
||||||
handleLoginTypeChange(event) {
|
handleLoginTypeChange(event) {
|
||||||
const type = event.currentTarget.dataset.type
|
const type = event.currentTarget.dataset.type
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.setData({
|
this.setData({
|
||||||
loginType: type,
|
loginType: type,
|
||||||
authHelperText: this.buildAuthHelperText(this.data.activeTab, type),
|
authHelperText: this.buildAuthHelperText(this.data.activeTab, type),
|
||||||
@@ -189,6 +228,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleShowTraditionalLogin() {
|
handleShowTraditionalLogin() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.setData({
|
this.setData({
|
||||||
traditionalLoginExpanded: true,
|
traditionalLoginExpanded: true,
|
||||||
showResetPanel: false
|
showResetPanel: false
|
||||||
@@ -196,6 +236,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleToggleResetPanel() {
|
handleToggleResetPanel() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.setData({
|
this.setData({
|
||||||
showResetPanel: !this.data.showResetPanel
|
showResetPanel: !this.data.showResetPanel
|
||||||
})
|
})
|
||||||
@@ -299,6 +340,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async handleAccountBlur() {
|
async handleAccountBlur() {
|
||||||
|
this.handleKeyboardBlur()
|
||||||
const account = this.data.form.account.trim()
|
const account = this.data.form.account.trim()
|
||||||
if (!account) {
|
if (!account) {
|
||||||
return
|
return
|
||||||
@@ -320,6 +362,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async handlePhoneBlur() {
|
async handlePhoneBlur() {
|
||||||
|
this.handleKeyboardBlur()
|
||||||
const phone = this.data.form.phone.trim()
|
const phone = this.data.form.phone.trim()
|
||||||
if (!phone) {
|
if (!phone) {
|
||||||
return
|
return
|
||||||
@@ -849,6 +892,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
openMiniShopSelector(result) {
|
openMiniShopSelector(result) {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
const shops = Array.isArray(result && result.shops) ? result.shops : []
|
||||||
if (!shops.length) {
|
if (!shops.length) {
|
||||||
wx.showToast({
|
wx.showToast({
|
||||||
@@ -887,6 +931,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async finishLogin(payload, successMessage) {
|
async finishLogin(payload, successMessage) {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
getApp().setUserSession(payload)
|
getApp().setUserSession(payload)
|
||||||
this.clearMiniShopSelector()
|
this.clearMiniShopSelector()
|
||||||
this.setData({
|
this.setData({
|
||||||
|
|||||||
@@ -1,7 +1,17 @@
|
|||||||
|
<view class="auth-page-root">
|
||||||
<navigation-bar title="账号中心" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
<navigation-bar title="账号中心" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
||||||
|
|
||||||
<view class="page-shell auth-page">
|
<scroll-view
|
||||||
<view class="page-content auth-content">
|
class="auth-scroll"
|
||||||
|
scroll-y
|
||||||
|
enable-flex
|
||||||
|
enhanced
|
||||||
|
show-scrollbar="false"
|
||||||
|
scroll-with-animation="{{true}}"
|
||||||
|
scroll-into-view="{{keyboardAnchorId}}"
|
||||||
|
>
|
||||||
|
<view class="page-shell auth-page-shell auth-page">
|
||||||
|
<view class="page-content auth-content {{keyboardVisible ? 'keyboard-active' : ''}}">
|
||||||
<view class="page-card auth-panel">
|
<view class="page-card auth-panel">
|
||||||
<view class="tab-row">
|
<view class="tab-row">
|
||||||
<view class="tab-item {{activeTab === 'login' ? 'active' : ''}}" data-tab="login" bindtap="handleTabChange">登录</view>
|
<view class="tab-item {{activeTab === 'login' ? 'active' : ''}}" data-tab="login" bindtap="handleTabChange">登录</view>
|
||||||
@@ -63,46 +73,135 @@
|
|||||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="auth-helper">{{authHelperText}}</view>
|
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="auth-helper">{{authHelperText}}</view>
|
||||||
|
|
||||||
<block wx:if="{{activeTab === 'register'}}">
|
<block wx:if="{{activeTab === 'register'}}">
|
||||||
<view class="field-block">
|
<view id="auth-register-nickname-anchor" class="field-block">
|
||||||
<text class="field-label">昵称</text>
|
<text class="field-label">昵称</text>
|
||||||
<input class="field-input" placeholder="请输入昵称" placeholder-class="field-placeholder" value="{{form.nickname}}" data-field="nickname" bindinput="handleInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
placeholder="请输入昵称"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.nickname}}"
|
||||||
|
data-field="nickname"
|
||||||
|
data-keyboard-anchor="auth-register-nickname-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
</block>
|
</block>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="field-block">
|
<view id="auth-account-anchor" wx:if="{{activeTab === 'register' || traditionalLoginExpanded}}" class="field-block">
|
||||||
<text class="field-label">账号</text>
|
<text class="field-label">账号</text>
|
||||||
<input class="field-input" placeholder="请输入账号" placeholder-class="field-placeholder" value="{{form.account}}" data-field="account" bindinput="handleInputChange" bindblur="handleAccountBlur"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
placeholder="请输入账号"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.account}}"
|
||||||
|
data-field="account"
|
||||||
|
data-keyboard-anchor="auth-account-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindblur="handleAccountBlur"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<text wx:if="{{activeTab === 'login' && loginAccountStatusText}}" class="status-text {{loginAccountStatusType}}">{{loginAccountStatusText}}</text>
|
<text wx:if="{{activeTab === 'login' && loginAccountStatusText}}" class="status-text {{loginAccountStatusType}}">{{loginAccountStatusText}}</text>
|
||||||
<text wx:if="{{activeTab === 'register' && registerAccountStatusText}}" class="status-text {{registerAccountStatusType}}">{{registerAccountStatusText}}</text>
|
<text wx:if="{{activeTab === 'register' && registerAccountStatusText}}" class="status-text {{registerAccountStatusType}}">{{registerAccountStatusText}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
|
<view id="auth-phone-anchor" wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
|
||||||
<text class="field-label">手机号</text>
|
<text class="field-label">手机号</text>
|
||||||
<input class="field-input" type="number" placeholder="请输入手机号" placeholder-class="field-placeholder" value="{{form.phone}}" data-field="phone" bindinput="handleInputChange" bindblur="handlePhoneBlur"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.phone}}"
|
||||||
|
data-field="phone"
|
||||||
|
data-keyboard-anchor="auth-phone-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindblur="handlePhoneBlur"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<text wx:if="{{activeTab === 'register' && registerPhoneStatusText}}" class="status-text {{registerPhoneStatusType}}">{{registerPhoneStatusText}}</text>
|
<text wx:if="{{activeTab === 'register' && registerPhoneStatusText}}" class="status-text {{registerPhoneStatusType}}">{{registerPhoneStatusText}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'login' && traditionalLoginExpanded && loginType === 'password'}}" class="field-block">
|
<view id="auth-login-password-anchor" wx:if="{{activeTab === 'login' && traditionalLoginExpanded && loginType === 'password'}}" class="field-block">
|
||||||
<text class="field-label">密码</text>
|
<text class="field-label">密码</text>
|
||||||
<input class="field-input" password placeholder="请输入密码" placeholder-class="field-placeholder" value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请输入密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.password}}"
|
||||||
|
data-field="password"
|
||||||
|
data-keyboard-anchor="auth-login-password-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
|
<view id="auth-code-anchor" wx:if="{{activeTab === 'register' || (traditionalLoginExpanded && loginType === 'phone')}}" class="field-block">
|
||||||
<text class="field-label">验证码</text>
|
<text class="field-label">验证码</text>
|
||||||
<view class="code-row">
|
<view class="code-row">
|
||||||
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{form.verificationCode}}" data-field="verificationCode" bindinput="handleInputChange"></input>
|
<input
|
||||||
|
class="field-input code-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.verificationCode}}"
|
||||||
|
data-field="verificationCode"
|
||||||
|
data-keyboard-anchor="auth-code-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register'}}" class="field-block">
|
<view id="auth-register-password-anchor" wx:if="{{activeTab === 'register'}}" class="field-block">
|
||||||
<text class="field-label">密码</text>
|
<text class="field-label">密码</text>
|
||||||
<input class="field-input" password placeholder="请输入密码" placeholder-class="field-placeholder" value="{{form.password}}" data-field="password" bindinput="handleInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请输入密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.password}}"
|
||||||
|
data-field="password"
|
||||||
|
data-keyboard-anchor="auth-register-password-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register'}}" class="field-block">
|
<view id="auth-register-confirm-password-anchor" wx:if="{{activeTab === 'register'}}" class="field-block">
|
||||||
<text class="field-label">确认密码</text>
|
<text class="field-label">确认密码</text>
|
||||||
<input class="field-input" password placeholder="请再次输入密码" placeholder-class="field-placeholder" value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="handleInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请再次输入密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.confirmPassword}}"
|
||||||
|
data-field="confirmPassword"
|
||||||
|
data-keyboard-anchor="auth-register-confirm-password-anchor"
|
||||||
|
bindinput="handleInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view wx:if="{{activeTab === 'register'}}" class="field-block">
|
<view wx:if="{{activeTab === 'register'}}" class="field-block">
|
||||||
@@ -132,28 +231,71 @@
|
|||||||
<view class="section-title">重置密码</view>
|
<view class="section-title">重置密码</view>
|
||||||
<view class="section-subtitle">短信验证后重置密码</view>
|
<view class="section-subtitle">短信验证后重置密码</view>
|
||||||
|
|
||||||
<view class="field-block">
|
<view id="auth-reset-phone-anchor" class="field-block">
|
||||||
<text class="field-label">手机号</text>
|
<text class="field-label">手机号</text>
|
||||||
<input class="field-input" type="number" placeholder="请输入绑定手机号" placeholder-class="field-placeholder" value="{{resetForm.phone}}" data-field="phone" bindinput="handleResetInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入绑定手机号"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{resetForm.phone}}"
|
||||||
|
data-field="phone"
|
||||||
|
data-keyboard-anchor="auth-reset-phone-anchor"
|
||||||
|
bindinput="handleResetInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="field-block">
|
<view id="auth-reset-code-anchor" class="field-block">
|
||||||
<text class="field-label">验证码</text>
|
<text class="field-label">验证码</text>
|
||||||
<view class="code-row">
|
<view class="code-row">
|
||||||
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{resetForm.verificationCode}}" data-field="verificationCode" bindinput="handleResetInputChange"></input>
|
<input
|
||||||
|
class="field-input code-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{resetForm.verificationCode}}"
|
||||||
|
data-field="verificationCode"
|
||||||
|
data-keyboard-anchor="auth-reset-code-anchor"
|
||||||
|
bindinput="handleResetInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<view class="code-btn {{forgotCountdown > 0 ? 'disabled' : ''}}" bindtap="handleSendForgotCode">{{forgotCountdown > 0 ? forgotCountdown + 's' : '发送验证码'}}</view>
|
<view class="code-btn {{forgotCountdown > 0 ? 'disabled' : ''}}" bindtap="handleSendForgotCode">{{forgotCountdown > 0 ? forgotCountdown + 's' : '发送验证码'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="field-block">
|
<view id="auth-reset-password-anchor" class="field-block">
|
||||||
<text class="field-label">新密码</text>
|
<text class="field-label">新密码</text>
|
||||||
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{resetForm.newPassword}}" data-field="newPassword" bindinput="handleResetInputChange"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请输入新密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{resetForm.newPassword}}"
|
||||||
|
data-field="newPassword"
|
||||||
|
data-keyboard-anchor="auth-reset-password-anchor"
|
||||||
|
bindinput="handleResetInputChange"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="primary-btn submit-btn" bindtap="handleResetPassword">确认重置密码</view>
|
<view class="primary-btn submit-btn" bindtap="handleResetPassword">确认重置密码</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{keyboardVisible}}" class="keyboard-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
|
||||||
|
</view>
|
||||||
|
</scroll-view>
|
||||||
|
|
||||||
<view wx:if="{{showMiniShopSelector}}" class="mini-shop-mask" catchtouchmove="noop">
|
<view wx:if="{{showMiniShopSelector}}" class="mini-shop-mask" catchtouchmove="noop">
|
||||||
<view class="page-card mini-shop-modal">
|
<view class="page-card mini-shop-modal">
|
||||||
<text class="mini-shop-kicker">{{miniShopNewUser ? '首次微信登录' : '确认本次登录门店'}}</text>
|
<text class="mini-shop-kicker">{{miniShopNewUser ? '首次微信登录' : '确认本次登录门店'}}</text>
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
.auth-page-root {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-scroll {
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.auth-page-shell {
|
||||||
|
min-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.auth-page {
|
.auth-page {
|
||||||
background:
|
background:
|
||||||
radial-gradient(circle at top right, rgba(255, 204, 219, 0.32), transparent 30%),
|
radial-gradient(circle at top right, rgba(255, 204, 219, 0.32), transparent 30%),
|
||||||
@@ -5,7 +21,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.auth-content {
|
.auth-content {
|
||||||
min-height: calc(100vh - 120rpx);
|
min-height: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@@ -13,6 +29,11 @@
|
|||||||
padding: 24rpx 24rpx 40rpx;
|
padding: 24rpx 24rpx 40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.auth-content.keyboard-active {
|
||||||
|
justify-content: flex-start;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
.auth-panel,
|
.auth-panel,
|
||||||
.reset-card {
|
.reset-card {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
@@ -282,3 +303,8 @@
|
|||||||
.mini-shop-action {
|
.mini-shop-action {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keyboard-spacer {
|
||||||
|
width: 100%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,17 +4,28 @@ const cache = require('../../utils/cache')
|
|||||||
const { buildProductCards } = require('../../utils/product')
|
const { buildProductCards } = require('../../utils/product')
|
||||||
const { resolveImageList } = require('../../utils/file')
|
const { resolveImageList } = require('../../utils/file')
|
||||||
const { DEFAULT_SHOP_IMAGE, CACHE_TTL } = require('../../utils/config')
|
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 productApi = require('../../api/product')
|
||||||
const shopApi = require('../../api/shop')
|
const shopApi = require('../../api/shop')
|
||||||
const userApi = require('../../api/user')
|
const userApi = require('../../api/user')
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: Object.assign(createKeyboardSafeData({
|
||||||
|
cursorSpacing: 96
|
||||||
|
}), {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingMore: false,
|
loadingMore: false,
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
userInfo: null,
|
userInfo: null,
|
||||||
|
navTitle: '游客模式',
|
||||||
greeting: '欢迎来到 Yumi Nail',
|
greeting: '欢迎来到 Yumi Nail',
|
||||||
displayName: '先看看门店和作品',
|
displayName: '先看看门店和作品',
|
||||||
searchKeyword: '',
|
searchKeyword: '',
|
||||||
@@ -25,20 +36,32 @@ Page({
|
|||||||
pageSize: 6,
|
pageSize: 6,
|
||||||
hasMore: false,
|
hasMore: false,
|
||||||
popularTotal: 0
|
popularTotal: 0
|
||||||
},
|
}),
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.homeRequestId = 0
|
this.homeRequestId = 0
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.loadHomeData()
|
this.loadHomeData()
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.syncUserState()
|
this.syncUserState()
|
||||||
if (this.data.initialized && this.data.isLoggedIn) {
|
if (this.data.initialized && this.data.isLoggedIn) {
|
||||||
this.loadUserProfile()
|
this.loadUserProfile()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onHide() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
|
},
|
||||||
|
|
||||||
|
onUnload() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
|
},
|
||||||
|
|
||||||
async onPullDownRefresh() {
|
async onPullDownRefresh() {
|
||||||
cache.removeByPrefix('home:')
|
cache.removeByPrefix('home:')
|
||||||
await this.loadHomeData()
|
await this.loadHomeData()
|
||||||
@@ -52,10 +75,20 @@ Page({
|
|||||||
this.loadPopularProducts(false)
|
this.loadPopularProducts(false)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ensureKeyboardSafe() {
|
||||||
|
attachKeyboardSafe(this, {
|
||||||
|
cursorSpacing: 96,
|
||||||
|
spacerExtraRpx: 24
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
syncUserState() {
|
syncUserState() {
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
const userInfo = auth.getStoredUserInfo()
|
const userInfo = auth.getStoredUserInfo()
|
||||||
const isLoggedIn = auth.isLoggedIn()
|
const isLoggedIn = auth.isLoggedIn()
|
||||||
|
const navTitle = userInfo && String(userInfo.shopName || '').trim()
|
||||||
|
? String(userInfo.shopName).trim()
|
||||||
|
: '游客模式'
|
||||||
if (app) {
|
if (app) {
|
||||||
app.globalData.userInfo = userInfo
|
app.globalData.userInfo = userInfo
|
||||||
app.globalData.isLoggedIn = isLoggedIn
|
app.globalData.isLoggedIn = isLoggedIn
|
||||||
@@ -64,6 +97,7 @@ Page({
|
|||||||
this.setData({
|
this.setData({
|
||||||
isLoggedIn,
|
isLoggedIn,
|
||||||
userInfo,
|
userInfo,
|
||||||
|
navTitle,
|
||||||
greeting: isLoggedIn ? '欢迎回来' : '游客模式',
|
greeting: isLoggedIn ? '欢迎回来' : '游客模式',
|
||||||
displayName: isLoggedIn
|
displayName: isLoggedIn
|
||||||
? ((userInfo && userInfo.nickname) || 'Yumi 用户')
|
? ((userInfo && userInfo.nickname) || 'Yumi 用户')
|
||||||
@@ -203,7 +237,16 @@ Page({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleSearchFocus(event) {
|
||||||
|
handleKeyboardFocus(this, event)
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSearchBlur() {
|
||||||
|
handleKeyboardBlur(this)
|
||||||
|
},
|
||||||
|
|
||||||
handleSearchConfirm() {
|
handleSearchConfirm() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
navigation.openProducts({
|
navigation.openProducts({
|
||||||
keyword: this.data.searchKeyword.trim()
|
keyword: this.data.searchKeyword.trim()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<view class="home-page-root">
|
<view class="home-page-root">
|
||||||
<navigation-bar title="Yumi Nail" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
<navigation-bar title="{{navTitle}}" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
||||||
|
|
||||||
<scroll-view class="home-scroll" scroll-y enable-flex enhanced show-scrollbar="false">
|
<scroll-view class="home-scroll" scroll-y enable-flex enhanced show-scrollbar="false" scroll-with-animation="{{true}}" scroll-into-view="{{keyboardAnchorId}}">
|
||||||
<view class="page-shell home-page">
|
<view class="page-shell home-page {{keyboardVisible ? 'keyboard-active' : ''}}">
|
||||||
<view class="page-content">
|
<view class="page-content">
|
||||||
<view class="page-hero home-hero">
|
<view class="page-hero home-hero">
|
||||||
<text class="hero-kicker">{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}</text>
|
<text class="hero-kicker">{{isLoggedIn ? greeting : 'YUMI NAIL 小程序'}}</text>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<view class="hero-action secondary" bindtap="handleSeeAllPopular">看看热门作品</view>
|
<view class="hero-action secondary" bindtap="handleSeeAllPopular">看看热门作品</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="search-box">
|
<view id="home-search-anchor" class="search-box">
|
||||||
<input
|
<input
|
||||||
class="search-input"
|
class="search-input"
|
||||||
placeholder="搜索作品、风格或门店"
|
placeholder="搜索作品、风格或门店"
|
||||||
@@ -22,6 +22,11 @@
|
|||||||
value="{{searchKeyword}}"
|
value="{{searchKeyword}}"
|
||||||
bindinput="handleSearchInput"
|
bindinput="handleSearchInput"
|
||||||
bindconfirm="handleSearchConfirm"
|
bindconfirm="handleSearchConfirm"
|
||||||
|
bindfocus="handleSearchFocus"
|
||||||
|
bindblur="handleSearchBlur"
|
||||||
|
data-keyboard-anchor="home-search-anchor"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
confirm-type="search"
|
confirm-type="search"
|
||||||
/>
|
/>
|
||||||
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
|
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
|
||||||
@@ -135,6 +140,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<view wx:if="{{keyboardVisible}}" class="keyboard-light-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -17,6 +17,10 @@
|
|||||||
linear-gradient(180deg, #fff7f8 0%, #fffdfb 100%);
|
linear-gradient(180deg, #fff7f8 0%, #fffdfb 100%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.home-page.keyboard-active {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.home-hero {
|
.home-hero {
|
||||||
background:
|
background:
|
||||||
radial-gradient(circle at top right, rgba(255, 186, 207, 0.5), transparent 36%),
|
radial-gradient(circle at top right, rgba(255, 186, 207, 0.5), transparent 36%),
|
||||||
@@ -159,3 +163,8 @@
|
|||||||
font-size: 22rpx;
|
font-size: 22rpx;
|
||||||
color: #8d7a84;
|
color: #8d7a84;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keyboard-light-spacer {
|
||||||
|
width: 100%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,13 +8,23 @@ const { buildProductCards } = require('../../utils/product')
|
|||||||
const navigation = require('../../utils/navigation')
|
const navigation = require('../../utils/navigation')
|
||||||
const { runWithLoading } = require('../../utils/loading')
|
const { runWithLoading } = require('../../utils/loading')
|
||||||
const { CACHE_TTL } = require('../../utils/config')
|
const { CACHE_TTL } = require('../../utils/config')
|
||||||
|
const {
|
||||||
|
createKeyboardSafeData,
|
||||||
|
attachKeyboardSafe,
|
||||||
|
detachKeyboardSafe,
|
||||||
|
handleKeyboardFocus,
|
||||||
|
handleKeyboardBlur,
|
||||||
|
resetKeyboardSafe
|
||||||
|
} = require('../../utils/keyboard-safe')
|
||||||
|
|
||||||
const ALL_CATEGORY = '\u5168\u90e8'
|
const ALL_CATEGORY = '\u5168\u90e8'
|
||||||
const FILTER_BUSY_MESSAGE = '\u7b5b\u9009\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
|
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'
|
const CART_BUSY_MESSAGE = '\u8d2d\u7269\u8f66\u5904\u7406\u4e2d\uff0c\u8bf7\u52ff\u91cd\u590d\u64cd\u4f5c'
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: Object.assign(createKeyboardSafeData({
|
||||||
|
cursorSpacing: 96
|
||||||
|
}), {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
loadingMore: false,
|
loadingMore: false,
|
||||||
@@ -27,14 +37,16 @@ Page({
|
|||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
total: 0,
|
total: 0,
|
||||||
hasMore: false
|
hasMore: false
|
||||||
},
|
}),
|
||||||
|
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
this.filterRequestId = 0
|
this.filterRequestId = 0
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.bootstrapPage(options || {})
|
this.bootstrapPage(options || {})
|
||||||
},
|
},
|
||||||
|
|
||||||
async onShow() {
|
async onShow() {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
const app = getApp()
|
const app = getApp()
|
||||||
const pendingFilter = app && app.globalData ? app.globalData.pendingProductFilter : null
|
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() {
|
async onPullDownRefresh() {
|
||||||
await this.loadProducts(true)
|
await this.loadProducts(true)
|
||||||
wx.stopPullDownRefresh()
|
wx.stopPullDownRefresh()
|
||||||
@@ -63,6 +85,13 @@ Page({
|
|||||||
this.loadProducts(false)
|
this.loadProducts(false)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ensureKeyboardSafe() {
|
||||||
|
attachKeyboardSafe(this, {
|
||||||
|
cursorSpacing: 96,
|
||||||
|
spacerExtraRpx: 16
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
async bootstrapPage(options) {
|
async bootstrapPage(options) {
|
||||||
this.setData({
|
this.setData({
|
||||||
loading: true
|
loading: true
|
||||||
@@ -263,7 +292,16 @@ Page({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handleSearchFocus(event) {
|
||||||
|
handleKeyboardFocus(this, event)
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSearchBlur() {
|
||||||
|
handleKeyboardBlur(this)
|
||||||
|
},
|
||||||
|
|
||||||
async handleSearchConfirm() {
|
async handleSearchConfirm() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
try {
|
try {
|
||||||
await actionGuard.run(this, 'products:search', async () => {
|
await actionGuard.run(this, 'products:search', async () => {
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -287,6 +325,7 @@ Page({
|
|||||||
|
|
||||||
async handleSelectCategory(event) {
|
async handleSelectCategory(event) {
|
||||||
const category = event.currentTarget.dataset.category
|
const category = event.currentTarget.dataset.category
|
||||||
|
resetKeyboardSafe(this)
|
||||||
try {
|
try {
|
||||||
await actionGuard.run(this, `products:category:${category}`, async () => {
|
await actionGuard.run(this, `products:category:${category}`, async () => {
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -310,6 +349,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async handleResetFilters() {
|
async handleResetFilters() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
try {
|
try {
|
||||||
await actionGuard.run(this, 'products:reset', async () => {
|
await actionGuard.run(this, 'products:reset', async () => {
|
||||||
this.setData({
|
this.setData({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<navigation-bar title="作品库" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
<navigation-bar title="作品库" back="{{false}}" color="#2d2430" background="#fff7f8"></navigation-bar>
|
||||||
|
|
||||||
<view class="page-shell product-page">
|
<view class="page-shell product-page {{keyboardVisible ? 'keyboard-active' : ''}}">
|
||||||
<view class="page-content product-page-content">
|
<view class="page-content product-page-content" style="{{keyboardVisible ? 'padding-bottom: ' + keyboardInsetRpx + 'rpx;' : ''}}">
|
||||||
<view class="sticky-filter-bar">
|
<view class="sticky-filter-bar">
|
||||||
<view class="filter-surface">
|
<view class="filter-surface">
|
||||||
<view class="search-row">
|
<view class="search-row">
|
||||||
@@ -12,6 +12,11 @@
|
|||||||
value="{{searchKeyword}}"
|
value="{{searchKeyword}}"
|
||||||
bindinput="handleSearchInput"
|
bindinput="handleSearchInput"
|
||||||
bindconfirm="handleSearchConfirm"
|
bindconfirm="handleSearchConfirm"
|
||||||
|
bindfocus="handleSearchFocus"
|
||||||
|
bindblur="handleSearchBlur"
|
||||||
|
data-keyboard-anchor="products-search-anchor"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
confirm-type="search"
|
confirm-type="search"
|
||||||
/>
|
/>
|
||||||
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
|
<view class="search-btn" bindtap="handleSearchConfirm">搜索</view>
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ const navigation = require('../../utils/navigation')
|
|||||||
const { DEFAULT_AVATAR } = require('../../utils/config')
|
const { DEFAULT_AVATAR } = require('../../utils/config')
|
||||||
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
|
const { getDraftValue, clearDraft, scheduleDraftSave, clearDraftTimer } = require('../../utils/form-draft')
|
||||||
const { runWithLoading } = require('../../utils/loading')
|
const { runWithLoading } = require('../../utils/loading')
|
||||||
|
const {
|
||||||
|
createKeyboardSafeData,
|
||||||
|
attachKeyboardSafe,
|
||||||
|
detachKeyboardSafe,
|
||||||
|
handleKeyboardFocus,
|
||||||
|
handleKeyboardBlur,
|
||||||
|
resetKeyboardSafe
|
||||||
|
} = require('../../utils/keyboard-safe')
|
||||||
|
|
||||||
const phoneRegex = /^1[3-9]\d{9}$/
|
const phoneRegex = /^1[3-9]\d{9}$/
|
||||||
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
|
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/
|
||||||
@@ -41,7 +49,9 @@ const placeholderEntries = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: Object.assign(createKeyboardSafeData({
|
||||||
|
cursorSpacing: 108
|
||||||
|
}), {
|
||||||
isLoggedIn: false,
|
isLoggedIn: false,
|
||||||
loading: false,
|
loading: false,
|
||||||
savingProfile: false,
|
savingProfile: false,
|
||||||
@@ -72,22 +82,46 @@ Page({
|
|||||||
password: '',
|
password: '',
|
||||||
confirmPassword: ''
|
confirmPassword: ''
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
onLoad() {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
},
|
},
|
||||||
|
|
||||||
onShow() {
|
onShow() {
|
||||||
|
this.ensureKeyboardSafe()
|
||||||
this.loadSettings()
|
this.loadSettings()
|
||||||
},
|
},
|
||||||
|
|
||||||
onHide() {
|
onHide() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
this.clearCountdown()
|
this.clearCountdown()
|
||||||
clearDraftTimer(this)
|
clearDraftTimer(this)
|
||||||
},
|
},
|
||||||
|
|
||||||
onUnload() {
|
onUnload() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
|
detachKeyboardSafe(this)
|
||||||
this.clearCountdown()
|
this.clearCountdown()
|
||||||
clearDraftTimer(this)
|
clearDraftTimer(this)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ensureKeyboardSafe() {
|
||||||
|
attachKeyboardSafe(this, {
|
||||||
|
cursorSpacing: 108,
|
||||||
|
spacerExtraRpx: 48
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
handleKeyboardFocus(event) {
|
||||||
|
handleKeyboardFocus(this, event)
|
||||||
|
},
|
||||||
|
|
||||||
|
handleKeyboardBlur() {
|
||||||
|
handleKeyboardBlur(this)
|
||||||
|
},
|
||||||
|
|
||||||
clearCountdown() {
|
clearCountdown() {
|
||||||
if (this.countdownTimer) {
|
if (this.countdownTimer) {
|
||||||
clearInterval(this.countdownTimer)
|
clearInterval(this.countdownTimer)
|
||||||
@@ -252,6 +286,7 @@ Page({
|
|||||||
handleToggleSecurityPanel(event) {
|
handleToggleSecurityPanel(event) {
|
||||||
const panel = event.currentTarget.dataset.panel
|
const panel = event.currentTarget.dataset.panel
|
||||||
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
|
const nextPanel = this.data.activeSecurityPanel === panel ? '' : panel
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.clearCountdown()
|
this.clearCountdown()
|
||||||
this.resetSecurityForms()
|
this.resetSecurityForms()
|
||||||
this.setData({
|
this.setData({
|
||||||
@@ -262,6 +297,7 @@ Page({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleCloseSecurityPanel() {
|
handleCloseSecurityPanel() {
|
||||||
|
resetKeyboardSafe(this)
|
||||||
this.resetSecurityForms()
|
this.resetSecurityForms()
|
||||||
this.clearCountdown()
|
this.clearCountdown()
|
||||||
this.setData({
|
this.setData({
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
<view class="settings-page-root">
|
<view class="settings-page-root">
|
||||||
<navigation-bar title="设置中心" color="#2d2430" background="#fff7f8" bindback="handleBack"></navigation-bar>
|
<navigation-bar title="设置中心" color="#2d2430" background="#fff7f8" bindback="handleBack"></navigation-bar>
|
||||||
|
|
||||||
<scroll-view class="settings-scroll" scroll-y enable-flex enhanced show-scrollbar="false">
|
<scroll-view
|
||||||
<view class="page-shell settings-page-shell">
|
class="settings-scroll"
|
||||||
|
scroll-y
|
||||||
|
enable-flex
|
||||||
|
enhanced
|
||||||
|
show-scrollbar="false"
|
||||||
|
scroll-with-animation="{{true}}"
|
||||||
|
scroll-into-view="{{keyboardAnchorId}}"
|
||||||
|
>
|
||||||
|
<view class="page-shell settings-page-shell {{keyboardVisible ? 'keyboard-active' : ''}}">
|
||||||
<view class="page-content">
|
<view class="page-content">
|
||||||
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
|
<view wx:if="{{!isLoggedIn}}" class="page-card empty-card">
|
||||||
<text class="empty-title">登录后进入设置中心</text>
|
<text class="empty-title">登录后进入设置中心</text>
|
||||||
@@ -37,14 +45,38 @@
|
|||||||
当前账号未设置登录密码。
|
当前账号未设置登录密码。
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="field-block">
|
<view id="settings-profile-nickname-anchor" class="field-block">
|
||||||
<text class="field-label">昵称</text>
|
<text class="field-label">昵称</text>
|
||||||
<input class="field-input" placeholder="请输入昵称" placeholder-class="field-placeholder" value="{{form.nickname}}" data-field="nickname" bindinput="handleFormInput"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
placeholder="请输入昵称"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.nickname}}"
|
||||||
|
data-field="nickname"
|
||||||
|
data-keyboard-anchor="settings-profile-nickname-anchor"
|
||||||
|
bindinput="handleFormInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="field-block">
|
<view id="settings-profile-signature-anchor" class="field-block">
|
||||||
<text class="field-label">个性签名</text>
|
<text class="field-label">个性签名</text>
|
||||||
<textarea class="field-textarea" placeholder="请输入个性签名" placeholder-class="field-placeholder" value="{{form.signature}}" data-field="signature" bindinput="handleFormInput"></textarea>
|
<textarea
|
||||||
|
class="field-textarea"
|
||||||
|
placeholder="请输入个性签名"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{form.signature}}"
|
||||||
|
data-field="signature"
|
||||||
|
data-keyboard-anchor="settings-profile-signature-anchor"
|
||||||
|
bindinput="handleFormInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></textarea>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="primary-btn save-btn" bindtap="handleSaveProfile">{{savingProfile ? '保存中...' : '保存资料'}}</view>
|
<view class="primary-btn save-btn" bindtap="handleSaveProfile">{{savingProfile ? '保存中...' : '保存资料'}}</view>
|
||||||
@@ -87,14 +119,40 @@
|
|||||||
|
|
||||||
<view wx:if="{{activeSecurityPanel === 'bindPhone'}}" class="security-panel">
|
<view wx:if="{{activeSecurityPanel === 'bindPhone'}}" class="security-panel">
|
||||||
<view class="section-subtitle">输入后完成绑定</view>
|
<view class="section-subtitle">输入后完成绑定</view>
|
||||||
<view class="field-block">
|
<view id="settings-bind-phone-anchor" class="field-block">
|
||||||
<text class="field-label">手机号</text>
|
<text class="field-label">手机号</text>
|
||||||
<input class="field-input" type="number" placeholder="请输入手机号" placeholder-class="field-placeholder" value="{{bindPhoneForm.phone}}" data-field="phone" bindinput="handleBindPhoneInput"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入手机号"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{bindPhoneForm.phone}}"
|
||||||
|
data-field="phone"
|
||||||
|
data-keyboard-anchor="settings-bind-phone-anchor"
|
||||||
|
bindinput="handleBindPhoneInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
<view class="field-block">
|
<view id="settings-bind-phone-code-anchor" class="field-block">
|
||||||
<text class="field-label">验证码</text>
|
<text class="field-label">验证码</text>
|
||||||
<view class="code-row">
|
<view class="code-row">
|
||||||
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{bindPhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleBindPhoneInput"></input>
|
<input
|
||||||
|
class="field-input code-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{bindPhoneForm.verificationCode}}"
|
||||||
|
data-field="verificationCode"
|
||||||
|
data-keyboard-anchor="settings-bind-phone-code-anchor"
|
||||||
|
bindinput="handleBindPhoneInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendBindPhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendBindPhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -110,14 +168,40 @@
|
|||||||
<text class="field-label">当前手机号</text>
|
<text class="field-label">当前手机号</text>
|
||||||
<view class="field-static">{{userInfo.phone}}</view>
|
<view class="field-static">{{userInfo.phone}}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="field-block">
|
<view id="settings-change-phone-anchor" class="field-block">
|
||||||
<text class="field-label">新手机号</text>
|
<text class="field-label">新手机号</text>
|
||||||
<input class="field-input" type="number" placeholder="请输入新的手机号" placeholder-class="field-placeholder" value="{{changePhoneForm.newPhone}}" data-field="newPhone" bindinput="handleChangePhoneInput"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入新的手机号"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{changePhoneForm.newPhone}}"
|
||||||
|
data-field="newPhone"
|
||||||
|
data-keyboard-anchor="settings-change-phone-anchor"
|
||||||
|
bindinput="handleChangePhoneInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
<view class="field-block">
|
<view id="settings-change-phone-code-anchor" class="field-block">
|
||||||
<text class="field-label">验证码</text>
|
<text class="field-label">验证码</text>
|
||||||
<view class="code-row">
|
<view class="code-row">
|
||||||
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{changePhoneForm.verificationCode}}" data-field="verificationCode" bindinput="handleChangePhoneInput"></input>
|
<input
|
||||||
|
class="field-input code-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{changePhoneForm.verificationCode}}"
|
||||||
|
data-field="verificationCode"
|
||||||
|
data-keyboard-anchor="settings-change-phone-code-anchor"
|
||||||
|
bindinput="handleChangePhoneInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendChangePhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendChangePhoneCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -131,20 +215,59 @@
|
|||||||
<view wx:if="{{!userInfo.phone}}" class="hint-card password-hint">请先绑定手机号,再通过验证码设置或修改登录密码。</view>
|
<view wx:if="{{!userInfo.phone}}" class="hint-card password-hint">请先绑定手机号,再通过验证码设置或修改登录密码。</view>
|
||||||
<block wx:else>
|
<block wx:else>
|
||||||
<view class="section-subtitle">密码需包含字母和数字</view>
|
<view class="section-subtitle">密码需包含字母和数字</view>
|
||||||
<view class="field-block">
|
<view id="settings-password-code-anchor" class="field-block">
|
||||||
<text class="field-label">验证码</text>
|
<text class="field-label">验证码</text>
|
||||||
<view class="code-row">
|
<view class="code-row">
|
||||||
<input class="field-input code-input" type="number" placeholder="请输入验证码" placeholder-class="field-placeholder" value="{{passwordForm.verificationCode}}" data-field="verificationCode" bindinput="handlePasswordInput"></input>
|
<input
|
||||||
|
class="field-input code-input"
|
||||||
|
type="number"
|
||||||
|
placeholder="请输入验证码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{passwordForm.verificationCode}}"
|
||||||
|
data-field="verificationCode"
|
||||||
|
data-keyboard-anchor="settings-password-code-anchor"
|
||||||
|
bindinput="handlePasswordInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
<view class="code-btn {{countdown > 0 ? 'disabled' : ''}}" bindtap="handleSendPasswordCode">{{countdown > 0 ? countdown + 's' : '发送验证码'}}</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="field-block">
|
<view id="settings-password-anchor" class="field-block">
|
||||||
<text class="field-label">新密码</text>
|
<text class="field-label">新密码</text>
|
||||||
<input class="field-input" password placeholder="请输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.password}}" data-field="password" bindinput="handlePasswordInput"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请输入新密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{passwordForm.password}}"
|
||||||
|
data-field="password"
|
||||||
|
data-keyboard-anchor="settings-password-anchor"
|
||||||
|
bindinput="handlePasswordInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
<view class="field-block">
|
<view id="settings-password-confirm-anchor" class="field-block">
|
||||||
<text class="field-label">确认密码</text>
|
<text class="field-label">确认密码</text>
|
||||||
<input class="field-input" password placeholder="请再次输入新密码" placeholder-class="field-placeholder" value="{{passwordForm.confirmPassword}}" data-field="confirmPassword" bindinput="handlePasswordInput"></input>
|
<input
|
||||||
|
class="field-input"
|
||||||
|
password
|
||||||
|
placeholder="请再次输入新密码"
|
||||||
|
placeholder-class="field-placeholder"
|
||||||
|
value="{{passwordForm.confirmPassword}}"
|
||||||
|
data-field="confirmPassword"
|
||||||
|
data-keyboard-anchor="settings-password-confirm-anchor"
|
||||||
|
bindinput="handlePasswordInput"
|
||||||
|
bindfocus="handleKeyboardFocus"
|
||||||
|
bindblur="handleKeyboardBlur"
|
||||||
|
adjust-position="false"
|
||||||
|
cursor-spacing="{{keyboardCursorSpacing}}"
|
||||||
|
></input>
|
||||||
</view>
|
</view>
|
||||||
<view class="panel-actions">
|
<view class="panel-actions">
|
||||||
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
|
<view class="secondary-btn panel-btn" bindtap="handleCloseSecurityPanel">取消</view>
|
||||||
@@ -176,6 +299,8 @@
|
|||||||
<view class="logout-btn" bindtap="handleLogout">退出登录</view>
|
<view class="logout-btn" bindtap="handleLogout">退出登录</view>
|
||||||
</block>
|
</block>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<view wx:if="{{keyboardVisible}}" class="keyboard-spacer" style="height: {{keyboardInsetRpx}}rpx;"></view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -14,6 +14,10 @@
|
|||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.settings-page-shell.keyboard-active {
|
||||||
|
padding-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.settings-hero {
|
.settings-hero {
|
||||||
margin-bottom: 20rpx;
|
margin-bottom: 20rpx;
|
||||||
}
|
}
|
||||||
@@ -225,3 +229,8 @@
|
|||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.keyboard-spacer {
|
||||||
|
width: 100%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,243 @@
|
|||||||
|
const DEFAULT_CURSOR_SPACING = 96
|
||||||
|
const DEFAULT_SPACER_EXTRA_RPX = 48
|
||||||
|
const DEFAULT_SCROLL_DELAY = 32
|
||||||
|
const MAX_CURSOR_SPACING = 180
|
||||||
|
|
||||||
|
function getWindowWidth() {
|
||||||
|
try {
|
||||||
|
if (typeof wx.getWindowInfo === 'function') {
|
||||||
|
const info = wx.getWindowInfo()
|
||||||
|
if (info && info.windowWidth) {
|
||||||
|
return info.windowWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const systemInfo = wx.getSystemInfoSync()
|
||||||
|
return (systemInfo && systemInfo.windowWidth) || 375
|
||||||
|
} catch (error) {
|
||||||
|
return 375
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function pxToRpx(px) {
|
||||||
|
return Math.round((Number(px) || 0) * 750 / getWindowWidth())
|
||||||
|
}
|
||||||
|
|
||||||
|
function createKeyboardSafeData(options = {}) {
|
||||||
|
const cursorSpacing = Number(options.cursorSpacing) > 0
|
||||||
|
? Math.round(Number(options.cursorSpacing))
|
||||||
|
: DEFAULT_CURSOR_SPACING
|
||||||
|
|
||||||
|
return {
|
||||||
|
keyboardVisible: false,
|
||||||
|
keyboardHeightPx: 0,
|
||||||
|
keyboardInsetRpx: 0,
|
||||||
|
keyboardAnchorId: '',
|
||||||
|
keyboardCursorSpacing: cursorSpacing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearKeyboardTimers(state) {
|
||||||
|
if (!state) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.anchorTimer) {
|
||||||
|
clearTimeout(state.anchorTimer)
|
||||||
|
state.anchorTimer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.blurTimer) {
|
||||||
|
clearTimeout(state.blurTimer)
|
||||||
|
state.blurTimer = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function queueAnchorScroll(page, anchorId) {
|
||||||
|
const state = page && page.__keyboardSafe
|
||||||
|
if (!page || !state || !anchorId) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.anchorTimer) {
|
||||||
|
clearTimeout(state.anchorTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
const nextDelay = Number(state.options.scrollDelay) || DEFAULT_SCROLL_DELAY
|
||||||
|
const updateAnchor = () => {
|
||||||
|
if (!page.__keyboardSafe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
page.setData({
|
||||||
|
keyboardAnchorId: anchorId
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page.data && page.data.keyboardAnchorId === anchorId) {
|
||||||
|
page.setData({
|
||||||
|
keyboardAnchorId: ''
|
||||||
|
})
|
||||||
|
state.anchorTimer = setTimeout(updateAnchor, nextDelay)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
state.anchorTimer = setTimeout(updateAnchor, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function attachKeyboardSafe(page, options = {}) {
|
||||||
|
if (!page) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
detachKeyboardSafe(page)
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
activeAnchorId: '',
|
||||||
|
anchorTimer: null,
|
||||||
|
blurTimer: null,
|
||||||
|
options: {
|
||||||
|
cursorSpacing: Number(options.cursorSpacing) > 0
|
||||||
|
? Math.round(Number(options.cursorSpacing))
|
||||||
|
: DEFAULT_CURSOR_SPACING,
|
||||||
|
spacerExtraRpx: Number(options.spacerExtraRpx) >= 0
|
||||||
|
? Number(options.spacerExtraRpx)
|
||||||
|
: DEFAULT_SPACER_EXTRA_RPX,
|
||||||
|
scrollDelay: Number(options.scrollDelay) > 0
|
||||||
|
? Number(options.scrollDelay)
|
||||||
|
: DEFAULT_SCROLL_DELAY
|
||||||
|
},
|
||||||
|
listener: null
|
||||||
|
}
|
||||||
|
|
||||||
|
state.listener = result => {
|
||||||
|
const nextHeight = Math.max(0, Number(result && result.height) || 0)
|
||||||
|
const keyboardVisible = nextHeight > 0
|
||||||
|
const keyboardInsetRpx = keyboardVisible
|
||||||
|
? pxToRpx(nextHeight) + state.options.spacerExtraRpx
|
||||||
|
: 0
|
||||||
|
const keyboardCursorSpacing = keyboardVisible
|
||||||
|
? Math.max(
|
||||||
|
state.options.cursorSpacing,
|
||||||
|
Math.min(MAX_CURSOR_SPACING, Math.round(nextHeight * 0.38))
|
||||||
|
)
|
||||||
|
: state.options.cursorSpacing
|
||||||
|
|
||||||
|
page.setData({
|
||||||
|
keyboardVisible,
|
||||||
|
keyboardHeightPx: nextHeight,
|
||||||
|
keyboardInsetRpx,
|
||||||
|
keyboardCursorSpacing,
|
||||||
|
keyboardAnchorId: keyboardVisible ? page.data.keyboardAnchorId : (state.activeAnchorId ? page.data.keyboardAnchorId : '')
|
||||||
|
})
|
||||||
|
|
||||||
|
if (keyboardVisible && state.activeAnchorId) {
|
||||||
|
queueAnchorScroll(page, state.activeAnchorId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
page.__keyboardSafe = state
|
||||||
|
|
||||||
|
if (typeof wx.onKeyboardHeightChange === 'function') {
|
||||||
|
wx.onKeyboardHeightChange(state.listener)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function detachKeyboardSafe(page) {
|
||||||
|
if (!page || !page.__keyboardSafe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = page.__keyboardSafe
|
||||||
|
clearKeyboardTimers(state)
|
||||||
|
|
||||||
|
if (typeof wx.offKeyboardHeightChange === 'function' && state.listener) {
|
||||||
|
try {
|
||||||
|
wx.offKeyboardHeightChange(state.listener)
|
||||||
|
} catch (error) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
delete page.__keyboardSafe
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyboardFocus(page, event) {
|
||||||
|
const state = page && page.__keyboardSafe
|
||||||
|
if (!page || !state) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.blurTimer) {
|
||||||
|
clearTimeout(state.blurTimer)
|
||||||
|
state.blurTimer = null
|
||||||
|
}
|
||||||
|
|
||||||
|
const anchorId = String(
|
||||||
|
event
|
||||||
|
&& event.currentTarget
|
||||||
|
&& event.currentTarget.dataset
|
||||||
|
&& event.currentTarget.dataset.keyboardAnchor
|
||||||
|
? event.currentTarget.dataset.keyboardAnchor
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
|
||||||
|
state.activeAnchorId = anchorId
|
||||||
|
|
||||||
|
if (anchorId) {
|
||||||
|
queueAnchorScroll(page, anchorId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!page.data.keyboardCursorSpacing || page.data.keyboardCursorSpacing < state.options.cursorSpacing) {
|
||||||
|
page.setData({
|
||||||
|
keyboardCursorSpacing: state.options.cursorSpacing
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetKeyboardSafe(page, options = {}) {
|
||||||
|
if (!page) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const state = page.__keyboardSafe
|
||||||
|
if (state) {
|
||||||
|
clearKeyboardTimers(state)
|
||||||
|
if (options.clearActiveAnchor !== false) {
|
||||||
|
state.activeAnchorId = ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallbackCursorSpacing = state ? state.options.cursorSpacing : DEFAULT_CURSOR_SPACING
|
||||||
|
|
||||||
|
page.setData({
|
||||||
|
keyboardVisible: false,
|
||||||
|
keyboardHeightPx: 0,
|
||||||
|
keyboardInsetRpx: 0,
|
||||||
|
keyboardAnchorId: options.keepAnchor ? (page.data.keyboardAnchorId || '') : '',
|
||||||
|
keyboardCursorSpacing: fallbackCursorSpacing
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeyboardBlur(page) {
|
||||||
|
const state = page && page.__keyboardSafe
|
||||||
|
if (!page || !state) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.blurTimer) {
|
||||||
|
clearTimeout(state.blurTimer)
|
||||||
|
}
|
||||||
|
|
||||||
|
state.blurTimer = setTimeout(() => {
|
||||||
|
if (!page.__keyboardSafe) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resetKeyboardSafe(page)
|
||||||
|
}, 120)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createKeyboardSafeData,
|
||||||
|
attachKeyboardSafe,
|
||||||
|
detachKeyboardSafe,
|
||||||
|
handleKeyboardFocus,
|
||||||
|
handleKeyboardBlur,
|
||||||
|
resetKeyboardSafe
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user