cd-personselector 1.0.8 → 1.1.0

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/index.js CHANGED
@@ -1 +1 @@
1
- (function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f.CdPersonSelector={},f.Vue))})(this,function(f,e){"use strict";const H={class:"cd-ps-container"},Q={key:0,class:"cd-ps-tips"},X={key:1,class:"cd-ps-search"},Y={key:0,class:"cd-ps-org-select"},Z={class:"cd-ps-search-input"},K={class:"cd-ps-content"},v={class:"cd-ps-left"},ee={key:0,class:"cd-ps-search-results"},te={class:"cd-ps-search-header"},oe={key:0,class:"cd-ps-loading"},le={key:1,class:"cd-ps-empty"},ne={key:2,class:"cd-ps-result-list"},ae=["onClick"],se={class:"cd-ps-avatar"},ce={class:"cd-ps-info"},de={class:"cd-ps-name"},re={class:"cd-ps-meta"},ie={key:0},pe={key:1},me={key:2},fe={class:"cd-ps-tree"},ke={key:0,class:"cd-ps-count"},he={key:1,class:"cd-ps-empty"},_e={class:"cd-ps-right"},ye={class:"cd-ps-right-header"},Ne={class:"cd-ps-num"},Ve={class:"cd-ps-right-list"},ge={key:0,class:"cd-ps-empty"},Ce={key:1,class:"cd-ps-selected-list"},Be={class:"cd-ps-item-info"},ue={class:"cd-ps-info"},Ee={class:"cd-ps-name"},Se={class:"cd-ps-meta"},xe={key:0},be={key:1},we={key:2},Ue={key:3},R=((V,T)=>{const U=V.__vccOpts||V;for(const[s,k]of T)U[s]=k;return U})(e.defineComponent({__name:"PersonSelector",props:{visible:{type:Boolean,default:!1},tabs:{default:()=>[]},organizations:{default:()=>[]},modelValue:{default:()=>[]},dialogWidth:{default:"900px"},tips:{default:""},showSearch:{type:Boolean,default:!0}},emits:["update:visible","update:modelValue","confirm","load-users","search","org-change"],setup(V,{expose:T,emit:U}){var q,A;const s=V,k=U,g=e.ref(s.visible),h=e.ref(((A=(q=s.tabs)==null?void 0:q[0])==null?void 0:A.key)||""),_=e.ref(null),C=e.ref(""),r=e.ref([]),E=e.ref(new Map),z=e.ref({}),P=e.ref(!1),D=e.ref(!1),S=e.ref([]),Ie=e.computed(()=>s.tabs||[]),L=e.computed(()=>s.organizations||[]),F=e.computed(()=>s.tips||""),Te=e.computed(()=>s.showSearch),ze=e.computed(()=>s.dialogWidth),y=e.ref({});e.watch(()=>s.tabs,l=>{if(l&&l.length>0){const t={};l.forEach(n=>{t[n.key]=JSON.parse(JSON.stringify(n.tree))}),y.value=t,(!h.value||!l.find(n=>n.key===h.value))&&(h.value=l[0].key)}},{immediate:!0,deep:!0}),e.watch(()=>s.visible,l=>{g.value=l,l&&(r.value=s.modelValue?[...s.modelValue]:[],E.value.clear(),s.organizations.length>0&&!_.value&&(_.value=s.organizations[0].id))}),e.watch(g,l=>{k("update:visible",l)});function Pe(l,t){t&&(z.value[l]=t)}function W(l,t){for(const n of l){if(n.id===t)return n;if(n.children){const a=W(n.children,t);if(a)return a}}return null}const x=e.computed(()=>r.value.map(l=>E.value.get(l)).filter(Boolean));function $(l,t){r.value.includes(l)||r.value.push(l),E.value.set(l,t)}function M(l){r.value=r.value.filter(t=>t!==l),E.value.delete(l)}const Me=()=>{C.value=""},Oe=l=>{const t={};s.tabs.forEach(n=>{t[n.key]=[]}),y.value=t,k("org-change",l)};let B=null;const Re=()=>{if(B&&clearTimeout(B),!C.value.trim()){O();return}P.value=!0,D.value=!0,B=setTimeout(()=>Le(),300)},Le=()=>{S.value=[];const l=t=>{S.value=t.map(n=>({...n,isUser:!0})),D.value=!1};k("search",{keyword:C.value,orgId:_.value||void 0,callback:l})},O=()=>{B&&(clearTimeout(B),B=null),P.value=!1,C.value="",S.value=[],D.value=!1},Fe=l=>{r.value.indexOf(l.id)>-1?M(l.id):$(l.id,{...l,isUser:!0,typeName:"搜索结果",orgId:_.value})};function We(l){const t=[],n=a=>{for(const p of a)t.push(p.id),p.children&&n(p.children)};return n(l),t}const $e=(l,t)=>{var c;const n=t==null?void 0:t.node;if(n){const d=n.value??((c=n.data)==null?void 0:c.id);if(d!==void 0){if(n.checked){const u=s.tabs.find(w=>w.key===h.value),b=u?u.name.replace(/^按/,""):"";$(d,{...n.data,typeName:b,orgId:_.value})}else M(d);return}}const a=y.value[h.value]||[],p=We(a),m=r.value.filter(d=>!p.includes(d));r.value=[...m,...l]};function j(l,t,n){for(const a of l){if(a.id===t)return a.children=a.children||[],a.children.push(...n),a.loaded=!0,!0;if(a.children&&j(a.children,t,n))return!0}return!1}async function je(l,t){const n=l.value,a=z.value[t];k("load-users",{tabKey:t,nodeId:n,node:l,callback:async m=>{if(m.length>0){const c=m.map(N=>{const{id:u,name:b,...w}=N;return{...w,id:u,name:N.displayName||b,isUser:!0}}),d=y.value[t];if(d&&j(d,n,c),a){a.appendTo(n,c),l.data.loaded=!0,await e.nextTick();try{a.setItem(n,{expanded:!0})}catch{}}}else{l.data.loaded=!0;const c=y.value[t];if(c){const d=W(c,n);d&&(d.loaded=!0)}}}})}const Je=l=>{M(l)},J=()=>{r.value=[],E.value.clear()},qe=()=>{k("update:modelValue",r.value),k("confirm",x.value),g.value=!1},Ae=()=>{g.value=!1};return T({clearSelection:J,appendUsers:(l,t,n)=>{const a=z.value[l];if(a&&n.length>0){const p=n.map(m=>{const{id:c,name:d,...N}=m;return{...N,id:c,name:m.displayName||d,isUser:!0}});a.appendTo(t,p)}}}),(l,t)=>{const n=e.resolveComponent("t-icon"),a=e.resolveComponent("t-option"),p=e.resolveComponent("t-select"),m=e.resolveComponent("t-input"),c=e.resolveComponent("t-button"),d=e.resolveComponent("t-loading"),N=e.resolveComponent("t-checkbox"),u=e.resolveComponent("t-tree"),b=e.resolveComponent("t-tab-panel"),w=e.resolveComponent("t-tabs"),Ge=e.resolveComponent("t-dialog");return e.openBlock(),e.createBlock(Ge,{visible:g.value,"onUpdate:visible":t[4]||(t[4]=o=>g.value=o),header:"选择人员",width:ze.value,footer:!0,placement:"center","destroy-on-close":"",onConfirm:qe,onClose:Ae},{default:e.withCtx(()=>[e.createElementVNode("div",H,[F.value?(e.openBlock(),e.createElementBlock("div",Q,[e.createVNode(n,{name:"info-circle"}),e.createElementVNode("span",null,e.toDisplayString(F.value),1)])):e.createCommentVNode("",!0),Te.value?(e.openBlock(),e.createElementBlock("div",X,[L.value.length>0?(e.openBlock(),e.createElementBlock("div",Y,[e.createVNode(p,{modelValue:_.value,"onUpdate:modelValue":t[0]||(t[0]=o=>_.value=o),placeholder:"选择组织",style:{width:"200px"},onChange:Oe},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(L.value,o=>(e.openBlock(),e.createBlock(a,{key:o.id,value:o.id,label:o.displayName||o.name},null,8,["value","label"]))),128))]),_:1},8,["modelValue"])])):e.createCommentVNode("",!0),e.createElementVNode("div",Z,[e.createVNode(m,{modelValue:C.value,"onUpdate:modelValue":t[1]||(t[1]=o=>C.value=o),placeholder:"输入手机号/工号/姓名/部门/职位搜索",clearable:"",onInput:Re,onClear:O},{"prefix-icon":e.withCtx(()=>[e.createVNode(n,{name:"search"})]),_:1},8,["modelValue"])])])):e.createCommentVNode("",!0),e.createElementVNode("div",K,[e.createElementVNode("div",v,[P.value?(e.openBlock(),e.createElementBlock("div",ee,[e.createElementVNode("div",te,[t[6]||(t[6]=e.createElementVNode("span",null,"搜索结果",-1)),e.createVNode(c,{size:"small",variant:"text",onClick:O},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("返回",-1)])]),_:1})]),D.value?(e.openBlock(),e.createElementBlock("div",oe,[e.createVNode(d),t[7]||(t[7]=e.createElementVNode("span",null,"搜索中...",-1))])):S.value.length===0?(e.openBlock(),e.createElementBlock("div",le,[e.createVNode(n,{name:"search",size:"48px",style:{color:"#ddd"}}),t[8]||(t[8]=e.createElementVNode("p",null,"未找到匹配的人员",-1))])):(e.openBlock(),e.createElementBlock("div",ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(S.value,o=>(e.openBlock(),e.createElementBlock("div",{key:o.id,class:e.normalizeClass(["cd-ps-result-item",{"cd-ps-selected":r.value.includes(o.id)}]),onClick:I=>Fe(o)},[e.createVNode(N,{checked:r.value.includes(o.id),onClick:t[2]||(t[2]=e.withModifiers(()=>{},["stop"]))},null,8,["checked"]),e.createElementVNode("div",se,[e.createVNode(n,{name:"user"})]),e.createElementVNode("div",ce,[e.createElementVNode("div",de,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",re,[o.position?(e.openBlock(),e.createElementBlock("span",ie,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.department?(e.openBlock(),e.createElementBlock("span",pe,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.phone?(e.openBlock(),e.createElementBlock("span",me,e.toDisplayString(o.phone),1)):e.createCommentVNode("",!0)])])],10,ae))),128))]))])):(e.openBlock(),e.createBlock(w,{key:1,modelValue:h.value,"onUpdate:modelValue":t[3]||(t[3]=o=>h.value=o),onChange:Me},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ie.value,o=>(e.openBlock(),e.createBlock(b,{key:o.key,value:o.key,label:o.name},{default:e.withCtx(()=>{var I;return[e.createElementVNode("div",fe,[((I=y.value[o.key])==null?void 0:I.length)>0?(e.openBlock(),e.createBlock(u,{key:0,ref_for:!0,ref:i=>Pe(o.key,i),data:y.value[o.key],keys:{value:"id",label:"name",children:"children"},hover:"",checkable:"","expand-all":!1,value:r.value,onChange:$e},{label:e.withCtx(({node:i})=>{var G;return[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-node",{"cd-ps-node-user":i.data.isUser}])},[e.createVNode(n,{name:i.data.isUser?"user":o.icon||"folder"},null,8,["name"]),e.createElementVNode("span",null,e.toDisplayString(i.label),1),i.data.userCount&&!i.data.isUser?(e.openBlock(),e.createElementBlock("span",ke,"("+e.toDisplayString(i.data.userCount)+")",1)):e.createCommentVNode("",!0),!i.data.isUser&&!((G=i.data.children)!=null&&G.length)&&!i.data.loaded?(e.openBlock(),e.createBlock(c,{key:1,size:"small",variant:"text",class:"cd-ps-load-btn",onClick:e.withModifiers(Xe=>je(i,o.key),["stop"])},{default:e.withCtx(()=>[...t[9]||(t[9]=[e.createTextVNode("显示人员",-1)])]),_:1},8,["onClick"])):e.createCommentVNode("",!0)],2)]}),_:2},1032,["data","value"])):(e.openBlock(),e.createElementBlock("div",he,[e.createVNode(n,{name:o.icon||"folder-open",size:"48px",style:{color:"#ddd"}},null,8,["name"]),t[10]||(t[10]=e.createElementVNode("p",null,"暂无数据",-1))]))])]}),_:2},1032,["value","label"]))),128))]),_:1},8,["modelValue"]))]),e.createElementVNode("div",_e,[e.createElementVNode("div",ye,[t[12]||(t[12]=e.createElementVNode("span",{class:"cd-ps-title"},"已选择",-1)),e.createElementVNode("span",Ne,e.toDisplayString(x.value.length)+" 项",1),x.value.length>0?(e.openBlock(),e.createBlock(c,{key:0,size:"small",variant:"text",onClick:J},{default:e.withCtx(()=>[...t[11]||(t[11]=[e.createTextVNode("清空",-1)])]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",Ve,[x.value.length===0?(e.openBlock(),e.createElementBlock("div",ge,[e.createVNode(n,{name:"user-checked",size:"64px",style:{color:"#ddd"}}),t[13]||(t[13]=e.createElementVNode("p",null,"暂无选择",-1))])):(e.openBlock(),e.createElementBlock("div",Ce,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(x.value,o=>(e.openBlock(),e.createElementBlock("div",{key:o.id,class:e.normalizeClass(["cd-ps-selected-item",{"cd-ps-dept-item":!o.isUser}])},[e.createElementVNode("div",Be,[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-avatar",{"cd-ps-avatar-dept":!o.isUser}])},[e.createVNode(n,{name:o.isUser?"user":"folder"},null,8,["name"])],2),e.createElementVNode("div",ue,[e.createElementVNode("div",Ee,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",Se,[o.isUser&&o.position?(e.openBlock(),e.createElementBlock("span",xe,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.isUser&&o.department?(e.openBlock(),e.createElementBlock("span",be,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.isUser?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",we,e.toDisplayString(o.typeName||"部门"),1)),!o.isUser&&o.userCount?(e.openBlock(),e.createElementBlock("span",Ue,e.toDisplayString(o.userCount)+"人",1)):e.createCommentVNode("",!0)])])]),e.createVNode(c,{size:"small",variant:"text",shape:"circle",onClick:I=>Je(o.id)},{icon:e.withCtx(()=>[e.createVNode(n,{name:"close"})]),_:1},8,["onClick"])],2))),128))]))])])])])]),_:1},8,["visible","width"])}}}),[["__scopeId","data-v-0a6760cf"]]),De={install(V){V.component("PersonSelector",R)}};f.PersonSelector=R,f.default=De,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
1
+ (function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f.CdPersonSelector={},f.Vue))})(this,function(f,e){"use strict";const Q={class:"cd-ps-container"},X={key:0,class:"cd-ps-tips"},Y={key:1,class:"cd-ps-search"},Z={key:0,class:"cd-ps-org-select"},K={class:"cd-ps-search-input"},v={class:"cd-ps-content"},ee={class:"cd-ps-left"},te={key:0,class:"cd-ps-search-results"},oe={class:"cd-ps-search-header"},le={key:0,class:"cd-ps-loading"},ne={key:1,class:"cd-ps-empty"},ae={key:2,class:"cd-ps-result-list"},se=["onClick"],ce={class:"cd-ps-avatar"},de={class:"cd-ps-info"},re={class:"cd-ps-name"},ie={class:"cd-ps-meta"},pe={key:0},me={key:1},fe={key:2},he={class:"cd-ps-tree"},ke={class:"cd-ps-node-name"},_e={key:0,class:"cd-ps-position"},ye={key:0,class:"cd-ps-count"},Ve={key:1,class:"cd-ps-empty"},Ne={class:"cd-ps-right"},ue={class:"cd-ps-right-header"},ge={class:"cd-ps-num"},Be={class:"cd-ps-right-list"},Ce={key:0,class:"cd-ps-empty"},Ee={key:1,class:"cd-ps-selected-list"},Se={class:"cd-ps-item-info"},xe={class:"cd-ps-info"},be={class:"cd-ps-name"},we={class:"cd-ps-meta"},Ue={key:0},De={key:1},Ie={key:2},Te={key:3},R=((g,T)=>{const U=g.__vccOpts||g;for(const[a,h]of T)U[a]=h;return U})(e.defineComponent({__name:"PersonSelector",props:{visible:{type:Boolean,default:!1},tabs:{default:()=>[]},organizations:{default:()=>[]},modelValue:{default:()=>[]},dialogWidth:{default:"900px"},tips:{default:""},showSearch:{type:Boolean,default:!0},showOrg:{type:Boolean,default:!0}},emits:["update:visible","update:modelValue","confirm","load-users","search","org-change"],setup(g,{expose:T,emit:U}){var A,G;const a=g,h=U,k=e.ref(a.visible),_=e.ref(((G=(A=a.tabs)==null?void 0:A[0])==null?void 0:G.key)||""),y=e.ref(null),B=e.ref(""),c=e.ref([]),V=e.ref(new Map),z=e.ref({}),O=e.ref(!1),D=e.ref(!1),S=e.ref([]),Oe=e.computed(()=>a.tabs||[]),L=e.computed(()=>a.organizations||[]),F=e.computed(()=>a.tips||""),Me=e.computed(()=>a.showSearch),Pe=e.computed(()=>a.showOrg),Re=e.computed(()=>a.dialogWidth),N=e.ref({});e.watch(()=>a.tabs,o=>{if(o&&o.length>0){const t={};o.forEach(n=>{t[n.key]=JSON.parse(JSON.stringify(n.tree))}),N.value=t,(!_.value||!o.find(n=>n.key===_.value))&&(_.value=o[0].key)}},{immediate:!0,deep:!0});function j(){if(a.modelValue&&a.modelValue.length>0){const o=a.modelValue[0];typeof o=="object"&&o!==null&&"id"in o?(c.value=a.modelValue.map(t=>t.id),V.value.clear(),a.modelValue.forEach(t=>{V.value.set(t.id,t)})):c.value=[...a.modelValue]}else c.value=[],V.value.clear()}e.watch(()=>a.modelValue,o=>{k.value&&o&&j()},{deep:!0}),e.watch(()=>a.visible,o=>{k.value=o,o&&(j(),a.organizations.length>0&&!y.value&&(y.value=a.organizations[0].id))}),e.watch(k,o=>{h("update:visible",o)});function Le(o,t){t&&(z.value[o]=t)}function W(o,t){for(const n of o){if(n.id===t)return n;if(n.children){const s=W(n.children,t);if(s)return s}}return null}const x=e.computed(()=>c.value.map(o=>V.value.get(o)).filter(Boolean));function $(o,t){c.value.includes(o)||c.value.push(o),V.value.set(o,t)}function M(o){c.value=c.value.filter(t=>t!==o),V.value.delete(o)}const Fe=()=>{B.value=""},je=o=>{const t={};a.tabs.forEach(n=>{t[n.key]=[]}),N.value=t,h("org-change",o)};let C=null;const We=()=>{if(C&&clearTimeout(C),!B.value.trim()){P();return}O.value=!0,D.value=!0,C=setTimeout(()=>$e(),300)},$e=()=>{S.value=[];const o=t=>{S.value=t.map(n=>({...n,isUser:!0})),D.value=!1};h("search",{keyword:B.value,orgId:y.value||void 0,callback:o})},P=()=>{C&&(clearTimeout(C),C=null),O.value=!1,B.value="",S.value=[],D.value=!1},Je=o=>{c.value.indexOf(o.id)>-1?M(o.id):$(o.id,{...o,isUser:!0,typeName:"搜索结果",orgId:y.value})};function qe(o){const t=[],n=s=>{for(const p of s)t.push(p.id),p.children&&n(p.children)};return n(o),t}const Ae=(o,t)=>{var d;const n=t==null?void 0:t.node;if(n){const r=n.value??((d=n.data)==null?void 0:d.id);if(r!==void 0){if(n.checked){const E=a.tabs.find(w=>w.key===_.value),b=E?E.name.replace(/^按/,""):"";$(r,{...n.data,typeName:b,orgId:y.value})}else M(r);return}}const s=N.value[_.value]||[],p=qe(s),m=c.value.filter(r=>!p.includes(r));c.value=[...m,...o]};function J(o,t,n){for(const s of o){if(s.id===t)return s.children=s.children||[],s.children.push(...n),s.loaded=!0,!0;if(s.children&&J(s.children,t,n))return!0}return!1}async function Ge(o,t){const n=o.value,s=z.value[t];h("load-users",{tabKey:t,nodeId:n,node:o,callback:async m=>{if(m.length>0){const d=m.map(u=>{const{id:E,name:b,...w}=u;return{...w,id:E,name:u.displayName||b,isUser:!0}}),r=N.value[t];if(r&&J(r,n,d),s){s.appendTo(n,d),o.data.loaded=!0,await e.nextTick();try{s.setItem(n,{expanded:!0})}catch{}}}else{o.data.loaded=!0;const d=N.value[t];if(d){const r=W(d,n);r&&(r.loaded=!0)}}}})}const He=o=>{M(o)},q=()=>{c.value=[],V.value.clear()},Qe=()=>{h("update:modelValue",c.value),h("confirm",x.value),k.value=!1},Xe=()=>{k.value=!1};return T({clearSelection:q,appendUsers:(o,t,n)=>{const s=z.value[o];if(s&&n.length>0){const p=n.map(m=>{const{id:d,name:r,...u}=m;return{...u,id:d,name:m.displayName||r,isUser:!0}});s.appendTo(t,p)}}}),(o,t)=>{const n=e.resolveComponent("t-icon"),s=e.resolveComponent("t-option"),p=e.resolveComponent("t-select"),m=e.resolveComponent("t-input"),d=e.resolveComponent("t-button"),r=e.resolveComponent("t-loading"),u=e.resolveComponent("t-checkbox"),E=e.resolveComponent("t-tree"),b=e.resolveComponent("t-tab-panel"),w=e.resolveComponent("t-tabs"),Ye=e.resolveComponent("t-dialog");return e.openBlock(),e.createBlock(Ye,{visible:k.value,"onUpdate:visible":t[4]||(t[4]=l=>k.value=l),header:"选择人员",width:Re.value,footer:!0,placement:"center","destroy-on-close":"",onConfirm:Qe,onClose:Xe},{default:e.withCtx(()=>[e.createElementVNode("div",Q,[F.value?(e.openBlock(),e.createElementBlock("div",X,[e.createVNode(n,{name:"info-circle"}),e.createElementVNode("span",null,e.toDisplayString(F.value),1)])):e.createCommentVNode("",!0),Me.value?(e.openBlock(),e.createElementBlock("div",Y,[Pe.value&&L.value.length>0?(e.openBlock(),e.createElementBlock("div",Z,[e.createVNode(p,{modelValue:y.value,"onUpdate:modelValue":t[0]||(t[0]=l=>y.value=l),placeholder:"选择组织",style:{width:"200px"},onChange:je},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(L.value,l=>(e.openBlock(),e.createBlock(s,{key:l.id,value:l.id,label:l.displayName||l.name},null,8,["value","label"]))),128))]),_:1},8,["modelValue"])])):e.createCommentVNode("",!0),e.createElementVNode("div",K,[e.createVNode(m,{modelValue:B.value,"onUpdate:modelValue":t[1]||(t[1]=l=>B.value=l),placeholder:"输入手机号/工号/姓名/部门/职位搜索",clearable:"",onInput:We,onClear:P},{"prefix-icon":e.withCtx(()=>[e.createVNode(n,{name:"search"})]),_:1},8,["modelValue"])])])):e.createCommentVNode("",!0),e.createElementVNode("div",v,[e.createElementVNode("div",ee,[O.value?(e.openBlock(),e.createElementBlock("div",te,[e.createElementVNode("div",oe,[t[6]||(t[6]=e.createElementVNode("span",null,"搜索结果",-1)),e.createVNode(d,{size:"small",variant:"text",onClick:P},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("返回",-1)])]),_:1})]),D.value?(e.openBlock(),e.createElementBlock("div",le,[e.createVNode(r),t[7]||(t[7]=e.createElementVNode("span",null,"搜索中...",-1))])):S.value.length===0?(e.openBlock(),e.createElementBlock("div",ne,[e.createVNode(n,{name:"search",size:"48px",style:{color:"#ddd"}}),t[8]||(t[8]=e.createElementVNode("p",null,"未找到匹配的人员",-1))])):(e.openBlock(),e.createElementBlock("div",ae,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(S.value,l=>(e.openBlock(),e.createElementBlock("div",{key:l.id,class:e.normalizeClass(["cd-ps-result-item",{"cd-ps-selected":c.value.includes(l.id)}]),onClick:I=>Je(l)},[e.createVNode(u,{checked:c.value.includes(l.id),onClick:t[2]||(t[2]=e.withModifiers(()=>{},["stop"]))},null,8,["checked"]),e.createElementVNode("div",ce,[e.createVNode(n,{name:"user"})]),e.createElementVNode("div",de,[e.createElementVNode("div",re,e.toDisplayString(l.displayName||l.name),1),e.createElementVNode("div",ie,[l.position?(e.openBlock(),e.createElementBlock("span",pe,e.toDisplayString(l.position),1)):e.createCommentVNode("",!0),l.department?(e.openBlock(),e.createElementBlock("span",me,e.toDisplayString(l.department),1)):e.createCommentVNode("",!0),l.phone?(e.openBlock(),e.createElementBlock("span",fe,e.toDisplayString(l.phone),1)):e.createCommentVNode("",!0)])])],10,se))),128))]))])):(e.openBlock(),e.createBlock(w,{key:1,modelValue:_.value,"onUpdate:modelValue":t[3]||(t[3]=l=>_.value=l),onChange:Fe},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Oe.value,l=>(e.openBlock(),e.createBlock(b,{key:l.key,value:l.key,label:l.name},{default:e.withCtx(()=>{var I;return[e.createElementVNode("div",he,[((I=N.value[l.key])==null?void 0:I.length)>0?(e.openBlock(),e.createBlock(E,{key:0,ref_for:!0,ref:i=>Le(l.key,i),data:N.value[l.key],keys:{value:"id",label:"name",children:"children"},hover:"",checkable:"","expand-all":!1,value:c.value,onChange:Ae},{label:e.withCtx(({node:i})=>{var H;return[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-node",{"cd-ps-node-user":i.data.isUser}])},[e.createVNode(n,{name:i.data.isUser?"user":l.icon||"folder"},null,8,["name"]),e.createElementVNode("span",ke,[e.createTextVNode(e.toDisplayString(i.label)+" ",1),i.data.isUser&&i.data.position?(e.openBlock(),e.createElementBlock("span",_e,e.toDisplayString(i.data.position),1)):e.createCommentVNode("",!0)]),i.data.userCount&&!i.data.isUser?(e.openBlock(),e.createElementBlock("span",ye,"("+e.toDisplayString(i.data.userCount)+")",1)):e.createCommentVNode("",!0),!i.data.isUser&&!((H=i.data.children)!=null&&H.length)&&!i.data.loaded?(e.openBlock(),e.createBlock(d,{key:1,size:"small",variant:"text",class:"cd-ps-load-btn",onClick:e.withModifiers(ve=>Ge(i,l.key),["stop"])},{default:e.withCtx(()=>[...t[9]||(t[9]=[e.createTextVNode("显示人员",-1)])]),_:1},8,["onClick"])):e.createCommentVNode("",!0)],2)]}),_:2},1032,["data","value"])):(e.openBlock(),e.createElementBlock("div",Ve,[e.createVNode(n,{name:l.icon||"folder-open",size:"48px",style:{color:"#ddd"}},null,8,["name"]),t[10]||(t[10]=e.createElementVNode("p",null,"暂无数据",-1))]))])]}),_:2},1032,["value","label"]))),128))]),_:1},8,["modelValue"]))]),e.createElementVNode("div",Ne,[e.createElementVNode("div",ue,[t[12]||(t[12]=e.createElementVNode("span",{class:"cd-ps-title"},"已选择",-1)),e.createElementVNode("span",ge,e.toDisplayString(x.value.length)+" 项",1),x.value.length>0?(e.openBlock(),e.createBlock(d,{key:0,size:"small",variant:"text",onClick:q},{default:e.withCtx(()=>[...t[11]||(t[11]=[e.createTextVNode("清空",-1)])]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",Be,[x.value.length===0?(e.openBlock(),e.createElementBlock("div",Ce,[e.createVNode(n,{name:"user-checked",size:"64px",style:{color:"#ddd"}}),t[13]||(t[13]=e.createElementVNode("p",null,"暂无选择",-1))])):(e.openBlock(),e.createElementBlock("div",Ee,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(x.value,l=>(e.openBlock(),e.createElementBlock("div",{key:l.id,class:e.normalizeClass(["cd-ps-selected-item",{"cd-ps-dept-item":!l.isUser}])},[e.createElementVNode("div",Se,[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-avatar",{"cd-ps-avatar-dept":!l.isUser}])},[e.createVNode(n,{name:l.isUser?"user":"folder"},null,8,["name"])],2),e.createElementVNode("div",xe,[e.createElementVNode("div",be,e.toDisplayString(l.displayName||l.name),1),e.createElementVNode("div",we,[l.isUser&&l.position?(e.openBlock(),e.createElementBlock("span",Ue,e.toDisplayString(l.position),1)):e.createCommentVNode("",!0),l.isUser&&l.department?(e.openBlock(),e.createElementBlock("span",De,e.toDisplayString(l.department),1)):e.createCommentVNode("",!0),l.isUser?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",Ie,e.toDisplayString(l.typeName||"部门"),1)),!l.isUser&&l.userCount?(e.openBlock(),e.createElementBlock("span",Te,e.toDisplayString(l.userCount)+"人",1)):e.createCommentVNode("",!0)])])]),e.createVNode(d,{size:"small",variant:"text",shape:"circle",onClick:I=>He(l.id)},{icon:e.withCtx(()=>[e.createVNode(n,{name:"close"})]),_:1},8,["onClick"])],2))),128))]))])])])])]),_:1},8,["visible","width"])}}}),[["__scopeId","data-v-a0450286"]]),ze={install(g){g.component("PersonSelector",R)}};f.PersonSelector=R,f.default=ze,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/dist/index.mjs CHANGED
@@ -1,38 +1,41 @@
1
- import { defineComponent as Ne, ref as _, computed as B, watch as Q, resolveComponent as m, createBlock as S, openBlock as a, withCtx as y, createElementVNode as n, createElementBlock as o, createCommentVNode as v, createVNode as u, toDisplayString as h, Fragment as $, renderList as J, createTextVNode as X, normalizeClass as A, withModifiers as oe, nextTick as Ue } from "vue";
2
- const xe = { class: "cd-ps-container" }, Se = {
1
+ import { defineComponent as Ne, ref as _, computed as S, watch as $, resolveComponent as m, createBlock as w, openBlock as a, withCtx as y, createElementVNode as n, createElementBlock as o, createCommentVNode as h, createVNode as v, toDisplayString as f, Fragment as J, renderList as j, createTextVNode as A, normalizeClass as F, withModifiers as de, nextTick as xe } from "vue";
2
+ const Ie = { class: "cd-ps-container" }, Se = {
3
3
  key: 0,
4
4
  class: "cd-ps-tips"
5
- }, Ie = {
5
+ }, we = {
6
6
  key: 1,
7
7
  class: "cd-ps-search"
8
- }, Ve = {
8
+ }, ze = {
9
9
  key: 0,
10
10
  class: "cd-ps-org-select"
11
- }, ze = { class: "cd-ps-search-input" }, Te = { class: "cd-ps-content" }, we = { class: "cd-ps-left" }, Be = {
11
+ }, Te = { class: "cd-ps-search-input" }, Oe = { class: "cd-ps-content" }, Be = { class: "cd-ps-left" }, De = {
12
12
  key: 0,
13
13
  class: "cd-ps-search-results"
14
- }, De = { class: "cd-ps-search-header" }, Re = {
14
+ }, Re = { class: "cd-ps-search-header" }, Ee = {
15
15
  key: 0,
16
16
  class: "cd-ps-loading"
17
- }, Oe = {
17
+ }, Me = {
18
18
  key: 1,
19
19
  class: "cd-ps-empty"
20
20
  }, Pe = {
21
21
  key: 2,
22
22
  class: "cd-ps-result-list"
23
- }, Ee = ["onClick"], Me = { class: "cd-ps-avatar" }, Le = { class: "cd-ps-info" }, We = { class: "cd-ps-name" }, $e = { class: "cd-ps-meta" }, Je = { key: 0 }, Ae = { key: 1 }, Fe = { key: 2 }, je = { class: "cd-ps-tree" }, qe = {
23
+ }, Le = ["onClick"], We = { class: "cd-ps-avatar" }, $e = { class: "cd-ps-info" }, Je = { class: "cd-ps-name" }, je = { class: "cd-ps-meta" }, Ae = { key: 0 }, Fe = { key: 1 }, qe = { key: 2 }, Ge = { class: "cd-ps-tree" }, He = { class: "cd-ps-node-name" }, Qe = {
24
+ key: 0,
25
+ class: "cd-ps-position"
26
+ }, Xe = {
24
27
  key: 0,
25
28
  class: "cd-ps-count"
26
- }, Ge = {
29
+ }, Ye = {
27
30
  key: 1,
28
31
  class: "cd-ps-empty"
29
- }, He = { class: "cd-ps-right" }, Qe = { class: "cd-ps-right-header" }, Xe = { class: "cd-ps-num" }, Ye = { class: "cd-ps-right-list" }, Ze = {
32
+ }, Ze = { class: "cd-ps-right" }, Ke = { class: "cd-ps-right-header" }, et = { class: "cd-ps-num" }, tt = { class: "cd-ps-right-list" }, st = {
30
33
  key: 0,
31
34
  class: "cd-ps-empty"
32
- }, Ke = {
35
+ }, lt = {
33
36
  key: 1,
34
37
  class: "cd-ps-selected-list"
35
- }, et = { class: "cd-ps-item-info" }, tt = { class: "cd-ps-info" }, st = { class: "cd-ps-name" }, lt = { class: "cd-ps-meta" }, at = { key: 0 }, nt = { key: 1 }, ot = { key: 2 }, dt = { key: 3 }, ct = /* @__PURE__ */ Ne({
38
+ }, at = { class: "cd-ps-item-info" }, nt = { class: "cd-ps-info" }, ot = { class: "cd-ps-name" }, dt = { class: "cd-ps-meta" }, ct = { key: 0 }, it = { key: 1 }, rt = { key: 2 }, ut = { key: 3 }, pt = /* @__PURE__ */ Ne({
36
39
  __name: "PersonSelector",
37
40
  props: {
38
41
  visible: { type: Boolean, default: !1 },
@@ -41,311 +44,327 @@ const xe = { class: "cd-ps-container" }, Se = {
41
44
  modelValue: { default: () => [] },
42
45
  dialogWidth: { default: "900px" },
43
46
  tips: { default: "" },
44
- showSearch: { type: Boolean, default: !0 }
47
+ showSearch: { type: Boolean, default: !0 },
48
+ showOrg: { type: Boolean, default: !0 }
45
49
  },
46
50
  emits: ["update:visible", "update:modelValue", "confirm", "load-users", "search", "org-change"],
47
- setup(I, { expose: F, emit: M }) {
48
- var le, ae;
49
- const c = I, C = M, V = _(c.visible), b = _(((ae = (le = c.tabs) == null ? void 0 : le[0]) == null ? void 0 : ae.key) || ""), N = _(null), z = _(""), p = _([]), D = _(/* @__PURE__ */ new Map()), j = _({}), q = _(!1), L = _(!1), R = _([]), de = B(() => c.tabs || []), Y = B(() => c.organizations || []), Z = B(() => c.tips || ""), ce = B(() => c.showSearch), ie = B(() => c.dialogWidth), U = _({});
50
- Q(() => c.tabs, (s) => {
51
- if (s && s.length > 0) {
51
+ setup(z, { expose: q, emit: P }) {
52
+ var ae, ne;
53
+ const d = z, C = P, b = _(d.visible), V = _(((ne = (ae = d.tabs) == null ? void 0 : ae[0]) == null ? void 0 : ne.key) || ""), U = _(null), T = _(""), i = _([]), N = _(/* @__PURE__ */ new Map()), G = _({}), H = _(!1), L = _(!1), D = _([]), ce = S(() => d.tabs || []), Y = S(() => d.organizations || []), Z = S(() => d.tips || ""), ie = S(() => d.showSearch), re = S(() => d.showOrg), ue = S(() => d.dialogWidth), x = _({});
54
+ $(() => d.tabs, (t) => {
55
+ if (t && t.length > 0) {
52
56
  const e = {};
53
- s.forEach((l) => {
57
+ t.forEach((l) => {
54
58
  e[l.key] = JSON.parse(JSON.stringify(l.tree));
55
- }), U.value = e, (!b.value || !s.find((l) => l.key === b.value)) && (b.value = s[0].key);
59
+ }), x.value = e, (!V.value || !t.find((l) => l.key === V.value)) && (V.value = t[0].key);
56
60
  }
57
- }, { immediate: !0, deep: !0 }), Q(() => c.visible, (s) => {
58
- V.value = s, s && (p.value = c.modelValue ? [...c.modelValue] : [], D.value.clear(), c.organizations.length > 0 && !N.value && (N.value = c.organizations[0].id));
59
- }), Q(V, (s) => {
60
- C("update:visible", s);
61
+ }, { immediate: !0, deep: !0 });
62
+ function K() {
63
+ if (d.modelValue && d.modelValue.length > 0) {
64
+ const t = d.modelValue[0];
65
+ typeof t == "object" && t !== null && "id" in t ? (i.value = d.modelValue.map((e) => e.id), N.value.clear(), d.modelValue.forEach((e) => {
66
+ N.value.set(e.id, e);
67
+ })) : i.value = [...d.modelValue];
68
+ } else
69
+ i.value = [], N.value.clear();
70
+ }
71
+ $(() => d.modelValue, (t) => {
72
+ b.value && t && K();
73
+ }, { deep: !0 }), $(() => d.visible, (t) => {
74
+ b.value = t, t && (K(), d.organizations.length > 0 && !U.value && (U.value = d.organizations[0].id));
75
+ }), $(b, (t) => {
76
+ C("update:visible", t);
61
77
  });
62
- function re(s, e) {
63
- e && (j.value[s] = e);
78
+ function pe(t, e) {
79
+ e && (G.value[t] = e);
64
80
  }
65
- function K(s, e) {
66
- for (const l of s) {
81
+ function ee(t, e) {
82
+ for (const l of t) {
67
83
  if (l.id === e) return l;
68
84
  if (l.children) {
69
- const d = K(l.children, e);
70
- if (d) return d;
85
+ const c = ee(l.children, e);
86
+ if (c) return c;
71
87
  }
72
88
  }
73
89
  return null;
74
90
  }
75
- const O = B(() => p.value.map((s) => D.value.get(s)).filter(Boolean));
76
- function ee(s, e) {
77
- p.value.includes(s) || p.value.push(s), D.value.set(s, e);
91
+ const R = S(() => i.value.map((t) => N.value.get(t)).filter(Boolean));
92
+ function te(t, e) {
93
+ i.value.includes(t) || i.value.push(t), N.value.set(t, e);
78
94
  }
79
- function G(s) {
80
- p.value = p.value.filter((e) => e !== s), D.value.delete(s);
95
+ function Q(t) {
96
+ i.value = i.value.filter((e) => e !== t), N.value.delete(t);
81
97
  }
82
- const ue = () => {
83
- z.value = "";
84
- }, pe = (s) => {
98
+ const ve = () => {
99
+ T.value = "";
100
+ }, he = (t) => {
85
101
  const e = {};
86
- c.tabs.forEach((l) => {
102
+ d.tabs.forEach((l) => {
87
103
  e[l.key] = [];
88
- }), U.value = e, C("org-change", s);
104
+ }), x.value = e, C("org-change", t);
89
105
  };
90
- let T = null;
91
- const ve = () => {
92
- if (T && clearTimeout(T), !z.value.trim()) {
93
- H();
106
+ let O = null;
107
+ const fe = () => {
108
+ if (O && clearTimeout(O), !T.value.trim()) {
109
+ X();
94
110
  return;
95
111
  }
96
- q.value = !0, L.value = !0, T = setTimeout(() => he(), 300);
97
- }, he = () => {
98
- R.value = [];
99
- const s = (e) => {
100
- R.value = e.map((l) => ({ ...l, isUser: !0 })), L.value = !1;
112
+ H.value = !0, L.value = !0, O = setTimeout(() => _e(), 300);
113
+ }, _e = () => {
114
+ D.value = [];
115
+ const t = (e) => {
116
+ D.value = e.map((l) => ({ ...l, isUser: !0 })), L.value = !1;
101
117
  };
102
- C("search", { keyword: z.value, orgId: N.value || void 0, callback: s });
103
- }, H = () => {
104
- T && (clearTimeout(T), T = null), q.value = !1, z.value = "", R.value = [], L.value = !1;
105
- }, fe = (s) => {
106
- p.value.indexOf(s.id) > -1 ? G(s.id) : ee(s.id, { ...s, isUser: !0, typeName: "搜索结果", orgId: N.value });
118
+ C("search", { keyword: T.value, orgId: U.value || void 0, callback: t });
119
+ }, X = () => {
120
+ O && (clearTimeout(O), O = null), H.value = !1, T.value = "", D.value = [], L.value = !1;
121
+ }, me = (t) => {
122
+ i.value.indexOf(t.id) > -1 ? Q(t.id) : te(t.id, { ...t, isUser: !0, typeName: "搜索结果", orgId: U.value });
107
123
  };
108
- function _e(s) {
109
- const e = [], l = (d) => {
110
- for (const k of d)
124
+ function ke(t) {
125
+ const e = [], l = (c) => {
126
+ for (const k of c)
111
127
  e.push(k.id), k.children && l(k.children);
112
128
  };
113
- return l(s), e;
129
+ return l(t), e;
114
130
  }
115
- const me = (s, e) => {
116
- var i;
131
+ const ye = (t, e) => {
132
+ var r;
117
133
  const l = e == null ? void 0 : e.node;
118
134
  if (l) {
119
- const r = l.value ?? ((i = l.data) == null ? void 0 : i.id);
120
- if (r !== void 0) {
135
+ const u = l.value ?? ((r = l.data) == null ? void 0 : r.id);
136
+ if (u !== void 0) {
121
137
  if (l.checked) {
122
- const w = c.tabs.find((E) => E.key === b.value), P = w ? w.name.replace(/^按/, "") : "";
123
- ee(r, { ...l.data, typeName: P, orgId: N.value });
138
+ const B = d.tabs.find((M) => M.key === V.value), E = B ? B.name.replace(/^按/, "") : "";
139
+ te(u, { ...l.data, typeName: E, orgId: U.value });
124
140
  } else
125
- G(r);
141
+ Q(u);
126
142
  return;
127
143
  }
128
144
  }
129
- const d = U.value[b.value] || [], k = _e(d), g = p.value.filter((r) => !k.includes(r));
130
- p.value = [...g, ...s];
145
+ const c = x.value[V.value] || [], k = ke(c), g = i.value.filter((u) => !k.includes(u));
146
+ i.value = [...g, ...t];
131
147
  };
132
- function te(s, e, l) {
133
- for (const d of s) {
134
- if (d.id === e)
135
- return d.children = d.children || [], d.children.push(...l), d.loaded = !0, !0;
136
- if (d.children && te(d.children, e, l))
148
+ function se(t, e, l) {
149
+ for (const c of t) {
150
+ if (c.id === e)
151
+ return c.children = c.children || [], c.children.push(...l), c.loaded = !0, !0;
152
+ if (c.children && se(c.children, e, l))
137
153
  return !0;
138
154
  }
139
155
  return !1;
140
156
  }
141
- async function ke(s, e) {
142
- const l = s.value, d = j.value[e];
143
- C("load-users", { tabKey: e, nodeId: l, node: s, callback: async (g) => {
157
+ async function ge(t, e) {
158
+ const l = t.value, c = G.value[e];
159
+ C("load-users", { tabKey: e, nodeId: l, node: t, callback: async (g) => {
144
160
  if (g.length > 0) {
145
- const i = g.map((x) => {
146
- const { id: w, name: P, ...E } = x;
147
- return { ...E, id: w, name: x.displayName || P, isUser: !0 };
148
- }), r = U.value[e];
149
- if (r && te(r, l, i), d) {
150
- d.appendTo(l, i), s.data.loaded = !0, await Ue();
161
+ const r = g.map((I) => {
162
+ const { id: B, name: E, ...M } = I;
163
+ return { ...M, id: B, name: I.displayName || E, isUser: !0 };
164
+ }), u = x.value[e];
165
+ if (u && se(u, l, r), c) {
166
+ c.appendTo(l, r), t.data.loaded = !0, await xe();
151
167
  try {
152
- d.setItem(l, { expanded: !0 });
168
+ c.setItem(l, { expanded: !0 });
153
169
  } catch {
154
170
  }
155
171
  }
156
172
  } else {
157
- s.data.loaded = !0;
158
- const i = U.value[e];
159
- if (i) {
160
- const r = K(i, l);
161
- r && (r.loaded = !0);
173
+ t.data.loaded = !0;
174
+ const r = x.value[e];
175
+ if (r) {
176
+ const u = ee(r, l);
177
+ u && (u.loaded = !0);
162
178
  }
163
179
  }
164
180
  } });
165
181
  }
166
- const ye = (s) => {
167
- G(s);
168
- }, se = () => {
169
- p.value = [], D.value.clear();
170
- }, ge = () => {
171
- C("update:modelValue", p.value), C("confirm", O.value), V.value = !1;
172
- }, Ce = () => {
173
- V.value = !1;
182
+ const Ce = (t) => {
183
+ Q(t);
184
+ }, le = () => {
185
+ i.value = [], N.value.clear();
186
+ }, be = () => {
187
+ C("update:modelValue", i.value), C("confirm", R.value), b.value = !1;
188
+ }, Ve = () => {
189
+ b.value = !1;
174
190
  };
175
- return F({
176
- clearSelection: se,
177
- appendUsers: (s, e, l) => {
178
- const d = j.value[s];
179
- if (d && l.length > 0) {
191
+ return q({
192
+ clearSelection: le,
193
+ appendUsers: (t, e, l) => {
194
+ const c = G.value[t];
195
+ if (c && l.length > 0) {
180
196
  const k = l.map((g) => {
181
- const { id: i, name: r, ...x } = g;
182
- return { ...x, id: i, name: g.displayName || r, isUser: !0 };
197
+ const { id: r, name: u, ...I } = g;
198
+ return { ...I, id: r, name: g.displayName || u, isUser: !0 };
183
199
  });
184
- d.appendTo(e, k);
200
+ c.appendTo(e, k);
185
201
  }
186
202
  }
187
- }), (s, e) => {
188
- const l = m("t-icon"), d = m("t-option"), k = m("t-select"), g = m("t-input"), i = m("t-button"), r = m("t-loading"), x = m("t-checkbox"), w = m("t-tree"), P = m("t-tab-panel"), E = m("t-tabs"), be = m("t-dialog");
189
- return a(), S(be, {
190
- visible: V.value,
191
- "onUpdate:visible": e[4] || (e[4] = (t) => V.value = t),
203
+ }), (t, e) => {
204
+ const l = m("t-icon"), c = m("t-option"), k = m("t-select"), g = m("t-input"), r = m("t-button"), u = m("t-loading"), I = m("t-checkbox"), B = m("t-tree"), E = m("t-tab-panel"), M = m("t-tabs"), Ue = m("t-dialog");
205
+ return a(), w(Ue, {
206
+ visible: b.value,
207
+ "onUpdate:visible": e[4] || (e[4] = (s) => b.value = s),
192
208
  header: "选择人员",
193
- width: ie.value,
209
+ width: ue.value,
194
210
  footer: !0,
195
211
  placement: "center",
196
212
  "destroy-on-close": "",
197
- onConfirm: ge,
198
- onClose: Ce
213
+ onConfirm: be,
214
+ onClose: Ve
199
215
  }, {
200
216
  default: y(() => [
201
- n("div", xe, [
217
+ n("div", Ie, [
202
218
  Z.value ? (a(), o("div", Se, [
203
- u(l, { name: "info-circle" }),
204
- n("span", null, h(Z.value), 1)
205
- ])) : v("", !0),
206
- ce.value ? (a(), o("div", Ie, [
207
- Y.value.length > 0 ? (a(), o("div", Ve, [
208
- u(k, {
209
- modelValue: N.value,
210
- "onUpdate:modelValue": e[0] || (e[0] = (t) => N.value = t),
219
+ v(l, { name: "info-circle" }),
220
+ n("span", null, f(Z.value), 1)
221
+ ])) : h("", !0),
222
+ ie.value ? (a(), o("div", we, [
223
+ re.value && Y.value.length > 0 ? (a(), o("div", ze, [
224
+ v(k, {
225
+ modelValue: U.value,
226
+ "onUpdate:modelValue": e[0] || (e[0] = (s) => U.value = s),
211
227
  placeholder: "选择组织",
212
228
  style: { width: "200px" },
213
- onChange: pe
229
+ onChange: he
214
230
  }, {
215
231
  default: y(() => [
216
- (a(!0), o($, null, J(Y.value, (t) => (a(), S(d, {
217
- key: t.id,
218
- value: t.id,
219
- label: t.displayName || t.name
232
+ (a(!0), o(J, null, j(Y.value, (s) => (a(), w(c, {
233
+ key: s.id,
234
+ value: s.id,
235
+ label: s.displayName || s.name
220
236
  }, null, 8, ["value", "label"]))), 128))
221
237
  ]),
222
238
  _: 1
223
239
  }, 8, ["modelValue"])
224
- ])) : v("", !0),
225
- n("div", ze, [
226
- u(g, {
227
- modelValue: z.value,
228
- "onUpdate:modelValue": e[1] || (e[1] = (t) => z.value = t),
240
+ ])) : h("", !0),
241
+ n("div", Te, [
242
+ v(g, {
243
+ modelValue: T.value,
244
+ "onUpdate:modelValue": e[1] || (e[1] = (s) => T.value = s),
229
245
  placeholder: "输入手机号/工号/姓名/部门/职位搜索",
230
246
  clearable: "",
231
- onInput: ve,
232
- onClear: H
247
+ onInput: fe,
248
+ onClear: X
233
249
  }, {
234
250
  "prefix-icon": y(() => [
235
- u(l, { name: "search" })
251
+ v(l, { name: "search" })
236
252
  ]),
237
253
  _: 1
238
254
  }, 8, ["modelValue"])
239
255
  ])
240
- ])) : v("", !0),
241
- n("div", Te, [
242
- n("div", we, [
243
- q.value ? (a(), o("div", Be, [
244
- n("div", De, [
256
+ ])) : h("", !0),
257
+ n("div", Oe, [
258
+ n("div", Be, [
259
+ H.value ? (a(), o("div", De, [
260
+ n("div", Re, [
245
261
  e[6] || (e[6] = n("span", null, "搜索结果", -1)),
246
- u(i, {
262
+ v(r, {
247
263
  size: "small",
248
264
  variant: "text",
249
- onClick: H
265
+ onClick: X
250
266
  }, {
251
267
  default: y(() => [...e[5] || (e[5] = [
252
- X("返回", -1)
268
+ A("返回", -1)
253
269
  ])]),
254
270
  _: 1
255
271
  })
256
272
  ]),
257
- L.value ? (a(), o("div", Re, [
258
- u(r),
273
+ L.value ? (a(), o("div", Ee, [
274
+ v(u),
259
275
  e[7] || (e[7] = n("span", null, "搜索中...", -1))
260
- ])) : R.value.length === 0 ? (a(), o("div", Oe, [
261
- u(l, {
276
+ ])) : D.value.length === 0 ? (a(), o("div", Me, [
277
+ v(l, {
262
278
  name: "search",
263
279
  size: "48px",
264
280
  style: { color: "#ddd" }
265
281
  }),
266
282
  e[8] || (e[8] = n("p", null, "未找到匹配的人员", -1))
267
283
  ])) : (a(), o("div", Pe, [
268
- (a(!0), o($, null, J(R.value, (t) => (a(), o("div", {
269
- key: t.id,
270
- class: A(["cd-ps-result-item", { "cd-ps-selected": p.value.includes(t.id) }]),
271
- onClick: (W) => fe(t)
284
+ (a(!0), o(J, null, j(D.value, (s) => (a(), o("div", {
285
+ key: s.id,
286
+ class: F(["cd-ps-result-item", { "cd-ps-selected": i.value.includes(s.id) }]),
287
+ onClick: (W) => me(s)
272
288
  }, [
273
- u(x, {
274
- checked: p.value.includes(t.id),
275
- onClick: e[2] || (e[2] = oe(() => {
289
+ v(I, {
290
+ checked: i.value.includes(s.id),
291
+ onClick: e[2] || (e[2] = de(() => {
276
292
  }, ["stop"]))
277
293
  }, null, 8, ["checked"]),
278
- n("div", Me, [
279
- u(l, { name: "user" })
294
+ n("div", We, [
295
+ v(l, { name: "user" })
280
296
  ]),
281
- n("div", Le, [
282
- n("div", We, h(t.displayName || t.name), 1),
283
- n("div", $e, [
284
- t.position ? (a(), o("span", Je, h(t.position), 1)) : v("", !0),
285
- t.department ? (a(), o("span", Ae, h(t.department), 1)) : v("", !0),
286
- t.phone ? (a(), o("span", Fe, h(t.phone), 1)) : v("", !0)
297
+ n("div", $e, [
298
+ n("div", Je, f(s.displayName || s.name), 1),
299
+ n("div", je, [
300
+ s.position ? (a(), o("span", Ae, f(s.position), 1)) : h("", !0),
301
+ s.department ? (a(), o("span", Fe, f(s.department), 1)) : h("", !0),
302
+ s.phone ? (a(), o("span", qe, f(s.phone), 1)) : h("", !0)
287
303
  ])
288
304
  ])
289
- ], 10, Ee))), 128))
305
+ ], 10, Le))), 128))
290
306
  ]))
291
- ])) : (a(), S(E, {
307
+ ])) : (a(), w(M, {
292
308
  key: 1,
293
- modelValue: b.value,
294
- "onUpdate:modelValue": e[3] || (e[3] = (t) => b.value = t),
295
- onChange: ue
309
+ modelValue: V.value,
310
+ "onUpdate:modelValue": e[3] || (e[3] = (s) => V.value = s),
311
+ onChange: ve
296
312
  }, {
297
313
  default: y(() => [
298
- (a(!0), o($, null, J(de.value, (t) => (a(), S(P, {
299
- key: t.key,
300
- value: t.key,
301
- label: t.name
314
+ (a(!0), o(J, null, j(ce.value, (s) => (a(), w(E, {
315
+ key: s.key,
316
+ value: s.key,
317
+ label: s.name
302
318
  }, {
303
319
  default: y(() => {
304
320
  var W;
305
321
  return [
306
- n("div", je, [
307
- ((W = U.value[t.key]) == null ? void 0 : W.length) > 0 ? (a(), S(w, {
322
+ n("div", Ge, [
323
+ ((W = x.value[s.key]) == null ? void 0 : W.length) > 0 ? (a(), w(B, {
308
324
  key: 0,
309
325
  ref_for: !0,
310
- ref: (f) => re(t.key, f),
311
- data: U.value[t.key],
326
+ ref: (p) => pe(s.key, p),
327
+ data: x.value[s.key],
312
328
  keys: { value: "id", label: "name", children: "children" },
313
329
  hover: "",
314
330
  checkable: "",
315
331
  "expand-all": !1,
316
- value: p.value,
317
- onChange: me
332
+ value: i.value,
333
+ onChange: ye
318
334
  }, {
319
- label: y(({ node: f }) => {
320
- var ne;
335
+ label: y(({ node: p }) => {
336
+ var oe;
321
337
  return [
322
338
  n("div", {
323
- class: A(["cd-ps-node", { "cd-ps-node-user": f.data.isUser }])
339
+ class: F(["cd-ps-node", { "cd-ps-node-user": p.data.isUser }])
324
340
  }, [
325
- u(l, {
326
- name: f.data.isUser ? "user" : t.icon || "folder"
341
+ v(l, {
342
+ name: p.data.isUser ? "user" : s.icon || "folder"
327
343
  }, null, 8, ["name"]),
328
- n("span", null, h(f.label), 1),
329
- f.data.userCount && !f.data.isUser ? (a(), o("span", qe, "(" + h(f.data.userCount) + ")", 1)) : v("", !0),
330
- !f.data.isUser && !((ne = f.data.children) != null && ne.length) && !f.data.loaded ? (a(), S(i, {
344
+ n("span", He, [
345
+ A(f(p.label) + " ", 1),
346
+ p.data.isUser && p.data.position ? (a(), o("span", Qe, f(p.data.position), 1)) : h("", !0)
347
+ ]),
348
+ p.data.userCount && !p.data.isUser ? (a(), o("span", Xe, "(" + f(p.data.userCount) + ")", 1)) : h("", !0),
349
+ !p.data.isUser && !((oe = p.data.children) != null && oe.length) && !p.data.loaded ? (a(), w(r, {
331
350
  key: 1,
332
351
  size: "small",
333
352
  variant: "text",
334
353
  class: "cd-ps-load-btn",
335
- onClick: oe((ut) => ke(f, t.key), ["stop"])
354
+ onClick: de((ft) => ge(p, s.key), ["stop"])
336
355
  }, {
337
356
  default: y(() => [...e[9] || (e[9] = [
338
- X("显示人员", -1)
357
+ A("显示人员", -1)
339
358
  ])]),
340
359
  _: 1
341
- }, 8, ["onClick"])) : v("", !0)
360
+ }, 8, ["onClick"])) : h("", !0)
342
361
  ], 2)
343
362
  ];
344
363
  }),
345
364
  _: 2
346
- }, 1032, ["data", "value"])) : (a(), o("div", Ge, [
347
- u(l, {
348
- name: t.icon || "folder-open",
365
+ }, 1032, ["data", "value"])) : (a(), o("div", Ye, [
366
+ v(l, {
367
+ name: s.icon || "folder-open",
349
368
  size: "48px",
350
369
  style: { color: "#ddd" }
351
370
  }, null, 8, ["name"]),
@@ -360,61 +379,61 @@ const xe = { class: "cd-ps-container" }, Se = {
360
379
  _: 1
361
380
  }, 8, ["modelValue"]))
362
381
  ]),
363
- n("div", He, [
364
- n("div", Qe, [
382
+ n("div", Ze, [
383
+ n("div", Ke, [
365
384
  e[12] || (e[12] = n("span", { class: "cd-ps-title" }, "已选择", -1)),
366
- n("span", Xe, h(O.value.length) + " 项", 1),
367
- O.value.length > 0 ? (a(), S(i, {
385
+ n("span", et, f(R.value.length) + " 项", 1),
386
+ R.value.length > 0 ? (a(), w(r, {
368
387
  key: 0,
369
388
  size: "small",
370
389
  variant: "text",
371
- onClick: se
390
+ onClick: le
372
391
  }, {
373
392
  default: y(() => [...e[11] || (e[11] = [
374
- X("清空", -1)
393
+ A("清空", -1)
375
394
  ])]),
376
395
  _: 1
377
- })) : v("", !0)
396
+ })) : h("", !0)
378
397
  ]),
379
- n("div", Ye, [
380
- O.value.length === 0 ? (a(), o("div", Ze, [
381
- u(l, {
398
+ n("div", tt, [
399
+ R.value.length === 0 ? (a(), o("div", st, [
400
+ v(l, {
382
401
  name: "user-checked",
383
402
  size: "64px",
384
403
  style: { color: "#ddd" }
385
404
  }),
386
405
  e[13] || (e[13] = n("p", null, "暂无选择", -1))
387
- ])) : (a(), o("div", Ke, [
388
- (a(!0), o($, null, J(O.value, (t) => (a(), o("div", {
389
- key: t.id,
390
- class: A(["cd-ps-selected-item", { "cd-ps-dept-item": !t.isUser }])
406
+ ])) : (a(), o("div", lt, [
407
+ (a(!0), o(J, null, j(R.value, (s) => (a(), o("div", {
408
+ key: s.id,
409
+ class: F(["cd-ps-selected-item", { "cd-ps-dept-item": !s.isUser }])
391
410
  }, [
392
- n("div", et, [
411
+ n("div", at, [
393
412
  n("div", {
394
- class: A(["cd-ps-avatar", { "cd-ps-avatar-dept": !t.isUser }])
413
+ class: F(["cd-ps-avatar", { "cd-ps-avatar-dept": !s.isUser }])
395
414
  }, [
396
- u(l, {
397
- name: t.isUser ? "user" : "folder"
415
+ v(l, {
416
+ name: s.isUser ? "user" : "folder"
398
417
  }, null, 8, ["name"])
399
418
  ], 2),
400
- n("div", tt, [
401
- n("div", st, h(t.displayName || t.name), 1),
402
- n("div", lt, [
403
- t.isUser && t.position ? (a(), o("span", at, h(t.position), 1)) : v("", !0),
404
- t.isUser && t.department ? (a(), o("span", nt, h(t.department), 1)) : v("", !0),
405
- t.isUser ? v("", !0) : (a(), o("span", ot, h(t.typeName || "部门"), 1)),
406
- !t.isUser && t.userCount ? (a(), o("span", dt, h(t.userCount) + "人", 1)) : v("", !0)
419
+ n("div", nt, [
420
+ n("div", ot, f(s.displayName || s.name), 1),
421
+ n("div", dt, [
422
+ s.isUser && s.position ? (a(), o("span", ct, f(s.position), 1)) : h("", !0),
423
+ s.isUser && s.department ? (a(), o("span", it, f(s.department), 1)) : h("", !0),
424
+ s.isUser ? h("", !0) : (a(), o("span", rt, f(s.typeName || "部门"), 1)),
425
+ !s.isUser && s.userCount ? (a(), o("span", ut, f(s.userCount) + "人", 1)) : h("", !0)
407
426
  ])
408
427
  ])
409
428
  ]),
410
- u(i, {
429
+ v(r, {
411
430
  size: "small",
412
431
  variant: "text",
413
432
  shape: "circle",
414
- onClick: (W) => ye(t.id)
433
+ onClick: (W) => Ce(s.id)
415
434
  }, {
416
435
  icon: y(() => [
417
- u(l, { name: "close" })
436
+ v(l, { name: "close" })
418
437
  ]),
419
438
  _: 1
420
439
  }, 8, ["onClick"])
@@ -429,17 +448,17 @@ const xe = { class: "cd-ps-container" }, Se = {
429
448
  }, 8, ["visible", "width"]);
430
449
  };
431
450
  }
432
- }), it = (I, F) => {
433
- const M = I.__vccOpts || I;
434
- for (const [c, C] of F)
435
- M[c] = C;
436
- return M;
437
- }, rt = /* @__PURE__ */ it(ct, [["__scopeId", "data-v-0a6760cf"]]), vt = {
438
- install(I) {
439
- I.component("PersonSelector", rt);
451
+ }), vt = (z, q) => {
452
+ const P = z.__vccOpts || z;
453
+ for (const [d, C] of q)
454
+ P[d] = C;
455
+ return P;
456
+ }, ht = /* @__PURE__ */ vt(pt, [["__scopeId", "data-v-a0450286"]]), mt = {
457
+ install(z) {
458
+ z.component("PersonSelector", ht);
440
459
  }
441
460
  };
442
461
  export {
443
- rt as PersonSelector,
444
- vt as default
462
+ ht as PersonSelector,
463
+ mt as default
445
464
  };
@@ -37,6 +37,7 @@ interface Props {
37
37
  dialogWidth?: string;
38
38
  tips?: string;
39
39
  showSearch?: boolean;
40
+ showOrg?: boolean;
40
41
  }
41
42
  declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
42
43
  visible: boolean;
@@ -46,6 +47,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
46
47
  dialogWidth: string;
47
48
  tips: string;
48
49
  showSearch: boolean;
50
+ showOrg: boolean;
49
51
  }>>, {
50
52
  clearSelection: () => void;
51
53
  appendUsers: (tabKey: string, nodeId: number | string, users: User[]) => void;
@@ -73,6 +75,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
73
75
  dialogWidth: string;
74
76
  tips: string;
75
77
  showSearch: boolean;
78
+ showOrg: boolean;
76
79
  }>>> & Readonly<{
77
80
  "onUpdate:visible"?: ((value: boolean) => any) | undefined;
78
81
  "onUpdate:modelValue"?: ((value: (string | number)[]) => any) | undefined;
@@ -97,6 +100,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
97
100
  dialogWidth: string;
98
101
  tips: string;
99
102
  showSearch: boolean;
103
+ showOrg: boolean;
100
104
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
101
105
  export default _default;
102
106
  type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- .cd-ps-container[data-v-0a6760cf]{display:flex;flex-direction:column;gap:16px;min-height:500px}.cd-ps-tips[data-v-0a6760cf]{display:flex;align-items:center;gap:8px;padding:12px;background-color:#e8f4ff;border-radius:4px;font-size:13px;color:#0052d9}.cd-ps-search[data-v-0a6760cf]{display:flex;gap:12px;align-items:center}.cd-ps-org-select[data-v-0a6760cf]{flex-shrink:0}.cd-ps-search-input[data-v-0a6760cf]{flex:1}.cd-ps-content[data-v-0a6760cf]{display:flex;gap:0;height:450px;border:1px solid #dfe1e6;border-radius:4px;overflow:hidden}.cd-ps-left[data-v-0a6760cf]{width:480px;flex-shrink:0;border-right:1px solid #dfe1e6;display:flex;flex-direction:column;background-color:#fafafa}.cd-ps-left[data-v-0a6760cf] .t-tabs__nav-container{padding:0 8px;background-color:#fff}.cd-ps-left[data-v-0a6760cf] .t-tabs__content{flex:1;overflow:hidden}.cd-ps-tree[data-v-0a6760cf]{height:100%;overflow-y:auto;padding:8px}.cd-ps-tree[data-v-0a6760cf]::-webkit-scrollbar{width:6px}.cd-ps-tree[data-v-0a6760cf]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-tree[data-v-0a6760cf]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-node[data-v-0a6760cf]{display:flex;align-items:center;gap:6px;font-size:14px;width:100%}[data-v-0a6760cf] .t-tree__label{flex:1}[data-v-0a6760cf] .t-checkbox__label{width:100%}.cd-ps-node-user[data-v-0a6760cf]{font-size:13px;color:#666}.cd-ps-count[data-v-0a6760cf]{color:#999;font-size:12px}.cd-ps-load-btn[data-v-0a6760cf]{margin-left:auto;color:#0052d9;font-size:12px;flex-shrink:0}.cd-ps-empty[data-v-0a6760cf]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;color:#999}.cd-ps-empty p[data-v-0a6760cf]{margin-top:16px;font-size:14px}.cd-ps-search-results[data-v-0a6760cf]{display:flex;flex-direction:column;height:100%}.cd-ps-search-header[data-v-0a6760cf]{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;background:#fff;border-bottom:1px solid #dfe1e6;font-weight:500}.cd-ps-loading[data-v-0a6760cf]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;gap:12px;color:#999}.cd-ps-result-list[data-v-0a6760cf]{flex:1;overflow-y:auto;padding:8px}.cd-ps-result-item[data-v-0a6760cf]{display:flex;align-items:center;gap:10px;padding:10px 12px;background:#fff;border-radius:4px;border:1px solid #e5e7eb;margin-bottom:8px;cursor:pointer;transition:all .2s}.cd-ps-result-item[data-v-0a6760cf]:hover{border-color:#0052d9;background:#f0f5ff}.cd-ps-result-item.cd-ps-selected[data-v-0a6760cf]{border-color:#0052d9;background:#e8f4ff}.cd-ps-avatar[data-v-0a6760cf]{width:32px;height:32px;border-radius:50%;background:#667eea;display:flex;align-items:center;justify-content:center;color:#fff;font-size:16px;flex-shrink:0}.cd-ps-result-item .cd-ps-avatar[data-v-0a6760cf]{width:36px;height:36px}.cd-ps-avatar-dept[data-v-0a6760cf]{background:linear-gradient(135deg,#f5af19,#f12711)}.cd-ps-info[data-v-0a6760cf]{flex:1;min-width:0}.cd-ps-name[data-v-0a6760cf]{font-size:13px;font-weight:500;color:#333;margin-bottom:4px}.cd-ps-result-item .cd-ps-name[data-v-0a6760cf]{font-size:14px}.cd-ps-meta[data-v-0a6760cf]{display:flex;flex-wrap:wrap;gap:6px;font-size:11px;color:#999}.cd-ps-result-item .cd-ps-meta[data-v-0a6760cf]{font-size:12px}.cd-ps-meta span[data-v-0a6760cf]:before{content:"•";margin-right:4px}.cd-ps-meta span[data-v-0a6760cf]:first-child:before{display:none}.cd-ps-right[data-v-0a6760cf]{flex:1;display:flex;flex-direction:column;overflow:hidden;background-color:#fafafa}.cd-ps-right-header[data-v-0a6760cf]{display:flex;align-items:center;padding:12px 16px;border-bottom:1px solid #dfe1e6;background-color:#fff}.cd-ps-title[data-v-0a6760cf]{font-weight:500;font-size:14px;color:#333}.cd-ps-num[data-v-0a6760cf]{font-size:13px;color:#0052d9;font-weight:600;margin-left:8px;flex:1}.cd-ps-right-list[data-v-0a6760cf]{flex:1;overflow-y:auto;padding:8px}.cd-ps-right-list[data-v-0a6760cf]::-webkit-scrollbar{width:6px}.cd-ps-right-list[data-v-0a6760cf]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-right-list[data-v-0a6760cf]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-selected-list[data-v-0a6760cf]{display:flex;flex-direction:column;gap:8px}.cd-ps-selected-item[data-v-0a6760cf]{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#fff;border-radius:4px;border:1px solid #e5e7eb;transition:all .2s}.cd-ps-selected-item[data-v-0a6760cf]:hover{border-color:#0052d9;box-shadow:0 2px 4px #0052d91a}.cd-ps-dept-item[data-v-0a6760cf]{border-color:#f5af19}.cd-ps-item-info[data-v-0a6760cf]{flex:1;min-width:0;display:flex;align-items:center;gap:10px}
1
+ .cd-ps-container[data-v-a0450286]{display:flex;flex-direction:column;gap:16px;min-height:500px}.cd-ps-tips[data-v-a0450286]{display:flex;align-items:center;gap:8px;padding:12px;background-color:#e8f4ff;border-radius:4px;font-size:13px;color:#0052d9}.cd-ps-search[data-v-a0450286]{display:flex;gap:12px;align-items:center}.cd-ps-org-select[data-v-a0450286]{flex-shrink:0}.cd-ps-search-input[data-v-a0450286]{flex:1}.cd-ps-content[data-v-a0450286]{display:flex;gap:0;height:450px;border:1px solid #dfe1e6;border-radius:4px;overflow:hidden}.cd-ps-left[data-v-a0450286]{width:480px;flex-shrink:0;border-right:1px solid #dfe1e6;display:flex;flex-direction:column;background-color:#fafafa}.cd-ps-left[data-v-a0450286] .t-tabs__nav-container{padding:0 8px;background-color:#fff}.cd-ps-left[data-v-a0450286] .t-tabs__content{flex:1;overflow:hidden}.cd-ps-tree[data-v-a0450286]{height:100%;overflow-y:auto;padding:8px}.cd-ps-tree[data-v-a0450286]::-webkit-scrollbar{width:6px}.cd-ps-tree[data-v-a0450286]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-tree[data-v-a0450286]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-node[data-v-a0450286]{display:flex;align-items:center;gap:6px;font-size:14px;width:100%}.cd-ps-node-name[data-v-a0450286]{flex:1;min-width:0;display:flex;align-items:center;gap:6px}.cd-ps-position[data-v-a0450286]{color:#0052d9;font-size:12px;padding:2px 8px;background:#e8f4ff;border-radius:4px;white-space:nowrap;flex-shrink:0}[data-v-a0450286] .t-tree__label{flex:1}[data-v-a0450286] .t-checkbox__label{width:100%}.cd-ps-node-user[data-v-a0450286]{font-size:13px;color:#666}.cd-ps-count[data-v-a0450286]{color:#999;font-size:12px}.cd-ps-load-btn[data-v-a0450286]{margin-left:auto;color:#0052d9;font-size:12px;flex-shrink:0}.cd-ps-empty[data-v-a0450286]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;color:#999}.cd-ps-empty p[data-v-a0450286]{margin-top:16px;font-size:14px}.cd-ps-search-results[data-v-a0450286]{display:flex;flex-direction:column;height:100%}.cd-ps-search-header[data-v-a0450286]{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;background:#fff;border-bottom:1px solid #dfe1e6;font-weight:500}.cd-ps-loading[data-v-a0450286]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;gap:12px;color:#999}.cd-ps-result-list[data-v-a0450286]{flex:1;overflow-y:auto;padding:8px}.cd-ps-result-item[data-v-a0450286]{display:flex;align-items:center;gap:10px;padding:10px 12px;background:#fff;border-radius:4px;border:1px solid #e5e7eb;margin-bottom:8px;cursor:pointer;transition:all .2s}.cd-ps-result-item[data-v-a0450286]:hover{border-color:#0052d9;background:#f0f5ff}.cd-ps-result-item.cd-ps-selected[data-v-a0450286]{border-color:#0052d9;background:#e8f4ff}.cd-ps-avatar[data-v-a0450286]{width:32px;height:32px;border-radius:50%;background:#667eea;display:flex;align-items:center;justify-content:center;color:#fff;font-size:16px;flex-shrink:0}.cd-ps-result-item .cd-ps-avatar[data-v-a0450286]{width:36px;height:36px}.cd-ps-avatar-dept[data-v-a0450286]{background:linear-gradient(135deg,#f5af19,#f12711)}.cd-ps-info[data-v-a0450286]{flex:1;min-width:0}.cd-ps-name[data-v-a0450286]{font-size:13px;font-weight:500;color:#333;margin-bottom:4px}.cd-ps-result-item .cd-ps-name[data-v-a0450286]{font-size:14px}.cd-ps-meta[data-v-a0450286]{display:flex;flex-wrap:wrap;gap:6px;font-size:11px;color:#999}.cd-ps-result-item .cd-ps-meta[data-v-a0450286]{font-size:12px}.cd-ps-meta span[data-v-a0450286]:before{content:"•";margin-right:4px}.cd-ps-meta span[data-v-a0450286]:first-child:before{display:none}.cd-ps-right[data-v-a0450286]{flex:1;display:flex;flex-direction:column;overflow:hidden;background-color:#fafafa}.cd-ps-right-header[data-v-a0450286]{display:flex;align-items:center;padding:12px 16px;border-bottom:1px solid #dfe1e6;background-color:#fff}.cd-ps-title[data-v-a0450286]{font-weight:500;font-size:14px;color:#333}.cd-ps-num[data-v-a0450286]{font-size:13px;color:#0052d9;font-weight:600;margin-left:8px;flex:1}.cd-ps-right-list[data-v-a0450286]{flex:1;overflow-y:auto;padding:8px}.cd-ps-right-list[data-v-a0450286]::-webkit-scrollbar{width:6px}.cd-ps-right-list[data-v-a0450286]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-right-list[data-v-a0450286]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-selected-list[data-v-a0450286]{display:flex;flex-direction:column;gap:8px}.cd-ps-selected-item[data-v-a0450286]{display:flex;align-items:center;justify-content:space-between;padding:10px 12px;background:#fff;border-radius:4px;border:1px solid #e5e7eb;transition:all .2s}.cd-ps-selected-item[data-v-a0450286]:hover{border-color:#0052d9;box-shadow:0 2px 4px #0052d91a}.cd-ps-dept-item[data-v-a0450286]{border-color:#f5af19}.cd-ps-item-info[data-v-a0450286]{flex:1;min-width:0;display:flex;align-items:center;gap:10px}
package/package.json CHANGED
@@ -1,48 +1,47 @@
1
- {
2
- "name": "cd-personselector",
3
- "version": "1.0.8",
4
- "description": "人员选择器组件 - 支持多Tab、树形结构、搜索、懒加载",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "type": "module",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
14
- },
15
- "./style.css": "./dist/style.css"
16
- },
17
- "files": [
18
- "dist",
19
- "src"
20
- ],
21
- "scripts": {
22
- "build": "vite build",
23
- "prepublishOnly": "npm run build"
24
- },
25
- "keywords": [
26
- "vue",
27
- "vue3",
28
- "person-selector",
29
- "tdesign",
30
- "组织架构",
31
- "人员选择"
32
- ],
33
- "author": "",
34
- "license": "MIT",
35
- "peerDependencies": {
36
- "vue": "^3.0.0",
37
- "tdesign-vue-next": "^1.0.0"
38
- },
39
- "devDependencies": {
40
- "@vitejs/plugin-vue": "^5.0.0",
41
- "tdesign-vue-next": "^1.9.0",
42
- "typescript": "^5.0.0",
43
- "vite": "^5.0.0",
44
- "vite-plugin-dts": "^3.0.0",
45
- "vue": "^3.4.0",
46
- "vue-tsc": "^2.0.0"
47
- }
48
- }
1
+ {
2
+ "name": "cd-personselector",
3
+ "version": "1.1.0",
4
+ "description": "人员选择器组件 - 支持多Tab、树形结构、搜索、懒加载",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "type": "module",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./style.css": "./dist/style.css"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "keywords": [
22
+ "vue",
23
+ "vue3",
24
+ "person-selector",
25
+ "tdesign",
26
+ "组织架构",
27
+ "人员选择"
28
+ ],
29
+ "author": "",
30
+ "license": "MIT",
31
+ "peerDependencies": {
32
+ "vue": "^3.0.0",
33
+ "tdesign-vue-next": "^1.0.0"
34
+ },
35
+ "devDependencies": {
36
+ "@vitejs/plugin-vue": "^5.0.0",
37
+ "tdesign-vue-next": "^1.9.0",
38
+ "typescript": "^5.0.0",
39
+ "vite": "^5.0.0",
40
+ "vite-plugin-dts": "^3.0.0",
41
+ "vue": "^3.4.0",
42
+ "vue-tsc": "^2.0.0"
43
+ },
44
+ "scripts": {
45
+ "build": "vite build"
46
+ }
47
+ }
@@ -15,7 +15,7 @@
15
15
  <span>{{ tips }}</span>
16
16
  </div>
17
17
  <div v-if="showSearch" class="cd-ps-search">
18
- <div v-if="organizations.length > 0" class="cd-ps-org-select">
18
+ <div v-if="showOrg && organizations.length > 0" class="cd-ps-org-select">
19
19
  <t-select v-model="selectedOrgId" placeholder="选择组织" style="width: 200px" @change="handleOrgChange">
20
20
  <t-option v-for="org in organizations" :key="org.id" :value="org.id" :label="org.displayName || org.name" />
21
21
  </t-select>
@@ -67,7 +67,10 @@
67
67
  <template #label="{ node }">
68
68
  <div class="cd-ps-node" :class="{ 'cd-ps-node-user': node.data.isUser }">
69
69
  <t-icon :name="node.data.isUser ? 'user' : (tab.icon || 'folder')" />
70
- <span>{{ node.label }}</span>
70
+ <span class="cd-ps-node-name">
71
+ {{ node.label }}
72
+ <span v-if="node.data.isUser && node.data.position" class="cd-ps-position">{{ node.data.position }}</span>
73
+ </span>
71
74
  <span v-if="node.data.userCount && !node.data.isUser" class="cd-ps-count">({{ node.data.userCount }})</span>
72
75
  <t-button v-if="!node.data.isUser && !node.data.children?.length && !node.data.loaded" size="small" variant="text" class="cd-ps-load-btn" @click.stop="handleLoadUsers(node, tab.key)">显示人员</t-button>
73
76
  </div>
@@ -158,6 +161,7 @@ interface Props {
158
161
  dialogWidth?: string;
159
162
  tips?: string;
160
163
  showSearch?: boolean;
164
+ showOrg?: boolean;
161
165
  }
162
166
  const props = withDefaults(defineProps<Props>(), {
163
167
  visible: false,
@@ -167,6 +171,7 @@ const props = withDefaults(defineProps<Props>(), {
167
171
  dialogWidth: '900px',
168
172
  tips: '',
169
173
  showSearch: true,
174
+ showOrg: true,
170
175
  });
171
176
  const emit = defineEmits<{
172
177
  'update:visible': [value: boolean];
@@ -190,6 +195,7 @@ const tabs = computed(() => props.tabs || []);
190
195
  const organizations = computed(() => props.organizations || []);
191
196
  const tips = computed(() => props.tips || '');
192
197
  const showSearch = computed(() => props.showSearch);
198
+ const showOrg = computed(() => props.showOrg);
193
199
  const dialogWidth = computed(() => props.dialogWidth);
194
200
  const internalTreeData = ref<Record<string, TreeNode[]>>({});
195
201
  watch(() => props.tabs, (newTabs) => {
@@ -202,12 +208,40 @@ watch(() => props.tabs, (newTabs) => {
202
208
  }
203
209
  }
204
210
  }, { immediate: true, deep: true });
211
+ // 处理 modelValue 变化的通用函数
212
+ function syncModelValue() {
213
+ if (props.modelValue && props.modelValue.length > 0) {
214
+ const firstItem = props.modelValue[0];
215
+ if (typeof firstItem === 'object' && firstItem !== null && 'id' in firstItem) {
216
+ // 对象数组格式,提取 ID 并缓存完整信息
217
+ selectedIds.value = props.modelValue.map((item: any) => item.id);
218
+ selectedItemsMap.value.clear();
219
+ props.modelValue.forEach((item: any) => {
220
+ selectedItemsMap.value.set(item.id, item);
221
+ });
222
+ } else {
223
+ // ID 数组格式
224
+ selectedIds.value = [...props.modelValue] as (number | string)[];
225
+ // 不清空 selectedItemsMap,保留已有的缓存
226
+ }
227
+ } else {
228
+ selectedIds.value = [];
229
+ selectedItemsMap.value.clear();
230
+ }
231
+ }
232
+ // 监听 modelValue 变化(支持外部动态更新已选项)
233
+ watch(() => props.modelValue, (newVal) => {
234
+ if (dialogVisible.value && newVal) {
235
+ syncModelValue();
236
+ }
237
+ }, { deep: true });
205
238
  watch(() => props.visible, (newVal) => {
206
239
  dialogVisible.value = newVal;
207
240
  if (newVal) {
208
- selectedIds.value = props.modelValue ? [...props.modelValue] : [];
209
- // 清空缓存,重新初始化
210
- selectedItemsMap.value.clear();
241
+ // 支持两种格式的 modelValue
242
+ // 1. ID 数组:[1, 2, 3]
243
+ // 2. 对象数组:[{ id: 1, name: 'xxx', ... }, ...]
244
+ syncModelValue();
211
245
  if (props.organizations.length > 0 && !selectedOrgId.value) {
212
246
  selectedOrgId.value = props.organizations[0].id;
213
247
  }
@@ -225,7 +259,6 @@ function findNodeById(tree: TreeNode[], id: number | string): TreeNode | null {
225
259
  const selectedItems = computed(() => {
226
260
  return selectedIds.value.map(id => selectedItemsMap.value.get(id)).filter(Boolean);
227
261
  });
228
-
229
262
  // 添加选中项到缓存
230
263
  function addSelectedItem(id: number | string, item: any) {
231
264
  if (!selectedIds.value.includes(id)) {
@@ -233,7 +266,6 @@ function addSelectedItem(id: number | string, item: any) {
233
266
  }
234
267
  selectedItemsMap.value.set(id, item);
235
268
  }
236
-
237
269
  // 从缓存移除选中项
238
270
  function removeSelectedItem(id: number | string) {
239
271
  selectedIds.value = selectedIds.value.filter(i => i !== id);
@@ -395,6 +427,8 @@ defineExpose({
395
427
  .cd-ps-tree::-webkit-scrollbar-track { background: #f1f1f1; }
396
428
  .cd-ps-tree::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
397
429
  .cd-ps-node { display: flex; align-items: center; gap: 6px; font-size: 14px; width: 100%; }
430
+ .cd-ps-node-name { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
431
+ .cd-ps-position { color: #0052d9; font-size: 12px; padding: 2px 8px; background: #e8f4ff; border-radius: 4px; white-space: nowrap; flex-shrink: 0; }
398
432
  :deep(.t-tree__label) { flex: 1; }
399
433
  :deep(.t-checkbox__label) { width: 100%; }
400
434
  .cd-ps-node-user { font-size: 13px; color: #666; }