haomingming 97a504c6d2 优化
2023-05-05 11:44:37 +08:00

382 lines
11 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// TUIKit-WChat/Chat/index.js
import logger from '../../utils/logger';
import constant from '../../utils/constant';
import { API } from './../../../utils/network/api'
const api = new API()
// eslint-disable-next-line no-undef
const app = getApp();
const inputStyle = `
--padding: 0px;
`;
let newInputStyle = `
--padding: 0px;
position: absolute;
`;
const setNewInputStyle = (number) => {
const height = number;
newInputStyle = `--padding: ${height}px`;
};
Component({
/**
* 组件的属性列表
*/
properties: {
currentConversationID: {
type: String,
value: '',
observer(currentConversationID) {
this.setData({
conversationID: currentConversationID,
});
},
},
order_inquiry_id: {
type: String,
value: ''
},
inquiry_type: {
type: String,
value: ''
},
unreadCount: {
type: Number,
value: '',
observer(unreadCount) {
this.setData({
unreadCount,
});
},
},
hasCallKit: {
type: Boolean,
value: false,
observer(hasCallKit) {
this.setData({
hasCallKit,
});
},
},
baseInfo: {
type: Object,
value: {},
observer(baseInfo) {
this.setData({
"navbarData.title": baseInfo.patient_family_name
});
},
}
},
lifetimes: {
attached() {
if (app?.globalData?.reportType === constant.OPERATING_ENVIRONMENT) {
this.setData({
showTips: true,
message_rounds: 0
});
}
this.getNavbarHeight()
wx.onKeyboardHeightChange(res => {
console.log("键盘高度:", res.height)
this.setData({
keysboards_height: res.height
})
this.getNavbarHeight();
})
},
ready() {
//修改为组件传值
// this.getInquiryMessageBasic()
// console.log("app.globalData.scene from TUIchat ready: ", app.globalData.scene);
let pages = getCurrentPages();
// console.log("pages:", pages)
// console.log("pages.length:", pages.length)
// console.log("pages:", pages[0])
if(pages.length == 1){
console.log("navbarData.showCapsule");
this.setData({
"navbarData.showCapsule": 3
})
}
}
},
/**
* 组件的初始数据
*/
data: {
conversationName: '',
conversation: {},
messageList: [],
isShow: false,
showImage: false,
showChat: true,
conversationID: '',
config: {
sdkAppID: '',
userID: '',
userSig: '',
type: 1,
tim: null,
},
unreadCount: 0,
hasCallKit: false,
viewData: {
style: inputStyle,
},
input_area_style:"",
KeyboardHeight: 0,
showTips: false,
showGroupTips: false,
showAll: false,
navbarData: {
showCapsule: 2, //是否显示左上角图标 1表示显示 0表示不显示
title: '', //导航栏 中间的标题
},
navbar_height: 0,
dialog_visible: false,
KeysBoardsStatus: "down",
message_rounds: 0,
keysboards_height: 0
},
/**
* 组件的方法列表
*/
methods: {
refreshMessageRounds(e){
console.log("TUIchat refreshMessageRounds", e)
let message_rounds = e.detail.message_rounds
console.log("TUIchat refreshMessageRounds message_rounds", message_rounds)
this.setData({
message_rounds: message_rounds
})
},
getNavbarHeight(addHeight){
let rect = null;
if (wx.getMenuButtonBoundingClientRect) {
rect = wx.getMenuButtonBoundingClientRect();
}
console.log("rect: ", rect)
wx.getSystemInfo({
success: (res) => {
const { statusBarHeight } = wx.getSystemInfoSync();
console.log("statusBarHeight: ", statusBarHeight);
console.log("${rect.height}px: ", `${rect.height}`);
let height = Number.parseInt(statusBarHeight) + Number.parseInt(`${rect.height}`) + 50;
if(addHeight){
height = height + addHeight
}
let keysboards_height = this.data.keysboards_height
console.log("getNavbarHeight 键盘高度:", keysboards_height)
if(keysboards_height){
height = height + keysboards_height
}
this.setData({
navbar_height: height
})
},
fail: (err) => {
console.error('navbar 获取系统信息失败', err);
},
});
},
//结束问诊
putDoctorInquiryFinish() {
this.setData({
dialog_visible: true
})
},
cancelDialog(){
this.setData({
dialog_visible: false
})
},
confirmDialog(){
api.putDoctorInquiryFinish({order_inquiry_id: this.data.order_inquiry_id}).then(response => {
console.log(response);
this.getInquiryMessageBasic();
//调用子组件中的跳到最新消息
this.selectComponent('#MessageList').handleJumpNewMessage();
}).catch(errors => {console.error(errors);})
this.setData({
dialog_visible: false
})
},
//获取问诊订单消息内页基础数据
getInquiryMessageBasic() {
console.log("order_inquiry_id: ", this.data.order_inquiry_id);
api.getInquiryMessageBasic({order_inquiry_id: this.data.order_inquiry_id}).then(response => {
console.log(response);
this.setData({
baseInfo: response.data,
})
}).catch(errors => {console.error(errors);})
},
init() {
console.warn("TUIChat js: init", this.data.conversationID)
wx.$TUIKit.setMessageRead({ conversationID: this.data.conversationID }).then(() => {
logger.log('| TUI-chat | setMessageRead | ok');
});
wx.$TUIKit.getConversationProfile(this.data.conversationID).then((res) => {
const { conversation } = res.data;
this.setData({
conversationName: this.getConversationName(conversation),
conversation,
isShow: conversation.type === wx.$TUIKitTIM.TYPES.CONV_GROUP,
});
if (conversation.type !== wx.$TUIKitTIM.TYPES.CONV_GROUP) return;
if (!this.data.showTips) {
this.setData({
showGroupTips: true,
});
} else {
this.setData({
showAll: true,
});
}
});
},
getConversationName(conversation) {
if (conversation.type === '@TIM#SYSTEM') {
this.setData({
showChat: false,
});
return '系统通知';
}
if (conversation.type === wx.$TUIKitTIM.TYPES.CONV_C2C) {
return conversation.remark || conversation.userProfile.nick || conversation.userProfile.userID;
}
if (conversation.type === wx.$TUIKitTIM.TYPES.CONV_GROUP) {
return conversation.groupProfile.name || conversation.groupProfile.groupID;
}
},
sendMessage(event) {
// 将自己发送的消息写进消息列表里面
this.selectComponent('#MessageList').updateMessageList(event.detail.message);
this.getNavbarHeight();
},
showMessageErrorImage(event) {
this.selectComponent('#MessageList').sendMessageError(event);
},
triggerClose() {
console.log("message-list triggerClose")
if(this.data.baseInfo.inquiry_status == 4){
this.selectComponent('#MessageInput').handleClose();
}
wx.hideKeyboard()
this.getNavbarHeight()
},
handleCall(event) {
if (event.detail.conversationType === wx.$TUIKitTIM.TYPES.CONV_GROUP) {
this.selectComponent('#TUIGroup').callShowMoreMember(event);
} else {
this.triggerEvent('handleCall', event.detail);
}
},
groupCall(event) {
const { selectedUserIDList, type, groupID } = event.detail;
const userIDList = selectedUserIDList;
this.triggerEvent('handleCall', { userIDList, type, groupID });
},
goBack() {
this.triggerEvent('showConversationList');
wx.$TUIKit.setMessageRead({
conversationID: this.data.conversationID,
}).then(() => {
wx.navigateBack();
});
},
showConversationList() {
this.triggerEvent('showConversationList');
},
changeMemberCount(event) {
this.selectComponent('#TUIGroup').updateMemberCount(event.detail.groupOptionsNumber);
},
resendMessage(event) {
this.selectComponent('#MessageInput').onInputValueChange(event);
},
myhandleExtensions(e){
console.log("myhandleExtensionsmyhandleExtensions: ", e);
wx.hideKeyboard()
let displayFlag = e.detail.displayFlag;
setTimeout(() => {
if(displayFlag){
this.setData({
input_area_style: "position: absolute; bottom: 30px;"
})
this.getNavbarHeight(100);
this.selectComponent('#MessageList').handleJumpNewMessage();
}else{
this.setData({
input_area_style: "",
})
this.getNavbarHeight();
}
}, 100);
},
// 监听键盘,获取焦点时将输入框推到键盘上方
pullKeysBoards(event) {
console.log("pullKeysBoardspullKeysBoards")
setNewInputStyle(event.detail.event.detail.height);
this.getNavbarHeight();
this.setData({
'viewData.style': newInputStyle,
input_area_style: "position: absolute; bottom: 52rpx;",
KeysBoardsStatus: "pull"
});
this.selectComponent('#MessageList').handleJumpNewMessage();
},
// 监听键盘,失去焦点时收起键盘
downKeysBoards(event) {
console.log("downKeysBoardsdownKeysBoards")
console.log(event)
let value = event.detail.event.detail.value;
this.getNavbarHeight();
if(value){
this.setData({
'viewData.style': inputStyle,
KeysBoardsStatus: "down"
});
}else{
this.setData({
'viewData.style': inputStyle,
input_area_style: "",
KeysBoardsStatus: "down"
});
}
},
typing(event) {
const { STRING_TEXT, FEAT_NATIVE_CODE } = constant;
if (this.data.conversation.type === wx.$TUIKitTIM.TYPES.CONV_C2C) {
if (event.detail.typingMessage.typingStatus === FEAT_NATIVE_CODE.ISTYPING_STATUS && event.detail.typingMessage.actionParam === constant.TYPE_INPUT_STATUS_ING) {
this.setData({
conversationName: STRING_TEXT.TYPETYPING,
});
setTimeout(() => {
this.setData({
conversationName: this.getConversationName(this.data.conversation),
});
}, (1000 * 30));
} else if (event.detail.typingMessage.typingStatus === FEAT_NATIVE_CODE.NOTTYPING_STATUS && event.detail.typingMessage.actionParam === constant.TYPE_INPUT_STATUS_END) {
this.setData({
conversationName: this.getConversationName(this.data.conversation),
});
}
}
},
handleReport() {
const url = '/pages/TUI-User-Center/webview/webview?url=https://cloud.tencent.com/apply/p/xc3oaubi98g';
wx.navigateTo({
url,
});
},
},
});