portal html css js resource

resourceIssue.js 14KB

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