国内流行的内容管理系统(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.

534 lines
18KB

  1. var nForm = null;
  2. var nFrame = null;
  3. var picnameObj = null;
  4. var vImg = null;
  5. function GetWinPos(w, h) {
  6. var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : window.screenX;
  7. var dualScreenTop = window.screenTop !== undefined ? window.screenTop : window.screenY;
  8. var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
  9. var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
  10. var systemZoom = width / window.screen.availWidth;
  11. var left = (width - w) / 2 / systemZoom + dualScreenLeft;
  12. var top = (height - h) / 2 / systemZoom + dualScreenTop;
  13. return { left: left, top: top };
  14. }
  15. function SeePicNew(f, imgdid, frname, hpos, acname) {
  16. var newobj = null;
  17. if (f.value == '') return;
  18. vImg = $Obj(imgdid);
  19. picnameObj = document.getElementById('picname');
  20. nFrame = $Nav() == 'IE' ? eval('document.frames.' + frname) : $Obj(frname);
  21. nForm = f.form;
  22. //修改form的action等参数
  23. if (nForm.detachEvent) nForm.detachEvent("onsubmit", checkSubmit);
  24. else nForm.removeEventListener("submit", checkSubmit, false);
  25. nForm.action = 'archives_do.php';
  26. nForm.target = frname;
  27. nForm.dopost.value = 'uploadLitpic';
  28. nForm.submit();
  29. picnameObj.value = '';
  30. newobj = $Obj('uploadwait');
  31. if (!newobj) {
  32. newobj = document.createElement("div");
  33. newobj.id = 'uploadwait';
  34. newobj.style.position = 'absolute';
  35. newobj.className = 'uploadwait';
  36. newobj.style.width = 120;
  37. newobj.style.height = 20;
  38. newobj.style.top = hpos;
  39. newobj.style.left = 100;
  40. newobj.style.display = 'block';
  41. document.body.appendChild(newobj);
  42. newobj.innerHTML = '<img src="../../static/web/img/loadinglit.gif">';
  43. }
  44. newobj.style.display = 'block';
  45. //提交后还原form的action等参数
  46. nForm.action = acname;
  47. nForm.dopost.value = 'save';
  48. nForm.target = '';
  49. nForm.litpic.disabled = true;
  50. }
  51. function SelectMedia(fname) {
  52. var pos = GetWinPos(800,600);
  53. window.open("./dialog/select_media.php?f=" + fname + "&noeditor=yes", "popUpFlashWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  54. }
  55. function SelectSoft(fname) {
  56. var pos = GetWinPos(800,600);
  57. window.open("./dialog/select_soft.php?f=" + fname+ "&noeditor=yes", "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  58. }
  59. function SelectImage(fname, stype, imgsel="") {
  60. var pos = GetWinPos(800,600);
  61. if (!fname) fname = 'form1.picname';
  62. if (imgsel) imgsel = '&noeditor=yes';
  63. if (!stype) stype = 'small';
  64. window.open("./dialog/select_images.php?f=" + fname + "&noeditor=yes&imgstick=" + stype + imgsel, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  65. }
  66. function SelectImageN(fname, stype, vname) {
  67. var pos = GetWinPos(800,600);
  68. if (!fname) fname = 'form1.picname';
  69. if (!stype) stype = '';
  70. window.open("./dialog/select_images.php?f=" + fname + "&imgstick=" + stype + "&v=" + vname, "popUpImagesWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  71. }
  72. function SelectKeywords(f) {
  73. var pos = GetWinPos(800,600);
  74. window.open("article_keywords_select.php?f=" + f, "popUpkwWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  75. }
  76. function OpenMyWin(surl) {
  77. var pos = GetWinPos(800,600);
  78. window.open(surl, "popUpMyWin", "scrollbars=yes,resizable=yes,statebar=no,width=800,height=600,left=" + pos.left + ", top=" + pos.top);
  79. }
  80. function InitPage() {
  81. var selsource = $Obj('selsource');
  82. var selwriter = $Obj('selwriter');
  83. var colorbt = $Obj('color');
  84. if (selsource) { selsource.onmousedown = function(e) { SelectSource(e); } }
  85. if (selwriter) { selwriter.onmousedown = function(e) { SelectWriter(e); } }
  86. }
  87. function $Nav() {
  88. if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
  89. else return "OT";
  90. }
  91. function $Obj(objname) {
  92. return document.getElementById(objname);
  93. }
  94. function ColorSel(c, oname) {
  95. var tobj = $Obj(oname);
  96. if (!tobj) tobj = eval('document.form1.' + oname);
  97. if (!tobj) {
  98. $Obj('colordlg').style.display = 'none';
  99. return false;
  100. } else {
  101. tobj.value = c;
  102. $Obj('colordlg').style.display = 'none';
  103. return true;
  104. }
  105. }
  106. function ShowColor(e, o) {
  107. LoadNewDiv(e, '../../static/web/img/colornew.htm', 'colordlg');
  108. }
  109. function ShowHide(objname) {
  110. var obj = $Obj(objname);
  111. if (obj.style.display != "none") obj.style.display = "none";
  112. else obj.style.display = "inline-block";
  113. }
  114. function ShowObj(objname) {
  115. var obj = $Obj(objname);
  116. if (obj == null) return false;
  117. obj.style.display = "table-row";
  118. }
  119. function ShowObjRow(objname) {
  120. var obj = $Obj(objname);
  121. obj.style.display = "table-row";
  122. }
  123. function AddTypeid2() {
  124. ShowObjRow('typeid2tr');
  125. }
  126. function HideObj(objname) {
  127. var obj = $Obj(objname);
  128. if (obj == null) return false;
  129. obj.style.display = "none";
  130. }
  131. function SeePic(img, f) {
  132. if (f.value != '') img.src = f.value;
  133. }
  134. function PutSource(str) {
  135. var osource = $Obj('source');
  136. if (osource) osource.value = str;
  137. $Obj("mysource").style.display = "none";
  138. ChangeFullDiv("hide");
  139. }
  140. function PutWriter(str) {
  141. var owriter = $Obj("writer");
  142. if (owriter) owriter.value = str;
  143. $Obj("mywriter").style.display = "none";
  144. ChangeFullDiv("hide");
  145. }
  146. function ClearDivCt(objname) {
  147. if (!$Obj(objname)) return;
  148. $Obj(objname).innerHTML = "";
  149. $Obj(objname).style.display = "none";
  150. ChangeFullDiv("hide");
  151. }
  152. function ChangeFullDiv(showhide, screenheigt) {
  153. var newobj = $Obj("fullpagediv");
  154. if (showhide == "show") {
  155. if (!newobj) {
  156. newobj = document.createElement("div");
  157. newobj.id = "fullpagediv";
  158. newobj.style.position = "absolute";
  159. newobj.className = "fullpagediv";
  160. newobj.style.height = document.body.clientHeight + 50 + "px";
  161. document.body.appendChild(newobj);
  162. } else {
  163. newobj.style.display = "block";
  164. }
  165. } else {
  166. if (newobj) newobj.style.display = "none";
  167. }
  168. }
  169. function SelectSource(e) {
  170. LoadNewDiv(e, 'article_select_sw.php?t=source&k=8&rnd=' + Math.random(), 'mysource');
  171. }
  172. function SelectWriter(e) {
  173. LoadNewDiv(e, 'article_select_sw.php?t=writer&k=8&rnd=' + Math.random(), 'mywriter');
  174. }
  175. function LoadNewDiv(e, surl, oname) {
  176. var pxStr = '';
  177. posLeft = posLeft - 100;
  178. var newobj = $Obj(oname);
  179. if (!newobj) {
  180. newobj = document.createElement("div");
  181. newobj.id = oname;
  182. newobj.style.position = "absolute";
  183. newobj.className = oname;
  184. newobj.className += " dlgws";
  185. newobj.style.top = posTop + pxStr;
  186. newobj.style.left = posLeft + pxStr;
  187. document.body.appendChild(newobj);
  188. } else {
  189. newobj.style.display = "block";
  190. }
  191. if (newobj.innerHTML.length < 10) {
  192. fetch(surl).then(resp => resp.text()).then((d) => { newobj.innerHTML = d });
  193. }
  194. }
  195. function LoadNewDiv2(e, surl, oname, dlgcls) {
  196. var posLeft = 300;
  197. var posTop = 50;
  198. var newobj = $Obj(oname);
  199. if (!newobj) {
  200. newobj = document.createElement("div");
  201. newobj.id = oname;
  202. newobj.style.position = 'absolute';
  203. newobj.className = dlgcls;
  204. newobj.style.top = posTop;
  205. newobj.style.left = posLeft;
  206. newobj.style.display = 'none';
  207. document.body.appendChild(newobj);
  208. }
  209. newobj.innerHTML = '';
  210. fetch(surl).then(resp => resp.text()).then((d) => {
  211. newobj.innerHTML = d;
  212. });
  213. if (newobj.innerHTML == '') newobj.style.display = 'none';
  214. else newobj.style.display = 'block';
  215. jQuery(newobj).css('top', '50px').css('left', '300px');
  216. DedeXHTTP = null;
  217. }
  218. function ShowUrlTr() {
  219. var jumpTest = $Obj('flagsj');
  220. var jtr = $Obj('redirecturltr');
  221. var jf = $Obj('redirecturl');
  222. if (jumpTest.checked) jtr.style.display = "block";
  223. else {
  224. jf.value = '';
  225. jtr.style.display = "none";
  226. }
  227. }
  228. function ShowUrlTrEdit() {
  229. ShowUrlTr();
  230. var jumpTest = $Obj('isjump');
  231. var rurl = $Obj('redirecturl');
  232. if (!jumpTest.checked) rurl.value = "";
  233. }
  234. function LoadQuickDiv(e, surl, oname, w, h) {
  235. var newobj = $Obj(oname);
  236. if (!newobj) {
  237. newobj = document.createElement("div");
  238. newobj.id = oname;
  239. newobj.style.position = 'fixed';
  240. newobj.className = 'pubdlg';
  241. newobj.style.width = w;
  242. newobj.style.height = h + 30;
  243. document.body.appendChild(newobj);
  244. }
  245. newobj.style.top = "50%";
  246. newobj.style.left = "50%";
  247. newobj.style.display = 'block';
  248. newobj.style.transform = "translate(-50%, -201px)";
  249. newobj.innerHTML = '<img src="../../static/web/img/loadinglit.gif">';
  250. fetch(surl).then(resp => resp.text()).then((d) => {
  251. newobj.innerHTML = d;
  252. });
  253. }
  254. function ShowCatMap(e, obj, cid, targetId, oldvalue) {
  255. LoadQuickDiv(e, 'archives_do.php?dopost=getCatMap&targetid=' + targetId + '&channelid=' + cid + '&oldvalue=' + oldvalue + '&rnd=' + Math.random(), 'getCatMap', '700px', '500px');
  256. ChangeFullDiv('show');
  257. }
  258. function getSelCat(targetId) {
  259. var selBox = document.quicksel.seltypeid;
  260. var targetObj = $Obj(targetId);
  261. var selvalue = '';
  262. if (targetId == 'typeid2') {
  263. var j = 0;
  264. for (var i = 0; i < selBox.length; i++) {
  265. if (selBox[i].checked) {
  266. j++;
  267. if (j == 10) break;
  268. selvalue += (selvalue == '' ? selBox[i].value : ',' + selBox[i].value);
  269. }
  270. }
  271. if (targetObj) targetObj.value = selvalue;
  272. } else {
  273. if (selBox) {
  274. for (var i = 0; i < selBox.length; i++) {
  275. if (selBox[i].checked) selvalue = selBox[i].value;
  276. }
  277. }
  278. if (selvalue == '') {
  279. alert('您没有选中任何栏目');
  280. return;
  281. }
  282. if (targetObj) {
  283. for (var j = 0; j < targetObj.length; j++) {
  284. op = targetObj.options[j];
  285. if (op.value == selvalue) op.selected = true;
  286. }
  287. }
  288. }
  289. HideObj("getCatMap");
  290. ChangeFullDiv("hide");
  291. }
  292. //生成一个随机id
  293. function guid() {
  294. function S4() {
  295. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  296. }
  297. return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  298. }
  299. var _DedeConfirmFuncs = {};
  300. var _DedeConfirmFuncsClose = {};
  301. function __DedeConfirmRun(modalID) {
  302. _DedeConfirmFuncs[modalID]();
  303. }
  304. function __DedeConfirmRunClose(modalID) {
  305. _DedeConfirmFuncsClose[modalID]();
  306. }
  307. function DedeConfirm(content = "", title = "确认提示") {
  308. let modalID = guid();
  309. return new Promise((resolve, reject) => {
  310. _DedeConfirmFuncs[modalID] = ()=>{
  311. resolve("success");
  312. CloseModal(`DedeModal${modalID}`);
  313. }
  314. _DedeConfirmFuncsClose[modalID] = ()=>{
  315. reject("cancel");
  316. CloseModal(`DedeModal${modalID}`);
  317. }
  318. let footer = `<button type="button" class="btn btn-outline-success btn-sm" onclick="__DedeConfirmRunClose(\'${modalID}\')">取消</button><button type="button" class="btn btn-success btn-sm" onclick="__DedeConfirmRun(\'${modalID}\')">确定</button>`;
  319. let modal = `<div id="DedeModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="DedeModalLabel${modalID}"><div class="modal-dialog modal-dialog-centered" role="document"><div class="modal-content"><div class="modal-header"><h6 class="modal-title" id="DedeModalLabel${modalID}">${title}</h6>`;
  320. modal += `<button type="button" class="update-close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>`;
  321. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  322. $("body").append(modal)
  323. $("#DedeModal" + modalID).modal({
  324. backdrop: 'static',
  325. show: true
  326. });
  327. $("#DedeModal" + modalID).on('hidden.bs.modal', function(e) {
  328. $("#DedeModal" + modalID).remove();
  329. })
  330. })
  331. }
  332. //函数会返回一个modalID,通过这个id可自已定义一些方法,这里用到了一个展开语法:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax
  333. function ShowMsg(content, ...args) {
  334. title = "系统提示";
  335. size = "";
  336. if (typeof content == "undefined") content = "";
  337. modalID = guid();
  338. var footer = `<button type="button" class="btn btn-primary btn-sm" onclick="CloseModal(\'GKModal${modalID}\')">确定</button>`;
  339. var noClose = false;
  340. if (args.length == 1) {
  341. //存在args参数
  342. if (typeof args[0].title !== 'undefined' && args[0].title != "") {
  343. title = args[0].title;
  344. }
  345. if (typeof args[0].footer !== 'undefined' && args[0].footer != "") {
  346. footer = args[0].footer;
  347. }
  348. if (typeof args[0].size !== 'undefined' && args[0].size != "") {
  349. size = args[0].size;
  350. }
  351. if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) {
  352. noClose = true;
  353. }
  354. }
  355. footer = footer.replaceAll("~modalID~", modalID);
  356. content = content.replaceAll("~modalID~", modalID);
  357. var modal = `<div id="GKModal${modalID}" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="GKModalLabel${modalID}"><div class="modal-dialog ${size}" role="document"><div class="modal-content"><div class="modal-header"><h5 class="modal-title" id="GKModalLabel${modalID}">${title}</h5>`;
  358. if (!noClose) {
  359. modal += `<button type="button" class="update-close" data-dismiss="modal" aria-label="Close"><i class="fa fa-times"></i></button>`;
  360. }
  361. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  362. $("body").append(modal)
  363. $("#GKModal" + modalID).modal({
  364. backdrop: 'static',
  365. show: true
  366. });
  367. $("#GKModal" + modalID).on('hidden.bs.modal', function(e) {
  368. $("#GKModal" + modalID).remove();
  369. })
  370. return modalID;
  371. }
  372. //隐藏并销毁modal
  373. function CloseModal(modalID) {
  374. $("#" + modalID).modal('hide');
  375. $("#" + modalID).on('hidden.bs.modal', function(e) {
  376. if ($("#" + modalID).length > 0) {
  377. $("#" + modalID).remove();
  378. }
  379. })
  380. }
  381. //获取缩略图
  382. var litpicImgSrc = "";
  383. var litpicImg = "";
  384. var mdlCropperID = "";
  385. var optCropper = {
  386. preview: ".pv",
  387. crop: function(e) {
  388. $("#cropWidth").text(Math.round(e.detail.height));
  389. $("#cropHeight").text(Math.round(e.detail.width));
  390. if ($(this).cropper("getCroppedCanvas")) {
  391. var dataUrl = $(this).cropper("getCroppedCanvas").toDataURL();
  392. litpicImg = dataUrl;
  393. $("#litPic").attr("src", litpicImg);
  394. }
  395. },
  396. aspectRatio: 4 / 3,
  397. cropend: function(data) {
  398. var dataUrl = $(this).cropper("getCroppedCanvas").toDataURL();
  399. litpicImg = dataUrl;
  400. $("#litPic").attr("src", litpicImg);
  401. $("#litpic_b64").val(litpicImg);
  402. }
  403. }
  404. var cropperAspectRatio = {
  405. 0: 16 / 9,
  406. 1: 4 / 3,
  407. 2: 1 / 1,
  408. 3: 2 / 3,
  409. 4: NaN,
  410. }
  411. function setAspectRatio(ar) {
  412. var opts = optCropper;
  413. opts.aspectRatio = cropperAspectRatio[ar];
  414. $("#cropImg" + mdlCropperID).cropper('destroy').cropper(opts);
  415. }
  416. function okImage(modalID) {
  417. uploadImage(litpicImg);
  418. $("#litPic").attr("src", litpicImg);
  419. CloseModal('GKModal' + modalID);
  420. }
  421. function useDefault(modalID) {
  422. uploadImage(litpicImgSrc);
  423. $("#litPic").attr("src", litpicImgSrc);
  424. CloseModal('GKModal' + modalID);
  425. }
  426. function uploadImage(litpicImgSrc) {
  427. const formData = new FormData()
  428. formData.append('litpic_b64', litpicImgSrc);
  429. fetch('archives_do.php?dopost=upload_base64_image', {
  430. method: 'POST',
  431. body: formData
  432. })
  433. .then(r => {
  434. if (r.ok) {
  435. return r.json()
  436. }
  437. throw new Error(errMsg);
  438. })
  439. .then(d => {
  440. if (d.code == 200) {
  441. $("#picname").val(d.data.image_url);
  442. }
  443. }).catch((error) => {
  444. alert("上传缩略图错误");
  445. });
  446. }
  447. function SetThumb(srcURL) {
  448. var footer = "<p><a href='javascript:useDefault(\"~modalID~\");' class='btn btn-success btn-sm'>使用原图</a><a href='javascript:okImage(\"~modalID~\")' class='btn btn-success btn-sm'>确定</a></p>";
  449. var optButton = `<p><label for="aspectRatio">比例</label><select id="aspectRatio" onchange="setAspectRatio(this.selectedIndex)"><option>16:9</option><option selected>4:3</option><option>1:1</option><option>2:3</option><option>自定义</option></select></p>`;
  450. mdlCropperID = ShowMsg('<div class="float-left" style="width:320px"><p><img id="cropImg~modalID~" src="' + srcURL + '"></p><p>宽度:<span id="cropWidth"></span>px,高度:<span id="cropHeight"></span>px</p>' + optButton + '</div><div class="pv float-right" style="width:200px;height:100px;overflow:hidden"></div>', {
  451. footer: footer,
  452. noClose: false,
  453. title: '图片裁剪',
  454. });
  455. setTimeout(function() {
  456. $("#cropImg" + mdlCropperID).cropper(optCropper);
  457. }, 500);
  458. }
  459. $(document).ready(function() {
  460. $("#togglemenu").click(function() {
  461. if ($("body").attr("class") == "showmenu") {
  462. $("body").attr("class", "hidemenu");
  463. $(this).html('<i class="fa fa-indent"></i>');
  464. } else {
  465. $("body").attr("class", "showmenu");
  466. $(this).html('<i class="fa fa-dedent"></i>');
  467. }
  468. });
  469. $("#btnClearAll").click(function(event) {
  470. litpicImgSrc = "";
  471. litpicImg = "";
  472. $("#picname").val(litpicImg);
  473. $("#litPic").attr("src", "/static/web/img/thumbnail.jpg");
  474. })
  475. $("#iptAddImages").change(function(event) {
  476. var files = event.target.files;
  477. for (var i = 0, f; f = files[i]; i++) {
  478. if (!f.type.match('image.*')) {
  479. continue;
  480. }
  481. var reader = new FileReader();
  482. reader.onload = (function(theFile) {
  483. return function(e) {
  484. litpicImgSrc = e.target.result;
  485. if (cfg_uplitpic_cut == 'Y') {
  486. SetThumb(litpicImgSrc);
  487. } else {
  488. uploadImage(litpicImgSrc);
  489. $("#litPic").attr("src", litpicImgSrc);
  490. }
  491. };
  492. })(f);
  493. reader.readAsDataURL(f);
  494. }
  495. $("#iptAddImages").val("");
  496. });
  497. if ($.fn.daterangepicker) {
  498. $('.datepicker').daterangepicker({
  499. "singleDatePicker": true,
  500. "autoApply": true,
  501. "showDropdowns": true,
  502. "linkedCalendars": false,
  503. "timePicker": true,
  504. "timePicker24Hour": true,
  505. "timePickerSeconds": true,
  506. "showCustomRangeLabel": false,
  507. "drops": "up",
  508. ranges: {
  509. '今日': [moment(), moment()],
  510. '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  511. '本月': [moment().startOf('month'), moment().startOf('month')],
  512. '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').startOf('month')]
  513. },
  514. "locale": {
  515. format: 'YYYY-MM-DD HH:mm:ss',
  516. applyLabel: '确定',
  517. cancelLabel: '取消',
  518. daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
  519. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  520. firstDay: 1
  521. }
  522. }, function(start) {
  523. $(this).val(start.format("YYYY-MM-DD HH:mm:ss"));
  524. });
  525. $('.datepicker').on('show.daterangepicker', function(ev, picker) {
  526. if (picker.element.offset().top - $(window).scrollTop() + picker.container.outerHeight() > $(window).height()) {
  527. picker.drops = 'up';
  528. } else {
  529. picker.drops = 'down';
  530. }
  531. picker.move();
  532. })
  533. }
  534. });