portal html css js resource

resourceIssue.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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().text('最多可添加5个关键词,每个关键词10字以内');
  198. },
  199. blur: function() {
  200. $("#keywordPrompt").text('');
  201. },
  202. keyup: function() {
  203. var lNum=$.trim($(this).val()).length;
  204. console.log(lNum);
  205. if(lNum > 10) {
  206. $(this).val($(this).val().substr(0, 10));
  207. } else if(0 < lNum&& lNum < 10) {
  208. $("#addKeyword").show();
  209. $.ajax({
  210. "url": "/ajax/dataDict/qaHotKey",
  211. "type": "GET",
  212. "success": function(data) {
  213. console.log(data);
  214. if(data.success) {
  215. if(data.data.length==0) {
  216. $("#keyList").addClass("displayNone");
  217. $("#keyList ul").html("");
  218. }else{
  219. $("#keyList").removeClass("displayNone");
  220. var oSr="";
  221. for(var i=0;i<data.data.length;i++) {
  222. oSr+='<li><p class="h2Font">'+data.data[i].caption+'</p></li>'
  223. }
  224. $("#keyList ul").html(oSr);
  225. }
  226. }else {
  227. $("#keyList ul").html("");
  228. }
  229. },
  230. "data": {
  231. "key":$(this).val()
  232. },
  233. dataType: "json",
  234. 'error':function() {
  235. $.MsgBox.Alert('提示', '服务器连接超时!');
  236. }
  237. });
  238. }else if(lNum == 0){
  239. $("#addKeyword").hide();
  240. $("#keyList ul").html("");
  241. }
  242. }
  243. });
  244. $("#keyList ul").on("click","li",function(){
  245. keyWord($(this).find("p").text());
  246. $("#keyList ul").html("");
  247. $("#keyList").addClass("displayNone");
  248. $("#addKeyword").hide();
  249. })
  250. /*添加关键词*/
  251. $("#addKeyword").click(function() {
  252. keyWord($("#keywordName").val());
  253. })
  254. function keyWord(atl) {
  255. var oKeywordName = $.trim(atl);
  256. var keywordListLength = $("#keywordList").find("li");
  257. if(oKeywordName.length == 0) {
  258. $("#keywordPrompt").text('关键词输入不能为空');
  259. return;
  260. }
  261. for(var i = 0; i < keywordListLength.length; i++) {
  262. if(oKeywordName == keywordListLength.find("p").eq(i).text()) {
  263. $("#keywordPrompt").text('该关键词已存在');
  264. return;
  265. }
  266. }
  267. $("#keyList ul").html("");
  268. $("#addKeyword").hide();
  269. var oStr = '<li><p class="h2Font">' + oKeywordName + '</p><div class="closeThis"></div></li>'
  270. $("#keywordList").append(oStr);
  271. $("#keywordName").val("");
  272. if((keywordListLength.length + 1) == 5) {
  273. $("#keywordHide").hide();
  274. $("#keyList").css("border-top","none");
  275. }
  276. }
  277. /*删除关键词*/
  278. $("#keywordList").on("click", ".closeThis", function() {
  279. $(this).parent().remove();
  280. var keywordListLength = $("#keywordList").find("li");
  281. if(keywordListLength.length < 5) {
  282. $("#keywordHide").show();
  283. $("#keyList").css("border-top","1px solid #E5E5E5");
  284. }
  285. });
  286. /*应用用途*/
  287. $("#application").bind({
  288. focus: function() {
  289. $("#applicationPrompt").show();
  290. },
  291. blur: function() {
  292. $("#applicationPrompt").hide();
  293. },
  294. keyup: function() {
  295. if($(this).val().length > 50) {
  296. $(this).val($(this).val().substr(0, 50));
  297. }
  298. }
  299. })
  300. /*所属机构*/
  301. $("#organizationName").bind({
  302. focus: function() {
  303. $("#organization").show();
  304. $("#department").show();
  305. },
  306. blur: function() {
  307. $("#organization").hide();
  308. setTimeout(function(){
  309. $("#department").hide();
  310. },100)
  311. },
  312. keyup: function() {
  313. if($(this).val().length > 50) {
  314. $(this).val($(this).val().substr(0, 50));
  315. } else if(0 < $(this).val().length < 50) {
  316. $.ajax({
  317. "url": "/ajax/org/querylimit",
  318. "type": "GET",
  319. "success": function(data) {
  320. console.log(data);
  321. if(data.success) {
  322. if(data.data==null) {
  323. $("#department ul").html("");
  324. }else{
  325. addHtml(data.data);
  326. }
  327. }
  328. },
  329. "data": {
  330. name:$(this).val(),
  331. rows: 3
  332. },
  333. dataType: "json",
  334. 'error':function() {
  335. $.MsgBox.Alert('提示', '服务器连接超时!');
  336. }
  337. });
  338. }
  339. }
  340. })
  341. function addHtml($html) {
  342. var i=0;
  343. var oSum="";
  344. for( i in $html) {
  345. var oImg="";
  346. console.log($html[i].hasOrgLogo)
  347. if($html[i].hasOrgLogo) {
  348. oImg="/images/org/" + $html[i].id + ".jpg"
  349. }else{
  350. oImg="../images/default-icon.jpg"
  351. }
  352. oSum+='<li class="orgList"><img src="'+oImg+'" class="floatL" /><p class="h2Font floatL">'+$html[i].name+'</p></li>'
  353. }
  354. $("#department ul").html(oSum);
  355. }
  356. $("#department ul").on("click","li",function(){
  357. $("#organizationName").val($(this).find("p").text());
  358. $("#department ul").html("");
  359. })
  360. /*厂商型号*/
  361. $("#modelNumber").bind({
  362. focus: function() {
  363. $("#model").show();
  364. },
  365. blur: function() {
  366. $("#model").hide();
  367. },
  368. keyup: function() {
  369. if($(this).val().length > 50) {
  370. $(this).val($(this).val().substr(0, 50));
  371. }
  372. }
  373. });
  374. function para(sel1, sel2, sel3) {
  375. $(sel1).bind({
  376. focus: function() {
  377. $(sel2).show();
  378. },
  379. blur: function() {
  380. $(sel2).hide();
  381. },
  382. keyup: function(e) {
  383. if($(this).val().length > 200) {
  384. $(this).val($(this).val().substring(0, 200));
  385. e.preventDefault();
  386. }
  387. setTimeout(function() {
  388. $(sel3).text($(sel1).val().length);
  389. }, 1);
  390. }
  391. });
  392. }
  393. /*性能参数*/
  394. para("#performancePa", "#performance", "#entry1");
  395. /*合作备注*/
  396. para('#remarkContent', '#remark', '#entry2');
  397. /*发布*/
  398. $(".goFabu").click(function(){
  399. var oYes=term();
  400. if(oYes==0) {
  401. return;
  402. }
  403. $.MsgBox.Confirm("提示", "确认发布该资源?",ajsPost);
  404. })
  405. /*预览*/
  406. $("#oPreview").click(function(){
  407. var oYes=term();
  408. if(oYes==0) {
  409. return;
  410. }
  411. ajsPost("/ajax/resource/draft",1);
  412. })
  413. /*存草稿*/
  414. $("#oDraft").click(function(){
  415. var oYes=term();
  416. if(oYes==0) {
  417. return;
  418. }
  419. ajsPost("/ajax/resource/draft",2);
  420. })
  421. /*删除*/
  422. $("#operateBlocko").on("click",".deleteResource",function(){
  423. $.MsgBox.Confirm("提示", "确认删除该资源?",deleResource);
  424. })
  425. /*删除函数*/
  426. function deleResource() {
  427. $.ajax({
  428. "url": "/ajax/resource/delete",
  429. "type": "POST",
  430. "success": function(data) {
  431. console.log(data)
  432. if(data.success) {
  433. location.href="resourceList.html"
  434. }
  435. },
  436. "data": {"resourceId":resourceId},
  437. "beforeSend": function() { /*console.log(this.data)*/ },
  438. "contentType": "application/x-www-form-urlencoded",
  439. dataType: "json"
  440. });
  441. }
  442. /*条件是否匹配*/
  443. function term(){
  444. var $len = $("#fileList").find("img").length;
  445. var reName=$("#resourceName").val();
  446. var oIndustry=$("#application").val();
  447. if($len==0) {
  448. $.MsgBox.Alert('提示', '请上传资源图片。');
  449. return 0;
  450. }
  451. if(reName=="") {
  452. $.MsgBox.Alert('提示', '请输入资源名称。');
  453. return 0;
  454. }
  455. if(oIndustry=="") {
  456. $.MsgBox.Alert('提示', '请输入应用用途。');
  457. return 0;
  458. }
  459. }
  460. /*发布函数*/
  461. function ajsPost(pa1,pa2) {
  462. var oUrl="/ajax/resource/save";
  463. if(pa1) {
  464. oUrl=pa1
  465. }
  466. var $data = {};
  467. if(resourceId) {
  468. $data.resourceId=resourceId;
  469. }
  470. $data.professorId=userid;
  471. $data.resourceName = $("#resourceName").val();//资源名字
  472. $data.cooperationNotes = $("#remarkContent").val();//合作备注
  473. $data.subject = captiureSubInd("keywordList p");
  474. console.log($data.subject);
  475. $data.supportedServices=$("#application").val();
  476. $data.orgName=$("#organizationName").val();
  477. $data.spec=$("#modelNumber").val();
  478. $data.parameter=$("#performancePa").val();
  479. $data.descp=ue.getContent();
  480. $data.fns=temp;
  481. $data.imageIds=array;
  482. //$data.imageIds:资源图片ID NULL 字符串数组
  483. console.log(temp);
  484. $.ajax({
  485. "url": oUrl,
  486. "type": "POST",
  487. "success": function(data) {
  488. console.log(data)
  489. if(data.success) {
  490. if(pa2==1) {
  491. resourceId=data.data;
  492. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  493. window.open("resourcePreview.html?resourceId="+data.data);
  494. //弹出预览
  495. }else if(pa2==2) {
  496. $("#deleteResource").removeClass("disableLi").addClass("deleteResource");
  497. resourceId=data.data;
  498. $.MsgBox.Alert('提示', '资源已保存草稿。');
  499. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  500. }else{
  501. $.MsgBox.Alert('提示', '资源发布成功!');
  502. $("#mb_msgicon").css("background", 'url("images/sign_icon_chenggong_nor.png") 0% 0% / contain');
  503. location.href="resourceList.html"
  504. }
  505. }
  506. },
  507. "data": $data,
  508. "beforeSend": function() { /*console.log(this.data)*/ },
  509. "contentType": "application/x-www-form-urlencoded",
  510. "traditional":true,
  511. dataType: "json"
  512. });
  513. }
  514. function captiureSubInd(subIndu) {
  515. var industrys = $("#" + subIndu + "");
  516. var industryAll = "";
  517. if(industrys.size() > 0) {
  518. for(var i = 0; i < industrys.size(); i++) {
  519. industryAll += industrys[i].innerText;
  520. industryAll += ',';
  521. };
  522. industryAll = industryAll.substring(0, industryAll.length - 1);
  523. }
  524. return industryAll;
  525. }
  526. })