提交 3cefef5b 编写于 作者: guangjun.yang's avatar guangjun.yang

下拉刷新、实时刷新等

上级 dad4c59e
...@@ -13,6 +13,7 @@ import 'element-ui/lib/theme-chalk/index.css'; ...@@ -13,6 +13,7 @@ import 'element-ui/lib/theme-chalk/index.css';
import vViewer from 'v-viewer'; import vViewer from 'v-viewer';
import 'viewerjs/dist/viewer.css'; import 'viewerjs/dist/viewer.css';
import ClipboardJS from 'clipboard'; import ClipboardJS from 'clipboard';
// import '@/utils/directive';
Vue.prototype.ClipboardJS = ClipboardJS; Vue.prototype.ClipboardJS = ClipboardJS;
Vue.use(vViewer); Vue.use(vViewer);
......
import Vue from 'vue'
Vue.directive('loadmore', {
bind (el, binding) {
// 获取element-ui定义好的scroll盒子
const SELECTWRAP_DOM = el.querySelector('.scroll-box')
console.log(SELECTWRAP_DOM);
let flag = true;
SELECTWRAP_DOM.addEventListener('scroll', function () {
console.log(this.scrollHeight, this.scrollTop, this.clientHeight);
const CONDITION = this.scrollTop <= 20;
if (CONDITION) {
if(flag) {
flag = false;
setTimeout( () => {
binding.value()
flag = true;
}, 200)
}
}
});
}
})
\ No newline at end of file
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
</div> </div>
<!-- <span class="close-btn">结束会话</span> --> <!-- <span class="close-btn">结束会话</span> -->
</section> </section>
<section class="msg-content" :style="{'height': (containerHeight - 35) + 'px'}"> <p class="refreshText"></p>
<section class="msg-content scroll-box" :style="{'height': (containerHeight - 35) + 'px'}">
<article <article
class="msg-item" class="msg-item"
:class="{'cr': item.sendOrReceive}" :class="{'cr': item.sendOrReceive}"
...@@ -97,7 +98,7 @@ ...@@ -97,7 +98,7 @@
<el-upload <el-upload
class="bg-uploader" class="bg-uploader"
action="#" action="#"
accept=".jpg,.png,.pdf" accept=".jpg, .png, .pdf"
:show-file-list="false" :show-file-list="false"
:before-upload="beforeUploadFile" :before-upload="beforeUploadFile"
> >
...@@ -196,6 +197,8 @@ export default { ...@@ -196,6 +197,8 @@ export default {
currentTaskLogId: "", // 当前会话ID currentTaskLogId: "", // 当前会话ID
currentToAccId: "", currentToAccId: "",
picakfAccId: "", picakfAccId: "",
historyTimestamp: 0,
realTimestamp: 0,
doctorInfo: { doctorInfo: {
name: "杨Song", name: "杨Song",
mobilePhone: "138****7261", mobilePhone: "138****7261",
...@@ -212,12 +215,8 @@ export default { ...@@ -212,12 +215,8 @@ export default {
// 消息列表 showType 1: 文本; 2: 图片; 3: PDF; 4: 链接; 5: 不支持类型; // 消息列表 showType 1: 文本; 2: 图片; 3: PDF; 4: 链接; 5: 不支持类型;
messageList: [], messageList: [],
rules: { rules: {
info: [ info: [{ required: true, message: "请输入链接文案", trigger: "blur" }],
{ required: true, message: "请输入链接文案", trigger: "blur" }, url: [{ required: true, message: "请选择链接地址", trigger: "change" }]
],
url: [
{ required: true, message: "请选择链接地址", trigger: "change" },
],
} }
}; };
}, },
...@@ -235,9 +234,73 @@ export default { ...@@ -235,9 +234,73 @@ export default {
this.getFiveContentList(); this.getFiveContentList();
}, },
mounted: function() {}, mounted: function() {
let _this = this;
(function(window) {
var _element = document.querySelector(".scroll-box"),
_refreshText = document.querySelector(".refreshText"),
_startPos = 0,
_transitionHeight = 0,
_isMousedown = false;
_element.addEventListener(
"mousedown",
function(e) {
var event = e || window.event;
_isMousedown = true;
console.log("##########", event);
console.log("初始位置:", event.pageX);
_startPos = event.pageX;
_element.style.position = "relative";
_element.style.transition = "transform 0s";
},
false
);
_element.addEventListener(
"mousemove",
function(e) {
if (!_isMousedown) return;
var event = e || window.event;
console.log("##########", event);
console.log("当前位置:", event.pageX);
_transitionHeight = event.pageX - _startPos;
if (_transitionHeight > 0 && _transitionHeight < 40) {
// _refreshText.innerText = "下拉刷新";
_refreshText.innerText = "";
_element.style.transform =
"translateY(" + _transitionHeight + "px)";
if (_transitionHeight > 20) {
// _refreshText.innerText = "释放更新";
_refreshText.innerText = "";
}
}
},
false
);
_element.addEventListener(
"mouseup",
function(e) {
_isMousedown = false;
_element.style.transition = "transform 0.5s ease 1s";
_element.style.transform = "translateY(0px)";
// _refreshText.innerText = "更新中";
_refreshText.innerText = "";
// todo...
_this.getOldMSGHistory();
},
false
);
})(window);
},
methods: { methods: {
// 下拉刷新
loadmore() {
console.log("in loadmore...");
},
// 查询医生和居民的消息历史(下拉刷新时调用) // 查询医生和居民的消息历史(下拉刷新时调用)
getOldMSGHistory() { getOldMSGHistory() {
...@@ -247,15 +310,16 @@ export default { ...@@ -247,15 +310,16 @@ export default {
includeFlag: 0, // 不带本条消息 includeFlag: 0, // 不带本条消息
lastClientIdServer: session.lastMsgIdClient, lastClientIdServer: session.lastMsgIdClient,
lastMsgIdServer: session.lastMsgIdServer, lastMsgIdServer: session.lastMsgIdServer,
lastMsgTimestamp: session.lastMsgTime, lastMsgTimestamp: this.historyTimestamp,
limit: 20, limit: 20,
patientAccId: this.picakfAccId, patientAccId: this.picakfAccId,
unionId: "" unionId: ""
}; };
this.POST("/im/msg/history", params).then(res => { this.POST("/im/msg/history", params).then(res => {
if (res.code === "000000") { if (res.code === "000000") {
console.log("res", res);
// 将新消息合并到之前的消息中, 并且重置最后一条消息 // 将新消息合并到之前的消息中, 并且重置最后一条消息
// this.convertMessageList(res.data); this.convertMessageList(res.data, 3);
} else { } else {
this.$message({ this.$message({
message: res.message, message: res.message,
...@@ -279,7 +343,7 @@ export default { ...@@ -279,7 +343,7 @@ export default {
}; };
this.POST("/im/msg/history", params).then(res => { this.POST("/im/msg/history", params).then(res => {
if (res.code === "000000") { if (res.code === "000000") {
this.convertMessageList(res.data); this.convertMessageList(res.data, 1);
} else { } else {
this.$message({ this.$message({
message: res.message, message: res.message,
...@@ -298,7 +362,7 @@ export default { ...@@ -298,7 +362,7 @@ export default {
includeFlag: 0, includeFlag: 0,
lastClientIdServer: session.lastMsgIdClient, lastClientIdServer: session.lastMsgIdClient,
lastMsgIdServer: session.lastMsgIdServer, lastMsgIdServer: session.lastMsgIdServer,
lastMsgTimestamp: session.lastMsgTime, lastMsgTimestamp: this.realTimestamp,
limit: 20, limit: 20,
patientAccId: this.picakfAccId, patientAccId: this.picakfAccId,
unionId: "" unionId: ""
...@@ -306,6 +370,7 @@ export default { ...@@ -306,6 +370,7 @@ export default {
this.POST("/im/msg/forward", params).then(res => { this.POST("/im/msg/forward", params).then(res => {
if (res.code === "000000") { if (res.code === "000000") {
this.convertMessageList(res.data, 2); this.convertMessageList(res.data, 2);
this.readAllMsg();
} else { } else {
this.$message({ this.$message({
message: res.message, message: res.message,
...@@ -320,7 +385,7 @@ export default { ...@@ -320,7 +385,7 @@ export default {
// type == TEXT(showType:1) // type == TEXT(showType:1)
// type == image 或 picture(showType:2) // type == image 或 picture(showType:2)
// type == custom时,1 ~ 17: 不支持(showType:5); 18: PDF文件(showType:3); 19: 链接信息(showType:4); // type == custom时,1 ~ 17: 不支持(showType:5); 18: PDF文件(showType:3); 19: 链接信息(showType:4);
// directFlag 1: 拼接历史消息(push); 2: 拼接实时消息(unshift) // directFlag 1: 第一次取数据; 2: 拼接实时消息(unshift); 3: 拼接历史消息(push);
convertMessageList(messageList, directFlag = 1) { convertMessageList(messageList, directFlag = 1) {
messageList.sort((a, b) => { messageList.sort((a, b) => {
return a.timestamp - b.timestamp; return a.timestamp - b.timestamp;
...@@ -379,9 +444,25 @@ export default { ...@@ -379,9 +444,25 @@ export default {
if (directFlag === 1) { if (directFlag === 1) {
this.messageList = cMessageList; this.messageList = cMessageList;
// this.messageList.unshift(...cMessageList); } else if (directFlag === 2) {
this.messageList.push(...cMessageList);
} else { } else {
// this.messageList.push(...cMessageList); this.messageList.unshift(...cMessageList);
}
// 重新设置历史与实时的时间戳
if (this.messageList.length) {
this.historyTimestamp = this.messageList[0].timestamp;
this.realTimestamp = this.messageList[
this.messageList.length - 1
].timestamp;
}
if(directFlag == 1) {
forwardMsgIntervalId && clearInterval(forwardMsgIntervalId);
forwardMsgIntervalId = setInterval(() => {
this.getMSGForward();
}, 10000);
} }
console.log("this.messageList", this.messageList); console.log("this.messageList", this.messageList);
}, },
...@@ -400,7 +481,7 @@ export default { ...@@ -400,7 +481,7 @@ export default {
this.getDoctorInfo(this.currentToAccId); this.getDoctorInfo(this.currentToAccId);
// 调用全部已读 // 调用全部已读
if (session.unreadCount) { if (session.unreadCount) {
this.readAllMsg(this.currentToAccId, this.picakfAccId); this.readAllMsg();
} }
}, },
...@@ -433,22 +514,23 @@ export default { ...@@ -433,22 +514,23 @@ export default {
sessionList: [], sessionList: [],
waitingTaskCount: 0 waitingTaskCount: 0
}; };
if ( let sLength = this.sessionListData.sessionList.length;
!this.currentTaskLogId && // 第一次进入页面
this.sessionListData.sessionList.length if (!this.currentTaskLogId) {
) {
this.convertSessions(this.sessionListData.sessionList);
this.$forceUpdate();
this.currentSession = this.sessionListData.sessionList[0]; this.currentSession = this.sessionListData.sessionList[0];
this.currentSessionIndex = 0; this.currentSessionIndex = 0;
this.currentTaskLogId = this.currentSession.id; this.currentTaskLogId = this.currentSession.id;
this.currentToAccId = this.currentSession.toAccId; this.currentToAccId = this.currentSession.toAccId;
// this.realTimestamp = this.sessionListData.sessionList[
// sLength - 1
// ].lastMsgTime;
}
if (sLength) {
this.convertSessions(this.sessionListData.sessionList);
this.$forceUpdate();
console.log("this.currentSession", this.currentSession); console.log("this.currentSession", this.currentSession);
this.getMSGHistory(this.currentSession); this.getMSGHistory(this.currentSession);
this.getDoctorInfo(this.currentToAccId); this.getDoctorInfo(this.currentToAccId);
forwardMsgIntervalId = setInterval(() => {
this.getMSGForward();
}, 10000);
} }
} else { } else {
this.$message({ this.$message({
...@@ -525,7 +607,9 @@ export default { ...@@ -525,7 +607,9 @@ export default {
}, },
// 设置全部消息已读 // 设置全部消息已读
readAllMsg(fromAccount, toAccount) { readAllMsg() {
let fromAccount = this.currentToAccId,
toAccount = this.picakfAccId;
let params = { let params = {
fromAccount, fromAccount,
toAccount toAccount
...@@ -582,7 +666,7 @@ export default { ...@@ -582,7 +666,7 @@ export default {
// 上传文件 // 上传文件
beforeUploadFile(file) { beforeUploadFile(file) {
let vm = this; let vm = this;
console.log('file', file); console.log("file", file);
doUpload( doUpload(
vm, vm,
file, file,
...@@ -599,7 +683,10 @@ export default { ...@@ -599,7 +683,10 @@ export default {
params.type = 2; params.type = 2;
// 如果是图片,则要获取其宽与高 // 如果是图片,则要获取其宽与高
if(params.fileExt.toLowerCase() === '.jpg' || params.fileExt.toLowerCase() === '.png') { if (
params.fileExt.toLowerCase() === ".jpg" ||
params.fileExt.toLowerCase() === ".png"
) {
params.type = 1; params.type = 1;
let image = new Image(); let image = new Image();
image.src = params.url; image.src = params.url;
...@@ -627,22 +714,22 @@ export default { ...@@ -627,22 +714,22 @@ export default {
// 发送带链接消息 // 发送带链接消息
sendLinkMsg() { sendLinkMsg() {
this.$refs['linkFormRef'].validate(valid => { this.$refs["linkFormRef"].validate(valid => {
if(valid) { if (valid) {
let params = this.linkForm; let params = this.linkForm;
params.url = getPhomeDemain() + `/template_v2/?id=${params.url}`; params.url = getPhomeDemain() + `/template_v2/?id=${params.url}`;
params.type = 3; params.type = 3;
this.sendCommonMsg(params); this.sendCommonMsg(params);
this.showSelectDialog = false; this.showSelectDialog = false;
} }
}) });
}, },
// 发送文本消息 // 发送文本消息
sendTextMsg() { sendTextMsg() {
if (!this.canSend) return; if (!this.canSend) return;
this.sendCommonMsg({ info: this.sendText }); this.sendCommonMsg({ info: this.sendText });
this.sendText = ''; this.sendText = "";
}, },
// 发送通用消息 // 发送通用消息
...@@ -659,7 +746,7 @@ export default { ...@@ -659,7 +746,7 @@ export default {
remark: "", // 其他信息(链接中的前缀文案) remark: "", // 其他信息(链接中的前缀文案)
type: 0, // 类型 0文本 1图片 2pdf 3链接 type: 0, // 类型 0文本 1图片 2pdf 3链接
url: "" // url地址(图片、pdf,链接) url: "" // url地址(图片、pdf,链接)
} };
params = Object.assign(sendMsgParams, params); params = Object.assign(sendMsgParams, params);
console.log("sendMsgParams", params); console.log("sendMsgParams", params);
this.POST("/im/msg/sendMessage", params).then(res => { this.POST("/im/msg/sendMessage", params).then(res => {
...@@ -674,7 +761,7 @@ export default { ...@@ -674,7 +761,7 @@ export default {
}); });
} }
}); });
}, }
}, },
beforeDestroy() { beforeDestroy() {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册