增加聊天功能
This commit is contained in:
91
http/php/chat.js
Normal file
91
http/php/chat.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import { request } from "./request";
|
||||
const prveUrl = "chat/";
|
||||
|
||||
/**
|
||||
* 群消息
|
||||
* @param {Object} data
|
||||
* @returns
|
||||
*/
|
||||
export const groupInfo = (data) => {
|
||||
return request(prveUrl + "group/info", "POST", data, true);
|
||||
};
|
||||
|
||||
export const commonPhrase = (data) => {
|
||||
return request(prveUrl + "common-phrase/index", "POST", data, true);
|
||||
};
|
||||
export const commonPhraseAdd = (data) => {
|
||||
return request(prveUrl + "common-phrase/add", "POST", data, true);
|
||||
};
|
||||
|
||||
export const commonPhraseDel = (data) => {
|
||||
return request(prveUrl + "common-phrase/del", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupCreate = (data) => {
|
||||
return request(prveUrl + "group/create", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupJoin = (data) => {
|
||||
return request(prveUrl + "group/join", "POST", data, true);
|
||||
};
|
||||
export const groupGetGroupUrl = (data) => {
|
||||
return request(prveUrl + "group/getgrepurl", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupQuit = (data) => {
|
||||
return request(prveUrl + "group/quit", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupTarsGroup = (data) => {
|
||||
return request(prveUrl + "group/tarsgroup", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupAnnouncement = (data) => {
|
||||
return request(prveUrl + "group/announcement", "POST", data, true);
|
||||
};
|
||||
export const groupMute = (data) => {
|
||||
return request(prveUrl + "group/mute", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupMunute = (data) => {
|
||||
return request(prveUrl + "group/unmute", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupKick = (data) => {
|
||||
return request(prveUrl + "group/kick", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupMembers = (data) => {
|
||||
return request(prveUrl + "group/members", "POST", data, true);
|
||||
};
|
||||
|
||||
export const messageHistory = (data) => {
|
||||
return request(prveUrl + "message/history", "POST", data, true);
|
||||
};
|
||||
|
||||
export const messageMarkRead = (data) => {
|
||||
return request(prveUrl + "message/mark-read", "POST", data, true);
|
||||
};
|
||||
|
||||
export const messageMarkReadAll = (data) => {
|
||||
return request(prveUrl + "message/mark-read-all", "POST", data, true);
|
||||
};
|
||||
|
||||
export const messageUnreadCount = (data) => {
|
||||
return request(prveUrl + "message/unread-count", "POST", data, true);
|
||||
};
|
||||
|
||||
export const messageSessionList = (data) => {
|
||||
return request(prveUrl + "message/sessionlist", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupDoNotDisturb = (data) => {
|
||||
return request(prveUrl + "group/do-not-disturb", "POST", data, true);
|
||||
};
|
||||
|
||||
export const groupShopinfo = (data) => {
|
||||
return request(prveUrl + "group/shopinfo", "POST", data, true);
|
||||
};
|
||||
export const sessionlistdel = (data) => {
|
||||
return request(prveUrl + "message/sessionlistdel", "POST", data, true);
|
||||
};
|
||||
100
http/php/request.ts
Normal file
100
http/php/request.ts
Normal file
@@ -0,0 +1,100 @@
|
||||
//服务器接口地址
|
||||
// const baseURL : string = 'https://newblockwlx.sxczgkj.cn/index.php/api/'
|
||||
let baseURL: string = "http://192.168.1.42:8787/api/";
|
||||
// #ifdef H5
|
||||
baseURL = "/phpapi/api/";
|
||||
// #endif
|
||||
|
||||
|
||||
// 封装公共请求方法
|
||||
function request(
|
||||
url: string,
|
||||
method: "GET" | "POST" | undefined,
|
||||
data: object | any,
|
||||
toast: boolean
|
||||
) {
|
||||
let networkType = "";
|
||||
uni.getNetworkType({
|
||||
success: (res) => {
|
||||
networkType = res.networkType;
|
||||
},
|
||||
});
|
||||
if (networkType == "none") {
|
||||
uni.showToast({
|
||||
title: "网络异常,请检查网络",
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (toast) {
|
||||
uni.showLoading({
|
||||
title: "加载中",
|
||||
mask: true,
|
||||
});
|
||||
}
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let header: any;
|
||||
header = {
|
||||
"content-type": "application/json",
|
||||
token: uni.cache.get('token'),
|
||||
};
|
||||
uni.request({
|
||||
url: baseURL + url,
|
||||
method: method,
|
||||
data: data,
|
||||
header: header,
|
||||
success(res: any) {
|
||||
if (res.data.code != 1) {
|
||||
if (res.data.code === 3000) {
|
||||
uni.showToast({
|
||||
title: '请登录后操作',
|
||||
icon: "none",
|
||||
});
|
||||
uni.hideLoading();
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
//是否提示错误
|
||||
if (toast) {
|
||||
uni.showToast({
|
||||
title: res.data.msg || res.data.message,
|
||||
icon: "none",
|
||||
});
|
||||
setTimeout(() => {
|
||||
uni.hideLoading();
|
||||
}, 1000);
|
||||
}
|
||||
if (res.data.code == 401) {
|
||||
uni.showToast({
|
||||
title: res.message || res.msg,
|
||||
icon: "none",
|
||||
success: () => {
|
||||
// uni.removeStorageSync('logintoken');
|
||||
// uni.removeStorageSync('token');
|
||||
uni.reLaunch({
|
||||
url: "/pages/index/index",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
uni.hideLoading();
|
||||
reject(res.message | res.msg);
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
console.log(res);
|
||||
resolve(res.data.data);
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
uni.hideLoading();
|
||||
//请求失败
|
||||
uni.showToast({
|
||||
title: "无法连接到服务器",
|
||||
icon: "none",
|
||||
});
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
export { request, baseURL };
|
||||
Reference in New Issue
Block a user