@banmao/hooks 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # @banmao/hooks
2
+
3
+ 这是一个基于 Vue Composition API 的自定义 Hooks 库,旨在提高开发效率并简化复杂的状态管理和逻辑处理。
4
+
5
+ ## 特性
6
+
7
+ - 提供多种实用的 Vue Composition API Hooks
8
+ - 易于集成到 Vue 3 项目中
9
+ - 支持 TypeScript,具有完善的类型定义
10
+
11
+ ## 安装
12
+
13
+ 使用 pnpm 或 yarn 安装:
14
+
15
+ ```bash
16
+ pnpm install @banmao/hooks
17
+ # 或者
18
+ yarn add @banmao/hooks
19
+
20
+ ```vue
21
+ import { useCustomHook } from '@banmao/hooks';
22
+ <script setup>
23
+ defineComponent({
24
+ setup() {
25
+ const { value, setValue } = useCustomHook();
26
+
27
+ return {
28
+ value,
29
+ setValue,
30
+ };
31
+ },
32
+ });
33
+ </script>
34
+
35
+ <template>
36
+ <!-- element -->
37
+ </template>
38
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue");function ce(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Z={exports:{}},le=Z.exports,re;function de(){return re||(re=1,function(t,s){(function(d,m){t.exports=m()})(le,function(){var d=1e3,m=6e4,w=36e5,y="millisecond",f="second",v="minute",h="hour",p="day",S="week",o="month",g="quarter",D="year",O="date",j="Invalid Date",I=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,G=/\[([^\]]+)]|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,b={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("_"),ordinal:function(a){var r=["th","st","nd","rd"],e=a%100;return"["+a+(r[(e-20)%10]||r[e]||r[0])+"]"}},L=function(a,r,e){var i=String(a);return!i||i.length>=r?a:""+Array(r+1-i.length).join(e)+a},z={s:L,z:function(a){var r=-a.utcOffset(),e=Math.abs(r),i=Math.floor(e/60),n=e%60;return(r<=0?"+":"-")+L(i,2,"0")+":"+L(n,2,"0")},m:function a(r,e){if(r.date()<e.date())return-a(e,r);var i=12*(e.year()-r.year())+(e.month()-r.month()),n=r.clone().add(i,o),u=e-n<0,c=r.clone().add(i+(u?-1:1),o);return+(-(i+(e-n)/(u?n-c:c-n))||0)},a:function(a){return a<0?Math.ceil(a)||0:Math.floor(a)},p:function(a){return{M:o,y:D,w:S,d:p,D:O,h,m:v,s:f,ms:y,Q:g}[a]||String(a||"").toLowerCase().replace(/s$/,"")},u:function(a){return a===void 0}},H="en",T={};T[H]=b;var K="$isDayjsObject",P=function(a){return a instanceof J||!(!a||!a[K])},Y=function a(r,e,i){var n;if(!r)return H;if(typeof r=="string"){var u=r.toLowerCase();T[u]&&(n=u),e&&(T[u]=e,n=u);var c=r.split("-");if(!n&&c.length>1)return a(c[0])}else{var M=r.name;T[M]=r,n=M}return!i&&n&&(H=n),n||!i&&H},_=function(a,r){if(P(a))return a.clone();var e=typeof r=="object"?r:{};return e.date=a,e.args=arguments,new J(e)},$=z;$.l=Y,$.i=P,$.w=function(a,r){return _(a,{locale:r.$L,utc:r.$u,x:r.$x,$offset:r.$offset})};var J=function(){function a(e){this.$L=Y(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[K]=!0}var r=a.prototype;return r.parse=function(e){this.$d=function(i){var n=i.date,u=i.utc;if(n===null)return new Date(NaN);if($.u(n))return new Date;if(n instanceof Date)return new Date(n);if(typeof n=="string"&&!/Z$/i.test(n)){var c=n.match(I);if(c){var M=c[2]-1||0,x=(c[7]||"0").substring(0,3);return u?new Date(Date.UTC(c[1],M,c[3]||1,c[4]||0,c[5]||0,c[6]||0,x)):new Date(c[1],M,c[3]||1,c[4]||0,c[5]||0,c[6]||0,x)}}return new Date(n)}(e),this.init()},r.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},r.$utils=function(){return $},r.isValid=function(){return this.$d.toString()!==j},r.isSame=function(e,i){var n=_(e);return this.startOf(i)<=n&&n<=this.endOf(i)},r.isAfter=function(e,i){return _(e)<this.startOf(i)},r.isBefore=function(e,i){return this.endOf(i)<_(e)},r.$g=function(e,i,n){return $.u(e)?this[i]:this.set(n,e)},r.unix=function(){return Math.floor(this.valueOf()/1e3)},r.valueOf=function(){return this.$d.getTime()},r.startOf=function(e,i){var n=this,u=!!$.u(i)||i,c=$.p(e),M=function(R,C){var A=$.w(n.$u?Date.UTC(n.$y,C,R):new Date(n.$y,C,R),n);return u?A:A.endOf(p)},x=function(R,C){return $.w(n.toDate()[R].apply(n.toDate("s"),(u?[0,0,0,0]:[23,59,59,999]).slice(C)),n)},E=this.$W,W=this.$M,k=this.$D,F="set"+(this.$u?"UTC":"");switch(c){case D:return u?M(1,0):M(31,11);case o:return u?M(1,W):M(0,W+1);case S:var V=this.$locale().weekStart||0,U=(E<V?E+7:E)-V;return M(u?k-U:k+(6-U),W);case p:case O:return x(F+"Hours",0);case h:return x(F+"Minutes",1);case v:return x(F+"Seconds",2);case f:return x(F+"Milliseconds",3);default:return this.clone()}},r.endOf=function(e){return this.startOf(e,!1)},r.$set=function(e,i){var n,u=$.p(e),c="set"+(this.$u?"UTC":""),M=(n={},n[p]=c+"Date",n[O]=c+"Date",n[o]=c+"Month",n[D]=c+"FullYear",n[h]=c+"Hours",n[v]=c+"Minutes",n[f]=c+"Seconds",n[y]=c+"Milliseconds",n)[u],x=u===p?this.$D+(i-this.$W):i;if(u===o||u===D){var E=this.clone().set(O,1);E.$d[M](x),E.init(),this.$d=E.set(O,Math.min(this.$D,E.daysInMonth())).$d}else M&&this.$d[M](x);return this.init(),this},r.set=function(e,i){return this.clone().$set(e,i)},r.get=function(e){return this[$.p(e)]()},r.add=function(e,i){var n,u=this;e=Number(e);var c=$.p(i),M=function(W){var k=_(u);return $.w(k.date(k.date()+Math.round(W*e)),u)};if(c===o)return this.set(o,this.$M+e);if(c===D)return this.set(D,this.$y+e);if(c===p)return M(1);if(c===S)return M(7);var x=(n={},n[v]=m,n[h]=w,n[f]=d,n)[c]||1,E=this.$d.getTime()+e*x;return $.w(E,this)},r.subtract=function(e,i){return this.add(-1*e,i)},r.format=function(e){var i=this,n=this.$locale();if(!this.isValid())return n.invalidDate||j;var u=e||"YYYY-MM-DDTHH:mm:ssZ",c=$.z(this),M=this.$H,x=this.$m,E=this.$M,W=n.weekdays,k=n.months,F=n.meridiem,V=function(C,A,B,Q){return C&&(C[A]||C(i,u))||B[A].slice(0,Q)},U=function(C){return $.s(M%12||12,C,"0")},R=F||function(C,A,B){var Q=C<12?"AM":"PM";return B?Q.toLowerCase():Q};return u.replace(G,function(C,A){return A||function(B){switch(B){case"YY":return String(i.$y).slice(-2);case"YYYY":return $.s(i.$y,4,"0");case"M":return E+1;case"MM":return $.s(E+1,2,"0");case"MMM":return V(n.monthsShort,E,k,3);case"MMMM":return V(k,E);case"D":return i.$D;case"DD":return $.s(i.$D,2,"0");case"d":return String(i.$W);case"dd":return V(n.weekdaysMin,i.$W,W,2);case"ddd":return V(n.weekdaysShort,i.$W,W,3);case"dddd":return W[i.$W];case"H":return String(M);case"HH":return $.s(M,2,"0");case"h":return U(1);case"hh":return U(2);case"a":return R(M,x,!0);case"A":return R(M,x,!1);case"m":return String(x);case"mm":return $.s(x,2,"0");case"s":return String(i.$s);case"ss":return $.s(i.$s,2,"0");case"SSS":return $.s(i.$ms,3,"0");case"Z":return c}return null}(C)||c.replace(":","")})},r.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},r.diff=function(e,i,n){var u,c=this,M=$.p(i),x=_(e),E=(x.utcOffset()-this.utcOffset())*m,W=this-x,k=function(){return $.m(c,x)};switch(M){case D:u=k()/12;break;case o:u=k();break;case g:u=k()/3;break;case S:u=(W-E)/6048e5;break;case p:u=(W-E)/864e5;break;case h:u=W/w;break;case v:u=W/m;break;case f:u=W/d;break;default:u=W}return n?u:$.a(u)},r.daysInMonth=function(){return this.endOf(o).$D},r.$locale=function(){return T[this.$L]},r.locale=function(e,i){if(!e)return this.$L;var n=this.clone(),u=Y(e,i,!0);return u&&(n.$L=u),n},r.clone=function(){return $.w(this.$d,this)},r.toDate=function(){return new Date(this.valueOf())},r.toJSON=function(){return this.isValid()?this.toISOString():null},r.toISOString=function(){return this.$d.toISOString()},r.toString=function(){return this.$d.toUTCString()},a}(),ne=J.prototype;return _.prototype=ne,[["$ms",y],["$s",f],["$m",v],["$H",h],["$W",p],["$M",o],["$y",D],["$D",O]].forEach(function(a){ne[a[1]]=function(r){return this.$g(r,a[0],a[1])}}),_.extend=function(a,r){return a.$i||(a(r,J,_),a.$i=!0),_},_.locale=Y,_.isDayjs=P,_.unix=function(a){return _(1e3*a)},_.en=T[H],_.Ls=T,_.p={},_})}(Z)),Z.exports}var fe=de();const he=ce(fe);function me(t){const s=new Blob([t],{type:"application/vnd.ms-excel"});return window.URL.createObjectURL(s)}function ve(){return document.createElement("a")}function oe(t,s){const d=he().format("yyyy-MM-dd hh:mm:ss");function m(){const w=ve(),y=me(t);w.href=y,s?w.download=s||`${s}-${d}.xlsx`:w.download=`${d}.xlsx`,document.body.appendChild(w),w.click(),document.body.removeChild(w),window.URL.revokeObjectURL(y)}m()}function pe(t,s){throw new Error(`[naive/${t}]: ${s}`)}const ge="n-message-api";function we(){const t=l.inject(ge,null);return t===null&&pe("use-message","No outer <n-message-provider /> founded. See prerequisite in https://www.naiveui.com/en-US/os-theme/components/message for more details. If you want to use `useMessage` outside setup, please check https://www.naiveui.com/zh-CN/os-theme/components/message#Q-&-A."),t}function $e(t,s={}){const{exportRequestFn:d,filterOption:m=l.ref(),callback:w,immediate:y=!0,code:f=200}=s,v=l.ref(!1),h=l.ref({page:1,pageSize:10,itemCount:0,showSizePicker:!0,pageSizes:[10,20,30,40],showQuickJumper:!0,prefix:b=>`共 ${b.itemCount} 条`}),p=l.ref([]),S=l.computed(()=>m.value),o=async(b=h.value.page,L)=>{v.value=!0;try{const{status:z,data:H}=await t({pageNum:b,pageSize:h.value.pageSize,...S.value,...L}),{list:T,pageNum:K,total:P,pageSize:Y}=w&&w(H)||H;if(z===f&&Array.isArray(T))p.value=T,h.value={...h.value,page:K,itemCount:P,pageSize:Y};else throw p.value=[],h.value={...h.value,pageSize:10,itemCount:0,page:1},new Error("list的数据类型错误")}catch(z){throw console.error("Error in loadData:",z),z}finally{v.value=!1}},g=we(),D=async()=>{if(!d||typeof d!="function")throw new Error("当前没有提供exportRequest函数");try{const{data:b,fileName:L}=await d(m.value);oe(b,L),g==null||g.success("成功导出")}catch(b){throw console.error("Error in handleExcelData:",b),b}},O=(b,L)=>{L!==void 0&&(h.value.pageSize=L),o(b)},j=b=>{O(b)},I=b=>{O(1,b)},G=b=>{if(b.sorter){const L=[...p.value].sort((z,H)=>b.order==="ascend"?z[b.columnKey]>H[b.columnKey]?1:-1:b.order==="descend"?z[b.columnKey]<H[b.columnKey]?1:-1:0);p.value=L}};return l.onMounted(()=>y&&o(h.value.page)),{dataSource:p,loading:v,pagination:h,handleExcelData:D,handlePageChange:j,handlePageSizeChange:I,handleSortChange:G,loadData:o}}function te(t){return l.getCurrentScope()?(l.onScopeDispose(t),!0):!1}const X=new WeakMap,ye=(...t)=>{var s;const d=t[0],m=(s=l.getCurrentInstance())==null?void 0:s.proxy;if(m==null&&!l.hasInjectionContext())throw new Error("injectLocal must be called in setup");return m&&X.has(m)&&d in X.get(m)?X.get(m)[d]:l.inject(...t)},Me=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Se=Object.prototype.toString,be=t=>Se.call(t)==="[object Object]",De=()=>{};function se(t){return t.endsWith("rem")?Number.parseFloat(t)*16:Number.parseFloat(t)}function Oe(t){return l.getCurrentInstance()}function ee(t){return Array.isArray(t)?t:[t]}function ae(t,s=!0,d){Oe()?l.onMounted(t,d):s?t():l.nextTick(t)}const q=Me?window:void 0;function N(t){var s;const d=l.toValue(t);return(s=d==null?void 0:d.$el)!=null?s:d}function ie(...t){let s,d,m,w;if(typeof t[0]=="string"||Array.isArray(t[0])?([d,m,w]=t,s=q):[s,d,m,w]=t,!s)return De;d=ee(d),m=ee(m);const y=[],f=()=>{y.forEach(S=>S()),y.length=0},v=(S,o,g,D)=>(S.addEventListener(o,g,D),()=>S.removeEventListener(o,g,D)),h=l.watch(()=>[N(s),l.toValue(w)],([S,o])=>{if(f(),!S)return;const g=be(o)?{...o}:o;y.push(...d.flatMap(D=>m.map(O=>v(S,D,O,g))))},{immediate:!0,flush:"post"}),p=()=>{h(),f()};return te(p),p}function xe(){const t=l.ref(!1),s=l.getCurrentInstance();return s&&l.onMounted(()=>{t.value=!0},s),t}function ue(t){const s=xe();return l.computed(()=>(s.value,!!t()))}const _e=Symbol("vueuse-ssr-width");function Ee(){const t=l.hasInjectionContext()?ye(_e,null):null;return typeof t=="number"?t:void 0}function We(t,s={}){const{window:d=q,ssrWidth:m=Ee()}=s,w=ue(()=>d&&"matchMedia"in d&&typeof d.matchMedia=="function"),y=l.ref(typeof m=="number");let f;const v=l.ref(!1),h=o=>{v.value=o.matches},p=()=>{f&&("removeEventListener"in f?f.removeEventListener("change",h):f.removeListener(h))},S=l.watchEffect(()=>{if(y.value){y.value=!w.value;const o=l.toValue(t).split(",");v.value=o.some(g=>{const D=g.includes("not all"),O=g.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),j=g.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/);let I=!!(O||j);return O&&I&&(I=m>=se(O[1])),j&&I&&(I=m<=se(j[1])),D?!I:I});return}w.value&&(p(),f=d.matchMedia(l.toValue(t)),"addEventListener"in f?f.addEventListener("change",h):f.addListener(h),v.value=f.matches)});return te(()=>{S(),p(),f=void 0}),l.computed(()=>v.value)}function Ce(t,s,d={}){const{window:m=q,...w}=d;let y;const f=ue(()=>m&&"ResizeObserver"in m),v=()=>{y&&(y.disconnect(),y=void 0)},h=l.computed(()=>{const o=l.toValue(t);return Array.isArray(o)?o.map(g=>N(g)):[N(o)]}),p=l.watch(h,o=>{if(v(),f.value&&m){y=new ResizeObserver(s);for(const g of o)g&&y.observe(g,w)}},{immediate:!0,flush:"post"}),S=()=>{v(),p()};return te(S),{isSupported:f,stop:S}}function je(t,s={width:0,height:0},d={}){const{window:m=q,box:w="content-box"}=d,y=l.computed(()=>{var o,g;return(g=(o=N(t))==null?void 0:o.namespaceURI)==null?void 0:g.includes("svg")}),f=l.ref(s.width),v=l.ref(s.height),{stop:h}=Ce(t,([o])=>{const g=w==="border-box"?o.borderBoxSize:w==="content-box"?o.contentBoxSize:o.devicePixelContentBoxSize;if(m&&y.value){const D=N(t);if(D){const O=D.getBoundingClientRect();f.value=O.width,v.value=O.height}}else if(g){const D=ee(g);f.value=D.reduce((O,{inlineSize:j})=>O+j,0),v.value=D.reduce((O,{blockSize:j})=>O+j,0)}else f.value=o.contentRect.width,v.value=o.contentRect.height},d);ae(()=>{const o=N(t);o&&(f.value="offsetWidth"in o?o.offsetWidth:s.width,v.value="offsetHeight"in o?o.offsetHeight:s.height)});const p=l.watch(()=>N(t),o=>{f.value=o?s.width:0,v.value=o?s.height:0});function S(){h(),p()}return{width:f,height:v,stop:S}}function Le(t={}){const{window:s=q,initialWidth:d=Number.POSITIVE_INFINITY,initialHeight:m=Number.POSITIVE_INFINITY,listenOrientation:w=!0,includeScrollbar:y=!0,type:f="inner"}=t,v=l.ref(d),h=l.ref(m),p=()=>{if(s)if(f==="outer")v.value=s.outerWidth,h.value=s.outerHeight;else if(f==="visual"&&s.visualViewport){const{width:S,height:o,scale:g}=s.visualViewport;v.value=Math.round(S*g),h.value=Math.round(o*g)}else y?(v.value=s.innerWidth,h.value=s.innerHeight):(v.value=s.document.documentElement.clientWidth,h.value=s.document.documentElement.clientHeight)};if(p(),ae(p),ie("resize",p,{passive:!0}),s&&f==="visual"&&s.visualViewport&&ie(s.visualViewport,"resize",p,{passive:!0}),w){const S=We("(orientation: portrait)");l.watch(S,()=>p())}return{width:v,height:h}}function ke(t,s){if(!t)throw new Error("tableRef are required");const d=l.computed(()=>{var h;return(h=t.value)==null?void 0:h.searchRef}),{height:m}=Le(),{height:w}=je(d),{height:y=0,minHeight:f=600}=s||{};return{height:l.computed(()=>{const h=m.value-w.value-y;return h>f?h:f})}}exports.useExportFile=oe;exports.useList=$e;exports.useTableHeight=ke;
@@ -0,0 +1,3 @@
1
+ export * from './useExportRemoteFile';
2
+ export * from './useList';
3
+ export * from './useTableHeight';
package/dist/index.js ADDED
@@ -0,0 +1,586 @@
1
+ import { inject as de, ref as H, computed as V, onMounted as se, nextTick as me, getCurrentScope as pe, onScopeDispose as ge, getCurrentInstance as ie, hasInjectionContext as he, watch as ee, toValue as q, watchEffect as we } from "vue";
2
+ function $e(t) {
3
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
4
+ }
5
+ var X = { exports: {} }, ye = X.exports, ue;
6
+ function Me() {
7
+ return ue || (ue = 1, function(t, s) {
8
+ (function(l, f) {
9
+ t.exports = f();
10
+ })(ye, function() {
11
+ var l = 1e3, f = 6e4, g = 36e5, $ = "millisecond", d = "second", v = "minute", h = "hour", m = "day", M = "week", o = "month", p = "quarter", b = "year", D = "date", C = "Invalid Date", I = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, te = /\[([^\]]+)]|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, S = { 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("_"), ordinal: function(a) {
12
+ var r = ["th", "st", "nd", "rd"], e = a % 100;
13
+ return "[" + a + (r[(e - 20) % 10] || r[e] || r[0]) + "]";
14
+ } }, L = function(a, r, e) {
15
+ var i = String(a);
16
+ return !i || i.length >= r ? a : "" + Array(r + 1 - i.length).join(e) + a;
17
+ }, T = { s: L, z: function(a) {
18
+ var r = -a.utcOffset(), e = Math.abs(r), i = Math.floor(e / 60), n = e % 60;
19
+ return (r <= 0 ? "+" : "-") + L(i, 2, "0") + ":" + L(n, 2, "0");
20
+ }, m: function a(r, e) {
21
+ if (r.date() < e.date()) return -a(e, r);
22
+ var i = 12 * (e.year() - r.year()) + (e.month() - r.month()), n = r.clone().add(i, o), u = e - n < 0, c = r.clone().add(i + (u ? -1 : 1), o);
23
+ return +(-(i + (e - n) / (u ? n - c : c - n)) || 0);
24
+ }, a: function(a) {
25
+ return a < 0 ? Math.ceil(a) || 0 : Math.floor(a);
26
+ }, p: function(a) {
27
+ return { M: o, y: b, w: M, d: m, D, h, m: v, s: d, ms: $, Q: p }[a] || String(a || "").toLowerCase().replace(/s$/, "");
28
+ }, u: function(a) {
29
+ return a === void 0;
30
+ } }, j = "en", z = {};
31
+ z[j] = S;
32
+ var Q = "$isDayjsObject", U = function(a) {
33
+ return a instanceof Z || !(!a || !a[Q]);
34
+ }, F = function a(r, e, i) {
35
+ var n;
36
+ if (!r) return j;
37
+ if (typeof r == "string") {
38
+ var u = r.toLowerCase();
39
+ z[u] && (n = u), e && (z[u] = e, n = u);
40
+ var c = r.split("-");
41
+ if (!n && c.length > 1) return a(c[0]);
42
+ } else {
43
+ var y = r.name;
44
+ z[y] = r, n = y;
45
+ }
46
+ return !i && n && (j = n), n || !i && j;
47
+ }, x = function(a, r) {
48
+ if (U(a)) return a.clone();
49
+ var e = typeof r == "object" ? r : {};
50
+ return e.date = a, e.args = arguments, new Z(e);
51
+ }, w = T;
52
+ w.l = F, w.i = U, w.w = function(a, r) {
53
+ return x(a, { locale: r.$L, utc: r.$u, x: r.$x, $offset: r.$offset });
54
+ };
55
+ var Z = function() {
56
+ function a(e) {
57
+ this.$L = F(e.locale, null, !0), this.parse(e), this.$x = this.$x || e.x || {}, this[Q] = !0;
58
+ }
59
+ var r = a.prototype;
60
+ return r.parse = function(e) {
61
+ this.$d = function(i) {
62
+ var n = i.date, u = i.utc;
63
+ if (n === null) return /* @__PURE__ */ new Date(NaN);
64
+ if (w.u(n)) return /* @__PURE__ */ new Date();
65
+ if (n instanceof Date) return new Date(n);
66
+ if (typeof n == "string" && !/Z$/i.test(n)) {
67
+ var c = n.match(I);
68
+ if (c) {
69
+ var y = c[2] - 1 || 0, O = (c[7] || "0").substring(0, 3);
70
+ return u ? new Date(Date.UTC(c[1], y, c[3] || 1, c[4] || 0, c[5] || 0, c[6] || 0, O)) : new Date(c[1], y, c[3] || 1, c[4] || 0, c[5] || 0, c[6] || 0, O);
71
+ }
72
+ }
73
+ return new Date(n);
74
+ }(e), this.init();
75
+ }, r.init = function() {
76
+ var e = this.$d;
77
+ this.$y = e.getFullYear(), this.$M = e.getMonth(), this.$D = e.getDate(), this.$W = e.getDay(), this.$H = e.getHours(), this.$m = e.getMinutes(), this.$s = e.getSeconds(), this.$ms = e.getMilliseconds();
78
+ }, r.$utils = function() {
79
+ return w;
80
+ }, r.isValid = function() {
81
+ return this.$d.toString() !== C;
82
+ }, r.isSame = function(e, i) {
83
+ var n = x(e);
84
+ return this.startOf(i) <= n && n <= this.endOf(i);
85
+ }, r.isAfter = function(e, i) {
86
+ return x(e) < this.startOf(i);
87
+ }, r.isBefore = function(e, i) {
88
+ return this.endOf(i) < x(e);
89
+ }, r.$g = function(e, i, n) {
90
+ return w.u(e) ? this[i] : this.set(n, e);
91
+ }, r.unix = function() {
92
+ return Math.floor(this.valueOf() / 1e3);
93
+ }, r.valueOf = function() {
94
+ return this.$d.getTime();
95
+ }, r.startOf = function(e, i) {
96
+ var n = this, u = !!w.u(i) || i, c = w.p(e), y = function(N, W) {
97
+ var A = w.w(n.$u ? Date.UTC(n.$y, W, N) : new Date(n.$y, W, N), n);
98
+ return u ? A : A.endOf(m);
99
+ }, O = function(N, W) {
100
+ return w.w(n.toDate()[N].apply(n.toDate("s"), (u ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(W)), n);
101
+ }, _ = this.$W, E = this.$M, k = this.$D, P = "set" + (this.$u ? "UTC" : "");
102
+ switch (c) {
103
+ case b:
104
+ return u ? y(1, 0) : y(31, 11);
105
+ case o:
106
+ return u ? y(1, E) : y(0, E + 1);
107
+ case M:
108
+ var R = this.$locale().weekStart || 0, B = (_ < R ? _ + 7 : _) - R;
109
+ return y(u ? k - B : k + (6 - B), E);
110
+ case m:
111
+ case D:
112
+ return O(P + "Hours", 0);
113
+ case h:
114
+ return O(P + "Minutes", 1);
115
+ case v:
116
+ return O(P + "Seconds", 2);
117
+ case d:
118
+ return O(P + "Milliseconds", 3);
119
+ default:
120
+ return this.clone();
121
+ }
122
+ }, r.endOf = function(e) {
123
+ return this.startOf(e, !1);
124
+ }, r.$set = function(e, i) {
125
+ var n, u = w.p(e), c = "set" + (this.$u ? "UTC" : ""), y = (n = {}, n[m] = c + "Date", n[D] = c + "Date", n[o] = c + "Month", n[b] = c + "FullYear", n[h] = c + "Hours", n[v] = c + "Minutes", n[d] = c + "Seconds", n[$] = c + "Milliseconds", n)[u], O = u === m ? this.$D + (i - this.$W) : i;
126
+ if (u === o || u === b) {
127
+ var _ = this.clone().set(D, 1);
128
+ _.$d[y](O), _.init(), this.$d = _.set(D, Math.min(this.$D, _.daysInMonth())).$d;
129
+ } else y && this.$d[y](O);
130
+ return this.init(), this;
131
+ }, r.set = function(e, i) {
132
+ return this.clone().$set(e, i);
133
+ }, r.get = function(e) {
134
+ return this[w.p(e)]();
135
+ }, r.add = function(e, i) {
136
+ var n, u = this;
137
+ e = Number(e);
138
+ var c = w.p(i), y = function(E) {
139
+ var k = x(u);
140
+ return w.w(k.date(k.date() + Math.round(E * e)), u);
141
+ };
142
+ if (c === o) return this.set(o, this.$M + e);
143
+ if (c === b) return this.set(b, this.$y + e);
144
+ if (c === m) return y(1);
145
+ if (c === M) return y(7);
146
+ var O = (n = {}, n[v] = f, n[h] = g, n[d] = l, n)[c] || 1, _ = this.$d.getTime() + e * O;
147
+ return w.w(_, this);
148
+ }, r.subtract = function(e, i) {
149
+ return this.add(-1 * e, i);
150
+ }, r.format = function(e) {
151
+ var i = this, n = this.$locale();
152
+ if (!this.isValid()) return n.invalidDate || C;
153
+ var u = e || "YYYY-MM-DDTHH:mm:ssZ", c = w.z(this), y = this.$H, O = this.$m, _ = this.$M, E = n.weekdays, k = n.months, P = n.meridiem, R = function(W, A, K, G) {
154
+ return W && (W[A] || W(i, u)) || K[A].slice(0, G);
155
+ }, B = function(W) {
156
+ return w.s(y % 12 || 12, W, "0");
157
+ }, N = P || function(W, A, K) {
158
+ var G = W < 12 ? "AM" : "PM";
159
+ return K ? G.toLowerCase() : G;
160
+ };
161
+ return u.replace(te, function(W, A) {
162
+ return A || function(K) {
163
+ switch (K) {
164
+ case "YY":
165
+ return String(i.$y).slice(-2);
166
+ case "YYYY":
167
+ return w.s(i.$y, 4, "0");
168
+ case "M":
169
+ return _ + 1;
170
+ case "MM":
171
+ return w.s(_ + 1, 2, "0");
172
+ case "MMM":
173
+ return R(n.monthsShort, _, k, 3);
174
+ case "MMMM":
175
+ return R(k, _);
176
+ case "D":
177
+ return i.$D;
178
+ case "DD":
179
+ return w.s(i.$D, 2, "0");
180
+ case "d":
181
+ return String(i.$W);
182
+ case "dd":
183
+ return R(n.weekdaysMin, i.$W, E, 2);
184
+ case "ddd":
185
+ return R(n.weekdaysShort, i.$W, E, 3);
186
+ case "dddd":
187
+ return E[i.$W];
188
+ case "H":
189
+ return String(y);
190
+ case "HH":
191
+ return w.s(y, 2, "0");
192
+ case "h":
193
+ return B(1);
194
+ case "hh":
195
+ return B(2);
196
+ case "a":
197
+ return N(y, O, !0);
198
+ case "A":
199
+ return N(y, O, !1);
200
+ case "m":
201
+ return String(O);
202
+ case "mm":
203
+ return w.s(O, 2, "0");
204
+ case "s":
205
+ return String(i.$s);
206
+ case "ss":
207
+ return w.s(i.$s, 2, "0");
208
+ case "SSS":
209
+ return w.s(i.$ms, 3, "0");
210
+ case "Z":
211
+ return c;
212
+ }
213
+ return null;
214
+ }(W) || c.replace(":", "");
215
+ });
216
+ }, r.utcOffset = function() {
217
+ return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
218
+ }, r.diff = function(e, i, n) {
219
+ var u, c = this, y = w.p(i), O = x(e), _ = (O.utcOffset() - this.utcOffset()) * f, E = this - O, k = function() {
220
+ return w.m(c, O);
221
+ };
222
+ switch (y) {
223
+ case b:
224
+ u = k() / 12;
225
+ break;
226
+ case o:
227
+ u = k();
228
+ break;
229
+ case p:
230
+ u = k() / 3;
231
+ break;
232
+ case M:
233
+ u = (E - _) / 6048e5;
234
+ break;
235
+ case m:
236
+ u = (E - _) / 864e5;
237
+ break;
238
+ case h:
239
+ u = E / g;
240
+ break;
241
+ case v:
242
+ u = E / f;
243
+ break;
244
+ case d:
245
+ u = E / l;
246
+ break;
247
+ default:
248
+ u = E;
249
+ }
250
+ return n ? u : w.a(u);
251
+ }, r.daysInMonth = function() {
252
+ return this.endOf(o).$D;
253
+ }, r.$locale = function() {
254
+ return z[this.$L];
255
+ }, r.locale = function(e, i) {
256
+ if (!e) return this.$L;
257
+ var n = this.clone(), u = F(e, i, !0);
258
+ return u && (n.$L = u), n;
259
+ }, r.clone = function() {
260
+ return w.w(this.$d, this);
261
+ }, r.toDate = function() {
262
+ return new Date(this.valueOf());
263
+ }, r.toJSON = function() {
264
+ return this.isValid() ? this.toISOString() : null;
265
+ }, r.toISOString = function() {
266
+ return this.$d.toISOString();
267
+ }, r.toString = function() {
268
+ return this.$d.toUTCString();
269
+ }, a;
270
+ }(), ae = Z.prototype;
271
+ return x.prototype = ae, [["$ms", $], ["$s", d], ["$m", v], ["$H", h], ["$W", m], ["$M", o], ["$y", b], ["$D", D]].forEach(function(a) {
272
+ ae[a[1]] = function(r) {
273
+ return this.$g(r, a[0], a[1]);
274
+ };
275
+ }), x.extend = function(a, r) {
276
+ return a.$i || (a(r, Z, x), a.$i = !0), x;
277
+ }, x.locale = F, x.isDayjs = U, x.unix = function(a) {
278
+ return x(1e3 * a);
279
+ }, x.en = z[j], x.Ls = z, x.p = {}, x;
280
+ });
281
+ }(X)), X.exports;
282
+ }
283
+ var Se = Me();
284
+ const be = /* @__PURE__ */ $e(Se);
285
+ function De(t) {
286
+ const s = new Blob([t], {
287
+ type: "application/vnd.ms-excel"
288
+ // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
289
+ });
290
+ return window.URL.createObjectURL(s);
291
+ }
292
+ function Oe() {
293
+ return document.createElement("a");
294
+ }
295
+ function xe(t, s) {
296
+ const l = be().format("yyyy-MM-dd hh:mm:ss");
297
+ function f() {
298
+ const g = Oe(), $ = De(t);
299
+ g.href = $, s ? g.download = s || `${s}-${l}.xlsx` : g.download = `${l}.xlsx`, document.body.appendChild(g), g.click(), document.body.removeChild(g), window.URL.revokeObjectURL($);
300
+ }
301
+ f();
302
+ }
303
+ function _e(t, s) {
304
+ throw new Error(`[naive/${t}]: ${s}`);
305
+ }
306
+ const Ee = "n-message-api";
307
+ function We() {
308
+ const t = de(Ee, null);
309
+ return t === null && _e("use-message", "No outer <n-message-provider /> founded. See prerequisite in https://www.naiveui.com/en-US/os-theme/components/message for more details. If you want to use `useMessage` outside setup, please check https://www.naiveui.com/zh-CN/os-theme/components/message#Q-&-A."), t;
310
+ }
311
+ function Pe(t, s = {}) {
312
+ const {
313
+ exportRequestFn: l,
314
+ filterOption: f = H(),
315
+ callback: g,
316
+ immediate: $ = !0,
317
+ code: d = 200
318
+ } = s, v = H(!1), h = H({
319
+ page: 1,
320
+ pageSize: 10,
321
+ itemCount: 0,
322
+ showSizePicker: !0,
323
+ pageSizes: [10, 20, 30, 40],
324
+ showQuickJumper: !0,
325
+ prefix: (S) => `共 ${S.itemCount} 条`
326
+ }), m = H([]), M = V(() => f.value), o = async (S = h.value.page, L) => {
327
+ v.value = !0;
328
+ try {
329
+ const { status: T, data: j } = await t({
330
+ pageNum: S,
331
+ pageSize: h.value.pageSize,
332
+ ...M.value,
333
+ ...L
334
+ }), { list: z, pageNum: Q, total: U, pageSize: F } = g && g(j) || j;
335
+ if (T === d && Array.isArray(z))
336
+ m.value = z, h.value = {
337
+ ...h.value,
338
+ page: Q,
339
+ itemCount: U,
340
+ pageSize: F
341
+ };
342
+ else
343
+ throw m.value = [], h.value = {
344
+ ...h.value,
345
+ pageSize: 10,
346
+ itemCount: 0,
347
+ page: 1
348
+ }, new Error("list的数据类型错误");
349
+ } catch (T) {
350
+ throw console.error("Error in loadData:", T), T;
351
+ } finally {
352
+ v.value = !1;
353
+ }
354
+ }, p = We(), b = async () => {
355
+ if (!l || typeof l != "function")
356
+ throw new Error("当前没有提供exportRequest函数");
357
+ try {
358
+ const { data: S, fileName: L } = await l(f.value);
359
+ xe(S, L), p == null || p.success("成功导出");
360
+ } catch (S) {
361
+ throw console.error("Error in handleExcelData:", S), S;
362
+ }
363
+ }, D = (S, L) => {
364
+ L !== void 0 && (h.value.pageSize = L), o(S);
365
+ }, C = (S) => {
366
+ D(S);
367
+ }, I = (S) => {
368
+ D(1, S);
369
+ }, te = (S) => {
370
+ if (S.sorter) {
371
+ const L = [...m.value].sort((T, j) => S.order === "ascend" ? T[S.columnKey] > j[S.columnKey] ? 1 : -1 : S.order === "descend" ? T[S.columnKey] < j[S.columnKey] ? 1 : -1 : 0);
372
+ m.value = L;
373
+ }
374
+ };
375
+ return se(() => $ && o(h.value.page)), {
376
+ dataSource: m,
377
+ loading: v,
378
+ pagination: h,
379
+ handleExcelData: b,
380
+ handlePageChange: C,
381
+ handlePageSizeChange: I,
382
+ handleSortChange: te,
383
+ loadData: o
384
+ };
385
+ }
386
+ function oe(t) {
387
+ return pe() ? (ge(t), !0) : !1;
388
+ }
389
+ const ne = /* @__PURE__ */ new WeakMap(), Ce = (...t) => {
390
+ var s;
391
+ const l = t[0], f = (s = ie()) == null ? void 0 : s.proxy;
392
+ if (f == null && !he())
393
+ throw new Error("injectLocal must be called in setup");
394
+ return f && ne.has(f) && l in ne.get(f) ? ne.get(f)[l] : de(...t);
395
+ }, Le = typeof window < "u" && typeof document < "u";
396
+ typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
397
+ const ke = Object.prototype.toString, je = (t) => ke.call(t) === "[object Object]", He = () => {
398
+ };
399
+ function ce(t) {
400
+ return t.endsWith("rem") ? Number.parseFloat(t) * 16 : Number.parseFloat(t);
401
+ }
402
+ function Ie(t) {
403
+ return ie();
404
+ }
405
+ function re(t) {
406
+ return Array.isArray(t) ? t : [t];
407
+ }
408
+ function fe(t, s = !0, l) {
409
+ Ie() ? se(t, l) : s ? t() : me(t);
410
+ }
411
+ const J = Le ? window : void 0;
412
+ function Y(t) {
413
+ var s;
414
+ const l = q(t);
415
+ return (s = l == null ? void 0 : l.$el) != null ? s : l;
416
+ }
417
+ function le(...t) {
418
+ let s, l, f, g;
419
+ if (typeof t[0] == "string" || Array.isArray(t[0]) ? ([l, f, g] = t, s = J) : [s, l, f, g] = t, !s)
420
+ return He;
421
+ l = re(l), f = re(f);
422
+ const $ = [], d = () => {
423
+ $.forEach((M) => M()), $.length = 0;
424
+ }, v = (M, o, p, b) => (M.addEventListener(o, p, b), () => M.removeEventListener(o, p, b)), h = ee(
425
+ () => [Y(s), q(g)],
426
+ ([M, o]) => {
427
+ if (d(), !M)
428
+ return;
429
+ const p = je(o) ? { ...o } : o;
430
+ $.push(
431
+ ...l.flatMap((b) => f.map((D) => v(M, b, D, p)))
432
+ );
433
+ },
434
+ { immediate: !0, flush: "post" }
435
+ ), m = () => {
436
+ h(), d();
437
+ };
438
+ return oe(m), m;
439
+ }
440
+ function ze() {
441
+ const t = H(!1), s = ie();
442
+ return s && se(() => {
443
+ t.value = !0;
444
+ }, s), t;
445
+ }
446
+ function ve(t) {
447
+ const s = ze();
448
+ return V(() => (s.value, !!t()));
449
+ }
450
+ const Te = Symbol("vueuse-ssr-width");
451
+ function Ae() {
452
+ const t = he() ? Ce(Te, null) : null;
453
+ return typeof t == "number" ? t : void 0;
454
+ }
455
+ function Re(t, s = {}) {
456
+ const { window: l = J, ssrWidth: f = Ae() } = s, g = ve(() => l && "matchMedia" in l && typeof l.matchMedia == "function"), $ = H(typeof f == "number");
457
+ let d;
458
+ const v = H(!1), h = (o) => {
459
+ v.value = o.matches;
460
+ }, m = () => {
461
+ d && ("removeEventListener" in d ? d.removeEventListener("change", h) : d.removeListener(h));
462
+ }, M = we(() => {
463
+ if ($.value) {
464
+ $.value = !g.value;
465
+ const o = q(t).split(",");
466
+ v.value = o.some((p) => {
467
+ const b = p.includes("not all"), D = p.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/), C = p.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/);
468
+ let I = !!(D || C);
469
+ return D && I && (I = f >= ce(D[1])), C && I && (I = f <= ce(C[1])), b ? !I : I;
470
+ });
471
+ return;
472
+ }
473
+ g.value && (m(), d = l.matchMedia(q(t)), "addEventListener" in d ? d.addEventListener("change", h) : d.addListener(h), v.value = d.matches);
474
+ });
475
+ return oe(() => {
476
+ M(), m(), d = void 0;
477
+ }), V(() => v.value);
478
+ }
479
+ function Ne(t, s, l = {}) {
480
+ const { window: f = J, ...g } = l;
481
+ let $;
482
+ const d = ve(() => f && "ResizeObserver" in f), v = () => {
483
+ $ && ($.disconnect(), $ = void 0);
484
+ }, h = V(() => {
485
+ const o = q(t);
486
+ return Array.isArray(o) ? o.map((p) => Y(p)) : [Y(o)];
487
+ }), m = ee(
488
+ h,
489
+ (o) => {
490
+ if (v(), d.value && f) {
491
+ $ = new ResizeObserver(s);
492
+ for (const p of o)
493
+ p && $.observe(p, g);
494
+ }
495
+ },
496
+ { immediate: !0, flush: "post" }
497
+ ), M = () => {
498
+ v(), m();
499
+ };
500
+ return oe(M), {
501
+ isSupported: d,
502
+ stop: M
503
+ };
504
+ }
505
+ function Ye(t, s = { width: 0, height: 0 }, l = {}) {
506
+ const { window: f = J, box: g = "content-box" } = l, $ = V(() => {
507
+ var o, p;
508
+ return (p = (o = Y(t)) == null ? void 0 : o.namespaceURI) == null ? void 0 : p.includes("svg");
509
+ }), d = H(s.width), v = H(s.height), { stop: h } = Ne(
510
+ t,
511
+ ([o]) => {
512
+ const p = g === "border-box" ? o.borderBoxSize : g === "content-box" ? o.contentBoxSize : o.devicePixelContentBoxSize;
513
+ if (f && $.value) {
514
+ const b = Y(t);
515
+ if (b) {
516
+ const D = b.getBoundingClientRect();
517
+ d.value = D.width, v.value = D.height;
518
+ }
519
+ } else if (p) {
520
+ const b = re(p);
521
+ d.value = b.reduce((D, { inlineSize: C }) => D + C, 0), v.value = b.reduce((D, { blockSize: C }) => D + C, 0);
522
+ } else
523
+ d.value = o.contentRect.width, v.value = o.contentRect.height;
524
+ },
525
+ l
526
+ );
527
+ fe(() => {
528
+ const o = Y(t);
529
+ o && (d.value = "offsetWidth" in o ? o.offsetWidth : s.width, v.value = "offsetHeight" in o ? o.offsetHeight : s.height);
530
+ });
531
+ const m = ee(
532
+ () => Y(t),
533
+ (o) => {
534
+ d.value = o ? s.width : 0, v.value = o ? s.height : 0;
535
+ }
536
+ );
537
+ function M() {
538
+ h(), m();
539
+ }
540
+ return {
541
+ width: d,
542
+ height: v,
543
+ stop: M
544
+ };
545
+ }
546
+ function Ve(t = {}) {
547
+ const {
548
+ window: s = J,
549
+ initialWidth: l = Number.POSITIVE_INFINITY,
550
+ initialHeight: f = Number.POSITIVE_INFINITY,
551
+ listenOrientation: g = !0,
552
+ includeScrollbar: $ = !0,
553
+ type: d = "inner"
554
+ } = t, v = H(l), h = H(f), m = () => {
555
+ if (s)
556
+ if (d === "outer")
557
+ v.value = s.outerWidth, h.value = s.outerHeight;
558
+ else if (d === "visual" && s.visualViewport) {
559
+ const { width: M, height: o, scale: p } = s.visualViewport;
560
+ v.value = Math.round(M * p), h.value = Math.round(o * p);
561
+ } else $ ? (v.value = s.innerWidth, h.value = s.innerHeight) : (v.value = s.document.documentElement.clientWidth, h.value = s.document.documentElement.clientHeight);
562
+ };
563
+ if (m(), fe(m), le("resize", m, { passive: !0 }), s && d === "visual" && s.visualViewport && le(s.visualViewport, "resize", m, { passive: !0 }), g) {
564
+ const M = Re("(orientation: portrait)");
565
+ ee(M, () => m());
566
+ }
567
+ return { width: v, height: h };
568
+ }
569
+ function Ue(t, s) {
570
+ if (!t) throw new Error("tableRef are required");
571
+ const l = V(() => {
572
+ var h;
573
+ return (h = t.value) == null ? void 0 : h.searchRef;
574
+ }), { height: f } = Ve(), { height: g } = Ye(l), { height: $ = 0, minHeight: d = 600 } = s || {};
575
+ return {
576
+ height: V(() => {
577
+ const h = f.value - g.value - $;
578
+ return h > d ? h : d;
579
+ })
580
+ };
581
+ }
582
+ export {
583
+ xe as useExportFile,
584
+ Pe as useList,
585
+ Ue as useTableHeight
586
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 使用设备信息钩子
3
+ * 该钩子用于获取客户端设备的信息,如浏览器类型、操作系统等
4
+ * 它基于UAParser实例来解析用户代理字符串
5
+ *
6
+ * @returns {object} 返回解析后的设备信息对象
7
+ */
8
+ export declare function useDeviceInfo(): Promise<import('ua-parser-js').IResult>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 导出文件
3
+ *
4
+ * @param data - 要导出的数据
5
+ * @param fileName - 导出的文件名(可选)
6
+ */
7
+ export declare function useExportFile(data: BlobPart, fileName?: string): void;
@@ -0,0 +1,36 @@
1
+ import { OptionsType } from './types';
2
+ import { DataTableSortState } from 'naive-ui';
3
+ export declare function useList<T extends (...args: any) => Promise<any>>(listRequestFn: T, options?: OptionsType): {
4
+ dataSource: import('vue').Ref<any[], any[]>;
5
+ loading: import('vue').Ref<boolean, boolean>;
6
+ pagination: import('vue').Ref<{
7
+ page: number;
8
+ pageSize: number;
9
+ itemCount: number;
10
+ showSizePicker: boolean;
11
+ pageSizes: number[];
12
+ showQuickJumper: boolean;
13
+ prefix: (info: any) => string;
14
+ }, {
15
+ page: number;
16
+ pageSize: number;
17
+ itemCount: number;
18
+ showSizePicker: boolean;
19
+ pageSizes: number[];
20
+ showQuickJumper: boolean;
21
+ prefix: (info: any) => string;
22
+ } | {
23
+ page: number;
24
+ pageSize: number;
25
+ itemCount: number;
26
+ showSizePicker: boolean;
27
+ pageSizes: number[];
28
+ showQuickJumper: boolean;
29
+ prefix: (info: any) => string;
30
+ }>;
31
+ handleExcelData: () => Promise<void>;
32
+ handlePageChange: (page: number) => void;
33
+ handlePageSizeChange: (pageSize: number) => void;
34
+ handleSortChange: (options: DataTableSortState) => void;
35
+ loadData: (page?: number, filterParams?: any) => Promise<void>;
36
+ };
@@ -0,0 +1,18 @@
1
+ import { Ref } from 'vue';
2
+ export interface OptionsType<T = any> {
3
+ requestError?: () => void;
4
+ requestSuccess?: () => void;
5
+ callback?: (data: any) => CallbackResult;
6
+ filterOption?: Ref<T>;
7
+ exportRequestFn?: (...args: any) => Promise<any>;
8
+ /** 不立即执行请求获取数据 */
9
+ immediate?: boolean;
10
+ /** 请求响应码 */
11
+ code?: number;
12
+ }
13
+ export interface CallbackResult {
14
+ list: any[];
15
+ total: number;
16
+ pageSize: number;
17
+ pageNum: number;
18
+ }
@@ -0,0 +1,20 @@
1
+ interface Options {
2
+ height?: number;
3
+ minHeight?: number;
4
+ }
5
+ /**
6
+ * useTableHeight
7
+ *
8
+ * @description 计算表格高度
9
+ * @example const { height } = useTableHeight(tableRef, { height: 100, minHeight: 600 })
10
+ *
11
+ * @param tableRef - 表格元素引用
12
+ * @param options - 表格高度配置
13
+ * @param options.height - 表格之外的高度值
14
+ * @param options.minHeight - 表格的最小高度
15
+ * @returns { height } - 表格高度
16
+ */
17
+ export declare function useTableHeight(tableRef: any, options?: Options): {
18
+ height: import('vue').ComputedRef<number>;
19
+ };
20
+ export {};
package/package.json CHANGED
@@ -1,16 +1,46 @@
1
1
  {
2
2
  "name": "@banmao/hooks",
3
- "version": "0.0.2",
4
- "description": "",
5
- "main": "index.ts",
6
- "keywords": [],
7
- "author": "",
8
- "license": "MIT",
9
- "dependencies": {
10
- "ua-parser-js": "^2.0.0"
3
+ "version": "0.0.4",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/index.d.ts",
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
10
+ }
11
11
  },
12
+ "main": "./dist/index.cjs",
13
+ "module": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
12
18
  "devDependencies": {
13
- "@types/ua-parser-js": "^0.7.39"
19
+ "@vue/tsconfig": "^0.7.0",
20
+ "echarts": "^5.6.0",
21
+ "glob": "^11.0.0",
22
+ "naive-ui": "^2.41.0",
23
+ "typescript": "~5.6.2",
24
+ "vite": "^6.0.5",
25
+ "vite-plugin-compression": "^0.5.1",
26
+ "vue": "^3.5.13",
27
+ "vue-echarts": "^7.0.3",
28
+ "vue-tsc": "^2.2.0"
29
+ },
30
+ "peerDependencies": {
31
+ "echarts": "^5.6.0",
32
+ "naive-ui": "^2.41.0",
33
+ "vue": "^3.5.13",
34
+ "vue-echarts": "^7.0.3"
35
+ },
36
+ "dependencies": {
37
+ "dayjs": "^1.11.13",
38
+ "ua-parser-js": "^2.0.0"
14
39
  },
15
- "scripts": {}
40
+ "scripts": {
41
+ "dev": "vite",
42
+ "build": "vue-tsc -b && vite build",
43
+ "preview": "vite preview",
44
+ "test": "vitest run"
45
+ }
16
46
  }
package/CHANGELOG.md DELETED
@@ -1,13 +0,0 @@
1
- # @banmao/hooks
2
-
3
- ## 0.0.2
4
-
5
- ### Patch Changes
6
-
7
- - 修复 useList().pagination 属性默认数量初始值为 0
8
-
9
- ## 0.0.1
10
-
11
- ### Patch Changes
12
-
13
- - 创建 useList, useDeviceInfo 等 hooks
package/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './src/useExportRemoteFile'
2
- export * from './src/useList'
@@ -1,42 +0,0 @@
1
- import { UAParser } from 'ua-parser-js'
2
-
3
- /**
4
- * 单例模式下的 UAParser 实例管理
5
- */
6
- const parserInstance = (function() {
7
- let instance: UAParser | null = null
8
- const initializing: Promise<UAParser> = (async () => {
9
- try {
10
- instance = new UAParser()
11
- return instance
12
- } catch (error) {
13
- console.error('Failed to initialize UAParser:', error)
14
- throw error
15
- }
16
- })()
17
-
18
- return {
19
- /**
20
- * 获取 UAParser 实例
21
- * @returns 返回 {Promise<UAParser>} 解析用户代理字符串的实例
22
- */
23
- getInstance: async () => {
24
- if (!instance) {
25
- instance = await initializing
26
- }
27
- return instance
28
- }
29
- }
30
- })()
31
-
32
- /**
33
- * 使用设备信息钩子
34
- * 该钩子用于获取客户端设备的信息,如浏览器类型、操作系统等
35
- * 它基于UAParser实例来解析用户代理字符串
36
- *
37
- * @returns {Object} 返回解析后的设备信息对象
38
- */
39
- export const useDeviceInfo = async () => {
40
- const instance = await parserInstance.getInstance()
41
- return instance.getResult()
42
- }
@@ -1,65 +0,0 @@
1
- import dayjs from 'dayjs'
2
-
3
- /**
4
- * 将给定的数据转换为 Blob 对象,并生成一个 URL 对象,用于下载或显示该 Blob 对象
5
- * 此函数主要用于准备数据以便在浏览器中下载或展示
6
- *
7
- * @param data {BlobPart} - 需要转换为 Blob 的数据部分,可以是数组、Blob、字符串等
8
- * @returns {string} 一个 URL 对象,表示新创建的 Blob 对象的位置
9
- */
10
- function transformBlob(data: BlobPart) {
11
- // 创建一个新的 Blob 对象,包含传入的数据部分,并指定 MIME 类型
12
- // 此处的 MIME 类型为 'application/vnd.ms-excel',用于处理 Excel 文件
13
- // 另一个 MIME 类型 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' 用于处理 Office Open XML 格式的 Excel 文件
14
- const blob = new Blob([data], {
15
- type: 'application/vnd.ms-excel'
16
- // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
17
- })
18
-
19
- // 使用 window.URL.createObjectURL 方法创建一个新的 URL 对象,指向 Blob 对象
20
- // 这个 URL 可以在浏览器中直接访问,用于下载或展示 Blob 中的数据
21
- const href = window.URL.createObjectURL(blob)
22
-
23
- // 返回创建的 URL 对象
24
- return href
25
- }
26
-
27
- /**
28
- * 创建一个新的 HTML 元素,通常是 <a> 标签,用于下载文件
29
- *
30
- * @returns {HTMLAnchorElement} 一个新创建的 <a> 标签元素
31
- */
32
- function createElement() {
33
- const downloadElement = document.createElement('a')
34
- return downloadElement
35
- }
36
-
37
- /**
38
- * 导出文件
39
- *
40
- * @param data - 要导出的数据
41
- * @param fileName - 导出的文件名(可选)
42
- */
43
- export function useExportFile(data: BlobPart, fileName?: string) {
44
- const time = dayjs().format('yyyy-MM-dd hh:mm:ss')
45
-
46
- function download() {
47
- const downloadDOM = createElement()
48
- const href = transformBlob(data)
49
-
50
- downloadDOM.href = href
51
- if (fileName) {
52
- downloadDOM.download = fileName || `${fileName}-${time}.xlsx`
53
- } else {
54
- downloadDOM.download = `${time}.xlsx`
55
- }
56
-
57
- document.body.appendChild(downloadDOM)
58
- downloadDOM.click()
59
-
60
- document.body.removeChild(downloadDOM)
61
- window.URL.revokeObjectURL(href)
62
- }
63
-
64
- download()
65
- }
@@ -1,134 +0,0 @@
1
- // import { EnumResponseCode } from '@/enums/responseCode'
2
- import { OptionsType } from './types'
3
- import { computed, onMounted, ref } from 'vue'
4
- import { useExportFile } from '../useExportRemoteFile'
5
- import { useMessage } from 'naive-ui'
6
- // import { getPagination } from '@/utils'
7
-
8
- export function useList<
9
- T extends (...args: any) => Promise<any>
10
- >(listRequestFn: T, options: OptionsType = {}) {
11
- const {
12
- exportRequestFn,
13
- filterOption = ref(),
14
- callback,
15
- immediate = true,
16
- code = 200
17
- } = options
18
-
19
- // 加载态
20
- const loading = ref(false)
21
- const pagination = ref({
22
- page: 1,
23
- pageSize: 10,
24
- itemCount: 0,
25
- showSizePicker: true,
26
- pageSizes: [10, 20, 30, 40],
27
- showQuickJumper: true,
28
- prefix: (info) => `共 ${info.itemCount} 条`
29
- })
30
- // 数据
31
- const dataSource = ref<any[]>([])
32
-
33
- const searchParams = computed(() => {
34
- return filterOption.value
35
- })
36
-
37
- /**
38
- * 加载数据
39
- * @param page - 当前页
40
- * @param pageSize - 页数
41
- */
42
- const loadData = async (
43
- page = pagination.value.page,
44
- filterParams?: any
45
- ) => {
46
- loading.value = true
47
- try {
48
- const { status, data } = await listRequestFn({
49
- pageNum: page,
50
- pageSize: pagination.value.pageSize,
51
- ...searchParams.value,
52
- ...filterParams
53
- })
54
-
55
- const { list, pageNum, total, pageSize } =
56
- (callback && callback(data)) || data
57
- if (status === code && Array.isArray(list)) {
58
- dataSource.value = list
59
- pagination.value = {
60
- ...pagination.value,
61
- page: pageNum,
62
- itemCount: total,
63
- pageSize: pageSize
64
- }
65
- } else {
66
- dataSource.value = []
67
- pagination.value = {
68
- ...pagination.value,
69
- pageSize: 10,
70
- itemCount: 0,
71
- page: 1
72
- }
73
- throw new Error('list的数据类型错误')
74
- }
75
- } catch (error) {
76
- console.error('Error in loadData:', error)
77
- throw error
78
- } finally {
79
- loading.value = false
80
- }
81
- }
82
-
83
- const message = useMessage()
84
- /**
85
- * 导出文件
86
- */
87
- const handleExcelData = async () => {
88
- if (!exportRequestFn || typeof exportRequestFn !== 'function') {
89
- throw new Error('当前没有提供exportRequest函数')
90
- }
91
- try {
92
- const { data, fileName } = await exportRequestFn(filterOption.value)
93
- useExportFile(data, fileName)
94
- message?.success('成功导出')
95
- } catch (error) {
96
- console.error('Error in handleExcelData:', error)
97
- throw error
98
- }
99
- }
100
-
101
- /**
102
- * 更新分页并加载数据
103
- * @param page - 当前页
104
- * @param pageSize - 每页条数
105
- */
106
- const updatePaginationAndLoadData = (page: number, pageSize?: number) => {
107
- if (pageSize !== undefined) {
108
- pagination.value.pageSize = pageSize
109
- }
110
- loadData(page)
111
- }
112
-
113
- const handlePageChange = (page: number) => {
114
- updatePaginationAndLoadData(page)
115
- }
116
-
117
- const handlePageSizeChange = (pageSize: number) => {
118
- updatePaginationAndLoadData(1, pageSize)
119
- }
120
-
121
- onMounted(() => immediate && loadData(pagination.value.page))
122
-
123
- return {
124
- dataSource,
125
- loading,
126
- pagination,
127
- handleExcelData,
128
- handlePageChange,
129
- handlePageSizeChange,
130
- loadData
131
- }
132
- }
133
-
134
- export default useList
@@ -1,20 +0,0 @@
1
- import { Ref } from 'vue'
2
-
3
- export interface OptionsType<T = any> {
4
- requestError?: () => void
5
- requestSuccess?: () => void
6
- callback?: (data: any) => CallbackResult
7
- filterOption?: Ref<T>
8
- exportRequestFn?: (...args: any) => Promise<any>
9
- /** 不立即执行请求获取数据 */
10
- immediate?: boolean
11
- /** 请求响应码 */
12
- code?: number
13
- }
14
-
15
- export interface CallbackResult {
16
- list: any[]
17
- total: number
18
- pageSize: number
19
- pageNum: number
20
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./",
5
- "types": ["node"]
6
- },
7
- "exclude": ["node_modules", "dist"]
8
- }