解决进入页面无法到底部问题

This commit is contained in:
许允枞 2025-03-14 09:51:29 +08:00
parent 463f26d465
commit b977324bb7
2 changed files with 54 additions and 33 deletions

View File

@ -28,7 +28,8 @@
<view class="right_top"></view> <view class="right_top"></view>
</view> </view>
<!-- 聊天内容 --> <!-- 聊天内容 -->
<scroll-view class="chat" id="scrollview" scroll-y="true" scroll-with-animation="true" :scroll-into-view="scrollToView"> <scroll-view class="chat" id="scrollview" scroll-y="true" scroll-with-animation="true"
:scroll-into-view="scrollToView">
<view class="chat-main" :style="{paddingBottom:inputh+'px'}" id="msglistview"> <view class="chat-main" :style="{paddingBottom:inputh+'px'}" id="msglistview">
<view class="chat-ls" v-for="(item,index) in messagesList" :key="index" :id="'msg'+ index"> <view class="chat-ls" v-for="(item,index) in messagesList" :key="index" :id="'msg'+ index">
<view class="msg-m msg-right" v-if="item.isTrans"> <view class="msg-m msg-right" v-if="item.isTrans">
@ -494,7 +495,11 @@ export default {
} else { } else {
this.messagesList = tempList this.messagesList = tempList
} }
this.goBottom() //
setTimeout(() => {
this.goBottom()
}, 500);
// this.goBottom()
}, },
// //
getMessage() { getMessage() {
@ -528,7 +533,9 @@ export default {
that.$set(that.messagesList, that.messagesList.length - 1, that.messagesList[that.messagesList that.$set(that.messagesList, that.messagesList.length - 1, that.messagesList[that.messagesList
.length - 1]) .length - 1])
// Vue.js Vue.nextTick // Vue.js Vue.nextTick
that.goBottom() setTimeout(() => {
that.goBottom()
}, 500);
} }
get(); get();
@ -698,7 +705,6 @@ export default {
}, },
// //
goBottom() { goBottom() {
this.$nextTick(() => { this.$nextTick(() => {
this.scrollToView = this.scrollId; this.scrollToView = this.scrollId;
this.$nextTick(() => { this.$nextTick(() => {
@ -709,22 +715,22 @@ export default {
}) })
}, },
// //
scrollToBottom(e){ scrollToBottom(e) {
setTimeout(()=>{ setTimeout(() => {
let query = uni.createSelectorQuery().in(this); let query = uni.createSelectorQuery().in(this);
query.select('#scrollview').boundingClientRect(); query.select('#scrollview').boundingClientRect();
query.select('#msglistview').boundingClientRect(); query.select('#msglistview').boundingClientRect();
query.exec((res) =>{ query.exec((res) => {
if(res[1].height > res[0].height){ if (res[1].height > res[0].height) {
this.scrollTop = this.rpxTopx(res[1].height - res[0].height) this.scrollTop = this.rpxTopx(res[1].height - res[0].height)
} }
}) })
},15) }, 15)
}, },
// pxrpx // pxrpx
rpxTopx(px){ rpxTopx(px) {
let deviceWidth = uni.getSystemInfoSync().windowWidth let deviceWidth = uni.getSystemInfoSync().windowWidth
let rpx = ( 750 / deviceWidth ) * Number(px) let rpx = (750 / deviceWidth) * Number(px)
return Math.floor(rpx) return Math.floor(rpx)
}, },
} }

View File

@ -2,28 +2,28 @@
<view class="contact-container"> <view class="contact-container">
<u-card title="Contact Us" class="card"> <u-card title="Contact Us" class="card">
<view class="info"> <view class="info">
<u-icon name="map" size="28" color="#2E7D32" /> <u-icon name="map" size="28" color="#2E7D32"/>
<text class="info-text">123 Main Street, New York, NY 10001</text> <text class="info-text">123 Main Street, New York, NY 10001</text>
</view> </view>
<view class="info"> <view class="info">
<u-icon name="phone" size="28" color="#2E7D32" /> <u-icon name="phone" size="28" color="#2E7D32"/>
<text class="info-text">+1 (123) 456-7890</text> <text class="info-text">+1 (123) 456-7890</text>
</view> </view>
<view class="info"> <view class="info">
<u-icon name="email" size="28" color="#2E7D32" /> <u-icon name="email" size="28" color="#2E7D32"/>
<text class="info-text">contact@company.com</text> <text class="info-text">contact@company.com</text>
</view> </view>
</u-card> </u-card>
<u-form labelPosition="top" :model="form" ref="formRef" class=""> <u-form labelPosition="top" :rules="rules" :model="form" ref="formRef">
<u-form-item label="Name" prop="name" borderBottom> <u-form-item label="Name" prop="name" borderBottom>
<u-input v-model="form.name" placeholder="Enter your name" font-size="18" /> <u-input v-model="form.name" placeholder="Enter your name" font-size="18"/>
</u-form-item> </u-form-item>
<u-form-item label="Email" prop="email" borderBottom> <u-form-item label="Email" prop="email" borderBottom>
<u-input v-model="form.email" placeholder="Enter your email" font-size="18" /> <u-input v-model="form.email" placeholder="Enter your email" font-size="18"/>
</u-form-item> </u-form-item>
<u-form-item label="Message" prop="message" borderBottom> <u-form-item label="Message" prop="message" borderBottom>
<u-textarea v-model="form.message" font-size="18" placeholder="Enter your message" ></u-textarea> <u-textarea v-model="form.message" font-size="18" placeholder="Enter your message"></u-textarea>
</u-form-item> </u-form-item>
<view class="button-container"> <view class="button-container">
<u-button @click="submitForm" class="submit-button" text="Submit"></u-button> <u-button @click="submitForm" class="submit-button" text="Submit"></u-button>
@ -45,7 +45,26 @@ export default {
name: [ name: [
{ {
required: true, required: true,
message: '请输入姓名', message: 'Please enter your name',
trigger: ['blur', 'change']
}
],
email: [
{
required: true,
message: 'Please enter your email address',
trigger: ['blur', 'change']
},
{
pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
message: 'Please enter a valid email address',
trigger: ['blur', 'change']
}
],
message: [
{
required: true,
message: 'Please enter your feedback',
trigger: ['blur', 'change'] trigger: ['blur', 'change']
} }
] ]
@ -55,21 +74,11 @@ export default {
methods: { methods: {
submitForm() { submitForm() {
this.$refs.formRef.validate().then(res => { this.$refs.formRef.validate().then(res => {
uni.$u.toast('校验通过') uni.showToast({title: 'Successfully', icon: 'success'});
this.form = {name: '', email: '', message: ''};
}).catch(errors => { }).catch(errors => {
uni.$u.toast('校验失败') uni.$u.toast('Validation failed')
}) })
if (!this.form.name || !this.form.email || !this.form.message) {
uni.showToast({ title: 'Please fill in all fields', icon: 'none' });
return;
}
//
if (!this.form.email.match(/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/)) {
uni.showToast({ title: 'Invalid email address', icon: 'none' });
return;
}
uni.showToast({ title: 'Successfully', icon: 'success' });
this.form = { name: '', email: '', message: '' };
} }
} }
}; };
@ -86,6 +95,7 @@ export default {
font-size: 20rpx; font-size: 20rpx;
background-color: #FFFFFF; background-color: #FFFFFF;
} }
.card { .card {
width: 90%; width: 90%;
padding: 30rpx; padding: 30rpx;
@ -94,6 +104,7 @@ export default {
color: #FFFFFF; color: #FFFFFF;
border-radius: 20rpx; border-radius: 20rpx;
} }
.info { .info {
display: flex; display: flex;
align-items: center; align-items: center;
@ -101,11 +112,13 @@ export default {
margin-bottom: 20rpx; margin-bottom: 20rpx;
color: #FFFFFF; color: #FFFFFF;
} }
.info-text { .info-text {
margin-left: 15rpx; margin-left: 15rpx;
font-size: 22rpx; font-size: 22rpx;
color: #FFFFFF; color: #FFFFFF;
} }
.form-container { .form-container {
width: 90%; width: 90%;
//display: flex; //display: flex;
@ -113,12 +126,14 @@ export default {
align-items: center; align-items: center;
font-size: 22rpx; font-size: 22rpx;
} }
.button-container { .button-container {
display: flex; display: flex;
justify-content: center; justify-content: center;
width: 100%; width: 100%;
margin-top: 20rpx; margin-top: 20rpx;
} }
.submit-button { .submit-button {
font-size: 22rpx; font-size: 22rpx;
padding: 15rpx 30rpx; padding: 15rpx 30rpx;