123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- import axios from '../http'
- import axiosForm from '../httpForm'
- import { cryptoMsg, decryptoMsg } from '@/util/util.js'
- import Message from '@/store/db/Message.js'
- export default {
- /**
- * 群聊 获取最新消息【不需要登录】
- * @param {Object} params
- * @param {Number} params.group_id 会话id
- * @param {Number} params.client_hash 客户端上的最新消息的hash 【可为null】
- */
- async getNewMsg (params) {
- let res = await axios.request({
- url: 'group/newMsg',
- method: 'get',
- needLogin: false,
- params: params
- })
- const objMessage = new Message()
- // 如果不同步执行,第一次初始化数据库会出现很奇怪的问题...
- await objMessage.saveMsg(params['group_id'], res.data.data)
- // 解密数据
- res.data.data.list.forEach(item => {
- if (item.msg_type == 4) {
- // 针对红包类型
- item.msg = JSON.parse(decryptoMsg(item.msg))
- } else {
- item.msg = decryptoMsg(item.msg)
- }
- })
- return res
- },
- /**
- * 群聊 获取历史消息【不需要登录】
- * @param {Object} params
- * @param {Number} params.group_id 会话id
- * @param {Number} params.client_hash 客户端上的最旧消息的hash
- */
- getHistoryMsg (params) {
- return axios.request({
- url: 'group/historyMsg',
- method: 'get',
- needLogin: false,
- params
- })
- },
- /**
- * 群聊信息
- * @param {Object} data
- * @param {Number} data.group_id 会话id
- */
- getGroupInfo (params) {
- return axios.request({
- url: 'group/info',
- method: 'get',
- needLogin: false,
- params
- })
- },
- /**
- * 群聊信息( 比getGroupInfo多了缓存 )
- * @param {Object} data
- * @param {Number} data.group_id 会话id
- */
- getGroupInfo2 (params, callback) {
- axios.request2({
- url: 'group/info',
- method: 'get',
- needLogin: false,
- cache: true,
- cacheKeys: ['user_id', 'group_id'],
- params,
- callback
- })
- },
- /**
- * 发送群聊消息
- * @param {Object} data
- * @param {Number} data.group_id 会话id
- * @param {Number} data.msg_type 消息类型:0:文本,1:图片,2:视频
- * @param {String} data.msg 内容
- */
- sendMsg (data) {
- data.msg = cryptoMsg(data.msg)
- return axios.request({
- url: 'group/sendMsg',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 创建群组
- * @param {Object} data
- */
- createGroup (data) {
- return axios.request({
- url: 'group/create',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 加入群组
- * @param {Object} data
- */
- joinGroup (params) {
- return axios.request({
- url: 'group/join',
- method: 'get',
- needLogin: true,
- params
- })
- },
- /**
- * 离开群组
- * @param {Object} data
- */
- leaveGroup (params) {
- return axios.request({
- url: 'group/leave',
- method: 'get',
- needLogin: true,
- params
- })
- },
- /**
- * 封禁用户
- * @param {Object} data
- */
- blockUser (params) {
- return axios.request({
- url: 'group/blockUser',
- method: 'get',
- needLogin: true,
- params
- })
- },
- /**
- * 解封用户
- * @param {Object} data
- */
- unblockUser (params) {
- return axios.request({
- url: 'group/unblockUser',
- method: 'get',
- needLogin: true,
- params
- })
- },
- /**
- * 更新群名称
- * @param {Object} data
- */
- changeName (data) {
- return axios.request({
- url: 'group/changeName',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 更新群公告
- * @param {Object} data
- */
- changeNotice (data) {
- return axios.request({
- url: 'group/changeNotice',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 更新群图标
- * @param {Object} data
- */
- changeCover (data) {
- return axiosForm.request({
- url: 'group/changeCover',
- method: 'post',
- data
- })
- },
- /**
- * 更新群标题
- * @param {Object} data
- */
- changeTitle (data) {
- return axios.request({
- url: 'group/changeTitle',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 邀请用户
- * @param {Object} data
- */
- invites (data) {
- return axios.request({
- url: 'group/invites',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 移除用户
- * @param {Object} data
- */
- removes (data) {
- return axios.request({
- url: 'group/removes',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 发送私聊信息
- * @param {Object} data
- * @param {String} data.group_id 会话id
- * @param {String} data.hash 会话hash
- */
- repealGroupMsg (data) {
- return axios.request({
- url: 'group/repealMsg',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * 发送图片信息
- * @param {Object} formData
- */
- sendImageMsg (data) {
- return axios.request({
- url: 'group/sendImageMsg',
- method: 'post',
- needLogin: true,
- headers: { 'Content-Type': 'multipart/form-data' },
- data
- })
- },
- /**
- * 获取好友列表
- * @param {Object} formData
- */
- getFriends (params) {
- return axios.request({
- url: 'group/getFriends',
- method: 'get',
- needLogin: true,
- params
- })
- },
- /**
- * @param {Object} data
- * @param {String} data.group_id
- * @param {Stirng} data.hash
- */
- pinMsg (data) {
- return axios.request({
- url: 'group/pinMsg',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @param {Object} data
- * @param {String} data.group_id
- * @param {Stirng} data.hash
- */
- unpinMsg (data) {
- return axios.request({
- url: 'group/unpinMsg',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @param {Object} data
- * @param {String} data.group_id
- * @param {Stirng} data.user_id
- */
- addAdmin (data) {
- return axios.request({
- url: 'group/addAdmin',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @param {Object} data
- * @param {String} data.group_id
- * @param {Stirng} data.user_id
- */
- removeAdmin (data) {
- return axios.request({
- url: 'group/removeAdmin',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @param {Object} data
- * @param {Stirng} data.keyword
- */
- searchMember (data) {
- return axios.request({
- url: 'group/memberSearch',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @param {Object} data
- * @param {Stirng} data.group_id
- * @param {Stirng} data.new_creator
- */
- changeCreator (data) {
- return axios.request({
- url: 'group/changeCreator',
- method: 'post',
- needLogin: true,
- data
- })
- },
- /**
- * @des 热门群推荐
- */
- getHotList () {
- return axios.request({
- url: 'group/hotList ',
- method: 'post',
- needLogin: true
- })
- }
- }
|