cd-personselector 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -23
- package/dist/index.js +1 -1
- package/dist/index.mjs +226 -220
- package/dist/src/PersonSelector.vue.d.ts +2 -0
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/PersonSelector.vue +58 -27
package/README.md
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
# cd-personselector
|
|
2
|
-
|
|
3
2
|
基于 Vue 3 + TDesign 的人员选择器组件,支持多 Tab、树形结构、搜索、懒加载等功能。
|
|
4
|
-
|
|
5
3
|
## 安装
|
|
6
|
-
|
|
7
4
|
```bash
|
|
8
5
|
npm install cd-personselector
|
|
9
6
|
```
|
|
10
|
-
|
|
11
7
|
## 使用
|
|
12
|
-
|
|
13
8
|
```vue
|
|
14
9
|
<template>
|
|
15
10
|
<PersonSelector
|
|
@@ -21,17 +16,15 @@ npm install cd-personselector
|
|
|
21
16
|
@confirm="handleConfirm"
|
|
22
17
|
@load-users="handleLoadUsers"
|
|
23
18
|
@search="handleSearch"
|
|
19
|
+
@org-change="handleOrgChange"
|
|
24
20
|
/>
|
|
25
21
|
</template>
|
|
26
|
-
|
|
27
22
|
<script setup>
|
|
28
23
|
import { ref } from 'vue'
|
|
29
24
|
import PersonSelector from 'cd-personselector'
|
|
30
25
|
import 'cd-personselector/style.css'
|
|
31
|
-
|
|
32
26
|
const showSelector = ref(false)
|
|
33
27
|
const selectedIds = ref([])
|
|
34
|
-
|
|
35
28
|
const tabs = ref([
|
|
36
29
|
{
|
|
37
30
|
key: 'department',
|
|
@@ -51,29 +44,29 @@ const tabs = ref([
|
|
|
51
44
|
]
|
|
52
45
|
}
|
|
53
46
|
])
|
|
54
|
-
|
|
55
47
|
const organizations = ref([
|
|
56
48
|
{ id: 'org-1', name: '总公司' }
|
|
57
49
|
])
|
|
58
|
-
|
|
59
50
|
function handleConfirm(items) {
|
|
60
51
|
console.log('选中项:', items)
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
function handleLoadUsers({ tabKey, nodeId, callback }) {
|
|
64
54
|
// 异步加载用户数据
|
|
65
55
|
fetchUsers(nodeId).then(users => callback(users))
|
|
66
56
|
}
|
|
67
|
-
|
|
68
57
|
function handleSearch({ keyword, orgId, callback }) {
|
|
69
58
|
// 搜索用户
|
|
70
59
|
searchUsers(keyword).then(users => callback(users))
|
|
71
60
|
}
|
|
61
|
+
function handleOrgChange(orgId) {
|
|
62
|
+
// 切换组织时重新加载 tabs 数据
|
|
63
|
+
loadTabsByOrg(orgId).then(data => {
|
|
64
|
+
tabs.value = data
|
|
65
|
+
})
|
|
66
|
+
}
|
|
72
67
|
</script>
|
|
73
68
|
```
|
|
74
|
-
|
|
75
69
|
## Props
|
|
76
|
-
|
|
77
70
|
| 属性 | 类型 | 默认值 | 说明 |
|
|
78
71
|
|------|------|--------|------|
|
|
79
72
|
| visible | boolean | false | 控制弹窗显示 |
|
|
@@ -83,17 +76,14 @@ function handleSearch({ keyword, orgId, callback }) {
|
|
|
83
76
|
| dialogWidth | string | '900px' | 弹窗宽度 |
|
|
84
77
|
| tips | string | '' | 顶部提示文字 |
|
|
85
78
|
| showSearch | boolean | true | 是否显示搜索 |
|
|
86
|
-
|
|
87
79
|
## Events
|
|
88
|
-
|
|
89
80
|
| 事件 | 参数 | 说明 |
|
|
90
81
|
|------|------|------|
|
|
91
|
-
| confirm | items: any[] |
|
|
82
|
+
| confirm | items: any[] | 确认选择时触发,每项包含 orgId |
|
|
92
83
|
| load-users | { tabKey, nodeId, callback } | 点击"显示人员"时触发 |
|
|
93
84
|
| search | { keyword, orgId, callback } | 搜索时触发 |
|
|
94
|
-
|
|
85
|
+
| org-change | orgId: string\|number | 切换组织时触发,用于重新加载 tabs 数据 |
|
|
95
86
|
## 类型定义
|
|
96
|
-
|
|
97
87
|
```typescript
|
|
98
88
|
interface TabConfig {
|
|
99
89
|
key: string
|
|
@@ -101,7 +91,6 @@ interface TabConfig {
|
|
|
101
91
|
icon?: string
|
|
102
92
|
tree: TreeNode[]
|
|
103
93
|
}
|
|
104
|
-
|
|
105
94
|
interface TreeNode {
|
|
106
95
|
id: number | string
|
|
107
96
|
name: string
|
|
@@ -109,7 +98,6 @@ interface TreeNode {
|
|
|
109
98
|
userCount?: number
|
|
110
99
|
isUser?: boolean
|
|
111
100
|
}
|
|
112
|
-
|
|
113
101
|
interface User {
|
|
114
102
|
id: number | string
|
|
115
103
|
name: string
|
|
@@ -119,8 +107,6 @@ interface User {
|
|
|
119
107
|
department?: string
|
|
120
108
|
}
|
|
121
109
|
```
|
|
122
|
-
|
|
123
110
|
## 依赖
|
|
124
|
-
|
|
125
111
|
- vue >= 3.0.0
|
|
126
112
|
- tdesign-vue-next >= 1.0.0
|
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 q={class:"cd-ps-container"},A={key:0,class:"cd-ps-tips"},G={key:1,class:"cd-ps-search"},H={key:0,class:"cd-ps-org-select"},Q={class:"cd-ps-search-input"},X={class:"cd-ps-content"},Y={class:"cd-ps-left"},Z={key:0,class:"cd-ps-search-results"},K={class:"cd-ps-search-header"},v={key:0,class:"cd-ps-loading"},ee={key:1,class:"cd-ps-empty"},te={key:2,class:"cd-ps-result-list"},oe=["onClick"],le={class:"cd-ps-avatar"},ne={class:"cd-ps-info"},se={class:"cd-ps-name"},ae={class:"cd-ps-meta"},ce={key:0},de={key:1},re={key:2},ie={class:"cd-ps-tree"},pe={key:0,class:"cd-ps-count"},me={key:1,class:"cd-ps-empty"},fe={class:"cd-ps-right"},ke={class:"cd-ps-right-header"},he={class:"cd-ps-num"},_e={class:"cd-ps-right-list"},ye={key:0,class:"cd-ps-empty"},Ne={key:1,class:"cd-ps-selected-list"},Ve={class:"cd-ps-item-info"},Ce={class:"cd-ps-info"},Be={class:"cd-ps-name"},ue={class:"cd-ps-meta"},ge={key:0},Ee={key:1},Se={key:2},xe={key:3},R=((y,w)=>{const x=y.__vccOpts||y;for(const[d,k]of w)x[d]=k;return x})(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"],setup(y,{expose:w,emit:x}){var $,j;const d=y,k=x,N=e.ref(d.visible),V=e.ref(((j=($=d.tabs)==null?void 0:$[0])==null?void 0:j.key)||""),g=e.ref(null),C=e.ref(""),a=e.ref([]),D=e.ref({}),T=e.ref(!1),b=e.ref(!1),B=e.ref([]),Ue=e.computed(()=>d.tabs||[]),L=e.computed(()=>d.organizations||[]),M=e.computed(()=>d.tips||""),we=e.computed(()=>d.showSearch),De=e.computed(()=>d.dialogWidth),h=e.ref({});e.watch(()=>d.tabs,n=>{if(n&&n.length>0){const t={};n.forEach(l=>{t[l.key]=JSON.parse(JSON.stringify(l.tree))}),h.value=t,(!V.value||!n.find(l=>l.key===V.value))&&(V.value=n[0].key)}},{immediate:!0,deep:!0}),e.watch(()=>d.visible,n=>{N.value=n,n&&(a.value=d.modelValue?[...d.modelValue]:[],d.organizations.length>0&&!g.value&&(g.value=d.organizations[0].id))}),e.watch(N,n=>{k("update:visible",n)});function Te(n,t){t&&(D.value[n]=t)}function z(n,t){for(const l of n){if(l.id===t)return l;if(l.children){const s=z(l.children,t);if(s)return s}}return null}const E=e.computed(()=>{const n=[];return a.value.forEach(t=>{const l=B.value.find(s=>s.id===t);if(l){n.push({...l,typeName:"搜索结果"});return}for(const s of d.tabs){const i=h.value[s.key]||[],p=z(i,t);if(p){const c=s.name.replace(/^按/,"");n.push({...p,typeName:c});break}}}),n}),ze=()=>{C.value=""},Ie=()=>{};let u=null;const Pe=()=>{if(u&&clearTimeout(u),!C.value.trim()){I();return}T.value=!0,b.value=!0,u=setTimeout(()=>Oe(),300)},Oe=()=>{B.value=[];const n=t=>{B.value=t.map(l=>({...l,isUser:!0})),b.value=!1};k("search",{keyword:C.value,orgId:g.value||void 0,callback:n})},I=()=>{u&&(clearTimeout(u),u=null),T.value=!1,C.value="",B.value=[],b.value=!1},Re=n=>{const t=a.value.indexOf(n.id);t>-1?a.value.splice(t,1):a.value.push(n.id)};function Le(n){const t=[],l=s=>{for(const i of s)t.push(i.id),i.children&&l(i.children)};return l(n),t}const Me=(n,t)=>{var c;const l=t==null?void 0:t.node;if(l){const r=l.value??((c=l.data)==null?void 0:c.id);if(r!==void 0){l.checked?a.value.includes(r)||(a.value=[...a.value,r]):a.value=a.value.filter(S=>S!==r);return}}const s=h.value[V.value]||[],i=Le(s),p=a.value.filter(r=>!i.includes(r));a.value=[...p,...n]};function F(n,t,l){for(const s of n){if(s.id===t)return s.children=s.children||[],s.children.push(...l),s.loaded=!0,!0;if(s.children&&F(s.children,t,l))return!0}return!1}async function Fe(n,t){const l=n.value,s=D.value[t];k("load-users",{tabKey:t,nodeId:l,node:n,callback:async p=>{if(p.length>0){const c=p.map(_=>{const{id:S,name:P,...O}=_;return{...O,id:S,name:_.displayName||P,isUser:!0}}),r=h.value[t];if(r&&F(r,l,c),s){s.appendTo(l,c),n.data.loaded=!0,await e.nextTick();try{s.setItem(l,{expanded:!0})}catch{}}}else{n.data.loaded=!0;const c=h.value[t];if(c){const r=z(c,l);r&&(r.loaded=!0)}}}})}const We=n=>{a.value=a.value.filter(t=>t!==n)},W=()=>{a.value=[]},$e=()=>{k("update:modelValue",a.value),k("confirm",E.value),N.value=!1},je=()=>{N.value=!1};return w({clearSelection:W,appendUsers:(n,t,l)=>{const s=D.value[n];if(s&&l.length>0){const i=l.map(p=>{const{id:c,name:r,..._}=p;return{..._,id:c,name:p.displayName||r,isUser:!0}});s.appendTo(t,i)}}}),(n,t)=>{const l=e.resolveComponent("t-icon"),s=e.resolveComponent("t-option"),i=e.resolveComponent("t-select"),p=e.resolveComponent("t-input"),c=e.resolveComponent("t-button"),r=e.resolveComponent("t-loading"),_=e.resolveComponent("t-checkbox"),S=e.resolveComponent("t-tree"),P=e.resolveComponent("t-tab-panel"),O=e.resolveComponent("t-tabs"),Je=e.resolveComponent("t-dialog");return e.openBlock(),e.createBlock(Je,{visible:N.value,"onUpdate:visible":t[4]||(t[4]=o=>N.value=o),header:"选择人员",width:De.value,footer:!0,placement:"center","destroy-on-close":"",onConfirm:$e,onClose:je},{default:e.withCtx(()=>[e.createElementVNode("div",q,[M.value?(e.openBlock(),e.createElementBlock("div",A,[e.createVNode(l,{name:"info-circle"}),e.createElementVNode("span",null,e.toDisplayString(M.value),1)])):e.createCommentVNode("",!0),we.value?(e.openBlock(),e.createElementBlock("div",G,[L.value.length>0?(e.openBlock(),e.createElementBlock("div",H,[e.createVNode(i,{modelValue:g.value,"onUpdate:modelValue":t[0]||(t[0]=o=>g.value=o),placeholder:"选择组织",style:{width:"200px"},onChange:Ie},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(L.value,o=>(e.openBlock(),e.createBlock(s,{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",Q,[e.createVNode(p,{modelValue:C.value,"onUpdate:modelValue":t[1]||(t[1]=o=>C.value=o),placeholder:"输入手机号/工号/姓名/部门/职位搜索",clearable:"",onInput:Pe,onClear:I},{"prefix-icon":e.withCtx(()=>[e.createVNode(l,{name:"search"})]),_:1},8,["modelValue"])])])):e.createCommentVNode("",!0),e.createElementVNode("div",X,[e.createElementVNode("div",Y,[T.value?(e.openBlock(),e.createElementBlock("div",Z,[e.createElementVNode("div",K,[t[6]||(t[6]=e.createElementVNode("span",null,"搜索结果",-1)),e.createVNode(c,{size:"small",variant:"text",onClick:I},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("返回",-1)])]),_:1})]),b.value?(e.openBlock(),e.createElementBlock("div",v,[e.createVNode(r),t[7]||(t[7]=e.createElementVNode("span",null,"搜索中...",-1))])):B.value.length===0?(e.openBlock(),e.createElementBlock("div",ee,[e.createVNode(l,{name:"search",size:"48px",style:{color:"#ddd"}}),t[8]||(t[8]=e.createElementVNode("p",null,"未找到匹配的人员",-1))])):(e.openBlock(),e.createElementBlock("div",te,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,o=>(e.openBlock(),e.createElementBlock("div",{key:o.id,class:e.normalizeClass(["cd-ps-result-item",{"cd-ps-selected":a.value.includes(o.id)}]),onClick:U=>Re(o)},[e.createVNode(_,{checked:a.value.includes(o.id),onClick:t[2]||(t[2]=e.withModifiers(()=>{},["stop"]))},null,8,["checked"]),e.createElementVNode("div",le,[e.createVNode(l,{name:"user"})]),e.createElementVNode("div",ne,[e.createElementVNode("div",se,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",ae,[o.position?(e.openBlock(),e.createElementBlock("span",ce,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.department?(e.openBlock(),e.createElementBlock("span",de,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.phone?(e.openBlock(),e.createElementBlock("span",re,e.toDisplayString(o.phone),1)):e.createCommentVNode("",!0)])])],10,oe))),128))]))])):(e.openBlock(),e.createBlock(O,{key:1,modelValue:V.value,"onUpdate:modelValue":t[3]||(t[3]=o=>V.value=o),onChange:ze},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Ue.value,o=>(e.openBlock(),e.createBlock(P,{key:o.key,value:o.key,label:o.name},{default:e.withCtx(()=>{var U;return[e.createElementVNode("div",ie,[((U=h.value[o.key])==null?void 0:U.length)>0?(e.openBlock(),e.createBlock(S,{key:0,ref_for:!0,ref:m=>Te(o.key,m),data:h.value[o.key],keys:{value:"id",label:"name",children:"children"},hover:"",checkable:"","expand-all":!1,value:a.value,onChange:Me},{label:e.withCtx(({node:m})=>{var J;return[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-node",{"cd-ps-node-user":m.data.isUser}])},[e.createVNode(l,{name:m.data.isUser?"user":o.icon||"folder"},null,8,["name"]),e.createElementVNode("span",null,e.toDisplayString(m.label),1),m.data.userCount&&!m.data.isUser?(e.openBlock(),e.createElementBlock("span",pe,"("+e.toDisplayString(m.data.userCount)+")",1)):e.createCommentVNode("",!0),!m.data.isUser&&!((J=m.data.children)!=null&&J.length)&&!m.data.loaded?(e.openBlock(),e.createBlock(c,{key:1,size:"small",variant:"text",class:"cd-ps-load-btn",onClick:e.withModifiers(Ge=>Fe(m,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",me,[e.createVNode(l,{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",fe,[e.createElementVNode("div",ke,[t[12]||(t[12]=e.createElementVNode("span",{class:"cd-ps-title"},"已选择",-1)),e.createElementVNode("span",he,e.toDisplayString(E.value.length)+" 项",1),E.value.length>0?(e.openBlock(),e.createBlock(c,{key:0,size:"small",variant:"text",onClick:W},{default:e.withCtx(()=>[...t[11]||(t[11]=[e.createTextVNode("清空",-1)])]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",_e,[E.value.length===0?(e.openBlock(),e.createElementBlock("div",ye,[e.createVNode(l,{name:"user-checked",size:"64px",style:{color:"#ddd"}}),t[13]||(t[13]=e.createElementVNode("p",null,"暂无选择",-1))])):(e.openBlock(),e.createElementBlock("div",Ne,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(E.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",Ve,[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-avatar",{"cd-ps-avatar-dept":!o.isUser}])},[e.createVNode(l,{name:o.isUser?"user":"folder"},null,8,["name"])],2),e.createElementVNode("div",Ce,[e.createElementVNode("div",Be,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",ue,[o.isUser&&o.position?(e.openBlock(),e.createElementBlock("span",ge,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.isUser&&o.department?(e.openBlock(),e.createElementBlock("span",Ee,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.isUser?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",Se,e.toDisplayString(o.typeName||"部门"),1)),!o.isUser&&o.userCount?(e.openBlock(),e.createElementBlock("span",xe,e.toDisplayString(o.userCount)+"人",1)):e.createCommentVNode("",!0)])])]),e.createVNode(c,{size:"small",variant:"text",shape:"circle",onClick:U=>We(o.id)},{icon:e.withCtx(()=>[e.createVNode(l,{name:"close"})]),_:1},8,["onClick"])],2))),128))]))])])])])]),_:1},8,["visible","width"])}}}),[["__scopeId","data-v-91e8592b"]]),be={install(y){y.component("PersonSelector",R)}};f.PersonSelector=R,f.default=be,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 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"},he={key:0,class:"cd-ps-count"},ke={key:1,class:"cd-ps-empty"},_e={class:"cd-ps-right"},ye={class:"cd-ps-right-header"},Ve={class:"cd-ps-num"},Ne={class:"cd-ps-right-list"},ue={key:0,class:"cd-ps-empty"},ge={key:1,class:"cd-ps-selected-list"},Ce={class:"cd-ps-item-info"},Be={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=((u,T)=>{const U=u.__vccOpts||u;for(const[s,h]of T)U[s]=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}},emits:["update:visible","update:modelValue","confirm","load-users","search","org-change"],setup(u,{expose:T,emit:U}){var q,A;const s=u,h=U,g=e.ref(s.visible),_=e.ref(((A=(q=s.tabs)==null?void 0:q[0])==null?void 0:A.key)||""),y=e.ref(null),C=e.ref(""),c=e.ref([]),k=e.ref(new Map),z=e.ref({}),P=e.ref(!1),I=e.ref(!1),S=e.ref([]),De=e.computed(()=>s.tabs||[]),L=e.computed(()=>s.organizations||[]),F=e.computed(()=>s.tips||""),Te=e.computed(()=>s.showSearch),ze=e.computed(()=>s.dialogWidth),V=e.ref({});e.watch(()=>s.tabs,n=>{if(n&&n.length>0){const t={};n.forEach(l=>{t[l.key]=JSON.parse(JSON.stringify(l.tree))}),V.value=t,(!_.value||!n.find(l=>l.key===_.value))&&(_.value=n[0].key)}},{immediate:!0,deep:!0}),e.watch(()=>s.visible,n=>{if(g.value=n,n){if(s.modelValue&&s.modelValue.length>0){const t=s.modelValue[0];typeof t=="object"&&t!==null&&"id"in t?(c.value=s.modelValue.map(l=>l.id),k.value.clear(),s.modelValue.forEach(l=>{k.value.set(l.id,l)})):(c.value=[...s.modelValue],k.value.clear())}else c.value=[],k.value.clear();s.organizations.length>0&&!y.value&&(y.value=s.organizations[0].id)}}),e.watch(g,n=>{h("update:visible",n)});function Pe(n,t){t&&(z.value[n]=t)}function j(n,t){for(const l of n){if(l.id===t)return l;if(l.children){const a=j(l.children,t);if(a)return a}}return null}const x=e.computed(()=>c.value.map(n=>k.value.get(n)).filter(Boolean));function W(n,t){c.value.includes(n)||c.value.push(n),k.value.set(n,t)}function M(n){c.value=c.value.filter(t=>t!==n),k.value.delete(n)}const Me=()=>{C.value=""},Oe=n=>{const t={};s.tabs.forEach(l=>{t[l.key]=[]}),V.value=t,h("org-change",n)};let B=null;const Re=()=>{if(B&&clearTimeout(B),!C.value.trim()){O();return}P.value=!0,I.value=!0,B=setTimeout(()=>Le(),300)},Le=()=>{S.value=[];const n=t=>{S.value=t.map(l=>({...l,isUser:!0})),I.value=!1};h("search",{keyword:C.value,orgId:y.value||void 0,callback:n})},O=()=>{B&&(clearTimeout(B),B=null),P.value=!1,C.value="",S.value=[],I.value=!1},Fe=n=>{c.value.indexOf(n.id)>-1?M(n.id):W(n.id,{...n,isUser:!0,typeName:"搜索结果",orgId:y.value})};function je(n){const t=[],l=a=>{for(const p of a)t.push(p.id),p.children&&l(p.children)};return l(n),t}const We=(n,t)=>{var d;const l=t==null?void 0:t.node;if(l){const r=l.value??((d=l.data)==null?void 0:d.id);if(r!==void 0){if(l.checked){const E=s.tabs.find(w=>w.key===_.value),b=E?E.name.replace(/^按/,""):"";W(r,{...l.data,typeName:b,orgId:y.value})}else M(r);return}}const a=V.value[_.value]||[],p=je(a),m=c.value.filter(r=>!p.includes(r));c.value=[...m,...n]};function $(n,t,l){for(const a of n){if(a.id===t)return a.children=a.children||[],a.children.push(...l),a.loaded=!0,!0;if(a.children&&$(a.children,t,l))return!0}return!1}async function $e(n,t){const l=n.value,a=z.value[t];h("load-users",{tabKey:t,nodeId:l,node:n,callback:async m=>{if(m.length>0){const d=m.map(N=>{const{id:E,name:b,...w}=N;return{...w,id:E,name:N.displayName||b,isUser:!0}}),r=V.value[t];if(r&&$(r,l,d),a){a.appendTo(l,d),n.data.loaded=!0,await e.nextTick();try{a.setItem(l,{expanded:!0})}catch{}}}else{n.data.loaded=!0;const d=V.value[t];if(d){const r=j(d,l);r&&(r.loaded=!0)}}}})}const Je=n=>{M(n)},J=()=>{c.value=[],k.value.clear()},qe=()=>{h("update:modelValue",c.value),h("confirm",x.value),g.value=!1},Ae=()=>{g.value=!1};return T({clearSelection:J,appendUsers:(n,t,l)=>{const a=z.value[n];if(a&&l.length>0){const p=l.map(m=>{const{id:d,name:r,...N}=m;return{...N,id:d,name:m.displayName||r,isUser:!0}});a.appendTo(t,p)}}}),(n,t)=>{const l=e.resolveComponent("t-icon"),a=e.resolveComponent("t-option"),p=e.resolveComponent("t-select"),m=e.resolveComponent("t-input"),d=e.resolveComponent("t-button"),r=e.resolveComponent("t-loading"),N=e.resolveComponent("t-checkbox"),E=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(l,{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:y.value,"onUpdate:modelValue":t[0]||(t[0]=o=>y.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(l,{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(d,{size:"small",variant:"text",onClick:O},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("返回",-1)])]),_:1})]),I.value?(e.openBlock(),e.createElementBlock("div",oe,[e.createVNode(r),t[7]||(t[7]=e.createElementVNode("span",null,"搜索中...",-1))])):S.value.length===0?(e.openBlock(),e.createElementBlock("div",le,[e.createVNode(l,{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":c.value.includes(o.id)}]),onClick:D=>Fe(o)},[e.createVNode(N,{checked:c.value.includes(o.id),onClick:t[2]||(t[2]=e.withModifiers(()=>{},["stop"]))},null,8,["checked"]),e.createElementVNode("div",se,[e.createVNode(l,{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:_.value,"onUpdate:modelValue":t[3]||(t[3]=o=>_.value=o),onChange:Me},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(De.value,o=>(e.openBlock(),e.createBlock(b,{key:o.key,value:o.key,label:o.name},{default:e.withCtx(()=>{var D;return[e.createElementVNode("div",fe,[((D=V.value[o.key])==null?void 0:D.length)>0?(e.openBlock(),e.createBlock(E,{key:0,ref_for:!0,ref:i=>Pe(o.key,i),data:V.value[o.key],keys:{value:"id",label:"name",children:"children"},hover:"",checkable:"","expand-all":!1,value:c.value,onChange:We},{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(l,{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",he,"("+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(d,{key:1,size:"small",variant:"text",class:"cd-ps-load-btn",onClick:e.withModifiers(Xe=>$e(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",ke,[e.createVNode(l,{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",Ve,e.toDisplayString(x.value.length)+" 项",1),x.value.length>0?(e.openBlock(),e.createBlock(d,{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",Ne,[x.value.length===0?(e.openBlock(),e.createElementBlock("div",ue,[e.createVNode(l,{name:"user-checked",size:"64px",style:{color:"#ddd"}}),t[13]||(t[13]=e.createElementVNode("p",null,"暂无选择",-1))])):(e.openBlock(),e.createElementBlock("div",ge,[(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",Ce,[e.createElementVNode("div",{class:e.normalizeClass(["cd-ps-avatar",{"cd-ps-avatar-dept":!o.isUser}])},[e.createVNode(l,{name:o.isUser?"user":"folder"},null,8,["name"])],2),e.createElementVNode("div",Be,[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(d,{size:"small",variant:"text",shape:"circle",onClick:D=>Je(o.id)},{icon:e.withCtx(()=>[e.createVNode(l,{name:"close"})]),_:1},8,["onClick"])],2))),128))]))])])])])]),_:1},8,["visible","width"])}}}),[["__scopeId","data-v-e9913ad1"]]),Ie={install(u){u.component("PersonSelector",R)}};f.PersonSelector=R,f.default=Ie,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const
|
|
1
|
+
import { defineComponent as Ve, ref as m, computed as D, watch as Q, resolveComponent as _, createBlock as I, openBlock as a, withCtx as y, createElementVNode as n, createElementBlock as o, createCommentVNode as v, createVNode as p, toDisplayString as h, Fragment as $, renderList as J, createTextVNode as X, normalizeClass as j, withModifiers as oe, nextTick as Ne } from "vue";
|
|
2
|
+
const Ue = { class: "cd-ps-container" }, xe = {
|
|
3
3
|
key: 0,
|
|
4
4
|
class: "cd-ps-tips"
|
|
5
|
-
},
|
|
5
|
+
}, Ie = {
|
|
6
6
|
key: 1,
|
|
7
7
|
class: "cd-ps-search"
|
|
8
|
-
},
|
|
8
|
+
}, Se = {
|
|
9
9
|
key: 0,
|
|
10
10
|
class: "cd-ps-org-select"
|
|
11
|
-
},
|
|
11
|
+
}, ze = { class: "cd-ps-search-input" }, Te = { class: "cd-ps-content" }, we = { class: "cd-ps-left" }, Be = {
|
|
12
12
|
key: 0,
|
|
13
13
|
class: "cd-ps-search-results"
|
|
14
|
-
},
|
|
14
|
+
}, De = { class: "cd-ps-search-header" }, Re = {
|
|
15
15
|
key: 0,
|
|
16
16
|
class: "cd-ps-loading"
|
|
17
|
-
},
|
|
17
|
+
}, Oe = {
|
|
18
18
|
key: 1,
|
|
19
19
|
class: "cd-ps-empty"
|
|
20
|
-
},
|
|
20
|
+
}, Ee = {
|
|
21
21
|
key: 2,
|
|
22
22
|
class: "cd-ps-result-list"
|
|
23
|
-
},
|
|
23
|
+
}, Pe = ["onClick"], Me = { class: "cd-ps-avatar" }, Le = { class: "cd-ps-info" }, We = { class: "cd-ps-name" }, $e = { class: "cd-ps-meta" }, Je = { key: 0 }, je = { key: 1 }, Ae = { key: 2 }, Fe = { class: "cd-ps-tree" }, qe = {
|
|
24
24
|
key: 0,
|
|
25
25
|
class: "cd-ps-count"
|
|
26
|
-
},
|
|
26
|
+
}, Ge = {
|
|
27
27
|
key: 1,
|
|
28
28
|
class: "cd-ps-empty"
|
|
29
|
-
},
|
|
29
|
+
}, He = { class: "cd-ps-right" }, Qe = { class: "cd-ps-right-header" }, Xe = { class: "cd-ps-num" }, Ye = { class: "cd-ps-right-list" }, Ze = {
|
|
30
30
|
key: 0,
|
|
31
31
|
class: "cd-ps-empty"
|
|
32
|
-
},
|
|
32
|
+
}, Ke = {
|
|
33
33
|
key: 1,
|
|
34
34
|
class: "cd-ps-selected-list"
|
|
35
|
-
},
|
|
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__ */ Ve({
|
|
36
36
|
__name: "PersonSelector",
|
|
37
37
|
props: {
|
|
38
38
|
visible: { type: Boolean, default: !1 },
|
|
@@ -43,180 +43,186 @@ const be = { class: "cd-ps-container" }, Ne = {
|
|
|
43
43
|
tips: { default: "" },
|
|
44
44
|
showSearch: { type: Boolean, default: !0 }
|
|
45
45
|
},
|
|
46
|
-
emits: ["update:visible", "update:modelValue", "confirm", "load-users", "search"],
|
|
47
|
-
setup(
|
|
48
|
-
var
|
|
49
|
-
const
|
|
50
|
-
|
|
46
|
+
emits: ["update:visible", "update:modelValue", "confirm", "load-users", "search", "org-change"],
|
|
47
|
+
setup(S, { expose: A, emit: M }) {
|
|
48
|
+
var le, ae;
|
|
49
|
+
const c = S, C = M, z = m(c.visible), V = m(((ae = (le = c.tabs) == null ? void 0 : le[0]) == null ? void 0 : ae.key) || ""), N = m(null), T = m(""), i = m([]), b = m(/* @__PURE__ */ new Map()), F = m({}), q = m(!1), L = m(!1), R = m([]), de = D(() => c.tabs || []), Y = D(() => c.organizations || []), Z = D(() => c.tips || ""), ce = D(() => c.showSearch), ie = D(() => c.dialogWidth), U = m({});
|
|
50
|
+
Q(() => c.tabs, (l) => {
|
|
51
51
|
if (l && l.length > 0) {
|
|
52
52
|
const e = {};
|
|
53
53
|
l.forEach((s) => {
|
|
54
54
|
e[s.key] = JSON.parse(JSON.stringify(s.tree));
|
|
55
|
-
}),
|
|
55
|
+
}), U.value = e, (!V.value || !l.find((s) => s.key === V.value)) && (V.value = l[0].key);
|
|
56
56
|
}
|
|
57
|
-
}, { immediate: !0, deep: !0 }),
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
}, { immediate: !0, deep: !0 }), Q(() => c.visible, (l) => {
|
|
58
|
+
if (z.value = l, l) {
|
|
59
|
+
if (c.modelValue && c.modelValue.length > 0) {
|
|
60
|
+
const e = c.modelValue[0];
|
|
61
|
+
typeof e == "object" && e !== null && "id" in e ? (i.value = c.modelValue.map((s) => s.id), b.value.clear(), c.modelValue.forEach((s) => {
|
|
62
|
+
b.value.set(s.id, s);
|
|
63
|
+
})) : (i.value = [...c.modelValue], b.value.clear());
|
|
64
|
+
} else
|
|
65
|
+
i.value = [], b.value.clear();
|
|
66
|
+
c.organizations.length > 0 && !N.value && (N.value = c.organizations[0].id);
|
|
67
|
+
}
|
|
68
|
+
}), Q(z, (l) => {
|
|
60
69
|
C("update:visible", l);
|
|
61
70
|
});
|
|
62
|
-
function
|
|
63
|
-
e && (
|
|
71
|
+
function re(l, e) {
|
|
72
|
+
e && (F.value[l] = e);
|
|
64
73
|
}
|
|
65
|
-
function
|
|
74
|
+
function K(l, e) {
|
|
66
75
|
for (const s of l) {
|
|
67
76
|
if (s.id === e) return s;
|
|
68
77
|
if (s.children) {
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
78
|
+
const d = K(s.children, e);
|
|
79
|
+
if (d) return d;
|
|
71
80
|
}
|
|
72
81
|
}
|
|
73
82
|
return null;
|
|
74
83
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}), l;
|
|
92
|
-
}), ie = () => {
|
|
93
|
-
I.value = "";
|
|
94
|
-
}, ce = () => {
|
|
84
|
+
const O = D(() => i.value.map((l) => b.value.get(l)).filter(Boolean));
|
|
85
|
+
function ee(l, e) {
|
|
86
|
+
i.value.includes(l) || i.value.push(l), b.value.set(l, e);
|
|
87
|
+
}
|
|
88
|
+
function G(l) {
|
|
89
|
+
i.value = i.value.filter((e) => e !== l), b.value.delete(l);
|
|
90
|
+
}
|
|
91
|
+
const ue = () => {
|
|
92
|
+
T.value = "";
|
|
93
|
+
}, pe = (l) => {
|
|
94
|
+
const e = {};
|
|
95
|
+
c.tabs.forEach((s) => {
|
|
96
|
+
e[s.key] = [];
|
|
97
|
+
}), U.value = e, C("org-change", l);
|
|
95
98
|
};
|
|
96
|
-
let
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
|
|
99
|
+
let w = null;
|
|
100
|
+
const ve = () => {
|
|
101
|
+
if (w && clearTimeout(w), !T.value.trim()) {
|
|
102
|
+
H();
|
|
100
103
|
return;
|
|
101
104
|
}
|
|
102
|
-
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
+
q.value = !0, L.value = !0, w = setTimeout(() => he(), 300);
|
|
106
|
+
}, he = () => {
|
|
107
|
+
R.value = [];
|
|
105
108
|
const l = (e) => {
|
|
106
|
-
|
|
109
|
+
R.value = e.map((s) => ({ ...s, isUser: !0 })), L.value = !1;
|
|
107
110
|
};
|
|
108
|
-
C("search", { keyword:
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
e > -1 ? i.value.splice(e, 1) : i.value.push(l.id);
|
|
111
|
+
C("search", { keyword: T.value, orgId: N.value || void 0, callback: l });
|
|
112
|
+
}, H = () => {
|
|
113
|
+
w && (clearTimeout(w), w = null), q.value = !1, T.value = "", R.value = [], L.value = !1;
|
|
114
|
+
}, fe = (l) => {
|
|
115
|
+
i.value.indexOf(l.id) > -1 ? G(l.id) : ee(l.id, { ...l, isUser: !0, typeName: "搜索结果", orgId: N.value });
|
|
114
116
|
};
|
|
115
|
-
function
|
|
116
|
-
const e = [], s = (
|
|
117
|
-
for (const
|
|
118
|
-
e.push(
|
|
117
|
+
function me(l) {
|
|
118
|
+
const e = [], s = (d) => {
|
|
119
|
+
for (const k of d)
|
|
120
|
+
e.push(k.id), k.children && s(k.children);
|
|
119
121
|
};
|
|
120
122
|
return s(l), e;
|
|
121
123
|
}
|
|
122
|
-
const
|
|
123
|
-
var
|
|
124
|
+
const _e = (l, e) => {
|
|
125
|
+
var r;
|
|
124
126
|
const s = e == null ? void 0 : e.node;
|
|
125
127
|
if (s) {
|
|
126
|
-
const u = s.value ?? ((
|
|
128
|
+
const u = s.value ?? ((r = s.data) == null ? void 0 : r.id);
|
|
127
129
|
if (u !== void 0) {
|
|
128
|
-
s.checked
|
|
130
|
+
if (s.checked) {
|
|
131
|
+
const B = c.tabs.find((P) => P.key === V.value), E = B ? B.name.replace(/^按/, "") : "";
|
|
132
|
+
ee(u, { ...s.data, typeName: E, orgId: N.value });
|
|
133
|
+
} else
|
|
134
|
+
G(u);
|
|
129
135
|
return;
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
|
-
const
|
|
133
|
-
i.value = [...
|
|
138
|
+
const d = U.value[V.value] || [], k = me(d), g = i.value.filter((u) => !k.includes(u));
|
|
139
|
+
i.value = [...g, ...l];
|
|
134
140
|
};
|
|
135
|
-
function
|
|
136
|
-
for (const
|
|
137
|
-
if (
|
|
138
|
-
return
|
|
139
|
-
if (
|
|
141
|
+
function te(l, e, s) {
|
|
142
|
+
for (const d of l) {
|
|
143
|
+
if (d.id === e)
|
|
144
|
+
return d.children = d.children || [], d.children.push(...s), d.loaded = !0, !0;
|
|
145
|
+
if (d.children && te(d.children, e, s))
|
|
140
146
|
return !0;
|
|
141
147
|
}
|
|
142
148
|
return !1;
|
|
143
149
|
}
|
|
144
|
-
async function
|
|
145
|
-
const s = l.value,
|
|
146
|
-
C("load-users", { tabKey: e, nodeId: s, node: l, callback: async (
|
|
147
|
-
if (
|
|
148
|
-
const
|
|
149
|
-
const { id: B, name:
|
|
150
|
-
return { ...
|
|
151
|
-
}), u =
|
|
152
|
-
if (u &&
|
|
153
|
-
|
|
150
|
+
async function ke(l, e) {
|
|
151
|
+
const s = l.value, d = F.value[e];
|
|
152
|
+
C("load-users", { tabKey: e, nodeId: s, node: l, callback: async (g) => {
|
|
153
|
+
if (g.length > 0) {
|
|
154
|
+
const r = g.map((x) => {
|
|
155
|
+
const { id: B, name: E, ...P } = x;
|
|
156
|
+
return { ...P, id: B, name: x.displayName || E, isUser: !0 };
|
|
157
|
+
}), u = U.value[e];
|
|
158
|
+
if (u && te(u, s, r), d) {
|
|
159
|
+
d.appendTo(s, r), l.data.loaded = !0, await Ne();
|
|
154
160
|
try {
|
|
155
|
-
|
|
161
|
+
d.setItem(s, { expanded: !0 });
|
|
156
162
|
} catch {
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
} else {
|
|
160
166
|
l.data.loaded = !0;
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
const u =
|
|
167
|
+
const r = U.value[e];
|
|
168
|
+
if (r) {
|
|
169
|
+
const u = K(r, s);
|
|
164
170
|
u && (u.loaded = !0);
|
|
165
171
|
}
|
|
166
172
|
}
|
|
167
173
|
} });
|
|
168
174
|
}
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
},
|
|
172
|
-
i.value = [];
|
|
173
|
-
},
|
|
174
|
-
C("update:modelValue", i.value), C("confirm",
|
|
175
|
-
},
|
|
176
|
-
|
|
175
|
+
const ye = (l) => {
|
|
176
|
+
G(l);
|
|
177
|
+
}, se = () => {
|
|
178
|
+
i.value = [], b.value.clear();
|
|
179
|
+
}, ge = () => {
|
|
180
|
+
C("update:modelValue", i.value), C("confirm", O.value), z.value = !1;
|
|
181
|
+
}, Ce = () => {
|
|
182
|
+
z.value = !1;
|
|
177
183
|
};
|
|
178
|
-
return
|
|
179
|
-
clearSelection:
|
|
184
|
+
return A({
|
|
185
|
+
clearSelection: se,
|
|
180
186
|
appendUsers: (l, e, s) => {
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
const
|
|
184
|
-
const { id:
|
|
185
|
-
return { ...
|
|
187
|
+
const d = F.value[l];
|
|
188
|
+
if (d && s.length > 0) {
|
|
189
|
+
const k = s.map((g) => {
|
|
190
|
+
const { id: r, name: u, ...x } = g;
|
|
191
|
+
return { ...x, id: r, name: g.displayName || u, isUser: !0 };
|
|
186
192
|
});
|
|
187
|
-
|
|
193
|
+
d.appendTo(e, k);
|
|
188
194
|
}
|
|
189
195
|
}
|
|
190
196
|
}), (l, e) => {
|
|
191
|
-
const s =
|
|
192
|
-
return a(),
|
|
193
|
-
visible:
|
|
194
|
-
"onUpdate:visible": e[4] || (e[4] = (t) =>
|
|
197
|
+
const s = _("t-icon"), d = _("t-option"), k = _("t-select"), g = _("t-input"), r = _("t-button"), u = _("t-loading"), x = _("t-checkbox"), B = _("t-tree"), E = _("t-tab-panel"), P = _("t-tabs"), be = _("t-dialog");
|
|
198
|
+
return a(), I(be, {
|
|
199
|
+
visible: z.value,
|
|
200
|
+
"onUpdate:visible": e[4] || (e[4] = (t) => z.value = t),
|
|
195
201
|
header: "选择人员",
|
|
196
|
-
width:
|
|
202
|
+
width: ie.value,
|
|
197
203
|
footer: !0,
|
|
198
204
|
placement: "center",
|
|
199
205
|
"destroy-on-close": "",
|
|
200
|
-
onConfirm:
|
|
201
|
-
onClose:
|
|
206
|
+
onConfirm: ge,
|
|
207
|
+
onClose: Ce
|
|
202
208
|
}, {
|
|
203
|
-
default:
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
default: y(() => [
|
|
210
|
+
n("div", Ue, [
|
|
211
|
+
Z.value ? (a(), o("div", xe, [
|
|
206
212
|
p(s, { name: "info-circle" }),
|
|
207
|
-
|
|
213
|
+
n("span", null, h(Z.value), 1)
|
|
208
214
|
])) : v("", !0),
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
p(
|
|
212
|
-
modelValue:
|
|
213
|
-
"onUpdate:modelValue": e[0] || (e[0] = (t) =>
|
|
215
|
+
ce.value ? (a(), o("div", Ie, [
|
|
216
|
+
Y.value.length > 0 ? (a(), o("div", Se, [
|
|
217
|
+
p(k, {
|
|
218
|
+
modelValue: N.value,
|
|
219
|
+
"onUpdate:modelValue": e[0] || (e[0] = (t) => N.value = t),
|
|
214
220
|
placeholder: "选择组织",
|
|
215
221
|
style: { width: "200px" },
|
|
216
|
-
onChange:
|
|
222
|
+
onChange: pe
|
|
217
223
|
}, {
|
|
218
|
-
default:
|
|
219
|
-
(a(!0),
|
|
224
|
+
default: y(() => [
|
|
225
|
+
(a(!0), o($, null, J(Y.value, (t) => (a(), I(d, {
|
|
220
226
|
key: t.id,
|
|
221
227
|
value: t.id,
|
|
222
228
|
label: t.displayName || t.name
|
|
@@ -225,120 +231,120 @@ const be = { class: "cd-ps-container" }, Ne = {
|
|
|
225
231
|
_: 1
|
|
226
232
|
}, 8, ["modelValue"])
|
|
227
233
|
])) : v("", !0),
|
|
228
|
-
|
|
229
|
-
p(
|
|
230
|
-
modelValue:
|
|
231
|
-
"onUpdate:modelValue": e[1] || (e[1] = (t) =>
|
|
234
|
+
n("div", ze, [
|
|
235
|
+
p(g, {
|
|
236
|
+
modelValue: T.value,
|
|
237
|
+
"onUpdate:modelValue": e[1] || (e[1] = (t) => T.value = t),
|
|
232
238
|
placeholder: "输入手机号/工号/姓名/部门/职位搜索",
|
|
233
239
|
clearable: "",
|
|
234
|
-
onInput:
|
|
235
|
-
onClear:
|
|
240
|
+
onInput: ve,
|
|
241
|
+
onClear: H
|
|
236
242
|
}, {
|
|
237
|
-
"prefix-icon":
|
|
243
|
+
"prefix-icon": y(() => [
|
|
238
244
|
p(s, { name: "search" })
|
|
239
245
|
]),
|
|
240
246
|
_: 1
|
|
241
247
|
}, 8, ["modelValue"])
|
|
242
248
|
])
|
|
243
249
|
])) : v("", !0),
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
e[6] || (e[6] =
|
|
249
|
-
p(
|
|
250
|
+
n("div", Te, [
|
|
251
|
+
n("div", we, [
|
|
252
|
+
q.value ? (a(), o("div", Be, [
|
|
253
|
+
n("div", De, [
|
|
254
|
+
e[6] || (e[6] = n("span", null, "搜索结果", -1)),
|
|
255
|
+
p(r, {
|
|
250
256
|
size: "small",
|
|
251
257
|
variant: "text",
|
|
252
|
-
onClick:
|
|
258
|
+
onClick: H
|
|
253
259
|
}, {
|
|
254
|
-
default:
|
|
255
|
-
|
|
260
|
+
default: y(() => [...e[5] || (e[5] = [
|
|
261
|
+
X("返回", -1)
|
|
256
262
|
])]),
|
|
257
263
|
_: 1
|
|
258
264
|
})
|
|
259
265
|
]),
|
|
260
|
-
|
|
266
|
+
L.value ? (a(), o("div", Re, [
|
|
261
267
|
p(u),
|
|
262
|
-
e[7] || (e[7] =
|
|
263
|
-
])) :
|
|
268
|
+
e[7] || (e[7] = n("span", null, "搜索中...", -1))
|
|
269
|
+
])) : R.value.length === 0 ? (a(), o("div", Oe, [
|
|
264
270
|
p(s, {
|
|
265
271
|
name: "search",
|
|
266
272
|
size: "48px",
|
|
267
273
|
style: { color: "#ddd" }
|
|
268
274
|
}),
|
|
269
|
-
e[8] || (e[8] =
|
|
270
|
-
])) : (a(),
|
|
271
|
-
(a(!0),
|
|
275
|
+
e[8] || (e[8] = n("p", null, "未找到匹配的人员", -1))
|
|
276
|
+
])) : (a(), o("div", Ee, [
|
|
277
|
+
(a(!0), o($, null, J(R.value, (t) => (a(), o("div", {
|
|
272
278
|
key: t.id,
|
|
273
|
-
class:
|
|
274
|
-
onClick: (
|
|
279
|
+
class: j(["cd-ps-result-item", { "cd-ps-selected": i.value.includes(t.id) }]),
|
|
280
|
+
onClick: (W) => fe(t)
|
|
275
281
|
}, [
|
|
276
|
-
p(
|
|
282
|
+
p(x, {
|
|
277
283
|
checked: i.value.includes(t.id),
|
|
278
|
-
onClick: e[2] || (e[2] =
|
|
284
|
+
onClick: e[2] || (e[2] = oe(() => {
|
|
279
285
|
}, ["stop"]))
|
|
280
286
|
}, null, 8, ["checked"]),
|
|
281
|
-
|
|
287
|
+
n("div", Me, [
|
|
282
288
|
p(s, { name: "user" })
|
|
283
289
|
]),
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
t.position ? (a(),
|
|
288
|
-
t.department ? (a(),
|
|
289
|
-
t.phone ? (a(),
|
|
290
|
+
n("div", Le, [
|
|
291
|
+
n("div", We, h(t.displayName || t.name), 1),
|
|
292
|
+
n("div", $e, [
|
|
293
|
+
t.position ? (a(), o("span", Je, h(t.position), 1)) : v("", !0),
|
|
294
|
+
t.department ? (a(), o("span", je, h(t.department), 1)) : v("", !0),
|
|
295
|
+
t.phone ? (a(), o("span", Ae, h(t.phone), 1)) : v("", !0)
|
|
290
296
|
])
|
|
291
297
|
])
|
|
292
|
-
], 10,
|
|
298
|
+
], 10, Pe))), 128))
|
|
293
299
|
]))
|
|
294
|
-
])) : (a(),
|
|
300
|
+
])) : (a(), I(P, {
|
|
295
301
|
key: 1,
|
|
296
302
|
modelValue: V.value,
|
|
297
303
|
"onUpdate:modelValue": e[3] || (e[3] = (t) => V.value = t),
|
|
298
|
-
onChange:
|
|
304
|
+
onChange: ue
|
|
299
305
|
}, {
|
|
300
|
-
default:
|
|
301
|
-
(a(!0),
|
|
306
|
+
default: y(() => [
|
|
307
|
+
(a(!0), o($, null, J(de.value, (t) => (a(), I(E, {
|
|
302
308
|
key: t.key,
|
|
303
309
|
value: t.key,
|
|
304
310
|
label: t.name
|
|
305
311
|
}, {
|
|
306
|
-
default:
|
|
307
|
-
var
|
|
312
|
+
default: y(() => {
|
|
313
|
+
var W;
|
|
308
314
|
return [
|
|
309
|
-
|
|
310
|
-
((
|
|
315
|
+
n("div", Fe, [
|
|
316
|
+
((W = U.value[t.key]) == null ? void 0 : W.length) > 0 ? (a(), I(B, {
|
|
311
317
|
key: 0,
|
|
312
318
|
ref_for: !0,
|
|
313
|
-
ref: (
|
|
314
|
-
data:
|
|
319
|
+
ref: (f) => re(t.key, f),
|
|
320
|
+
data: U.value[t.key],
|
|
315
321
|
keys: { value: "id", label: "name", children: "children" },
|
|
316
322
|
hover: "",
|
|
317
323
|
checkable: "",
|
|
318
324
|
"expand-all": !1,
|
|
319
325
|
value: i.value,
|
|
320
|
-
onChange:
|
|
326
|
+
onChange: _e
|
|
321
327
|
}, {
|
|
322
|
-
label:
|
|
323
|
-
var
|
|
328
|
+
label: y(({ node: f }) => {
|
|
329
|
+
var ne;
|
|
324
330
|
return [
|
|
325
|
-
|
|
326
|
-
class:
|
|
331
|
+
n("div", {
|
|
332
|
+
class: j(["cd-ps-node", { "cd-ps-node-user": f.data.isUser }])
|
|
327
333
|
}, [
|
|
328
334
|
p(s, {
|
|
329
|
-
name:
|
|
335
|
+
name: f.data.isUser ? "user" : t.icon || "folder"
|
|
330
336
|
}, null, 8, ["name"]),
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
!
|
|
337
|
+
n("span", null, h(f.label), 1),
|
|
338
|
+
f.data.userCount && !f.data.isUser ? (a(), o("span", qe, "(" + h(f.data.userCount) + ")", 1)) : v("", !0),
|
|
339
|
+
!f.data.isUser && !((ne = f.data.children) != null && ne.length) && !f.data.loaded ? (a(), I(r, {
|
|
334
340
|
key: 1,
|
|
335
341
|
size: "small",
|
|
336
342
|
variant: "text",
|
|
337
343
|
class: "cd-ps-load-btn",
|
|
338
|
-
onClick:
|
|
344
|
+
onClick: oe((ut) => ke(f, t.key), ["stop"])
|
|
339
345
|
}, {
|
|
340
|
-
default:
|
|
341
|
-
|
|
346
|
+
default: y(() => [...e[9] || (e[9] = [
|
|
347
|
+
X("显示人员", -1)
|
|
342
348
|
])]),
|
|
343
349
|
_: 1
|
|
344
350
|
}, 8, ["onClick"])) : v("", !0)
|
|
@@ -346,13 +352,13 @@ const be = { class: "cd-ps-container" }, Ne = {
|
|
|
346
352
|
];
|
|
347
353
|
}),
|
|
348
354
|
_: 2
|
|
349
|
-
}, 1032, ["data", "value"])) : (a(),
|
|
355
|
+
}, 1032, ["data", "value"])) : (a(), o("div", Ge, [
|
|
350
356
|
p(s, {
|
|
351
357
|
name: t.icon || "folder-open",
|
|
352
358
|
size: "48px",
|
|
353
359
|
style: { color: "#ddd" }
|
|
354
360
|
}, null, 8, ["name"]),
|
|
355
|
-
e[10] || (e[10] =
|
|
361
|
+
e[10] || (e[10] = n("p", null, "暂无数据", -1))
|
|
356
362
|
]))
|
|
357
363
|
])
|
|
358
364
|
];
|
|
@@ -363,60 +369,60 @@ const be = { class: "cd-ps-container" }, Ne = {
|
|
|
363
369
|
_: 1
|
|
364
370
|
}, 8, ["modelValue"]))
|
|
365
371
|
]),
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
e[12] || (e[12] =
|
|
369
|
-
|
|
370
|
-
|
|
372
|
+
n("div", He, [
|
|
373
|
+
n("div", Qe, [
|
|
374
|
+
e[12] || (e[12] = n("span", { class: "cd-ps-title" }, "已选择", -1)),
|
|
375
|
+
n("span", Xe, h(O.value.length) + " 项", 1),
|
|
376
|
+
O.value.length > 0 ? (a(), I(r, {
|
|
371
377
|
key: 0,
|
|
372
378
|
size: "small",
|
|
373
379
|
variant: "text",
|
|
374
|
-
onClick:
|
|
380
|
+
onClick: se
|
|
375
381
|
}, {
|
|
376
|
-
default:
|
|
377
|
-
|
|
382
|
+
default: y(() => [...e[11] || (e[11] = [
|
|
383
|
+
X("清空", -1)
|
|
378
384
|
])]),
|
|
379
385
|
_: 1
|
|
380
386
|
})) : v("", !0)
|
|
381
387
|
]),
|
|
382
|
-
|
|
383
|
-
|
|
388
|
+
n("div", Ye, [
|
|
389
|
+
O.value.length === 0 ? (a(), o("div", Ze, [
|
|
384
390
|
p(s, {
|
|
385
391
|
name: "user-checked",
|
|
386
392
|
size: "64px",
|
|
387
393
|
style: { color: "#ddd" }
|
|
388
394
|
}),
|
|
389
|
-
e[13] || (e[13] =
|
|
390
|
-
])) : (a(),
|
|
391
|
-
(a(!0),
|
|
395
|
+
e[13] || (e[13] = n("p", null, "暂无选择", -1))
|
|
396
|
+
])) : (a(), o("div", Ke, [
|
|
397
|
+
(a(!0), o($, null, J(O.value, (t) => (a(), o("div", {
|
|
392
398
|
key: t.id,
|
|
393
|
-
class:
|
|
399
|
+
class: j(["cd-ps-selected-item", { "cd-ps-dept-item": !t.isUser }])
|
|
394
400
|
}, [
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
class:
|
|
401
|
+
n("div", et, [
|
|
402
|
+
n("div", {
|
|
403
|
+
class: j(["cd-ps-avatar", { "cd-ps-avatar-dept": !t.isUser }])
|
|
398
404
|
}, [
|
|
399
405
|
p(s, {
|
|
400
406
|
name: t.isUser ? "user" : "folder"
|
|
401
407
|
}, null, 8, ["name"])
|
|
402
408
|
], 2),
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
t.isUser && t.position ? (a(),
|
|
407
|
-
t.isUser && t.department ? (a(),
|
|
408
|
-
t.isUser ? v("", !0) : (a(),
|
|
409
|
-
!t.isUser && t.userCount ? (a(),
|
|
409
|
+
n("div", tt, [
|
|
410
|
+
n("div", st, h(t.displayName || t.name), 1),
|
|
411
|
+
n("div", lt, [
|
|
412
|
+
t.isUser && t.position ? (a(), o("span", at, h(t.position), 1)) : v("", !0),
|
|
413
|
+
t.isUser && t.department ? (a(), o("span", nt, h(t.department), 1)) : v("", !0),
|
|
414
|
+
t.isUser ? v("", !0) : (a(), o("span", ot, h(t.typeName || "部门"), 1)),
|
|
415
|
+
!t.isUser && t.userCount ? (a(), o("span", dt, h(t.userCount) + "人", 1)) : v("", !0)
|
|
410
416
|
])
|
|
411
417
|
])
|
|
412
418
|
]),
|
|
413
|
-
p(
|
|
419
|
+
p(r, {
|
|
414
420
|
size: "small",
|
|
415
421
|
variant: "text",
|
|
416
422
|
shape: "circle",
|
|
417
|
-
onClick: (
|
|
423
|
+
onClick: (W) => ye(t.id)
|
|
418
424
|
}, {
|
|
419
|
-
icon:
|
|
425
|
+
icon: y(() => [
|
|
420
426
|
p(s, { name: "close" })
|
|
421
427
|
]),
|
|
422
428
|
_: 1
|
|
@@ -432,17 +438,17 @@ const be = { class: "cd-ps-container" }, Ne = {
|
|
|
432
438
|
}, 8, ["visible", "width"]);
|
|
433
439
|
};
|
|
434
440
|
}
|
|
435
|
-
}),
|
|
436
|
-
const
|
|
437
|
-
for (const [
|
|
438
|
-
|
|
439
|
-
return
|
|
440
|
-
},
|
|
441
|
-
install(
|
|
442
|
-
|
|
441
|
+
}), it = (S, A) => {
|
|
442
|
+
const M = S.__vccOpts || S;
|
|
443
|
+
for (const [c, C] of A)
|
|
444
|
+
M[c] = C;
|
|
445
|
+
return M;
|
|
446
|
+
}, rt = /* @__PURE__ */ it(ct, [["__scopeId", "data-v-e9913ad1"]]), vt = {
|
|
447
|
+
install(S) {
|
|
448
|
+
S.component("PersonSelector", rt);
|
|
443
449
|
}
|
|
444
450
|
};
|
|
445
451
|
export {
|
|
446
|
-
|
|
447
|
-
|
|
452
|
+
rt as PersonSelector,
|
|
453
|
+
vt as default
|
|
448
454
|
};
|
|
@@ -64,6 +64,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
64
64
|
orgId?: number | string;
|
|
65
65
|
callback: (users: User[]) => void;
|
|
66
66
|
}) => void;
|
|
67
|
+
"org-change": (orgId: string | number) => void;
|
|
67
68
|
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
|
|
68
69
|
visible: boolean;
|
|
69
70
|
tabs: () => never[];
|
|
@@ -87,6 +88,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
87
88
|
orgId?: number | string;
|
|
88
89
|
callback: (users: User[]) => void;
|
|
89
90
|
}) => any) | undefined;
|
|
91
|
+
"onOrg-change"?: ((orgId: string | number) => any) | undefined;
|
|
90
92
|
}>, {
|
|
91
93
|
visible: boolean;
|
|
92
94
|
tabs: TabConfig[];
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.cd-ps-container[data-v-
|
|
1
|
+
.cd-ps-container[data-v-e9913ad1]{display:flex;flex-direction:column;gap:16px;min-height:500px}.cd-ps-tips[data-v-e9913ad1]{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-e9913ad1]{display:flex;gap:12px;align-items:center}.cd-ps-org-select[data-v-e9913ad1]{flex-shrink:0}.cd-ps-search-input[data-v-e9913ad1]{flex:1}.cd-ps-content[data-v-e9913ad1]{display:flex;gap:0;height:450px;border:1px solid #dfe1e6;border-radius:4px;overflow:hidden}.cd-ps-left[data-v-e9913ad1]{width:480px;flex-shrink:0;border-right:1px solid #dfe1e6;display:flex;flex-direction:column;background-color:#fafafa}.cd-ps-left[data-v-e9913ad1] .t-tabs__nav-container{padding:0 8px;background-color:#fff}.cd-ps-left[data-v-e9913ad1] .t-tabs__content{flex:1;overflow:hidden}.cd-ps-tree[data-v-e9913ad1]{height:100%;overflow-y:auto;padding:8px}.cd-ps-tree[data-v-e9913ad1]::-webkit-scrollbar{width:6px}.cd-ps-tree[data-v-e9913ad1]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-tree[data-v-e9913ad1]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-node[data-v-e9913ad1]{display:flex;align-items:center;gap:6px;font-size:14px;width:100%}[data-v-e9913ad1] .t-tree__label{flex:1}[data-v-e9913ad1] .t-checkbox__label{width:100%}.cd-ps-node-user[data-v-e9913ad1]{font-size:13px;color:#666}.cd-ps-count[data-v-e9913ad1]{color:#999;font-size:12px}.cd-ps-load-btn[data-v-e9913ad1]{margin-left:auto;color:#0052d9;font-size:12px;flex-shrink:0}.cd-ps-empty[data-v-e9913ad1]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;color:#999}.cd-ps-empty p[data-v-e9913ad1]{margin-top:16px;font-size:14px}.cd-ps-search-results[data-v-e9913ad1]{display:flex;flex-direction:column;height:100%}.cd-ps-search-header[data-v-e9913ad1]{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-e9913ad1]{display:flex;flex-direction:column;align-items:center;justify-content:center;padding:60px 20px;gap:12px;color:#999}.cd-ps-result-list[data-v-e9913ad1]{flex:1;overflow-y:auto;padding:8px}.cd-ps-result-item[data-v-e9913ad1]{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-e9913ad1]:hover{border-color:#0052d9;background:#f0f5ff}.cd-ps-result-item.cd-ps-selected[data-v-e9913ad1]{border-color:#0052d9;background:#e8f4ff}.cd-ps-avatar[data-v-e9913ad1]{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-e9913ad1]{width:36px;height:36px}.cd-ps-avatar-dept[data-v-e9913ad1]{background:linear-gradient(135deg,#f5af19,#f12711)}.cd-ps-info[data-v-e9913ad1]{flex:1;min-width:0}.cd-ps-name[data-v-e9913ad1]{font-size:13px;font-weight:500;color:#333;margin-bottom:4px}.cd-ps-result-item .cd-ps-name[data-v-e9913ad1]{font-size:14px}.cd-ps-meta[data-v-e9913ad1]{display:flex;flex-wrap:wrap;gap:6px;font-size:11px;color:#999}.cd-ps-result-item .cd-ps-meta[data-v-e9913ad1]{font-size:12px}.cd-ps-meta span[data-v-e9913ad1]:before{content:"•";margin-right:4px}.cd-ps-meta span[data-v-e9913ad1]:first-child:before{display:none}.cd-ps-right[data-v-e9913ad1]{flex:1;display:flex;flex-direction:column;overflow:hidden;background-color:#fafafa}.cd-ps-right-header[data-v-e9913ad1]{display:flex;align-items:center;padding:12px 16px;border-bottom:1px solid #dfe1e6;background-color:#fff}.cd-ps-title[data-v-e9913ad1]{font-weight:500;font-size:14px;color:#333}.cd-ps-num[data-v-e9913ad1]{font-size:13px;color:#0052d9;font-weight:600;margin-left:8px;flex:1}.cd-ps-right-list[data-v-e9913ad1]{flex:1;overflow-y:auto;padding:8px}.cd-ps-right-list[data-v-e9913ad1]::-webkit-scrollbar{width:6px}.cd-ps-right-list[data-v-e9913ad1]::-webkit-scrollbar-track{background:#f1f1f1}.cd-ps-right-list[data-v-e9913ad1]::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:3px}.cd-ps-selected-list[data-v-e9913ad1]{display:flex;flex-direction:column;gap:8px}.cd-ps-selected-item[data-v-e9913ad1]{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-e9913ad1]:hover{border-color:#0052d9;box-shadow:0 2px 4px #0052d91a}.cd-ps-dept-item[data-v-e9913ad1]{border-color:#f5af19}.cd-ps-item-info[data-v-e9913ad1]{flex:1;min-width:0;display:flex;align-items:center;gap:10px}
|
package/package.json
CHANGED
package/src/PersonSelector.vue
CHANGED
|
@@ -174,12 +174,14 @@ const emit = defineEmits<{
|
|
|
174
174
|
'confirm': [items: any[]];
|
|
175
175
|
'load-users': [params: { tabKey: string; nodeId: number | string; node: any; callback: (users: User[]) => void }];
|
|
176
176
|
'search': [params: { keyword: string; orgId?: number | string; callback: (users: User[]) => void }];
|
|
177
|
+
'org-change': [orgId: number | string];
|
|
177
178
|
}>();
|
|
178
179
|
const dialogVisible = ref(props.visible);
|
|
179
180
|
const activeTab = ref(props.tabs?.[0]?.key || '');
|
|
180
181
|
const selectedOrgId = ref<number | string | null>(null);
|
|
181
182
|
const searchKeyword = ref('');
|
|
182
183
|
const selectedIds = ref<(number | string)[]>([]);
|
|
184
|
+
const selectedItemsMap = ref<Map<number | string, any>>(new Map()); // 缓存已选中项的完整信息
|
|
183
185
|
const treeRefs = ref<Record<string, any>>({});
|
|
184
186
|
const isSearchMode = ref(false);
|
|
185
187
|
const searchLoading = ref(false);
|
|
@@ -203,7 +205,27 @@ watch(() => props.tabs, (newTabs) => {
|
|
|
203
205
|
watch(() => props.visible, (newVal) => {
|
|
204
206
|
dialogVisible.value = newVal;
|
|
205
207
|
if (newVal) {
|
|
206
|
-
|
|
208
|
+
// 支持两种格式的 modelValue:
|
|
209
|
+
// 1. ID 数组:[1, 2, 3]
|
|
210
|
+
// 2. 对象数组:[{ id: 1, name: 'xxx', ... }, ...]
|
|
211
|
+
if (props.modelValue && props.modelValue.length > 0) {
|
|
212
|
+
const firstItem = props.modelValue[0];
|
|
213
|
+
if (typeof firstItem === 'object' && firstItem !== null && 'id' in firstItem) {
|
|
214
|
+
// 对象数组格式,提取 ID 并缓存完整信息
|
|
215
|
+
selectedIds.value = props.modelValue.map((item: any) => item.id);
|
|
216
|
+
selectedItemsMap.value.clear();
|
|
217
|
+
props.modelValue.forEach((item: any) => {
|
|
218
|
+
selectedItemsMap.value.set(item.id, item);
|
|
219
|
+
});
|
|
220
|
+
} else {
|
|
221
|
+
// ID 数组格式
|
|
222
|
+
selectedIds.value = [...props.modelValue] as (number | string)[];
|
|
223
|
+
selectedItemsMap.value.clear();
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
selectedIds.value = [];
|
|
227
|
+
selectedItemsMap.value.clear();
|
|
228
|
+
}
|
|
207
229
|
if (props.organizations.length > 0 && !selectedOrgId.value) {
|
|
208
230
|
selectedOrgId.value = props.organizations[0].id;
|
|
209
231
|
}
|
|
@@ -219,25 +241,31 @@ function findNodeById(tree: TreeNode[], id: number | string): TreeNode | null {
|
|
|
219
241
|
return null;
|
|
220
242
|
}
|
|
221
243
|
const selectedItems = computed(() => {
|
|
222
|
-
|
|
223
|
-
selectedIds.value.forEach(id => {
|
|
224
|
-
const searchUser = searchResults.value.find(u => u.id === id);
|
|
225
|
-
if (searchUser) { items.push({ ...searchUser, typeName: '搜索结果' }); return; }
|
|
226
|
-
for (const tab of props.tabs) {
|
|
227
|
-
const treeData = internalTreeData.value[tab.key] || [];
|
|
228
|
-
const node = findNodeById(treeData, id);
|
|
229
|
-
if (node) {
|
|
230
|
-
// 去掉 tab.name 开头的"按"字
|
|
231
|
-
const typeName = tab.name.replace(/^按/, '');
|
|
232
|
-
items.push({ ...node, typeName });
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
return items;
|
|
244
|
+
return selectedIds.value.map(id => selectedItemsMap.value.get(id)).filter(Boolean);
|
|
238
245
|
});
|
|
246
|
+
|
|
247
|
+
// 添加选中项到缓存
|
|
248
|
+
function addSelectedItem(id: number | string, item: any) {
|
|
249
|
+
if (!selectedIds.value.includes(id)) {
|
|
250
|
+
selectedIds.value.push(id);
|
|
251
|
+
}
|
|
252
|
+
selectedItemsMap.value.set(id, item);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// 从缓存移除选中项
|
|
256
|
+
function removeSelectedItem(id: number | string) {
|
|
257
|
+
selectedIds.value = selectedIds.value.filter(i => i !== id);
|
|
258
|
+
selectedItemsMap.value.delete(id);
|
|
259
|
+
}
|
|
239
260
|
const handleTabChange = () => { searchKeyword.value = ''; };
|
|
240
|
-
const handleOrgChange = () => {
|
|
261
|
+
const handleOrgChange = (orgId: number | string) => {
|
|
262
|
+
// 清空左侧树数据,等待父组件重新传入
|
|
263
|
+
const newData: Record<string, TreeNode[]> = {};
|
|
264
|
+
props.tabs.forEach((tab) => { newData[tab.key] = []; });
|
|
265
|
+
internalTreeData.value = newData;
|
|
266
|
+
// 触发事件,让父组件重新加载数据
|
|
267
|
+
emit('org-change', orgId);
|
|
268
|
+
};
|
|
241
269
|
let searchTimer: ReturnType<typeof setTimeout> | null = null;
|
|
242
270
|
const handleSearchInput = () => {
|
|
243
271
|
if (searchTimer) clearTimeout(searchTimer);
|
|
@@ -263,8 +291,11 @@ const clearSearch = () => {
|
|
|
263
291
|
};
|
|
264
292
|
const toggleSearchResultSelect = (user: User) => {
|
|
265
293
|
const idx = selectedIds.value.indexOf(user.id);
|
|
266
|
-
if (idx > -1)
|
|
267
|
-
|
|
294
|
+
if (idx > -1) {
|
|
295
|
+
removeSelectedItem(user.id);
|
|
296
|
+
} else {
|
|
297
|
+
addSelectedItem(user.id, { ...user, isUser: true, typeName: '搜索结果', orgId: selectedOrgId.value });
|
|
298
|
+
}
|
|
268
299
|
};
|
|
269
300
|
function getAllNodeIds(tree: TreeNode[]): (number | string)[] {
|
|
270
301
|
const ids: (number | string)[] = [];
|
|
@@ -279,14 +310,14 @@ const handleTreeCheck = (checkedIds: (number | string)[], context: any) => {
|
|
|
279
310
|
if (node) {
|
|
280
311
|
const nodeId = node.value ?? node.data?.id;
|
|
281
312
|
if (nodeId !== undefined) {
|
|
282
|
-
// 检查节点当前是否被选中(通过 node.checked 属性)
|
|
283
313
|
const isChecked = node.checked;
|
|
284
314
|
if (isChecked) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
315
|
+
// 获取当前 tab 信息
|
|
316
|
+
const currentTab = props.tabs.find(t => t.key === activeTab.value);
|
|
317
|
+
const typeName = currentTab ? currentTab.name.replace(/^按/, '') : '';
|
|
318
|
+
addSelectedItem(nodeId, { ...node.data, typeName, orgId: selectedOrgId.value });
|
|
288
319
|
} else {
|
|
289
|
-
|
|
320
|
+
removeSelectedItem(nodeId);
|
|
290
321
|
}
|
|
291
322
|
return;
|
|
292
323
|
}
|
|
@@ -345,8 +376,8 @@ async function handleLoadUsers(node: any, tabKey: string) {
|
|
|
345
376
|
};
|
|
346
377
|
emit('load-users', { tabKey, nodeId, node, callback });
|
|
347
378
|
}
|
|
348
|
-
const handleRemoveItem = (id: number | string) => {
|
|
349
|
-
const clearSelection = () => { selectedIds.value = []; };
|
|
379
|
+
const handleRemoveItem = (id: number | string) => { removeSelectedItem(id); };
|
|
380
|
+
const clearSelection = () => { selectedIds.value = []; selectedItemsMap.value.clear(); };
|
|
350
381
|
const handleConfirm = () => {
|
|
351
382
|
emit('update:modelValue', selectedIds.value);
|
|
352
383
|
emit('confirm', selectedItems.value);
|