cd-personselector 1.0.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/README.md +126 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +446 -0
- package/dist/src/PersonSelector.vue.d.ts +116 -0
- package/dist/src/types.d.ts +51 -0
- package/dist/style.css +1 -0
- package/package.json +48 -0
- package/src/PersonSelector.vue +819 -0
- package/src/types.ts +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# cd-personselector
|
|
2
|
+
|
|
3
|
+
基于 Vue 3 + TDesign 的人员选择器组件,支持多 Tab、树形结构、搜索、懒加载等功能。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install cd-personselector
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<template>
|
|
15
|
+
<PersonSelector
|
|
16
|
+
v-model:visible="showSelector"
|
|
17
|
+
v-model="selectedIds"
|
|
18
|
+
:tabs="tabs"
|
|
19
|
+
:organizations="organizations"
|
|
20
|
+
tips="支持用户名、手机号、职务搜索"
|
|
21
|
+
@confirm="handleConfirm"
|
|
22
|
+
@load-users="handleLoadUsers"
|
|
23
|
+
@search="handleSearch"
|
|
24
|
+
/>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<script setup>
|
|
28
|
+
import { ref } from 'vue'
|
|
29
|
+
import PersonSelector from 'cd-personselector'
|
|
30
|
+
import 'cd-personselector/style.css'
|
|
31
|
+
|
|
32
|
+
const showSelector = ref(false)
|
|
33
|
+
const selectedIds = ref([])
|
|
34
|
+
|
|
35
|
+
const tabs = ref([
|
|
36
|
+
{
|
|
37
|
+
key: 'department',
|
|
38
|
+
name: '按部门',
|
|
39
|
+
icon: 'folder',
|
|
40
|
+
tree: [
|
|
41
|
+
{ id: 'dept-1', name: '研发部', userCount: 5 },
|
|
42
|
+
{ id: 'dept-2', name: '产品部', userCount: 3 }
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: 'external',
|
|
47
|
+
name: '外部联系人',
|
|
48
|
+
icon: 'usergroup',
|
|
49
|
+
tree: [
|
|
50
|
+
{ id: 'ext-1', name: '客户A', isUser: true, phone: '13800001111' }
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
])
|
|
54
|
+
|
|
55
|
+
const organizations = ref([
|
|
56
|
+
{ id: 'org-1', name: '总公司' }
|
|
57
|
+
])
|
|
58
|
+
|
|
59
|
+
function handleConfirm(items) {
|
|
60
|
+
console.log('选中项:', items)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function handleLoadUsers({ tabKey, nodeId, callback }) {
|
|
64
|
+
// 异步加载用户数据
|
|
65
|
+
fetchUsers(nodeId).then(users => callback(users))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function handleSearch({ keyword, orgId, callback }) {
|
|
69
|
+
// 搜索用户
|
|
70
|
+
searchUsers(keyword).then(users => callback(users))
|
|
71
|
+
}
|
|
72
|
+
</script>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Props
|
|
76
|
+
|
|
77
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
78
|
+
|------|------|--------|------|
|
|
79
|
+
| visible | boolean | false | 控制弹窗显示 |
|
|
80
|
+
| tabs | TabConfig[] | [] | Tab 配置数组 |
|
|
81
|
+
| organizations | Organization[] | [] | 组织列表 |
|
|
82
|
+
| modelValue | (string\|number)[] | [] | 选中的 ID 数组 |
|
|
83
|
+
| dialogWidth | string | '900px' | 弹窗宽度 |
|
|
84
|
+
| tips | string | '' | 顶部提示文字 |
|
|
85
|
+
| showSearch | boolean | true | 是否显示搜索 |
|
|
86
|
+
|
|
87
|
+
## Events
|
|
88
|
+
|
|
89
|
+
| 事件 | 参数 | 说明 |
|
|
90
|
+
|------|------|------|
|
|
91
|
+
| confirm | items: any[] | 确认选择时触发 |
|
|
92
|
+
| load-users | { tabKey, nodeId, callback } | 点击"显示人员"时触发 |
|
|
93
|
+
| search | { keyword, orgId, callback } | 搜索时触发 |
|
|
94
|
+
|
|
95
|
+
## 类型定义
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface TabConfig {
|
|
99
|
+
key: string
|
|
100
|
+
name: string
|
|
101
|
+
icon?: string
|
|
102
|
+
tree: TreeNode[]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface TreeNode {
|
|
106
|
+
id: number | string
|
|
107
|
+
name: string
|
|
108
|
+
children?: TreeNode[]
|
|
109
|
+
userCount?: number
|
|
110
|
+
isUser?: boolean
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface User {
|
|
114
|
+
id: number | string
|
|
115
|
+
name: string
|
|
116
|
+
displayName?: string
|
|
117
|
+
phone?: string
|
|
118
|
+
position?: string
|
|
119
|
+
department?: string
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 依赖
|
|
124
|
+
|
|
125
|
+
- vue >= 3.0.0
|
|
126
|
+
- tdesign-vue-next >= 1.0.0
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(m,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(m=typeof globalThis<"u"?globalThis:m||self,e(m.CdPersonSelector={},m.Vue))})(this,function(m,e){"use strict";const j={class:"person-selector"},J={key:0,class:"selector-tips"},q={key:1,class:"search-area"},A={key:0,class:"org-select"},G={class:"search-input"},H={class:"content-area"},K={class:"left-panel tree-panel"},Q={key:0,class:"search-results"},X={class:"search-results-header"},Y={key:0,class:"search-loading"},Z={key:1,class:"empty-search"},v={key:2,class:"search-result-list"},ee=["onClick"],te={class:"user-avatar"},oe={class:"user-details"},le={class:"user-name"},ne={class:"user-meta"},ae={key:0},se={key:1},ce={key:2},re={class:"tree-container"},de={key:0,class:"user-count"},ie={key:1,class:"empty-tree"},me={class:"right-panel"},pe={class:"selected-header"},ke={class:"header-count"},he={class:"selected-list-container"},fe={key:0,class:"empty-selected"},_e={key:1,class:"selected-user-list"},ye={class:"user-info"},Ne={class:"user-details"},Ve={class:"user-name"},Be={class:"user-meta"},Ce={key:0},ge={key:1},ue={key:2},Ee={key:3},P=((f,U)=>{const x=f.__vccOpts||f;for(const[s,h]of U)x[s]=h;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(f,{expose:U,emit:x}){var F,W;const s=f,h=x,_=e.ref(s.visible),y=e.ref(((W=(F=s.tabs)==null?void 0:F[0])==null?void 0:W.key)||""),C=e.ref(null),N=e.ref(""),c=e.ref([]),w=e.ref({}),D=e.ref(!1),S=e.ref(!1),V=e.ref([]),Se=e.computed(()=>s.tabs||[]),O=e.computed(()=>s.organizations||[]),R=e.computed(()=>s.tips||""),be=e.computed(()=>s.showSearch),Ue=e.computed(()=>s.dialogWidth),g=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))}),g.value=t,(!y.value||!l.find(n=>n.key===y.value))&&(y.value=l[0].key)}},{immediate:!0,deep:!0}),e.watch(()=>s.visible,l=>{_.value=l,l&&(c.value=s.modelValue?[...s.modelValue]:[],s.organizations.length>0&&!C.value&&(C.value=s.organizations[0].id))}),e.watch(_,l=>{h("update:visible",l)});function we(l,t){t&&(w.value[l]=t)}function L(l,t){for(const n of l){if(n.id===t)return n;if(n.children){const a=L(n.children,t);if(a)return a}}return null}const u=e.computed(()=>{const l=[];return c.value.forEach(t=>{const n=V.value.find(a=>a.id===t);if(n){l.push({...n,typeName:"搜索结果"});return}for(const a of s.tabs){const r=g.value[a.key]||[],i=L(r,t);if(i){l.push({...i,typeName:a.name});break}}}),l}),De=()=>{N.value=""},ze=()=>{};let B=null;const Te=()=>{if(B&&clearTimeout(B),!N.value.trim()){z();return}D.value=!0,S.value=!0,B=setTimeout(()=>{Ie()},300)},Ie=()=>{V.value=[];const l=t=>{V.value=t.map(n=>({...n,isUser:!0})),S.value=!1};h("search",{keyword:N.value,orgId:C.value||void 0,callback:l})},z=()=>{B&&(clearTimeout(B),B=null),D.value=!1,N.value="",V.value=[],S.value=!1},Pe=l=>{const t=c.value.indexOf(l.id);t>-1?c.value.splice(t,1):c.value.push(l.id)};function Oe(l){const t=[],n=a=>{for(const r of a)t.push(r.id),r.children&&n(r.children)};return n(l),t}const Re=l=>{const t=g.value[y.value]||[],n=Oe(t),a=c.value.filter(r=>!n.includes(r));c.value=[...a,...l]};async function Le(l,t){const n=l.value,a=w.value[t];h("load-users",{tabKey:t,nodeId:n,node:l,callback:async i=>{if(i.length>0){const p=i.map(k=>{const{id:E,name:T,...I}=k;return{...I,id:E,name:k.displayName||T,isUser:!0}});if(a){a.appendTo(n,p),l.data.loaded=!0,await e.nextTick();try{a.setItem(n,{expanded:!0})}catch(k){console.log("展开节点失败",k)}}}else l.data.loaded=!0}})}const Me=l=>{c.value=c.value.filter(t=>t!==l)},M=()=>{c.value=[]},Fe=()=>{h("update:modelValue",c.value),h("confirm",u.value),_.value=!1},We=()=>{_.value=!1};return U({clearSelection:M,appendUsers:(l,t,n)=>{const a=w.value[l];if(a&&n.length>0){const r=n.map(i=>{const{id:p,name:k,...E}=i;return{...E,id:p,name:i.displayName||k,isUser:!0}});a.appendTo(t,r)}}}),(l,t)=>{const n=e.resolveComponent("t-icon"),a=e.resolveComponent("t-option"),r=e.resolveComponent("t-select"),i=e.resolveComponent("t-input"),p=e.resolveComponent("t-button"),k=e.resolveComponent("t-loading"),E=e.resolveComponent("t-checkbox"),T=e.resolveComponent("t-tree"),I=e.resolveComponent("t-tab-panel"),$e=e.resolveComponent("t-tabs"),je=e.resolveComponent("t-dialog");return e.openBlock(),e.createBlock(je,{visible:_.value,"onUpdate:visible":t[4]||(t[4]=o=>_.value=o),header:"选择人员",width:Ue.value,footer:!0,"destroy-on-close":"",onConfirm:Fe,onClose:We},{default:e.withCtx(()=>[e.createElementVNode("div",j,[R.value?(e.openBlock(),e.createElementBlock("div",J,[e.createVNode(n,{name:"info-circle"}),e.createElementVNode("span",null,e.toDisplayString(R.value),1)])):e.createCommentVNode("",!0),be.value?(e.openBlock(),e.createElementBlock("div",q,[O.value.length>0?(e.openBlock(),e.createElementBlock("div",A,[e.createVNode(r,{modelValue:C.value,"onUpdate:modelValue":t[0]||(t[0]=o=>C.value=o),placeholder:"选择组织",style:{width:"200px"},onChange:ze},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(O.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",G,[e.createVNode(i,{modelValue:N.value,"onUpdate:modelValue":t[1]||(t[1]=o=>N.value=o),placeholder:"搜索",clearable:"",onInput:Te,onClear:z},{"prefix-icon":e.withCtx(()=>[e.createVNode(n,{name:"search"})]),_:1},8,["modelValue"])])])):e.createCommentVNode("",!0),e.createElementVNode("div",H,[e.createElementVNode("div",K,[D.value?(e.openBlock(),e.createElementBlock("div",Q,[e.createElementVNode("div",X,[t[6]||(t[6]=e.createElementVNode("span",null,"搜索结果",-1)),e.createVNode(p,{size:"small",variant:"text",onClick:z},{default:e.withCtx(()=>[...t[5]||(t[5]=[e.createTextVNode("返回",-1)])]),_:1})]),S.value?(e.openBlock(),e.createElementBlock("div",Y,[e.createVNode(k),t[7]||(t[7]=e.createElementVNode("span",null,"搜索中...",-1))])):V.value.length===0?(e.openBlock(),e.createElementBlock("div",Z,[e.createVNode(n,{name:"search",size:"48px",style:{color:"#ddd"}}),t[8]||(t[8]=e.createElementVNode("p",null,"未找到匹配的人员",-1))])):(e.openBlock(),e.createElementBlock("div",v,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(V.value,o=>(e.openBlock(),e.createElementBlock("div",{key:o.id,class:e.normalizeClass(["search-result-item",{"is-selected":c.value.includes(o.id)}]),onClick:b=>Pe(o)},[e.createVNode(E,{checked:c.value.includes(o.id),onClick:t[2]||(t[2]=e.withModifiers(()=>{},["stop"]))},null,8,["checked"]),e.createElementVNode("div",te,[e.createVNode(n,{name:"user"})]),e.createElementVNode("div",oe,[e.createElementVNode("div",le,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",ne,[o.position?(e.openBlock(),e.createElementBlock("span",ae,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.department?(e.openBlock(),e.createElementBlock("span",se,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.phone?(e.openBlock(),e.createElementBlock("span",ce,e.toDisplayString(o.phone),1)):e.createCommentVNode("",!0)])])],10,ee))),128))]))])):(e.openBlock(),e.createBlock($e,{key:1,modelValue:y.value,"onUpdate:modelValue":t[3]||(t[3]=o=>y.value=o),onChange:De},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Se.value,o=>(e.openBlock(),e.createBlock(I,{key:o.key,value:o.key,label:o.name},{default:e.withCtx(()=>{var b;return[e.createElementVNode("div",re,[((b=g.value[o.key])==null?void 0:b.length)>0?(e.openBlock(),e.createBlock(T,{key:0,ref_for:!0,ref:d=>we(o.key,d),data:g.value[o.key],keys:{value:"id",label:"name",children:"children"},hover:"",checkable:"","expand-all":!1,value:c.value,onChange:Re},{label:e.withCtx(({node:d})=>{var $;return[e.createElementVNode("div",{class:e.normalizeClass(["tree-node-label",{"is-user":d.data.isUser}])},[e.createVNode(n,{name:d.data.isUser?"user":o.icon||"folder"},null,8,["name"]),e.createElementVNode("span",null,e.toDisplayString(d.label),1),d.data.userCount&&!d.data.isUser?(e.openBlock(),e.createElementBlock("span",de,"("+e.toDisplayString(d.data.userCount)+")",1)):e.createCommentVNode("",!0),!d.data.isUser&&!(($=d.data.children)!=null&&$.length)&&!d.data.loaded?(e.openBlock(),e.createBlock(p,{key:1,size:"small",variant:"text",class:"load-users-btn",onClick:e.withModifiers(Ae=>Le(d,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",ie,[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",me,[e.createElementVNode("div",pe,[t[12]||(t[12]=e.createElementVNode("span",{class:"header-title"},"已选择",-1)),e.createElementVNode("span",ke,e.toDisplayString(u.value.length)+" 项",1),u.value.length>0?(e.openBlock(),e.createBlock(p,{key:0,size:"small",variant:"text",onClick:M},{default:e.withCtx(()=>[...t[11]||(t[11]=[e.createTextVNode("清空",-1)])]),_:1})):e.createCommentVNode("",!0)]),e.createElementVNode("div",he,[u.value.length===0?(e.openBlock(),e.createElementBlock("div",fe,[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",_e,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(u.value,o=>(e.openBlock(),e.createElementBlock("div",{key:o.id,class:e.normalizeClass(["selected-user-item",{"selected-dept-item":!o.isUser}])},[e.createElementVNode("div",ye,[e.createElementVNode("div",{class:e.normalizeClass(["user-avatar",{"dept-avatar":!o.isUser}])},[e.createVNode(n,{name:o.isUser?"user":"folder"},null,8,["name"])],2),e.createElementVNode("div",Ne,[e.createElementVNode("div",Ve,e.toDisplayString(o.displayName||o.name),1),e.createElementVNode("div",Be,[o.isUser&&o.position?(e.openBlock(),e.createElementBlock("span",Ce,e.toDisplayString(o.position),1)):e.createCommentVNode("",!0),o.isUser&&o.department?(e.openBlock(),e.createElementBlock("span",ge,e.toDisplayString(o.department),1)):e.createCommentVNode("",!0),o.isUser?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("span",ue,e.toDisplayString(o.typeName||"部门"),1)),!o.isUser&&o.userCount?(e.openBlock(),e.createElementBlock("span",Ee,e.toDisplayString(o.userCount)+"人",1)):e.createCommentVNode("",!0)])])]),e.createVNode(p,{size:"small",variant:"text",shape:"circle",onClick:b=>Me(o.id)},{icon:e.withCtx(()=>[e.createVNode(n,{name:"close"})]),_:1},8,["onClick"])],2))),128))]))])])])])]),_:1},8,["visible","width"])}}}),[["__scopeId","data-v-210902ae"]]),xe={install(f){f.component("PersonSelector",P)}};m.PersonSelector=P,m.default=xe,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { defineComponent as ye, ref as f, computed as z, watch as q, resolveComponent as _, createBlock as b, openBlock as a, withCtx as k, createElementVNode as n, createElementBlock as o, createCommentVNode as u, createVNode as r, toDisplayString as v, Fragment as E, renderList as L, createTextVNode as G, normalizeClass as W, withModifiers as te, nextTick as ge } from "vue";
|
|
2
|
+
const Ce = { class: "person-selector" }, be = {
|
|
3
|
+
key: 0,
|
|
4
|
+
class: "selector-tips"
|
|
5
|
+
}, xe = {
|
|
6
|
+
key: 1,
|
|
7
|
+
class: "search-area"
|
|
8
|
+
}, Ue = {
|
|
9
|
+
key: 0,
|
|
10
|
+
class: "org-select"
|
|
11
|
+
}, Ne = { class: "search-input" }, Se = { class: "content-area" }, Ve = { class: "left-panel tree-panel" }, Ie = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "search-results"
|
|
14
|
+
}, ze = { class: "search-results-header" }, Te = {
|
|
15
|
+
key: 0,
|
|
16
|
+
class: "search-loading"
|
|
17
|
+
}, we = {
|
|
18
|
+
key: 1,
|
|
19
|
+
class: "empty-search"
|
|
20
|
+
}, Re = {
|
|
21
|
+
key: 2,
|
|
22
|
+
class: "search-result-list"
|
|
23
|
+
}, Be = ["onClick"], Oe = { class: "user-avatar" }, De = { class: "user-details" }, Pe = { class: "user-name" }, Ee = { class: "user-meta" }, Le = { key: 0 }, We = { key: 1 }, $e = { key: 2 }, Je = { class: "tree-container" }, Me = {
|
|
24
|
+
key: 0,
|
|
25
|
+
class: "user-count"
|
|
26
|
+
}, Ae = {
|
|
27
|
+
key: 1,
|
|
28
|
+
class: "empty-tree"
|
|
29
|
+
}, Fe = { class: "right-panel" }, je = { class: "selected-header" }, qe = { class: "header-count" }, Ge = { class: "selected-list-container" }, He = {
|
|
30
|
+
key: 0,
|
|
31
|
+
class: "empty-selected"
|
|
32
|
+
}, Ke = {
|
|
33
|
+
key: 1,
|
|
34
|
+
class: "selected-user-list"
|
|
35
|
+
}, Qe = { class: "user-info" }, Xe = { class: "user-details" }, Ye = { class: "user-name" }, Ze = { class: "user-meta" }, et = { key: 0 }, tt = { key: 1 }, st = { key: 2 }, lt = { key: 3 }, at = /* @__PURE__ */ ye({
|
|
36
|
+
__name: "PersonSelector",
|
|
37
|
+
props: {
|
|
38
|
+
visible: { type: Boolean, default: !1 },
|
|
39
|
+
tabs: { default: () => [] },
|
|
40
|
+
organizations: { default: () => [] },
|
|
41
|
+
modelValue: { default: () => [] },
|
|
42
|
+
dialogWidth: { default: "900px" },
|
|
43
|
+
tips: { default: "" },
|
|
44
|
+
showSearch: { type: Boolean, default: !0 }
|
|
45
|
+
},
|
|
46
|
+
emits: ["update:visible", "update:modelValue", "confirm", "load-users", "search"],
|
|
47
|
+
setup(x, { expose: $, emit: O }) {
|
|
48
|
+
var Y, Z;
|
|
49
|
+
const d = x, C = O, U = f(d.visible), N = f(((Z = (Y = d.tabs) == null ? void 0 : Y[0]) == null ? void 0 : Z.key) || ""), T = f(null), S = f(""), c = f([]), J = f({}), M = f(!1), D = f(!1), V = f([]), se = z(() => d.tabs || []), H = z(() => d.organizations || []), K = z(() => d.tips || ""), le = z(() => d.showSearch), ae = z(() => d.dialogWidth), w = f({});
|
|
50
|
+
q(
|
|
51
|
+
() => d.tabs,
|
|
52
|
+
(s) => {
|
|
53
|
+
if (s && s.length > 0) {
|
|
54
|
+
const e = {};
|
|
55
|
+
s.forEach((l) => {
|
|
56
|
+
e[l.key] = JSON.parse(JSON.stringify(l.tree));
|
|
57
|
+
}), w.value = e, (!N.value || !s.find((l) => l.key === N.value)) && (N.value = s[0].key);
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
{ immediate: !0, deep: !0 }
|
|
61
|
+
), q(() => d.visible, (s) => {
|
|
62
|
+
U.value = s, s && (c.value = d.modelValue ? [...d.modelValue] : [], d.organizations.length > 0 && !T.value && (T.value = d.organizations[0].id));
|
|
63
|
+
}), q(U, (s) => {
|
|
64
|
+
C("update:visible", s);
|
|
65
|
+
});
|
|
66
|
+
function ne(s, e) {
|
|
67
|
+
e && (J.value[s] = e);
|
|
68
|
+
}
|
|
69
|
+
function Q(s, e) {
|
|
70
|
+
for (const l of s) {
|
|
71
|
+
if (l.id === e) return l;
|
|
72
|
+
if (l.children) {
|
|
73
|
+
const i = Q(l.children, e);
|
|
74
|
+
if (i) return i;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const R = z(() => {
|
|
80
|
+
const s = [];
|
|
81
|
+
return c.value.forEach((e) => {
|
|
82
|
+
const l = V.value.find((i) => i.id === e);
|
|
83
|
+
if (l) {
|
|
84
|
+
s.push({ ...l, typeName: "搜索结果" });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (const i of d.tabs) {
|
|
88
|
+
const p = w.value[i.key] || [], m = Q(p, e);
|
|
89
|
+
if (m) {
|
|
90
|
+
s.push({
|
|
91
|
+
...m,
|
|
92
|
+
typeName: i.name
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}), s;
|
|
98
|
+
}), oe = () => {
|
|
99
|
+
S.value = "";
|
|
100
|
+
}, ie = () => {
|
|
101
|
+
};
|
|
102
|
+
let I = null;
|
|
103
|
+
const de = () => {
|
|
104
|
+
if (I && clearTimeout(I), !S.value.trim()) {
|
|
105
|
+
A();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
M.value = !0, D.value = !0, I = setTimeout(() => {
|
|
109
|
+
re();
|
|
110
|
+
}, 300);
|
|
111
|
+
}, re = () => {
|
|
112
|
+
V.value = [];
|
|
113
|
+
const s = (e) => {
|
|
114
|
+
V.value = e.map((l) => ({ ...l, isUser: !0 })), D.value = !1;
|
|
115
|
+
};
|
|
116
|
+
C("search", {
|
|
117
|
+
keyword: S.value,
|
|
118
|
+
orgId: T.value || void 0,
|
|
119
|
+
callback: s
|
|
120
|
+
});
|
|
121
|
+
}, A = () => {
|
|
122
|
+
I && (clearTimeout(I), I = null), M.value = !1, S.value = "", V.value = [], D.value = !1;
|
|
123
|
+
}, ce = (s) => {
|
|
124
|
+
const e = c.value.indexOf(s.id);
|
|
125
|
+
e > -1 ? c.value.splice(e, 1) : c.value.push(s.id);
|
|
126
|
+
};
|
|
127
|
+
function ue(s) {
|
|
128
|
+
const e = [], l = (i) => {
|
|
129
|
+
for (const p of i)
|
|
130
|
+
e.push(p.id), p.children && l(p.children);
|
|
131
|
+
};
|
|
132
|
+
return l(s), e;
|
|
133
|
+
}
|
|
134
|
+
const ve = (s) => {
|
|
135
|
+
const e = w.value[N.value] || [], l = ue(e), i = c.value.filter((p) => !l.includes(p));
|
|
136
|
+
c.value = [...i, ...s];
|
|
137
|
+
};
|
|
138
|
+
async function pe(s, e) {
|
|
139
|
+
const l = s.value, i = J.value[e];
|
|
140
|
+
C("load-users", { tabKey: e, nodeId: l, node: s, callback: async (m) => {
|
|
141
|
+
if (m.length > 0) {
|
|
142
|
+
const y = m.map((g) => {
|
|
143
|
+
const { id: B, name: F, ...j } = g;
|
|
144
|
+
return {
|
|
145
|
+
...j,
|
|
146
|
+
id: B,
|
|
147
|
+
name: g.displayName || F,
|
|
148
|
+
isUser: !0
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
if (i) {
|
|
152
|
+
i.appendTo(l, y), s.data.loaded = !0, await ge();
|
|
153
|
+
try {
|
|
154
|
+
i.setItem(l, { expanded: !0 });
|
|
155
|
+
} catch (g) {
|
|
156
|
+
console.log("展开节点失败", g);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} else
|
|
160
|
+
s.data.loaded = !0;
|
|
161
|
+
} });
|
|
162
|
+
}
|
|
163
|
+
const he = (s) => {
|
|
164
|
+
c.value = c.value.filter((e) => e !== s);
|
|
165
|
+
}, X = () => {
|
|
166
|
+
c.value = [];
|
|
167
|
+
}, _e = () => {
|
|
168
|
+
C("update:modelValue", c.value), C("confirm", R.value), U.value = !1;
|
|
169
|
+
}, me = () => {
|
|
170
|
+
U.value = !1;
|
|
171
|
+
};
|
|
172
|
+
return $({
|
|
173
|
+
clearSelection: X,
|
|
174
|
+
appendUsers: (s, e, l) => {
|
|
175
|
+
const i = J.value[s];
|
|
176
|
+
if (i && l.length > 0) {
|
|
177
|
+
const p = l.map((m) => {
|
|
178
|
+
const { id: y, name: g, ...B } = m;
|
|
179
|
+
return {
|
|
180
|
+
...B,
|
|
181
|
+
id: y,
|
|
182
|
+
name: m.displayName || g,
|
|
183
|
+
isUser: !0
|
|
184
|
+
};
|
|
185
|
+
});
|
|
186
|
+
i.appendTo(e, p);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}), (s, e) => {
|
|
190
|
+
const l = _("t-icon"), i = _("t-option"), p = _("t-select"), m = _("t-input"), y = _("t-button"), g = _("t-loading"), B = _("t-checkbox"), F = _("t-tree"), j = _("t-tab-panel"), fe = _("t-tabs"), ke = _("t-dialog");
|
|
191
|
+
return a(), b(ke, {
|
|
192
|
+
visible: U.value,
|
|
193
|
+
"onUpdate:visible": e[4] || (e[4] = (t) => U.value = t),
|
|
194
|
+
header: "选择人员",
|
|
195
|
+
width: ae.value,
|
|
196
|
+
footer: !0,
|
|
197
|
+
"destroy-on-close": "",
|
|
198
|
+
onConfirm: _e,
|
|
199
|
+
onClose: me
|
|
200
|
+
}, {
|
|
201
|
+
default: k(() => [
|
|
202
|
+
n("div", Ce, [
|
|
203
|
+
K.value ? (a(), o("div", be, [
|
|
204
|
+
r(l, { name: "info-circle" }),
|
|
205
|
+
n("span", null, v(K.value), 1)
|
|
206
|
+
])) : u("", !0),
|
|
207
|
+
le.value ? (a(), o("div", xe, [
|
|
208
|
+
H.value.length > 0 ? (a(), o("div", Ue, [
|
|
209
|
+
r(p, {
|
|
210
|
+
modelValue: T.value,
|
|
211
|
+
"onUpdate:modelValue": e[0] || (e[0] = (t) => T.value = t),
|
|
212
|
+
placeholder: "选择组织",
|
|
213
|
+
style: { width: "200px" },
|
|
214
|
+
onChange: ie
|
|
215
|
+
}, {
|
|
216
|
+
default: k(() => [
|
|
217
|
+
(a(!0), o(E, null, L(H.value, (t) => (a(), b(i, {
|
|
218
|
+
key: t.id,
|
|
219
|
+
value: t.id,
|
|
220
|
+
label: t.displayName || t.name
|
|
221
|
+
}, null, 8, ["value", "label"]))), 128))
|
|
222
|
+
]),
|
|
223
|
+
_: 1
|
|
224
|
+
}, 8, ["modelValue"])
|
|
225
|
+
])) : u("", !0),
|
|
226
|
+
n("div", Ne, [
|
|
227
|
+
r(m, {
|
|
228
|
+
modelValue: S.value,
|
|
229
|
+
"onUpdate:modelValue": e[1] || (e[1] = (t) => S.value = t),
|
|
230
|
+
placeholder: "搜索",
|
|
231
|
+
clearable: "",
|
|
232
|
+
onInput: de,
|
|
233
|
+
onClear: A
|
|
234
|
+
}, {
|
|
235
|
+
"prefix-icon": k(() => [
|
|
236
|
+
r(l, { name: "search" })
|
|
237
|
+
]),
|
|
238
|
+
_: 1
|
|
239
|
+
}, 8, ["modelValue"])
|
|
240
|
+
])
|
|
241
|
+
])) : u("", !0),
|
|
242
|
+
n("div", Se, [
|
|
243
|
+
n("div", Ve, [
|
|
244
|
+
M.value ? (a(), o("div", Ie, [
|
|
245
|
+
n("div", ze, [
|
|
246
|
+
e[6] || (e[6] = n("span", null, "搜索结果", -1)),
|
|
247
|
+
r(y, {
|
|
248
|
+
size: "small",
|
|
249
|
+
variant: "text",
|
|
250
|
+
onClick: A
|
|
251
|
+
}, {
|
|
252
|
+
default: k(() => [...e[5] || (e[5] = [
|
|
253
|
+
G("返回", -1)
|
|
254
|
+
])]),
|
|
255
|
+
_: 1
|
|
256
|
+
})
|
|
257
|
+
]),
|
|
258
|
+
D.value ? (a(), o("div", Te, [
|
|
259
|
+
r(g),
|
|
260
|
+
e[7] || (e[7] = n("span", null, "搜索中...", -1))
|
|
261
|
+
])) : V.value.length === 0 ? (a(), o("div", we, [
|
|
262
|
+
r(l, {
|
|
263
|
+
name: "search",
|
|
264
|
+
size: "48px",
|
|
265
|
+
style: { color: "#ddd" }
|
|
266
|
+
}),
|
|
267
|
+
e[8] || (e[8] = n("p", null, "未找到匹配的人员", -1))
|
|
268
|
+
])) : (a(), o("div", Re, [
|
|
269
|
+
(a(!0), o(E, null, L(V.value, (t) => (a(), o("div", {
|
|
270
|
+
key: t.id,
|
|
271
|
+
class: W(["search-result-item", { "is-selected": c.value.includes(t.id) }]),
|
|
272
|
+
onClick: (P) => ce(t)
|
|
273
|
+
}, [
|
|
274
|
+
r(B, {
|
|
275
|
+
checked: c.value.includes(t.id),
|
|
276
|
+
onClick: e[2] || (e[2] = te(() => {
|
|
277
|
+
}, ["stop"]))
|
|
278
|
+
}, null, 8, ["checked"]),
|
|
279
|
+
n("div", Oe, [
|
|
280
|
+
r(l, { name: "user" })
|
|
281
|
+
]),
|
|
282
|
+
n("div", De, [
|
|
283
|
+
n("div", Pe, v(t.displayName || t.name), 1),
|
|
284
|
+
n("div", Ee, [
|
|
285
|
+
t.position ? (a(), o("span", Le, v(t.position), 1)) : u("", !0),
|
|
286
|
+
t.department ? (a(), o("span", We, v(t.department), 1)) : u("", !0),
|
|
287
|
+
t.phone ? (a(), o("span", $e, v(t.phone), 1)) : u("", !0)
|
|
288
|
+
])
|
|
289
|
+
])
|
|
290
|
+
], 10, Be))), 128))
|
|
291
|
+
]))
|
|
292
|
+
])) : (a(), b(fe, {
|
|
293
|
+
key: 1,
|
|
294
|
+
modelValue: N.value,
|
|
295
|
+
"onUpdate:modelValue": e[3] || (e[3] = (t) => N.value = t),
|
|
296
|
+
onChange: oe
|
|
297
|
+
}, {
|
|
298
|
+
default: k(() => [
|
|
299
|
+
(a(!0), o(E, null, L(se.value, (t) => (a(), b(j, {
|
|
300
|
+
key: t.key,
|
|
301
|
+
value: t.key,
|
|
302
|
+
label: t.name
|
|
303
|
+
}, {
|
|
304
|
+
default: k(() => {
|
|
305
|
+
var P;
|
|
306
|
+
return [
|
|
307
|
+
n("div", Je, [
|
|
308
|
+
((P = w.value[t.key]) == null ? void 0 : P.length) > 0 ? (a(), b(F, {
|
|
309
|
+
key: 0,
|
|
310
|
+
ref_for: !0,
|
|
311
|
+
ref: (h) => ne(t.key, h),
|
|
312
|
+
data: w.value[t.key],
|
|
313
|
+
keys: { value: "id", label: "name", children: "children" },
|
|
314
|
+
hover: "",
|
|
315
|
+
checkable: "",
|
|
316
|
+
"expand-all": !1,
|
|
317
|
+
value: c.value,
|
|
318
|
+
onChange: ve
|
|
319
|
+
}, {
|
|
320
|
+
label: k(({ node: h }) => {
|
|
321
|
+
var ee;
|
|
322
|
+
return [
|
|
323
|
+
n("div", {
|
|
324
|
+
class: W(["tree-node-label", { "is-user": h.data.isUser }])
|
|
325
|
+
}, [
|
|
326
|
+
r(l, {
|
|
327
|
+
name: h.data.isUser ? "user" : t.icon || "folder"
|
|
328
|
+
}, null, 8, ["name"]),
|
|
329
|
+
n("span", null, v(h.label), 1),
|
|
330
|
+
h.data.userCount && !h.data.isUser ? (a(), o("span", Me, "(" + v(h.data.userCount) + ")", 1)) : u("", !0),
|
|
331
|
+
!h.data.isUser && !((ee = h.data.children) != null && ee.length) && !h.data.loaded ? (a(), b(y, {
|
|
332
|
+
key: 1,
|
|
333
|
+
size: "small",
|
|
334
|
+
variant: "text",
|
|
335
|
+
class: "load-users-btn",
|
|
336
|
+
onClick: te((it) => pe(h, t.key), ["stop"])
|
|
337
|
+
}, {
|
|
338
|
+
default: k(() => [...e[9] || (e[9] = [
|
|
339
|
+
G(" 显示人员 ", -1)
|
|
340
|
+
])]),
|
|
341
|
+
_: 1
|
|
342
|
+
}, 8, ["onClick"])) : u("", !0)
|
|
343
|
+
], 2)
|
|
344
|
+
];
|
|
345
|
+
}),
|
|
346
|
+
_: 2
|
|
347
|
+
}, 1032, ["data", "value"])) : (a(), o("div", Ae, [
|
|
348
|
+
r(l, {
|
|
349
|
+
name: t.icon || "folder-open",
|
|
350
|
+
size: "48px",
|
|
351
|
+
style: { color: "#ddd" }
|
|
352
|
+
}, null, 8, ["name"]),
|
|
353
|
+
e[10] || (e[10] = n("p", null, "暂无数据", -1))
|
|
354
|
+
]))
|
|
355
|
+
])
|
|
356
|
+
];
|
|
357
|
+
}),
|
|
358
|
+
_: 2
|
|
359
|
+
}, 1032, ["value", "label"]))), 128))
|
|
360
|
+
]),
|
|
361
|
+
_: 1
|
|
362
|
+
}, 8, ["modelValue"]))
|
|
363
|
+
]),
|
|
364
|
+
n("div", Fe, [
|
|
365
|
+
n("div", je, [
|
|
366
|
+
e[12] || (e[12] = n("span", { class: "header-title" }, "已选择", -1)),
|
|
367
|
+
n("span", qe, v(R.value.length) + " 项", 1),
|
|
368
|
+
R.value.length > 0 ? (a(), b(y, {
|
|
369
|
+
key: 0,
|
|
370
|
+
size: "small",
|
|
371
|
+
variant: "text",
|
|
372
|
+
onClick: X
|
|
373
|
+
}, {
|
|
374
|
+
default: k(() => [...e[11] || (e[11] = [
|
|
375
|
+
G("清空", -1)
|
|
376
|
+
])]),
|
|
377
|
+
_: 1
|
|
378
|
+
})) : u("", !0)
|
|
379
|
+
]),
|
|
380
|
+
n("div", Ge, [
|
|
381
|
+
R.value.length === 0 ? (a(), o("div", He, [
|
|
382
|
+
r(l, {
|
|
383
|
+
name: "user-checked",
|
|
384
|
+
size: "64px",
|
|
385
|
+
style: { color: "#ddd" }
|
|
386
|
+
}),
|
|
387
|
+
e[13] || (e[13] = n("p", null, "暂无选择", -1))
|
|
388
|
+
])) : (a(), o("div", Ke, [
|
|
389
|
+
(a(!0), o(E, null, L(R.value, (t) => (a(), o("div", {
|
|
390
|
+
key: t.id,
|
|
391
|
+
class: W(["selected-user-item", { "selected-dept-item": !t.isUser }])
|
|
392
|
+
}, [
|
|
393
|
+
n("div", Qe, [
|
|
394
|
+
n("div", {
|
|
395
|
+
class: W(["user-avatar", { "dept-avatar": !t.isUser }])
|
|
396
|
+
}, [
|
|
397
|
+
r(l, {
|
|
398
|
+
name: t.isUser ? "user" : "folder"
|
|
399
|
+
}, null, 8, ["name"])
|
|
400
|
+
], 2),
|
|
401
|
+
n("div", Xe, [
|
|
402
|
+
n("div", Ye, v(t.displayName || t.name), 1),
|
|
403
|
+
n("div", Ze, [
|
|
404
|
+
t.isUser && t.position ? (a(), o("span", et, v(t.position), 1)) : u("", !0),
|
|
405
|
+
t.isUser && t.department ? (a(), o("span", tt, v(t.department), 1)) : u("", !0),
|
|
406
|
+
t.isUser ? u("", !0) : (a(), o("span", st, v(t.typeName || "部门"), 1)),
|
|
407
|
+
!t.isUser && t.userCount ? (a(), o("span", lt, v(t.userCount) + "人", 1)) : u("", !0)
|
|
408
|
+
])
|
|
409
|
+
])
|
|
410
|
+
]),
|
|
411
|
+
r(y, {
|
|
412
|
+
size: "small",
|
|
413
|
+
variant: "text",
|
|
414
|
+
shape: "circle",
|
|
415
|
+
onClick: (P) => he(t.id)
|
|
416
|
+
}, {
|
|
417
|
+
icon: k(() => [
|
|
418
|
+
r(l, { name: "close" })
|
|
419
|
+
]),
|
|
420
|
+
_: 1
|
|
421
|
+
}, 8, ["onClick"])
|
|
422
|
+
], 2))), 128))
|
|
423
|
+
]))
|
|
424
|
+
])
|
|
425
|
+
])
|
|
426
|
+
])
|
|
427
|
+
])
|
|
428
|
+
]),
|
|
429
|
+
_: 1
|
|
430
|
+
}, 8, ["visible", "width"]);
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
}), nt = (x, $) => {
|
|
434
|
+
const O = x.__vccOpts || x;
|
|
435
|
+
for (const [d, C] of $)
|
|
436
|
+
O[d] = C;
|
|
437
|
+
return O;
|
|
438
|
+
}, ot = /* @__PURE__ */ nt(at, [["__scopeId", "data-v-210902ae"]]), rt = {
|
|
439
|
+
install(x) {
|
|
440
|
+
x.component("PersonSelector", ot);
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
export {
|
|
444
|
+
ot as PersonSelector,
|
|
445
|
+
rt as default
|
|
446
|
+
};
|