dz-hooks
Version:
Vue3的实用Hooks集合
4 lines (3 loc) • 34.8 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["dz-hooks"]={},t.Vue)}(this,(function(t,e){"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r={exports:{}};!function(t,e){t.exports=function(){var t=1e3,e=6e4,r=36e5,o="millisecond",u="second",i="minute",a="hour",c="day",f="week",l="month",s="quarter",v="year",d="date",h="Invalid Date",p=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,y=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,m={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_")},g=function(t,e,n){var r=String(t);return!r||r.length>=e?t:""+Array(e+1-r.length).join(n)+t},w={s:g,z:function(t){var e=-t.utcOffset(),n=Math.abs(e),r=Math.floor(n/60),o=n%60;return(e<=0?"+":"-")+g(r,2,"0")+":"+g(o,2,"0")},m:function t(e,n){if(e.date()<n.date())return-t(n,e);var r=12*(n.year()-e.year())+(n.month()-e.month()),o=e.clone().add(r,l),u=n-o<0,i=e.clone().add(r+(u?-1:1),l);return+(-(r+(n-o)/(u?o-i:i-o))||0)},a:function(t){return t<0?Math.ceil(t)||0:Math.floor(t)},p:function(t){return{M:l,y:v,w:f,d:c,D:d,h:a,m:i,s:u,ms:o,Q:s}[t]||String(t||"").toLowerCase().replace(/s$/,"")},u:function(t){return void 0===t}},b="en",x={};x[b]=m;var S=function(t){return t instanceof D},O=function t(e,n,r){var o;if(!e)return b;if("string"==typeof e){var u=e.toLowerCase();x[u]&&(o=u),n&&(x[u]=n,o=u);var i=e.split("-");if(!o&&i.length>1)return t(i[0])}else{var a=e.name;x[a]=e,o=a}return!r&&o&&(b=o),o||!r&&b},$=function(t,e){if(S(t))return t.clone();var r="object"==n(e)?e:{};return r.date=t,r.args=arguments,new D(r)},E=w;E.l=O,E.i=S,E.w=function(t,e){return $(t,{locale:e.$L,utc:e.$u,x:e.$x,$offset:e.$offset})};var D=function(){function n(t){this.$L=O(t.locale,null,!0),this.parse(t)}var m=n.prototype;return m.parse=function(t){this.$d=function(t){var e=t.date,n=t.utc;if(null===e)return new Date(NaN);if(E.u(e))return new Date;if(e instanceof Date)return new Date(e);if("string"==typeof e&&!/Z$/i.test(e)){var r=e.match(p);if(r){var o=r[2]-1||0,u=(r[7]||"0").substring(0,3);return n?new Date(Date.UTC(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,u)):new Date(r[1],o,r[3]||1,r[4]||0,r[5]||0,r[6]||0,u)}}return new Date(e)}(t),this.$x=t.x||{},this.init()},m.init=function(){var t=this.$d;this.$y=t.getFullYear(),this.$M=t.getMonth(),this.$D=t.getDate(),this.$W=t.getDay(),this.$H=t.getHours(),this.$m=t.getMinutes(),this.$s=t.getSeconds(),this.$ms=t.getMilliseconds()},m.$utils=function(){return E},m.isValid=function(){return!(this.$d.toString()===h)},m.isSame=function(t,e){var n=$(t);return this.startOf(e)<=n&&n<=this.endOf(e)},m.isAfter=function(t,e){return $(t)<this.startOf(e)},m.isBefore=function(t,e){return this.endOf(e)<$(t)},m.$g=function(t,e,n){return E.u(t)?this[e]:this.set(n,t)},m.unix=function(){return Math.floor(this.valueOf()/1e3)},m.valueOf=function(){return this.$d.getTime()},m.startOf=function(t,e){var n=this,r=!!E.u(e)||e,o=E.p(t),s=function(t,e){var o=E.w(n.$u?Date.UTC(n.$y,e,t):new Date(n.$y,e,t),n);return r?o:o.endOf(c)},h=function(t,e){return E.w(n.toDate()[t].apply(n.toDate("s"),(r?[0,0,0,0]:[23,59,59,999]).slice(e)),n)},p=this.$W,y=this.$M,m=this.$D,g="set"+(this.$u?"UTC":"");switch(o){case v:return r?s(1,0):s(31,11);case l:return r?s(1,y):s(0,y+1);case f:var w=this.$locale().weekStart||0,b=(p<w?p+7:p)-w;return s(r?m-b:m+(6-b),y);case c:case d:return h(g+"Hours",0);case a:return h(g+"Minutes",1);case i:return h(g+"Seconds",2);case u:return h(g+"Milliseconds",3);default:return this.clone()}},m.endOf=function(t){return this.startOf(t,!1)},m.$set=function(t,e){var n,r=E.p(t),f="set"+(this.$u?"UTC":""),s=(n={},n[c]=f+"Date",n[d]=f+"Date",n[l]=f+"Month",n[v]=f+"FullYear",n[a]=f+"Hours",n[i]=f+"Minutes",n[u]=f+"Seconds",n[o]=f+"Milliseconds",n)[r],h=r===c?this.$D+(e-this.$W):e;if(r===l||r===v){var p=this.clone().set(d,1);p.$d[s](h),p.init(),this.$d=p.set(d,Math.min(this.$D,p.daysInMonth())).$d}else s&&this.$d[s](h);return this.init(),this},m.set=function(t,e){return this.clone().$set(t,e)},m.get=function(t){return this[E.p(t)]()},m.add=function(n,o){var s,d=this;n=Number(n);var h=E.p(o),p=function(t){var e=$(d);return E.w(e.date(e.date()+Math.round(t*n)),d)};if(h===l)return this.set(l,this.$M+n);if(h===v)return this.set(v,this.$y+n);if(h===c)return p(1);if(h===f)return p(7);var y=(s={},s[i]=e,s[a]=r,s[u]=t,s)[h]||1,m=this.$d.getTime()+n*y;return E.w(m,this)},m.subtract=function(t,e){return this.add(-1*t,e)},m.format=function(t){var e=this,n=this.$locale();if(!this.isValid())return n.invalidDate||h;var r=t||"YYYY-MM-DDTHH:mm:ssZ",o=E.z(this),u=this.$H,i=this.$m,a=this.$M,c=n.weekdays,f=n.months,l=function(t,n,o,u){return t&&(t[n]||t(e,r))||o[n].slice(0,u)},s=function(t){return E.s(u%12||12,t,"0")},v=n.meridiem||function(t,e,n){var r=t<12?"AM":"PM";return n?r.toLowerCase():r},d={YY:String(this.$y).slice(-2),YYYY:this.$y,M:a+1,MM:E.s(a+1,2,"0"),MMM:l(n.monthsShort,a,f,3),MMMM:l(f,a),D:this.$D,DD:E.s(this.$D,2,"0"),d:String(this.$W),dd:l(n.weekdaysMin,this.$W,c,2),ddd:l(n.weekdaysShort,this.$W,c,3),dddd:c[this.$W],H:String(u),HH:E.s(u,2,"0"),h:s(1),hh:s(2),a:v(u,i,!0),A:v(u,i,!1),m:String(i),mm:E.s(i,2,"0"),s:String(this.$s),ss:E.s(this.$s,2,"0"),SSS:E.s(this.$ms,3,"0"),Z:o};return r.replace(y,(function(t,e){return e||d[t]||o.replace(":","")}))},m.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},m.diff=function(n,o,d){var h,p=E.p(o),y=$(n),m=(y.utcOffset()-this.utcOffset())*e,g=this-y,w=E.m(this,y);return w=(h={},h[v]=w/12,h[l]=w,h[s]=w/3,h[f]=(g-m)/6048e5,h[c]=(g-m)/864e5,h[a]=g/r,h[i]=g/e,h[u]=g/t,h)[p]||g,d?w:E.a(w)},m.daysInMonth=function(){return this.endOf(l).$D},m.$locale=function(){return x[this.$L]},m.locale=function(t,e){if(!t)return this.$L;var n=this.clone(),r=O(t,e,!0);return r&&(n.$L=r),n},m.clone=function(){return E.w(this.$d,this)},m.toDate=function(){return new Date(this.valueOf())},m.toJSON=function(){return this.isValid()?this.toISOString():null},m.toISOString=function(){return this.$d.toISOString()},m.toString=function(){return this.$d.toUTCString()},n}(),M=D.prototype;return $.prototype=M,[["$ms",o],["$s",u],["$m",i],["$H",a],["$W",c],["$M",l],["$y",v],["$D",d]].forEach((function(t){M[t[1]]=function(e){return this.$g(e,t[0],t[1])}})),$.extend=function(t,e){return t.$i||(t(e,D,$),t.$i=!0),$},$.locale=O,$.isDayjs=S,$.unix=function(t){return $(1e3*t)},$.en=x[b],$.Ls=x,$.p={},$}()}(r);var o=r.exports;const u={format:"YYYY-MM-DD HH:mm:ss",method:"format"};const i=(t,e)=>{let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout((()=>{t.call(this,...r)}),e)}},a=(t,e)=>{let n=Date.now();return function(...r){const o=Date.now();o-n<e||(n=o,t.call(this,...r))}},c=(t,e)=>({run:i(t,"number"==typeof e?e:1e3)}),f=(t,e)=>({run:a(t,"number"==typeof e?e:1e3)});function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function v(t,e){return v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},v(t,e)}function d(t,e){if(e&&("object"===n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function p(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}function y(t,e,n){return y=p()?Reflect.construct.bind():function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&v(o,n.prototype),o},y.apply(null,arguments)}function m(t){var e="function"==typeof Map?new Map:void 0;return m=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return y(t,arguments,h(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),v(r,t)},m(t)}function g(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,o)}function w(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){g(u,r,o,i,a,"next",t)}function a(t){g(u,r,o,i,a,"throw",t)}i(void 0)}))}}function b(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return l(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?l(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function x(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}var S={exports:{}},O={exports:{}};!function(t){function e(n){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(n)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports}(O),function(t){var e=O.exports.default;function n(){
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
t.exports=n=function(){return r},t.exports.__esModule=!0,t.exports.default=t.exports;var r={},o=Object.prototype,u=o.hasOwnProperty,i="function"==typeof Symbol?Symbol:{},a=i.iterator||"@@iterator",c=i.asyncIterator||"@@asyncIterator",f=i.toStringTag||"@@toStringTag";function l(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{l({},"")}catch(t){l=function(t,e,n){return t[e]=n}}function s(t,e,n,r){var o=e&&e.prototype instanceof h?e:h,u=Object.create(o.prototype),i=new D(r||[]);return u._invoke=function(t,e,n){var r="suspendedStart";return function(o,u){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw u;return T()}for(n.method=o,n.arg=u;;){var i=n.delegate;if(i){var a=O(i,n);if(a){if(a===d)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=v(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===d)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,i),u}function v(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}r.wrap=s;var d={};function h(){}function p(){}function y(){}var m={};l(m,a,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(M([])));w&&w!==o&&u.call(w,a)&&(m=w);var b=y.prototype=h.prototype=Object.create(m);function x(t){["next","throw","return"].forEach((function(e){l(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,n){function r(o,i,a,c){var f=v(t[o],t,i);if("throw"!==f.type){var l=f.arg,s=l.value;return s&&"object"==e(s)&&u.call(s,"__await")?n.resolve(s.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):n.resolve(s).then((function(t){l.value=t,a(l)}),(function(t){return r("throw",t,a,c)}))}c(f.arg)}var o;this._invoke=function(t,e){function u(){return new n((function(n,o){r(t,e,n,o)}))}return o=o?o.then(u,u):u()}}function O(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,O(t,e),"throw"===e.method))return d;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var r=v(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,d;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,d):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function $(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function D(t){this.tryEntries=[{tryLoc:"root"}],t.forEach($,this),this.reset(!0)}function M(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,r=function e(){for(;++n<t.length;)if(u.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return r.next=r}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=y,l(b,"constructor",y),l(y,"constructor",p),p.displayName=l(y,f,"GeneratorFunction"),r.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===p||"GeneratorFunction"===(e.displayName||e.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,l(t,f,"GeneratorFunction")),t.prototype=Object.create(b),t},r.awrap=function(t){return{__await:t}},x(S.prototype),l(S.prototype,c,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,o,u){void 0===u&&(u=Promise);var i=new S(s(t,e,n,o),u);return r.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(b),l(b,f,"Generator"),l(b,a,(function(){return this})),l(b,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},r.values=M,D.prototype={constructor:D,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(n,r){return i.type="throw",i.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r],i=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var a=u.call(o,"catchLoc"),c=u.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var r=this.tryEntries[n];if(r.tryLoc<=this.prev&&u.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var o=r;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,d):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),E(n),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;E(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:M(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},r}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports}(S);var $=S.exports(),E=$;try{regeneratorRuntime=$}catch(t){"object"===("undefined"==typeof globalThis?"undefined":n(globalThis))?globalThis.regeneratorRuntime=$:Function("r","regeneratorRuntime = r")($)}function D(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,r=h(t);if(e){var o=h(this).constructor;n=Reflect.construct(r,arguments,o)}else n=r.apply(this,arguments);return d(this,n)}}function M(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function T(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?M(Object(n),!0).forEach((function(e){x(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var _={},L=Symbol("GLOBAL_OPTIONS_PROVIDE_KEY"),j=function(){return _},P=function(t){return null!==t&&"object"===n(t)},A=function(t){return t instanceof Function},R=function(t){return null==t},C="undefined"==typeof window,k=function(){var t;return!(!C&&!R(null===(t=window.document)||void 0===t?void 0:t.visibilityState))||"visible"===window.document.visibilityState},I=function(){return new Promise((function(){}))},N=function(t){return e.isRef(t)?t.value:t},F=new Map;function B(t,e,n){var r,o,u,i,a,c,f=0,l=!1,s=!1,v=!0,d=!e&&0!==e&&"function"==typeof window.requestAnimationFrame;if("function"!=typeof t)throw new TypeError("Expected a function");function h(e){var n=r,u=o;return r=o=void 0,f=e,i=t.apply(u,n)}function p(t,e){return d?(window.cancelAnimationFrame(a),window.requestAnimationFrame(t)):setTimeout(t,e)}function y(t){return f=t,a=p(g,e),l?h(t):i}function m(t){var n=t-c;return void 0===c||n>=e||n<0||s&&t-f>=u}function g(){var t=Date.now();if(m(t))return w(t);a=p(g,function(t){var n=t-f,r=e-(t-c);return s?Math.min(r,u-n):r}(t))}function w(t){return a=void 0,v&&r?h(t):(r=o=void 0,i)}function b(){for(var t=Date.now(),n=m(t),u=arguments.length,f=new Array(u),l=0;l<u;l++)f[l]=arguments[l];if(r=f,o=this,c=t,n){if(void 0===a)return y(c);if(s)return a=p(g,e),h(c)}return void 0===a&&(a=p(g,e)),i}return e=+e||0,P(n)&&(l=!!n.leading,u=(s="maxWait"in n)?Math.max(+n.maxWait||0,e):u,v="trailing"in n?!!n.trailing:v),b.cancel=function(){void 0!==a&&function(t){if(d)return window.cancelAnimationFrame(t);clearTimeout(t)}(a),f=0,r=c=o=a=void 0},b.flush=function(){return void 0===a?i:w(Date.now())},b.pending=function(){return void 0!==a},b}var Y=function(t,n){var r=n.debounceInterval,o=n.debounceOptions,u=n.manual,i=e.ref(!1),a=e.ref(),c=e.computed((function(){return o})),f=e.computed((function(){return N(r)})),l=e.ref(t.context.runAsync);return u||(i.value=!0),e.watchEffect((function(e){R(f.value)||(a.value=B((function(t){return t()}),f.value,c.value),t.context.runAsync=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return new Promise((function(t,n){i.value?(i.value=!1,l.value.apply(l,e).then(t).catch(n)):a.value((function(){l.value.apply(l,e).then(t).catch(n)}))}))},e((function(){var e;null===(e=a.value)||void 0===e||e.cancel(),t.context.runAsync=l.value})))})),{onCancel:function(){var t;null===(t=a.value)||void 0===t||t.cancel()}}},z=function(t,n){var r=n.errorRetryCount,o=void 0===r?0:r,u=n.errorRetryInterval,i=void 0===u?0:u,a=e.ref(),c=e.ref(0),f=e.computed((function(){return N(o)})),l=e.computed((function(){return N(i)})),s=!1,v=function(){c.value=0},d=e.computed((function(){if(l.value)return l.value;return 1e3*Math.floor(Math.random()*Math.pow(2,Math.min(c.value,9))+1)})),h=function(){a.value&&a.value()};return{onBefore:function(){s||v(),s=!1,h()},onSuccess:function(){v()},onError:function(){var e,n,r;a.value=(n=-1===f.value,r=c.value<f.value,(n||r)&&(n||(c.value+=1),e=setTimeout((function(){s=!0,t.context.refresh()}),d.value)),function(){return e&&clearTimeout(e)})},onCancel:function(){v(),h()}}},H=function(t,n){var r=n.ready,o=void 0===r?e.ref(!0):r,u=n.manual,i=n.defaultParams,a=void 0===i?[]:i;return e.watch(o,(function(e){var n;!u&&e&&(n=t.context).run.apply(n,b(a))}),{flush:"sync"}),{onBefore:function(){if(!o.value)return t.loading.value=!1,{isBreak:!0}}}},W=function(t,n){var r=n.refreshDeps,o=void 0===r?[]:r,u=n.refreshDepsAction,i=n.manual;return null!=o&&o.length&&e.watch(o,(function(){u?u():!i&&t.context.refresh()})),{}},U=function(t,n){var r=n.throttleInterval,o=n.throttleOptions,u=e.ref(),i=e.computed((function(){return N(r)})),a=e.computed((function(){return o})),c=e.ref(t.context.runAsync);return e.watchEffect((function(e){if(R(r))return{};u.value=function(t,e,n){var r=!0,o=!0;if("function"!=typeof t)throw new TypeError("Expected a function");return P(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),B(t,e,{leading:r,trailing:o,maxWait:e})}((function(t){return t()}),i.value,a.value),t.context.runAsync=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];return new Promise((function(t,n){u.value((function(){c.value.apply(c,e).then(t).catch(n)}))}))},e((function(){var e;null===(e=u.value)||void 0===e||e.cancel(),t.context.runAsync=c.value}))})),{onCancel:function(){var t;null===(t=u.value)||void 0===t||t.cancel()}}},V=function(t,e){return function(){for(var n=e,r=t.length;r-- >0;)n=t[r](n);return n()}},q=function(t,n,r){var o,u,i,a,c=n.initialData,f=n.onSuccess,l=n.onError,s=n.onBefore,v=n.onAfter,d=e.ref(null!==(o=null==r?void 0:r.loading)&&void 0!==o&&o),h=e.shallowRef(null!==(u=null==r?void 0:r.data)&&void 0!==u?u:c),p=e.shallowRef(null==r?void 0:r.error),y=e.ref(null==r?void 0:r.params),m=e.ref([]),g=e.shallowRef("pending"),x={},S=(i={status:g,loading:d,data:h,error:p,params:y},a=[],function(t){Object.keys(t).forEach((function(e){i[e].value=t[e]})),a.forEach((function(t){return t(i)}))}),O=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];if("onQuery"===t){var o=m.value.map((function(t){return t.onQuery})).filter(Boolean);return{servicePromise:V(o,n[0])()}}var u=m.value.map((function(e){var r,o;return null===(o=e[t])||void 0===o?void 0:(r=o).call.apply(r,[e].concat(n))}));return Object.assign.apply(Object,[{}].concat(b(u)))},$=e.ref(0);return x.runAsync=w(E.mark((function e(){var n,r,o,u,i,a,c,d,h,p,m,g,w=arguments;return E.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=w.length,r=new Array(n),o=0;o<n;o++)r[o]=w[o];if(S({loading:!0,params:r,status:"pending"}),$.value+=1,u=$.value,i=O("onBefore",r),a=i.isBreak,c=i.breakResult,d=void 0===c?I():c,!a){e.next=8;break}return S({status:"settled"}),e.abrupt("return",d);case 8:return null==s||s(r),e.prev=9,p=O("onQuery",h=function(){return new Promise((function(e){return e(t.apply(void 0,b(y.value)))}))}),(m=p.servicePromise)||(m=h()),e.next=15,m;case 15:if(g=e.sent,u===$.value){e.next=18;break}return e.abrupt("return",I());case 18:return S({data:g,loading:!1,error:void 0,status:"settled"}),O("onSuccess",g,r),null==f||f(g,r),O("onAfter",r,g,void 0),null==v||v(r),e.abrupt("return",g);case 26:if(e.prev=26,e.t0=e.catch(9),u===$.value){e.next=30;break}return e.abrupt("return",I());case 30:throw S({loading:!1,error:e.t0,status:"settled"}),O("onError",e.t0,r),null==l||l(e.t0,r),O("onAfter",r,void 0,e.t0),null==v||v(r),e.t0;case 36:case"end":return e.stop()}}),e,null,[[9,26]])}))),x.run=w(E.mark((function t(){var e=arguments;return E.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:x.runAsync.apply(x,e).catch((function(t){l||console.error(t)}));case 1:case"end":return t.stop()}}),t)}))),x.cancel=function(){$.value+=1,S({loading:!1}),O("onCancel")},x.refresh=function(){x.run.apply(x,b(y.value||[]))},x.refreshAsync=function(){return x.runAsync.apply(x,b(y.value||[]))},x.mutate=function(t){var e=A(t)?t(h.value):t,n=P(e)?Object.assign({},e):e;S({data:n}),O("onMutate",n)},{status:g,loading:d,data:h,error:p,params:y,plugins:m,context:x}};var G=new Map,K=new Map,Q=function(t,n){var r=n.cacheKey,o=n.cacheTime,u=void 0===o?6e5:o,i=n.staleTime,a=void 0===i?0:i,c=n.getCache,f=n.setCache;if(!r)return{};var l,s=A(r)?r:function(){return r},v=e.ref((function(){})),d=function(t){return c?c(t):function(t){if(!R(t))return F.get(t)}(t)},h=function(t,e,n){f?f(t,n):function(t,e,n){var r=F.get(t);null!=r&&r.timer&&clearTimeout(r.timer);var o=setTimeout((function(){return F.delete(t)}),e);F.set(t,T(T({},n),{},{timer:o}))}(t,e,n),function(t,e){K.has(t)&&K.get(t).forEach((function(t){return t(e)}))}(t,n.data)},p=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},y=function(e){var n,r,o=s(e);return n=o,r=function(e){t.data.value=e},K.has(n)?K.get(n).push(r):K.set(n,[r]),function(){var t=K.get(n).indexOf(r);K.get(n).splice(t,1)}},m=s(),g=d(m);return g&&p(g,"data")&&(t.data.value=g.data,t.params.value=g.params),m&&(v.value=y()),e.onUnmounted((function(){v.value()})),{onBefore:function(e){var n,r=s(e),o=d(r);return o&&p(o,"data")?(n=o.time,-1===a||n+a>(new Date).getTime()?(t.data.value=o.data,t.loading.value=!1,{isBreak:!0,breakResult:o.data}):void(t.data.value=o.data)):{}},onQuery:function(e){var n=t.params.value,r=s(n),o=function(t){return G.get(t)}(r);return o&&o!==l||(o=e(),l=o,function(t,e){G.set(t,e),e.then((function(e){return G.delete(t),e})).catch((function(){G.delete(t)}))}(r,o)),function(){return o}},onSuccess:function(t,e){var n=s(e);n&&(v.value(),h(n,u,{data:t,params:e,time:(new Date).getTime()}),v.value=y(e))},onMutate:function(e){var n=s(t.params.value);n&&(v.value(),h(n,u,{data:e,params:t.params.value,time:(new Date).getTime()}),v.value=y(t.params.value))}}};function J(t){var e,n;return new(function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&v(t,e)}(a,t);var r,o,u,i=D(a);function a(t){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(r=i.call(this,t)).cancel=function(){n(),clearTimeout(e)},r}return r=a,o&&s(r.prototype,o),u&&s(r,u),Object.defineProperty(r,"prototype",{writable:!1}),r}(m(Promise)))((function(r){n=r,e=setTimeout(n,t)}))}function Z(){return(new Date).getTime()}var X,tt=function(t,n){var r=n.loadingDelay,o=void 0===r?0:r,u=n.loadingKeep,i=void 0===u?0:u,a=e.ref((function(){})),c=e.computed((function(){return N(o)})),f=e.computed((function(){return N(i)})),l=Z(),s={};return{onBefore:function(){var e;t.loading.value=!c.value,a.value(),a.value=(c.value&&(e=setTimeout((function(){"pending"===t.status.value&&(t.loading.value=!0)}),c.value)),function(){return e&&clearTimeout(e)}),l=Z()},onQuery:function(t){if(!f.value)return function(){return t()};s=J(f.value+c.value);var e=Promise.allSettled([t().finally((function(){Z()-l<=c.value&&s.cancel()})),s]).then((function(t){var e=t[0];return"fulfilled"===e.status?e.value:Promise.reject(e.reason)}));return function(){return e}},onCancel:function(){a.value()},onAfter:function(){a.value()}}},et=new Set,nt=new Set,rt=new Set,ot=function(t,e){var n;switch(t){case"FOCUS_LISTENER":n=et;break;case"RECONNECT_LISTENER":n=rt;break;case"VISIBLE_LISTENER":n=nt}if(!n.has(e))return n.add(e),function(){n.delete(e)}},ut=function(t){t.forEach((function(t){t()}))};!C&&null!==(X=window)&&void 0!==X&&X.addEventListener&&(window.addEventListener("visibilitychange",(function(){k()&&ut(nt)}),!1),window.addEventListener("focus",(function(){return ut(et)}),!1),window.addEventListener("online",(function(){return ut(rt)}),!1));var it=function(t,n){var r=n.pollingInterval,o=n.pollingWhenHidden,u=void 0!==o&&o,i=n.pollingWhenOffline,a=void 0!==i&&i,c=n.errorRetryCount,f=void 0===c?0:c,l=e.ref(),s=e.ref(!1),v=e.computed((function(){return N(r)})),d=e.computed((function(){return N(f)})),h=[],p=function(t){t&&h.push(t)},y=function(){return(u||k())&&(a||null===(t=!C&&(null===(e=window.navigator)||void 0===e?void 0:e.onLine))||void 0===t||t);var t,e},m=function(e){if(!t.error.value||0===d.value){var n;if(!R(v.value)&&v.value>=0){if(!y())return void(s.value=!0);n=setTimeout(e,v.value)}return function(){return n&&clearTimeout(n)}}},g=function(){s.value&&y()&&(t.context.refresh(),s.value=!1)};return e.watch(v,(function(){l.value&&(l.value(),l.value=m((function(){return t.context.refresh()})))})),u||p(ot("VISIBLE_LISTENER",g)),a||p(ot("RECONNECT_LISTENER",g)),e.onUnmounted((function(){h.forEach((function(t){return t()}))})),{onBefore:function(){var t;null===(t=l.value)||void 0===t||t.call(l)},onCancel:function(){var t;null===(t=l.value)||void 0===t||t.call(l)},onAfter:function(){l.value=m((function(){return t.context.refresh()}))}}},at=function(t,n){var r=n.refreshOnWindowFocus,o=void 0!==r&&r,u=n.refocusTimespan,i=void 0===u?5e3:u,a=e.computed((function(){return N(o)})),c=e.computed((function(){return N(i)})),f=[],l=function(t){t&&f.push(t)},s=function(){f.forEach((function(t){return t()}))};return e.watchEffect((function(){if(s(),a.value){var e=(n=t.context.refresh,r=c.value,o=!1,function(){o||(o=!0,n.apply(void 0,arguments),setTimeout((function(){o=!1}),r))});l(ot("VISIBLE_LISTENER",e)),l(ot("FOCUS_LISTENER",e))}var n,r,o})),e.onUnmounted((function(){s()})),{}};var ct;"undefined"!=typeof window&&(null==(ct=null==window?void 0:window.navigator)?void 0:ct.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent);const ft=t=>{var n,r,o,u,i;const a=e.ref(t.pageNum),c=e.ref(t.pageSize),f=e.ref(null!==(n=t.pageNumSendKey)&&void 0!==n?n:"pageNum"),l=e.ref(null!==(r=t.pageSizeSendKey)&&void 0!==r?r:"pageSize"),s=e.ref(null!==(o=t.listKey)&&void 0!==o?o:"records"),v=e.ref(null!==(u=t.pageSizeKey)&&void 0!==u?u:"size"),d=e.ref(null!==(i=t.totalKey)&&void 0!==i?i:"total"),h=e.ref(0),p=e.reactive(t.defaultParams?t.defaultParams:{});let y=e.reactive({...e.toRefs(p),[f.value]:a.value,[l.value]:c.value});const m=e.ref({loading:!1,data:void 0}),g=function(){t.requestList&&"function"==typeof t.requestList||console.error("请定义一个函数用于获取列表数据"),m.value.loading=!0,t.requestList(y).then((t=>{m.value.loading=!1,m.value.data=t[s.value],c.value=t[v.value],h.value=t[d.value]})).catch((t=>{console.error(t),m.value.loading=!1}))};g();return{pageNum:a,pageSize:c,total:h,onCurrentChange:t=>{y[f.value]=t,a.value=t,g()},onSizeChange:t=>{y[f.value]=1,a.value=1,y[l.value]=t,c.value=t,g()},fetchData:g,pageDatas:m}};t.useBoolean=function(t){let[n,r]=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=n.truthyValue,o=void 0===r||r,u=n.falsyValue,i=void 0!==u&&u,a=e.isRef(t),c=e.ref(t);function f(t){return arguments.length?(c.value=t,c.value):(c.value=c.value===e.unref(o)?e.unref(i):e.unref(o),c.value)}return a?f:[c,f]}();n.value=t||false;const o={toggle:()=>{r()},setTrue:()=>{n.value=!0},setFalse:()=>{n.value=!1}};return[n,o]},t.useDate=function(t,n){const r=e.ref();let i=t||+new Date;const{format:a,method:c,methodParam:f}={...u,...n},l=t=>{switch(console.log(t),i=t||+new Date,c){case"format":r.value=o(i).format(a);break;case void 0:break;default:let t=o(i);f&&(t=t[c](f),n&&n.format&&(t=t.format(a))),r.value=t}};return l(),{data:e.readonly(r),refresh:l}},t.useDebounce=(t,n)=>{n=n||1e3;const r=e.ref(t.value),{run:o}=c((()=>r.value=t.value),n);return e.watch(t,(()=>o()),{deep:!0}),r},t.useDebounceFn=c,t.useFormTable=t=>{const e=t.formRef;let{pageNum:n,pageSize:r,total:o,onCurrentChange:u,onSizeChange:i,fetchData:a,pageDatas:c}=ft(t);return{pageNum:n,pageSize:r,total:o,reset:()=>{e.value&&(e.value.resetFields(),n.value=1,r.value=t.pageSize,a())},onCurrentChange:u,onSizeChange:i,fetchData:a,pageDatas:c}},t.useModalFn=function(){const t=e.ref(!1),n=e.ref(),r=()=>{t.value=!1,n.value=void 0};return{editId:n,visible:t,openModal:e=>{t.value=!0,n.value=e||void 0},closeModal:r,onCancel:async t=>{t&&"function"==typeof t?(await t(),r()):console.error("请定义一个函数用于退出弹窗回调")},onOk:async t=>{t&&"function"==typeof t?(await t(),r()):console.error("请定义一个函数用于确认弹窗回调")}}},t.usePagination=ft,t.useRequest=function(t,n){return function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2?arguments[2]:void 0,o=e.inject(L,{}),u=T(T(T({},j()),o),n),i=u.manual,a=void 0!==i&&i,c=u.defaultParams,f=void 0===c?[]:c,l=q(t,u);if(l.plugins.value=r.map((function(t){return t(l,u)})),!a){var s,v=l.params.value||f;(s=l.context).run.apply(s,b(v))}return e.onUnmounted((function(){l.context.cancel()})),{loading:l.loading,data:l.data,error:l.error,params:l.params,cancel:l.context.cancel,refresh:l.context.refresh,refreshAsync:l.context.refreshAsync,mutate:l.context.mutate,run:l.context.run,runAsync:l.context.runAsync}}(t,n,[tt,z,Y,it,U,at,W,H,Q])},t.useRequestProvider=function(t){e.provide(L,t)},t.useThrottle=(t,n)=>{n=n||1e3;const r=e.ref(t.value),{run:o}=f((()=>r.value=t.value),n);return e.watch(t,(()=>o()),{deep:!0}),r},t.useThrottleFn=f,Object.defineProperty(t,"__esModule",{value:!0})}));