|
@@ -28,7 +28,8 @@
|
|
<script>
|
|
<script>
|
|
// import wangEditor from '@common/src/components/frame/wang-editor.vue';
|
|
// import wangEditor from '@common/src/components/frame/wang-editor.vue';
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
import { mapState, createNamespacedHelpers } from 'vuex';
|
|
-const { mapActions: personalChat } = createNamespacedHelpers('personalchat');
|
|
|
|
|
|
+const { mapActions: personChat } = createNamespacedHelpers('personChat');
|
|
|
|
+const _ = require('lodash');
|
|
export default {
|
|
export default {
|
|
name: 'chats',
|
|
name: 'chats',
|
|
props: {
|
|
props: {
|
|
@@ -42,11 +43,11 @@ export default {
|
|
};
|
|
};
|
|
},
|
|
},
|
|
created() {},
|
|
created() {},
|
|
- mounted() {
|
|
|
|
|
|
+ async mounted() {
|
|
this.channel();
|
|
this.channel();
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- ...personalChat(['create', 'query']),
|
|
|
|
|
|
+ ...personChat(['create', 'query']),
|
|
async search() {
|
|
async search() {
|
|
let res = await this.query({ personroom_id: this.room.id });
|
|
let res = await this.query({ personroom_id: this.room.id });
|
|
if (this.$checkRes(res)) {
|
|
if (this.$checkRes(res)) {
|
|
@@ -56,11 +57,11 @@ export default {
|
|
},
|
|
},
|
|
async sendMessage() {
|
|
async sendMessage() {
|
|
if (this.content != '') {
|
|
if (this.content != '') {
|
|
- let obj = { personroom_id: this.room.id, content: this.content, sender_id: this.user.uid, sender_name: this.user.name, send_time: '13:00' };
|
|
|
|
- let keys = Object.keys(this.room);
|
|
|
|
- let fres = keys.find(f => this.room[f] == this.user.uid);
|
|
|
|
- obj.receiver_id = fres === 'buyer_id' ? this.room['seller_id'] : this.room['buyer_id'];
|
|
|
|
- obj.receiver_name = fres === 'buyer_id' ? this.room['seller_name'] : this.room['buyer_name'];
|
|
|
|
|
|
+ let obj = { room_id: this.room.id, content: this.content, sender_id: this.user.id, sender_name: this.user.name };
|
|
|
|
+ let pos = 'p1';
|
|
|
|
+ if (_.get(this.room, 'p1_id') === this.user.id) pos = 'p2';
|
|
|
|
+ obj.receiver_id = _.get(this.room, `${pos}_id`);
|
|
|
|
+ obj.receiver = _.get(this.room, pos);
|
|
let res = await this.create(obj);
|
|
let res = await this.create(obj);
|
|
// this.$refs.editor.setContent();
|
|
// this.$refs.editor.setContent();
|
|
this.$set(this, `content`, '');
|
|
this.$set(this, `content`, '');
|
|
@@ -77,11 +78,14 @@ export default {
|
|
console.warn('未获取到房间id,无法进行订阅');
|
|
console.warn('未获取到房间id,无法进行订阅');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ // console.log(`/exchange/personChat/${this.room.id}/${this.user.id}`);
|
|
this.$stomp({
|
|
this.$stomp({
|
|
- [`/exchange/person_chat/${this.room.id}_${this.user.uid}`]: this.onMessage,
|
|
|
|
|
|
+ [`/exchange/personChat/${this.room.id}.${this.user.id}`]: this.onMessage,
|
|
});
|
|
});
|
|
},
|
|
},
|
|
onMessage(message) {
|
|
onMessage(message) {
|
|
|
|
+ console.log('in function:');
|
|
|
|
+ console.log(message);
|
|
let body = _.get(message, 'body');
|
|
let body = _.get(message, 'body');
|
|
if (body) {
|
|
if (body) {
|
|
body = JSON.parse(body);
|
|
body = JSON.parse(body);
|