@mtn-ui/components 1.0.11 → 1.0.12
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/dist/antd-wrapped/action-group/action-group.vue2.js +9 -9
- package/dist/antd-wrapped/dropdown-button/dropdown-button.js +6 -6
- package/dist/index.cjs +2 -1
- package/dist/index.js +25 -25
- package/dist/index.mjs +25 -24
- package/dist/types/index.d.ts +5 -0
- package/dist/types/packages/components/src/index.d.ts +5 -0
- package/package.json +6 -2
|
@@ -3,25 +3,25 @@ import { useDebounceFn as Be } from "@vueuse/core";
|
|
|
3
3
|
import { MoreOutlined as Oe } from "@ant-design/icons-vue";
|
|
4
4
|
import { Menu as Y } from "ant-design-vue";
|
|
5
5
|
import Ue from "../button/button.js";
|
|
6
|
-
import De from "../button-group/button-group.js";
|
|
7
6
|
import le from "../dropdown-button/dropdown-button.js";
|
|
8
|
-
import { actionGroupProps as
|
|
9
|
-
import { PERMISSION_CHECKER_KEY as
|
|
10
|
-
import { filterValidChildren as
|
|
7
|
+
import { actionGroupProps as De } from "./props.js";
|
|
8
|
+
import { PERMISSION_CHECKER_KEY as je, defaultPermissionChecker as We } from "@mtn-ui/shared";
|
|
9
|
+
import { filterValidChildren as Ke, getButtonKey as $e } from "./utils.js";
|
|
10
|
+
import Fe from "../button-group/button-group.js";
|
|
11
11
|
const H = "link", ae = "small", Ge = 150, tn = /* @__PURE__ */ Ae({
|
|
12
12
|
name: "MActionGroup",
|
|
13
13
|
inheritAttrs: !1,
|
|
14
14
|
__name: "action-group",
|
|
15
|
-
props:
|
|
15
|
+
props: De,
|
|
16
16
|
emits: ["action-click"],
|
|
17
17
|
setup(ie, { emit: ue }) {
|
|
18
|
-
const t = ie, ce = ue, D = Me(), pe = Se(), y = I(), T = I(), E = I(), me = Ie(
|
|
18
|
+
const t = ie, ce = ue, D = Me(), pe = Se(), y = I(), T = I(), E = I(), me = Ie(je, I(We)), x = i(() => t.mode === "table"), A = i(() => x.value ? "small" : t.size), N = i(() => x.value ? "link" : "default"), q = i(() => x.value ? "" : t.moreText), Z = i(() => t.moreIcon || Oe);
|
|
19
19
|
function R(e) {
|
|
20
20
|
return e ? me.value(e) : !0;
|
|
21
21
|
}
|
|
22
22
|
const J = i(() => {
|
|
23
23
|
var e;
|
|
24
|
-
return
|
|
24
|
+
return Ke((e = D.default) == null ? void 0 : e.call(D));
|
|
25
25
|
}), h = Te([]);
|
|
26
26
|
function Q(e) {
|
|
27
27
|
var c, l, p;
|
|
@@ -68,7 +68,7 @@ const H = "link", ae = "small", Ge = 150, tn = /* @__PURE__ */ Ae({
|
|
|
68
68
|
return o.permission && o.permissionAction === "hide" ? R(o.permission) : !0;
|
|
69
69
|
}).map((e, o) => {
|
|
70
70
|
var l, p;
|
|
71
|
-
const n =
|
|
71
|
+
const n = $e(e, o), s = oe(e, {
|
|
72
72
|
type: ((l = e.props) == null ? void 0 : l.type) ?? (x.value ? N.value : void 0),
|
|
73
73
|
size: ((p = e.props) == null ? void 0 : p.size) ?? A.value
|
|
74
74
|
}), c = oe(e, {
|
|
@@ -230,7 +230,7 @@ const H = "link", ae = "small", Ge = 150, tn = /* @__PURE__ */ Ae({
|
|
|
230
230
|
ref: y,
|
|
231
231
|
class: "mtn-action-group"
|
|
232
232
|
}, [
|
|
233
|
-
$(C(
|
|
233
|
+
$(C(Fe), se(Re(fe.value)), {
|
|
234
234
|
default: m(() => [
|
|
235
235
|
t.actions ? (r(!0), v(P, { key: 0 }, z(X.value, (n) => (r(), u(d(n.component), U({
|
|
236
236
|
key: n.key,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { defineComponent as g, inject as h, ref as y, createVNode as a, mergeProps as m, h as v } from "vue";
|
|
2
2
|
import { Dropdown as l, Button as C, Menu as b } from "ant-design-vue";
|
|
3
3
|
import { dropdownButtonProps as k } from "./props.js";
|
|
4
|
-
import {
|
|
5
|
-
import { filterMenuByPermission as
|
|
6
|
-
import {
|
|
4
|
+
import { PERMISSION_CHECKER_KEY as w, defaultPermissionChecker as z } from "@mtn-ui/shared";
|
|
5
|
+
import { filterMenuByPermission as B } from "../../_utils/filterMenuByPermission.js";
|
|
6
|
+
import { usePermission as P } from "../../_utils/usePermission.js";
|
|
7
7
|
const H = /* @__PURE__ */ g({
|
|
8
8
|
name: "MDropdownButton",
|
|
9
9
|
props: k,
|
|
@@ -16,10 +16,10 @@ const H = /* @__PURE__ */ g({
|
|
|
16
16
|
const {
|
|
17
17
|
shouldHide: c,
|
|
18
18
|
shouldDisable: o
|
|
19
|
-
} =
|
|
19
|
+
} = P({
|
|
20
20
|
permission: e.permission,
|
|
21
21
|
permissionAction: e.permissionAction
|
|
22
|
-
}), f = h(
|
|
22
|
+
}), f = h(w, y(z)), r = (i) => {
|
|
23
23
|
u("click", i);
|
|
24
24
|
};
|
|
25
25
|
return () => {
|
|
@@ -29,7 +29,7 @@ const H = /* @__PURE__ */ g({
|
|
|
29
29
|
if (n.overlay)
|
|
30
30
|
i.overlay = n.overlay;
|
|
31
31
|
else if (e.menu && e.menu.length > 0) {
|
|
32
|
-
const t =
|
|
32
|
+
const t = B(e.menu, f.value);
|
|
33
33
|
i.overlay = () => v(b, {
|
|
34
34
|
items: t
|
|
35
35
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const T=require("@mtn-ui/shared"),e=require("vue"),Pe=require("class-variance-authority"),k=require("ant-design-vue"),J=require("@vueuse/core"),F=require("@ant-design/icons-vue"),Q={type:{type:String,default:"default"},color:{type:String}},Te=Pe.cva("inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border transition-colors",{variants:{type:{default:"bg-gray-100 text-gray-800 border-gray-200",success:"bg-green-100 text-green-800 border-green-200",processing:"bg-blue-100 text-blue-800 border-blue-200",error:"bg-red-100 text-red-800 border-red-200",warning:"bg-orange-100 text-orange-800 border-orange-200"}},defaultVariants:{type:"default"}}),we=e.defineComponent({name:"MTag",props:Q,setup(t,{slots:a,attrs:o}){return()=>{var c;const{type:r}=t;return e.createVNode("span",{class:T.cn(Te({type:r}),o.class)},[(c=a.default)==null?void 0:c.call(a)])}}}),ee=T.withInstall(we),te={type:{type:String,default:"default"},size:{type:String,default:"middle"},loading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},danger:{type:Boolean,default:!1},block:{type:Boolean,default:!1},ghost:{type:Boolean,default:!1},shape:{type:String,default:"default"},htmlType:{type:String,default:"button"},icon:{type:Object},permission:{type:[String,Array],default:void 0},permissionAction:{type:String,default:"hide"}};function ne(t){const{permission:a,permissionAction:o="hide"}=t,r=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),c=e.computed(()=>a?r.value(a):!0),f=e.computed(()=>!c.value&&o==="hide"),d=e.computed(()=>!c.value&&o==="disable");return{hasPermission:c,shouldHide:f,shouldDisable:d}}function De(t,a){return t.map(o=>{if(!o||o.type==="divider"||!o.permission)return o;if(!a(o.permission)){const c=o.permissionAction||"hide";if(c==="hide")return null;if(c==="disable")return{...o,disabled:!0}}return o}).filter(Boolean)}const M=e.defineComponent({name:"MButton",props:te,emits:["click"],setup(t,{slots:a,attrs:o,emit:r}){const{shouldHide:c,shouldDisable:f}=ne({permission:t.permission,permissionAction:t.permissionAction}),d=p=>{r("click",p)};return()=>c.value?null:e.createVNode(k.Button,e.mergeProps({type:t.type,size:t.size,loading:t.loading,disabled:t.disabled||f.value,danger:t.danger,block:t.block,ghost:t.ghost,shape:t.shape,htmlType:t.htmlType,icon:t.icon},o,{class:["mtn-button",o.class],onClick:d}),{default:()=>{var p;return(p=a.default)==null?void 0:p.call(a)},icon:()=>{var p;return(p=a.icon)==null?void 0:p.call(a)}})}}),oe={size:{type:String,default:"middle"},compact:{type:Boolean,default:!0},gap:{type:[Number,String],default:8},vertical:{type:Boolean,default:!1},block:{type:Boolean,default:!1}},U=e.defineComponent({name:"MButtonGroup",props:oe,setup(t,{slots:a,attrs:o}){return()=>e.createVNode(e.Fragment,null,[t.compact?e.createVNode(k.Space.Compact,e.mergeProps({size:t.size,direction:t.vertical?"vertical":"horizontal",block:t.block},o,{class:["mtn-button-group","mtn-button-group--compact",o.class]}),{default:()=>{var r;return[(r=a.default)==null?void 0:r.call(a)]}}):e.createVNode(k.Space,e.mergeProps({size:typeof t.gap=="number"?t.gap:parseInt(t.gap)||8,direction:t.vertical?"vertical":"horizontal"},o,{class:["mtn-button-group","mtn-button-group--normal",o.class]}),{default:()=>{var r;return[(r=a.default)==null?void 0:r.call(a)]}})])}}),ze={text:{type:String,default:"Dropdown"},type:{type:String,default:"default"},size:{type:String,default:"middle"},menu:{type:Array,default:void 0},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},danger:{type:Boolean,default:!1},placement:{type:String,default:"bottomLeft"},trigger:{type:Array,default:()=>["click"]},permission:{type:[String,Array],default:void 0},permissionAction:{type:String,default:"hide"}},G=e.defineComponent({name:"MDropdownButton",props:ze,emits:["click"],setup(t,{slots:a,attrs:o,emit:r}){const{shouldHide:c,shouldDisable:f}=ne({permission:t.permission,permissionAction:t.permissionAction}),d=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),p=y=>{r("click",y)};return()=>{if(c.value)return null;const y={};if(a.overlay)y.overlay=a.overlay;else if(t.menu&&t.menu.length>0){const g=De(t.menu,d.value);y.overlay=()=>e.h(k.Menu,{items:g})}return a.icon&&(y.icon=a.icon),!(a.default||t.text)?e.createVNode(k.Dropdown,e.mergeProps({placement:t.placement,trigger:t.trigger},o,{class:["mtn-dropdown-button",o.class]}),{default:()=>[e.createVNode(k.Button,{type:t.type,size:t.size==="middle"?void 0:t.size,disabled:t.disabled||f.value,loading:t.loading,danger:t.danger,onClick:p},{default:()=>{var g;return[(g=a.icon)==null?void 0:g.call(a)]}})],...y}):e.createVNode(k.Dropdown.Button,e.mergeProps({type:t.type,size:t.size==="middle"?void 0:t.size,disabled:t.disabled||f.value,loading:t.loading,danger:t.danger,placement:t.placement,trigger:t.trigger},o,{class:["mtn-dropdown-button",o.class],onClick:p}),{default:()=>{var g;return[((g=a.default)==null?void 0:g.call(a))||t.text]},...y})}}}),Ae={actions:{type:Array,default:void 0},mode:{type:String,default:"default"},maxItems:{type:Number,default:3},gap:{type:Number,default:8},moreText:{type:String,default:"更多"},moreIcon:{type:Object,default:void 0},moreProps:{type:Object,default:()=>({})},size:{type:String,default:"middle"},compact:{type:Boolean,default:!1},vertical:{type:Boolean,default:!1},block:{type:Boolean,default:!1},disableCollapse:{type:Boolean,default:!1}};function Ee(t){return t?t.filter(a=>a.type!==e.Comment&&a.type!==e.Text&&a.type!==Symbol.for("v-fgt")):[]}function Ne(t,a){var o,r;if(t.key!==null&&t.key!==void 0)return typeof t.key=="symbol"?t.key.toString():t.key;if(((o=t.props)==null?void 0:o.key)!==null&&((r=t.props)==null?void 0:r.key)!==void 0){const c=t.props.key;return typeof c=="symbol"?c.toString():c}return`button-${a}`}const H="link",Z="small",_e=150,Me=e.defineComponent({name:"MActionGroup",inheritAttrs:!1,__name:"action-group",props:Ae,emits:["action-click"],setup(t,{emit:a}){const o=t,r=a,c=e.useSlots(),f=e.useAttrs(),d=e.ref(),p=e.ref(),y=e.ref(),V=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),g=e.computed(()=>o.mode==="table"),w=e.computed(()=>g.value?"small":o.size),l=e.computed(()=>g.value?"link":"default"),u=e.computed(()=>g.value?"":o.moreText),x=e.computed(()=>o.moreIcon||F.MoreOutlined);function S(n){return n?V.value(n):!0}const K=e.computed(()=>{var n;return Ee((n=c.default)==null?void 0:n.call(c))}),D=e.shallowRef([]);function q(n){var b,v,B;const s=n.icon&&(n.icon.name||n.icon.__name)||"",i=n.component&&(n.component.name||n.component.__name)||"";return[n.key??"",n.label??"",s,i,Array.isArray(n.permission)?n.permission.join(","):n.permission??"",n.permissionAction??"",String(n.disabled??!1),String(((b=n.componentProps)==null?void 0:b.confirm)??""),String(((v=n.componentProps)==null?void 0:v.showSuccess)??""),String(((B=n.componentProps)==null?void 0:B.danger)??"")].join("|")}e.watch(()=>o.actions,n=>{if(!n){D.value=[];return}if(D.value.length!==n.length){D.value=n;return}const s=n.map(q).join("||"),i=D.value.map(q).join("||");s!==i&&(D.value=n)},{immediate:!0,deep:!1});const j=e.computed(()=>D.value.length?D.value.filter(n=>S(n.permission)):[]),C=e.computed(()=>o.actions?j.value.length:K.value.length),I=e.computed(()=>o.actions?j.value.map((n,s)=>({key:he(n,s),label:n.label||"",icon:n.icon||null,component:ke(n),props:be(n),menuProps:Be(n),handler:()=>Ce(n)})):K.value.filter(n=>{const s=n.props||{};return s.permission&&s.permissionAction==="hide"?S(s.permission):!0}).map((n,s)=>{var v,B;const i=Ne(n,s),m=e.cloneVNode(n,{type:((v=n.props)==null?void 0:v.type)??(g.value?l.value:void 0),size:((B=n.props)==null?void 0:B.size)??w.value}),b=e.cloneVNode(n,{...n.props,type:H,size:Z});return{key:i,label:"",icon:null,component:m,props:{},menuProps:{},handler:null,vnode:m,menuVnode:b}})),W=e.computed(()=>I.value.slice(0,Y.value)),$=e.computed(()=>I.value.slice(Y.value)),pe=e.computed(()=>({size:w.value,compact:o.compact,vertical:o.vertical,block:o.block,...f})),fe=e.computed(()=>({text:u.value,size:w.value,type:l.value,...o.moreProps})),O=e.ref(o.maxItems);function me(){if(!d.value||!p.value||!y.value)return Math.min(o.maxItems,C.value);const n=d.value.clientWidth,s=p.value.querySelectorAll(".measure-item");if(s.length===0)return Math.min(o.maxItems,C.value);const i=C.value,m=[];for(let h=0;h<Math.min(i,s.length);h++)m.push(s[h].offsetWidth);const b=y.value.offsetWidth??0;let v=0,B=0;for(let h=0;h<m.length;h++){const P=m[h],A=v===0?P:v+o.gap+P,E=m.length-(h+1)>0?v===0?b:o.gap+b:0;if(A+E<=n){v=A,B++;continue}break}return Math.max(0,Math.min(B,o.maxItems,i))}const L=()=>{if(o.disableCollapse){O.value=C.value;return}if(C.value<=1){O.value=C.value;return}O.value=me()},z=J.useDebounceFn(()=>{L()},_e),N=(n=!1)=>{n?(typeof z=="function"&&"cancel"in z&&z.cancel(),L()):z()};N.cancel=()=>{typeof z=="function"&&"cancel"in z&&z.cancel()};let _=null;const ye=async()=>{await e.nextTick(),L(),d.value&&typeof ResizeObserver<"u"&&(_=new ResizeObserver(n=>{n[0].contentRect.width>0&&N()}),_.observe(d.value))},ge=()=>{_&&d.value&&_.unobserve(d.value),_=null,"cancel"in N&&N.cancel()};e.onMounted(async()=>{L(),await e.nextTick(),ye()}),e.onUnmounted(()=>{ge()}),e.watch([j,C,()=>o.maxItems,()=>o.gap],async()=>{await e.nextTick(),N(!0)},{deep:!1});const Y=e.computed(()=>o.disableCollapse||C.value<=1?C.value:p.value&&y.value&&d.value?O.value:Math.min(o.maxItems,C.value)),ve=e.computed(()=>o.disableCollapse?!1:$.value.length>0);function ke(n){return n.component||M}function he(n,s){return n.key||n.label||`action-${s}`}function X(n){const{label:s,key:i,onClick:m,permission:b,permissionAction:v,icon:B,component:h,componentProps:P,slot:A,type:R,size:E,disabled:Se,...xe}=n;return{component:h,componentProps:P,type:R,size:E,rest:xe,permission:b,permissionAction:v,disabled:Se}}function be(n){const{component:s,componentProps:i,type:m,rest:b,permission:v,permissionAction:B,disabled:h}=X(n),P={type:m||l.value,size:w.value,disabled:h||!S(v)&&B==="disable",...b};if(s&&i){const A={...P,...i};return g.value&&(A.type="link"),A}return P}function Be(n){const{component:s,componentProps:i,rest:m,permission:b,permissionAction:v,disabled:B}=X(n),h={type:H,size:Z,disabled:B||!S(b)&&v==="disable",...m};if(s&&i){const{type:P,size:A,...R}=i,E={...h,...R};return E.type=H,E}return h}function Ce(n){n.onClick&&n.onClick(n),r("action-click",n)}return(n,s)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:d,class:"mtn-action-group"},[e.createVNode(e.unref(U),e.normalizeProps(e.guardReactiveProps(pe.value)),{default:e.withCtx(()=>[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(W.value,i=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({key:i.key,ref_for:!0},i.props,{onClick:i.handler}),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040,["onClick"]))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(W.value,i=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.vnode),{key:i.key}))),128)),ve.value?(e.openBlock(),e.createBlock(e.unref(G),e.normalizeProps(e.mergeProps({key:2},fe.value)),{icon:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(x.value)))]),overlay:e.withCtx(()=>[e.createVNode(e.unref(k.Menu),null,{default:e.withCtx(()=>[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList($.value,i=>(e.openBlock(),e.createBlock(e.unref(k.Menu).Item,{key:i.key},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({ref_for:!0},i.menuProps,{onClick:i.handler}),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040,["onClick"]))]),_:2},1024))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList($.value,i=>(e.openBlock(),e.createBlock(e.unref(k.Menu).Item,{key:i.key},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.menuVnode)))]),_:2},1024))),128))]),_:1})]),_:1},16)):e.createCommentVNode("",!0)]),_:1},16),e.createElementVNode("div",{ref_key:"measureRef",ref:p,class:"mtn-action-group-measure",style:e.normalizeStyle({gap:`${o.gap}px`})},[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(I.value,(i,m)=>(e.openBlock(),e.createElementBlock("span",{key:m,class:"measure-item"},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({ref_for:!0},i.props),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040))]))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(I.value,(i,m)=>(e.openBlock(),e.createElementBlock("span",{key:m,class:"measure-item"},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.vnode)))]))),128)),e.createElementVNode("span",{ref_key:"moreTriggerRef",ref:y,class:"measure-item"},[e.createVNode(e.unref(G),{text:u.value,size:w.value,type:l.value},{icon:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(x.value)))]),_:1},8,["text","size","type"])],512)],4)],512))}}),re=(t,a)=>{const o=t.__vccOpts||t;for(const[r,c]of a)o[r]=c;return o},ae=re(Me,[["__scopeId","data-v-29d941f4"]]),Ve={...te,loading:{type:Boolean,default:void 0},confirm:{type:[String,Boolean,Function],default:"确定要删除吗?"},confirmType:{type:String,default:"modal"},confirmTitle:{type:String,default:"确认删除"},okText:{type:String,default:"确定"},cancelText:{type:String,default:"取消"},hideIcon:{type:Boolean,default:!1},autoLoading:{type:Boolean,default:!0},beforeDelete:{type:Function,default:void 0},count:{type:Number,default:1},showSuccess:{type:Boolean,default:!1},successText:{type:String,default:"删除成功"},showError:{type:Boolean,default:!0},debounce:{type:Number,default:300},onDelete:{type:Function,default:void 0}},Ie=e.defineComponent({name:"MDeleteButton",inheritAttrs:!1,__name:"delete-button",props:Ve,emits:["delete","success","error"],setup(t,{emit:a}){const o=a,r=t,c=e.ref(!1),f=e.ref(null),d=e.computed(()=>r.loading!==void 0?r.loading:r.autoLoading?c.value:!1),p=e.computed(()=>typeof r.confirm=="function"?r.confirm(r.count):r.confirm);e.watch(d,l=>{f.value&&e.nextTick(()=>{var u;(u=f.value)==null||u.update({okButtonProps:{loading:l}})})},{flush:"post"}),e.onBeforeUnmount(()=>{f.value&&(f.value.destroy(),f.value=null)});const y=async()=>{try{if(r.beforeDelete&&await r.beforeDelete()===!1)return;r.autoLoading&&r.loading===void 0&&(c.value=!0);let l=!1;const u=()=>{l||(l=!0,r.autoLoading&&r.loading===void 0&&(c.value=!1))};if(r.onDelete){const x=r.onDelete(u);if(x&&typeof x.then=="function")try{const S=await x;l||u(),V(S)}catch(S){throw l||u(),S}}else o("delete",u),r.autoLoading&&r.loading===void 0&&setTimeout(()=>{l||u()},5e3)}catch(l){r.autoLoading&&r.loading===void 0&&(c.value=!1);const u=l instanceof Error?l:new Error(String(l));o("error",u),r.showError&&k.message.error(u.message||"删除失败,请重试")}},V=l=>{r.showSuccess&&k.message.success(r.successText||"删除成功"),o("success",l)},g=r.debounce>0?J.useDebounceFn(y,r.debounce):y,w=()=>{if(!p.value){g();return}if(r.confirmType==="popconfirm")return;const l=()=>{f.value=k.Modal.confirm({title:r.confirmTitle,content:p.value,okText:r.okText,cancelText:r.cancelText,okType:"danger",okButtonProps:{loading:d.value},onOk:async()=>{try{return await y(),new Promise(u=>{if(!d.value){u();return}const x=e.watch(d,S=>{S||(x(),u())})})}catch(u){throw u}},onCancel:()=>{f.value=null},afterClose:()=>{f.value=null}})};e.nextTick(l)};return(l,u)=>p.value&&l.confirmType==="popconfirm"?(e.openBlock(),e.createBlock(e.unref(k.Popconfirm),{key:0,title:p.value,"ok-text":l.okText,"cancel-text":l.cancelText,"ok-button-props":{loading:d.value,danger:!0},onConfirm:e.unref(g)},{icon:e.withCtx(()=>[e.renderSlot(l.$slots,"popconfirmIcon",{},()=>[e.createVNode(e.unref(F.ExclamationCircleOutlined),{class:"text-[--color-ant-error]"})],!0)]),default:e.withCtx(()=>[e.createVNode(e.unref(M),e.mergeProps(l.$attrs,{type:l.type,size:l.size,danger:!0,loading:d.value,disabled:l.disabled,permission:l.permission,"permission-action":l.permissionAction,class:"group"}),e.createSlots({default:e.withCtx(()=>[e.renderSlot(l.$slots,"default",{},()=>[u[0]||(u[0]=e.createTextVNode("删除",-1))],!0)]),_:2},[l.hideIcon?void 0:{name:"icon",fn:e.withCtx(()=>[e.renderSlot(l.$slots,"icon",{},()=>[e.createVNode(e.unref(F.DeleteOutlined))],!0)]),key:"0"}]),1040,["type","size","loading","disabled","permission","permission-action"])]),_:3},8,["title","ok-text","cancel-text","ok-button-props","onConfirm"])):(e.openBlock(),e.createBlock(e.unref(M),e.mergeProps({key:1},l.$attrs,{type:l.type,size:l.size,danger:!0,loading:d.value,disabled:l.disabled,permission:l.permission,"permission-action":l.permissionAction,onClick:w}),e.createSlots({default:e.withCtx(()=>[e.renderSlot(l.$slots,"default",{},()=>[u[1]||(u[1]=e.createTextVNode("删除",-1))],!0)]),_:2},[l.hideIcon?void 0:{name:"icon",fn:e.withCtx(()=>[e.renderSlot(l.$slots,"icon",{},()=>[e.createVNode(e.unref(F.DeleteOutlined))],!0)]),key:"0"}]),1040,["type","size","loading","disabled","permission","permission-action"]))}}),ie=re(Ie,[["__scopeId","data-v-a943bc19"]]);var le=(t=>(t.TEXT="text",t.TAG="tag",t.DATE="date",t.DATETIME="dateTime",t.SELECT="select",t.STATUS="status",t.CUSTOM="custom",t))(le||{}),ce=(t=>(t.LEFT="left",t.CENTER="center",t.RIGHT="right",t))(ce||{}),ue=(t=>(t.SMALL="small",t.MIDDLE="middle",t.LARGE="large",t))(ue||{}),se=(t=>(t.CHECKBOX="checkbox",t.RADIO="radio",t))(se||{}),de=(t=>(t.LEFT="left",t.RIGHT="right",t))(de||{});const Oe=[M,U,G,ae,ie,ee,k.Table],Le={install(t){Oe.forEach(a=>{const o=a.name||a.__name;if(o){const r=t._context.components;(!r||!r[o])&&t.component(o,a)}})}};Object.defineProperty(exports,"Table",{enumerable:!0,get:()=>k.Table});exports.ActionGroup=ae;exports.Button=M;exports.ButtonGroup=U;exports.ButtonPositionEnum=de;exports.DeleteButton=ie;exports.DropdownButton=G;exports.TableColumnAlignEnum=ce;exports.TableColumnTypeEnum=le;exports.TableSelectionTypeEnum=se;exports.TableSizeEnum=ue;exports.Tag=ee;exports.buttonGroupProps=oe;exports.default=Le;exports.tagProps=Q;
|
|
1
|
+
require("./components.css");
|
|
2
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),k=require("ant-design-vue"),T=require("@mtn-ui/shared"),J=require("@vueuse/core"),F=require("@ant-design/icons-vue"),Pe=require("class-variance-authority"),Q={type:{type:String,default:"default"},color:{type:String}},Te=Pe.cva("inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border transition-colors",{variants:{type:{default:"bg-gray-100 text-gray-800 border-gray-200",success:"bg-green-100 text-green-800 border-green-200",processing:"bg-blue-100 text-blue-800 border-blue-200",error:"bg-red-100 text-red-800 border-red-200",warning:"bg-orange-100 text-orange-800 border-orange-200"}},defaultVariants:{type:"default"}}),we=e.defineComponent({name:"MTag",props:Q,setup(t,{slots:a,attrs:o}){return()=>{var c;const{type:r}=t;return e.createVNode("span",{class:T.cn(Te({type:r}),o.class)},[(c=a.default)==null?void 0:c.call(a)])}}}),ee=T.withInstall(we),te={type:{type:String,default:"default"},size:{type:String,default:"middle"},loading:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},danger:{type:Boolean,default:!1},block:{type:Boolean,default:!1},ghost:{type:Boolean,default:!1},shape:{type:String,default:"default"},htmlType:{type:String,default:"button"},icon:{type:Object},permission:{type:[String,Array],default:void 0},permissionAction:{type:String,default:"hide"}};function ne(t){const{permission:a,permissionAction:o="hide"}=t,r=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),c=e.computed(()=>a?r.value(a):!0),f=e.computed(()=>!c.value&&o==="hide"),d=e.computed(()=>!c.value&&o==="disable");return{hasPermission:c,shouldHide:f,shouldDisable:d}}function De(t,a){return t.map(o=>{if(!o||o.type==="divider"||!o.permission)return o;if(!a(o.permission)){const c=o.permissionAction||"hide";if(c==="hide")return null;if(c==="disable")return{...o,disabled:!0}}return o}).filter(Boolean)}const M=e.defineComponent({name:"MButton",props:te,emits:["click"],setup(t,{slots:a,attrs:o,emit:r}){const{shouldHide:c,shouldDisable:f}=ne({permission:t.permission,permissionAction:t.permissionAction}),d=p=>{r("click",p)};return()=>c.value?null:e.createVNode(k.Button,e.mergeProps({type:t.type,size:t.size,loading:t.loading,disabled:t.disabled||f.value,danger:t.danger,block:t.block,ghost:t.ghost,shape:t.shape,htmlType:t.htmlType,icon:t.icon},o,{class:["mtn-button",o.class],onClick:d}),{default:()=>{var p;return(p=a.default)==null?void 0:p.call(a)},icon:()=>{var p;return(p=a.icon)==null?void 0:p.call(a)}})}}),oe={size:{type:String,default:"middle"},compact:{type:Boolean,default:!0},gap:{type:[Number,String],default:8},vertical:{type:Boolean,default:!1},block:{type:Boolean,default:!1}},U=e.defineComponent({name:"MButtonGroup",props:oe,setup(t,{slots:a,attrs:o}){return()=>e.createVNode(e.Fragment,null,[t.compact?e.createVNode(k.Space.Compact,e.mergeProps({size:t.size,direction:t.vertical?"vertical":"horizontal",block:t.block},o,{class:["mtn-button-group","mtn-button-group--compact",o.class]}),{default:()=>{var r;return[(r=a.default)==null?void 0:r.call(a)]}}):e.createVNode(k.Space,e.mergeProps({size:typeof t.gap=="number"?t.gap:parseInt(t.gap)||8,direction:t.vertical?"vertical":"horizontal"},o,{class:["mtn-button-group","mtn-button-group--normal",o.class]}),{default:()=>{var r;return[(r=a.default)==null?void 0:r.call(a)]}})])}}),ze={text:{type:String,default:"Dropdown"},type:{type:String,default:"default"},size:{type:String,default:"middle"},menu:{type:Array,default:void 0},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},danger:{type:Boolean,default:!1},placement:{type:String,default:"bottomLeft"},trigger:{type:Array,default:()=>["click"]},permission:{type:[String,Array],default:void 0},permissionAction:{type:String,default:"hide"}},G=e.defineComponent({name:"MDropdownButton",props:ze,emits:["click"],setup(t,{slots:a,attrs:o,emit:r}){const{shouldHide:c,shouldDisable:f}=ne({permission:t.permission,permissionAction:t.permissionAction}),d=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),p=y=>{r("click",y)};return()=>{if(c.value)return null;const y={};if(a.overlay)y.overlay=a.overlay;else if(t.menu&&t.menu.length>0){const g=De(t.menu,d.value);y.overlay=()=>e.h(k.Menu,{items:g})}return a.icon&&(y.icon=a.icon),!(a.default||t.text)?e.createVNode(k.Dropdown,e.mergeProps({placement:t.placement,trigger:t.trigger},o,{class:["mtn-dropdown-button",o.class]}),{default:()=>[e.createVNode(k.Button,{type:t.type,size:t.size==="middle"?void 0:t.size,disabled:t.disabled||f.value,loading:t.loading,danger:t.danger,onClick:p},{default:()=>{var g;return[(g=a.icon)==null?void 0:g.call(a)]}})],...y}):e.createVNode(k.Dropdown.Button,e.mergeProps({type:t.type,size:t.size==="middle"?void 0:t.size,disabled:t.disabled||f.value,loading:t.loading,danger:t.danger,placement:t.placement,trigger:t.trigger},o,{class:["mtn-dropdown-button",o.class],onClick:p}),{default:()=>{var g;return[((g=a.default)==null?void 0:g.call(a))||t.text]},...y})}}}),Ae={actions:{type:Array,default:void 0},mode:{type:String,default:"default"},maxItems:{type:Number,default:3},gap:{type:Number,default:8},moreText:{type:String,default:"更多"},moreIcon:{type:Object,default:void 0},moreProps:{type:Object,default:()=>({})},size:{type:String,default:"middle"},compact:{type:Boolean,default:!1},vertical:{type:Boolean,default:!1},block:{type:Boolean,default:!1},disableCollapse:{type:Boolean,default:!1}};function Ee(t){return t?t.filter(a=>a.type!==e.Comment&&a.type!==e.Text&&a.type!==Symbol.for("v-fgt")):[]}function Ne(t,a){var o,r;if(t.key!==null&&t.key!==void 0)return typeof t.key=="symbol"?t.key.toString():t.key;if(((o=t.props)==null?void 0:o.key)!==null&&((r=t.props)==null?void 0:r.key)!==void 0){const c=t.props.key;return typeof c=="symbol"?c.toString():c}return`button-${a}`}const H="link",Z="small",_e=150,Me=e.defineComponent({name:"MActionGroup",inheritAttrs:!1,__name:"action-group",props:Ae,emits:["action-click"],setup(t,{emit:a}){const o=t,r=a,c=e.useSlots(),f=e.useAttrs(),d=e.ref(),p=e.ref(),y=e.ref(),V=e.inject(T.PERMISSION_CHECKER_KEY,e.ref(T.defaultPermissionChecker)),g=e.computed(()=>o.mode==="table"),w=e.computed(()=>g.value?"small":o.size),l=e.computed(()=>g.value?"link":"default"),u=e.computed(()=>g.value?"":o.moreText),x=e.computed(()=>o.moreIcon||F.MoreOutlined);function S(n){return n?V.value(n):!0}const K=e.computed(()=>{var n;return Ee((n=c.default)==null?void 0:n.call(c))}),D=e.shallowRef([]);function q(n){var b,v,B;const s=n.icon&&(n.icon.name||n.icon.__name)||"",i=n.component&&(n.component.name||n.component.__name)||"";return[n.key??"",n.label??"",s,i,Array.isArray(n.permission)?n.permission.join(","):n.permission??"",n.permissionAction??"",String(n.disabled??!1),String(((b=n.componentProps)==null?void 0:b.confirm)??""),String(((v=n.componentProps)==null?void 0:v.showSuccess)??""),String(((B=n.componentProps)==null?void 0:B.danger)??"")].join("|")}e.watch(()=>o.actions,n=>{if(!n){D.value=[];return}if(D.value.length!==n.length){D.value=n;return}const s=n.map(q).join("||"),i=D.value.map(q).join("||");s!==i&&(D.value=n)},{immediate:!0,deep:!1});const j=e.computed(()=>D.value.length?D.value.filter(n=>S(n.permission)):[]),C=e.computed(()=>o.actions?j.value.length:K.value.length),I=e.computed(()=>o.actions?j.value.map((n,s)=>({key:he(n,s),label:n.label||"",icon:n.icon||null,component:ke(n),props:be(n),menuProps:Be(n),handler:()=>Ce(n)})):K.value.filter(n=>{const s=n.props||{};return s.permission&&s.permissionAction==="hide"?S(s.permission):!0}).map((n,s)=>{var v,B;const i=Ne(n,s),m=e.cloneVNode(n,{type:((v=n.props)==null?void 0:v.type)??(g.value?l.value:void 0),size:((B=n.props)==null?void 0:B.size)??w.value}),b=e.cloneVNode(n,{...n.props,type:H,size:Z});return{key:i,label:"",icon:null,component:m,props:{},menuProps:{},handler:null,vnode:m,menuVnode:b}})),W=e.computed(()=>I.value.slice(0,Y.value)),$=e.computed(()=>I.value.slice(Y.value)),pe=e.computed(()=>({size:w.value,compact:o.compact,vertical:o.vertical,block:o.block,...f})),fe=e.computed(()=>({text:u.value,size:w.value,type:l.value,...o.moreProps})),O=e.ref(o.maxItems);function me(){if(!d.value||!p.value||!y.value)return Math.min(o.maxItems,C.value);const n=d.value.clientWidth,s=p.value.querySelectorAll(".measure-item");if(s.length===0)return Math.min(o.maxItems,C.value);const i=C.value,m=[];for(let h=0;h<Math.min(i,s.length);h++)m.push(s[h].offsetWidth);const b=y.value.offsetWidth??0;let v=0,B=0;for(let h=0;h<m.length;h++){const P=m[h],A=v===0?P:v+o.gap+P,E=m.length-(h+1)>0?v===0?b:o.gap+b:0;if(A+E<=n){v=A,B++;continue}break}return Math.max(0,Math.min(B,o.maxItems,i))}const L=()=>{if(o.disableCollapse){O.value=C.value;return}if(C.value<=1){O.value=C.value;return}O.value=me()},z=J.useDebounceFn(()=>{L()},_e),N=(n=!1)=>{n?(typeof z=="function"&&"cancel"in z&&z.cancel(),L()):z()};N.cancel=()=>{typeof z=="function"&&"cancel"in z&&z.cancel()};let _=null;const ye=async()=>{await e.nextTick(),L(),d.value&&typeof ResizeObserver<"u"&&(_=new ResizeObserver(n=>{n[0].contentRect.width>0&&N()}),_.observe(d.value))},ge=()=>{_&&d.value&&_.unobserve(d.value),_=null,"cancel"in N&&N.cancel()};e.onMounted(async()=>{L(),await e.nextTick(),ye()}),e.onUnmounted(()=>{ge()}),e.watch([j,C,()=>o.maxItems,()=>o.gap],async()=>{await e.nextTick(),N(!0)},{deep:!1});const Y=e.computed(()=>o.disableCollapse||C.value<=1?C.value:p.value&&y.value&&d.value?O.value:Math.min(o.maxItems,C.value)),ve=e.computed(()=>o.disableCollapse?!1:$.value.length>0);function ke(n){return n.component||M}function he(n,s){return n.key||n.label||`action-${s}`}function X(n){const{label:s,key:i,onClick:m,permission:b,permissionAction:v,icon:B,component:h,componentProps:P,slot:A,type:R,size:E,disabled:Se,...xe}=n;return{component:h,componentProps:P,type:R,size:E,rest:xe,permission:b,permissionAction:v,disabled:Se}}function be(n){const{component:s,componentProps:i,type:m,rest:b,permission:v,permissionAction:B,disabled:h}=X(n),P={type:m||l.value,size:w.value,disabled:h||!S(v)&&B==="disable",...b};if(s&&i){const A={...P,...i};return g.value&&(A.type="link"),A}return P}function Be(n){const{component:s,componentProps:i,rest:m,permission:b,permissionAction:v,disabled:B}=X(n),h={type:H,size:Z,disabled:B||!S(b)&&v==="disable",...m};if(s&&i){const{type:P,size:A,...R}=i,E={...h,...R};return E.type=H,E}return h}function Ce(n){n.onClick&&n.onClick(n),r("action-click",n)}return(n,s)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerRef",ref:d,class:"mtn-action-group"},[e.createVNode(e.unref(U),e.normalizeProps(e.guardReactiveProps(pe.value)),{default:e.withCtx(()=>[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(W.value,i=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({key:i.key,ref_for:!0},i.props,{onClick:i.handler}),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040,["onClick"]))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(W.value,i=>(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.vnode),{key:i.key}))),128)),ve.value?(e.openBlock(),e.createBlock(e.unref(G),e.normalizeProps(e.mergeProps({key:2},fe.value)),{icon:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(x.value)))]),overlay:e.withCtx(()=>[e.createVNode(e.unref(k.Menu),null,{default:e.withCtx(()=>[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList($.value,i=>(e.openBlock(),e.createBlock(e.unref(k.Menu).Item,{key:i.key},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({ref_for:!0},i.menuProps,{onClick:i.handler}),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040,["onClick"]))]),_:2},1024))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList($.value,i=>(e.openBlock(),e.createBlock(e.unref(k.Menu).Item,{key:i.key},{default:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.menuVnode)))]),_:2},1024))),128))]),_:1})]),_:1},16)):e.createCommentVNode("",!0)]),_:1},16),e.createElementVNode("div",{ref_key:"measureRef",ref:p,class:"mtn-action-group-measure",style:e.normalizeStyle({gap:`${o.gap}px`})},[o.actions?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(I.value,(i,m)=>(e.openBlock(),e.createElementBlock("span",{key:m,class:"measure-item"},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.component),e.mergeProps({ref_for:!0},i.props),e.createSlots({default:e.withCtx(()=>[e.createTextVNode(" "+e.toDisplayString(i.label),1)]),_:2},[i.icon?{name:"icon",fn:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.icon)))]),key:"0"}:void 0]),1040))]))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(I.value,(i,m)=>(e.openBlock(),e.createElementBlock("span",{key:m,class:"measure-item"},[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(i.vnode)))]))),128)),e.createElementVNode("span",{ref_key:"moreTriggerRef",ref:y,class:"measure-item"},[e.createVNode(e.unref(G),{text:u.value,size:w.value,type:l.value},{icon:e.withCtx(()=>[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(x.value)))]),_:1},8,["text","size","type"])],512)],4)],512))}}),re=(t,a)=>{const o=t.__vccOpts||t;for(const[r,c]of a)o[r]=c;return o},ae=re(Me,[["__scopeId","data-v-29d941f4"]]),Ve={...te,loading:{type:Boolean,default:void 0},confirm:{type:[String,Boolean,Function],default:"确定要删除吗?"},confirmType:{type:String,default:"modal"},confirmTitle:{type:String,default:"确认删除"},okText:{type:String,default:"确定"},cancelText:{type:String,default:"取消"},hideIcon:{type:Boolean,default:!1},autoLoading:{type:Boolean,default:!0},beforeDelete:{type:Function,default:void 0},count:{type:Number,default:1},showSuccess:{type:Boolean,default:!1},successText:{type:String,default:"删除成功"},showError:{type:Boolean,default:!0},debounce:{type:Number,default:300},onDelete:{type:Function,default:void 0}},Ie=e.defineComponent({name:"MDeleteButton",inheritAttrs:!1,__name:"delete-button",props:Ve,emits:["delete","success","error"],setup(t,{emit:a}){const o=a,r=t,c=e.ref(!1),f=e.ref(null),d=e.computed(()=>r.loading!==void 0?r.loading:r.autoLoading?c.value:!1),p=e.computed(()=>typeof r.confirm=="function"?r.confirm(r.count):r.confirm);e.watch(d,l=>{f.value&&e.nextTick(()=>{var u;(u=f.value)==null||u.update({okButtonProps:{loading:l}})})},{flush:"post"}),e.onBeforeUnmount(()=>{f.value&&(f.value.destroy(),f.value=null)});const y=async()=>{try{if(r.beforeDelete&&await r.beforeDelete()===!1)return;r.autoLoading&&r.loading===void 0&&(c.value=!0);let l=!1;const u=()=>{l||(l=!0,r.autoLoading&&r.loading===void 0&&(c.value=!1))};if(r.onDelete){const x=r.onDelete(u);if(x&&typeof x.then=="function")try{const S=await x;l||u(),V(S)}catch(S){throw l||u(),S}}else o("delete",u),r.autoLoading&&r.loading===void 0&&setTimeout(()=>{l||u()},5e3)}catch(l){r.autoLoading&&r.loading===void 0&&(c.value=!1);const u=l instanceof Error?l:new Error(String(l));o("error",u),r.showError&&k.message.error(u.message||"删除失败,请重试")}},V=l=>{r.showSuccess&&k.message.success(r.successText||"删除成功"),o("success",l)},g=r.debounce>0?J.useDebounceFn(y,r.debounce):y,w=()=>{if(!p.value){g();return}if(r.confirmType==="popconfirm")return;const l=()=>{f.value=k.Modal.confirm({title:r.confirmTitle,content:p.value,okText:r.okText,cancelText:r.cancelText,okType:"danger",okButtonProps:{loading:d.value},onOk:async()=>{try{return await y(),new Promise(u=>{if(!d.value){u();return}const x=e.watch(d,S=>{S||(x(),u())})})}catch(u){throw u}},onCancel:()=>{f.value=null},afterClose:()=>{f.value=null}})};e.nextTick(l)};return(l,u)=>p.value&&l.confirmType==="popconfirm"?(e.openBlock(),e.createBlock(e.unref(k.Popconfirm),{key:0,title:p.value,"ok-text":l.okText,"cancel-text":l.cancelText,"ok-button-props":{loading:d.value,danger:!0},onConfirm:e.unref(g)},{icon:e.withCtx(()=>[e.renderSlot(l.$slots,"popconfirmIcon",{},()=>[e.createVNode(e.unref(F.ExclamationCircleOutlined),{class:"text-[--color-ant-error]"})],!0)]),default:e.withCtx(()=>[e.createVNode(e.unref(M),e.mergeProps(l.$attrs,{type:l.type,size:l.size,danger:!0,loading:d.value,disabled:l.disabled,permission:l.permission,"permission-action":l.permissionAction,class:"group"}),e.createSlots({default:e.withCtx(()=>[e.renderSlot(l.$slots,"default",{},()=>[u[0]||(u[0]=e.createTextVNode("删除",-1))],!0)]),_:2},[l.hideIcon?void 0:{name:"icon",fn:e.withCtx(()=>[e.renderSlot(l.$slots,"icon",{},()=>[e.createVNode(e.unref(F.DeleteOutlined))],!0)]),key:"0"}]),1040,["type","size","loading","disabled","permission","permission-action"])]),_:3},8,["title","ok-text","cancel-text","ok-button-props","onConfirm"])):(e.openBlock(),e.createBlock(e.unref(M),e.mergeProps({key:1},l.$attrs,{type:l.type,size:l.size,danger:!0,loading:d.value,disabled:l.disabled,permission:l.permission,"permission-action":l.permissionAction,onClick:w}),e.createSlots({default:e.withCtx(()=>[e.renderSlot(l.$slots,"default",{},()=>[u[1]||(u[1]=e.createTextVNode("删除",-1))],!0)]),_:2},[l.hideIcon?void 0:{name:"icon",fn:e.withCtx(()=>[e.renderSlot(l.$slots,"icon",{},()=>[e.createVNode(e.unref(F.DeleteOutlined))],!0)]),key:"0"}]),1040,["type","size","loading","disabled","permission","permission-action"]))}}),ie=re(Ie,[["__scopeId","data-v-a943bc19"]]);var le=(t=>(t.TEXT="text",t.TAG="tag",t.DATE="date",t.DATETIME="dateTime",t.SELECT="select",t.STATUS="status",t.CUSTOM="custom",t))(le||{}),ce=(t=>(t.LEFT="left",t.CENTER="center",t.RIGHT="right",t))(ce||{}),ue=(t=>(t.SMALL="small",t.MIDDLE="middle",t.LARGE="large",t))(ue||{}),se=(t=>(t.CHECKBOX="checkbox",t.RADIO="radio",t))(se||{}),de=(t=>(t.LEFT="left",t.RIGHT="right",t))(de||{});const Oe=[M,U,G,ae,ie,ee,k.Table],Le={install(t){Oe.forEach(a=>{const o=a.name||a.__name;if(o){const r=t._context.components;(!r||!r[o])&&t.component(o,a)}})}};Object.defineProperty(exports,"Table",{enumerable:!0,get:()=>k.Table});exports.ActionGroup=ae;exports.Button=M;exports.ButtonGroup=U;exports.ButtonPositionEnum=de;exports.DeleteButton=ie;exports.DropdownButton=G;exports.TableColumnAlignEnum=ce;exports.TableColumnTypeEnum=le;exports.TableSelectionTypeEnum=se;exports.TableSizeEnum=ue;exports.Tag=ee;exports.buttonGroupProps=oe;exports.default=Le;exports.tagProps=Q;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import m from "./antd-wrapped/button/button.js";
|
|
3
|
-
import p from "./antd-wrapped/button-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import f from "./antd-wrapped/delete-button/delete-button.vue.js";
|
|
1
|
+
import e from "./antd-wrapped/button/button.js";
|
|
2
|
+
import m from "./antd-wrapped/button-group/button-group.js";
|
|
3
|
+
import p from "./antd-wrapped/dropdown-button/dropdown-button.js";
|
|
4
|
+
import i from "./antd-wrapped/action-group/action-group.vue.js";
|
|
5
|
+
import u from "./antd-wrapped/delete-button/delete-button.vue.js";
|
|
6
|
+
import { Tag as f } from "./data-display/tag/index.js";
|
|
8
7
|
import { Table as a } from "ant-design-vue";
|
|
9
|
-
import { Table as
|
|
10
|
-
import { ButtonPositionEnum as
|
|
11
|
-
import { tagProps as
|
|
12
|
-
|
|
8
|
+
import { Table as G } from "ant-design-vue";
|
|
9
|
+
import { ButtonPositionEnum as _, TableColumnAlignEnum as y, TableColumnTypeEnum as A, TableSelectionTypeEnum as D, TableSizeEnum as S } from "./antd-wrapped/table/table.js";
|
|
10
|
+
import { tagProps as w } from "./data-display/tag/props.js";
|
|
11
|
+
import { buttonGroupProps as j } from "./antd-wrapped/button-group/props.js";
|
|
12
|
+
const l = [e, m, p, i, u, f, a], d = {
|
|
13
13
|
install(n) {
|
|
14
14
|
l.forEach((o) => {
|
|
15
15
|
const t = o.name || o.__name;
|
|
@@ -21,19 +21,19 @@ const l = [m, p, i, u, f, e, a], d = {
|
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
export {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
i as ActionGroup,
|
|
25
|
+
e as Button,
|
|
26
|
+
m as ButtonGroup,
|
|
27
|
+
_ as ButtonPositionEnum,
|
|
28
|
+
u as DeleteButton,
|
|
29
|
+
p as DropdownButton,
|
|
30
|
+
G as Table,
|
|
31
|
+
y as TableColumnAlignEnum,
|
|
32
|
+
A as TableColumnTypeEnum,
|
|
33
|
+
D as TableSelectionTypeEnum,
|
|
34
|
+
S as TableSizeEnum,
|
|
35
|
+
f as Tag,
|
|
36
|
+
j as buttonGroupProps,
|
|
37
37
|
d as default,
|
|
38
|
-
|
|
38
|
+
w as tagProps
|
|
39
39
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { defineComponent as G, createVNode as B, inject as
|
|
3
|
-
import {
|
|
4
|
-
import { Button as ze, Space as be, Dropdown as ke, Menu as Q, Popconfirm as ot, message as he, Modal as rt, Table as at } from "ant-design-vue";
|
|
1
|
+
import "./components.css";
|
|
2
|
+
import { defineComponent as G, createVNode as B, inject as le, ref as M, computed as p, mergeProps as x, Fragment as R, h as Ue, Comment as je, Text as Fe, useSlots as He, useAttrs as Ke, shallowRef as We, watch as ee, cloneVNode as ye, onMounted as Ye, nextTick as H, onUnmounted as Xe, createElementBlock as I, openBlock as s, createElementVNode as ge, unref as P, normalizeProps as ve, guardReactiveProps as qe, withCtx as m, createBlock as h, createCommentVNode as Ze, renderList as $, resolveDynamicComponent as A, createSlots as K, createTextVNode as W, toDisplayString as re, normalizeStyle as Je, onBeforeUnmount as Qe, renderSlot as F } from "vue";
|
|
3
|
+
import { Button as ze, Space as be, Dropdown as ke, Menu as Q, Popconfirm as et, message as he, Modal as tt, Table as nt } from "ant-design-vue";
|
|
5
4
|
import { Table as Vt } from "ant-design-vue";
|
|
5
|
+
import { cn as ot, withInstall as rt, PERMISSION_CHECKER_KEY as se, defaultPermissionChecker as ue } from "@mtn-ui/shared";
|
|
6
6
|
import { useDebounceFn as Ce } from "@vueuse/core";
|
|
7
|
-
import { MoreOutlined as
|
|
7
|
+
import { MoreOutlined as at, DeleteOutlined as Se, ExclamationCircleOutlined as it } from "@ant-design/icons-vue";
|
|
8
|
+
import { cva as lt } from "class-variance-authority";
|
|
8
9
|
const st = {
|
|
9
10
|
type: {
|
|
10
11
|
type: String,
|
|
@@ -13,7 +14,7 @@ const st = {
|
|
|
13
14
|
color: {
|
|
14
15
|
type: String
|
|
15
16
|
}
|
|
16
|
-
}, ut =
|
|
17
|
+
}, ut = lt("inline-flex items-center px-2 py-0.5 rounded text-xs font-medium border transition-colors", {
|
|
17
18
|
variants: {
|
|
18
19
|
type: {
|
|
19
20
|
default: "bg-gray-100 text-gray-800 border-gray-200",
|
|
@@ -39,13 +40,13 @@ const st = {
|
|
|
39
40
|
type: o
|
|
40
41
|
} = e;
|
|
41
42
|
return B("span", {
|
|
42
|
-
class:
|
|
43
|
+
class: ot(ut({
|
|
43
44
|
type: o
|
|
44
45
|
}), n.class)
|
|
45
46
|
}, [(l = r.default) == null ? void 0 : l.call(r)]);
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
|
-
}), dt =
|
|
49
|
+
}), dt = rt(ct), Pe = {
|
|
49
50
|
// 按钮类型
|
|
50
51
|
type: {
|
|
51
52
|
type: String,
|
|
@@ -107,7 +108,7 @@ const st = {
|
|
|
107
108
|
}
|
|
108
109
|
};
|
|
109
110
|
function Te(e) {
|
|
110
|
-
const { permission: r, permissionAction: n = "hide" } = e, o =
|
|
111
|
+
const { permission: r, permissionAction: n = "hide" } = e, o = le(se, M(ue)), l = p(() => r ? o.value(r) : !0), y = p(() => !l.value && n === "hide"), d = p(() => !l.value && n === "disable");
|
|
111
112
|
return {
|
|
112
113
|
hasPermission: l,
|
|
113
114
|
shouldHide: y,
|
|
@@ -304,7 +305,7 @@ const te = /* @__PURE__ */ G({
|
|
|
304
305
|
} = Te({
|
|
305
306
|
permission: e.permission,
|
|
306
307
|
permissionAction: e.permissionAction
|
|
307
|
-
}), d =
|
|
308
|
+
}), d = le(se, M(ue)), f = (v) => {
|
|
308
309
|
o("click", v);
|
|
309
310
|
};
|
|
310
311
|
return () => {
|
|
@@ -315,7 +316,7 @@ const te = /* @__PURE__ */ G({
|
|
|
315
316
|
v.overlay = r.overlay;
|
|
316
317
|
else if (e.menu && e.menu.length > 0) {
|
|
317
318
|
const b = ft(e.menu, d.value);
|
|
318
|
-
v.overlay = () =>
|
|
319
|
+
v.overlay = () => Ue(Q, {
|
|
319
320
|
items: b
|
|
320
321
|
});
|
|
321
322
|
}
|
|
@@ -450,7 +451,7 @@ const te = /* @__PURE__ */ G({
|
|
|
450
451
|
};
|
|
451
452
|
function gt(e) {
|
|
452
453
|
return e ? e.filter(
|
|
453
|
-
(r) => r.type !==
|
|
454
|
+
(r) => r.type !== je && r.type !== Fe && r.type !== Symbol.for("v-fgt")
|
|
454
455
|
) : [];
|
|
455
456
|
}
|
|
456
457
|
function vt(e, r) {
|
|
@@ -470,14 +471,14 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
470
471
|
props: yt,
|
|
471
472
|
emits: ["action-click"],
|
|
472
473
|
setup(e, { emit: r }) {
|
|
473
|
-
const n = e, o = r, l =
|
|
474
|
+
const n = e, o = r, l = He(), y = Ke(), d = M(), f = M(), v = M(), Y = le(se, M(ue)), b = p(() => n.mode === "table"), E = p(() => b.value ? "small" : n.size), i = p(() => b.value ? "link" : "default"), u = p(() => b.value ? "" : n.moreText), w = p(() => n.moreIcon || at);
|
|
474
475
|
function _(t) {
|
|
475
476
|
return t ? Y.value(t) : !0;
|
|
476
477
|
}
|
|
477
478
|
const ce = p(() => {
|
|
478
479
|
var t;
|
|
479
480
|
return gt((t = l.default) == null ? void 0 : t.call(l));
|
|
480
|
-
}), O =
|
|
481
|
+
}), O = We([]);
|
|
481
482
|
function de(t) {
|
|
482
483
|
var z, k, C;
|
|
483
484
|
const c = t.icon && (t.icon.name || t.icon.__name) || "", a = t.component && (t.component.name || t.component.__name) || "";
|
|
@@ -606,9 +607,9 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
606
607
|
}, De = () => {
|
|
607
608
|
j && d.value && j.unobserve(d.value), j = null, "cancel" in U && U.cancel();
|
|
608
609
|
};
|
|
609
|
-
|
|
610
|
+
Ye(async () => {
|
|
610
611
|
Z(), await H(), Me();
|
|
611
|
-
}),
|
|
612
|
+
}), Xe(() => {
|
|
612
613
|
De();
|
|
613
614
|
}), ee(
|
|
614
615
|
[ne, T, () => n.maxItems, () => n.gap],
|
|
@@ -685,7 +686,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
685
686
|
ref: d,
|
|
686
687
|
class: "mtn-action-group"
|
|
687
688
|
}, [
|
|
688
|
-
B(P(Ae), ve(
|
|
689
|
+
B(P(Ae), ve(qe(_e.value)), {
|
|
689
690
|
default: m(() => [
|
|
690
691
|
n.actions ? (s(!0), I(R, { key: 0 }, $(fe.value, (a) => (s(), h(A(a.component), x({
|
|
691
692
|
key: a.key,
|
|
@@ -750,7 +751,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
750
751
|
})
|
|
751
752
|
]),
|
|
752
753
|
_: 1
|
|
753
|
-
}, 16)) :
|
|
754
|
+
}, 16)) : Ze("", !0)
|
|
754
755
|
]),
|
|
755
756
|
_: 1
|
|
756
757
|
}, 16),
|
|
@@ -758,7 +759,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
758
759
|
ref_key: "measureRef",
|
|
759
760
|
ref: f,
|
|
760
761
|
class: "mtn-action-group-measure",
|
|
761
|
-
style:
|
|
762
|
+
style: Je({ gap: `${n.gap}px` })
|
|
762
763
|
}, [
|
|
763
764
|
n.actions ? (s(!0), I(R, { key: 0 }, $(X.value, (a, g) => (s(), I("span", {
|
|
764
765
|
key: g,
|
|
@@ -901,7 +902,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
901
902
|
okButtonProps: { loading: i }
|
|
902
903
|
});
|
|
903
904
|
});
|
|
904
|
-
}, { flush: "post" }),
|
|
905
|
+
}, { flush: "post" }), Qe(() => {
|
|
905
906
|
y.value && (y.value.destroy(), y.value = null);
|
|
906
907
|
});
|
|
907
908
|
const v = async () => {
|
|
@@ -940,7 +941,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
940
941
|
}
|
|
941
942
|
if (o.confirmType === "popconfirm") return;
|
|
942
943
|
H(() => {
|
|
943
|
-
y.value =
|
|
944
|
+
y.value = tt.confirm({
|
|
944
945
|
title: o.confirmTitle,
|
|
945
946
|
content: f.value,
|
|
946
947
|
okText: o.okText,
|
|
@@ -971,7 +972,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
971
972
|
});
|
|
972
973
|
});
|
|
973
974
|
};
|
|
974
|
-
return (i, u) => f.value && i.confirmType === "popconfirm" ? (s(), h(P(
|
|
975
|
+
return (i, u) => f.value && i.confirmType === "popconfirm" ? (s(), h(P(et), {
|
|
975
976
|
key: 0,
|
|
976
977
|
title: f.value,
|
|
977
978
|
"ok-text": i.okText,
|
|
@@ -981,7 +982,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
981
982
|
}, {
|
|
982
983
|
icon: m(() => [
|
|
983
984
|
F(i.$slots, "popconfirmIcon", {}, () => [
|
|
984
|
-
B(P(
|
|
985
|
+
B(P(it), { class: "text-[--color-ant-error]" })
|
|
985
986
|
], !0)
|
|
986
987
|
]),
|
|
987
988
|
default: m(() => [
|
|
@@ -1044,7 +1045,7 @@ const ae = "link", Be = "small", bt = 150, kt = /* @__PURE__ */ G({
|
|
|
1044
1045
|
}
|
|
1045
1046
|
}), zt = /* @__PURE__ */ xe(Bt, [["__scopeId", "data-v-a943bc19"]]);
|
|
1046
1047
|
var Ct = /* @__PURE__ */ ((e) => (e.TEXT = "text", e.TAG = "tag", e.DATE = "date", e.DATETIME = "dateTime", e.SELECT = "select", e.STATUS = "status", e.CUSTOM = "custom", e))(Ct || {}), Pt = /* @__PURE__ */ ((e) => (e.LEFT = "left", e.CENTER = "center", e.RIGHT = "right", e))(Pt || {}), Tt = /* @__PURE__ */ ((e) => (e.SMALL = "small", e.MIDDLE = "middle", e.LARGE = "large", e))(Tt || {}), At = /* @__PURE__ */ ((e) => (e.CHECKBOX = "checkbox", e.RADIO = "radio", e))(At || {}), xt = /* @__PURE__ */ ((e) => (e.LEFT = "left", e.RIGHT = "right", e))(xt || {});
|
|
1047
|
-
const _t = [te, Ae, ie, ht, zt, dt,
|
|
1048
|
+
const _t = [te, Ae, ie, ht, zt, dt, nt], Lt = {
|
|
1048
1049
|
install(e) {
|
|
1049
1050
|
_t.forEach((r) => {
|
|
1050
1051
|
const n = r.name || r.__name;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ import { App } from 'vue';
|
|
|
9
9
|
* - navigation: 导航组件(待添加)
|
|
10
10
|
* - data-entry: 数据录入组件(待添加)
|
|
11
11
|
* - feedback: 反馈组件(待添加)
|
|
12
|
+
*
|
|
13
|
+
* 注意:使用组件前需要导入样式文件:
|
|
14
|
+
* import '@mtn-ui/components/style'
|
|
15
|
+
* 或
|
|
16
|
+
* import '@mtn-ui/components/dist/components.css'
|
|
12
17
|
*/
|
|
13
18
|
export * from './packages/components/src/data-display';
|
|
14
19
|
export * from './packages/components/src/antd-wrapped';
|
|
@@ -9,6 +9,11 @@ import { App } from 'vue';
|
|
|
9
9
|
* - navigation: 导航组件(待添加)
|
|
10
10
|
* - data-entry: 数据录入组件(待添加)
|
|
11
11
|
* - feedback: 反馈组件(待添加)
|
|
12
|
+
*
|
|
13
|
+
* 注意:使用组件前需要导入样式文件:
|
|
14
|
+
* import '@mtn-ui/components/style'
|
|
15
|
+
* 或
|
|
16
|
+
* import '@mtn-ui/components/dist/components.css'
|
|
12
17
|
*/
|
|
13
18
|
export * from './data-display';
|
|
14
19
|
export * from './antd-wrapped';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtn-ui/components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core components for mtn-ui",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"**/*.css",
|
|
26
|
+
"dist/components.css"
|
|
27
|
+
],
|
|
24
28
|
"scripts": {
|
|
25
|
-
"build": "vite build && node scripts/fix-types.js",
|
|
29
|
+
"build": "vite build && node scripts/fix-types.js && node scripts/fix-css-import.js",
|
|
26
30
|
"dev": "vite build --watch",
|
|
27
31
|
"test": "vitest run",
|
|
28
32
|
"test:watch": "vitest"
|