xq-admin-page
Version:
基于Bootstrap5的表格列表,主要有后台管理的列表与搜索、添加、编辑、删除、导出等功能,同时列表支持自定义排序、分页大小等。
7 lines • 32.8 kB
JavaScript
/*!
* xq-admin-page v1.0.10 (https://xqkeji.cn/demo/xq-admin-page)
* Author xqkeji.cn
* LICENSE SSPL-1.0
* Copyright 2024 xqkeji.cn
*/
;(()=>{var N={tableClass:".xq-table",orderClass:".xq-order",orderAscClass:".xq-order-asc",orderDescClass:".xq-order-desc",dragClass:".xq-drag",checkAllClass:".xq-table .xq-check-all",addBtnClass:".xq-table .xq-add",editBtnClass:".xq-edit",viewBtnClass:".xq-view",deleteBtnClass:".xq-delete",exportBtnClass:".xq-export",copyBtnClass:".xq-copy",batchBtnClass:".xq-batch",backPageClass:".xq-backpage",authTableClass:".xq-auth-table",authCheckTableClass:".xq-auth-check-table",authCheckRowClass:".xq-auth-check-row",captchaClass:".xq-captcha",pageSizeId:"#xq-page-size"};var o={};var t=(e={})=>{o=Object.assign({},N);if(e){for(const t in e){if(Object.hasOwn(o,t)){treegridOptions[t]=e[t]}}}};var p=e=>{if(e in o){return o[e]}const t=o["tableClass"];const n=document.querySelector(t);if(n.hasAttribute(e)){return String(n.getAttribute(e))}return""};var n;var h=()=>{if(n){return n}else{const e=p("tableClass");const t=document.querySelector(e);n=t;return n}};var e=e=>{if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",e)}else{e()}};var l=(e,t)=>{const n=[];let o=e.parentNode;while(o&&o.nodeType===Node.ELEMENT_NODE){if(o.matches(t)){n.push(o)}o=o.parentNode}return n};var j=(e,t)=>{let n=e.nextElementSibling;while(n){if(n.matches(t)){return[n]}n=n.nextElementSibling}return[]};var k=(e,t)=>{const n=document.createRange().createContextualFragment(t);e.append(n)};var Y=e=>{const t={};const n=new FormData(e);for(const o of n){const r=o[0];if(r.includes("[")){const i=r.slice(0,Math.max(0,r.indexOf("[")));const a=r.slice(r.indexOf("[")+1,r.indexOf("]"));const s={};s[a]=o[1];if(t[i]){const l=t[i];l[a]=o[1];t[i]=l}else{t[i]=s}}else{t[o[0]]=o[1]}}return t};var g=(e,t,n)=>{if(n==void 0||n==null){return e}let o=new RegExp("([?&])"+t+"=.*?(&|$)","i");let r=e.indexOf("?")!==-1?"&":"?";if(e.match(o)){return e.replace(o,"$1"+t+"="+n+"$2")}else{return e+r+t+"="+n}};var z=()=>{const e=p("addBtnClass");const t=document.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;const n=l(t,"table")[0];const o=n.getAttribute("pid");let r=t.getAttribute("xq-url");if(!r){r=window.location.href;if(r.includes(".html")||r.includes("localhost")){r=r.slice(0,Math.max(0,r.lastIndexOf("/")));r+="/add.html"}else{if(o){r=r.replace("/"+o,"")}r=r.slice(0,Math.max(0,r.lastIndexOf("/")));r+=o?"/add/"+o:"/add"}}window.location.href=r})}};var R='<div id="xq-bs-modal" class="modal" tabindex="-1" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><h5 class="modal-title"><i></i><span>title</span></h5><button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body"><p>Modal content.</p></div><div class="modal-footer"></div></div></div></div>';var W={id:"xq-bs-modal",type:"alert",size:"modal-sm",position:"modal-dialog-centered",template:R,title:"提示信息",content:"您确认要进行操作吗?",icon:"info",confirmButton:"确认",cancelButton:"取消",confirmButtonClass:"btn-primary",cancelButtonClass:"btn-secondary",confirm:()=>{},cancel:()=>{},backgroundDismiss:true,autoClose:false};var r={};var F=(e={})=>{r=Object.assign({},W);if(e){for(const t in e){if(Object.prototype.hasOwnProperty.call(r,t)){r[t]=e[t]}}}};var M=e=>{if(e in r){return r[e]}const t=r["id"];const n=document.querySelector("#"+t);if(n.hasAttribute(e)){return String(n.getAttribute(e))}return""};var U={info:"bi bi-info-circle-fill link-primary",warn:"bi bi-info-circle-fill link-warning",error:"bi bi-info-circle-fill link-danger"};var X=e=>{if(Object.prototype.hasOwnProperty.call(U,e)){return U[e]}else{return e}};var J=(e={})=>{F(e);const t=M("template");k(document.body,t);const n=M("id");const r=document.querySelector("#"+n);if(r){const o=r.querySelector(".modal-dialog");const i=M("size");const a=M("position");o.classList.add(i);o.classList.add(a);const s=r.querySelector(".modal-title>i");const l=r.querySelector(".modal-title>span");const c=r.querySelector(".modal-body>p");if(s){const d=M("icon");const f=X(d);s.className=f}if(l){const u=M("title");l.innerHTML=u}if(c){const m=M("content");c.innerHTML=m}if(typeof bootstrap!==void 0&&typeof bootstrap.Modal!==void 0){const p=new bootstrap.Modal(r);const h=document.querySelector(".modal-footer");if(h){const v=M("type");if(v!=="alert"){const x=M("cancelButtonClass");const E=M("cancelButton");k(h,'<button id="xq-bs-modal-cancel" type="button" class="btn '+x+'" data-bs-dismiss="modal">'+E+"</button>");const q=h.querySelector("#xq-bs-modal-cancel");q?.addEventListener("click",e=>{e.preventDefault();p.hide();const t=M("cancel");if(t!==null){t()}})}const b=M("confirmButtonClass");const y=M("confirmButton");k(h,'<button id="xq-bs-modal-confirm" type="button" class="btn '+b+'">'+y+"</button>");const w=h.querySelector("#xq-bs-modal-confirm");w?.addEventListener("click",e=>{e.preventDefault();p.hide();const t=M("confirm");if(t!==null){t()}})}r.addEventListener("hidden.bs.modal",()=>{p.dispose();r.remove()});const g=M("autoClose");if(g){const C=g;if(C.indexOf("|")){const S=C.split("|");const L=S[0];const A=Number.parseInt(S[1],10);let t;let n;let o=Math.ceil(A/1e3);const T='<span class="countdown"> ('+o+")</span>";if(L==="confirm"){n=h.querySelector("#xq-bs-modal-confirm");k(n,T)}else{n=h.querySelector("#xq-bs-modal-cancel");k(n,T)}r.addEventListener("show.bs.modal",()=>{t=setInterval(function(){const e=n.querySelector(".countdown");o=o-1;e.innerHTML=" ("+o+") ";if(o<=0){clearInterval(t);n.click()}},1e3)})}}p.show()}else{console.log("error","the bootstrap not loaded!")}}};var c=(e={})=>{J(e)};window.xqConfirm=c;var V=i=>{const e=p("editBtnClass");const t=i.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;const n=h();const o=n?.getAttribute("pid");let r=i.getAttribute("id");r=r.replace("xq_","");if(r){let e=t.getAttribute("xq-url");if(!e){e=window.location.href;if(e.includes(".html")||e.endsWith("/")){e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e=e+"/edit.html?id="+r}else{if(o){e=e.replace("/"+o,"")}e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e=e+"/edit/"+r}}window.location.href=e}else{c({content:"找不到tr的id属性!"})}})}};var Q=i=>{const e=p("viewBtnClass");const t=i.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;const n=h();const o=n?.getAttribute("pid");let r=i.getAttribute("id");r=r.replace("xq_","");if(r){let e=t.getAttribute("xq-url");if(!e){e=window.location.href;if(e.includes(".html")||e.endsWith("/")){e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e=e+"/view.html?id="+r}else{if(o){e=e.replace("/"+o,"")}e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e=e+"/view/"+r}}window.location.href=e}else{c({content:"找不到tr的id属性!"})}})}};var G=e=>{const t=document.createElement("input");t.setAttribute("value",e);document.body.append(t);t.select();document.execCommand("copy");t.remove()};var K=t=>{const e=p("copyBtnClass");const n=t.querySelector(e);if(n){n.addEventListener("click",()=>{let e=t.getAttribute("id");e=e.replace("xq_","");if(e){G(e);c({content:"已经将id复制到粘贴板"})}})}};var Z=i=>{const e=p("deleteBtnClass");const t=i.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;const n=h();const o=n?.getAttribute("pid");let r=i.getAttribute("id");r=r.replace("xq_","");if(r){let e=t.getAttribute("xq-url");if(!e){e=window.location.href;if(o){e=e.replace("/"+o,"")}e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e+="/delete"}c({content:"确定要删除吗?",confirm(){fetch(e,{body:JSON.stringify({id:r}),headers:{"content-type":"application/json"},method:"POST"}).then(async e=>{return e.json()}).then(e=>{c({content:e.message,confirm(){if(e.code===200){window.location.reload()}}})})}})}else{c({content:"找不到tr的id属性!"})}})}};var ee=e=>{const l=h();let c=e.getAttribute("id");c=c?.replace("xq_","");const t=e.querySelectorAll("input,select");for(const n of t){const o=n.getAttribute("id");if(o!=="id"&&o!=="check_all"){n.addEventListener("change",e=>{const t=e.currentTarget;let n=null;n=t.type==="checkbox"?t.checked:t.value;const o=t.getAttribute("id");const r=o?.slice(0,Math.max(0,o.indexOf("_")));const i=l?.getAttribute("pid");let a=l?.getAttribute("xq-url");const s={id:c,field:r,value:n};if(!a){let e=window.location.href;if(i){e=e.replace("/"+i,"")}e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e+="/change";a=e}else{a+="/change"}fetch(a,{body:JSON.stringify(s),headers:{"content-type":"application/json"},method:"POST"}).then(async e=>{return e.json()}).then(e=>{console.log(e)})})}}};var te='<div id="xq-bs-mask" class="modal modal-dialog-centered" tabindex="-1" data-bs-backdrop="static" data-bs-keyboard="false" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"><div class="overlay"><i class="fa-spin bi bi-arrow-repeat"></i></div></div></div></div></div>';var ne={id:"xq-bs-mask",template:te};var i={};var oe=(e={})=>{i=Object.assign({},ne);if(e){for(const t in e){if(Object.prototype.hasOwnProperty.call(i,t)){i[t]=e[t]}}}};var re=e=>{if(e in i){return i[e]}const t=i["id"];const n=document.querySelector("#"+t);if(n.hasAttribute(e)){return String(n.getAttribute(e))}return""};var a=null;var ie=()=>{oe({});const e=re("template");k(document.body,e);const t=re("id");const n=document.querySelector("#"+t);if(n){n.querySelector(".modal-dialog");if(typeof bootstrap!==void 0&&typeof bootstrap.Modal!==void 0){a=new bootstrap.Modal(n);n.addEventListener("hidden.bs.modal",()=>{a.dispose();n.remove()});a.show()}else{console.log("error","the bootstrap not loaded!")}}};var ae=()=>{if(a){a.hide()}};var se=()=>{ie()};var le=()=>{ae()};window.xqMask=se;window.xqUnMask=le;var ce=()=>{const e=p("batchBtnClass");const t=document.querySelectorAll(e);if(t){for(const n of t){n.addEventListener("click",e=>{const t=e.currentTarget;const n=l(t,"table")[0];const o=n.getAttribute("pid");const r=l(t,"form")[0];const i=t.getAttribute("name");if(i){let e=t.getAttribute("xq-url");if(!e){e=window.location.href;if(o){e=e.replace("/"+o,"")}e=e.slice(0,Math.max(0,e.lastIndexOf("/")));e=e+"/"+i}const a=Y(r);const s=JSON.stringify(a);if(s!=="{}"){c({content:"确定要进行批量操作吗?",confirm(){se();fetch(e,{body:s,headers:{"content-type":"application/json"},method:"POST"}).then(async e=>{return e.json()}).then(e=>{le();c({content:e.message,confirm(){if(e.code===200){window.location.reload()}}})})}})}else{c({content:"没有选择操作数据."})}}})}}};function d(e,t,n){if(n===void 0){return e&&e.h5s&&e.h5s.data&&e.h5s.data[t]}else{e.h5s=e.h5s||{};e.h5s.data=e.h5s.data||{};e.h5s.data[t]=n}}function de(e){if(e.h5s){delete e.h5s.data}}var v=(e,t)=>{if(!(e instanceof NodeList||e instanceof HTMLCollection||e instanceof Array)){throw new Error("You must provide a nodeList/HTMLCollection/Array of elements to be filtered.")}if(typeof t!=="string"){return Array.from(e)}return Array.from(e).filter(e=>e.nodeType===1&&e.matches(t))};var b=new Map;var fe=class{constructor(){this._config=new Map;this._placeholder=void 0;this._data=new Map}set config(e){if(typeof e!=="object"){throw new Error("You must provide a valid configuration object to the config setter.")}const t=Object.assign({},e);this._config=new Map(Object.entries(t))}get config(){const n={};this._config.forEach((e,t)=>{n[t]=e});return n}setConfig(e,t){if(!this._config.has(e)){throw new Error(`Trying to set invalid configuration item: ${e}`)}this._config.set(e,t)}getConfig(e){if(!this._config.has(e)){throw new Error(`Invalid configuration item requested: ${e}`)}return this._config.get(e)}get placeholder(){return this._placeholder}set placeholder(e){if(!(e instanceof HTMLElement)&&e!==null){throw new Error("A placeholder must be an html element or null.")}this._placeholder=e}setData(e,t){if(typeof e!=="string"){throw new Error("The key must be a string.")}this._data.set(e,t)}getData(e){if(typeof e!=="string"){throw new Error("The key must be a string.")}return this._data.get(e)}deleteData(e){if(typeof e!=="string"){throw new Error("The key must be a string.")}return this._data.delete(e)}};var y=e=>{if(!(e instanceof HTMLElement)){throw new Error("Please provide a sortable to the store function.")}if(!b.has(e)){b.set(e,new fe)}return b.get(e)};function s(t,n,o){if(t instanceof Array){for(let e=0;e<t.length;++e){s(t[e],n,o)}return}t.addEventListener(n,o);y(t).setData(`event${n}`,o)}function f(t,n){if(t instanceof Array){for(let e=0;e<t.length;++e){f(t[e],n)}return}t.removeEventListener(n,y(t).getData(`event${n}`));y(t).deleteData(`event${n}`)}function u(t,n,o){if(t instanceof Array){for(let e=0;e<t.length;++e){u(t[e],n,o)}return}t.setAttribute(n,o)}function m(t,n){if(t instanceof Array){for(let e=0;e<t.length;++e){m(t[e],n)}return}t.removeAttribute(n)}var w=e=>{if(!e.parentElement||e.getClientRects().length===0){throw new Error("target element must be part of the dom")}const t=e.getClientRects()[0];return{left:t.left+window.pageXOffset,right:t.right+window.pageXOffset,top:t.top+window.pageYOffset,bottom:t.bottom+window.pageYOffset}};var ue=(t,n=0)=>{let o;return(...e)=>{clearTimeout(o);o=setTimeout(()=>{t(...e)},n)}};var x=(e,t)=>{if(!(e instanceof HTMLElement)||!(t instanceof NodeList||t instanceof HTMLCollection||t instanceof Array)){throw new Error("You must provide an element and a list of elements.")}return Array.from(t).indexOf(e)};var me=e=>{if(!(e instanceof HTMLElement)){throw new Error("Element is not a node element.")}return e.parentNode!==null};var pe=(e,t,n)=>{if(!(e instanceof HTMLElement)||!(e.parentElement instanceof HTMLElement)){throw new Error("target and element must be a node")}e.parentElement.insertBefore(t,n==="before"?e:e.nextElementSibling)};var he=(e,t)=>pe(e,t,"before");var ge=(e,t)=>pe(e,t,"after");var ve=(t,n=(e,t)=>e,e=e=>e)=>{if(!(t instanceof HTMLElement)||!t.isSortable===true){throw new Error("You need to provide a sortableContainer to be serialized.")}if(typeof n!=="function"||typeof e!=="function"){throw new Error("You need to provide a valid serializer for items and the container.")}const o=d(t,"opts");const r=o.items;const i=v(t.children,r);const a=i.map(e=>{return{parent:t,node:e,html:e.outerHTML,index:x(e,i)}});const s={node:t,itemCount:a.length};return{container:e(s),items:a.map(e=>n(e,t))}};var be=(e,t,n="sortable-placeholder")=>{if(!(e instanceof HTMLElement)){throw new Error("You must provide a valid element as a sortable.")}if(!(t instanceof HTMLElement)&&t!==void 0){throw new Error("You must provide a valid element as a placeholder or set ot to undefined.")}if(t===void 0){if(["UL","OL"].includes(e.tagName)){t=document.createElement("li")}else if(["TABLE","TBODY"].includes(e.tagName)){t=document.createElement("tr");t.innerHTML='<td colspan="100"></td>'}else{t=document.createElement("div")}}if(typeof n==="string"){t.classList.add(...n.split(" "))}return t};var ye=e=>{if(!(e instanceof HTMLElement)){throw new Error("You must provide a valid dom element")}const n=window.getComputedStyle(e);if(n.getPropertyValue("box-sizing")==="border-box"){return parseInt(n.getPropertyValue("height"),10)}return["height","padding-top","padding-bottom"].map(e=>{const t=parseInt(n.getPropertyValue(e),10);return isNaN(t)?0:t}).reduce((e,t)=>e+t)};var we=e=>{if(!(e instanceof HTMLElement)){throw new Error("You must provide a valid dom element")}const n=window.getComputedStyle(e);return["width","padding-left","padding-right"].map(e=>{const t=parseInt(n.getPropertyValue(e),10);return isNaN(t)?0:t}).reduce((e,t)=>e+t)};var E=(e,t)=>{if(!(e instanceof Array)){throw new Error("You must provide a Array of HTMLElements to be filtered.")}if(typeof t!=="string"){return e}return e.filter(e=>{return e.querySelector(t)instanceof HTMLElement||e.shadowRoot&&e.shadowRoot.querySelector(t)instanceof HTMLElement}).map(e=>{return e.querySelector(t)||e.shadowRoot&&e.shadowRoot.querySelector(t)})};var q=e=>{return e.composedPath&&e.composedPath()[0]||e.target};var xe=(e,t,n)=>{return{element:e,posX:n.pageX-t.left,posY:n.pageY-t.top}};var Ee=(e,t,n)=>{if(!(e instanceof Event)){throw new Error("setDragImage requires a DragEvent as the first argument.")}if(!(t instanceof HTMLElement)){throw new Error("setDragImage requires the dragged element as the second argument.")}if(!n){n=xe}if(e.dataTransfer&&e.dataTransfer.setDragImage){const o=w(t);const r=n(t,o,e);if(!(r.element instanceof HTMLElement)||typeof r.posX!=="number"||typeof r.posY!=="number"){throw new Error("The customDragImage function you provided must return and object with the properties element[string], posX[integer], posY[integer].")}e.dataTransfer.effectAllowed="copyMove";e.dataTransfer.setData("text/plain",q(e).id);e.dataTransfer.setDragImage(r.element,r.posX,r.posY)}};var qe=(e,t)=>{if(e.isSortable===true){const n=y(e).getConfig("acceptFrom");if(n!==null&&n!==false&&typeof n!=="string"){throw new Error('HTML5Sortable: Wrong argument, "acceptFrom" must be "null", "false", or a valid selector string.')}if(n!==null){return n!==false&&n.split(",").filter(function(e){return e.length>0&&t.matches(e)}).length>0}if(e===t){return true}if(y(e).getConfig("connectWith")!==void 0&&y(e).getConfig("connectWith")!==null){return y(e).getConfig("connectWith")===y(t).getConfig("connectWith")}}return false};var Ce={items:null,connectWith:null,disableIEFix:null,acceptFrom:null,copy:false,placeholder:null,placeholderClass:"sortable-placeholder",draggingClass:"sortable-dragging",hoverClass:false,dropTargetContainerClass:false,debounce:0,throttleTime:100,maxItems:0,itemSerializer:void 0,containerSerializer:void 0,customDragImage:null,orientation:"vertical"};function Se(n,o=250){if(typeof n!=="function"){throw new Error("You must provide a function as the first argument for throttle.")}if(typeof o!=="number"){throw new Error("You must provide a number as the second argument for throttle.")}let r=null;return(...e)=>{const t=Date.now();if(r===null||t-r>=o){r=t;n.apply(this,e)}}}var C=(e,t)=>{if(typeof y(e).getConfig("hoverClass")==="string"){const n=y(e).getConfig("hoverClass").split(" ");if(t===true){s(e,"mousemove",Se(t=>{if(t.buttons===0){v(e.children,y(e).getConfig("items")).forEach(e=>{if(e===t.target||e.contains(t.target)){e.classList.add(...n)}else{e.classList.remove(...n)}})}},y(e).getConfig("throttleTime")));s(e,"mouseleave",()=>{v(e.children,y(e).getConfig("items")).forEach(e=>{e.classList.remove(...n)})})}else{f(e,"mousemove");f(e,"mouseleave")}}};var S;var L;var A;var T;var O;var I;var D;var H;var _;var Le=function(e){f(e,"dragstart");f(e,"dragend");f(e,"dragover");f(e,"dragenter");f(e,"drop");f(e,"mouseenter");f(e,"mouseleave")};var Ae=function(e,t){if(e){f(e,"dragleave")}if(t&&t!==e){f(t,"dragleave")}};var Te=function(e,t){let n=e;if(y(t).getConfig("copy")===true){n=e.cloneNode(true);u(n,"aria-copied","true");e.parentElement.appendChild(n);n.style.display="none";n.oldDisplay=e.style.display}return n};var ke=function(e){de(e);m(e,"aria-dropeffect")};var Me=function(e){m(e,"aria-grabbed");m(e,"aria-copied");m(e,"draggable");m(e,"role")};function Oe(e,t){if(t.composedPath){return t.composedPath().find(e=>e.isSortable)}while(e.isSortable!==true){e=e.parentElement}return e}function Ie(e,t){const n=d(e,"opts");const o=v(e.children,n.items);const r=o.filter(function(e){return e.contains(t)||e.shadowRoot&&e.shadowRoot.contains(t)});return r.length>0?r[0]:t}var De=function(e){const t=d(e,"opts")||{};const n=v(e.children,t.items);const o=E(n,t.handle);C(e,false);f(e,"dragover");f(e,"dragenter");f(e,"dragstart");f(e,"dragend");f(e,"drop");ke(e);f(o,"mousedown");Le(n);Me(n);Ae(T,H);e.isSortable=false};var He=function(e){const t=d(e,"opts");const n=v(e.children,t.items);const o=E(n,t.handle);u(e,"aria-dropeffect","move");d(e,"_disabled","false");u(o,"draggable","true");C(e,true);if(t.disableIEFix===false){const r=(document||window.document).createElement("span");if(typeof r.dragDrop==="function"){s(o,"mousedown",function(){if(n.indexOf(this)!==-1){this.dragDrop()}else{let e=this.parentElement;while(n.indexOf(e)===-1){e=e.parentElement}e.dragDrop()}})}}};var _e=function(e){const t=d(e,"opts");const n=v(e.children,t.items);const o=E(n,t.handle);u(e,"aria-dropeffect","none");d(e,"_disabled","true");u(o,"draggable","false");f(o,"mousedown");C(e,false)};var Be=function(e){const t=d(e,"opts");const n=v(e.children,t.items);const o=E(n,t.handle);d(e,"_disabled","false");Le(n);Ae(T,H);f(o,"mousedown");f(e,"dragover");f(e,"dragenter");f(e,"drop")};function B(e,h){const i=String(h);h=h||{};if(typeof e==="string"){e=document.querySelectorAll(e)}if(e instanceof HTMLElement){e=[e]}e=Array.prototype.slice.call(e);if(/serialize/.test(i)){return e.map(e=>{const t=d(e,"opts");return ve(e,t.itemSerializer,t.containerSerializer)})}e.forEach(function(l){if(/enable|disable|destroy/.test(i)){return B[i](l)}["connectWith","disableIEFix"].forEach(e=>{if(Object.prototype.hasOwnProperty.call(h,e)&&h[e]!==null){console.warn(`HTML5Sortable: You are using the deprecated configuration "${e}". This will be removed in an upcoming version, make sure to migrate to the new options when updating.`)}});h=Object.assign({},Ce,y(l).config,h);y(l).config=h;d(l,"opts",h);l.isSortable=true;Be(l);const e=v(l.children,h.items);let t;if(h.placeholder!==null&&h.placeholder!==void 0){const o=document.createElement(l.tagName);if(h.placeholder instanceof HTMLElement){o.appendChild(h.placeholder)}else{o.innerHTML=h.placeholder}t=o.children[0]}y(l).placeholder=be(l,t,h.placeholderClass);d(l,"items",h.items);if(h.acceptFrom){d(l,"acceptFrom",h.acceptFrom)}else if(h.connectWith){d(l,"connectWith",h.connectWith)}He(l);u(e,"role","option");u(e,"aria-grabbed","false");s(l,"dragstart",function(e){const t=q(e);if(t.isSortable===true){return}e.stopImmediatePropagation();if(h.handle&&!t.matches(h.handle)||t.getAttribute("draggable")==="false"){return}const n=Oe(t,e);const o=Ie(n,t);D=v(n.children,h.items);O=D.indexOf(o);I=x(o,n.children);T=n;Ee(e,o,h.customDragImage);L=ye(o);A=we(o);o.classList.add(h.draggingClass);S=Te(o,n);u(S,"aria-grabbed","true");n.dispatchEvent(new CustomEvent("sortstart",{detail:{origin:{elementIndex:I,index:O,container:T},item:S,originalTarget:t,dragEvent:e}}))});s(l,"dragenter",e=>{const n=q(e);const o=Oe(n,e);if(o&&o!==H){_=v(o.children,d(o,"items")).filter(e=>e!==y(l).placeholder);if(h.dropTargetContainerClass){o.classList.add(h.dropTargetContainerClass)}o.dispatchEvent(new CustomEvent("sortenter",{detail:{origin:{elementIndex:I,index:O,container:T},destination:{container:o,itemsBeforeUpdate:_},item:S,originalTarget:n}}));s(o,"dragleave",function(e){const t=e.relatedTarget||e.fromElement;if(!e.currentTarget.contains(t)){if(h.dropTargetContainerClass){o.classList.remove(h.dropTargetContainerClass)}o.dispatchEvent(new CustomEvent("sortleave",{detail:{origin:{elementIndex:I,index:O,container:o},item:S,originalTarget:n}}))}})}H=o});s(l,"dragend",function(e){if(!S){return}S.classList.remove(h.draggingClass);u(S,"aria-grabbed","false");if(S.getAttribute("aria-copied")==="true"&&d(S,"dropped")!=="true"){S.remove()}if(S.oldDisplay!==void 0){S.style.display=S.oldDisplay;delete S.oldDisplay}const t=Array.from(b.values()).map(e=>e.placeholder).filter(e=>e instanceof HTMLElement).filter(me)[0];if(t){t.remove()}l.dispatchEvent(new CustomEvent("sortstop",{detail:{origin:{elementIndex:I,index:O,container:T},item:S,dragEvent:e}}));H=null;S=null;L=null;A=null});s(l,"drop",function(e){if(!qe(l,S.parentElement)){return}e.preventDefault();e.stopPropagation();d(S,"dropped","true");const t=Array.from(b.values()).map(e=>{return e.placeholder}).filter(e=>e instanceof HTMLElement).filter(me)[0];if(t){t.replaceWith(S);if(S.oldDisplay!==void 0){S.style.display=S.oldDisplay;delete S.oldDisplay}}else{d(S,"dropped","false");return}const n=y(l).placeholder;const o=v(T.children,h.items).filter(e=>e!==n);const r=this.isSortable===true?this:this.parentElement;const i=v(r.children,d(r,"items")).filter(e=>e!==n);const a=x(S,Array.from(S.parentElement.children).filter(e=>e!==n));const s=x(S,i);if(h.dropTargetContainerClass){r.classList.remove(h.dropTargetContainerClass)}l.dispatchEvent(new CustomEvent("sortstop",{detail:{origin:{elementIndex:I,index:O,container:T},item:S,destination:{index:s,elementIndex:a,container:r,itemsBeforeUpdate:_,items:i},dragEvent:e}}));if(I!==a||T!==r){l.dispatchEvent(new CustomEvent("sortupdate",{detail:{origin:{elementIndex:I,index:O,container:T,itemsBeforeUpdate:D,items:o},destination:{index:s,elementIndex:a,container:r,itemsBeforeUpdate:_,items:i},item:S,dragEvent:e}}))}});const r=ue((n,e,o,r)=>{if(!S){return}if(h.forcePlaceholderSize){y(n).placeholder.style.height=L+"px";y(n).placeholder.style.width=A+"px"}if(Array.from(n.children).indexOf(e)>-1){const i=ye(e);const a=we(e);const s=x(y(n).placeholder,e.parentElement.children);const l=x(e,e.parentElement.children);if(i>L||a>A){const c=i-L;const d=a-A;const f=w(e).top;const u=w(e).left;if(s<l&&(h.orientation==="vertical"&&r<f||h.orientation==="horizontal"&&o<u)){return}if(s>l&&(h.orientation==="vertical"&&r>f+i-c||h.orientation==="horizontal"&&o>u+a-d)){return}}if(S.oldDisplay===void 0){S.oldDisplay=S.style.display}if(S.style.display!=="none"){S.style.display="none"}let t=false;try{const m=w(e).top+e.offsetHeight/2;const p=w(e).left+e.offsetWidth/2;t=h.orientation==="vertical"&&r>=m||h.orientation==="horizontal"&&o>=p}catch(e){t=s<l}if(t){ge(e,y(n).placeholder)}else{he(e,y(n).placeholder)}Array.from(b.values()).filter(e=>e.placeholder!==void 0).forEach(e=>{if(e.placeholder!==y(n).placeholder){e.placeholder.remove()}})}else{const t=Array.from(b.values()).filter(e=>e.placeholder!==void 0).map(e=>{return e.placeholder});if(t.indexOf(e)===-1&&n===e&&!v(e.children,h.items).length){t.forEach(e=>e.remove());e.appendChild(y(n).placeholder)}}},h.debounce);const n=function(e){let t=e.target;const n=t.isSortable===true?t:Oe(t,e);t=Ie(n,t);if(!S||!qe(n,S.parentElement)||d(n,"_disabled")==="true"){return}const o=d(n,"opts");if(parseInt(o.maxItems)&&v(n.children,d(n,"items")).length>=parseInt(o.maxItems)&&S.parentElement!==n){return}e.preventDefault();e.stopPropagation();e.dataTransfer.dropEffect=y(n).getConfig("copy")===true?"copy":"move";r(n,t,e.pageX,e.pageY)};s(e.concat(l),"dragover",n);s(e.concat(l),"dragenter",n)});return e}B.destroy=function(e){De(e)};B.enable=function(e){He(e)};B.disable=function(e){_e(e)};B.__testing={data:d,removeItemEvents:Le,removeItemData:Me,removeSortableData:ke,removeContainerEvents:Ae};var Pe=()=>{const t=p("dragClass");const s=document.querySelector(t);if(s){let e=s.querySelector("tbody");if(e){const n=e.querySelector("tbody>tr:first-child");const o=n.getAttribute("id");const r=n.querySelector("td:first-child");r?.classList.add("xq-move");e.setAttribute("id","tbody_"+o);const i=e.querySelectorAll("tbody>tr:not(:first-child)");for(const a of i){const l=a.querySelector("td:first-child");l?.classList.add("xq-move");const c=document.createElement("tbody");c.append(a);const d=a.getAttribute("id");c.setAttribute("id","tbody_"+d);e.after(c);e=c}}B(t,{items:"tbody",handle:".xq-move",placeholder:'<tbody><tr><td colspan="99"> </td></tr><tbody>'});s.addEventListener("sortstop",()=>{const n=[];let o=0;const e=s.querySelectorAll("tbody");for(const i of e){o++;const e=i.querySelector("tr:first-child");const t=e?.getAttribute("id");const a={id:t,ordernum:o};n.push(a)}const t=s.getAttribute("pid");let r=s.getAttribute("xq-url");if(!r){r=window.location.href;if(t){r=r.replace("/"+t,"")}r=r.slice(0,Math.max(0,r.lastIndexOf("/")));r+="/b-order"}fetch(r,{body:JSON.stringify(n),headers:{"content-type":"application/json"},method:"POST"}).then(async e=>{return e.json()}).then(e=>{if(e.code===200){}})})}};var Ne=()=>{const e=p("checkAllClass");const t=document.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;const{checked:n}=t;const o=h();const r=o?.querySelectorAll("tr > td:first-child > input[type=checkbox]");for(const i of r){if(i===t){continue}if(n){i.checked=true}else{i.checked=false}}})}};var je=()=>{let e;let t;let n;const o=p("backPageClass");const r=document.querySelectorAll(o);if(r){e=document.referrer;n=null;if(window.top!==window){try{n=window.top?.location.href}catch(e){}}if(e&&e!==document.location.href&&e!==n){sessionStorage.setItem(document.location.href,e);t=e}else{const i=sessionStorage.getItem(document.location.href);if(i){t=i.toString()}}for(const a of r){a.addEventListener("click",e=>{e.preventDefault();if(t){document.location.href=t}else{c({content:"系统无法自动返回上一个页面."})}})}}};var Ye=()=>{const e=p("authTableClass");const t=document.querySelectorAll(e);if(t){for(const i of t){const a=p("authCheckTableClass");const n=i.querySelector(a);if(n){const s=n.querySelector("input[type=checkbox]");if(s){s.addEventListener("click",e=>{const t=e.currentTarget;const{checked:n}=t;const o=i.querySelectorAll("input[type=checkbox]:not("+a+">input[type=checkbox])");for(const r of o){if(n){r.checked=true}else{r.checked=false}}})}}const o=p("authCheckRowClass");const r=i.querySelectorAll(o);for(const l of r){const c=l.querySelector("input[type=checkbox]");if(c){c.addEventListener("click",e=>{const t=e.currentTarget;const{checked:n}=t;const o=j(l,"td")[0];const r=o.querySelectorAll("input[type=checkbox]");for(const i of r){if(n){i.checked=true}else{i.checked=false}}})}}}}};var ze=()=>{const t=document.querySelectorAll(".xq-fileinput");if(t&&typeof jQuery!==void 0){let e;for(const n of t){e=n.hasAttribute("xq-config")?n.getAttribute("xq-config"):"{}";$(n).fileinput(JSON.parse(e)).on("filedeleted",e=>{const t=e.currentTarget;P(t)}).on("fileuploaded",e=>{const t=e.currentTarget;P(t)}).on("filesorted",e=>{const t=e.currentTarget;P(t)});P(n)}}};var P=e=>{const t=e.getAttribute("id");const n=t.replace("-xq-fileinput","");const o=document.querySelector("#"+n);const r=$(e).fileinput("getPreview");o?.setAttribute("value",JSON.stringify(r));const i=$(e).fileinput("getFilesCount",true);const a=e.getAttribute("xq-config");const s=JSON.parse(a);if(s!==null&&"required"in s){if(i>0){e.removeAttribute("required")}else{e.setAttribute("required","true")}if("content"in r){const{content:l}=r;if(l.length===0){e.setCustomValidity("需要至少上传一个文件")}else{e.setCustomValidity("")}}}};var Re=()=>{const e=p("captchaClass");const t=document.querySelector(e);if(t){t.addEventListener("click",e=>{const t=e.currentTarget;let n=t.getAttribute("src");if(n.includes("?")){n=n.slice(0,Math.max(0,n.lastIndexOf("?")));n=n+"?xq-r="+Math.random().toString()}else{n=n+"?xq-r="+Math.random().toString()}t.setAttribute("src",n)})}};var We=()=>{const e=h();const t=e.querySelector("thead");const n=p("orderClass");const o=p("orderAscClass");const r=p("orderDescClass");const i=n.slice(1);const a=o.slice(1);const s=r.slice(1);const l=t.querySelectorAll(n);const c=new URLSearchParams(window.location.search);if(c.has("orderby")){const d=c.get("orderby");const f=c.get("ordertype")??1;const u=t?.querySelector('th[field="'+d+'"]');if(u){u.classList.remove(i);if(f==1){u.classList.add(a)}else{u.classList.add(s)}}}for(const m of l){m.addEventListener("click",e=>{let t=m.getAttribute("field");let n=0;if(m.classList.contains(i)){m.classList.remove(i);m.classList.add(a);n=1}else if(m.classList.contains(a)){m.classList.remove(a);m.classList.add(s);n=2}else if(m.classList.contains(s)){m.classList.remove(s);m.classList.add(a);n=1}let o=window.location.href;o=g(o,"orderby",t);switch(n){case 1:o=g(o,"ordertype",1);break;case 2:o=g(o,"ordertype",2);break;default:o=g(o,"ordertype",1);break}window.location.href=o})}};var Fe=()=>{const e=p("pageSizeId");const t=document.querySelector(e);if(t){const n=new URLSearchParams(window.location.search);if(n.has("page-size")){const o=n.get("page-size");t.value=o??"10"}t.addEventListener("change",e=>{const t=e.currentTarget;const n=t.value;let o=window.location.href;o=g(o,"page-size",n);window.location.href=o})}};var $e=()=>{const e=h();const t=p("exportBtnClass");const n=e.querySelector(t);if(n){n.addEventListener("click",()=>{const e=new URL(window.location.href);let t=e.origin+e.pathname;t=t.slice(0,Math.max(0,t.lastIndexOf("/")));t=t+"/export";const n=new URLSearchParams(window.location.search);if(n.size>0){t=t+"?"+n.toString()}const o="xq-export-form";let r=document.querySelector("#"+o);if(r){r.setAttribute("action",t)}else{const i='<form action="'+t+'" method="post" style="display: none;" id="'+o+'"></form>';k(document.body,i);r=document.querySelector("#"+o)}r.submit()})}};var Ue=()=>{const e=h();if(e){We();Fe();const t=e.querySelectorAll("tr");for(const n of t){Q(n);V(n);Z(n);ee(n);K(n)}Ne();z();ce();$e();Pe()}je();Ye();ze();Re()};var Xe=(e={})=>{t(e);Ue()};e(()=>{Xe()})})();