Common.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. MWF.xApplication.Forum = MWF.xApplication.Forum || {};
  2. window.MWFForum = MWF.xApplication.Forum;
  3. MWFForum.getDateDiff = function (publishTime, justNowStr) {
  4. if(!publishTime)return "";
  5. var dateTimeStamp = Date.parse(publishTime.replace(/-/gi, "/"));
  6. var minute = 1000 * 60;
  7. var hour = minute * 60;
  8. var day = hour * 24;
  9. var halfamonth = day * 15;
  10. var month = day * 30;
  11. var year = month * 12;
  12. var now = new Date().getTime();
  13. var diffValue = now - dateTimeStamp;
  14. if (diffValue < 0) {
  15. //若日期不符则弹出窗口告之
  16. //alert("结束日期不能小于开始日期!");
  17. }
  18. var yesterday = new Date().decrement('day', 1);
  19. var beforYesterday = new Date().decrement('day', 2);
  20. var yearC = diffValue / year;
  21. var monthC = diffValue / month;
  22. var weekC = diffValue / (7 * day);
  23. var dayC = diffValue / day;
  24. var hourC = diffValue / hour;
  25. var minC = diffValue / minute;
  26. if (yesterday.getFullYear() == dateTimeStamp.getFullYear() && yesterday.getMonth() == dateTimeStamp.getMonth() && yesterday.getDate() == dateTimeStamp.getDate()) {
  27. result = MWF.xApplication.Forum.LP.yesterday + " " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  28. } else if (beforYesterday.getFullYear() == dateTimeStamp.getFullYear() && beforYesterday.getMonth() == dateTimeStamp.getMonth() && beforYesterday.getDate() == dateTimeStamp.getDate()) {
  29. result = MWF.xApplication.Forum.LP.twoDaysAgo + " " + dateTimeStamp.getHours() + ":" + dateTimeStamp.getMinutes();
  30. } else if (yearC > 1) {
  31. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  32. } else if (monthC >= 1) {
  33. //result= parseInt(monthC) + "个月前";
  34. // s.getFullYear()+"年";
  35. result = dateTimeStamp.getFullYear() + "-" + (dateTimeStamp.getMonth() + 1) + "-" + dateTimeStamp.getDate();
  36. } else if (weekC >= 1) {
  37. result = parseInt(weekC) + MWF.xApplication.Forum.LP.weekAgo;
  38. } else if (dayC >= 1) {
  39. result = parseInt(dayC) + MWF.xApplication.Forum.LP.dayAgo;
  40. } else if (hourC >= 1) {
  41. result = parseInt(hourC) + MWF.xApplication.Forum.LP.hourAgo;
  42. } else if (minC >= 1) {
  43. result = parseInt(minC) + MWF.xApplication.Forum.LP.minuteAgo;
  44. } else
  45. result = justNowStr || MWF.xApplication.Forum.LP.publishJustNow;
  46. return result;
  47. };
  48. MWFForum.getDateDiff2 = function (publishTime) {
  49. return MWFForum.getDateDiff( publishTime, MWF.xApplication.Forum.LP.justNow );
  50. };
  51. MWFForum.BBS_LOGO_NAME = "BBS_LOGO_NAME";
  52. MWFForum.BBS_SUBJECT_TYPECATAGORY = "BBS_SUBJECT_TYPECATAGORY";
  53. MWFForum.BBS_TITLE_TAIL = "BBS_TITLE_TAIL";
  54. MWFForum.BBS_USE_NICKNAME = "BBS_USE_NICKNAME";
  55. MWFForum.BBS_ANONYMOUS_PERMISSION = "BBS_ANONYMOUS_PERMISSION";
  56. MWFForum.enableAnonymousSubject = function(){
  57. return MWFForum.getSystemConfigValue( MWFForum.BBS_ANONYMOUS_PERMISSION ) === "YES";
  58. }
  59. MWFForum.isSubjectMuted = function( usecache ){
  60. if( usecache && o2.typeOf( MWFForum.isMuted ) === "boolean" ){
  61. return MWFForum.isMuted;
  62. }
  63. o2.Actions.load("x_bbs_assemble_control").ShutupAction.getShutup(function(json){
  64. debugger;
  65. // json.data = {
  66. // "id": "a13843ac-0700-4a94-b7d9-a85e6fca131b",
  67. // "operator": "蔡祥熠@cxy@P",
  68. // "person": "龚新民@91eed25b-8891-4ba6-b234-a70ed97c42ae@P",
  69. // "unmuteDate": "2022-05-25",
  70. // "reason": "888",
  71. // "createTime": "2022-05-24 16:09:48",
  72. // "updateTime": "2022-05-24 16:09:48"
  73. // };
  74. var d = json.data || {};
  75. MWFForum.muteData = d;
  76. if( d.unmuteDate && (new Date(d.unmuteDate + " 00:00:00") > new Date())){
  77. MWFForum.isMuted = true;
  78. }else{
  79. MWFForum.isMuted = false;
  80. }
  81. }, null, false);
  82. if( o2.typeOf( MWFForum.isMuted ) !== "boolean" ){
  83. MWFForum.isMuted = false;
  84. }
  85. return MWFForum.isMuted;
  86. }
  87. MWFForum.isReplyMuted = function(){
  88. return MWFForum.isSubjectMuted( true );
  89. }
  90. MWFForum.isUseNickName = function(){
  91. return MWFForum.getSystemConfigValue( MWFForum.BBS_USE_NICKNAME ) === "YES";
  92. };
  93. MWFForum.Nick_Name_Map = {};
  94. MWFForum.getDisplayName = function( dn ){
  95. if( !dn || dn === layout.desktop.session.user.distinguishedName){
  96. dn = layout.desktop.session.user.distinguishedName;
  97. if( MWFForum.isUseNickName() ){
  98. return layout.desktop.session.user.nickName || dn.split("@")[0];
  99. }else{
  100. return dn.split("@")[0];
  101. }
  102. }else{
  103. if( MWFForum.isUseNickName() ){
  104. if( MWFForum.Nick_Name_Map[dn] )return MWFForum.Nick_Name_Map[dn];
  105. return o2.Actions.load("x_organization_assemble_express").PersonAction.getNickName( dn ).then(function (json) {
  106. MWFForum.Nick_Name_Map[dn] = json.data.value;
  107. return MWF.name.cn(json.data.value);
  108. }).catch(function () {
  109. return "";
  110. })
  111. }else{
  112. return dn.split("@")[0];
  113. }
  114. }
  115. };
  116. MWFForum.getSubjectCreatorName = function(d){
  117. return o2.name.cn( MWFForum.isUseNickName() ? (d.nickName || d.creatorName): d.creatorName );
  118. };
  119. MWFForum.getLastReplyUserName = function(d){
  120. return o2.name.cn( MWFForum.isUseNickName() ? (d.latestReplyUserNickName || d.latestReplyUser): d.latestReplyUser );
  121. };
  122. MWFForum.isSubjectEditor = function(d){
  123. var dn = layout.desktop.session.user.distinguishedName;
  124. return d.creatorName === dn || (d.editorList || []).contains(dn);
  125. };
  126. MWFForum.getReplyCreatorName = function(d){
  127. return o2.name.cn( MWFForum.isUseNickName() ? (d.nickName || d.creatorName): d.creatorName );
  128. };
  129. MWFForum.openPersonCenter = function( userName, data ){
  130. if( data && ( data.anonymousSubject || data.anonymousReply ) ){
  131. return;
  132. }
  133. if( MWFForum.isUseNickName() && userName!=="xadmin" ){
  134. o2.Actions.load("x_organization_assemble_express").PersonAction.listObject(
  135. { personList : [userName]}
  136. ).then(function(json){
  137. if( !json.data || !json.data.length )return;
  138. var flag = json.data[0].id;
  139. var appId = "ForumPerson"+flag;
  140. if (layout.desktop.apps[appId]){
  141. layout.desktop.apps[appId].setCurrent();
  142. }else {
  143. layout.desktop.openApplication(null, "ForumPerson", {
  144. "p" : flag,
  145. "appId": appId
  146. });
  147. }
  148. })
  149. }else{
  150. var appId = "ForumPerson"+userName;
  151. if (layout.desktop.apps[appId]){
  152. layout.desktop.apps[appId].setCurrent();
  153. }else {
  154. layout.desktop.openApplication(null, "ForumPerson", {
  155. "personName" : userName,
  156. "appId": appId
  157. });
  158. }
  159. }
  160. };
  161. MWFForum.getSystemConfig = function( code ){
  162. if( !MWFForum.SystemSetting )MWFForum.SystemSetting = {};
  163. if( typeOf( MWFForum.SystemSetting[code] ) !== "null" )return MWFForum.SystemSetting[code];
  164. o2.Actions.load("x_bbs_assemble_control").BBSConfigSettingAction.getByCode( {configCode : code }, function(json) {
  165. MWFForum.SystemSetting[code] = json.data;
  166. }.bind(this), function(){
  167. MWFForum.SystemSetting[code] = "";
  168. return true;
  169. }, false );
  170. return MWFForum.SystemSetting[code];
  171. };
  172. MWFForum.getSystemConfigValue = function( code ){
  173. var config = MWFForum.getSystemConfig(code);
  174. if( config && config.configValue ){
  175. return config.configValue;
  176. }else{
  177. return "";
  178. }
  179. };
  180. MWFForum.getBBSName = function(){
  181. if( typeOf( MWFForum.BBSName ) !== "null" )return MWFForum.BBSName;
  182. o2.Actions.load("x_bbs_assemble_control").BBSConfigSettingAnonymousAction.getBBSName( function(json) {
  183. MWFForum.BBSName = (json.data || {}).configValue;
  184. }.bind(this), function(){
  185. MWFForum.BBSName = "";
  186. }, false );
  187. return MWFForum.BBSName;
  188. };