滚动加载样式

master
2022-12-28 18:31:26 +08:00
parent 84d3dd247d
commit 779f6e4fa1
5 changed files with 281 additions and 175 deletions

View File

@ -28,6 +28,8 @@ export default {
this.Handler = new Date().getTime() - this.beforeUnload; this.Handler = new Date().getTime() - this.beforeUnload;
if (this.Handler <= 5) { if (this.Handler <= 5) {
localStorage.setItem('btnHide', 1) localStorage.setItem('btnHide', 1)
var storage = window.localStorage;
storage.clear()
} }
}, },
}, },

View File

@ -1,12 +1,10 @@
<template> <template>
<el-tabs v-model="activeName" @tab-click="handleClick" type="card"> <el-tabs v-model="activeName" @tab-click="handleClick" type="card" :stretch=true>
<el-tab-pane :label="toUser.storeFlag ? '正在咨询' : '他的足迹'" name="history"> <el-tab-pane :label="toUser.storeFlag ? '正在咨询' : '他的足迹'" name="history">
<div style="margin-left: 12px;" v-if="toUser.storeFlag"> <div style="margin-left: 12px;" v-if="toUser.storeFlag">
<GoodsLink :goodsDetail="goodsDetail" v-if="toUser.userId === goodsDetail.storeId" /> <GoodsLink :goodsDetail="goodsDetail" v-if="toUser.userId === goodsDetail.storeId"
<FootPrint :list="footPrintList" @loadMore="loadMoreFootPrint()" /> @sendMessage="submitSendMessage" />
</div> <FootPrint :list="footPrintList" @loadMore="loadMoreFootPrint()" @sendMessage="submitSendMessage" />
<div v-else>
</div> </div>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="店铺信息" name="UserInfo" v-if="toUser.storeFlag"> <el-tab-pane label="店铺信息" name="UserInfo" v-if="toUser.storeFlag">
@ -24,6 +22,8 @@ import { ServeGetGoodsDetail } from '@/api/goods'
import StoreDetail from "@/components/chat/panel/template/storeDetail.vue"; import StoreDetail from "@/components/chat/panel/template/storeDetail.vue";
import FootPrint from "@/components/chat/panel/template/footPrint.vue"; import FootPrint from "@/components/chat/panel/template/footPrint.vue";
import GoodsLink from "@/components/chat/panel/template/goodsLink.vue"; import GoodsLink from "@/components/chat/panel/template/goodsLink.vue";
import SocketInstance from "@/im-server/socket-instance";
import { mapState, mapGetters } from "vuex";
export default { export default {
components: { components: {
"el-tabs": Tabs, "el-tabs": Tabs,
@ -46,6 +46,12 @@ export default {
default: null, default: null,
}, },
}, },
computed: {
...mapGetters(["talkItems"]),
...mapState({
index_name: (state) => state.dialogue.index_name,
}),
},
data () { data () {
return { return {
activeName: 'history', activeName: 'history',
@ -112,6 +118,11 @@ export default {
} }
ServeGetFootPrint(this.footPrintParams).then(res => { ServeGetFootPrint(this.footPrintParams).then(res => {
res.result.records.forEach((item, index) => { res.result.records.forEach((item, index) => {
if (localStorage.getItem(item.goodsId)) {
item.btnHide = 0
} else {
item.btnHide = 1
}
if (item.goodsId === this.goodsParams.goodsId) { if (item.goodsId === this.goodsParams.goodsId) {
res.result.records.splice(index, 1) res.result.records.splice(index, 1)
} }
@ -121,12 +132,85 @@ export default {
}) })
// //
}, },
//
submitSendMessage (record, context) {
console.log("发送");
SocketInstance.emit("event_talk", record);
this.$store.commit("UPDATE_TALK_ITEM", {
index_name: this.index_name,
draft_text: "",
});
/**
* 插入数据
*/
const insterChat = {
createTime: this.formateDateAndTimeToString(new Date()),
fromUser: this.id,
toUser: record.to,
isRead: false,
messageType: "GOODS",
text: context,
float: "right",
};
console.log("insterChat", insterChat);
// console.log("",'')
//
this.$store.commit("PUSH_DIALOGUE", insterChat);
//
let el = document.getElementById("lumenChatPanel");
//
let isBottom =
Math.ceil(el.scrollTop) + el.clientHeight >= el.scrollHeight;
if (isBottom || record.to == this.id) {
this.$nextTick(() => {
el.scrollTop = el.scrollHeight;
});
} else {
this.$store.commit("SET_TLAK_UNREAD_MESSAGE", {
content: content,
nickname: record.name,
});
}
},
formateDateAndTimeToString (date) {
var hours = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var msecs = date.getMilliseconds();
if (hours < 10) hours = "0" + hours;
if (mins < 10) mins = "0" + mins;
if (secs < 10) secs = "0" + secs;
if (msecs < 10) secs = "0" + msecs;
return (
this.formatDateToString(date) + " " + hours + ":" + mins + ":" + secs
);
},
formatDateToString (date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
return year + "-" + month + "-" + day;
},
} }
} }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
// /deep/ .el-tabs__nav.is-top {
// }
/deep/ .el-tabs__nav { /deep/ .el-tabs__nav {
height: 60px; height: 60px;
line-height: 60px; line-height: 60px;

View File

@ -68,7 +68,7 @@
<pre v-html="item.text" /> <pre v-html="item.text" />
</div> </div>
<div v-else-if="item.messageType == 'GOODS'" class="text-message" :class="{ <div v-else-if="item.messageType == 'GOODS' && item.text != null" class="text-message" :class="{
left: item.float == 'left', left: item.float == 'left',
right: item.float == 'right', right: item.float == 'right',
}"> }">
@ -869,6 +869,7 @@ export default {
color: black; color: black;
} }
} }
.base { .base {
margin-top: 5px; margin-top: 5px;
height: 120px; height: 120px;
@ -889,6 +890,7 @@ export default {
} }
} }
.talk-bubble { .talk-bubble {
position: absolute; position: absolute;
left: 0px; left: 0px;

View File

@ -1,39 +1,79 @@
<template> <template>
<div class="box" @scroll="scrollBottom"> <div class="box" @scroll="scrollBottom">
<div class="tab"> <div class="tab">
<el-tabs v-model="activeName" @tab-click="handleClick"> <el-tabs v-model="activeName" @tab-click="handleClick" :stretch=true>
<el-tab-pane label="最近浏览" name="first"></el-tab-pane> <el-tab-pane label="最近浏览" name="goods">
</el-tabs>
</div>
<dl> <dl>
<dd v-for="item in list" v-infinite-scroll="loadMore"> <dd v-for="item in list" v-infinite-scroll="loadMore">
<div class="base" @click="linkToGoods(item.goodsId, item.id)"> <div class="base">
<div> <div>
<img :src="item.thumbnail" class="image" /> <img :src="item.thumbnail" class="image" />
</div> </div>
<div style="margin-left: 13px"> <div style="margin-left: 13px">
<a>{{ item.goodsName }}</a> <a class="goods_name" @click="linkToGoods(item.goodsId, item.id)">{{ item.goodsName }}</a>
<div> <div style="margin-top: 8px;">
<span style="color: red;">{{ item.price }}</span> <span style="color: red;">{{ item.price }}</span>
</div> </div>
<div>
<el-button class="store-button" type="danger" v-if="item.btnHide == 1" size="mini"
@click="submitSendGoodsMessage(item)" plain>发送</el-button>
</div>
</div> </div>
</div> </div>
</dd> </dd>
</dl> </dl>
</el-tab-pane>
<el-tab-pane label="订单列表" name="orders">
<dl>
<dd v-for="item in list" v-infinite-scroll="loadMore">
<div class="base">
<div>
<img :src="item.thumbnail" class="image" />
</div>
<div style="margin-left: 13px">
<a class="goods_name" @click="linkToGoods(item.goodsId, item.id)">{{ item.goodsName }}</a>
<div style="margin-top: 10px;">
<span style="color: red;">{{ item.price }}</span>
</div>
<div>
<el-button class="store-button" type="danger" v-if="item.btnHide == 1" size="mini"
@click="submitSendGoodsMessage(item)" plain>发送</el-button>
</div>
</div>
</div>
</dd>
</dl>
</el-tab-pane>
</el-tabs>
</div>
</div> </div>
</template> </template>
<script> <script>
import { Tag, button, Tabs, TabPane, InfiniteScroll } from 'element-ui' import { Tag, button, Tabs, TabPane, InfiniteScroll } from 'element-ui'
import { mapState, mapGetters } from "vuex";
export default { export default {
directives: { directives: {
"infinite-scroll": InfiniteScroll, "infinite-scroll": InfiniteScroll,
}, },
data () { data () {
return { return {
activeName: 'first' activeName: 'goods',
btnHide: undefined,
hide: true
} }
}, },
computed: {
...mapGetters(["talkItems"]),
...mapState({
id: (state) => state.user.id,
toUser: (state) => state.user.toUser,
}),
},
components: { components: {
"el-tag": Tag, "el-tag": Tag,
"el-button": button, "el-button": button,
@ -41,15 +81,37 @@ export default {
"el-tab-pane": TabPane, "el-tab-pane": TabPane,
}, },
methods: { methods: {
scrollBottom (e) { scrollBottom (e) {
const { scrollTop, scrollHeight, clientHeight } = e.srcElement const { scrollTop, scrollHeight, clientHeight } = e.srcElement
if (scrollTop + clientHeight >= scrollHeight) { if (scrollTop + clientHeight >= scrollHeight) {
if (this.noMore) return
this.$emit('loadMore') this.$emit('loadMore')
} }
}, },
loadMore () { loadMore () {
},
//
submitSendGoodsMessage (item) {
console.log("发送");
const context = {
id: item.id,
goodsId: item.goodsId,
thumbnail: item.thumbnail,
price: item.price,
goodsName: item.goodsName
}
const record = {
operation_type: "MESSAGE",
to: this.toUser.userId,
from: this.id,
message_type: "GOODS",
context: context,
talk_id: this.toUser.id,
};
this.$emit('sendMessage', record, context);
localStorage.setItem(item.goodsId, 0)
item.btnHide = 0
}, },
handleClick (tab, event) { handleClick (tab, event) {
console.log(tab, event); console.log(tab, event);
@ -63,12 +125,24 @@ export default {
}, },
mounted () { mounted () {
console.log(this.list, 'list'); console.log(this.list, 'list');
this.btnHide = localStorage.getItem('btnHide')
} }
} }
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
.goods_name {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
}
/deep/ .el-tabs__item.is-top:last-child { /deep/ .el-tabs__item.is-top:last-child {
color: black; color: black;
} }
@ -96,6 +170,7 @@ export default {
.store-button { .store-button {
background-color: white; background-color: white;
border-color: #F56C6C; border-color: #F56C6C;
} }
.base { .base {
@ -104,17 +179,18 @@ export default {
display: flex; display: flex;
div { div {
overflow: hidden; // overflow: hidden;
text-overflow: ellipsis; // text-overflow: ellipsis;
margin-top: 8px; // white-space: nowrap;
white-space: nowrap; // margin-top: 8px;
margin-top: 4px; //
// margin-top: 4px;
} }
.image { .image {
height: 100px; height: 100px;
margin-top: 3px; margin-top: 3px;
width: 100px width: 100px;
} }
} }

View File

@ -1,6 +1,5 @@
<template> <template>
<div style="width: 350px;"> <div style="width: 350px;">
当前浏览
<div class="base"> <div class="base">
<div> <div>
<img :src="goodsDetail.thumbnail" class="image" /> <img :src="goodsDetail.thumbnail" class="image" />
@ -11,23 +10,21 @@
<span style="color: red;">{{ goodsDetail.price }}</span> <span style="color: red;">{{ goodsDetail.price }}</span>
</div> </div>
<div v-if="hide"> <div v-if="hide">
<el-button class="store-button" type="danger" v-if="!sendFlag && btnHide == 1" size="mini" <el-button class="store-button" type="danger" v-if="btnHide == 1" size="mini" @click="submitSendMessage()"
@click="submitSendMessage()" plain>发送</el-button> plain>发送</el-button>
</div> </div>
</div> </div>
</div> </div>
<hr class="separate" />
</div> </div>
</template> </template>
<script> <script>
import { Tag, button } from 'element-ui' import { Tag, button } from 'element-ui'
import { mapState, mapGetters } from "vuex"; import { mapState, mapGetters } from "vuex";
import SocketInstance from "@/im-server/socket-instance";
export default { export default {
data () { data () {
return { return {
sendFlag: false,
btnHide: undefined, btnHide: undefined,
hide: true hide: true
} }
@ -36,12 +33,12 @@ export default {
...mapGetters(["talkItems"]), ...mapGetters(["talkItems"]),
...mapState({ ...mapState({
id: (state) => state.user.id, id: (state) => state.user.id,
index_name: (state) => state.dialogue.index_name,
toUser: (state) => state.user.toUser, toUser: (state) => state.user.toUser,
}), }),
}, },
mounted () { mounted () {
this.btnHide = localStorage.getItem('btnHide') this.btnHide = localStorage.getItem(this.goodsDetail.goodsId)
}, },
components: { components: {
"el-tag": Tag, "el-tag": Tag,
@ -59,7 +56,14 @@ export default {
// //
submitSendMessage () { submitSendMessage () {
console.log("发送"); console.log("发送");
const context = this.goodsDetail const context = {
id: this.goodsDetail.id,
goodsId: this.goodsDetail.goodsId,
thumbnail: this.goodsDetail.thumbnail,
price: this.goodsDetail.price,
goodsName: this.goodsDetail.goodsName
}
const record = { const record = {
operation_type: "MESSAGE", operation_type: "MESSAGE",
to: this.toUser.userId, to: this.toUser.userId,
@ -68,74 +72,12 @@ export default {
context: context, context: context,
talk_id: this.toUser.id, talk_id: this.toUser.id,
}; };
SocketInstance.emit("event_talk", record); this.$emit('sendMessage', record, context);
this.$store.commit("UPDATE_TALK_ITEM", {
index_name: this.index_name,
draft_text: "",
});
/**
* 插入数据
*/
const insterChat = {
createTime: this.formateDateAndTimeToString(new Date()),
fromUser: this.id,
toUser: record.to,
isRead: false,
messageType: "GOODS",
text: context,
float: "right",
};
console.log("insterChat", insterChat);
// console.log("",'')
//
this.$store.commit("PUSH_DIALOGUE", insterChat);
//
let el = document.getElementById("lumenChatPanel");
//
let isBottom =
Math.ceil(el.scrollTop) + el.clientHeight >= el.scrollHeight;
if (isBottom || record.to == this.id) {
this.$nextTick(() => {
el.scrollTop = el.scrollHeight;
});
} else {
this.$store.commit("SET_TLAK_UNREAD_MESSAGE", {
content: content,
nickname: record.name,
});
}
// 0 1 // 0 1
localStorage.setItem('btnHide', 0) localStorage.setItem(this.goodsDetail.goodsId, 0)
this.hide = false this.hide = false
}, },
formateDateAndTimeToString (date) {
var hours = date.getHours();
var mins = date.getMinutes();
var secs = date.getSeconds();
var msecs = date.getMilliseconds();
if (hours < 10) hours = "0" + hours;
if (mins < 10) mins = "0" + mins;
if (secs < 10) secs = "0" + secs;
if (msecs < 10) secs = "0" + msecs;
return (
this.formatDateToString(date) + " " + hours + ":" + mins + ":" + secs
);
},
formatDateToString (date) {
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
if (month < 10) month = "0" + month;
if (day < 10) day = "0" + day;
return year + "-" + month + "-" + day;
},
}, },
props: { props: {
goodsDetail: { goodsDetail: {