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

643 lines
22KB

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