portal html css js resource

resourceIssue.js 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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><p class="h2Font">'+oSub[i]+'</p><div class="closeThis"></div></li>'
  62. }
  63. $("#keywordList").html(oSt);
  64. }else{
  65. $("#keywordList").html("");
  66. }
  67. if($da.descp) {//编辑器
  68. ue.ready(function() {
  69. ue.setContent($da.descp);
  70. });
  71. }
  72. if($da.images.length) {
  73. var arr=[];
  74. for(var i=0;i<$da.images.length;i++) {
  75. var oString='<dd>' +
  76. '<div class="imgItem">'+
  77. '<img src="'+"/data/resource/"+$da.images[i].imageSrc+'"/>' +
  78. '</div>'+
  79. '<div class="file-panel">' +
  80. '<span class="cancel" flag=1></span>' +
  81. '</div>' +
  82. '</dd>'
  83. arr[i]=oString;
  84. array[i]=$da.images[i].imageId;
  85. }
  86. $("#fileList dd").eq(2).remove();
  87. if($da.images.length==1) {
  88. $("#fileList").prepend(arr[0]);
  89. }else if($da.images.length==2) {
  90. $("#fileList dd").eq(1).remove();
  91. $("#fileList").prepend(arr[1]);
  92. $("#fileList").prepend(arr[0]);
  93. }else if($da.images.length==3) {
  94. $("#fileList dd").eq(1).remove();
  95. $("#fileList").prepend(arr[2]);
  96. $("#fileList").prepend(arr[1]);
  97. $("#fileList").prepend(arr[0]);
  98. }
  99. }
  100. }
  101. var uploader = WebUploader.create({
  102. auto: true,
  103. fileNumLimit: 3,
  104. swf: '../js/webuploader/Uploader.swf',
  105. server: '../ajax/cachedFileUpload',
  106. fileSingleSizeLimit: 2 * 1024 * 1024,
  107. pick: {
  108. id: "#filePicker",
  109. multiple: false
  110. },
  111. accept: {
  112. title: 'Images',
  113. extensions: 'jpg,jpeg,png',
  114. mimeTypes: 'image/jpg,image/png'
  115. }
  116. });
  117. // 当有文件添加进来的时候
  118. uploader.on('fileQueued', function(file) {
  119. fileId = file.id;
  120. var $len = $("#fileList").find("img").length;
  121. if($len == 0 || $len == 1) {
  122. var oRemove = $("#fileList").find("dd");
  123. oRemove.eq(oRemove.length - 1).remove();
  124. }
  125. var $li = $(
  126. '<dd>' +
  127. '<div class="imgItem" id="' + file.id + '">'+
  128. '<img />' +
  129. '</div>'+
  130. //'<div class="info">' + file.name + '</div>' +
  131. '</dd>'
  132. ),
  133. $btns = $('<div class="file-panel">' +
  134. '<span class="cancel"></span>' +
  135. '</div>').appendTo($li),
  136. $img = $li.find('img');
  137. var $list = $("#fileList");
  138. if($len == 1) {
  139. $list.find("dd").eq(0).after($li)
  140. } else if($len == 2) {
  141. $list.find("dd").eq(1).after($li)
  142. } else {
  143. $list.prepend($li);
  144. }
  145. // 创建缩略图
  146. // 如果为非图片文件,可以不用调用此方法。
  147. // thumbnailWidth x thumbnailHeight 为 100 x 100
  148. uploader.makeThumb(file, function(error, src) {
  149. if(error) {
  150. $img.replaceWith('<span>不能预览</span>');
  151. return;
  152. }
  153. $img.attr('src', src);
  154. }, 1, 1);
  155. /*$li.on('mouseenter', function() {
  156. $btns.stop().animate({
  157. height: 30
  158. });
  159. });
  160. $li.on('mouseleave', function() {
  161. $btns.stop().animate({
  162. height: 0
  163. });
  164. });*/
  165. });
  166. uploader.onError = function(code) {
  167. console.log(code)
  168. $.MsgBox.Alert('提示', '请上传jpg、jpeg、png格式的图片,大小不超过2M')
  169. };
  170. uploader.on('uploadSuccess', function(file, data) {
  171. if(data.success) {
  172. uploader.removeFile(fileId);
  173. var cacheImageKey = temp.push(data.data[0].cacheKey);
  174. }else{
  175. $.MsgBox.Alert('提示', '只支持jpeg/jpg/png格式的图片');
  176. }
  177. });
  178. /*删除图片*/
  179. $("#fileList").on("click", ".cancel", function() {
  180. var flag=$(this).attr("flag");
  181. var oNum=$(this).parents("dd").index();
  182. if(flag==1) {
  183. array.splice(oNum,1);
  184. }else{
  185. temp.splice(oNum,1);
  186. }
  187. $(this).parent().parent().remove();
  188. var $len = $("#fileList").find("img").length;
  189. if($len != 2) {
  190. $("#fileList").append("<dd></dd>")
  191. }
  192. });
  193. /*资源名称*/
  194. $("#resourceName").bind({
  195. focus: function() {
  196. $("#resourceNamePrompt").show();
  197. },
  198. blur: function() {
  199. $("#resourceNamePrompt").hide();
  200. },
  201. keyup: function() {
  202. if($(this).val().length > 30) {
  203. $(this).val($(this).val().substr(0, 30));
  204. }
  205. }
  206. })
  207. /*关键词*/
  208. $("#keywordName").bind({
  209. focus: function() {
  210. $("#keywordPrompt").show().text('最多可添加5个关键词,每个关键词15字以内');
  211. },
  212. blur: function() {
  213. $("#keywordPrompt").text('');
  214. },
  215. keyup: function() {
  216. var ti=$(this).val();
  217. hbur=ti;
  218. var lNum=$.trim($(this).val()).length;
  219. console.log(lNum);
  220. if(lNum > 15) {
  221. $(this).val($(this).val().substr(0, 15));
  222. } else if(0 < lNum&& lNum < 15) {
  223. $("#addKeyword").show();
  224. setTimeout(function(){
  225. if( ti===hbur && ti!== hburEnd) {
  226. var tt=ti;
  227. hburEnd=tt;
  228. $.ajax({
  229. "url": "/ajax/dataDict/qaHotKey",
  230. "type": "GET",
  231. "success": function(data) {
  232. console.log(data);
  233. if(data.success) {
  234. if(hburEnd == tt){
  235. if(data.data.length==0) {
  236. $("#keyList").addClass("displayNone");
  237. $("#keyList ul").html("");
  238. }else{
  239. $("#keyList").removeClass("displayNone");
  240. var oSr="";
  241. for(var i=0;i<Math.min(data.data.length,5);i++) {
  242. oSr+='<li><p class="h2Font">'+data.data[i].caption+'</p></li>'
  243. }
  244. $("#keyList ul").html(oSr);
  245. }
  246. }
  247. }else {
  248. $("#keyList ul").html("");
  249. }
  250. },
  251. "data": {
  252. "key":$('#keywordName').val()
  253. },
  254. dataType: "json",
  255. 'error':function() {
  256. $.MsgBox.Alert('提示', '服务器连接超时!');
  257. }
  258. });
  259. }
  260. },500)
  261. }else if(lNum == 0){
  262. $("#addKeyword").hide();
  263. $("#keyList ul").html("");
  264. }
  265. }
  266. });
  267. $("#keyList ul").on("click","li",function(){
  268. keyWord($(this).find("p").text());
  269. $("#keyList ul").html("");
  270. $("#keyList").addClass("displayNone");
  271. $("#addKeyword").hide();
  272. })
  273. /*添加关键词*/
  274. $("#addKeyword").click(function() {
  275. keyWord($("#keywordName").val());
  276. })
  277. function keyWord(atl) {
  278. var oKeywordName = $.trim(atl);
  279. var keywordListLength = $("#keywordList").find("li");
  280. if(oKeywordName.length == 0) {
  281. $("#keywordPrompt").text('关键词输入不能为空');
  282. return;
  283. }
  284. for(var i = 0; i < keywordListLength.length; i++) {
  285. if(oKeywordName == keywordListLength.find("p").eq(i).text()) {
  286. $("#keywordPrompt").text('该关键词已存在');
  287. return;
  288. }
  289. }
  290. $("#keyList ul").html("");
  291. $("#addKeyword").hide();
  292. var oStr = '<li><p class="h2Font">' + oKeywordName + '</p><div class="closeThis"></div></li>'
  293. $("#keywordList").append(oStr);
  294. $("#keywordName").val("");
  295. if((keywordListLength.length + 1) == 5) {
  296. $("#keywordHide").hide();
  297. $("#keyList").css("border-top","none");
  298. }
  299. }
  300. /*删除关键词*/
  301. $("#keywordList").on("click", ".closeThis", function() {
  302. $(this).parent().remove();
  303. var keywordListLength = $("#keywordList").find("li");
  304. if(keywordListLength.length < 5) {
  305. $("#keywordHide").show();
  306. $("#keyList").css("border-top","1px solid #E5E5E5");
  307. }
  308. });
  309. /*应用用途*/
  310. $("#application").bind({
  311. focus: function() {
  312. $("#applicationPrompt").show();
  313. },
  314. blur: function() {
  315. $("#applicationPrompt").hide();
  316. },
  317. keyup: function() {
  318. if($(this).val().length > 50) {
  319. $(this).val($(this).val().substr(0, 50));
  320. }
  321. }
  322. })
  323. /*所属机构*/
  324. $("#organizationName").bind({
  325. focus: function() {
  326. $("#organization").show();
  327. $("#department").show();
  328. },
  329. blur: function() {
  330. $("#organization").hide();
  331. setTimeout(function(){
  332. $("#department").hide();
  333. },100)
  334. },
  335. keyup: function() {
  336. if($(this).val().length > 50) {
  337. $(this).val($(this).val().substr(0, 50));
  338. } else if(0 < $(this).val().length < 50) {
  339. $.ajax({
  340. "url": "/ajax/org/querylimit",
  341. "type": "GET",
  342. "success": function(data) {
  343. console.log(data);
  344. if(data.success) {
  345. if(data.data==null) {
  346. $("#department ul").html("");
  347. }else{
  348. addHtml(data.data);
  349. }
  350. }
  351. },
  352. "data": {
  353. name:$(this).val(),
  354. rows: 3
  355. },
  356. dataType: "json",
  357. 'error':function() {
  358. $.MsgBox.Alert('提示', '服务器连接超时!');
  359. }
  360. });
  361. }
  362. }
  363. })
  364. function addHtml($html) {
  365. var i=0;
  366. var oSum="";
  367. for( i in $html) {
  368. var oImg="";
  369. console.log($html[i].hasOrgLogo)
  370. if($html[i].hasOrgLogo) {
  371. oImg="/images/org/" + $html[i].id + ".jpg"
  372. }else{
  373. oImg="../images/default-icon.jpg"
  374. }
  375. oSum+='<li class="orgList"><img src="'+oImg+'" class="floatL" /><p class="h2Font floatL">'+$html[i].name+'</p></li>'
  376. }
  377. $("#department ul").html(oSum);
  378. }
  379. $("#department ul").on("click","li",function(){
  380. $("#organizationName").val($(this).find("p").text());
  381. $("#department ul").html("");
  382. })
  383. /*厂商型号*/
  384. $("#modelNumber").bind({
  385. focus: function() {
  386. $("#model").show();
  387. },
  388. blur: function() {
  389. $("#model").hide();
  390. },
  391. keyup: function() {
  392. if($(this).val().length > 50) {
  393. $(this).val($(this).val().substr(0, 50));
  394. }
  395. }
  396. });
  397. /*性能参数*/
  398. limitObj("#performancePa",200)
  399. /*合作备注*/
  400. limitObj("#remarkContent",200)
  401. /*发布*/
  402. $(".goFabu").click(function(){
  403. if($(this).hasClass("disableLi")){
  404. return;
  405. }
  406. var oYes=term();
  407. if(oYes==0) {
  408. return;
  409. }
  410. $.MsgBox.Confirm("提示", "确认发布该资源?",ajsPost);
  411. })
  412. /*预览*/
  413. $("#oPreview").click(function(){
  414. if($(this).hasClass("disableLi")){
  415. return;
  416. }
  417. var oYes=term();
  418. if(oYes==0) {
  419. return;
  420. }
  421. ajsPost("/ajax/resource/draft",1);
  422. })
  423. /*存草稿*/
  424. $("#oDraft").click(function(){
  425. if($(this).hasClass("disableLi")){
  426. return;
  427. }
  428. var oYes=term();
  429. if(oYes==0) {
  430. return;
  431. }
  432. ajsPost("/ajax/resource/draft",2);
  433. })
  434. /*删除*/
  435. $("#operateBlocko").on("click",".deleteResource",function(){
  436. $.MsgBox.Confirm("提示", "确认删除该资源?",deleResource);
  437. })
  438. /*删除函数*/
  439. function deleResource() {
  440. $.ajax({
  441. "url": "/ajax/resource/delete",
  442. "type": "POST",
  443. "success": function(data) {
  444. console.log(data)
  445. if(data.success) {
  446. location.href="resourceList.html"
  447. }
  448. },
  449. "data": {"resourceId":resourceId},
  450. "beforeSend": function() { /*console.log(this.data)*/ },
  451. "contentType": "application/x-www-form-urlencoded",
  452. dataType: "json"
  453. });
  454. }
  455. /*条件是否匹配*/
  456. function term(){
  457. var $len = $("#fileList").find("img").length;
  458. var reName=$("#resourceName").val();
  459. var oIndustry=$("#application").val();
  460. if($len==0) {
  461. $.MsgBox.Alert('提示', '请上传资源图片。');
  462. return 0;
  463. }
  464. if(reName=="") {
  465. $.MsgBox.Alert('提示', '请输入资源名称。');
  466. return 0;
  467. }
  468. if(oIndustry=="") {
  469. $.MsgBox.Alert('提示', '请输入应用用途。');
  470. return 0;
  471. }
  472. }
  473. /*发布函数*/
  474. function ajsPost(pa1,pa2) {
  475. $(".operateBlock").find("li").addClass("disableLi");
  476. var oUrl="/ajax/resource/save";
  477. if(pa1) {
  478. oUrl=pa1
  479. }
  480. var $data = {};
  481. if(resourceId) {
  482. $data.resourceId=resourceId;
  483. }
  484. $data.professorId=userid;
  485. $data.resourceName = $("#resourceName").val();//资源名字
  486. $data.cooperationNotes = $("#remarkContent").val();//合作备注
  487. $data.subject = captiureSubInd("keywordList p");
  488. console.log($data.subject);
  489. $data.supportedServices=$("#application").val();
  490. $data.orgName=$("#organizationName").val();
  491. $data.spec=$("#modelNumber").val();
  492. $data.parameter=$("#performancePa").val();
  493. $data.descp=ue.getContent();
  494. $data.fns=temp;
  495. $data.imageIds=array;
  496. //$data.imageIds:资源图片ID NULL 字符串数组
  497. console.log(temp);
  498. $.ajax({
  499. "url": oUrl,
  500. "type": "POST",
  501. "complete":function(){
  502. $(".operateBlock").find("li").removeClass("disableLi");
  503. },
  504. "success": function(data) {
  505. console.log(data)
  506. if(data.success) {
  507. if(pa2==1) {
  508. resourceId=data.data;
  509. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  510. window.open("resourcePreview.html?resourceId="+data.data);
  511. getRecourceMe();
  512. //弹出预览
  513. }else if(pa2==2) {
  514. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  515. resourceId=data.data;
  516. $.MsgBox.Alert('提示', '资源已保存草稿。');
  517. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  518. getRecourceMe();
  519. }else{
  520. $.MsgBox.Alert('提示', '资源发布成功!');
  521. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  522. location.href="resourceList.html"
  523. }
  524. }else{
  525. if(data.code==90) {
  526. $.MsgBox.Alert('提示', '由于操作时间过久,上传图片已失效,请重新上传。');
  527. }
  528. }
  529. },
  530. "data": $data,
  531. "beforeSend": function() { /*console.log(this.data)*/ },
  532. "contentType": "application/x-www-form-urlencoded",
  533. "traditional":true,
  534. dataType: "json"
  535. });
  536. }
  537. function captiureSubInd(subIndu) {
  538. var industrys = $("#" + subIndu + "");
  539. var industryAll = "";
  540. if(industrys.size() > 0) {
  541. for(var i = 0; i < industrys.size(); i++) {
  542. industryAll += industrys[i].innerText;
  543. industryAll += ',';
  544. };
  545. industryAll = industryAll.substring(0, industryAll.length - 1);
  546. }
  547. return industryAll;
  548. }
  549. })