@banmao/hooks 0.0.1 → 0.0.3
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 +5 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +389 -0
- package/dist/useDeviceInfo.d.ts +8 -0
- package/dist/useExportRemoteFile/index.d.ts +7 -0
- package/dist/useList/index.d.ts +37 -0
- package/dist/useList/types.d.ts +18 -0
- package/package.json +40 -10
- package/CHANGELOG.md +0 -7
- package/index.ts +0 -2
- package/src/useDeviceInfo.ts +0 -42
- package/src/useExportRemoteFile/index.ts +0 -65
- package/src/useList/index.ts +0 -134
- package/src/useList/types.ts +0 -20
- package/tsconfig.json +0 -8
package/README.md
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Vue 3 + TypeScript + Vite
|
|
2
|
+
|
|
3
|
+
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
|
|
4
|
+
|
|
5
|
+
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("vue");function ee(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}var Z={exports:{}},te=Z.exports,G;function ne(){return G||(G=1,function(l,b){(function(D,O){l.exports=O()})(te,function(){var D=1e3,O=6e4,g=36e5,E="millisecond",L="second",_="minute",$="hour",v="day",H="week",p="month",U="quarter",x="year",j="date",q="Invalid Date",B=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,Q=/\[([^\]]+)]|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,c={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(s){var n=["th","st","nd","rd"],e=s%100;return"["+s+(n[(e-20)%10]||n[e]||n[0])+"]"}},w=function(s,n,e){var r=String(s);return!r||r.length>=n?s:""+Array(n+1-r.length).join(e)+s},C={s:w,z:function(s){var n=-s.utcOffset(),e=Math.abs(n),r=Math.floor(e/60),t=e%60;return(n<=0?"+":"-")+w(r,2,"0")+":"+w(t,2,"0")},m:function s(n,e){if(n.date()<e.date())return-s(e,n);var r=12*(e.year()-n.year())+(e.month()-n.month()),t=n.clone().add(r,p),a=e-t<0,i=n.clone().add(r+(a?-1:1),p);return+(-(r+(e-t)/(a?t-i:i-t))||0)},a:function(s){return s<0?Math.ceil(s)||0:Math.floor(s)},p:function(s){return{M:p,y:x,w:H,d:v,D:j,h:$,m:_,s:L,ms:E,Q:U}[s]||String(s||"").toLowerCase().replace(/s$/,"")},u:function(s){return s===void 0}},S="en",k={};k[S]=c;var R="$isDayjsObject",F=function(s){return s instanceof K||!(!s||!s[R])},I=function s(n,e,r){var t;if(!n)return S;if(typeof n=="string"){var a=n.toLowerCase();k[a]&&(t=a),e&&(k[a]=e,t=a);var i=n.split("-");if(!t&&i.length>1)return s(i[0])}else{var o=n.name;k[o]=n,t=o}return!r&&t&&(S=t),t||!r&&S},d=function(s,n){if(F(s))return s.clone();var e=typeof n=="object"?n:{};return e.date=s,e.args=arguments,new K(e)},u=C;u.l=I,u.i=F,u.w=function(s,n){return d(s,{locale:n.$L,utc:n.$u,x:n.$x,$offset:n.$offset})};var K=function(){function s(e){this.$L=I(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[R]=!0}var n=s.prototype;return n.parse=function(e){this.$d=function(r){var t=r.date,a=r.utc;if(t===null)return new Date(NaN);if(u.u(t))return new Date;if(t instanceof Date)return new Date(t);if(typeof t=="string"&&!/Z$/i.test(t)){var i=t.match(B);if(i){var o=i[2]-1||0,f=(i[7]||"0").substring(0,3);return a?new Date(Date.UTC(i[1],o,i[3]||1,i[4]||0,i[5]||0,i[6]||0,f)):new Date(i[1],o,i[3]||1,i[4]||0,i[5]||0,i[6]||0,f)}}return new Date(t)}(e),this.init()},n.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()},n.$utils=function(){return u},n.isValid=function(){return this.$d.toString()!==q},n.isSame=function(e,r){var t=d(e);return this.startOf(r)<=t&&t<=this.endOf(r)},n.isAfter=function(e,r){return d(e)<this.startOf(r)},n.isBefore=function(e,r){return this.endOf(r)<d(e)},n.$g=function(e,r,t){return u.u(e)?this[r]:this.set(t,e)},n.unix=function(){return Math.floor(this.valueOf()/1e3)},n.valueOf=function(){return this.$d.getTime()},n.startOf=function(e,r){var t=this,a=!!u.u(r)||r,i=u.p(e),o=function(z,y){var T=u.w(t.$u?Date.UTC(t.$y,y,z):new Date(t.$y,y,z),t);return a?T:T.endOf(v)},f=function(z,y){return u.w(t.toDate()[z].apply(t.toDate("s"),(a?[0,0,0,0]:[23,59,59,999]).slice(y)),t)},h=this.$W,m=this.$M,M=this.$D,W="set"+(this.$u?"UTC":"");switch(i){case x:return a?o(1,0):o(31,11);case p:return a?o(1,m):o(0,m+1);case H:var Y=this.$locale().weekStart||0,N=(h<Y?h+7:h)-Y;return o(a?M-N:M+(6-N),m);case v:case j:return f(W+"Hours",0);case $:return f(W+"Minutes",1);case _:return f(W+"Seconds",2);case L:return f(W+"Milliseconds",3);default:return this.clone()}},n.endOf=function(e){return this.startOf(e,!1)},n.$set=function(e,r){var t,a=u.p(e),i="set"+(this.$u?"UTC":""),o=(t={},t[v]=i+"Date",t[j]=i+"Date",t[p]=i+"Month",t[x]=i+"FullYear",t[$]=i+"Hours",t[_]=i+"Minutes",t[L]=i+"Seconds",t[E]=i+"Milliseconds",t)[a],f=a===v?this.$D+(r-this.$W):r;if(a===p||a===x){var h=this.clone().set(j,1);h.$d[o](f),h.init(),this.$d=h.set(j,Math.min(this.$D,h.daysInMonth())).$d}else o&&this.$d[o](f);return this.init(),this},n.set=function(e,r){return this.clone().$set(e,r)},n.get=function(e){return this[u.p(e)]()},n.add=function(e,r){var t,a=this;e=Number(e);var i=u.p(r),o=function(m){var M=d(a);return u.w(M.date(M.date()+Math.round(m*e)),a)};if(i===p)return this.set(p,this.$M+e);if(i===x)return this.set(x,this.$y+e);if(i===v)return o(1);if(i===H)return o(7);var f=(t={},t[_]=O,t[$]=g,t[L]=D,t)[i]||1,h=this.$d.getTime()+e*f;return u.w(h,this)},n.subtract=function(e,r){return this.add(-1*e,r)},n.format=function(e){var r=this,t=this.$locale();if(!this.isValid())return t.invalidDate||q;var a=e||"YYYY-MM-DDTHH:mm:ssZ",i=u.z(this),o=this.$H,f=this.$m,h=this.$M,m=t.weekdays,M=t.months,W=t.meridiem,Y=function(y,T,P,J){return y&&(y[T]||y(r,a))||P[T].slice(0,J)},N=function(y){return u.s(o%12||12,y,"0")},z=W||function(y,T,P){var J=y<12?"AM":"PM";return P?J.toLowerCase():J};return a.replace(Q,function(y,T){return T||function(P){switch(P){case"YY":return String(r.$y).slice(-2);case"YYYY":return u.s(r.$y,4,"0");case"M":return h+1;case"MM":return u.s(h+1,2,"0");case"MMM":return Y(t.monthsShort,h,M,3);case"MMMM":return Y(M,h);case"D":return r.$D;case"DD":return u.s(r.$D,2,"0");case"d":return String(r.$W);case"dd":return Y(t.weekdaysMin,r.$W,m,2);case"ddd":return Y(t.weekdaysShort,r.$W,m,3);case"dddd":return m[r.$W];case"H":return String(o);case"HH":return u.s(o,2,"0");case"h":return N(1);case"hh":return N(2);case"a":return z(o,f,!0);case"A":return z(o,f,!1);case"m":return String(f);case"mm":return u.s(f,2,"0");case"s":return String(r.$s);case"ss":return u.s(r.$s,2,"0");case"SSS":return u.s(r.$ms,3,"0");case"Z":return i}return null}(y)||i.replace(":","")})},n.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},n.diff=function(e,r,t){var a,i=this,o=u.p(r),f=d(e),h=(f.utcOffset()-this.utcOffset())*O,m=this-f,M=function(){return u.m(i,f)};switch(o){case x:a=M()/12;break;case p:a=M();break;case U:a=M()/3;break;case H:a=(m-h)/6048e5;break;case v:a=(m-h)/864e5;break;case $:a=m/g;break;case _:a=m/O;break;case L:a=m/D;break;default:a=m}return t?a:u.a(a)},n.daysInMonth=function(){return this.endOf(p).$D},n.$locale=function(){return k[this.$L]},n.locale=function(e,r){if(!e)return this.$L;var t=this.clone(),a=I(e,r,!0);return a&&(t.$L=a),t},n.clone=function(){return u.w(this.$d,this)},n.toDate=function(){return new Date(this.valueOf())},n.toJSON=function(){return this.isValid()?this.toISOString():null},n.toISOString=function(){return this.$d.toISOString()},n.toString=function(){return this.$d.toUTCString()},s}(),V=K.prototype;return d.prototype=V,[["$ms",E],["$s",L],["$m",_],["$H",$],["$W",v],["$M",p],["$y",x],["$D",j]].forEach(function(s){V[s[1]]=function(n){return this.$g(n,s[0],s[1])}}),d.extend=function(s,n){return s.$i||(s(n,K,d),s.$i=!0),d},d.locale=I,d.isDayjs=F,d.unix=function(s){return d(1e3*s)},d.en=k[S],d.Ls=k,d.p={},d})}(Z)),Z.exports}var re=ne();const se=ee(re);function ae(l){const b=new Blob([l],{type:"application/vnd.ms-excel"});return window.URL.createObjectURL(b)}function ie(){return document.createElement("a")}function X(l,b){const D=se().format("yyyy-MM-dd hh:mm:ss");function O(){const g=ie(),E=ae(l);g.href=E,b?g.download=b||`${b}-${D}.xlsx`:g.download=`${D}.xlsx`,document.body.appendChild(g),g.click(),document.body.removeChild(g),window.URL.revokeObjectURL(E)}O()}function ue(l,b){throw new Error(`[naive/${l}]: ${b}`)}const oe="n-message-api";function ce(){const l=A.inject(oe,null);return l===null&&ue("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."),l}function fe(l,b={}){const{exportRequestFn:D,filterOption:O=A.ref(),callback:g,immediate:E=!0,code:L=200}=b,_=A.ref(!1),$=A.ref({page:1,pageSize:10,itemCount:0,showSizePicker:!0,pageSizes:[10,20,30,40],showQuickJumper:!0,prefix:c=>`共 ${c.itemCount} 条`}),v=A.ref([]),H=A.computed(()=>O.value),p=async(c=$.value.page,w)=>{_.value=!0;try{const{status:C,data:S}=await l({pageNum:c,pageSize:$.value.pageSize,...H.value,...w}),{list:k,pageNum:R,total:F,pageSize:I}=g&&g(S)||S;if(C===L&&Array.isArray(k))v.value=k,$.value={...$.value,page:R,itemCount:F,pageSize:I};else throw v.value=[],$.value={...$.value,pageSize:10,itemCount:0,page:1},new Error("list的数据类型错误")}catch(C){throw console.error("Error in loadData:",C),C}finally{_.value=!1}},U=ce(),x=async()=>{if(!D||typeof D!="function")throw new Error("当前没有提供exportRequest函数");try{const{data:c,fileName:w}=await D(O.value);X(c,w),U==null||U.success("成功导出")}catch(c){throw console.error("Error in handleExcelData:",c),c}},j=(c,w)=>{w!==void 0&&($.value.pageSize=w),p(c)},q=c=>{j(c)},B=c=>{j(1,c)},Q=c=>{if(c.sorter){const w=[...v.value].sort((C,S)=>c.order==="ascend"?C[c.columnKey]>S[c.columnKey]?1:-1:c.order==="descend"?C[c.columnKey]<S[c.columnKey]?1:-1:0);v.value=w}};return A.onMounted(()=>E&&p($.value.page)),{dataSource:v,loading:_,pagination:$,handleExcelData:x,handlePageChange:q,handlePageSizeChange:B,handleSortChange:Q,loadData:p}}exports.useExportFile=X;exports.useList=fe;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import { inject as X, ref as J, computed as ee, onMounted as te } from "vue";
|
|
2
|
+
function ne(l) {
|
|
3
|
+
return l && l.__esModule && Object.prototype.hasOwnProperty.call(l, "default") ? l.default : l;
|
|
4
|
+
}
|
|
5
|
+
var Z = { exports: {} }, re = Z.exports, G;
|
|
6
|
+
function se() {
|
|
7
|
+
return G || (G = 1, function(l, O) {
|
|
8
|
+
(function(D, b) {
|
|
9
|
+
l.exports = b();
|
|
10
|
+
})(re, function() {
|
|
11
|
+
var D = 1e3, b = 6e4, g = 36e5, E = "millisecond", L = "second", _ = "minute", $ = "hour", v = "day", H = "week", p = "month", T = "quarter", x = "year", C = "date", P = "Invalid Date", B = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, Q = /\[([^\]]+)]|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, c = { 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(s) {
|
|
12
|
+
var n = ["th", "st", "nd", "rd"], e = s % 100;
|
|
13
|
+
return "[" + s + (n[(e - 20) % 10] || n[e] || n[0]) + "]";
|
|
14
|
+
} }, w = function(s, n, e) {
|
|
15
|
+
var r = String(s);
|
|
16
|
+
return !r || r.length >= n ? s : "" + Array(n + 1 - r.length).join(e) + s;
|
|
17
|
+
}, j = { s: w, z: function(s) {
|
|
18
|
+
var n = -s.utcOffset(), e = Math.abs(n), r = Math.floor(e / 60), t = e % 60;
|
|
19
|
+
return (n <= 0 ? "+" : "-") + w(r, 2, "0") + ":" + w(t, 2, "0");
|
|
20
|
+
}, m: function s(n, e) {
|
|
21
|
+
if (n.date() < e.date()) return -s(e, n);
|
|
22
|
+
var r = 12 * (e.year() - n.year()) + (e.month() - n.month()), t = n.clone().add(r, p), a = e - t < 0, i = n.clone().add(r + (a ? -1 : 1), p);
|
|
23
|
+
return +(-(r + (e - t) / (a ? t - i : i - t)) || 0);
|
|
24
|
+
}, a: function(s) {
|
|
25
|
+
return s < 0 ? Math.ceil(s) || 0 : Math.floor(s);
|
|
26
|
+
}, p: function(s) {
|
|
27
|
+
return { M: p, y: x, w: H, d: v, D: C, h: $, m: _, s: L, ms: E, Q: T }[s] || String(s || "").toLowerCase().replace(/s$/, "");
|
|
28
|
+
}, u: function(s) {
|
|
29
|
+
return s === void 0;
|
|
30
|
+
} }, S = "en", k = {};
|
|
31
|
+
k[S] = c;
|
|
32
|
+
var R = "$isDayjsObject", W = function(s) {
|
|
33
|
+
return s instanceof q || !(!s || !s[R]);
|
|
34
|
+
}, U = function s(n, e, r) {
|
|
35
|
+
var t;
|
|
36
|
+
if (!n) return S;
|
|
37
|
+
if (typeof n == "string") {
|
|
38
|
+
var a = n.toLowerCase();
|
|
39
|
+
k[a] && (t = a), e && (k[a] = e, t = a);
|
|
40
|
+
var i = n.split("-");
|
|
41
|
+
if (!t && i.length > 1) return s(i[0]);
|
|
42
|
+
} else {
|
|
43
|
+
var o = n.name;
|
|
44
|
+
k[o] = n, t = o;
|
|
45
|
+
}
|
|
46
|
+
return !r && t && (S = t), t || !r && S;
|
|
47
|
+
}, d = function(s, n) {
|
|
48
|
+
if (W(s)) return s.clone();
|
|
49
|
+
var e = typeof n == "object" ? n : {};
|
|
50
|
+
return e.date = s, e.args = arguments, new q(e);
|
|
51
|
+
}, u = j;
|
|
52
|
+
u.l = U, u.i = W, u.w = function(s, n) {
|
|
53
|
+
return d(s, { locale: n.$L, utc: n.$u, x: n.$x, $offset: n.$offset });
|
|
54
|
+
};
|
|
55
|
+
var q = function() {
|
|
56
|
+
function s(e) {
|
|
57
|
+
this.$L = U(e.locale, null, !0), this.parse(e), this.$x = this.$x || e.x || {}, this[R] = !0;
|
|
58
|
+
}
|
|
59
|
+
var n = s.prototype;
|
|
60
|
+
return n.parse = function(e) {
|
|
61
|
+
this.$d = function(r) {
|
|
62
|
+
var t = r.date, a = r.utc;
|
|
63
|
+
if (t === null) return /* @__PURE__ */ new Date(NaN);
|
|
64
|
+
if (u.u(t)) return /* @__PURE__ */ new Date();
|
|
65
|
+
if (t instanceof Date) return new Date(t);
|
|
66
|
+
if (typeof t == "string" && !/Z$/i.test(t)) {
|
|
67
|
+
var i = t.match(B);
|
|
68
|
+
if (i) {
|
|
69
|
+
var o = i[2] - 1 || 0, f = (i[7] || "0").substring(0, 3);
|
|
70
|
+
return a ? new Date(Date.UTC(i[1], o, i[3] || 1, i[4] || 0, i[5] || 0, i[6] || 0, f)) : new Date(i[1], o, i[3] || 1, i[4] || 0, i[5] || 0, i[6] || 0, f);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return new Date(t);
|
|
74
|
+
}(e), this.init();
|
|
75
|
+
}, n.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
|
+
}, n.$utils = function() {
|
|
79
|
+
return u;
|
|
80
|
+
}, n.isValid = function() {
|
|
81
|
+
return this.$d.toString() !== P;
|
|
82
|
+
}, n.isSame = function(e, r) {
|
|
83
|
+
var t = d(e);
|
|
84
|
+
return this.startOf(r) <= t && t <= this.endOf(r);
|
|
85
|
+
}, n.isAfter = function(e, r) {
|
|
86
|
+
return d(e) < this.startOf(r);
|
|
87
|
+
}, n.isBefore = function(e, r) {
|
|
88
|
+
return this.endOf(r) < d(e);
|
|
89
|
+
}, n.$g = function(e, r, t) {
|
|
90
|
+
return u.u(e) ? this[r] : this.set(t, e);
|
|
91
|
+
}, n.unix = function() {
|
|
92
|
+
return Math.floor(this.valueOf() / 1e3);
|
|
93
|
+
}, n.valueOf = function() {
|
|
94
|
+
return this.$d.getTime();
|
|
95
|
+
}, n.startOf = function(e, r) {
|
|
96
|
+
var t = this, a = !!u.u(r) || r, i = u.p(e), o = function(A, y) {
|
|
97
|
+
var Y = u.w(t.$u ? Date.UTC(t.$y, y, A) : new Date(t.$y, y, A), t);
|
|
98
|
+
return a ? Y : Y.endOf(v);
|
|
99
|
+
}, f = function(A, y) {
|
|
100
|
+
return u.w(t.toDate()[A].apply(t.toDate("s"), (a ? [0, 0, 0, 0] : [23, 59, 59, 999]).slice(y)), t);
|
|
101
|
+
}, h = this.$W, m = this.$M, M = this.$D, I = "set" + (this.$u ? "UTC" : "");
|
|
102
|
+
switch (i) {
|
|
103
|
+
case x:
|
|
104
|
+
return a ? o(1, 0) : o(31, 11);
|
|
105
|
+
case p:
|
|
106
|
+
return a ? o(1, m) : o(0, m + 1);
|
|
107
|
+
case H:
|
|
108
|
+
var z = this.$locale().weekStart || 0, N = (h < z ? h + 7 : h) - z;
|
|
109
|
+
return o(a ? M - N : M + (6 - N), m);
|
|
110
|
+
case v:
|
|
111
|
+
case C:
|
|
112
|
+
return f(I + "Hours", 0);
|
|
113
|
+
case $:
|
|
114
|
+
return f(I + "Minutes", 1);
|
|
115
|
+
case _:
|
|
116
|
+
return f(I + "Seconds", 2);
|
|
117
|
+
case L:
|
|
118
|
+
return f(I + "Milliseconds", 3);
|
|
119
|
+
default:
|
|
120
|
+
return this.clone();
|
|
121
|
+
}
|
|
122
|
+
}, n.endOf = function(e) {
|
|
123
|
+
return this.startOf(e, !1);
|
|
124
|
+
}, n.$set = function(e, r) {
|
|
125
|
+
var t, a = u.p(e), i = "set" + (this.$u ? "UTC" : ""), o = (t = {}, t[v] = i + "Date", t[C] = i + "Date", t[p] = i + "Month", t[x] = i + "FullYear", t[$] = i + "Hours", t[_] = i + "Minutes", t[L] = i + "Seconds", t[E] = i + "Milliseconds", t)[a], f = a === v ? this.$D + (r - this.$W) : r;
|
|
126
|
+
if (a === p || a === x) {
|
|
127
|
+
var h = this.clone().set(C, 1);
|
|
128
|
+
h.$d[o](f), h.init(), this.$d = h.set(C, Math.min(this.$D, h.daysInMonth())).$d;
|
|
129
|
+
} else o && this.$d[o](f);
|
|
130
|
+
return this.init(), this;
|
|
131
|
+
}, n.set = function(e, r) {
|
|
132
|
+
return this.clone().$set(e, r);
|
|
133
|
+
}, n.get = function(e) {
|
|
134
|
+
return this[u.p(e)]();
|
|
135
|
+
}, n.add = function(e, r) {
|
|
136
|
+
var t, a = this;
|
|
137
|
+
e = Number(e);
|
|
138
|
+
var i = u.p(r), o = function(m) {
|
|
139
|
+
var M = d(a);
|
|
140
|
+
return u.w(M.date(M.date() + Math.round(m * e)), a);
|
|
141
|
+
};
|
|
142
|
+
if (i === p) return this.set(p, this.$M + e);
|
|
143
|
+
if (i === x) return this.set(x, this.$y + e);
|
|
144
|
+
if (i === v) return o(1);
|
|
145
|
+
if (i === H) return o(7);
|
|
146
|
+
var f = (t = {}, t[_] = b, t[$] = g, t[L] = D, t)[i] || 1, h = this.$d.getTime() + e * f;
|
|
147
|
+
return u.w(h, this);
|
|
148
|
+
}, n.subtract = function(e, r) {
|
|
149
|
+
return this.add(-1 * e, r);
|
|
150
|
+
}, n.format = function(e) {
|
|
151
|
+
var r = this, t = this.$locale();
|
|
152
|
+
if (!this.isValid()) return t.invalidDate || P;
|
|
153
|
+
var a = e || "YYYY-MM-DDTHH:mm:ssZ", i = u.z(this), o = this.$H, f = this.$m, h = this.$M, m = t.weekdays, M = t.months, I = t.meridiem, z = function(y, Y, F, K) {
|
|
154
|
+
return y && (y[Y] || y(r, a)) || F[Y].slice(0, K);
|
|
155
|
+
}, N = function(y) {
|
|
156
|
+
return u.s(o % 12 || 12, y, "0");
|
|
157
|
+
}, A = I || function(y, Y, F) {
|
|
158
|
+
var K = y < 12 ? "AM" : "PM";
|
|
159
|
+
return F ? K.toLowerCase() : K;
|
|
160
|
+
};
|
|
161
|
+
return a.replace(Q, function(y, Y) {
|
|
162
|
+
return Y || function(F) {
|
|
163
|
+
switch (F) {
|
|
164
|
+
case "YY":
|
|
165
|
+
return String(r.$y).slice(-2);
|
|
166
|
+
case "YYYY":
|
|
167
|
+
return u.s(r.$y, 4, "0");
|
|
168
|
+
case "M":
|
|
169
|
+
return h + 1;
|
|
170
|
+
case "MM":
|
|
171
|
+
return u.s(h + 1, 2, "0");
|
|
172
|
+
case "MMM":
|
|
173
|
+
return z(t.monthsShort, h, M, 3);
|
|
174
|
+
case "MMMM":
|
|
175
|
+
return z(M, h);
|
|
176
|
+
case "D":
|
|
177
|
+
return r.$D;
|
|
178
|
+
case "DD":
|
|
179
|
+
return u.s(r.$D, 2, "0");
|
|
180
|
+
case "d":
|
|
181
|
+
return String(r.$W);
|
|
182
|
+
case "dd":
|
|
183
|
+
return z(t.weekdaysMin, r.$W, m, 2);
|
|
184
|
+
case "ddd":
|
|
185
|
+
return z(t.weekdaysShort, r.$W, m, 3);
|
|
186
|
+
case "dddd":
|
|
187
|
+
return m[r.$W];
|
|
188
|
+
case "H":
|
|
189
|
+
return String(o);
|
|
190
|
+
case "HH":
|
|
191
|
+
return u.s(o, 2, "0");
|
|
192
|
+
case "h":
|
|
193
|
+
return N(1);
|
|
194
|
+
case "hh":
|
|
195
|
+
return N(2);
|
|
196
|
+
case "a":
|
|
197
|
+
return A(o, f, !0);
|
|
198
|
+
case "A":
|
|
199
|
+
return A(o, f, !1);
|
|
200
|
+
case "m":
|
|
201
|
+
return String(f);
|
|
202
|
+
case "mm":
|
|
203
|
+
return u.s(f, 2, "0");
|
|
204
|
+
case "s":
|
|
205
|
+
return String(r.$s);
|
|
206
|
+
case "ss":
|
|
207
|
+
return u.s(r.$s, 2, "0");
|
|
208
|
+
case "SSS":
|
|
209
|
+
return u.s(r.$ms, 3, "0");
|
|
210
|
+
case "Z":
|
|
211
|
+
return i;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}(y) || i.replace(":", "");
|
|
215
|
+
});
|
|
216
|
+
}, n.utcOffset = function() {
|
|
217
|
+
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
218
|
+
}, n.diff = function(e, r, t) {
|
|
219
|
+
var a, i = this, o = u.p(r), f = d(e), h = (f.utcOffset() - this.utcOffset()) * b, m = this - f, M = function() {
|
|
220
|
+
return u.m(i, f);
|
|
221
|
+
};
|
|
222
|
+
switch (o) {
|
|
223
|
+
case x:
|
|
224
|
+
a = M() / 12;
|
|
225
|
+
break;
|
|
226
|
+
case p:
|
|
227
|
+
a = M();
|
|
228
|
+
break;
|
|
229
|
+
case T:
|
|
230
|
+
a = M() / 3;
|
|
231
|
+
break;
|
|
232
|
+
case H:
|
|
233
|
+
a = (m - h) / 6048e5;
|
|
234
|
+
break;
|
|
235
|
+
case v:
|
|
236
|
+
a = (m - h) / 864e5;
|
|
237
|
+
break;
|
|
238
|
+
case $:
|
|
239
|
+
a = m / g;
|
|
240
|
+
break;
|
|
241
|
+
case _:
|
|
242
|
+
a = m / b;
|
|
243
|
+
break;
|
|
244
|
+
case L:
|
|
245
|
+
a = m / D;
|
|
246
|
+
break;
|
|
247
|
+
default:
|
|
248
|
+
a = m;
|
|
249
|
+
}
|
|
250
|
+
return t ? a : u.a(a);
|
|
251
|
+
}, n.daysInMonth = function() {
|
|
252
|
+
return this.endOf(p).$D;
|
|
253
|
+
}, n.$locale = function() {
|
|
254
|
+
return k[this.$L];
|
|
255
|
+
}, n.locale = function(e, r) {
|
|
256
|
+
if (!e) return this.$L;
|
|
257
|
+
var t = this.clone(), a = U(e, r, !0);
|
|
258
|
+
return a && (t.$L = a), t;
|
|
259
|
+
}, n.clone = function() {
|
|
260
|
+
return u.w(this.$d, this);
|
|
261
|
+
}, n.toDate = function() {
|
|
262
|
+
return new Date(this.valueOf());
|
|
263
|
+
}, n.toJSON = function() {
|
|
264
|
+
return this.isValid() ? this.toISOString() : null;
|
|
265
|
+
}, n.toISOString = function() {
|
|
266
|
+
return this.$d.toISOString();
|
|
267
|
+
}, n.toString = function() {
|
|
268
|
+
return this.$d.toUTCString();
|
|
269
|
+
}, s;
|
|
270
|
+
}(), V = q.prototype;
|
|
271
|
+
return d.prototype = V, [["$ms", E], ["$s", L], ["$m", _], ["$H", $], ["$W", v], ["$M", p], ["$y", x], ["$D", C]].forEach(function(s) {
|
|
272
|
+
V[s[1]] = function(n) {
|
|
273
|
+
return this.$g(n, s[0], s[1]);
|
|
274
|
+
};
|
|
275
|
+
}), d.extend = function(s, n) {
|
|
276
|
+
return s.$i || (s(n, q, d), s.$i = !0), d;
|
|
277
|
+
}, d.locale = U, d.isDayjs = W, d.unix = function(s) {
|
|
278
|
+
return d(1e3 * s);
|
|
279
|
+
}, d.en = k[S], d.Ls = k, d.p = {}, d;
|
|
280
|
+
});
|
|
281
|
+
}(Z)), Z.exports;
|
|
282
|
+
}
|
|
283
|
+
var ae = se();
|
|
284
|
+
const ie = /* @__PURE__ */ ne(ae);
|
|
285
|
+
function ue(l) {
|
|
286
|
+
const O = new Blob([l], {
|
|
287
|
+
type: "application/vnd.ms-excel"
|
|
288
|
+
// type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
289
|
+
});
|
|
290
|
+
return window.URL.createObjectURL(O);
|
|
291
|
+
}
|
|
292
|
+
function oe() {
|
|
293
|
+
return document.createElement("a");
|
|
294
|
+
}
|
|
295
|
+
function ce(l, O) {
|
|
296
|
+
const D = ie().format("yyyy-MM-dd hh:mm:ss");
|
|
297
|
+
function b() {
|
|
298
|
+
const g = oe(), E = ue(l);
|
|
299
|
+
g.href = E, O ? g.download = O || `${O}-${D}.xlsx` : g.download = `${D}.xlsx`, document.body.appendChild(g), g.click(), document.body.removeChild(g), window.URL.revokeObjectURL(E);
|
|
300
|
+
}
|
|
301
|
+
b();
|
|
302
|
+
}
|
|
303
|
+
function fe(l, O) {
|
|
304
|
+
throw new Error(`[naive/${l}]: ${O}`);
|
|
305
|
+
}
|
|
306
|
+
const le = "n-message-api";
|
|
307
|
+
function de() {
|
|
308
|
+
const l = X(le, null);
|
|
309
|
+
return l === null && fe("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."), l;
|
|
310
|
+
}
|
|
311
|
+
function $e(l, O = {}) {
|
|
312
|
+
const {
|
|
313
|
+
exportRequestFn: D,
|
|
314
|
+
filterOption: b = J(),
|
|
315
|
+
callback: g,
|
|
316
|
+
immediate: E = !0,
|
|
317
|
+
code: L = 200
|
|
318
|
+
} = O, _ = J(!1), $ = J({
|
|
319
|
+
page: 1,
|
|
320
|
+
pageSize: 10,
|
|
321
|
+
itemCount: 0,
|
|
322
|
+
showSizePicker: !0,
|
|
323
|
+
pageSizes: [10, 20, 30, 40],
|
|
324
|
+
showQuickJumper: !0,
|
|
325
|
+
prefix: (c) => `共 ${c.itemCount} 条`
|
|
326
|
+
}), v = J([]), H = ee(() => b.value), p = async (c = $.value.page, w) => {
|
|
327
|
+
_.value = !0;
|
|
328
|
+
try {
|
|
329
|
+
const { status: j, data: S } = await l({
|
|
330
|
+
pageNum: c,
|
|
331
|
+
pageSize: $.value.pageSize,
|
|
332
|
+
...H.value,
|
|
333
|
+
...w
|
|
334
|
+
}), { list: k, pageNum: R, total: W, pageSize: U } = g && g(S) || S;
|
|
335
|
+
if (j === L && Array.isArray(k))
|
|
336
|
+
v.value = k, $.value = {
|
|
337
|
+
...$.value,
|
|
338
|
+
page: R,
|
|
339
|
+
itemCount: W,
|
|
340
|
+
pageSize: U
|
|
341
|
+
};
|
|
342
|
+
else
|
|
343
|
+
throw v.value = [], $.value = {
|
|
344
|
+
...$.value,
|
|
345
|
+
pageSize: 10,
|
|
346
|
+
itemCount: 0,
|
|
347
|
+
page: 1
|
|
348
|
+
}, new Error("list的数据类型错误");
|
|
349
|
+
} catch (j) {
|
|
350
|
+
throw console.error("Error in loadData:", j), j;
|
|
351
|
+
} finally {
|
|
352
|
+
_.value = !1;
|
|
353
|
+
}
|
|
354
|
+
}, T = de(), x = async () => {
|
|
355
|
+
if (!D || typeof D != "function")
|
|
356
|
+
throw new Error("当前没有提供exportRequest函数");
|
|
357
|
+
try {
|
|
358
|
+
const { data: c, fileName: w } = await D(b.value);
|
|
359
|
+
ce(c, w), T == null || T.success("成功导出");
|
|
360
|
+
} catch (c) {
|
|
361
|
+
throw console.error("Error in handleExcelData:", c), c;
|
|
362
|
+
}
|
|
363
|
+
}, C = (c, w) => {
|
|
364
|
+
w !== void 0 && ($.value.pageSize = w), p(c);
|
|
365
|
+
}, P = (c) => {
|
|
366
|
+
C(c);
|
|
367
|
+
}, B = (c) => {
|
|
368
|
+
C(1, c);
|
|
369
|
+
}, Q = (c) => {
|
|
370
|
+
if (c.sorter) {
|
|
371
|
+
const w = [...v.value].sort((j, S) => c.order === "ascend" ? j[c.columnKey] > S[c.columnKey] ? 1 : -1 : c.order === "descend" ? j[c.columnKey] < S[c.columnKey] ? 1 : -1 : 0);
|
|
372
|
+
v.value = w;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
return te(() => E && p($.value.page)), {
|
|
376
|
+
dataSource: v,
|
|
377
|
+
loading: _,
|
|
378
|
+
pagination: $,
|
|
379
|
+
handleExcelData: x,
|
|
380
|
+
handlePageChange: P,
|
|
381
|
+
handlePageSizeChange: B,
|
|
382
|
+
handleSortChange: Q,
|
|
383
|
+
loadData: p
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
export {
|
|
387
|
+
ce as useExportFile,
|
|
388
|
+
$e as useList
|
|
389
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
};
|
|
37
|
+
export default useList;
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banmao/hooks",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
"version": "0.0.3",
|
|
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
|
-
"@
|
|
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
package/index.ts
DELETED
package/src/useDeviceInfo.ts
DELETED
|
@@ -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
|
-
}
|
package/src/useList/index.ts
DELETED
|
@@ -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: 2,
|
|
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
|
package/src/useList/types.ts
DELETED
|
@@ -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
|
-
}
|