Nav apraksta

resourceIssue.js 17KB

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