feat:添加按钮显示 + 触发切换逻辑

This commit is contained in:
Zhukj
2025-12-18 17:03:40 +08:00
parent 123daa600c
commit 5b37e00b98
6 changed files with 234 additions and 124 deletions

View File

@@ -128,6 +128,11 @@
<!-- #endif -->
<to-top v-if="showTop" @toTop="scrollToTopNative()"></to-top>
<ns-login ref="login"></ns-login>
<!-- 👇 新增语言切换按钮 -->
<view class="lang-switch-wrap" @click="toggleLang">
<text class="lang-text">{{ $lang('common.langSwitchBtn') }}</text>
</view>
</view>
</template>
@@ -138,7 +143,8 @@
import indexJs from './public/js/index.js';
import toTop from '@/components/toTop/toTop.vue';
import scroll from '@/common/js/scroll-view.js';
// 👇 引入语言工具文件
import langUtil from '@/common/js/lang.js';
export default {
components: {
@@ -146,7 +152,15 @@
nsNavbar,
toTop
},
mixins: [diyJs, scroll, indexJs]
mixins: [diyJs, scroll, indexJs],
methods: {
// 👇 新增:语言切换方法
toggleLang() {
const currentLang = this.$lang?.locale || 'zh-cn';
const targetLang = currentLang === 'zh-cn' ? 'en-us' : 'zh-cn';
langUtil.change(targetLang);
}
}
};
</script>
@@ -229,8 +243,33 @@
}
/deep/ .mescroll-totop {
right: 24rpx!important;
bottom: 182rpx!important;
right: 24rpx !important;
bottom: 182rpx !important;
}
/* 👇 新增:语言切换按钮样式 */
.lang-switch-wrap {
position: fixed !important;
bottom: 120rpx !important; /* 避开底部tabBar */
right: 30rpx !important;
z-index: 99999 !important; /* 层级拉满 */
width: 120rpx;
height: 60rpx;
background-color: #ffffff !important;
border: 1px solid #e5e5e5 !important;
border-radius: 30rpx !important;
display: flex !important;
align-items: center !important;
justify-content: center !important;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1) !important;
}
.lang-text {
font-size: 28rpx !important;
color: #333333 !important;
font-weight: 500 !important;
}
.lang-switch-wrap:active {
transform: scale(0.95) !important;
transition: transform 0.1s ease !important;
}
</style>