|
@@ -164,7 +164,7 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, onMounted, onUnmounted, nextTick, watch, onActivated, onDeactivated } from "vue";
|
|
|
|
|
|
|
+import { ref, onUnmounted, nextTick, watch, onActivated, onDeactivated } from "vue";
|
|
|
import { useRouter } from "vue-router";
|
|
import { useRouter } from "vue-router";
|
|
|
import { base_img_url2 } from "@/api/config";
|
|
import { base_img_url2 } from "@/api/config";
|
|
|
import { getFileExt } from "@/utils/util";
|
|
import { getFileExt } from "@/utils/util";
|
|
@@ -223,7 +223,7 @@ const createSession = (targetUserId,callback) =>{
|
|
|
// 先保存当前的对话样式消息 要注释
|
|
// 先保存当前的对话样式消息 要注释
|
|
|
const dialogMessages = messages.value.filter(msg => msg.messageType === 'dialog');
|
|
const dialogMessages = messages.value.filter(msg => msg.messageType === 'dialog');
|
|
|
|
|
|
|
|
- VE_API.bbs.createSession({farmId:766,targetUserId}).then(({data,code}) => {
|
|
|
|
|
|
|
+ VE_API.bbs.createSession({farmId:farmVal.value,targetUserId}).then(({data,code}) => {
|
|
|
if(code === 0){
|
|
if(code === 0){
|
|
|
senderIcon.value = localUserInfoIcon
|
|
senderIcon.value = localUserInfoIcon
|
|
|
receiverIcon.value = data.session.targetUserAvatar
|
|
receiverIcon.value = data.session.targetUserAvatar
|
|
@@ -269,7 +269,7 @@ const createSession = (targetUserId,callback) =>{
|
|
|
//类型 text ,file,image
|
|
//类型 text ,file,image
|
|
|
const sendMsg = (messageType = 'text',content = '',image = {}) =>{
|
|
const sendMsg = (messageType = 'text',content = '',image = {}) =>{
|
|
|
const params = {
|
|
const params = {
|
|
|
- farmId:766,
|
|
|
|
|
|
|
+ farmId:farmVal.value,
|
|
|
senderId:curUserId,
|
|
senderId:curUserId,
|
|
|
receiverId:userId.value,
|
|
receiverId:userId.value,
|
|
|
content,
|
|
content,
|
|
@@ -281,8 +281,9 @@ const sendMsg = (messageType = 'text',content = '',image = {}) =>{
|
|
|
|
|
|
|
|
const userId = ref(null)
|
|
const userId = ref(null)
|
|
|
|
|
|
|
|
-watch(()=>props.userId,(newValue) =>{
|
|
|
|
|
|
|
+watch(()=>props.userId, async (newValue) =>{
|
|
|
if(newValue){
|
|
if(newValue){
|
|
|
|
|
+ await getFarmList();
|
|
|
userId.value = newValue
|
|
userId.value = newValue
|
|
|
createSession(newValue,()=>{
|
|
createSession(newValue,()=>{
|
|
|
if(props.text){
|
|
if(props.text){
|
|
@@ -346,7 +347,7 @@ const previewImage = ref(null);
|
|
|
|
|
|
|
|
// 初始化 mqtt
|
|
// 初始化 mqtt
|
|
|
const initMqtt = () => {
|
|
const initMqtt = () => {
|
|
|
- const topics = [`user/chat/message/${766}/${curUserId}`]; // 订阅的主题数组
|
|
|
|
|
|
|
+ const topics = [`user/chat/message/${farmVal.value}/${curUserId}`]; // 订阅的主题数组
|
|
|
mqttClient.value = new MqttClient(topics, (topic, message) => {
|
|
mqttClient.value = new MqttClient(topics, (topic, message) => {
|
|
|
console.log(topic,'topic')
|
|
console.log(topic,'topic')
|
|
|
console.log('接收推送信息:', message);
|
|
console.log('接收推送信息:', message);
|
|
@@ -579,20 +580,15 @@ const options = ref([])
|
|
|
|
|
|
|
|
// 获取农场列表
|
|
// 获取农场列表
|
|
|
function getFarmList() {
|
|
function getFarmList() {
|
|
|
- VE_API.farm.userFarmSelectOption().then(({data}) => {
|
|
|
|
|
|
|
+ return VE_API.farm.userFarmSelectOption().then(({data}) => {
|
|
|
options.value = data || []
|
|
options.value = data || []
|
|
|
if (data && data.length > 0) {
|
|
if (data && data.length > 0) {
|
|
|
- farmVal.value = data[0].id
|
|
|
|
|
|
|
+ const defaultOption = data.find(item => item.defaultOption === true)
|
|
|
|
|
+ farmVal.value = defaultOption ? defaultOption.id : data[0].id
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 生命周期钩子
|
|
|
|
|
-onMounted(() => {
|
|
|
|
|
- // scrollToBottom();
|
|
|
|
|
- getFarmList();
|
|
|
|
|
-});
|
|
|
|
|
-
|
|
|
|
|
onActivated(()=>{
|
|
onActivated(()=>{
|
|
|
if(props.userId){
|
|
if(props.userId){
|
|
|
scrollToBottom();
|
|
scrollToBottom();
|