dcc
2024-07-02 7ff9b724438073bcdf332f24f67e734a4bca8f31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Axios from "@/utils/http";
import axios from "axios";
import { compress } from "image-conversion";
 
// 获取消息列表
export const _getMsg = (message_id = "", show_img = true) => {
  return new Promise((resolve, reject) => {
    Axios.fetch("wap/api/newOnlinechat!list.action", { message_id, show_img }).then(
      (res) => {
        resolve(res.data);
      }
    );
  });
};
 
// 未读消息
export const _getUnreadMsg = () => {
  return Axios.fetch("wap/api/newOnlinechat!unread.action", params);
};
 
// 发送消息
export const _sendMsg = (type = "text", content = "") => {
  return Axios.fetch("wap/api/newOnlinechat!send.action", { type, content });
};
 
// 图片上传,压缩
export const _uploadImage = (file, callback) => {
  console.log(file);
  const isLt2M = file.size / 1024 / 1024 < 10;
  if (!isLt2M) {
    Toast.fail("上传头像图片大小不能超过 10MB!");
    return false;
  }
 
  const BASE_URL = "https://galaxyhkvip.top";
  return new Promise((resolve, reject) => {
    compress(file, 0.6).then((res) => {
      const formData = new FormData();
      formData.append("file", res);
      axios
        .post(
          `${BASE_URL}/api/api/uploadFile`,
          formData,
          {
            onDownloadProgress: (progressEvent) => {
              console.log(progressEvent);
              if (progressEvent.lengthComputeable) {
                callback(
                  ((progressEvent.loaded / progressEvent.total) * 100).toFixed(
                    2
                  )
                );
              }
            },
          },
          { headers: { "Content-Type": "multipart/form-data" } }
        )
        .then((res) => {
          // Toast.clear()
          const { code, data } = res.data;
          if (code / 1 === 0) {
            resolve(data);
          }
        })
        .catch((err) => {
          // Toast.clear()
          reject(err);
        });
    });
  });
};
 
export default {
  _uploadImage,
  _getMsg,
  _sendMsg,
  _getUnreadMsg,
};