portal html css js resource

resourceIssue.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. $(document).ready(function() {
  2. var resourceId=GetQueryString("resourceId");
  3. if(resourceId) {
  4. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  5. getRecourceMe();
  6. }
  7. loginStatus(); //判断个人是否登录
  8. valUser();
  9. var userid = $.cookie("userid");
  10. var temp = [];
  11. var array=[];
  12. var hbur,hburEnd;
  13. ue = UE.getEditor('editor', {});
  14. /*获取资源信息*/
  15. function getRecourceMe() {
  16. $.ajax({
  17. "url": "/ajax/resource/queryOne",
  18. "type": "GET",
  19. "success": function(data) {
  20. console.log(data);
  21. if(data.success) {
  22. $("#uploadDd").siblings().remove();
  23. $("#fileList").append("<dd></dd><dd></dd>");
  24. temp=[];
  25. array=[];
  26. resourceHtml(data.data);
  27. }
  28. },
  29. "data": {
  30. "resourceId":resourceId
  31. },
  32. dataType: "json",
  33. 'error':function() {
  34. $.MsgBox.Alert('提示', '服务器连接超时!');
  35. }
  36. });
  37. }
  38. /*处理资源html代码*/
  39. function resourceHtml($da) {
  40. $("#resourceName").val($da.resourceName);//名字
  41. $("#application").val($da.supportedServices);//应用用途
  42. if($da.orgName) {//所属机构
  43. $("#organizationName").val($da.orgName);
  44. }
  45. if($da.comp) {//所属机构
  46. $("#organizationName").val($da.comp);
  47. }
  48. if($da.spec) {//厂商型号
  49. $("#modelNumber").val($da.spec);
  50. }
  51. if($da.parameter) {//性能参数
  52. $("#performancePa").val($da.parameter);
  53. }
  54. if($da.cooperationNotes) {//合作备注
  55. $("#remarkContent").val($da.cooperationNotes);
  56. }
  57. if($da.subject) {
  58. var oSub=$da.subject.split(",");
  59. var oSt="";
  60. for(var i=0;i<oSub.length;i++){
  61. oSt+='<li>'+oSub[i]+'<div class="closeThis"></div></li>'
  62. }
  63. $("#keyWordlist").html(oSt);
  64. if(oSub.length>4){
  65. $("#KeyWord").parent().addClass("displayNone");
  66. }
  67. }else{
  68. $("#keyWordlist").html("");
  69. }
  70. if($da.descp) {//编辑器
  71. ue.ready(function() {
  72. ue.setContent($da.descp);
  73. });
  74. }
  75. if($da.images.length) {
  76. var arr=[];
  77. for(var i=0;i<$da.images.length;i++) {
  78. var oString='<dd>' +
  79. '<div class="imgItem">'+
  80. '<img src="'+"/data/resource/"+$da.images[i].imageSrc+'"/>' +
  81. '</div>'+
  82. '<div class="file-panel">' +
  83. '<span class="cancel" flag=1></span>' +
  84. '</div>' +
  85. '</dd>'
  86. arr[i]=oString;
  87. array[i]=$da.images[i].imageId;
  88. }
  89. $("#fileList dd").eq(2).remove();
  90. if($da.images.length==1) {
  91. $("#fileList").prepend(arr[0]);
  92. }else if($da.images.length==2) {
  93. $("#fileList dd").eq(1).remove();
  94. $("#fileList").prepend(arr[1]);
  95. $("#fileList").prepend(arr[0]);
  96. }else if($da.images.length==3) {
  97. $("#fileList dd").eq(1).remove();
  98. $("#fileList").prepend(arr[2]);
  99. $("#fileList").prepend(arr[1]);
  100. $("#fileList").prepend(arr[0]);
  101. }
  102. }
  103. }
  104. var uploader = WebUploader.create({
  105. auto: true,
  106. fileNumLimit: 3,
  107. swf: '../js/webuploader/Uploader.swf',
  108. server: '../ajax/cachedFileUpload',
  109. fileSingleSizeLimit: 2 * 1024 * 1024,
  110. pick: {
  111. id: "#filePicker",
  112. multiple: false
  113. },
  114. accept: {
  115. title: 'Images',
  116. extensions: 'jpg,jpeg,png',
  117. mimeTypes: 'image/jpg,image/png'
  118. }
  119. });
  120. // 当有文件添加进来的时候
  121. uploader.on('fileQueued', function(file) {
  122. fileId = file.id;
  123. var $len = $("#fileList").find("img").length;
  124. if($len == 0 || $len == 1) {
  125. var oRemove = $("#fileList").find("dd");
  126. oRemove.eq(oRemove.length - 1).remove();
  127. }
  128. var $li = $(
  129. '<dd>' +
  130. '<div class="imgItem" id="' + file.id + '">'+
  131. '<img />' +
  132. '</div>'+
  133. //'<div class="info">' + file.name + '</div>' +
  134. '</dd>'
  135. ),
  136. $btns = $('<div class="file-panel">' +
  137. '<span class="cancel"></span>' +
  138. '</div>').appendTo($li),
  139. $img = $li.find('img');
  140. var $list = $("#fileList");
  141. if($len == 1) {
  142. $list.find("dd").eq(0).after($li)
  143. } else if($len == 2) {
  144. $list.find("dd").eq(1).after($li)
  145. } else {
  146. $list.prepend($li);
  147. }
  148. // 创建缩略图
  149. // 如果为非图片文件,可以不用调用此方法。
  150. // thumbnailWidth x thumbnailHeight 为 100 x 100
  151. uploader.makeThumb(file, function(error, src) {
  152. if(error) {
  153. $img.replaceWith('<span>不能预览</span>');
  154. return;
  155. }
  156. $img.attr('src', src);
  157. }, 1, 1);
  158. /*$li.on('mouseenter', function() {
  159. $btns.stop().animate({
  160. height: 30
  161. });
  162. });
  163. $li.on('mouseleave', function() {
  164. $btns.stop().animate({
  165. height: 0
  166. });
  167. });*/
  168. });
  169. uploader.onError = function(code) {
  170. console.log(code)
  171. $.MsgBox.Alert('提示', '请上传jpg、jpeg、png格式的图片,大小不超过2M')
  172. };
  173. uploader.on('uploadSuccess', function(file, data) {
  174. if(data.success) {
  175. uploader.removeFile(fileId);
  176. var cacheImageKey = temp.push(data.data[0].cacheKey);
  177. }else{
  178. $.MsgBox.Alert('提示', '只支持jpeg/jpg/png格式的图片');
  179. }
  180. });
  181. /*删除图片*/
  182. $("#fileList").on("click", ".cancel", function() {
  183. var flag=$(this).attr("flag");
  184. var oNum=$(this).parents("dd").index();
  185. if(flag==1) {
  186. array.splice(oNum,1);
  187. }else{
  188. temp.splice(oNum,1);
  189. }
  190. $(this).parent().parent().remove();
  191. var $len = $("#fileList").find("img").length;
  192. if($len != 2) {
  193. $("#fileList").append("<dd></dd>")
  194. }
  195. });
  196. /*资源名称*/
  197. $("#resourceName").bind({
  198. focus: function() {
  199. $("#resourceNamePrompt").show();
  200. },
  201. blur: function() {
  202. $("#resourceNamePrompt").hide();
  203. },
  204. keyup: function() {
  205. if($(this).val().length > 30) {
  206. $(this).val($(this).val().substr(0, 30));
  207. }
  208. }
  209. })
  210. hotKey(".oinput");
  211. //校验关键字
  212. $("#KeyWord").on({
  213. focus: function() {
  214. $("#keyPrompt").text("最多可添加5个关键词,每个关键词15字以内");
  215. },
  216. blur: function() {
  217. $("#keyPrompt").text("");
  218. }
  219. })
  220. $("#keyWordlist").on("click", ".closeThis", function() {
  221. $(this).parent().remove();
  222. var liNum = $("#keyWordlist").find("li").length;
  223. if(liNum < 5) {
  224. $("#keyWordlist").parents(".keyResult").siblings("div.col-w-12").show();
  225. }
  226. })
  227. /*应用用途*/
  228. $("#application").bind({
  229. focus: function() {
  230. $("#applicationPrompt").show();
  231. },
  232. blur: function() {
  233. $("#applicationPrompt").hide();
  234. },
  235. keyup: function() {
  236. if($(this).val().length > 50) {
  237. $(this).val($(this).val().substr(0, 50));
  238. }
  239. }
  240. })
  241. /*所属机构*/
  242. $("#organizationName").bind({
  243. focus: function() {
  244. $("#organization").show();
  245. $("#department").show();
  246. },
  247. blur: function() {
  248. $("#organization").hide();
  249. setTimeout(function(){
  250. $("#department").hide();
  251. },100)
  252. },
  253. keyup: function() {
  254. if($(this).val().length > 50) {
  255. $(this).val($(this).val().substr(0, 50));
  256. } else if(0 < $(this).val().length < 50) {
  257. $.ajax({
  258. "url": "/ajax/org/querylimit",
  259. "type": "GET",
  260. "success": function(data) {
  261. console.log(data);
  262. if(data.success) {
  263. if(data.data==null) {
  264. $("#department ul").html("");
  265. }else{
  266. addHtml(data.data);
  267. }
  268. }
  269. },
  270. "data": {
  271. name:$(this).val(),
  272. rows: 3
  273. },
  274. dataType: "json",
  275. 'error':function() {
  276. $.MsgBox.Alert('提示', '服务器连接超时!');
  277. }
  278. });
  279. }
  280. }
  281. })
  282. function addHtml($html) {
  283. var i=0;
  284. var oSum="";
  285. for( i in $html) {
  286. var oImg="";
  287. console.log($html[i].hasOrgLogo)
  288. if($html[i].hasOrgLogo) {
  289. oImg="/images/org/" + $html[i].id + ".jpg"
  290. }else{
  291. oImg="../images/default-icon.jpg"
  292. }
  293. oSum+='<li class="orgList"><img src="'+oImg+'" class="floatL" /><p class="h2Font floatL">'+$html[i].name+'</p></li>'
  294. }
  295. $("#department ul").html(oSum);
  296. }
  297. $("#department ul").on("click","li",function(){
  298. $("#organizationName").val($(this).find("p").text());
  299. $("#department ul").html("");
  300. })
  301. /*厂商型号*/
  302. $("#modelNumber").bind({
  303. focus: function() {
  304. $("#model").show();
  305. },
  306. blur: function() {
  307. $("#model").hide();
  308. },
  309. keyup: function() {
  310. if($(this).val().length > 50) {
  311. $(this).val($(this).val().substr(0, 50));
  312. }
  313. }
  314. });
  315. /*性能参数*/
  316. limitObj("#performancePa",200)
  317. /*合作备注*/
  318. limitObj("#remarkContent",200)
  319. /*发布*/
  320. $(".goFabu").click(function(){
  321. if($(this).hasClass("disableLi")){
  322. return;
  323. }
  324. var oYes=term();
  325. if(oYes==0) {
  326. return;
  327. }
  328. $.MsgBox.Confirm("提示", "确认发布该资源?",ajsPost);
  329. })
  330. /*预览*/
  331. $("#oPreview").click(function(){
  332. if($(this).hasClass("disableLi")){
  333. return;
  334. }
  335. var oYes=term();
  336. if(oYes==0) {
  337. return;
  338. }
  339. ajsPost("/ajax/resource/draft",1);
  340. })
  341. /*存草稿*/
  342. $("#oDraft").click(function(){
  343. if($(this).hasClass("disableLi")){
  344. return;
  345. }
  346. var oYes=term();
  347. if(oYes==0) {
  348. return;
  349. }
  350. ajsPost("/ajax/resource/draft",2);
  351. })
  352. /*删除*/
  353. $("#operateBlocko").on("click",".deleteResource",function(){
  354. $.MsgBox.Confirm("提示", "确认删除该资源?",deleResource);
  355. })
  356. /*删除函数*/
  357. function deleResource() {
  358. $.ajax({
  359. "url": "/ajax/resource/delete",
  360. "type": "POST",
  361. "success": function(data) {
  362. console.log(data)
  363. if(data.success) {
  364. location.href="resourceList.html"
  365. }
  366. },
  367. "data": {"resourceId":resourceId},
  368. "beforeSend": function() { /*console.log(this.data)*/ },
  369. "contentType": "application/x-www-form-urlencoded",
  370. dataType: "json"
  371. });
  372. }
  373. /*条件是否匹配*/
  374. function term(){
  375. var $len = $("#fileList").find("img").length;
  376. var reName=$("#resourceName").val();
  377. var oIndustry=$("#application").val();
  378. if($len==0) {
  379. $.MsgBox.Alert('提示', '请上传资源图片。');
  380. return 0;
  381. }
  382. if(reName=="") {
  383. $.MsgBox.Alert('提示', '请输入资源名称。');
  384. return 0;
  385. }
  386. if(oIndustry=="") {
  387. $.MsgBox.Alert('提示', '请输入应用用途。');
  388. return 0;
  389. }
  390. }
  391. /*发布函数*/
  392. function ajsPost(pa1,pa2) {
  393. var industrys = $("#keyWordlist li");
  394. var industryAll = "";
  395. if(industrys.size() > 0) {
  396. for(var i = 0; i < industrys.size(); i++) {
  397. industryAll += industrys[i].innerText.trim();
  398. industryAll += ',';
  399. };
  400. industryAll = industryAll.substring(0, industryAll.length - 1);
  401. }
  402. $(".operateBlock").find("li").addClass("disableLi");
  403. var oUrl="/ajax/resource/save";
  404. if(pa1) {
  405. oUrl=pa1
  406. }
  407. var $data = {};
  408. if(resourceId) {
  409. $data.resourceId=resourceId;
  410. }
  411. $data.professorId=userid;
  412. $data.resourceName = $("#resourceName").val();//资源名字
  413. $data.cooperationNotes = $("#remarkContent").val();//合作备注
  414. $data.subject = industryAll;
  415. console.log($data.subject);
  416. $data.supportedServices=$("#application").val();
  417. $data.orgName=$("#organizationName").val();
  418. $data.spec=$("#modelNumber").val();
  419. $data.parameter=$("#performancePa").val();
  420. $data.descp=ue.getContent();
  421. $data.fns=temp;
  422. $data.imageIds=array;
  423. //$data.imageIds:资源图片ID NULL 字符串数组
  424. console.log(temp);
  425. $.ajax({
  426. "url": oUrl,
  427. "type": "POST",
  428. "complete":function(){
  429. $(".operateBlock").find("li").removeClass("disableLi");
  430. },
  431. "success": function(data) {
  432. console.log(data)
  433. if(data.success) {
  434. if(pa2==1) {
  435. resourceId=data.data;
  436. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  437. window.open("resourcePreview.html?resourceId="+data.data);
  438. getRecourceMe();
  439. //弹出预览
  440. }else if(pa2==2) {
  441. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  442. resourceId=data.data;
  443. $.MsgBox.Alert('提示', '资源已保存草稿。');
  444. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  445. getRecourceMe();
  446. }else{
  447. $.MsgBox.Alert('提示', '资源发布成功!');
  448. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  449. location.href="resourceList.html"
  450. }
  451. }else{
  452. if(data.code==90) {
  453. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  454. }
  455. }
  456. },
  457. "data": $data,
  458. "beforeSend": function() { /*console.log(this.data)*/ },
  459. "contentType": "application/x-www-form-urlencoded",
  460. "traditional":true,
  461. dataType: "json"
  462. });
  463. }
  464. })