portal html css js resource

resourceIssue.js 14KB

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