Friend.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. 问题:
  3. 1、整套好友的功能流程图
  4. 2、设计缺少流程 只有大流程 没有那个按钮的细节流程
  5. */
  6. Namespace.register("U.MD.F"); //好友主命名空间
  7. //#region 初始化好友
  8. //初始化好友函数
  9. /**
  10. * 初始化加载好友
  11. */
  12. U.MD.F.initFriend = U.MD.F.CSHFG = function () {
  13. //如果第三方应用1473,包含了好友窗体。
  14. if ($("#U_MD_F_H_Z")[0]) {
  15. var i,
  16. _friendinfo,
  17. _selectbottomel,
  18. _childsel,
  19. _chatform = $("#U_MD_F_H_Z")[0], //好友窗体
  20. _userinfoel = $("#U_MD_F_H_ZLTI", _chatform)[0]; //多好友分栏
  21. //初始化出现右边的好友聊天
  22. U.MD.F.W.friendDisplayAndNone([{
  23. "display": "none",
  24. "left": "auto"
  25. },
  26. {
  27. "display": "block",
  28. "top": (US.height - 530) / 2,
  29. "right": "0px"
  30. }],
  31. true);
  32. //添加当前使用用户的头像
  33. $($("img", _userinfoel)[0] || $$("img")).addAttrArray({
  34. "onerror": U.MD.C.imgError,
  35. "src": U.MD.C.getHeadImage(US.userInfo.UserThumbnailImageHead),
  36. "onclick": U.MD.U.P.userDataSet
  37. }).appendTo(_userinfoel);
  38. if (US.friend.recentcontacts.length) {
  39. _friendinfo = US.friend.recentcontacts;
  40. }
  41. else {
  42. _friendinfo = US.friend.friends;
  43. }
  44. //右侧好友最近联系人
  45. U.MD.F.printRightFormFriend(_friendinfo, $("#U_MD_F_H_RC")[0]);
  46. //我的好友、我的群组等按钮,默认显示我的好友 所以找到我的好友的按钮,并且默认调用onclick
  47. _selectbottomel = $("#U_MD_F_H_ZLTA").Child()[0];
  48. $(_selectbottomel).Child()[0].onclick();
  49. }
  50. }
  51. /**
  52. * 初始化右边好友出现
  53. *
  54. * @param {object} 好友头像处理
  55. * @param {element} 元素处理
  56. */
  57. U.MD.F.printRightFormFriend = function (friendinfo, el) {
  58. var i,
  59. _tempel,
  60. _temponeel,
  61. _frag = $$("frag"),
  62. _childs = $(el).Child();
  63. //如果是用户登录多次,移除之前残留的信息
  64. for (i = 1; i < _childs.length; i++) {
  65. el.removeChild(_childs[i]);
  66. }
  67. //如果有好友资料输出
  68. if (friendinfo.length) {
  69. //循环打印好友资料
  70. for (i = 0; (i < friendinfo.length && i < 11); i++) {
  71. if (friendinfo[i].tf == 1) {
  72. friendinfo[i] = U.Json.select(US.friend.group, { "GroupManageID": friendinfo[i].UserId })[0];
  73. _friendoneel = $$("div", { "className": "U_MD_F_H_ZLZOCOI", "style": { "margin": "9px 0 0 10px" }, "title": friendinfo[i].GroupManageName, "onclick": U.UF.C.closure(function (friendinfo) {
  74. U.UF.EV.stopBubble();
  75. U.MD.F.N.CanelMarkMessage(friendinfo.GroupManageID);
  76. U.MD.F.W.popupFriendsForm(friendinfo);
  77. }, [friendinfo[i]])
  78. }, _frag);
  79. U.MD.F.printGroupHeadImage(friendinfo[i], _friendoneel, 4, [35, 35]);
  80. } else {
  81. $$("img",
  82. {
  83. "onerror": U.MD.C.imgError,
  84. "title": friendinfo[i]["FriendsDescript"],
  85. "className": "U_MD_F_H_RCI",
  86. "src": U.MD.C.getHeadImage(friendinfo[i].UserThumbnailImageHead),
  87. "alt": friendinfo[i].FriendsDescript || friendinfo[i].UserNickName,
  88. "onclick": U.UF.C.closure(function (friendinfo) {
  89. U.UF.EV.stopBubble();
  90. U.MD.F.W.popupFriendsForm(friendinfo);
  91. U.MD.F.N.CanelMarkMessage(friendinfo.UserID);
  92. }, [friendinfo[i]])
  93. }, _frag);
  94. }
  95. }
  96. }
  97. //暂无好友追随
  98. else {
  99. _tempel = $$("div", { "className": "U_MD_F_H_RCT" }, _frag);
  100. _temponeel = $$("div", { "className": "U_MD_F_H_RCTS" }, _tempel);
  101. $$("img", { "onerror": U.MD.C.imgError, "src": "/img/YSUN.png" }, _temponeel);
  102. $$("div", { "className": "U_MD_F_H_RCTZ U_Img" }, _tempel);
  103. $$("div", { "className": "U_MD_F_H_RCTX", "innerHTML": "暂时无追随" }, _tempel);
  104. }
  105. var _tipsicon = $$("div", { className: "U_MD_D_NewsTipsIcon" }, _frag);
  106. el.appendChild(_frag);
  107. }
  108. /**
  109. * 用户列表好友打印
  110. *
  111. * @param {elem_frag元素11
  112. */
  113. U.MD.F.printFriendGroupOrFriend = function (el) {
  114. var i,
  115. _tempel,
  116. _temponeel,
  117. _classinfo,
  118. _friendinfo = US.friend.allclass,
  119. _frag = $$("frag");
  120. el.innerText = "";
  121. //如果用户有好友则打印
  122. if (US.friend.friends.length) {
  123. //循环打印好友分组
  124. for (i = 0; i < _friendinfo.length; i++) {
  125. _classinfo = U.Json.select(US.friend.friends, { "FriendsGroupID": _friendinfo[i].FriendsGroupID }); //根据好友分组获取好友
  126. //打印好友分组
  127. _tempel = $$("div",
  128. {
  129. id: "g" + _friendinfo[i].FriendsGroupID,
  130. "TID": _friendinfo[i].FriendsGroupID,
  131. "className": "U_MD_F_H_ZLZO"
  132. },
  133. _frag);
  134. $$("div",
  135. {
  136. "className": "U_MD_F_H_ZLZOT",
  137. "innerHTML": _friendinfo[i].FriendsGroupName + "(" + _classinfo.length + ")",
  138. "onclick": U.UF.C.closure(function (i) {
  139. U.MD.F.openOrCloseFriendClass(this);
  140. }, [i]),
  141. "oncontextmenu": U.UF.C.closure(function (i) {
  142. U.MD.F.R.friendClassRightClickMenu(US.friend.allclass[i], this);
  143. }, [i])
  144. },
  145. _tempel);
  146. _temponeel = $$("div", { "className": "U_MD_F_H_ZLZOC" }, _tempel);
  147. //打印好友
  148. U.MD.F.printFriendOrGroup(_temponeel, _classinfo);
  149. }
  150. }
  151. //无好友打印提示
  152. else {
  153. U.MD.F.printHasNoFriend(_frag);
  154. }
  155. el.appendChild(_frag);
  156. }
  157. /**
  158. * 好友和群样式输出
  159. *
  160. * @param {element} 元素
  161. * @param {array} 好友数组
  162. */
  163. U.MD.F.printFriendOrGroup = function (el, friendorgroupinfo, isinsert) {
  164. var i,
  165. _isfront,
  166. _friendel,
  167. _friendoneel,
  168. _friendtwoel,
  169. _onlinefrag = $$("frag"),
  170. _offlinefrag = $$("frag");
  171. //循环所有的好友或者群,打印到左边好友或群面板中
  172. if (friendorgroupinfo.length == 0) {
  173. $$("div", { "class": "U_MD_F_H_ZLZOCO_under", "style": { "margin": "9px 0 0 10px" }, "innerHTML": "最近暂无任何聊天" }, el);
  174. } else {
  175. for (i = 0; i < friendorgroupinfo.length; i++) {
  176. if (friendorgroupinfo[i].tf == 1) {
  177. friendorgroupinfo[i] = U.Json.select(US.friend.group, { "GroupManageID": friendorgroupinfo[i].UserId })[0]
  178. }
  179. _friendel = $$("div",
  180. {
  181. "className": "U_MD_F_H_ZLZOCO",
  182. "onclick": U.UF.C.closure(function (friendorgroupinfo) {
  183. U.MD.F.N.CanelMarkMessage(friendorgroupinfo);
  184. U.MD.F.W.popupFriendsForm(friendorgroupinfo, this);
  185. }, [friendorgroupinfo[i]]),
  186. "TID": friendorgroupinfo[i].GroupManageID || friendorgroupinfo[i].UserId,
  187. "oncontextmenu": U.UF.C.closure(function (friendorgroupinfo) {
  188. alert();
  189. if (friendorgroupinfo.UserId) {
  190. U.MD.F.R.friendsRightClickMenu(this, friendorgroupinfo);
  191. } else if (friendorgroupinfo.GroupManageID) {
  192. U.MD.F.R.GroupRightClickMenu(this, friendorgroupinfo);
  193. }
  194. }, [friendorgroupinfo[i]])
  195. });
  196. _friendoneel = $$("div", { "className": "U_MD_F_H_ZLZOCOI" }, _friendel);
  197. //如果是群的处理,群的头像输出
  198. if (friendorgroupinfo[i].GroupManageID) {
  199. U.MD.F.printGroupHeadImage(U.Json.select(US.friend.group, { "GroupManageID": friendorgroupinfo[i].GroupManageID || friendorgroupinfo[i].UserId })[0], _friendoneel, 4, [35, 35]);
  200. }
  201. //好友头像输出
  202. else {
  203. $$("img",
  204. {
  205. "onerror": U.MD.C.imgError,
  206. "title": "点击查看",
  207. "src": U.MD.C.getHeadImage(friendorgroupinfo[i].UserThumbnailImageHead)
  208. },
  209. _friendoneel);
  210. }
  211. _friendtwoel = $$("div", { "className": "U_MD_F_H_ZLZOCOR U_MD_D_Text_Abbreviation" }, _friendel);
  212. $$("div", { "className": "U_MD_F_H_ZLZOCORN U_MD_D_Text_Abbreviation", "innerHTML": friendorgroupinfo[i].FriendsDescript || friendorgroupinfo[i].UserNickName || friendorgroupinfo[i].GroupManageName }, _friendtwoel);
  213. $$("div", { "className": "U_MD_F_H_ZLZOCORT U_MD_D_Text_Abbreviation", "innerHTML": friendorgroupinfo[i].UserIndividualitysignature || (friendorgroupinfo[i].GroupManageDescript == friendorgroupinfo[i].GroupManageName ? "" : friendorgroupinfo[i].GroupManageDescript) || "" }, _friendtwoel);
  214. //如果用户在线那么插入到最前面
  215. if (friendorgroupinfo[i].IsLogin == 1) {
  216. _onlinefrag.appendChild(_friendel);
  217. }
  218. //否则插入到后面
  219. else {
  220. _offlinefrag.appendChild(_friendel);
  221. }
  222. }
  223. el.insertBefore(_onlinefrag, el.firstChild); //在线用户插入到最前面
  224. //如果需要插入到最前面,那么则不管在不在线的用户都插入到最前面
  225. if (isinsert) {
  226. el.insertBefore(_offlinefrag, el.firstChild); //用户插入到最前面
  227. }
  228. else {
  229. el.appendChild(_offlinefrag); //非在线用户插入到最后米娜
  230. }
  231. }
  232. }
  233. /**
  234. * 打开分组展开好友
  235. *
  236. * @param {element} 展开好友的区域
  237. */
  238. U.MD.F.openOrCloseFriendClass = function (el) {
  239. var _firendel = $($(el).Parent()).Child()[1]; //获取好友分组对应的好友元素
  240. //如果现在隐藏了则打开
  241. if (_firendel.style.display == "none") {
  242. _firendel.style.display = "block";
  243. }
  244. //如果是显示则隐藏
  245. else {
  246. _firendel.style.display = "none";
  247. }
  248. }
  249. /**
  250. * 打印空好友
  251. *
  252. * @param {element} 打印的区域
  253. */
  254. U.MD.F.printHasNoFriend = function (el) {
  255. var _tempel,
  256. _temponeel
  257. ;
  258. _tempel = $$("div", { "className": "U_MD_F_H_ZLZT" }, el);
  259. _temponeel = $$("div", { "className": "U_MD_F_H_ZLZTS" }, _tempel);
  260. $$("img", { "onerror": U.MD.C.imgError, "src": "/img/YSUN.png" }, _temponeel);
  261. $$("div", { "className": "U_MD_F_H_ZLZTZ U_Img" }, _tempel);
  262. $$("div", { "className": "U_MD_F_H_ZLZTX", "innerHTML": "暂时没有添加追随!!" }, _tempel);
  263. }
  264. //#endregion
  265. //#region 好友功能
  266. /**
  267. * 打印空好友
  268. *
  269. * @param {string} 切换类型
  270. * @param {element} 点钱点击的区域
  271. * @param {element} 变化的样式
  272. */
  273. U.MD.F.switchFriendOrGroup = function (typename, el, classname) {
  274. var i,
  275. _chatform = $("#U_MD_F_H_ZLZ")[0], //打印内容区域
  276. _childsel = $(el).parentElement(2).Child(), //所有参与切换的元素
  277. _classarray = ["U_MD_F_H_ZLTO", "U_MD_F_H_ZLTT", "U_MD_F_H_ZLTS", "U_MD_F_H_ZLTF"]; //切换样式数组
  278. //切换按钮的样式,把样式改成用户默认按钮的样式
  279. for (i = 0; i < _childsel.length; i++) {
  280. $(_childsel[i]).Child()[0].className = _classarray[i] + " U_Img U_MD_F_H_ZLTOK";
  281. }
  282. //设置选中的按钮样式
  283. el.className = classname + " U_Img U_MD_F_H_ZLTOK";
  284. //点击好友添加按钮
  285. if (typename == "A") {
  286. U.MD.F.M.createFriendGroupPopup(); //调用创建群弹框
  287. }
  288. else {
  289. //群成员
  290. if (typename == "H") {
  291. var _grouparr = US.friend.group; //获取用户或有群信息
  292. _chatform.innerText = ""; //清空展示区域的内容
  293. U.MD.F.printFriendOrGroup(_chatform, _grouparr); //打印
  294. }
  295. //最近联系人
  296. else if (typename == "G") {
  297. var _recentcontacts = US.friend.recentcontacts;
  298. _chatform.innerText = ""; //清空展示区域的内容
  299. U.MD.F.printFriendOrGroup(_chatform, _recentcontacts); //打印
  300. }
  301. //打印好友,由于好友有好友分组,所以不能直接调用U.MD.F.printFriendOrGroup输出
  302. else {
  303. U.MD.F.printFriendGroupOrFriend(_chatform); //打印
  304. }
  305. }
  306. }
  307. /*
  308. if (j == _value.length) {
  309. U.MD.F.printFriendOrGroup(_chatform, _grouparr); //打印
  310. _grouparr.splice(0, _grouparr.length);
  311. }
  312. */
  313. /**
  314. * 获取群里头像集
  315. *
  316. * @param {object} 群信息
  317. * @param {element} 添加指定的元素
  318. * @param {element} 变化的样式
  319. * @param {element} 最大长度
  320. */
  321. U.MD.F.printGroupHeadImage = function (groupinfo, el, num, size) {
  322. var i, j,
  323. _groupnameel,
  324. _horizontal,
  325. _vertical,
  326. _imageel,
  327. _groupuserinfo = U.Json.select(US.friend.groupusers, { "GroupManageID": groupinfo.GroupManageID }, (num || 9)); //获取当前群
  328. if (_groupuserinfo.length < 3) {
  329. _horizontal = _groupuserinfo.length;
  330. } else {
  331. if (_groupuserinfo.length > 6) {
  332. _horizontal = 3;
  333. } else {
  334. _horizontal = 2;
  335. }
  336. } //每排几个
  337. if (_groupuserinfo.length > 4) {
  338. _vertical = 3
  339. } else {
  340. if (_groupuserinfo.length > 1) {
  341. _vertical = 2
  342. } else {
  343. _vertical = 1
  344. }
  345. } //一共多少行
  346. size = size || [el.offsetHeight || 40, el.offsetWidth || 40]; //最大长宽
  347. _groupnameel = $$("div", { "className": "U_MD_HomeSSZFZAIO", "title": groupinfo.GroupManageName }); //群名
  348. //打印所有群成员头像 横排打印
  349. for (i = 0; i < _horizontal; i++) {
  350. _imageel = $$("div", { "style": { "width": "100%", "height": Math.floor(size[0] / _horizontal) + "px"} }, _groupnameel);
  351. //竖排打印
  352. for (j = i * _vertical; j < i * _vertical + _vertical && j < _groupuserinfo.length; j++) {
  353. $$("img",
  354. {
  355. "onerror": U.MD.C.imgError,
  356. "src": U.MD.C.getHeadImage(_groupuserinfo[j].UserThumbnailImageHead),
  357. "style":
  358. {
  359. "width": Math.floor(size[1] / _vertical) + "px",
  360. "height": Math.floor(size[0] / _vertical) + "px"
  361. }
  362. }, _imageel);
  363. }
  364. };
  365. //追加
  366. el.appendChild(_groupnameel);
  367. }
  368. //#endregion