|
@@ -7,8 +7,9 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import _ from 'lodash';
|
|
|
import WS from '../../util/websocket';
|
|
|
-import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+import { mapState, createNamespacedHelpers, mapMutations } from 'vuex';
|
|
|
const { mapActions } = createNamespacedHelpers('shopNotice');
|
|
|
export default {
|
|
|
name: 'notice',
|
|
@@ -31,50 +32,73 @@ export default {
|
|
|
},
|
|
|
methods: {
|
|
|
...mapActions(['cnr']),
|
|
|
+ ...mapMutations(['setMessage']),
|
|
|
async initWebSocket() {
|
|
|
const shop_id = _.get(this.user, 'shop._id');
|
|
|
- const url = `ws://localhost:12214/dev/point/chat/v1/api/ws`;
|
|
|
- const ws = new WS(url, shop_id, (res) => console.log(res));
|
|
|
- },
|
|
|
-
|
|
|
- toNotice() {
|
|
|
- this.$router.push({ path: `/selfShop/notice` });
|
|
|
- },
|
|
|
- async getNotRead() {
|
|
|
- const res = await this.cnr(this.user.shop._id);
|
|
|
- if (this.$checkRes(res)) {
|
|
|
- this.$set(this, `notice`, res.data);
|
|
|
- }
|
|
|
- },
|
|
|
- channel() {
|
|
|
- const shop_id = _.get(this.user, 'shop._id');
|
|
|
- if (!shop_id) return;
|
|
|
- this.$stomp({
|
|
|
- [`/exchange/${this.$ex}/${shop_id}`]: this.onMessage,
|
|
|
+ // const url = `ws://192.168.1.197:12214/dev/point/chat/v1/api/ws`;
|
|
|
+ const url = `ws://broadcast.waityou24.cn/dev/point/chat/v1/api/ws`;
|
|
|
+ const ws = new WS(url, shop_id, (res) => {
|
|
|
+ console.log(res);
|
|
|
+ if (res.data != 'connect success') this.onMessage(res.data);
|
|
|
});
|
|
|
},
|
|
|
onMessage(message) {
|
|
|
- let body = message.body;
|
|
|
- if (!body) return;
|
|
|
- body = JSON.parse(body);
|
|
|
- const type = body.type;
|
|
|
+ let data = JSON.parse(message);
|
|
|
+ let type = data.type;
|
|
|
+ console.log(type);
|
|
|
if (type === 'shopMsg') {
|
|
|
- // this.$notify({
|
|
|
- // title: '新消息',
|
|
|
- // message: '您有新的消息,请注意及时处理!',
|
|
|
- // position: 'top-right',
|
|
|
- // type: 'warning',
|
|
|
- // });
|
|
|
- // this.getNotRead();
|
|
|
- } else if (type === 'chat') {
|
|
|
- this.$notify({
|
|
|
+ this.instance = this.$notify({
|
|
|
title: '新消息',
|
|
|
- message: '有顾客进行咨询,请及时回复!',
|
|
|
+ message: '您有新的消息,请注意及时处理!',
|
|
|
position: 'top-right',
|
|
|
type: 'warning',
|
|
|
+ onClick: () => {
|
|
|
+ this.close();
|
|
|
+ this.toNotice();
|
|
|
+ },
|
|
|
});
|
|
|
+ this.getNotRead();
|
|
|
+ } else if (type === 'chat') {
|
|
|
+ if (this.$route.path === '/selfShop/message') this.setMessage(data);
|
|
|
+ else {
|
|
|
+ this.instance = this.$notify({
|
|
|
+ title: '新消息',
|
|
|
+ message: '有顾客进行咨询,请及时回复!',
|
|
|
+ position: 'top-right',
|
|
|
+ type: 'warning',
|
|
|
+ onClick: () => {
|
|
|
+ this.close();
|
|
|
+ this.toApproval();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
+ close() {
|
|
|
+ this.instance.close();
|
|
|
+ },
|
|
|
+ // 系统提示
|
|
|
+ toNotice() {
|
|
|
+ if (this.$route.path != '/selfShop/notice') this.$router.push({ path: `/selfShop/notice` });
|
|
|
+ else this.$message({ type: `warning`, message: `已在该页面` });
|
|
|
+ },
|
|
|
+ // 聊天
|
|
|
+ toApproval() {
|
|
|
+ if (this.$route.path != '/selfShop/message') this.$router.push({ path: `/selfShop/message` });
|
|
|
+ else this.$message({ type: `warning`, message: `已在该页面` });
|
|
|
+ },
|
|
|
+ // 查询未读消息数量
|
|
|
+ async getNotRead() {
|
|
|
+ const res = await this.cnr(this.user.shop._id);
|
|
|
+ if (this.$checkRes(res)) this.$set(this, `notice`, res.data);
|
|
|
+ },
|
|
|
+ // channel() {
|
|
|
+ // const shop_id = _.get(this.user, 'shop._id');
|
|
|
+ // if (!shop_id) return;
|
|
|
+ // this.$stomp({
|
|
|
+ // [`/exchange/${this.$ex}/${shop_id}`]: this.onMessage,
|
|
|
+ // });
|
|
|
+ // },
|
|
|
},
|
|
|
};
|
|
|
</script>
|