import { GET, POST, DELETE, PUT, getApiUrl, getApiUrl2, getBSGlobal, getUserInfo } from './index' //用于获取feed数据的请求 const getFeedData = (param = {}) => { let defaultParam = { channelId: 2, //分类 pageSize: 20, //获取多少条数据 commentCount: 5, //回复展示几条 to_userId: 0, //看谁的动态 objId: '', // startId: '', //从哪条feed开始 version: 3 //3为后台接口走新逻辑 }, url = getApiUrl('feedchannel/feeds') return GET(url, { ...defaultParam, ...param }) } //获取全部回复 const getAllComment = (param = {}) => { let defaultParam = { feed_id: '', //feedId comment_type: 0 // } let url = getApiUrl2('comment/Get') return GET(url, { ...defaultParam, ...param }) } //删除单条回复 const deleteCommentById = (param = {}) => { let defaultParam = { feed_id: '', //feedId comment_id: '' //回复id } let url = getApiUrl2('comment/Delete') return DELETE(url, { ...defaultParam, ...param }) } //置顶 const stickFeedTop = ({ feed_id = '', titaObj_type = 2, titaObj_id = '' }) => { let url = getApiUrl2( `user/feed/Top?feed_id=${feed_id}&titaObj_type=${titaObj_type}&titaObj_id=${titaObj_id}` ) return POST(url) } //取消置顶 const cancelFeedTop = (param = {}) => { let defaultParam = { feed_id: '', //feedId titaObj_type: 2, //2租户 4项目 titaObj_id: '', //租户或项目的id ...param } //回复id let url = getApiUrl2('user/feed/CancelTop') return DELETE(url, defaultParam) } //删除feed const deleteFeed = (param = {}) => { let defaultParam = { feed_id: '' //feedId } let url = getApiUrl2('user/feed/Delete') return DELETE(url, { ...defaultParam, ...param }) } const collectFeed = (feedId: string) => { let url = getApiUrl2(`user/feed/Collect?feed_id=${feedId}`) return PUT(url) } const cancelCollectFeed = (feedId: string) => { let url = getApiUrl2(`user/feed/CancelCollect?feed_id=${feedId}`) return DELETE(url, {}) } // 发表分享 const handleShareBoxSubmit = ( textValue: string, fileList: string[], scope: number ) => { const url = getApiUrl2('user/feed/AddShare') const options = { Content: textValue, ObjType: scope == 1 ? 15 : 0, // 可见性为部门可见 ObjType为15 ObjId: scope == 1 ? getUserInfo().DepartmentId : 0, // 可见性为部门可见 ObjId为部门id FileUrls: fileList.join(','), Visibility: scope + 1, IsSendSMS: false } return POST(url, options) } // 获取emoji数据 const getEmojiData = () => { const url = getApiUrl('tenant/Eomticon?isvId=' + getBSGlobal('isv')) const formatData = (itemList: any) => { if (!itemList || !itemList.length) { return [] } const formatItem = (item: any) => { const iconList = item.emticons if (!iconList || !iconList.length) { return [] } return iconList.map((icon: { name: string; address: string }) => ({ title: icon.name, url: item.host + icon.address })) } let result = {} itemList.forEach((item: any) => (result[item.name] = formatItem(item))) return result } return GET(url).then(function(data) { const { Code, Data } = data if (Code === 1) { return formatData(Data.packages) } return null }) } // 处理动态 const handleSearchFeed = (value: string, channelId: number | string, startId: number | string) => { const api = getApiUrl('feedchannel/feeds/search') const options = { content: encodeURIComponent(value), channelId, startId, pageSize: 20, commentCount: 4, appObj_id: '', // user_id: BSGlobal.loginUserInfo.id, user_id: '112951054', version: 3 } return GET(api, options) } // 搜索人 const handleSearchUser = (user: { Id: number }, channelId: number | string, startId: number | string) => { const api = getApiUrl('feedchannel/feeds/searchbyuserid') const options = { channelId, searchUserId: user.Id, searchType: 1, startId, pageSize: 20, commentCount: 4, appObj_id: '', version: 3 } return GET(api, options) } // 发布回复 const handleReply = ( textValue: string, fileList: string[], FeedId: string, CommentId: string = '0' ) => { const url = getApiUrl2('comment/Add') const options = { FeedId, CommentId, Content: textValue, FileUrl: fileList.join(','), ObjId: 0, ObjType: 0, IsSendSMS: false } return POST(url, options) } // 发布任务 const saveTaskFeed = (data: any) => { const url = getBSGlobal('cloudHost') + 'mrest/Task/ItalentTask/100000/SimpleTask/SaveTaskFeed' return POST(url, data) } const getSingleFeedData = (feedId: string) => { const url = getApiUrl2( `user/feed/GetById?feed_id=${feedId}&comment_count=5&version=3` ) return GET(url) } var getProjectUsers = function(workId: string) { //获取项目相关成员 const url = getApiUrl2(`work/users?workId=${workId}`) return GET(url) } var getChannelList = function() { const url = getApiUrl('feedchannel/List') return GET(url) } export { getProjectUsers, getFeedData, getAllComment, deleteCommentById, stickFeedTop, cancelFeedTop, deleteFeed, getEmojiData, handleShareBoxSubmit, handleSearchFeed, handleSearchUser, handleReply, collectFeed, cancelCollectFeed, saveTaskFeed, getSingleFeedData, getChannelList }