@sy-common/organize-select-help 1.0.0-beta.69 → 1.0.0-beta.71

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.vue +221 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sy-common/organize-select-help",
3
- "version": "1.0.0-beta.69",
3
+ "version": "1.0.0-beta.71",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "lambo",
package/src/index.vue CHANGED
@@ -297,11 +297,31 @@
297
297
  <div class="clear-btn" @click="clearOrgNewList">清除全部</div>
298
298
  </div>
299
299
  <div class="group-list-content">
300
- <p class="list-item flex-r-bt" v-for="(item,index) in orgNewList" :key="item.id">
301
- <span>{{item.title}}</span>
302
- <img class="clear-icon" src="./assets/delete.png" alt="" @click="clearOrgNewByIndex(index)">
303
- </p>
304
- <p style="color:#CCCCCC" class="list-item" v-if="!orgNewList.length">未选择组织节点</p>
300
+ <div v-if="groupedOrgNewList.length > 0">
301
+ <div v-for="group in groupedOrgNewList" :key="group.parentOrgUnitId" class="org-group">
302
+ <div class="org-group-title">
303
+ <Icon type="md-folder" class="folder-icon" />
304
+ <span>{{ group.parentOrgName }}</span>
305
+ <span class="org-group-count">({{ group.items.length }})</span>
306
+ </div>
307
+ <div v-for="item in group.items" class="org-group-items">
308
+ <!-- <Tooltip -->
309
+ <!-- v-for="item in group.items" -->
310
+ <!-- :key="item.id" -->
311
+ <!-- :content="item.fullPath || item.title" -->
312
+ <!-- placement="left"-->
313
+ <!-- :max-width="400"-->
314
+ <!-- transfer-->
315
+ <!-- >-->
316
+ <p class="list-item flex-r-bt">
317
+ <span class="org-item-name">{{ item.title }}</span>
318
+ <img class="clear-icon" src="./assets/delete.png" alt="" @click="clearOrgNewByIndex(item.originalIndex)">
319
+ </p>
320
+ <!-- </Tooltip>-->
321
+ </div>
322
+ </div>
323
+ </div>
324
+ <p style="color:#CCCCCC" class="list-item" v-else>未选择组织节点</p>
305
325
  </div>
306
326
  </div>
307
327
  </div>
@@ -1360,11 +1380,19 @@ export default {
1360
1380
  this.orgNewList.splice(index,1)
1361
1381
  },
1362
1382
  confirm(){
1383
+ const cleanOrgNewList = this.orgNewList.map(item => ({
1384
+ id: item.id,
1385
+ orgUnitId: item.orgUnitId,
1386
+ orgNodeName: item.orgNodeName || item.title,
1387
+ title: item.title,
1388
+ includeLevel: item.includeLevel,
1389
+ parentOrgUnitId: item.parentOrgUnitId
1390
+ }))
1363
1391
  const v = {
1364
1392
  orgList:this.orgList,
1365
1393
  postList:this.postList,
1366
1394
  staffList:this.staffList,
1367
- orgNewList:this.orgNewList
1395
+ orgNewList:cleanOrgNewList
1368
1396
  }
1369
1397
  this.$emit('confirm',deepCopy(v))
1370
1398
  },
@@ -1964,6 +1992,10 @@ export default {
1964
1992
  // 处理树形数据,添加必要的字段
1965
1993
  const processedTree = this.processOrgNewTree(treeData);
1966
1994
  this.orgNewTree = this.safeDeepCopy(processedTree);
1995
+ // 树加载完成后,刷新 orgNewList 的父组织信息
1996
+ this.$nextTick(() => {
1997
+ this.refreshOrgNewListParentInfo();
1998
+ });
1967
1999
  }
1968
2000
  } catch (e) {
1969
2001
  this.$Message.error("组织选择(新)树初始化失败!");
@@ -2101,19 +2133,114 @@ export default {
2101
2133
  return;
2102
2134
  }
2103
2135
 
2136
+ // 获取父组织信息
2137
+ const parentInfo = this.findParentInfo(node.orgUnitId);
2138
+
2139
+ // 获取完整路径
2140
+ const fullPath = this.getOrgFullPath(node.orgUnitId);
2141
+
2142
+ // 根节点没有父组织时,使用自身作为分组(让根节点和其下级分到同一组)
2143
+ const finalParentId = parentInfo.id || node.orgUnitId;
2144
+ const finalParentName = parentInfo.name || node.title || node.orgNodeName;
2145
+
2104
2146
  // 创建组织条件项
2105
2147
  const orgItem = {
2106
2148
  ...node,
2107
2149
  title: includeLevel ? `${node.title}(包含下级组织节点)` : node.title,
2108
2150
  id: id,
2109
2151
  includeLevel: includeLevel,
2110
- orgNodeName: node.orgNodeName || node.title
2152
+ orgNodeName: node.orgNodeName || node.title,
2153
+ parentOrgUnitId: finalParentId,
2154
+ parentOrgName: finalParentName,
2155
+ fullPath: fullPath
2111
2156
  };
2112
2157
 
2113
2158
  // 添加到已选择列表
2114
2159
  this.orgNewList.push(orgItem);
2115
2160
  this.$Message.success(`已添加【${orgItem.title}】`);
2116
2161
  },
2162
+ findParentInfo(orgUnitId) {
2163
+ let result = { id: '', name: '' };
2164
+ const findParent = (nodes, parentId = '', parentName = '') => {
2165
+ for (const node of nodes) {
2166
+ if (node.orgUnitId === orgUnitId) {
2167
+ result = { id: parentId, name: parentName };
2168
+ return true;
2169
+ }
2170
+ if (node.children && node.children.length > 0) {
2171
+ if (findParent(node.children, node.orgUnitId, node.title || node.orgNodeName)) {
2172
+ return true;
2173
+ }
2174
+ }
2175
+ }
2176
+ return false;
2177
+ };
2178
+ findParent(this.orgNewTree);
2179
+ return result;
2180
+ },
2181
+ getOrgFullPath(orgUnitId) {
2182
+ const path = [];
2183
+ const findPath = (nodes, currentPath = []) => {
2184
+ for (const node of nodes) {
2185
+ const newPath = [...currentPath, node.title || node.orgNodeName];
2186
+ if (node.orgUnitId === orgUnitId) {
2187
+ path.push(...newPath);
2188
+ return true;
2189
+ }
2190
+ if (node.children && node.children.length > 0) {
2191
+ if (findPath(node.children, newPath)) {
2192
+ return true;
2193
+ }
2194
+ }
2195
+ }
2196
+ return false;
2197
+ };
2198
+ findPath(this.orgNewTree);
2199
+ return path.join(' > ');
2200
+ },
2201
+ findParentInfoFromTree(parentOrgUnitId) {
2202
+ let result = { id: parentOrgUnitId, name: '' };
2203
+ const findNode = (nodes) => {
2204
+ for (const node of nodes) {
2205
+ if (node.orgUnitId === parentOrgUnitId) {
2206
+ result.name = node.title || node.orgNodeName;
2207
+ return true;
2208
+ }
2209
+ if (node.children && node.children.length > 0) {
2210
+ if (findNode(node.children)) {
2211
+ return true;
2212
+ }
2213
+ }
2214
+ }
2215
+ return false;
2216
+ };
2217
+ findNode(this.orgNewTree);
2218
+ return result;
2219
+ },
2220
+ buildFullPathFromParent(item, parentInfo) {
2221
+ if (parentInfo.name) {
2222
+ return `${parentInfo.name} > ${item.title || item.orgNodeName}`;
2223
+ }
2224
+ return item.title || item.orgNodeName;
2225
+ },
2226
+ refreshOrgNewListParentInfo() {
2227
+ if (!this.orgNewTree || this.orgNewTree.length === 0) {
2228
+ return;
2229
+ }
2230
+ this.orgNewList.forEach(item => {
2231
+ if (item.parentOrgUnitId) {
2232
+ const parentInfo = this.findParentInfoFromTree(item.parentOrgUnitId);
2233
+ if (parentInfo.name) {
2234
+ item.parentOrgName = parentInfo.name;
2235
+ item.fullPath = this.buildFullPathFromParent(item, parentInfo);
2236
+ } else {
2237
+ item.parentOrgName = item.parentOrgName || '未知上级组织';
2238
+ }
2239
+ } else {
2240
+ item.parentOrgName = item.parentOrgName || '未知上级组织';
2241
+ }
2242
+ });
2243
+ },
2117
2244
  isProvinceAllSelected(province) {
2118
2245
  if (!province.children || province.children.length === 0) return false;
2119
2246
  return province.children.every(city => this.isCityAllSelected(city));
@@ -2276,6 +2403,29 @@ export default {
2276
2403
 
2277
2404
  // 直接使用原始树数据,不需要深拷贝
2278
2405
  return filterTree(this.orgNewTree);
2406
+ },
2407
+ groupedOrgNewList() {
2408
+ const groups = {};
2409
+ this.orgNewList.forEach((item, index) => {
2410
+ const groupKey = item.parentOrgUnitId || 'unknown';
2411
+ const groupName = item.parentOrgName || '未知上级组织';
2412
+ if (!groups[groupKey]) {
2413
+ groups[groupKey] = {
2414
+ parentOrgUnitId: groupKey,
2415
+ parentOrgName: groupName,
2416
+ items: []
2417
+ };
2418
+ }
2419
+ groups[groupKey].items.push({
2420
+ ...item,
2421
+ originalIndex: index
2422
+ });
2423
+ });
2424
+ return Object.values(groups).sort((a, b) => {
2425
+ if (a.parentOrgName === '未知上级组织') return 1;
2426
+ if (b.parentOrgName === '未知上级组织') return -1;
2427
+ return a.parentOrgName.localeCompare(b.parentOrgName, 'zh-CN');
2428
+ });
2279
2429
  }
2280
2430
  },
2281
2431
  watch:{
@@ -2300,11 +2450,30 @@ export default {
2300
2450
  this.postList = postList
2301
2451
  this.staffList = map.staffList || []
2302
2452
  let orgNewList = map.orgNewList || []
2303
- orgNewList.forEach(item=>{
2304
- item.title = item.includeLevel?`${item.orgNodeName}(包含下级组织节点)`:item.orgNodeName
2305
- item.id = item.includeLevel?('01'+'-' + item.orgUnitId):('00'+'-'+item.orgUnitId)
2453
+ orgNewList.forEach(item => {
2454
+ item.title = item.includeLevel ? `${item.orgNodeName}(包含下级组织节点)` : item.orgNodeName
2455
+ item.id = item.includeLevel ? ('01' + '-' + item.orgUnitId) : ('00' + '-' + item.orgUnitId)
2456
+ if (!item.parentOrgName && item.parentOrgUnitId) {
2457
+ if (this.orgNewTree && this.orgNewTree.length > 0) {
2458
+ const parentInfo = this.findParentInfoFromTree(item.parentOrgUnitId)
2459
+ item.parentOrgName = parentInfo.name
2460
+ item.fullPath = item.fullPath || this.buildFullPathFromParent(item, parentInfo)
2461
+ } else {
2462
+ item.parentOrgName = item.parentOrgName || '加载中...'
2463
+ }
2464
+ }
2465
+ if (!item.parentOrgName) {
2466
+ item.parentOrgName = '未知上级组织'
2467
+ }
2306
2468
  })
2307
2469
  this.orgNewList = orgNewList
2470
+ if (orgNewList.some(item => item.parentOrgName === '加载中...')) {
2471
+ this.$nextTick(() => {
2472
+ setTimeout(() => {
2473
+ this.refreshOrgNewListParentInfo()
2474
+ }, 1000)
2475
+ })
2476
+ }
2308
2477
  },
2309
2478
  deep: true,
2310
2479
  immediate: true,
@@ -3318,6 +3487,48 @@ export default {
3318
3487
  .clear-icon{
3319
3488
  cursor:pointer;
3320
3489
  }
3490
+ .org-group {
3491
+ margin-bottom: 12px;
3492
+ &:last-child {
3493
+ margin-bottom: 0;
3494
+ }
3495
+ .org-group-title {
3496
+ display: flex;
3497
+ align-items: center;
3498
+ padding: 6px 0;
3499
+ font-size: 13px;
3500
+ font-weight: 500;
3501
+ color: #666;
3502
+ border-bottom: 1px dashed #E5E6EB;
3503
+ margin-bottom: 8px;
3504
+ .folder-icon {
3505
+ margin-right: 6px;
3506
+ color: #faad14;
3507
+ font-size: 14px;
3508
+ }
3509
+ .org-group-count {
3510
+ margin-left: 4px;
3511
+ color: #999;
3512
+ font-weight: normal;
3513
+ font-size: 12px;
3514
+ }
3515
+ }
3516
+ .org-group-items {
3517
+ padding-left: 4px;
3518
+ .list-item {
3519
+ margin-top: 6px;
3520
+ &:first-child {
3521
+ margin-top: 0;
3522
+ }
3523
+ }
3524
+ }
3525
+ }
3526
+ .org-item-name {
3527
+ flex: 1;
3528
+ overflow: hidden;
3529
+ text-overflow: ellipsis;
3530
+ white-space: nowrap;
3531
+ }
3321
3532
  }
3322
3533
  .list-item{
3323
3534
  background:#F4F6FA;