refactor: 统一替换小程序事件绑定为@tap并优化跳转逻辑
1. 全局替换@click为@tap以适配uni-app事件规范 2. 优化toLogin方法的路由获取逻辑,增加空值判断 3. 重构redirectTo跳转逻辑,统一tab页跳转使用reLaunch确保页面栈正确
This commit is contained in:
@@ -477,8 +477,13 @@ export default {
|
||||
for (let i = 0; i < systemTabBarList.length; i++) {
|
||||
const tabBarUrl = systemTabBarList[i];
|
||||
if (url.indexOf(tabBarUrl) == 0) {
|
||||
// 首页特殊处理,采用switchTab, 其他页面采用redirectTo, 不能返回,不能退回
|
||||
(tabBarUrl == INDEX_PAGE_URL ? uni.switchTab : uni.redirectTo)({ url });
|
||||
// 首页使用switchTab(pages.json中注册的tabBar页面),其他tab页面使用reLaunch
|
||||
// reLaunch关闭所有页面再打开目标页,确保页面栈与浏览器历史一致,避免返回按钮异常
|
||||
if (tabBarUrl == INDEX_PAGE_URL) {
|
||||
uni.switchTab({ url });
|
||||
} else {
|
||||
uni.reLaunch({ url });
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -499,7 +504,8 @@ export default {
|
||||
if (isDiyTabRoot) {
|
||||
const adaptedUrl = adaptSubpackageUrl(cleanUrl);
|
||||
const inSystemTabBar = systemTabBarList.some(sysUrl => adaptedUrl === sysUrl || cleanUrl === sysUrl);
|
||||
const navApi = inSystemTabBar ? uni.switchTab : uni.redirectTo;
|
||||
// 首页用switchTab,其他DIY tab根页用reLaunch确保页面栈干净
|
||||
const navApi = inSystemTabBar ? (adaptedUrl === INDEX_PAGE_URL ? uni.switchTab : uni.reLaunch) : uni.reLaunch;
|
||||
navApi({
|
||||
url,
|
||||
fail: (err) => {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<view class="head">
|
||||
<text class="title">{{ $lang('components.ns-login.bindMobileTitle') }}</text>
|
||||
<text class="color-tip tips">{{ $lang('components.ns-login.bindMobileTip') }}</text>
|
||||
<text class="iconfont icon-close color-tip" @click="cancelCompleteInfo"></text>
|
||||
<text class="iconfont icon-close color-tip" @tap="cancelCompleteInfo"></text>
|
||||
</view>
|
||||
<view class="item-wrap">
|
||||
<text class="label">{{ $lang('components.ns-login.mobileLabel') }}</text>
|
||||
@@ -18,16 +18,16 @@
|
||||
<view class="item-wrap" v-if="isOpenCaptcha">
|
||||
<text class="label">{{ $lang('components.ns-login.captchaLabel') }}</text>
|
||||
<input type="number" :placeholder="$lang('components.ns-login.captchaPlaceholder')" v-model="formData.vercode" maxlength="4" />
|
||||
<image :src="captcha.img" class="captcha" @click="getCaptcha" show-menu-by-longpress></image>
|
||||
<image :src="captcha.img" class="captcha" @tap="getCaptcha" show-menu-by-longpress></image>
|
||||
</view>
|
||||
<view class="item-wrap">
|
||||
<text class="label">{{ $lang('components.ns-login.dynacodeLabel') }}</text>
|
||||
<input type="number" :placeholder="$lang('components.ns-login.dynacodePlaceholder')" v-model="formData.dynacode" maxlength="4" />
|
||||
<view class="send color-base-text" @click="sendMobileCode">{{ dynacodeData.codeText }}
|
||||
</view>
|
||||
<view class="send color-base-text" @tap="sendMobileCode">{{ dynacodeData.codeText }}
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
<button type="default" class="save-btn" @click="saveH5" :disabled="isDisabled">{{ $lang('components.ns-login.save') }}</button>
|
||||
<button type="default" class="save-btn" @tap="saveH5" :disabled="isDisabled">{{ $lang('components.ns-login.save') }}</button>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifdef MP -->
|
||||
@@ -37,21 +37,21 @@
|
||||
<template>{{ forceBindingMobileControl ? $lang('components.ns-login.loginWithMobile') : $lang('components.ns-login.registerLogin') }}</template>
|
||||
{{ $lang('components.ns-login.getServicesTip') }}
|
||||
</text>
|
||||
<text class="iconfont icon-close color-tip" @click="cancelCompleteInfo"></text>
|
||||
<text class="iconfont icon-close color-tip" @tap="cancelCompleteInfo"></text>
|
||||
</view>
|
||||
|
||||
<!-- 协议勾选 -->
|
||||
<view style="display: flex;">
|
||||
<view class="iconfont"
|
||||
:class="isAgree ? 'icon-fuxuankuang1 color-base-text' : 'icon-fuxuankuang2'"
|
||||
@click="isAgree = !isAgree"></view>
|
||||
<view style="text-align: left; margin-left: 10rpx; padding-top: 2rpx; font-size: 28rpx;">
|
||||
{{ $lang('components.ns-login.agree') }}
|
||||
<text style="color: #4395ff;"
|
||||
@click="tourl('/pages_tool/agreement/contenr?type=0')">{{ $lang('components.ns-login.privacyPolicy') }}</text>
|
||||
<text style="color: #4395ff;"
|
||||
@click="tourl('/pages_tool/agreement/contenr?type=1')">{{ $lang('components.ns-login.userServiceAgreement') }}</text>
|
||||
</view>
|
||||
@tap="isAgree = !isAgree"></view>
|
||||
<view style="text-align: left; margin-left: 10rpx; padding-top: 2rpx; font-size: 28rpx;">
|
||||
{{ $lang('components.ns-login.agree') }}
|
||||
<text style="color: #4395ff;"
|
||||
@tap="tourl('/pages_tool/agreement/contenr?type=0')">{{ $lang('components.ns-login.privacyPolicy') }}</text>
|
||||
<text style="color: #4395ff;"
|
||||
@tap="tourl('/pages_tool/agreement/contenr?type=1')">{{ $lang('components.ns-login.userServiceAgreement') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 手机号授权按钮 -->
|
||||
@@ -62,12 +62,12 @@
|
||||
</button>
|
||||
</block>
|
||||
<block v-else>
|
||||
<button class="auth-login save-btn border-0" style="border: none;" @click="authno">
|
||||
<button class="auth-login save-btn border-0" style="border: none;" @tap="authno">
|
||||
<text style="color: #fff; font-size: 30rpx;">{{ $lang('components.ns-login.authorizeMobile') }}</text>
|
||||
</button>
|
||||
</block>
|
||||
|
||||
<view @click="closeLogin"
|
||||
<view @tap="closeLogin"
|
||||
style="font-size: 30rpx; color: #888; text-align: center; padding-top: 10rpx;">
|
||||
{{ $lang('components.ns-login.notNow') }}
|
||||
</view>
|
||||
@@ -115,7 +115,7 @@
|
||||
<text class="color-base-text" v-else>{{ $lang('components.ns-login.getMobile') }}</text>
|
||||
</button>
|
||||
</view>
|
||||
<button type="default" class="save-btn" @click="saveMp" :disabled="isDisabled">{{ $lang('components.ns-login.save') }}</button>
|
||||
<button type="default" class="save-btn" @tap="saveMp" :disabled="isDisabled">{{ $lang('components.ns-login.save') }}</button>
|
||||
</template>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
|
||||
@@ -52,12 +52,12 @@
|
||||
<swiper autoplay="true" :circular="true" indicator-active-color="#fff"
|
||||
indicator-color="rgba(255,255,255,0.6)" :indicator-dots="true" interval="3000">
|
||||
<swiper-item v-for="(item, index) in adv.list" :key="index">
|
||||
<image class="slide-image" @click="$util.diyRedirectTo(item.link)" height="100%"
|
||||
<image class="slide-image" @tap="$util.diyRedirectTo(item.link)" height="100%"
|
||||
:src="$util.img(item.imageUrl)" width="100%" show-menu-by-longpress></image>
|
||||
<!-- <image bindtap="adverclose" class="slide-image" height="100%" src="{{item.imgurl}}" width="100%" wx:if="{{item.click==1}}" show-menu-by-longpress></image> -->
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view bindtap="adverclose" class="small-bot-close" @click="closePopupWindow">
|
||||
<view class="small-bot-close" @tap="closePopupWindow">
|
||||
<i class="iconfont icon-round-close" style="color:#fff"></i>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
'height': menuButtonBounding.height + 'px'
|
||||
}">
|
||||
<view class="navbar-wrap">
|
||||
<text class="iconfont icon-back_light back" @click="$util.redirectTo($util.MEMBER_PAGE_URL)"></text>
|
||||
<text class="iconfont icon-back_light back" @tap="$util.redirectTo($util.MEMBER_PAGE_URL)"></text>
|
||||
<view class="navbar-title">
|
||||
{{ $lang('member.balance.navbarTitle') }}
|
||||
</view>
|
||||
|
||||
@@ -20,18 +20,18 @@
|
||||
<ns-copyright v-show="isShowCopyRight" />
|
||||
|
||||
<view class="foot">
|
||||
<view class="item" @click="tourl('/pages_tool/agreement/contenr?type=0')">{{
|
||||
<view class="item" @tap="tourl('/pages_tool/agreement/contenr?type=0')">{{
|
||||
$lang('privacyPolicy') }}</view>
|
||||
<view class="item" @click="tourl('/pages_tool/agreement/contenr?type=1')">{{
|
||||
<view class="item" @tap="tourl('/pages_tool/agreement/contenr?type=1')">{{
|
||||
$lang('registrationAgreement') }}</view>
|
||||
</view>
|
||||
|
||||
<!-- 退出登录和账号注销按钮 -->
|
||||
<view class="action-buttons" v-if="storeToken">
|
||||
<view class="action-btn cancel-btn" v-if="isShowCancelButton"
|
||||
@click="cancellation">{{ $lang('cancellation') }}</view>
|
||||
@tap="cancellation">{{ $lang('cancellation') }}</view>
|
||||
<view class="action-btn logout-btn" v-if="isShowLogoutButton"
|
||||
@click="logout">{{ $lang('logout') }}</view>
|
||||
@tap="logout">{{ $lang('logout') }}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -41,9 +41,9 @@
|
||||
<uni-popup ref="uniPopupWindow" type="center" class="wap-floating" :maskClick="false">
|
||||
<view class="image-wrap">
|
||||
<image :src="$util.img(diyData.global.popWindow.imageUrl)" :style="popWindowStyle"
|
||||
@click="uniPopupWindowFn()" mode="aspectFit" show-menu-by-longpress/>
|
||||
@tap="uniPopupWindowFn()" mode="aspectFit" show-menu-by-longpress/>
|
||||
</view>
|
||||
<text class="iconfont icon-round-close" @click="closePopupWindow"></text>
|
||||
<text class="iconfont icon-round-close" @tap="closePopupWindow"></text>
|
||||
</uni-popup>
|
||||
</view>
|
||||
</template>
|
||||
@@ -58,7 +58,7 @@
|
||||
<view v-if="showTip" class="collectPopupWindow"
|
||||
:style="{ marginTop: (collectTop + statusBarHeight) * 2 + 'rpx' }">
|
||||
<image :src="$util.img('public/uniapp/index/collect2.png')" mode="aspectFit" show-menu-by-longpress/>
|
||||
<text @click="closeCollectPopupWindow">我知道了</text>
|
||||
<text @tap="closeCollectPopupWindow">我知道了</text>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}"
|
||||
>
|
||||
<view class="navbar-wrap">
|
||||
<text class="iconfont icon-back_light back" @click="$util.redirectTo($util.MEMBER_PAGE_URL)"></text>
|
||||
<text class="iconfont icon-back_light back" @tap="$util.redirectTo($util.MEMBER_PAGE_URL)"></text>
|
||||
<view class="navbar-title">
|
||||
{{ $lang('member.point.title') }}
|
||||
</view>
|
||||
|
||||
@@ -2,7 +2,9 @@ export default {
|
||||
methods: {
|
||||
// 跳转至登录页
|
||||
toLogin(url) {
|
||||
this.$refs.login.open(url ?? this.$util.getCurrentRoute());
|
||||
const currentRoute = this.$util.getCurrentRoute();
|
||||
const backUrl = url ?? (currentRoute && currentRoute.path ? currentRoute.path : '');
|
||||
this.$refs.login.open(backUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user