国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

742 lines
24KB

  1. var fixupPos = false;
  2. var canMove = false;
  3. var leftLeaning = 0;
  4. //异步上传缩略图相关变量
  5. var nForm = null;
  6. var nFrame = null;
  7. var picnameObj = null;
  8. var vImg = null;
  9. function $Nav() {
  10. if (window.navigator.userAgent.indexOf("MSIE") >= 1) return 'IE';
  11. else if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
  12. else return "OT";
  13. }
  14. function $Obj(objname) {
  15. return document.getElementById(objname);
  16. }
  17. function ColorSel(c, oname) {
  18. var tobj = $Obj(oname);
  19. if (!tobj) tobj = eval('document.form1.' + oname);
  20. if (!tobj) {
  21. $Obj('colordlg').style.display = 'none';
  22. return false;
  23. } else {
  24. tobj.value = c;
  25. $Obj('colordlg').style.display = 'none';
  26. return true;
  27. }
  28. }
  29. function ShowColor(e, o) {
  30. LoadNewDiv(e, '../../static/web/img/colornew.htm', 'colordlg');
  31. }
  32. function ShowHide(objname) {
  33. var obj = $Obj(objname);
  34. if (obj.style.display != "none") obj.style.display = "none";
  35. else obj.style.display = "inline-block";
  36. }
  37. function ShowHideT(objname) {
  38. var obj = $Obj(objname);
  39. if (obj.style.display != "none") obj.style.display = "none";
  40. else obj.style.display = ($Nav() == "IE" ? "inline-block" : "table");
  41. }
  42. function ShowObj(objname) {
  43. var obj = $Obj(objname);
  44. if (obj == null) return false;
  45. obj.style.display = ($Nav() == "IE" ? "inline-block" : "table");
  46. }
  47. function ShowObjRow(objname) {
  48. var obj = $Obj(objname);
  49. obj.style.display = ($Nav() == "IE" ? "inline-block" : "table-row");
  50. }
  51. function AddTypeid2() {
  52. ShowObjRow('typeid2tr');
  53. }
  54. function HideObj(objname) {
  55. var obj = $Obj(objname);
  56. if (obj == null) return false;
  57. obj.style.display = "none";
  58. }
  59. function ShowItem1() {
  60. ShowObj('needset'); ShowObj('head1'); HideObj('head2'); HideObj('adset'); ShowObj('votehead');
  61. }
  62. function ShowItem2() {
  63. ShowObj('head2'); ShowObj('adset'); HideObj('voteset'); HideObj('head1'); HideObj('needset'); HideObj('votehead');
  64. }
  65. function SeePic(img, f) {
  66. if (f.value != '') img.src = f.value;
  67. }
  68. function SeePicNew(f, imgdid, frname, hpos, acname) {
  69. var newobj = null;
  70. if (f.value == '') return;
  71. vImg = $Obj(imgdid);
  72. picnameObj = document.getElementById('picname');
  73. nFrame = $Nav() == 'IE' ? eval('document.frames.' + frname) : $Obj(frname);
  74. nForm = f.form;
  75. //修改form的action等参数
  76. if (nForm.detachEvent) nForm.detachEvent("onsubmit", checkSubmit);
  77. else nForm.removeEventListener("submit", checkSubmit, false);
  78. nForm.action = 'archives_do.php';
  79. nForm.target = frname;
  80. nForm.dopost.value = 'uploadLitpic';
  81. nForm.submit();
  82. picnameObj.value = '';
  83. newobj = $Obj('uploadwait');
  84. if (!newobj) {
  85. newobj = document.createElement("DIV");
  86. newobj.id = 'uploadwait';
  87. newobj.style.position = 'absolute';
  88. newobj.className = 'uploadwait';
  89. newobj.style.width = 120;
  90. newobj.style.height = 20;
  91. newobj.style.top = hpos;
  92. newobj.style.left = 100;
  93. newobj.style.display = 'block';
  94. document.body.appendChild(newobj);
  95. newobj.innerHTML = '<img src="../../static/web/img/loadinglit.gif" alit="" />上传中...';
  96. }
  97. newobj.style.display = 'block';
  98. //提交后还原form的action等参数
  99. nForm.action = acname;
  100. nForm.dopost.value = 'save';
  101. nForm.target = '';
  102. nForm.litpic.disabled = true;
  103. }
  104. function SelectFlash() {
  105. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 300; var posTop = window.event.clientY; }
  106. else { var posLeft = 100; var posTop = 100; }
  107. window.open("./dialog/select_media.php?f=form1.flashurl", "popUpFlashWin", "scrollbars=yes,resizable=yes,statebar=no,width=500,height=350,left=" + posLeft + ", top=" + posTop);
  108. }
  109. function SelectMedia(fname) {
  110. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 200; var posTop = window.event.clientY; }
  111. else { var posLeft = 100; var posTop = 100; }
  112. window.open("./dialog/select_media.php?f=" + fname, "popUpFlashWin", "scrollbars=yes,resizable=yes,statebar=no,width=500,height=350,left=" + posLeft + ", top=" + posTop);
  113. }
  114. function SelectSoft(fname) {
  115. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 200; var posTop = window.event.clientY - 50; }
  116. else { var posLeft = 100; var posTop = 100; }
  117. window.open("./dialog/select_soft.php?f=" + fname, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left=" + posLeft + ", top=" + posTop);
  118. }
  119. function SelectImage(fname, stype, imgsel) {
  120. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 100; var posTop = window.event.clientY; }
  121. else { var posLeft = 100; var posTop = 100; }
  122. if (!fname) fname = 'form1.picname';
  123. if (imgsel) imgsel = '&noeditor=yes';
  124. if (!stype) stype = '';
  125. window.open("./dialog/select_images.php?f=" + fname + "&noeditor=yes&imgstick=" + stype + imgsel, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=650,height=400,left=" + posLeft + ", top=" + posTop);
  126. }
  127. function imageCut(fname) {
  128. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 100; var posTop = window.event.clientY; }
  129. else { var posLeft = 100; var posTop = 100; }
  130. if (!fname) fname = 'picname';
  131. file = document.getElementById(fname).value;
  132. if (file == '') {
  133. alert('请先选择网站内已上传的图片');
  134. return false;
  135. }
  136. window.open("imagecut.php?f=" + fname + "&file=" + file, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + posLeft + ", top=" + posTop);
  137. }
  138. function SelectImageN(fname, stype, vname) {
  139. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 100; var posTop = window.event.clientY; }
  140. else { var posLeft = 100; var posTop = 100; }
  141. if (!fname) fname = 'form1.picname';
  142. if (!stype) stype = '';
  143. window.open("./dialog/select_images.php?f=" + fname + "&imgstick=" + stype + "&v=" + vname, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=400,left=" + posLeft + ", top=" + posTop);
  144. }
  145. function SelectKeywords(f) {
  146. if ($Nav() == 'IE') { var posLeft = window.event.clientX - 350; var posTop = window.event.clientY - 200; }
  147. else { var posLeft = 100; var posTop = 100; }
  148. window.open("article_keywords_select.php?f=" + f, "popUpkwWin", "scrollbars=yes,resizable=yes,statebar=no,width=600,height=450,left=" + posLeft + ", top=" + posTop);
  149. }
  150. function InitPage() {
  151. var selsource = $Obj('selsource');
  152. var selwriter = $Obj('selwriter');
  153. var titlechange = $Obj('title');
  154. var colorbt = $Obj('color');
  155. if (selsource) { selsource.onmousedown = function (e) { SelectSource(e); } }
  156. if (selwriter) { selwriter.onmousedown = function (e) { SelectWriter(e); } }
  157. if (titlechange) { titlechange.onchange = function (e) { TestHasTitle(e); } }
  158. }
  159. function OpenMyWin(surl) {
  160. window.open(surl, "popUpMyWin", "scrollbars=yes,resizable=yes,statebar=no,width=500,height=350,left=200, top=100");
  161. }
  162. function OpenMyWinCoOne(surl) {
  163. window.open(surl, "popUpMyWin2", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=450,left=100,top=50");
  164. }
  165. function PutSource(str) {
  166. var osource = $Obj('source');
  167. if (osource) osource.value = str;
  168. $Obj('mysource').style.display = 'none';
  169. ChangeFullDiv('hide');
  170. }
  171. function PutWriter(str) {
  172. var owriter = $Obj('writer');
  173. if (owriter) owriter.value = str;
  174. $Obj('mywriter').style.display = 'none';
  175. ChangeFullDiv('hide');
  176. }
  177. //增加选择投票内容
  178. function PutVote(str) {
  179. var ovote = $Obj('voteid');
  180. if (ovote) {
  181. ovote.value = str;
  182. tb_remove(false);
  183. } else {
  184. parent.document.form1.voteid.value = str;
  185. tb_remove(true);
  186. }
  187. }
  188. function ClearDivCt(objname) {
  189. if (!$Obj(objname)) return;
  190. $Obj(objname).innerHTML = '';
  191. $Obj(objname).style.display = 'none';
  192. ChangeFullDiv("hide");
  193. }
  194. function ChangeFullDiv(showhide, screenheigt) {
  195. var newobj = $Obj('fullpagediv');
  196. if (showhide == 'show') {
  197. if (!newobj) {
  198. newobj = document.createElement("DIV");
  199. newobj.id = 'fullpagediv';
  200. newobj.style.position = 'absolute';
  201. newobj.className = 'fullpagediv';
  202. newobj.style.height = document.body.clientHeight + 50 + 'px';
  203. document.body.appendChild(newobj);
  204. } else {
  205. newobj.style.display = 'block';
  206. }
  207. } else {
  208. if (newobj) newobj.style.display = 'none';
  209. }
  210. }
  211. function SelectSource(e) {
  212. LoadNewDiv(e, 'article_select_sw.php?t=source&k=8&rnd=' + Math.random(), 'mysource');
  213. }
  214. function SelectWriter(e) {
  215. LoadNewDiv(e, 'article_select_sw.php?t=writer&k=8&rnd=' + Math.random(), 'mywriter');
  216. }
  217. function LoadNewDiv(e, surl, oname) {
  218. var pxStr = '';
  219. if ($Nav() == 'IE') {
  220. var posLeft = window.event.clientX - 20;
  221. var posTop = window.event.clientY - 30;
  222. // IE下scrollTop的兼容性问题
  223. var scrollTop = document.documentElement.scrollTop || window.pageYOffset;
  224. if (typeof (scrollTop) == 'undefined') scrollTop = document.body.scrollTop;
  225. posTop += scrollTop;
  226. } else {
  227. var posLeft = e.pageX - 20;
  228. var posTop = e.pageY - 30;
  229. pxStr = 'px';
  230. }
  231. posLeft = posLeft - 100;
  232. var newobj = $Obj(oname);
  233. if (!newobj) {
  234. newobj = document.createElement("DIV");
  235. newobj.id = oname;
  236. newobj.style.position = 'absolute';
  237. newobj.className = oname;
  238. newobj.className += ' dlgws';
  239. newobj.style.top = posTop + pxStr;
  240. newobj.style.left = posLeft + pxStr;
  241. document.body.appendChild(newobj);
  242. } else {
  243. newobj.style.display = "block";
  244. }
  245. if (newobj.innerHTML.length < 10) {
  246. fetch(surl).then(resp=>resp.text()).then((d)=>{newobj.innerHTML = d});
  247. }
  248. }
  249. function TestHasTitle(e) {
  250. LoadNewDiv2(e, 'article_test_title.php?t=' + $Obj('title').value, 'mytitle', "dlgTesttitle");
  251. }
  252. function LoadNewDiv2(e, surl, oname, dlgcls) {
  253. var posLeft = 300;
  254. var posTop = 50;
  255. var newobj = $Obj(oname);
  256. if (!newobj) {
  257. newobj = document.createElement("DIV");
  258. newobj.id = oname;
  259. newobj.style.position = 'absolute';
  260. newobj.className = dlgcls;
  261. newobj.style.top = posTop;
  262. newobj.style.left = posLeft;
  263. newobj.style.display = 'none';
  264. document.body.appendChild(newobj);
  265. }
  266. newobj.innerHTML = '';
  267. fetch(surl).then(resp=>resp.text()).then((d)=>{
  268. newobj.innerHTML = d;
  269. });
  270. if (newobj.innerHTML == '') newobj.style.display = 'none';
  271. else newobj.style.display = 'block';
  272. jQuery(newobj).css('top', '50px').css('left', '300px');
  273. DedeXHTTP = null;
  274. }
  275. function ShowUrlTr() {
  276. var jumpTest = $Obj('flagsj');
  277. var jtr = $Obj('redirecturltr');
  278. var jf = $Obj('redirecturl');
  279. if (jumpTest.checked) jtr.style.display = "block";
  280. else {
  281. jf.value = '';
  282. jtr.style.display = "none";
  283. }
  284. }
  285. function ShowUrlTrEdit() {
  286. ShowUrlTr();
  287. var jumpTest = $Obj('isjump');
  288. var rurl = $Obj('redirecturl');
  289. if (!jumpTest.checked) rurl.value = "";
  290. }
  291. function CkRemote() {
  292. document.getElementById('picname').value = '';
  293. }
  294. //载入指定宽高的AJAX窗体
  295. function LoadQuickDiv(e, surl, oname, w, h) {
  296. if ($Nav() == 'IE') {
  297. if (window.event) {
  298. var posLeft = window.event.clientX - 20;
  299. var posTop = window.event.clientY - 30;
  300. } else {
  301. var posLeft = e.clientX - 20;
  302. var posTop = e.clientY + 30;
  303. }
  304. } else {
  305. var posLeft = e.pageX - 20;
  306. var posTop = e.pageY - 30;
  307. }
  308. posTop += MyGetScrollTop();
  309. posLeft = posLeft - 400;
  310. //固定位置的高度
  311. if (fixupPos) {
  312. posLeft = posTop = 50;
  313. }
  314. var newobj = $Obj(oname);
  315. if (!newobj) {
  316. newobj = document.createElement("DIV");
  317. newobj.id = oname;
  318. newobj.style.position = 'absolute';
  319. newobj.className = 'pubdlg';
  320. newobj.style.width = w;
  321. newobj.style.height = h + 30;
  322. document.body.appendChild(newobj);
  323. }
  324. if (posTop > 500) posTop = 500;
  325. if (posLeft < 50) posLeft = 50;
  326. newobj.style.minWidth = "450px";
  327. newobj.style.top = posTop + "px";
  328. newobj.style.left = posLeft + "px";
  329. newobj.innerHTML = '<div style="margin-top:10px;margin-left:10px;"><img src="../../static/web/img/loadinglit.gif">Loading...</div>';
  330. newobj.style.display = 'block';
  331. fetch(surl).then(resp=>resp.text()).then((d)=>{
  332. newobj.innerHTML = d;
  333. });
  334. fixupPos = false;
  335. }
  336. function MyGetScrollTop() {
  337. return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
  338. }
  339. //通用事件获取接口
  340. function getEvent() {
  341. if ($Nav() == 'IE') return window.event;
  342. func = getEvent.caller;
  343. while (func != null) {
  344. var arg0 = func.arguments[0];
  345. if (arg0) {
  346. if ((arg0.constructor == Event || arg0.constructor == MouseEvent)
  347. || (typeof (arg0) == "object" && arg0.preventDefault && arg0.stopPropagation)) {
  348. return arg0;
  349. }
  350. }
  351. func = func.caller;
  352. }
  353. return null;
  354. }
  355. //模拟ondrop事件相关代码
  356. /*----------------------------
  357. leftLeaning = 300;
  358. 如果对象内容固定,用onmousedown=DropStart去除底下的DropStop
  359. newobj.ondblclick = DropStart;
  360. newobj.onmousemove = DropMove;
  361. newobj.onmousedown = DropStop;
  362. ----------------------------*/
  363. function DropStart() {
  364. this.style.cursor = 'move';
  365. }
  366. function DropStop() {
  367. this.style.cursor = 'default';
  368. }
  369. function DropMove() {
  370. if (this.style.cursor != 'move') return;
  371. var event = getEvent();
  372. if ($Nav() == 'IE') {
  373. var posLeft = event.clientX - 20;
  374. var posTop = event.clientY - 30;
  375. posTop += document.body.scrollTop;
  376. } else {
  377. var posLeft = event.pageX - 20;
  378. var posTop = event.pageY - 30;
  379. }
  380. this.style.top = posTop;
  381. this.style.left = posLeft - leftLeaning;
  382. }
  383. //对指定的元素绑定move事件
  384. /*-----------------------------
  385. onmousemove="DropMoveHand('divname', 225);"
  386. onmousedown="DropStartHand();"
  387. onmouseup="DropStopHand();"
  388. -----------------------------*/
  389. function DropStartHand() {
  390. canMove = (canMove ? false : true);
  391. }
  392. function DropStopHand() {
  393. canMove = false;
  394. }
  395. function DropMoveHand(objid, mleftLeaning) {
  396. var event = getEvent();
  397. var obj = $Obj(objid);
  398. if (!canMove) return;
  399. if ($Nav() == 'IE') {
  400. var posLeft = event.clientX - 20;
  401. var posTop = event.clientY - 20;
  402. posTop += window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
  403. } else {
  404. var posLeft = event.pageX - 20;
  405. var posTop = event.pageY - 20;
  406. }
  407. obj.style.top = posTop + "px";
  408. obj.style.left = posLeft - mleftLeaning + "px";
  409. }
  410. //复制内容到剪切板
  411. function copyToClipboard(txt) {
  412. if (txt == null || txt == '') {
  413. alert("没有选择任何内容!");
  414. return;
  415. }
  416. if (window.clipboardData) {
  417. window.clipboardData.clearData();
  418. window.clipboardData.setData("Text", txt);
  419. } else if (navigator.userAgent.indexOf('Opera') != -1) {
  420. window.location = txt;
  421. } else {
  422. try {
  423. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  424. } catch (e) {
  425. alert("被浏览器拒绝\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
  426. }
  427. var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  428. if (!clip) return;
  429. var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  430. if (!trans) return;
  431. trans.addDataFlavor('text/unicode');
  432. var str = new Object();
  433. var len = new Object();
  434. var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  435. var copytext = txt;
  436. str.data = copytext;
  437. trans.setTransferData("text/unicode", str, copytext.length * 2);
  438. var clipid = Components.interfaces.nsIClipboard;
  439. if (!clip) return false;
  440. clip.setData(trans, null, clipid.kGlobalClipboard);
  441. }
  442. }
  443. function getSelTxt() {
  444. var g, r;
  445. if (document.all) {
  446. g = document.selection.createRange().text;
  447. } else {
  448. g = document.getSelection();
  449. }
  450. return g;
  451. }
  452. //显示栏目Map地图
  453. function ShowCatMap(e, obj, cid, targetId, oldvalue) {
  454. fixupPos = true;
  455. LoadQuickDiv(e, 'archives_do.php?dopost=getCatMap&targetid=' + targetId + '&channelid=' + cid + '&oldvalue=' + oldvalue + '&rnd=' + Math.random(), 'getCatMap', '700px', '500px');
  456. ChangeFullDiv('show');
  457. }
  458. function getSelCat(targetId) {
  459. var selBox = document.quicksel.seltypeid;
  460. var targetObj = $Obj(targetId);
  461. var selvalue = '';
  462. //副栏目(多选)
  463. if (targetId == 'typeid2') {
  464. var j = 0;
  465. for (var i = 0; i < selBox.length; i++) {
  466. if (selBox[i].checked) {
  467. j++;
  468. if (j == 10) break;
  469. selvalue += (selvalue == '' ? selBox[i].value : ',' + selBox[i].value);
  470. }
  471. }
  472. if (targetObj) targetObj.value = selvalue;
  473. }
  474. //主栏目(单选)
  475. else {
  476. if (selBox) {
  477. for (var i = 0; i < selBox.length; i++) {
  478. if (selBox[i].checked) selvalue = selBox[i].value;
  479. }
  480. }
  481. if (selvalue == '') {
  482. alert('您没有选中任何项目');
  483. return;
  484. }
  485. if (targetObj) {
  486. for (var j = 0; j < targetObj.length; j++) {
  487. op = targetObj.options[j];
  488. if (op.value == selvalue) op.selected = true;
  489. }
  490. }
  491. }
  492. HideObj("getCatMap");
  493. ChangeFullDiv("hide");
  494. }
  495. function getElementLeft(element) {
  496. var actualLeft = element.offsetLeft;
  497. var current = element.offsetParent;
  498. while (current !== null) {
  499. actualLeft += current.offsetLeft;
  500. current = current.offsetParent;
  501. }
  502. return actualLeft;
  503. }
  504. function getElementTop(element) {
  505. var actualTop = element.offsetTop;
  506. var current = element.offsetParent;
  507. while (current !== null) {
  508. actualTop += current.offsetTop;
  509. current = current.offsetParent;
  510. }
  511. return actualTop;
  512. }
  513. //Copyright 2020 The MuEMS Authors. All rights reserved.
  514. //license that can be found in the LICENSE file.
  515. //-----msgbox-------------------------------------
  516. //生成一个随机ID
  517. function guid() {
  518. function S4() {
  519. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  520. }
  521. return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  522. }
  523. // 函数会返回一个modalID,通过这个ID可自已定义一些方法
  524. // 这里用到了一个展开语法
  525. // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax
  526. function ShowMsg(content, ...args) {
  527. title = "系统提示";
  528. if (typeof content == "undefined") content = "";
  529. modalID = guid();
  530. var footer = `<button type="button" class="btn btn-primary" onClick="CloseModal(\'GKModal${modalID}\')">Ok</button>`;
  531. var noClose = false;
  532. if (args.length == 1) {
  533. // 存在args参数
  534. if (typeof args[0].title !== 'undefined' && args[0].title != "") {
  535. title = args[0].title;
  536. }
  537. if (typeof args[0].footer !== 'undefined' && args[0].footer != "") {
  538. footer = args[0].footer;
  539. }
  540. if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) {
  541. noClose = true;
  542. }
  543. }
  544. footer = footer.replaceAll("~modalID~", modalID);
  545. content = content.replaceAll("~modalID~", modalID);
  546. var modal = `<div id="GKModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="GKModalLabel${modalID}" aria-hidden="true">
  547. <div class="modal-dialog" role="document">
  548. <div class="modal-content"><div class="modal-header">
  549. <h5 class="modal-title" id="GKModalLabel${modalID}">${title}</h5>`;
  550. if (!noClose) {
  551. modal += `<button type="button" class="close" data-dismiss="modal" aria-label="Close">
  552. <span aria-hidden="true">&times;</span>
  553. </button>`;
  554. }
  555. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  556. $("body").append(modal)
  557. $("#GKModal" + modalID).modal({
  558. backdrop: 'static',
  559. show: true
  560. });
  561. $("#GKModal" + modalID).on('hidden.bs.modal', function (e) {
  562. $("#GKModal" + modalID).remove();
  563. })
  564. return modalID;
  565. }
  566. //隐藏并销毁modal
  567. function CloseModal(modalID) {
  568. $("#" + modalID).modal('hide');
  569. $("#" + modalID).on('hidden.bs.modal', function (e) {
  570. if ($("#" + modalID).length > 0) {
  571. $("#" + modalID).remove();
  572. }
  573. })
  574. }
  575. //获取缩略图
  576. var litpicImgSrc = "";
  577. var litpicImg = "";
  578. var currentCID = 0;
  579. var mdlCropperID = "";
  580. var pubAt = 0;
  581. var optCropper = {
  582. preview: ".pv",
  583. crop: function (e) {
  584. $("#cropWidth").text(Math.round(e.detail.height));
  585. $("#cropHeight").text(Math.round(e.detail.width));
  586. var dataUrl = $(this).cropper("getCroppedCanvas")
  587. .toDataURL();
  588. litpicImg = dataUrl;
  589. $("#litPic").attr("src", litpicImg);
  590. },
  591. aspectRatio: 4 / 3,
  592. //拖动截取缩略图后,截取的缩略图更新到imageItems中
  593. cropend: function (data) {
  594. //这里的ID要单独取出来
  595. var dataUrl = $(this).cropper("getCroppedCanvas").toDataURL();
  596. litpicImg = dataUrl;
  597. $("#litPic").attr("src", litpicImg);
  598. $("#litpic_b64").val(litpicImg);
  599. }
  600. }
  601. var cropperAspectRatio = {
  602. 0: 16 / 9,
  603. 1: 4 / 3,
  604. 2: 1 / 1,
  605. 3: 2 / 3,
  606. 4: NaN,
  607. }
  608. function setAspectRatio(ar) {
  609. var opts = optCropper;
  610. opts.aspectRatio = cropperAspectRatio[ar];
  611. $("#cropImg" + mdlCropperID).cropper('destroy').cropper(opts);
  612. }
  613. function okImage(modalID) {
  614. uploadImage(litpicImg);
  615. $("#litPic").attr("src", litpicImg);
  616. CloseModal('GKModal' + modalID);
  617. }
  618. function useDefault(modalID) {
  619. uploadImage(litpicImgSrc);
  620. $("#litPic").attr("src", litpicImgSrc);
  621. CloseModal('GKModal' + modalID);
  622. }
  623. function uploadImage(litpicImgSrc) {
  624. const formData = new FormData()
  625. formData.append('litpic_b64', litpicImgSrc);
  626. fetch('archives_do.php?dopost=upload_base64_image', {
  627. method: 'POST',
  628. body: formData
  629. })
  630. .then(r => {
  631. if (r.ok) {
  632. return r.json()
  633. }
  634. throw new Error(errMsg);
  635. })
  636. .then(d => {
  637. if (d.code == 200) {
  638. $("#picname").val(d.data.image_url);
  639. }
  640. }).catch((error) => {
  641. alert("上传缩略图错误");
  642. });
  643. }
  644. $(document).ready(function () {
  645. $("#btnClearAll").click(function (event) {
  646. litpicImgSrc = "";
  647. litpicImg = "";
  648. $("#picname").val(litpicImg);
  649. $("#litPic").attr("src", "../../static/web/img/defaultpic.jpg");
  650. })
  651. //添加图片
  652. $("#iptAddImages").change(function (event) {
  653. var files = event.target.files;
  654. for (var i = 0, f; f = files[i]; i++) {
  655. //如果不是图片忽略
  656. if (!f.type.match('image.*')) {
  657. continue;
  658. }
  659. //将图片渲染到浏览器
  660. var reader = new FileReader();
  661. reader.onload = (function (theFile) {
  662. return function (e) {
  663. litpicImgSrc = e.target.result;
  664. if (cfg_uplitpic_cut=='Y') {
  665. SetThumb(litpicImgSrc);
  666. } else {
  667. uploadImage(litpicImgSrc);
  668. $("#litPic").attr("src", litpicImgSrc);
  669. }
  670. };
  671. })(f);
  672. reader.readAsDataURL(f);
  673. }
  674. $("#iptAddImages").val("");
  675. });
  676. //截取缩略图
  677. function SetThumb(srcURL) {
  678. var footer =
  679. "<p><a href='javascript:useDefault(\"~modalID~\");' class='btn btn-success'>使用原图</a> <a href='javascript:okImage(\"~modalID~\")' class='btn btn-success'>确定</a></p>";
  680. var optButton = `<p><div class="form-group">
  681. <label for="aspectRatio">比例</label>
  682. <select class="form-control" id="aspectRatio" onchange="setAspectRatio(this.selectedIndex)">
  683. <option>16:9</option>
  684. <option selected>4:3</option>
  685. <option>1:1</option>
  686. <option>2:3</option>
  687. <option>自定义</option>
  688. </select>
  689. </div></p>`;
  690. mdlCropperID = ShowMsg(
  691. '<div><div class="float-left" style="width:300px;"><img id="cropImg~modalID~" src="' +
  692. srcURL +
  693. '"0><p>宽度:<span id="cropWidth"></span>px,高度:<span id="cropHeight"></span>px</p>' + optButton + '</div><div class="pv float-right" style="width:150px;height:100px;overflow:hidden;"></div></div>', {
  694. footer: footer,
  695. noClose: false,
  696. title: 'DedeBIZ缩略图裁剪',
  697. });
  698. setTimeout(function () {
  699. $("#cropImg" + mdlCropperID).cropper(optCropper);
  700. }, 500);
  701. }
  702. if ($.fn.daterangepicker) {
  703. $('.datepicker').daterangepicker({
  704. "singleDatePicker": true,
  705. "autoApply": true,
  706. "showDropdowns": true,
  707. "linkedCalendars": false,
  708. "timePicker": true,
  709. "timePicker24Hour": true,
  710. "timePickerSeconds": true,
  711. "showCustomRangeLabel": false,
  712. "drops": "up",
  713. ranges: {
  714. '今日': [moment(), moment()],
  715. '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  716. '本月': [moment().startOf('month'), moment().startOf('month')],
  717. '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').startOf('month')]
  718. },
  719. "locale": {
  720. format: 'YYYY-MM-DD HH:mm:ss',
  721. applyLabel: '确定',
  722. cancelLabel: '取消',
  723. daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
  724. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
  725. '七月', '八月', '九月', '十月', '十一月', '十二月'],
  726. firstDay: 1
  727. }
  728. }, function (start) {
  729. $(this).val(start.format("YYYY-MM-DD HH:mm:ss"));
  730. });
  731. $('.datepicker').on('show.daterangepicker', function (ev, picker) {
  732. if (picker.element.offset().top - $(window).scrollTop() + picker.container.outerHeight() > $(window).height()) {
  733. picker.drops = 'up';
  734. } else {
  735. picker.drops = 'down';
  736. }
  737. picker.move();
  738. })
  739. }
  740. })