国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

644 рядки
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.minWidth = "500px";
  291. newobj.style.top = "50%";
  292. newobj.style.left = "50%";
  293. newobj.style.transform = "translate(-50%, -50%)";
  294. newobj.innerHTML = '<img src="../../static/web/img/loadinglit.gif">';
  295. newobj.style.display = 'block';
  296. fetch(surl).then(resp => resp.text()).then((d) => {
  297. newobj.innerHTML = d;
  298. });
  299. fixupPos = false;
  300. }
  301. //复制文档到剪切板
  302. function copyToClipboard(txt) {
  303. if (txt == null || txt == '') {
  304. alert("没有选择任何文档");
  305. return;
  306. }
  307. if (window.clipboardData) {
  308. window.clipboardData.clearData();
  309. window.clipboardData.setData("Text", txt);
  310. } else if (navigator.userAgent.indexOf('Opera') != -1) {
  311. window.location = txt;
  312. } else {
  313. try {
  314. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  315. } catch (e) {
  316. alert("浏览器已拒绝,请稍后重试");
  317. }
  318. var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
  319. if (!clip) return;
  320. var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
  321. if (!trans) return;
  322. trans.addDataFlavor('text/unicode');
  323. var str = new Object();
  324. var len = new Object();
  325. var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  326. var copytext = txt;
  327. str.data = copytext;
  328. trans.setTransferData("text/unicode", str, copytext.length * 2);
  329. var clipid = Components.interfaces.nsIClipboard;
  330. if (!clip) return false;
  331. clip.setData(trans, null, clipid.kGlobalClipboard);
  332. }
  333. }
  334. function getSelTxt() {
  335. var g, r;
  336. if (document.all) {
  337. g = document.selection.createRange().text;
  338. } else {
  339. g = document.getSelection();
  340. }
  341. return g;
  342. }
  343. //显示栏目Map地图
  344. function ShowCatMap(e, obj, cid, targetId, oldvalue) {
  345. fixupPos = true;
  346. LoadQuickDiv(e, 'archives_do.php?dopost=getCatMap&targetid=' + targetId + '&channelid=' + cid + '&oldvalue=' + oldvalue + '&rnd=' + Math.random(), 'getCatMap', '700px', '500px');
  347. ChangeFullDiv('show');
  348. }
  349. function getSelCat(targetId) {
  350. var selBox = document.quicksel.seltypeid;
  351. var targetObj = $Obj(targetId);
  352. var selvalue = '';
  353. //副栏目多选
  354. if (targetId == 'typeid2') {
  355. var j = 0;
  356. for (var i = 0; i < selBox.length; i++) {
  357. if (selBox[i].checked) {
  358. j++;
  359. if (j == 10) break;
  360. selvalue += (selvalue == '' ? selBox[i].value : ',' + selBox[i].value);
  361. }
  362. }
  363. if (targetObj) targetObj.value = selvalue;
  364. } else {
  365. //主栏目单选
  366. if (selBox) {
  367. for (var i = 0; i < selBox.length; i++) {
  368. if (selBox[i].checked) selvalue = selBox[i].value;
  369. }
  370. }
  371. if (selvalue == '') {
  372. alert('您没有选中任何项目');
  373. return;
  374. }
  375. if (targetObj) {
  376. for (var j = 0; j < targetObj.length; j++) {
  377. op = targetObj.options[j];
  378. if (op.value == selvalue) op.selected = true;
  379. }
  380. }
  381. }
  382. HideObj("getCatMap");
  383. ChangeFullDiv("hide");
  384. }
  385. function getElementLeft(element) {
  386. var actualLeft = element.offsetLeft;
  387. var current = element.offsetParent;
  388. while (current !== null) {
  389. actualLeft += current.offsetLeft;
  390. current = current.offsetParent;
  391. }
  392. return actualLeft;
  393. }
  394. function getElementTop(element) {
  395. var actualTop = element.offsetTop;
  396. var current = element.offsetParent;
  397. while (current !== null) {
  398. actualTop += current.offsetTop;
  399. current = current.offsetParent;
  400. }
  401. return actualTop;
  402. }
  403. //生成一个随机id
  404. function guid() {
  405. function S4() {
  406. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  407. }
  408. return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
  409. }
  410. var _DedeConfirmFuncs = {};
  411. var _DedeConfirmFuncsClose = {};
  412. function __DedeConfirmRun(modalID) {
  413. _DedeConfirmFuncs[modalID]();
  414. }
  415. function __DedeConfirmRunClose(modalID) {
  416. _DedeConfirmFuncsClose[modalID]();
  417. }
  418. function DedeConfirm(content="",title="确认提示") {
  419. let modalID = guid();
  420. return new Promise((resolve, reject) => {
  421. _DedeConfirmFuncs[modalID] = ()=>{
  422. resolve("success");
  423. CloseModal(`DedeModal${modalID}`);
  424. }
  425. _DedeConfirmFuncsClose[modalID] = ()=>{
  426. reject("cancel");
  427. CloseModal(`DedeModal${modalID}`);
  428. }
  429. 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>`;
  430. 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>`;
  431. modal += `<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>&times;</span></button>`;
  432. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  433. $("body").append(modal)
  434. $("#DedeModal" + modalID).modal({
  435. backdrop: 'static',
  436. show: true
  437. });
  438. $("#DedeModal" + modalID).on('hidden.bs.modal', function (e) {
  439. $("#DedeModal" + modalID).remove();
  440. })
  441. })
  442. }
  443. //函数会返回一个modalID,通过这个id可自已定义一些方法,这里用到了一个展开语法https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Spread_syntax
  444. function ShowMsg(content, ...args) {
  445. title = "系统提示";
  446. size = "";
  447. if (typeof content == "undefined") content = "";
  448. modalID = guid();
  449. var footer = `<button type="button" class="btn btn-primary" onClick="CloseModal(\'GKModal${modalID}\')">确定</button>`;
  450. var noClose = false;
  451. if (args.length == 1) {
  452. //存在args参数
  453. if (typeof args[0].title !== 'undefined' && args[0].title != "") {
  454. title = args[0].title;
  455. }
  456. if (typeof args[0].footer !== 'undefined' && args[0].footer != "") {
  457. footer = args[0].footer;
  458. }
  459. if (typeof args[0].size !== 'undefined' && args[0].size != "") {
  460. size = args[0].size;
  461. }
  462. if (typeof args[0].noClose !== 'undefined' && args[0].noClose == true) {
  463. noClose = true;
  464. }
  465. }
  466. footer = footer.replaceAll("~modalID~", modalID);
  467. content = content.replaceAll("~modalID~", modalID);
  468. 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>`;
  469. if (!noClose) {
  470. modal += `<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span>&times;</span></button>`;
  471. }
  472. modal += `</div><div class="modal-body">${content}</div><div class="modal-footer">${footer}</div></div></div></div>`;
  473. $("body").append(modal)
  474. $("#GKModal" + modalID).modal({
  475. backdrop: 'static',
  476. show: true
  477. });
  478. $("#GKModal" + modalID).on('hidden.bs.modal', function (e) {
  479. $("#GKModal" + modalID).remove();
  480. })
  481. return modalID;
  482. }
  483. //隐藏并销毁modal
  484. function CloseModal(modalID) {
  485. $("#" + modalID).modal('hide');
  486. $("#" + modalID).on('hidden.bs.modal', function (e) {
  487. if ($("#" + modalID).length > 0) {
  488. $("#" + modalID).remove();
  489. }
  490. })
  491. }
  492. //获取缩略图
  493. var litpicImgSrc = "";
  494. var litpicImg = "";
  495. var currentCID = 0;
  496. var mdlCropperID = "";
  497. var pubAt = 0;
  498. var optCropper = {
  499. preview: ".pv",
  500. crop: function (e) {
  501. $("#cropWidth").text(Math.round(e.detail.height));
  502. $("#cropHeight").text(Math.round(e.detail.width));
  503. if ($(this).cropper("getCroppedCanvas")) {
  504. var dataUrl = $(this).cropper("getCroppedCanvas").toDataURL();
  505. litpicImg = dataUrl;
  506. $("#litPic").attr("src", litpicImg);
  507. }
  508. },
  509. aspectRatio: 4 / 3,
  510. //拖动截取缩略图后,截取的缩略图更新到imageItems中
  511. cropend: function (data) {
  512. //这里的id要单独取出来
  513. var dataUrl = $(this).cropper("getCroppedCanvas").toDataURL();
  514. litpicImg = dataUrl;
  515. $("#litPic").attr("src", litpicImg);
  516. $("#litpic_b64").val(litpicImg);
  517. }
  518. }
  519. var cropperAspectRatio = {
  520. 0: 16 / 9,
  521. 1: 4 / 3,
  522. 2: 1 / 1,
  523. 3: 2 / 3,
  524. 4: NaN,
  525. }
  526. function setAspectRatio(ar) {
  527. var opts = optCropper;
  528. opts.aspectRatio = cropperAspectRatio[ar];
  529. $("#cropImg" + mdlCropperID).cropper('destroy').cropper(opts);
  530. }
  531. function okImage(modalID) {
  532. uploadImage(litpicImg);
  533. $("#litPic").attr("src", litpicImg);
  534. CloseModal('GKModal' + modalID);
  535. }
  536. function useDefault(modalID) {
  537. uploadImage(litpicImgSrc);
  538. $("#litPic").attr("src", litpicImgSrc);
  539. CloseModal('GKModal' + modalID);
  540. }
  541. function uploadImage(litpicImgSrc) {
  542. const formData = new FormData()
  543. formData.append('litpic_b64', litpicImgSrc);
  544. fetch('archives_do.php?dopost=upload_base64_image', {
  545. method: 'POST',
  546. body: formData
  547. })
  548. .then(r => {
  549. if (r.ok) {
  550. return r.json()
  551. }
  552. throw new Error(errMsg);
  553. })
  554. .then(d => {
  555. if (d.code == 200) {
  556. $("#picname").val(d.data.image_url);
  557. }
  558. }).catch((error) => {
  559. alert("上传缩略图错误");
  560. });
  561. }
  562. $(document).ready(function () {
  563. $("#btnClearAll").click(function (event) {
  564. litpicImgSrc = "";
  565. litpicImg = "";
  566. $("#picname").val(litpicImg);
  567. $("#litPic").attr("src", "../../static/web/img/thumbnail.jpg");
  568. })
  569. //添加图片
  570. $("#iptAddImages").change(function (event) {
  571. var files = event.target.files;
  572. for (var i = 0, f; f = files[i]; i++) {
  573. //如果不是图片忽略
  574. if (!f.type.match('image.*')) {
  575. continue;
  576. }
  577. //将图片渲染到浏览器
  578. var reader = new FileReader();
  579. reader.onload = (function (theFile) {
  580. return function (e) {
  581. litpicImgSrc = e.target.result;
  582. if (cfg_uplitpic_cut == 'Y') {
  583. SetThumb(litpicImgSrc);
  584. } else {
  585. uploadImage(litpicImgSrc);
  586. $("#litPic").attr("src", litpicImgSrc);
  587. }
  588. };
  589. })(f);
  590. reader.readAsDataURL(f);
  591. }
  592. $("#iptAddImages").val("");
  593. });
  594. //截取缩略图
  595. function SetThumb(srcURL) {
  596. 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>";
  597. 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>`;
  598. 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>', {
  599. footer: footer,
  600. noClose: false,
  601. title: '图片裁剪',
  602. });
  603. setTimeout(function () {
  604. $("#cropImg" + mdlCropperID).cropper(optCropper);
  605. }, 500);
  606. }
  607. if ($.fn.daterangepicker) {
  608. $('.datepicker').daterangepicker({
  609. "singleDatePicker": true,
  610. "autoApply": true,
  611. "showDropdowns": true,
  612. "linkedCalendars": false,
  613. "timePicker": true,
  614. "timePicker24Hour": true,
  615. "timePickerSeconds": true,
  616. "showCustomRangeLabel": false,
  617. "drops": "up",
  618. ranges: {
  619. '今日': [moment(), moment()],
  620. '昨日': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  621. '本月': [moment().startOf('month'), moment().startOf('month')],
  622. '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').startOf('month')]
  623. },
  624. "locale": {
  625. format: 'YYYY-MM-DD HH:mm:ss',
  626. applyLabel: '确定',
  627. cancelLabel: '取消',
  628. daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
  629. monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  630. firstDay: 1
  631. }
  632. }, function (start) {
  633. $(this).val(start.format("YYYY-MM-DD HH:mm:ss"));
  634. });
  635. $('.datepicker').on('show.daterangepicker', function (ev, picker) {
  636. if (picker.element.offset().top - $(window).scrollTop() + picker.container.outerHeight() > $(window).height()) {
  637. picker.drops = 'up';
  638. } else {
  639. picker.drops = 'down';
  640. }
  641. picker.move();
  642. })
  643. }
  644. });