feat: 增加navbar,fab组件

master
xjs 2025-03-08 10:18:14 +08:00
parent c3b1d6e40c
commit 790fdf4114
9 changed files with 535 additions and 39 deletions

View File

@ -6,11 +6,7 @@
@touchend.stop="endDrag" @touchend.stop="endDrag"
:style="{ right: position.x + 'px', bottom: position.y + 'px' }" :style="{ right: position.x + 'px', bottom: position.y + 'px' }"
> >
<image <image class="w-full h-full rounded-full" src="/static/images/home/customerService.svg"></image>
@click="handleClick"
class="w-full h-full rounded-full"
src="/static/images/home/customerService.svg"
></image>
</view> </view>
</template> </template>
@ -31,19 +27,62 @@ const props = defineProps({
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getSystemInfoSync()
const position = ref({ x: props.initialX, y: props.initialY }) const position = ref({ x: props.initialX, y: props.initialY })
const startPosition = ref({ x: 0, y: 0 }) const startPosition = ref({ x: 0, y: 0 })
const startTime = ref(0)
const longPressTimer = ref<number | null>(null)
const canDrag = ref(false)
const moveDistance = ref(0)
const startDrag = (event: TouchEvent) => { const startDrag = (event: TouchEvent) => {
startPosition.value = { x: event.touches[0].clientX, y: event.touches[0].clientY } startPosition.value = { x: event.touches[0].clientX, y: event.touches[0].clientY }
startTime.value = Date.now()
canDrag.value = false
moveDistance.value = 0
// 300ms
longPressTimer.value = setTimeout(() => {
if (!canDrag.value) {
canDrag.value = true
}
}, 300) as unknown as number
} }
const onDrag = (event: TouchEvent) => { const onDrag = (event: TouchEvent) => {
const deltaX = event.touches[0].clientX - startPosition.value.x const deltaX = event.touches[0].clientX - startPosition.value.x
const deltaY = event.touches[0].clientY - startPosition.value.y const deltaY = event.touches[0].clientY - startPosition.value.y
//
moveDistance.value = Math.sqrt(deltaX * deltaX + deltaY * deltaY)
//
if (moveDistance.value > 10 && !canDrag.value) {
canDrag.value = true
if (longPressTimer.value) {
clearTimeout(longPressTimer.value)
longPressTimer.value = null
}
}
if (!canDrag.value) return
position.value = { x: position.value.x - deltaX, y: position.value.y - deltaY } position.value = { x: position.value.x - deltaX, y: position.value.y - deltaY }
startPosition.value = { x: event.touches[0].clientX, y: event.touches[0].clientY } startPosition.value = { x: event.touches[0].clientX, y: event.touches[0].clientY }
} }
const endDrag = () => { const endDrag = () => {
//
if (longPressTimer.value) {
clearTimeout(longPressTimer.value)
longPressTimer.value = null
}
// 300ms
if (!canDrag.value && moveDistance.value < 10 && Date.now() - startTime.value < 300) {
handleClick()
return
}
//
if (canDrag.value) {
const windowWidth = systemInfo.windowWidth const windowWidth = systemInfo.windowWidth
const windowHeight = systemInfo.windowHeight const windowHeight = systemInfo.windowHeight
const buttonWidth = 128 // const buttonWidth = 128 //
@ -52,7 +91,9 @@ const endDrag = () => {
if (position.value.x < 0) position.value.x = 0 if (position.value.x < 0) position.value.x = 0
if (position.value.y < 0) position.value.y = 0 if (position.value.y < 0) position.value.y = 0
if (position.value.x + buttonWidth > windowWidth) position.value.x = windowWidth - buttonWidth if (position.value.x + buttonWidth > windowWidth) position.value.x = windowWidth - buttonWidth
if (position.value.y + buttonHeight > windowHeight) position.value.y = windowHeight - buttonHeight if (position.value.y + buttonHeight > windowHeight)
position.value.y = windowHeight - buttonHeight
}
} }
const handleClick = () => { const handleClick = () => {

View File

@ -1,7 +1,8 @@
<template> <template>
<wd-overlay :show="show"> <Overlay :show="show" @update:show="handleClose">
<view <view
class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center bg-white p-[40rpx] rounded-[32rpx]" class="fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center bg-white p-[40rpx] rounded-[32rpx]"
@click.stop
> >
<image <image
class="w-[200rpx] h-[200rpx]" class="w-[200rpx] h-[200rpx]"
@ -12,15 +13,16 @@
<text class="text-[26rpx] mt-[20rpx] mb-[40rpx]" :selectable="false"> <text class="text-[26rpx] mt-[20rpx] mb-[40rpx]" :selectable="false">
{{ phone ? '申请使用您的手机号' : '申请获取您的个人信息' }} {{ phone ? '申请使用您的手机号' : '申请获取您的个人信息' }}
</text> </text>
<wd-button <button
size="large" class="w-[493rpx] mb-[40rpx] h-[88rpx] rounded-[44rpx] text-[32rpx] text-white"
custom-class="w-[493rpx] mb-[40rpx]" :class="checked ? 'bg-[#1580FF]' : 'bg-[#BFBFBF]'"
@click.stop="handleClick" @click.stop="handleClick"
open-type="getPhoneNumber" open-type="getPhoneNumber"
@getphonenumber="getPhoneNumber" @getphonenumber="getPhoneNumber"
:disabled="!checked"
> >
手机号快捷登录 手机号快捷登录
</wd-button> </button>
<view class="flex items-center flex-nowrap" @click.stop="checked = true"> <view class="flex items-center flex-nowrap" @click.stop="checked = true">
<wd-radio-group v-model="checked" custom-class="mr-10rpx"> <wd-radio-group v-model="checked" custom-class="mr-10rpx">
@ -31,14 +33,13 @@
</view> </view>
</view> </view>
</view> </view>
<wd-toast />
</view> </view>
</wd-overlay> </Overlay>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useToast } from 'wot-design-uni'
import { useLogin } from '@/login-sub/hooks/useUserInfo' import { useLogin } from '@/login-sub/hooks/useUserInfo'
import Overlay from './Overlay.vue'
import { import {
getSessionKey, getSessionKey,
getVolunteerInitialization, getVolunteerInitialization,
@ -62,7 +63,6 @@ defineOptions({
const emits = defineEmits(['update:show', 'authReady']) const emits = defineEmits(['update:show', 'authReady'])
const toast = useToast()
const userStore = useUserStore() const userStore = useUserStore()
const handleClose = () => { const handleClose = () => {
@ -74,24 +74,35 @@ const checked = ref(false) // 是否同意条款
const getPhoneInfo = ref(null) const getPhoneInfo = ref(null)
const getPhoneNumber = async (e: any) => { const getPhoneNumber = async (e: any) => {
if (e.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
const detail = e.detail
let _getPhoneInfo = { let _getPhoneInfo = {
iv: e.iv, iv: detail.iv,
encryptedData: e.encryptedData, encryptedData: detail.encryptedData,
code: e.code, code: detail.code,
} }
getPhoneInfo.value = _getPhoneInfo getPhoneInfo.value = _getPhoneInfo
await getUserInfo(e.code) await getUserInfo(detail.code)
} else if (e.errMsg == 'getPhoneNumber:fail not login') { } else if (e.detail.errMsg == 'getPhoneNumber:fail not login') {
toast.warning('请先登录') uni.showToast({
title: '请先登录',
icon: 'none',
})
} else { } else {
toast.warning('获取手机号失败') uni.showToast({
title: '获取手机号失败',
icon: 'none',
})
} }
} }
const handleClick = () => { const handleClick = () => {
if (!checked.value) { if (!checked.value) {
toast.warning('您需先同意《服务条款》和《隐私条款》') uni.showToast({
title: '您需先同意《服务条款》和《隐私条款》',
icon: 'none',
})
return
} }
} }
@ -135,7 +146,10 @@ const getUserInfo = async (code: string) => {
}) })
} }
} else { } else {
toast.warning('您需先授权') uni.showToast({
title: '您需先授权',
icon: 'none',
})
} }
} }
</script> </script>

View File

@ -0,0 +1,54 @@
<template>
<view
v-if="show"
class="overlay"
:class="{ 'overlay-show': show }"
@click="handleClick"
:style="{ zIndex }"
>
<slot></slot>
</view>
</template>
<script lang="ts" setup>
const props = defineProps({
show: {
type: Boolean,
default: false,
},
zIndex: {
type: Number,
default: 10,
},
closeOnClickOverlay: {
type: Boolean,
default: true,
},
})
const emit = defineEmits(['click', 'update:show'])
const handleClick = (event: Event) => {
emit('click', event)
if (props.closeOnClickOverlay) {
emit('update:show', false)
}
}
</script>
<style scoped>
.overlay {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.7);
transition: all 0.3s ease;
}
.overlay-show {
opacity: 1;
visibility: visible;
}
</style>

View File

@ -0,0 +1,190 @@
<template>
<view class="navbar">
<!-- 状态栏占位 -->
<view
v-if="safeAreaInsetTop"
class="status-bar"
:style="{ height: statusBarHeight + 'px', backgroundColor: bgColor }"
></view>
<!-- 导航栏主体 -->
<view
class="navbar-content"
:class="{
'navbar-fixed': fixed,
'navbar-border': bordered,
}"
:style="{
backgroundColor: bgColor,
height: navHeight + 'px',
top: fixed ? (safeAreaInsetTop ? statusBarHeight : 0) + 'px' : '0',
}"
>
<!-- 左侧区域 -->
<view class="navbar-left" @click="handleClickLeft">
<view v-if="leftArrow" class="back-icon">
<image src="./left.jpg" mode="aspectFit" class="w-[48rpx] h-[48rpx]" />
</view>
<slot name="left"></slot>
</view>
<!-- 中间标题区域 -->
<view class="navbar-title">
<slot name="title">
<text class="title-text">{{ title }}</text>
</slot>
</view>
<!-- 右侧区域 -->
<view class="navbar-right">
<slot name="right"></slot>
</view>
</view>
<!-- 占位元素 -->
<view
v-if="placeholder && fixed"
:style="{
height: `${navHeight}px`,
backgroundColor: bgColor,
}"
></view>
</view>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
const props = defineProps({
title: {
type: String,
default: '',
},
leftArrow: {
type: Boolean,
default: false,
},
fixed: {
type: Boolean,
default: false,
},
placeholder: {
type: Boolean,
default: false,
},
bordered: {
type: Boolean,
default: true,
},
safeAreaInsetTop: {
type: Boolean,
default: true,
},
bgColor: {
type: String,
default: '#ffffff',
},
})
const emit = defineEmits(['clickLeft'])
//
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
//
const navHeight = computed(() => {
//
const { platform, screenWidth } = systemInfo
// pxrpx
const ratio = 750 / screenWidth
//
if (platform === 'ios') {
return 88 / ratio // iOS 44ptpx
} else if (platform === 'android') {
return 96 / ratio // Android 48dppx
} else {
return 88 / ratio //
}
})
const handleClickLeft = () => {
emit('clickLeft')
}
</script>
<style scoped>
.navbar {
width: 100%;
}
.status-bar {
width: 100%;
background-color: inherit;
}
.navbar-content {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
box-sizing: border-box;
background-color: #fff;
}
.navbar-fixed {
position: fixed;
left: 0;
width: 100%;
z-index: 99;
}
.navbar-border {
border-bottom: 1rpx solid #eee;
}
.navbar-left {
display: flex;
align-items: center;
min-width: 100rpx;
height: 100%;
}
.back-icon {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.navbar-title {
flex: 1;
text-align: center;
padding: 0 100rpx;
overflow: hidden;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.title-text {
font-size: 32rpx;
color: #333;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.navbar-right {
display: flex;
align-items: center;
min-width: 100rpx;
justify-content: flex-end;
height: 100%;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -9,11 +9,17 @@
<template> <template>
<view class="h-screen flex flex-col"> <view class="h-screen flex flex-col">
<wd-navbar safeAreaInsetTop custom-class="bg-transparent!" :bordered="false" fixed> <Navbar
safeAreaInsetTop
:bordered="false"
:fixed="true"
:placeholder="true"
bgColor="transparent"
>
<template #title> <template #title>
<text class="text-[#1F2329] text-[36rpx] font-medium">新高考选科</text> <text class="text-[#1F2329] text-[36rpx] font-medium">新高考选科</text>
</template> </template>
</wd-navbar> </Navbar>
<view class="flex flex-col justify-center items-center flex-1 pb-safe"> <view class="flex flex-col justify-center items-center flex-1 pb-safe">
<image <image
class="w-[424rpx] h-[424rpx]" class="w-[424rpx] h-[424rpx]"
@ -33,6 +39,8 @@
<script setup lang="ts"> <script setup lang="ts">
import LoginMask from './components/LoginMask.vue' import LoginMask from './components/LoginMask.vue'
import Navbar from './components/navbar/Navbar.vue'
const show = ref(false) const show = ref(false)
const handleLogin = () => { const handleLogin = () => {

View File

@ -0,0 +1,190 @@
<template>
<view class="navbar">
<!-- 状态栏占位 -->
<view
v-if="safeAreaInsetTop"
class="status-bar"
:style="{ height: statusBarHeight + 'px', backgroundColor: bgColor }"
></view>
<!-- 导航栏主体 -->
<view
class="navbar-content"
:class="{
'navbar-fixed': fixed,
'navbar-border': bordered,
}"
:style="{
backgroundColor: bgColor,
height: navHeight + 'px',
top: fixed ? (safeAreaInsetTop ? statusBarHeight : 0) + 'px' : '0',
}"
>
<!-- 左侧区域 -->
<view class="navbar-left" @click="handleClickLeft">
<view v-if="leftArrow" class="back-icon">
<image src="./left.jpg" mode="aspectFit" class="w-[48rpx] h-[48rpx]" />
</view>
<slot name="left"></slot>
</view>
<!-- 中间标题区域 -->
<view class="navbar-title">
<slot name="title">
<text class="title-text">{{ title }}</text>
</slot>
</view>
<!-- 右侧区域 -->
<view class="navbar-right">
<slot name="right"></slot>
</view>
</view>
<!-- 占位元素 -->
<view
v-if="placeholder && fixed"
:style="{
height: `${navHeight}px`,
backgroundColor: bgColor,
}"
></view>
</view>
</template>
<script lang="ts" setup>
import { computed } from 'vue'
const props = defineProps({
title: {
type: String,
default: '',
},
leftArrow: {
type: Boolean,
default: false,
},
fixed: {
type: Boolean,
default: false,
},
placeholder: {
type: Boolean,
default: false,
},
bordered: {
type: Boolean,
default: true,
},
safeAreaInsetTop: {
type: Boolean,
default: true,
},
bgColor: {
type: String,
default: '#ffffff',
},
})
const emit = defineEmits(['clickLeft'])
//
const systemInfo = uni.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
//
const navHeight = computed(() => {
//
const { platform, screenWidth } = systemInfo
// pxrpx
const ratio = 750 / screenWidth
//
if (platform === 'ios') {
return 88 / ratio // iOS 44ptpx
} else if (platform === 'android') {
return 96 / ratio // Android 48dppx
} else {
return 88 / ratio //
}
})
const handleClickLeft = () => {
emit('clickLeft')
}
</script>
<style scoped>
.navbar {
width: 100%;
}
.status-bar {
width: 100%;
background-color: inherit;
}
.navbar-content {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
box-sizing: border-box;
background-color: #fff;
}
.navbar-fixed {
position: fixed;
left: 0;
width: 100%;
z-index: 99;
}
.navbar-border {
border-bottom: 1rpx solid #eee;
}
.navbar-left {
display: flex;
align-items: center;
min-width: 100rpx;
height: 100%;
}
.back-icon {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
}
.navbar-title {
flex: 1;
text-align: center;
padding: 0 100rpx;
overflow: hidden;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.title-text {
font-size: 32rpx;
color: #333;
font-weight: 500;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.navbar-right {
display: flex;
align-items: center;
min-width: 100rpx;
justify-content: flex-end;
height: 100%;
}
</style>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -9,14 +9,11 @@
<template> <template>
<view class="bg-[#fff] h-[100vh] flex flex-col"> <view class="bg-[#fff] h-[100vh] flex flex-col">
<wd-navbar safeAreaInsetTop custom-class="bg-transparent!" :bordered="false"> <Navbar safeAreaInsetTop :bordered="false" title="在线客服" leftArrow @clickLeft="handleBack">
<template #title> <template #title>
<text class="text-[#1F2329] text-[36rpx] font-medium">在线客服</text> <text class="text-[#1F2329] text-[36rpx] font-medium">在线客服</text>
</template> </template>
<template #left> </Navbar>
<wd-icon name="thin-arrow-left" custom-style="icon-style" @click="handleBack"></wd-icon>
</template>
</wd-navbar>
<view class="flex-1 bg-[#F8F8F8] px-[32rpx] pb-safe"> <view class="flex-1 bg-[#F8F8F8] px-[32rpx] pb-safe">
<view class="mt-[84rpx] h-[754rpx] radius-[16rpx] bg-[#fff]"> <view class="mt-[84rpx] h-[754rpx] radius-[16rpx] bg-[#fff]">
@ -62,6 +59,8 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import Navbar from '@/pages-sub/components/navbar/Navbar.vue'
const makePhoneCall = () => { const makePhoneCall = () => {
uni uni
.makePhoneCall({ .makePhoneCall({