国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

502 řádky
17KB

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