portal html css js resource

resourceIssue.js 15KB

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