| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import TIM from 'tim-js-sdk';
- import COS from 'cos-js-sdk-v5';
- import request from '../Utils/RequestUtils';
- import User from '../flooks/User';
- const IM = (now) => ({
- SDKAppID: 1400375593,
- userID: 0,
- userSig: null,
- messages: [],
- chatList: [],
- sysNoticeList: [],
- chatInfo: {},
- tim: null,
- getSysNotice() {
- request.get('/email/my').then((res) => {
- now({ sysNoticeList: res });
- });
- },
- getChat() {
- request.get('/chat/my').then((res) => {
- if (res) {
- now({ chatList: res });
- }
- });
- },
- initChat() {
- const { getSysNotice, getChat, getUserSig } = now();
- getUserSig();
- getSysNotice();
- getChat();
- },
- getUserSig() {
- const { id } = now(User);
- request
- .get('/chat/getUserSig', {
- params: {
- userId: id,
- },
- })
- .then((res) => {
- now({
- userSig: res,
- userID: id,
- });
- });
- },
- updateChatInfo(info) {
- now({ chatInfo: info });
- },
- sendMessage(content, receiveUserId) {
- const { id } = now(User);
- request
- .post('/chat/save', {
- data: {
- sendUserId: id,
- receiveUserId,
- content,
- },
- })
- .then((res) => {
- const { timSend } = now();
- timSend(content, receiveUserId);
- });
- },
- setTim(tim) {
- now({ tim });
- },
- timSend(text, toUserId) {
- const { tim } = now();
- if (tim) tim.injectJavaScript(`window.sendMessage(${text},${toUserId})`);
- },
- });
- export default IM;
|