@aplus-frontend/ui
Version:
2 lines (1 loc) • 4.78 kB
JavaScript
;Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),z=require("@ant-design/icons-vue"),h=require("@aplus-frontend/antdv"),N=require("../../ap-action/index.js");require("../../config-provider/index.js");const i=require("lodash-unified"),T=require("../../config-provider/hooks/use-locale.js"),$=require("../../config-provider/hooks/use-namespace.js"),q=require("../../config-provider/hooks/use-global-config.js"),A=["onClick"],D=e.defineComponent({__name:"ApExpandAlert",props:{type:{default:"warning"},data:{default:()=>[]},prefix:{default:""},tipTitle:{default:""},mapLabel:{},separator:{default:"|"},separatorStyle:{default:()=>({})},contentStyle:{default:()=>({})},prefixStyle:{default:()=>({})},rows:{default:2},defaultExpand:{type:Boolean,default:!0},showIcon:{type:Boolean,default:!0}},emits:["choose","expand"],setup(g,{expose:v,emit:B}){const f=B,r=g,{t:m}=T.useLocale(),S=e.computed(()=>{if(r.type!="card")return r.type}),l=e.ref(""),s=e.ref(null),w=e.computed(()=>({fontWeight:"400",wordBreak:"break-all",overflow:"hidden",display:"-webkit-box",webkitLineClamp:l.value,webkitBoxOrient:"vertical",lineHeight:"18px"}));function C(){l.value==="1"?(l.value="",f("expand","expand")):(l.value="1",f("expand","collapse"))}const x=e.computed(()=>l.value==="1"?m("ap.apExpandAlert.expand"):m("ap.apExpandAlert.collapse")),u=e.ref(!0),y=e.computed(()=>l.value!=="1");function c(t){t?l.value="":l.value="1"}e.watch(()=>r.data,()=>{l.value="",e.nextTick(()=>{if(s.value){const t=Number(s.value.clientHeight),o=Number(parseInt(s.value.style.lineHeight));t<o*Number(r.rows)&&y.value?u.value=!1:u.value=!0}})},{immediate:!0}),e.watch(()=>r.defaultExpand,t=>{t?e.nextTick(()=>{c(t)}):e.nextTick(()=>{c(t)})},{immediate:!0}),e.onMounted(()=>{e.watch(()=>r.contentStyle,t=>{i.isNil(t.lineHeight)||e.nextTick(()=>{const o=document.querySelector(`#${p} .ant-alert-action`),a=document.querySelector(`#${p} .ant-alert-icon`);o&&o.setAttribute("style",`line-height: ${t.lineHeight}`),a&&a.setAttribute("style",`line-height: ${t.lineHeight}`)})},{deep:!0,immediate:!0,flush:"post"})});const{b:k,e:n,m:E}=$.useNamespace("ap-expand-alert"),p=`${k()}-key-${Date.now()}-${(Math.random()*1e6).toFixed(0)}`,b=q.useGlobalConfig("uiMode","aplus");return v({setExpand:c}),(t,o)=>(e.openBlock(),e.createElementBlock("div",{id:p,class:e.normalizeClass([e.unref(k)(),`${e.unref(E)(e.unref(b))}`])},[e.createVNode(e.unref(h.Alert),{type:S.value,"show-icon":t.showIcon,class:e.normalizeClass([e.unref(n)("antAlert"),t.type=="card"?"card-alert":""])},{action:e.withCtx(()=>[u.value?(e.openBlock(),e.createBlock(e.unref(N.ApActionItem),{key:0,size:"small",style:{"font-size":"12px","padding-left":"16px"},onClick:o[0]||(o[0]=a=>C())},{default:e.withCtx(()=>[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n)("expandText"))},e.toDisplayString(x.value),3),e.createVNode(e.unref(z.DownOutlined),{class:e.normalizeClass(y.value?e.unref(n)("expandIcon"):e.unref(n)("collapseIcon"))},null,8,["class"])]),_:1})):e.createCommentVNode("",!0)]),message:e.withCtx(()=>[e.createElementVNode("div",{ref_key:"ellipsisBoxRef",ref:s,style:e.normalizeStyle({...w.value,...t.contentStyle}),class:e.normalizeClass(e.unref(n)("alertContent"))},[e.renderSlot(t.$slots,"default",{},()=>[e.unref(i.isString)(t.prefix)?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(e.unref(n)("prefix")),style:e.normalizeStyle(t.prefixStyle)},e.toDisplayString(t.prefix),7)):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.prefix),{key:1,style:e.normalizeStyle(t.prefixStyle)},null,8,["style"])),e.unref(i.isString)(t.data)?(e.openBlock(),e.createElementBlock("span",{key:2,class:e.normalizeClass(e.unref(n)("text"))},e.toDisplayString(t.data),3)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:3},e.renderList(t.data,(a,d)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:d},[e.createVNode(e.unref(h.Tooltip),{title:t.tipTitle?t.tipTitle:null},{default:e.withCtx(()=>[e.renderSlot(t.$slots,"item",{record:a,index:d},()=>[e.createElementVNode("span",{class:e.normalizeClass(e.unref(n)("showItem")),onClick:V=>t.$emit("choose",a)},e.toDisplayString(t.mapLabel?a[t.mapLabel]:a),11,A)])]),_:2},1032,["title"]),d!==t.data.length-1?(e.openBlock(),e.createElementBlock("span",{key:0,class:e.normalizeClass(e.unref(n)("spliter")),style:e.normalizeStyle(t.separatorStyle)},[e.unref(i.isString)(t.separator)?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode(e.toDisplayString(t.separator),1)],64)):(e.openBlock(),e.createBlock(e.resolveDynamicComponent(t.separator),{key:1}))],6)):e.createCommentVNode("",!0)],64))),128))])],6)]),_:3},8,["type","show-icon","class"])],2))}});exports.default=D;