@weitutech/by-components 1.1.221 → 1.2.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/lib/by-components.common.js +2914 -422
- package/lib/by-components.umd.js +3064 -572
- package/lib/by-components.umd.min.js +15 -15
- package/lib/index.css +1 -1
- package/package.json +1 -1
|
@@ -74276,6 +74276,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
74276
74276
|
ByCardSelector: function() { return /* reexport */ ByCardSelector; },
|
|
74277
74277
|
ByCardView: function() { return /* reexport */ ByCardView; },
|
|
74278
74278
|
ByCascaderPanel: function() { return /* reexport */ ByCascaderPanel; },
|
|
74279
|
+
ByCascaderPanelPro: function() { return /* reexport */ ByCascaderPanelPro; },
|
|
74279
74280
|
ByCommonInput: function() { return /* reexport */ ByCommonInput; },
|
|
74280
74281
|
ByCommonSelector: function() { return /* reexport */ ByCommonSelector; },
|
|
74281
74282
|
ByCustomDatePicker: function() { return /* reexport */ custom_date_picker; },
|
|
@@ -74293,7 +74294,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
74293
74294
|
ByTable: function() { return /* reexport */ table; },
|
|
74294
74295
|
ByTag: function() { return /* reexport */ ByTag; },
|
|
74295
74296
|
ByToolBar: function() { return /* reexport */ ByToolBar; },
|
|
74296
|
-
ByTreePanel: function() { return /* reexport */ ByTreePanel; },
|
|
74297
74297
|
ByTreeSearch: function() { return /* reexport */ ByTreeSearch; },
|
|
74298
74298
|
GridItem: function() { return /* reexport */ vue_grid_layout_common.GridItem; },
|
|
74299
74299
|
ToolBarItemType: function() { return /* reexport */ ToolBarItemType; },
|
|
@@ -96015,12 +96015,12 @@ var ByCascaderPanel_component = normalizeComponent(
|
|
|
96015
96015
|
)
|
|
96016
96016
|
|
|
96017
96017
|
/* harmony default export */ var ByCascaderPanel = (ByCascaderPanel_component.exports);
|
|
96018
|
-
;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"8cd600e8-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/
|
|
96019
|
-
var
|
|
96018
|
+
;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"8cd600e8-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/ByCascaderPanelPro.vue?vue&type=template&id=4bdb9820
|
|
96019
|
+
var ByCascaderPanelProvue_type_template_id_4bdb9820_render = function render() {
|
|
96020
96020
|
var _vm = this,
|
|
96021
96021
|
_c = _vm._self._c;
|
|
96022
96022
|
return _c('div', {
|
|
96023
|
-
staticClass: "
|
|
96023
|
+
staticClass: "cascader-panel-pro"
|
|
96024
96024
|
}, [_c('div', {
|
|
96025
96025
|
staticClass: "panel-container"
|
|
96026
96026
|
}, [_c('div', {
|
|
@@ -96041,9 +96041,6 @@ var ByTreePanelvue_type_template_id_af06ba0a_render = function render() {
|
|
|
96041
96041
|
"size": "mini",
|
|
96042
96042
|
"disabled": _vm.isViewMode
|
|
96043
96043
|
},
|
|
96044
|
-
on: {
|
|
96045
|
-
"input": _vm.handleSearch
|
|
96046
|
-
},
|
|
96047
96044
|
model: {
|
|
96048
96045
|
value: _vm.searchInput,
|
|
96049
96046
|
callback: function ($$v) {
|
|
@@ -96056,7 +96053,7 @@ var ByTreePanelvue_type_template_id_af06ba0a_render = function render() {
|
|
|
96056
96053
|
"placement": "bottom-start",
|
|
96057
96054
|
"width": 300,
|
|
96058
96055
|
"trigger": "click",
|
|
96059
|
-
"popper-class": "batch-search-popover"
|
|
96056
|
+
"popper-class": "batch-search-popover-pro"
|
|
96060
96057
|
},
|
|
96061
96058
|
on: {
|
|
96062
96059
|
"show": _vm.handleBatchSearchShow
|
|
@@ -96128,26 +96125,68 @@ var ByTreePanelvue_type_template_id_af06ba0a_render = function render() {
|
|
|
96128
96125
|
height: _vm.computedPanelHeight + 'px'
|
|
96129
96126
|
}
|
|
96130
96127
|
}, [_c('div', {
|
|
96131
|
-
staticClass: "
|
|
96132
|
-
|
|
96133
|
-
|
|
96134
|
-
|
|
96128
|
+
staticClass: "cascader-content-wrapper",
|
|
96129
|
+
style: {
|
|
96130
|
+
height: '100%'
|
|
96131
|
+
}
|
|
96132
|
+
}, [_vm.isShow && _vm.filteredOptions.length > 0 ? _c('VirtualCascaderPanel', {
|
|
96133
|
+
directives: [{
|
|
96134
|
+
name: "show",
|
|
96135
|
+
rawName: "v-show",
|
|
96136
|
+
value: _vm.searchInput === '' || !_vm.isShowSearch,
|
|
96137
|
+
expression: "searchInput === '' || !isShowSearch"
|
|
96138
|
+
}],
|
|
96139
|
+
ref: "cascaderPanel",
|
|
96140
|
+
staticClass: "cascader-panel-inner",
|
|
96141
|
+
style: {
|
|
96142
|
+
height: _vm.computedPanelHeight - 20 + 'px'
|
|
96143
|
+
},
|
|
96135
96144
|
attrs: {
|
|
96136
|
-
"
|
|
96137
|
-
"
|
|
96138
|
-
"
|
|
96139
|
-
"
|
|
96140
|
-
"
|
|
96141
|
-
"
|
|
96142
|
-
"
|
|
96143
|
-
"
|
|
96144
|
-
"
|
|
96145
|
+
"value": _vm.panelPresentationValue,
|
|
96146
|
+
"sync-value-from-parent": !_vm.useCompactSelection,
|
|
96147
|
+
"options": _vm.filteredOptions,
|
|
96148
|
+
"props": _vm.cascaderProps,
|
|
96149
|
+
"height": _vm.computedPanelHeight - 20,
|
|
96150
|
+
"column-min-width": _vm.columnMinWidth,
|
|
96151
|
+
"column-max-width": _vm.columnMaxWidth,
|
|
96152
|
+
"disabled-config": _vm.disabledConfig,
|
|
96153
|
+
"is-view-mode": _vm.isViewMode
|
|
96154
|
+
},
|
|
96155
|
+
on: {
|
|
96156
|
+
"input": _vm.onMainPanelInput,
|
|
96157
|
+
"change": _vm.handleValueChange
|
|
96158
|
+
}
|
|
96159
|
+
}) : _vm._e(), _vm.searchOptions.length > 0 ? _c('VirtualCascaderPanel', {
|
|
96160
|
+
directives: [{
|
|
96161
|
+
name: "show",
|
|
96162
|
+
rawName: "v-show",
|
|
96163
|
+
value: _vm.searchInput !== '' && _vm.isShowSearch,
|
|
96164
|
+
expression: "searchInput !== '' && isShowSearch"
|
|
96165
|
+
}],
|
|
96166
|
+
ref: "searchCascaderPanel",
|
|
96167
|
+
staticClass: "cascader-panel-inner",
|
|
96168
|
+
attrs: {
|
|
96169
|
+
"value": _vm.compactSearchPanelValue,
|
|
96170
|
+
"sync-value-from-parent": false,
|
|
96171
|
+
"options": _vm.searchOptions,
|
|
96172
|
+
"props": _vm.cascaderProps,
|
|
96173
|
+
"height": _vm.computedPanelHeight - 20,
|
|
96174
|
+
"column-min-width": _vm.columnMinWidth,
|
|
96175
|
+
"column-max-width": _vm.columnMaxWidth,
|
|
96176
|
+
"disabled-config": _vm.disabledConfig,
|
|
96177
|
+
"is-view-mode": _vm.isViewMode
|
|
96145
96178
|
},
|
|
96146
96179
|
on: {
|
|
96147
|
-
"
|
|
96148
|
-
"
|
|
96180
|
+
"input": _vm.onSearchPanelInput,
|
|
96181
|
+
"change": _vm.handleSearchValueChange
|
|
96149
96182
|
}
|
|
96150
|
-
}) : _vm.
|
|
96183
|
+
}) : _vm._e(), _vm.isShowSearch && _vm.searchOptions.length === 0 ? _c('div', {
|
|
96184
|
+
directives: [{
|
|
96185
|
+
name: "show",
|
|
96186
|
+
rawName: "v-show",
|
|
96187
|
+
value: _vm.searchInput !== '',
|
|
96188
|
+
expression: "searchInput !== ''"
|
|
96189
|
+
}],
|
|
96151
96190
|
staticClass: "empty-search"
|
|
96152
96191
|
}, [_c('el-empty', {
|
|
96153
96192
|
attrs: {
|
|
@@ -96173,33 +96212,54 @@ var ByTreePanelvue_type_template_id_af06ba0a_render = function render() {
|
|
|
96173
96212
|
}
|
|
96174
96213
|
}, [_c('div', {
|
|
96175
96214
|
staticClass: "selected-list"
|
|
96176
|
-
}, [_vm.
|
|
96177
|
-
|
|
96178
|
-
|
|
96179
|
-
|
|
96180
|
-
},
|
|
96181
|
-
|
|
96182
|
-
|
|
96183
|
-
|
|
96184
|
-
|
|
96185
|
-
|
|
96186
|
-
|
|
96187
|
-
|
|
96188
|
-
|
|
96189
|
-
|
|
96190
|
-
|
|
96191
|
-
|
|
96215
|
+
}, [_vm.selectedItems.length > 0 ? _c('VcpVirtualList', {
|
|
96216
|
+
staticClass: "selected-virtual-list",
|
|
96217
|
+
style: {
|
|
96218
|
+
height: _vm.selectedListHeight + 'px'
|
|
96219
|
+
},
|
|
96220
|
+
attrs: {
|
|
96221
|
+
"items": _vm.selectedItems,
|
|
96222
|
+
"item-height": _vm.selectedItemHeight,
|
|
96223
|
+
"height": _vm.selectedListHeight,
|
|
96224
|
+
"list-padding": 0,
|
|
96225
|
+
"overscan": 10
|
|
96226
|
+
},
|
|
96227
|
+
scopedSlots: _vm._u([{
|
|
96228
|
+
key: "default",
|
|
96229
|
+
fn: function ({
|
|
96230
|
+
item,
|
|
96231
|
+
index
|
|
96232
|
+
}) {
|
|
96233
|
+
return [_c('div', {
|
|
96234
|
+
key: 'selected-' + item.value + '-' + index,
|
|
96235
|
+
staticClass: "selected-item-row"
|
|
96236
|
+
}, [_c('div', {
|
|
96237
|
+
staticClass: "selected-item"
|
|
96238
|
+
}, [_c('div', {
|
|
96239
|
+
staticClass: "item-content"
|
|
96240
|
+
}, [_c('div', {
|
|
96241
|
+
staticClass: "item-label"
|
|
96242
|
+
}, [_vm._v(_vm._s(item.label || ''))]), _vm.showSubtitle && _vm.subtitleField && item[_vm.subtitleField] ? _c('div', {
|
|
96243
|
+
staticClass: "item-subtitle"
|
|
96244
|
+
}, [_vm._v(" " + _vm._s(item[_vm.subtitleField]) + " ")]) : _vm._e()]), !_vm.isViewMode ? _c('div', {
|
|
96245
|
+
staticClass: "remove-btn",
|
|
96246
|
+
on: {
|
|
96247
|
+
"click": function ($event) {
|
|
96248
|
+
return _vm.removeItem(item, index);
|
|
96249
|
+
}
|
|
96250
|
+
}
|
|
96251
|
+
}, [_c('i', {
|
|
96252
|
+
staticClass: "el-icon-close"
|
|
96253
|
+
})]) : _vm._e()])])];
|
|
96192
96254
|
}
|
|
96193
|
-
},
|
|
96194
|
-
|
|
96195
|
-
})]) : _vm._e()]);
|
|
96196
|
-
}), _vm.selectedItems.length === 0 ? _c('div', {
|
|
96255
|
+
}], null, false, 2638469921)
|
|
96256
|
+
}) : _c('div', {
|
|
96197
96257
|
staticClass: "empty-state"
|
|
96198
|
-
}, [_vm._v("暂无选中项")])
|
|
96258
|
+
}, [_vm._v("暂无选中项")])], 1)])])])]);
|
|
96199
96259
|
};
|
|
96200
|
-
var
|
|
96260
|
+
var ByCascaderPanelProvue_type_template_id_4bdb9820_staticRenderFns = [];
|
|
96201
96261
|
|
|
96202
|
-
;// ./
|
|
96262
|
+
;// ./src/components/cascader-panel-pro/cascaderUtilsPro.js
|
|
96203
96263
|
|
|
96204
96264
|
|
|
96205
96265
|
|
|
@@ -96208,374 +96268,2669 @@ var ByTreePanelvue_type_template_id_af06ba0a_staticRenderFns = [];
|
|
|
96208
96268
|
|
|
96209
96269
|
|
|
96210
96270
|
|
|
96211
|
-
|
|
96212
|
-
|
|
96213
|
-
|
|
96214
|
-
|
|
96215
|
-
|
|
96216
|
-
|
|
96217
|
-
|
|
96218
|
-
|
|
96219
|
-
|
|
96220
|
-
|
|
96221
|
-
|
|
96222
|
-
|
|
96223
|
-
|
|
96224
|
-
|
|
96225
|
-
|
|
96226
|
-
|
|
96227
|
-
|
|
96228
|
-
children: 'children'
|
|
96229
|
-
})
|
|
96230
|
-
},
|
|
96231
|
-
panelHeight: {
|
|
96232
|
-
type: [String, Number],
|
|
96233
|
-
default: 300
|
|
96234
|
-
},
|
|
96235
|
-
searchPlaceholder: {
|
|
96236
|
-
type: String,
|
|
96237
|
-
default: '请输入名称搜索'
|
|
96238
|
-
},
|
|
96239
|
-
disabledField: {
|
|
96240
|
-
type: String,
|
|
96241
|
-
default: 'disabled'
|
|
96242
|
-
},
|
|
96243
|
-
disabledValue: {
|
|
96244
|
-
type: [String, Number, Boolean],
|
|
96245
|
-
default: true
|
|
96246
|
-
},
|
|
96247
|
-
disabledCheck: {
|
|
96248
|
-
type: Function,
|
|
96249
|
-
default: null
|
|
96250
|
-
},
|
|
96251
|
-
showSelectAll: {
|
|
96252
|
-
type: Boolean,
|
|
96253
|
-
default: true
|
|
96254
|
-
},
|
|
96255
|
-
aggregationMode: {
|
|
96256
|
-
type: Boolean,
|
|
96257
|
-
default: false
|
|
96258
|
-
},
|
|
96259
|
-
parentNodePrefix: {
|
|
96260
|
-
type: String,
|
|
96261
|
-
default: '__parent__'
|
|
96262
|
-
},
|
|
96263
|
-
isViewMode: {
|
|
96264
|
-
type: Boolean,
|
|
96265
|
-
default: false
|
|
96266
|
-
},
|
|
96267
|
-
showSubtitle: {
|
|
96268
|
-
type: Boolean,
|
|
96269
|
-
default: false
|
|
96270
|
-
},
|
|
96271
|
-
subtitleField: {
|
|
96272
|
-
type: String,
|
|
96273
|
-
default: ''
|
|
96274
|
-
}
|
|
96275
|
-
},
|
|
96276
|
-
data() {
|
|
96277
|
-
return {
|
|
96278
|
-
selectedValues: [],
|
|
96279
|
-
filteredOptions: [],
|
|
96280
|
-
displayOptions: [],
|
|
96281
|
-
selectedItems: [],
|
|
96282
|
-
searchInput: '',
|
|
96283
|
-
totalCount: 0,
|
|
96284
|
-
selectedCount: 0,
|
|
96285
|
-
isAllSelected: false,
|
|
96286
|
-
isInternalUpdate: false,
|
|
96287
|
-
batchSearchVisible: false,
|
|
96288
|
-
batchSearchContent: '',
|
|
96289
|
-
searchDebounceTimer: null,
|
|
96290
|
-
isSyncingTree: false
|
|
96291
|
-
};
|
|
96292
|
-
},
|
|
96293
|
-
computed: {
|
|
96294
|
-
computedPanelHeight() {
|
|
96295
|
-
const height = Number(this.panelHeight);
|
|
96296
|
-
if (isNaN(height)) return 300;
|
|
96297
|
-
return Math.max(200, Math.min(800, height));
|
|
96298
|
-
},
|
|
96299
|
-
isMultiple() {
|
|
96300
|
-
return this.cascaderProps.multiple !== false;
|
|
96301
|
-
},
|
|
96302
|
-
valueKey() {
|
|
96303
|
-
return this.cascaderProps.value || 'value';
|
|
96304
|
-
},
|
|
96305
|
-
labelKey() {
|
|
96306
|
-
return this.cascaderProps.label || 'label';
|
|
96307
|
-
},
|
|
96308
|
-
childrenKey() {
|
|
96309
|
-
return this.cascaderProps.children || 'children';
|
|
96310
|
-
},
|
|
96311
|
-
nodeKey() {
|
|
96312
|
-
return this.valueKey;
|
|
96313
|
-
},
|
|
96314
|
-
treeFieldProps() {
|
|
96315
|
-
return {
|
|
96316
|
-
label: this.labelKey,
|
|
96317
|
-
children: this.childrenKey,
|
|
96318
|
-
disabled: 'disabled'
|
|
96319
|
-
};
|
|
96320
|
-
},
|
|
96321
|
-
disabledConfig() {
|
|
96322
|
-
return {
|
|
96323
|
-
disabledField: this.disabledField,
|
|
96324
|
-
disabledValue: this.disabledValue,
|
|
96325
|
-
disabledCheck: this.disabledCheck
|
|
96326
|
-
};
|
|
96327
|
-
},
|
|
96328
|
-
currentValue() {
|
|
96329
|
-
if (this.isMultiple) {
|
|
96330
|
-
return this.selectedItems.map(item => item.value);
|
|
96331
|
-
}
|
|
96332
|
-
return this.selectedItems.length > 0 ? this.selectedItems[0].value : null;
|
|
96271
|
+
|
|
96272
|
+
|
|
96273
|
+
|
|
96274
|
+
|
|
96275
|
+
|
|
96276
|
+
|
|
96277
|
+
|
|
96278
|
+
/**
|
|
96279
|
+
* 级联选择器工具类(Pro 版,独立于 CascaderUtils)
|
|
96280
|
+
*/
|
|
96281
|
+
class CascaderUtilsPro {
|
|
96282
|
+
/**
|
|
96283
|
+
* 估算级联节点标签文本宽度(px)
|
|
96284
|
+
*/
|
|
96285
|
+
static measureCascaderLabelWidth(label, fontSize = 14) {
|
|
96286
|
+
if (!label) {
|
|
96287
|
+
return 0;
|
|
96333
96288
|
}
|
|
96334
|
-
|
|
96335
|
-
|
|
96336
|
-
|
|
96337
|
-
|
|
96338
|
-
|
|
96339
|
-
},
|
|
96340
|
-
immediate: true
|
|
96341
|
-
},
|
|
96342
|
-
value: {
|
|
96343
|
-
handler() {
|
|
96344
|
-
if (this.isInternalUpdate) {
|
|
96345
|
-
this.isInternalUpdate = false;
|
|
96346
|
-
return;
|
|
96347
|
-
}
|
|
96348
|
-
if (!this.filteredOptions.length) return;
|
|
96349
|
-
this.processValue();
|
|
96350
|
-
},
|
|
96351
|
-
deep: true
|
|
96352
|
-
},
|
|
96353
|
-
selectedValues: {
|
|
96354
|
-
handler() {
|
|
96355
|
-
this.updateSelectAllState();
|
|
96356
|
-
},
|
|
96357
|
-
deep: true
|
|
96289
|
+
const str = String(label);
|
|
96290
|
+
let width = 0;
|
|
96291
|
+
for (let i = 0; i < str.length; i++) {
|
|
96292
|
+
const code = str.charCodeAt(i);
|
|
96293
|
+
width += code > 255 ? fontSize : Math.ceil(fontSize * 0.55);
|
|
96358
96294
|
}
|
|
96359
|
-
|
|
96360
|
-
|
|
96361
|
-
|
|
96362
|
-
|
|
96363
|
-
|
|
96295
|
+
return width;
|
|
96296
|
+
}
|
|
96297
|
+
|
|
96298
|
+
/**
|
|
96299
|
+
* 根据列内最长标签计算列宽
|
|
96300
|
+
*/
|
|
96301
|
+
static getCascaderColumnWidth(nodes, options = {}) {
|
|
96302
|
+
const {
|
|
96303
|
+
minWidth = 180,
|
|
96304
|
+
maxWidth = 420,
|
|
96305
|
+
extraPadding = 56,
|
|
96306
|
+
hasCheckbox = true
|
|
96307
|
+
} = options;
|
|
96308
|
+
if (!nodes || nodes.length === 0) {
|
|
96309
|
+
return minWidth;
|
|
96310
|
+
}
|
|
96311
|
+
let maxLabelWidth = 0;
|
|
96312
|
+
nodes.forEach(node => {
|
|
96313
|
+
maxLabelWidth = Math.max(maxLabelWidth, this.measureCascaderLabelWidth(node.label));
|
|
96364
96314
|
});
|
|
96365
|
-
|
|
96366
|
-
|
|
96367
|
-
|
|
96368
|
-
|
|
96315
|
+
const checkboxWidth = hasCheckbox ? 28 : 0;
|
|
96316
|
+
const arrowWidth = 24;
|
|
96317
|
+
const contentWidth = maxLabelWidth + extraPadding + checkboxWidth + arrowWidth;
|
|
96318
|
+
return Math.min(maxWidth, Math.max(minWidth, Math.ceil(contentWidth)));
|
|
96319
|
+
}
|
|
96320
|
+
|
|
96321
|
+
/**
|
|
96322
|
+
* 判断项目是否禁用
|
|
96323
|
+
* @param {Object} item - 项目数据
|
|
96324
|
+
* @param {Object} config - 禁用配置
|
|
96325
|
+
* @param {String} config.disabledField - 禁用字段名
|
|
96326
|
+
* @param {*} config.disabledValue - 禁用值
|
|
96327
|
+
* @param {Function} config.disabledCheck - 自定义禁用判断函数
|
|
96328
|
+
* @returns {Boolean} 是否禁用
|
|
96329
|
+
*/
|
|
96330
|
+
static isItemDisabled(item, config) {
|
|
96331
|
+
const {
|
|
96332
|
+
disabledField,
|
|
96333
|
+
disabledValue,
|
|
96334
|
+
disabledCheck
|
|
96335
|
+
} = config;
|
|
96336
|
+
|
|
96337
|
+
// 优先使用自定义禁用判断函数
|
|
96338
|
+
if (disabledCheck && typeof disabledCheck === 'function') {
|
|
96339
|
+
return disabledCheck(item);
|
|
96369
96340
|
}
|
|
96370
|
-
|
|
96371
|
-
|
|
96372
|
-
|
|
96373
|
-
|
|
96374
|
-
|
|
96375
|
-
|
|
96376
|
-
|
|
96377
|
-
|
|
96378
|
-
|
|
96379
|
-
|
|
96380
|
-
|
|
96381
|
-
|
|
96382
|
-
|
|
96383
|
-
|
|
96384
|
-
|
|
96385
|
-
|
|
96386
|
-
|
|
96341
|
+
|
|
96342
|
+
// 检查直接的 disabled 属性
|
|
96343
|
+
if (item.disabled === true) {
|
|
96344
|
+
return true;
|
|
96345
|
+
}
|
|
96346
|
+
|
|
96347
|
+
// 使用字段判断
|
|
96348
|
+
const fieldValue = item[disabledField];
|
|
96349
|
+
if (fieldValue !== undefined) {
|
|
96350
|
+
return fieldValue === disabledValue;
|
|
96351
|
+
}
|
|
96352
|
+
return false;
|
|
96353
|
+
}
|
|
96354
|
+
|
|
96355
|
+
/**
|
|
96356
|
+
* 检查路径上是否存在禁选项
|
|
96357
|
+
* @param {Array} tree - 树形数据
|
|
96358
|
+
* @param {Array} path - 路径数组
|
|
96359
|
+
* @param {Object} config - 禁用配置
|
|
96360
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96361
|
+
* @returns {Boolean} 路径上是否存在禁选项
|
|
96362
|
+
*/
|
|
96363
|
+
static isPathDisabled(tree, path, config, cascaderProps) {
|
|
96364
|
+
if (!path || path.length === 0) return false;
|
|
96365
|
+
const findPathInTree = (nodes, targetPath, currentIndex = 0) => {
|
|
96366
|
+
if (currentIndex >= targetPath.length) return false;
|
|
96367
|
+
for (const node of nodes) {
|
|
96368
|
+
if (node[cascaderProps.value] === targetPath[currentIndex]) {
|
|
96369
|
+
// 检查当前节点是否禁用
|
|
96370
|
+
if (this.isItemDisabled(node, config)) {
|
|
96371
|
+
return true;
|
|
96372
|
+
}
|
|
96373
|
+
|
|
96374
|
+
// 如果还有下一级,继续检查
|
|
96375
|
+
if (currentIndex < targetPath.length - 1 && node[cascaderProps.children]) {
|
|
96376
|
+
return findPathInTree(node[cascaderProps.children], targetPath, currentIndex + 1);
|
|
96377
|
+
}
|
|
96378
|
+
|
|
96379
|
+
// 如果已经到达路径末尾,返回false(路径上没有禁选项)
|
|
96380
|
+
return false;
|
|
96381
|
+
}
|
|
96382
|
+
}
|
|
96383
|
+
return false;
|
|
96384
|
+
};
|
|
96385
|
+
return findPathInTree(tree, path);
|
|
96386
|
+
}
|
|
96387
|
+
|
|
96388
|
+
/**
|
|
96389
|
+
* 设置禁用项
|
|
96390
|
+
* @param {Array} options - 选项数据
|
|
96391
|
+
* @param {Object} config - 禁用配置
|
|
96392
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96393
|
+
*/
|
|
96394
|
+
static setDisabledItems(options, config, cascaderProps) {
|
|
96395
|
+
const processItems = items => {
|
|
96396
|
+
items.forEach(item => {
|
|
96397
|
+
// 判断是否禁用
|
|
96398
|
+
if (this.isItemDisabled(item, config)) {
|
|
96399
|
+
item.disabled = true;
|
|
96400
|
+
}
|
|
96401
|
+
// 递归处理子项
|
|
96402
|
+
if (item[cascaderProps.children]) {
|
|
96403
|
+
processItems(item[cascaderProps.children]);
|
|
96404
|
+
}
|
|
96405
|
+
});
|
|
96406
|
+
};
|
|
96407
|
+
processItems(options);
|
|
96408
|
+
}
|
|
96409
|
+
|
|
96410
|
+
/**
|
|
96411
|
+
* 统计总项目数(排除禁用项和路径上有禁选项的项)
|
|
96412
|
+
* @param {Array} options - 选项数据
|
|
96413
|
+
* @param {Object} config - 禁用配置
|
|
96414
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96415
|
+
* @returns {Number} 总项目数
|
|
96416
|
+
*/
|
|
96417
|
+
static countTotalItems(options, config, cascaderProps) {
|
|
96418
|
+
let totalCount = 0;
|
|
96419
|
+
const countItems = (items, currentPath = []) => {
|
|
96420
|
+
items.forEach(item => {
|
|
96421
|
+
const newPath = [...currentPath, item[cascaderProps.value]];
|
|
96422
|
+
|
|
96423
|
+
// 检查当前节点是否禁用
|
|
96424
|
+
const isCurrentDisabled = this.isItemDisabled(item, config);
|
|
96425
|
+
if (!item[cascaderProps.children]) {
|
|
96426
|
+
// 只统计非禁用项且路径上没有禁选项的叶子节点
|
|
96427
|
+
if (!isCurrentDisabled && !this.isPathDisabled(options, newPath, config, cascaderProps)) {
|
|
96428
|
+
totalCount++;
|
|
96429
|
+
}
|
|
96430
|
+
} else {
|
|
96431
|
+
// 如果当前节点禁用,则其所有子节点都不可选
|
|
96432
|
+
if (!isCurrentDisabled) {
|
|
96433
|
+
countItems(item[cascaderProps.children], newPath);
|
|
96434
|
+
}
|
|
96435
|
+
}
|
|
96436
|
+
});
|
|
96437
|
+
};
|
|
96438
|
+
countItems(options);
|
|
96439
|
+
return totalCount;
|
|
96440
|
+
}
|
|
96441
|
+
|
|
96442
|
+
/**
|
|
96443
|
+
* 在树形数据中搜索
|
|
96444
|
+
* @param {Array} tree - 树形数据
|
|
96445
|
+
* @param {String} keyword - 搜索关键词
|
|
96446
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96447
|
+
* @returns {Array} 搜索结果
|
|
96448
|
+
*/
|
|
96449
|
+
static searchInTree(tree, keyword, cascaderProps) {
|
|
96450
|
+
const result = [];
|
|
96451
|
+
const labelKey = cascaderProps.label || 'label';
|
|
96452
|
+
const childrenKey = cascaderProps.children || 'children';
|
|
96453
|
+
tree.forEach(node => {
|
|
96454
|
+
const label = node[labelKey];
|
|
96455
|
+
if (label && label.includes(keyword)) {
|
|
96456
|
+
result.push({
|
|
96457
|
+
...node
|
|
96458
|
+
});
|
|
96459
|
+
} else if (node[childrenKey]) {
|
|
96460
|
+
const matchedChildren = this.searchInTree(node[childrenKey], keyword, cascaderProps);
|
|
96461
|
+
if (matchedChildren.length > 0) {
|
|
96462
|
+
result.push({
|
|
96463
|
+
...node,
|
|
96464
|
+
[childrenKey]: matchedChildren
|
|
96465
|
+
});
|
|
96466
|
+
}
|
|
96467
|
+
}
|
|
96468
|
+
});
|
|
96469
|
+
return result;
|
|
96470
|
+
}
|
|
96471
|
+
|
|
96472
|
+
/**
|
|
96473
|
+
* 基于扁平 store 快速搜索(父节点命中时直接复用 raw 子树,跳过子级遍历)
|
|
96474
|
+
*/
|
|
96475
|
+
static searchFromStore(store, keyword, cascaderProps) {
|
|
96476
|
+
if (!store || !keyword) {
|
|
96477
|
+
return [];
|
|
96478
|
+
}
|
|
96479
|
+
const childrenKey = cascaderProps.children || 'children';
|
|
96480
|
+
const walk = parentId => {
|
|
96481
|
+
const childIds = parentId == null ? store.rootIds : store.childrenByParentId.get(parentId) || [];
|
|
96482
|
+
const result = [];
|
|
96483
|
+
for (let i = 0; i < childIds.length; i++) {
|
|
96484
|
+
const node = store.nodeById.get(childIds[i]);
|
|
96485
|
+
if (!node) {
|
|
96486
|
+
continue;
|
|
96487
|
+
}
|
|
96488
|
+
const label = node.label || '';
|
|
96489
|
+
if (label.includes(keyword)) {
|
|
96490
|
+
result.push({
|
|
96491
|
+
...node.raw
|
|
96492
|
+
});
|
|
96493
|
+
} else if (!node.isLeaf) {
|
|
96494
|
+
const matchedChildren = walk(node.id);
|
|
96495
|
+
if (matchedChildren.length > 0) {
|
|
96496
|
+
result.push({
|
|
96497
|
+
...node.raw,
|
|
96498
|
+
[childrenKey]: matchedChildren
|
|
96499
|
+
});
|
|
96500
|
+
}
|
|
96501
|
+
}
|
|
96502
|
+
}
|
|
96503
|
+
return result;
|
|
96504
|
+
};
|
|
96505
|
+
return walk(null);
|
|
96506
|
+
}
|
|
96507
|
+
|
|
96508
|
+
/**
|
|
96509
|
+
* 获取叶子节点的值
|
|
96510
|
+
* @param {Array} tree - 树形数据
|
|
96511
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96512
|
+
* @returns {Array} 叶子节点值数组
|
|
96513
|
+
*/
|
|
96514
|
+
static getLeafValues(tree, cascaderProps) {
|
|
96515
|
+
const leafValues = [];
|
|
96516
|
+
const traverse = nodes => {
|
|
96517
|
+
nodes.forEach(node => {
|
|
96518
|
+
if (!node[cascaderProps.children]) {
|
|
96519
|
+
leafValues.push(node[cascaderProps.value]);
|
|
96520
|
+
} else {
|
|
96521
|
+
traverse(node[cascaderProps.children]);
|
|
96522
|
+
}
|
|
96523
|
+
});
|
|
96524
|
+
};
|
|
96525
|
+
traverse(tree);
|
|
96526
|
+
return leafValues;
|
|
96527
|
+
}
|
|
96528
|
+
|
|
96529
|
+
/**
|
|
96530
|
+
* 获取所有叶子节点的路径(排除禁用项和路径上有禁选项的项)
|
|
96531
|
+
* @param {Array} tree - 树形数据
|
|
96532
|
+
* @param {Object} config - 禁用配置
|
|
96533
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96534
|
+
* @returns {Array} 路径数组
|
|
96535
|
+
*/
|
|
96536
|
+
static getAllLeafPaths(tree, config, cascaderProps) {
|
|
96537
|
+
const paths = [];
|
|
96538
|
+
const traverse = (nodes, currentPath = []) => {
|
|
96539
|
+
nodes.forEach(node => {
|
|
96540
|
+
const newPath = [...currentPath, node[cascaderProps.value]];
|
|
96541
|
+
|
|
96542
|
+
// 检查当前节点是否禁用
|
|
96543
|
+
const isCurrentDisabled = this.isItemDisabled(node, config);
|
|
96544
|
+
if (!node[cascaderProps.children]) {
|
|
96545
|
+
// 只包含非禁用项且路径上没有禁选项的叶子节点
|
|
96546
|
+
if (!isCurrentDisabled && !this.isPathDisabled(tree, newPath, config, cascaderProps)) {
|
|
96547
|
+
paths.push(newPath);
|
|
96548
|
+
}
|
|
96549
|
+
} else {
|
|
96550
|
+
// 如果当前节点禁用,则其所有子节点都不可选
|
|
96551
|
+
if (!isCurrentDisabled) {
|
|
96552
|
+
traverse(node[cascaderProps.children], newPath);
|
|
96553
|
+
}
|
|
96554
|
+
}
|
|
96555
|
+
});
|
|
96556
|
+
};
|
|
96557
|
+
traverse(tree);
|
|
96558
|
+
return paths;
|
|
96559
|
+
}
|
|
96560
|
+
|
|
96561
|
+
/**
|
|
96562
|
+
* 根据路径查找节点
|
|
96563
|
+
* @param {Array} tree - 树形数据
|
|
96564
|
+
* @param {Array} path - 路径数组
|
|
96565
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96566
|
+
* @returns {Object|null} 找到的节点
|
|
96567
|
+
*/
|
|
96568
|
+
static findNodeByPath(tree, path, cascaderProps) {
|
|
96569
|
+
if (!path || path.length === 0) return null;
|
|
96570
|
+
const findInTree = (nodes, targetPath) => {
|
|
96571
|
+
for (const node of nodes) {
|
|
96572
|
+
if (node[cascaderProps.value] == targetPath[0]) {
|
|
96573
|
+
if (targetPath.length === 1) {
|
|
96574
|
+
return node;
|
|
96575
|
+
} else if (node[cascaderProps.children]) {
|
|
96576
|
+
return findInTree(node[cascaderProps.children], targetPath.slice(1));
|
|
96577
|
+
}
|
|
96578
|
+
}
|
|
96579
|
+
}
|
|
96580
|
+
return null;
|
|
96581
|
+
};
|
|
96582
|
+
return findInTree(tree, path);
|
|
96583
|
+
}
|
|
96584
|
+
|
|
96585
|
+
/**
|
|
96586
|
+
* 基于 selectedValues 构建已选项列表
|
|
96587
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96588
|
+
* @param {Array} options - 选项数据
|
|
96589
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96590
|
+
* @returns {Array} 已选项列表
|
|
96591
|
+
*/
|
|
96592
|
+
static buildSelectedItemsFromValues(selectedValues, options, cascaderProps) {
|
|
96593
|
+
const items = [];
|
|
96594
|
+
selectedValues.forEach(path => {
|
|
96595
|
+
if (path.length > 0) {
|
|
96596
|
+
const leafValue = path[path.length - 1];
|
|
96597
|
+
// 从原始数据中查找对应的节点信息
|
|
96598
|
+
const node = this.findNodeByPath(options, path, cascaderProps);
|
|
96599
|
+
if (node) {
|
|
96600
|
+
// 包含完整的节点数据,以便访问额外的字段(如子标题字段)
|
|
96601
|
+
items.push({
|
|
96602
|
+
...node,
|
|
96603
|
+
// 展开所有原始节点数据
|
|
96604
|
+
value: leafValue,
|
|
96605
|
+
label: node[cascaderProps.label],
|
|
96606
|
+
path: path
|
|
96607
|
+
});
|
|
96608
|
+
}
|
|
96609
|
+
}
|
|
96610
|
+
});
|
|
96611
|
+
return items;
|
|
96612
|
+
}
|
|
96613
|
+
|
|
96614
|
+
/**
|
|
96615
|
+
* 从自研面板 selection 直接构建已选项(紧凑模式,避免生成万级路径数组)
|
|
96616
|
+
*/
|
|
96617
|
+
static buildSelectedItemsFromSelection(store, selection, options, cascaderProps) {
|
|
96618
|
+
if (!store || !selection) {
|
|
96619
|
+
return [];
|
|
96620
|
+
}
|
|
96621
|
+
const items = [];
|
|
96622
|
+
selection.selectedLeafSet.forEach(leafValue => {
|
|
96623
|
+
const path = store.pathByLeafValue.get(leafValue);
|
|
96624
|
+
const node = store.nodeByValue.get(leafValue);
|
|
96625
|
+
if (!path || !node) {
|
|
96626
|
+
return;
|
|
96627
|
+
}
|
|
96628
|
+
items.push({
|
|
96629
|
+
...node.raw,
|
|
96630
|
+
value: leafValue,
|
|
96631
|
+
label: node.label,
|
|
96632
|
+
path
|
|
96633
|
+
});
|
|
96634
|
+
});
|
|
96635
|
+
return items;
|
|
96636
|
+
}
|
|
96637
|
+
|
|
96638
|
+
/**
|
|
96639
|
+
* 获取搜索范围内的选中值
|
|
96640
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96641
|
+
* @param {Array} searchOptions - 搜索结果
|
|
96642
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96643
|
+
* @returns {Array} 搜索范围内的选中值
|
|
96644
|
+
*/
|
|
96645
|
+
static getSearchSelectedValues(selectedValues, searchOptions, cascaderProps) {
|
|
96646
|
+
const searchLeafValues = this.getLeafValues(searchOptions, cascaderProps);
|
|
96647
|
+
return selectedValues.filter(path => {
|
|
96648
|
+
const leafValue = path[path.length - 1];
|
|
96649
|
+
return searchLeafValues.includes(leafValue);
|
|
96650
|
+
});
|
|
96651
|
+
}
|
|
96652
|
+
|
|
96653
|
+
/**
|
|
96654
|
+
* 检查父项的所有子项是否都被选中
|
|
96655
|
+
* @param {Object} parentNode - 父节点
|
|
96656
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96657
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96658
|
+
* @returns {Boolean} 是否所有子项都被选中
|
|
96659
|
+
*/
|
|
96660
|
+
static isParentFullySelected(parentNode, selectedValues, cascaderProps) {
|
|
96661
|
+
if (!parentNode[cascaderProps.children]) {
|
|
96662
|
+
return false;
|
|
96663
|
+
}
|
|
96664
|
+
|
|
96665
|
+
// 获取父项的所有叶子节点
|
|
96666
|
+
const allLeafValues = this.getLeafValues([parentNode], cascaderProps);
|
|
96667
|
+
|
|
96668
|
+
// 检查所有叶子节点是否都在选中值中
|
|
96669
|
+
return allLeafValues.every(leafValue => {
|
|
96670
|
+
return selectedValues.some(path => {
|
|
96671
|
+
const pathLeafValue = path[path.length - 1];
|
|
96672
|
+
return pathLeafValue === leafValue;
|
|
96673
|
+
});
|
|
96674
|
+
});
|
|
96675
|
+
}
|
|
96676
|
+
|
|
96677
|
+
/**
|
|
96678
|
+
* 根据路径获取对应的标签数组
|
|
96679
|
+
* @param {Array} path - 节点路径
|
|
96680
|
+
* @param {Array} options - 选项数据
|
|
96681
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96682
|
+
* @returns {Array} 标签数组
|
|
96683
|
+
*/
|
|
96684
|
+
static getPathLabels(path, options, cascaderProps) {
|
|
96685
|
+
const labels = [];
|
|
96686
|
+
let currentNodes = options;
|
|
96687
|
+
for (let i = 0; i < path.length; i++) {
|
|
96688
|
+
const targetValue = path[i];
|
|
96689
|
+
const foundNode = currentNodes.find(node => node[cascaderProps.value] === targetValue);
|
|
96690
|
+
if (foundNode) {
|
|
96691
|
+
labels.push(foundNode[cascaderProps.label]);
|
|
96692
|
+
if (foundNode[cascaderProps.children] && i < path.length - 1) {
|
|
96693
|
+
currentNodes = foundNode[cascaderProps.children];
|
|
96694
|
+
}
|
|
96695
|
+
} else {
|
|
96696
|
+
labels.push(targetValue); // 如果找不到对应的节点,使用原始值
|
|
96697
|
+
}
|
|
96698
|
+
}
|
|
96699
|
+
return labels;
|
|
96700
|
+
}
|
|
96701
|
+
|
|
96702
|
+
/**
|
|
96703
|
+
* 构建完整的节点信息对象
|
|
96704
|
+
* @param {Object} node - 原始节点数据
|
|
96705
|
+
* @param {Array} path - 节点路径
|
|
96706
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96707
|
+
* @param {Array} options - 选项数据
|
|
96708
|
+
* @param {Boolean} isAggregated - 是否为聚合项
|
|
96709
|
+
* @returns {Object} 完整的节点信息对象
|
|
96710
|
+
*/
|
|
96711
|
+
static buildCompleteNodeInfo(node, path, cascaderProps, options, isAggregated = false) {
|
|
96712
|
+
const hasChildren = !!node[cascaderProps.children];
|
|
96713
|
+
const level = path.length - 1;
|
|
96714
|
+
return {
|
|
96715
|
+
// 展开原始节点的所有属性,以便访问额外的字段(如子标题字段)
|
|
96716
|
+
...node,
|
|
96717
|
+
// 基本属性(覆盖原始节点中的同名属性)
|
|
96718
|
+
value: node[cascaderProps.value],
|
|
96719
|
+
label: node[cascaderProps.label],
|
|
96720
|
+
path: path,
|
|
96721
|
+
isAggregated: isAggregated,
|
|
96722
|
+
// 节点结构信息
|
|
96723
|
+
hasChildren: hasChildren,
|
|
96724
|
+
level: level,
|
|
96725
|
+
children: hasChildren ? node[cascaderProps.children] : undefined,
|
|
96726
|
+
// 级联面板相关属性
|
|
96727
|
+
checked: true,
|
|
96728
|
+
indeterminate: false,
|
|
96729
|
+
loaded: true,
|
|
96730
|
+
loading: false,
|
|
96731
|
+
// 原始数据
|
|
96732
|
+
data: node,
|
|
96733
|
+
// 路径相关
|
|
96734
|
+
pathLabels: this.getPathLabels(path, options, cascaderProps),
|
|
96735
|
+
// 其他可能需要的属性
|
|
96736
|
+
config: cascaderProps,
|
|
96737
|
+
parent: null,
|
|
96738
|
+
// 在级联面板中会动态设置
|
|
96739
|
+
pathNodes: null // 在级联面板中会动态设置
|
|
96740
|
+
};
|
|
96741
|
+
}
|
|
96742
|
+
|
|
96743
|
+
/**
|
|
96744
|
+
* 从自研面板的选中状态递归构建聚合列表(与 getAggregatedSelectedItems 逻辑一致)
|
|
96745
|
+
* 父节点全选时只返回父项;半选时向下展开到具体子项
|
|
96746
|
+
*/
|
|
96747
|
+
static getAggregatedItemsFromSelection(store, selection, options, cascaderProps) {
|
|
96748
|
+
if (!store || !selection) {
|
|
96749
|
+
return [];
|
|
96750
|
+
}
|
|
96751
|
+
const items = [];
|
|
96752
|
+
const walk = nodeId => {
|
|
96753
|
+
const node = store.nodeById.get(nodeId);
|
|
96754
|
+
if (!node || node.disabled) {
|
|
96755
|
+
return;
|
|
96756
|
+
}
|
|
96757
|
+
const state = selection.getCheckState(nodeId);
|
|
96758
|
+
if (state === 'unchecked' || state === 'disabled') {
|
|
96759
|
+
return;
|
|
96760
|
+
}
|
|
96761
|
+
if (!node.isLeaf && state === 'checked') {
|
|
96762
|
+
items.push(this.buildCompleteNodeInfo(node.raw, node.path, cascaderProps, options, true));
|
|
96763
|
+
return;
|
|
96764
|
+
}
|
|
96765
|
+
if (node.isLeaf && state === 'checked') {
|
|
96766
|
+
items.push(this.buildCompleteNodeInfo(node.raw, node.path, cascaderProps, options, false));
|
|
96767
|
+
return;
|
|
96768
|
+
}
|
|
96769
|
+
const childIds = node.childIds || [];
|
|
96770
|
+
childIds.forEach(childId => walk(childId));
|
|
96771
|
+
};
|
|
96772
|
+
store.rootIds.forEach(rootId => walk(rootId));
|
|
96773
|
+
return items;
|
|
96774
|
+
}
|
|
96775
|
+
|
|
96776
|
+
/** @deprecated 使用 getAggregatedItemsFromSelection */
|
|
96777
|
+
static getAggregatedItemsFromRootSelection(store, selection, options, cascaderProps) {
|
|
96778
|
+
return this.getAggregatedItemsFromSelection(store, selection, options, cascaderProps);
|
|
96779
|
+
}
|
|
96780
|
+
static getAggregatedEmitValues(items, prefix = '__parent__') {
|
|
96781
|
+
return items.map(item => {
|
|
96782
|
+
if (item.isAggregated) {
|
|
96783
|
+
return this.addParentNodePrefix(item.value, prefix);
|
|
96784
|
+
}
|
|
96785
|
+
return item.value;
|
|
96786
|
+
});
|
|
96787
|
+
}
|
|
96788
|
+
|
|
96789
|
+
/**
|
|
96790
|
+
* 获取聚合模式下的选中项(如果父项完全选中,则只返回父项)
|
|
96791
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96792
|
+
* @param {Array} options - 选项数据
|
|
96793
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96794
|
+
* @returns {Array} 聚合后的选中项列表
|
|
96795
|
+
*/
|
|
96796
|
+
static getAggregatedSelectedItems(selectedValues, options, cascaderProps) {
|
|
96797
|
+
const items = [];
|
|
96798
|
+
const processedPaths = new Set();
|
|
96799
|
+
|
|
96800
|
+
// 递归检查每个节点
|
|
96801
|
+
const checkNode = (nodes, currentPath = []) => {
|
|
96802
|
+
nodes.forEach(node => {
|
|
96803
|
+
const newPath = [...currentPath, node[cascaderProps.value]];
|
|
96804
|
+
const pathKey = newPath.join(',');
|
|
96805
|
+
|
|
96806
|
+
// 如果这个路径已经被处理过,跳过
|
|
96807
|
+
if (processedPaths.has(pathKey)) {
|
|
96808
|
+
return;
|
|
96809
|
+
}
|
|
96810
|
+
|
|
96811
|
+
// 检查当前节点是否完全选中
|
|
96812
|
+
if (this.isParentFullySelected(node, selectedValues, cascaderProps)) {
|
|
96813
|
+
// 父项完全选中,添加父项
|
|
96814
|
+
items.push(this.buildCompleteNodeInfo(node, newPath, cascaderProps, options, true));
|
|
96815
|
+
|
|
96816
|
+
// 标记所有子路径为已处理
|
|
96817
|
+
const allLeafValues = this.getLeafValues([node], cascaderProps);
|
|
96818
|
+
selectedValues.forEach(path => {
|
|
96819
|
+
const pathLeafValue = path[path.length - 1];
|
|
96820
|
+
if (allLeafValues.includes(pathLeafValue)) {
|
|
96821
|
+
processedPaths.add(path.join(','));
|
|
96822
|
+
}
|
|
96823
|
+
});
|
|
96824
|
+
} else if (!node[cascaderProps.children]) {
|
|
96825
|
+
// 叶子节点,检查是否在选中值中且未被父项覆盖
|
|
96826
|
+
const leafValue = node[cascaderProps.value];
|
|
96827
|
+
const isSelected = selectedValues.some(path => {
|
|
96828
|
+
const pathLeafValue = path[path.length - 1];
|
|
96829
|
+
return pathLeafValue === leafValue;
|
|
96830
|
+
});
|
|
96831
|
+
if (isSelected && !processedPaths.has(pathKey)) {
|
|
96832
|
+
items.push(this.buildCompleteNodeInfo(node, newPath, cascaderProps, options, false));
|
|
96833
|
+
processedPaths.add(pathKey);
|
|
96834
|
+
}
|
|
96835
|
+
} else {
|
|
96836
|
+
// 继续检查子节点
|
|
96837
|
+
checkNode(node[cascaderProps.children], newPath);
|
|
96838
|
+
}
|
|
96839
|
+
});
|
|
96840
|
+
};
|
|
96841
|
+
checkNode(options);
|
|
96842
|
+
return items;
|
|
96843
|
+
}
|
|
96844
|
+
|
|
96845
|
+
/**
|
|
96846
|
+
* 获取聚合模式下的选中值(只返回最终选中的值,不包含被聚合的子项)
|
|
96847
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96848
|
+
* @param {Array} options - 选项数据
|
|
96849
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96850
|
+
* @param {String} prefix - 前缀标识
|
|
96851
|
+
* @returns {Array} 聚合后的选中值
|
|
96852
|
+
*/
|
|
96853
|
+
static getAggregatedSelectedValues(selectedValues, options, cascaderProps, prefix = '__parent__') {
|
|
96854
|
+
const aggregatedItems = this.getAggregatedSelectedItems(selectedValues, options, cascaderProps);
|
|
96855
|
+
return aggregatedItems.map(item => {
|
|
96856
|
+
// 如果是聚合项(非叶子节点),添加前缀标识
|
|
96857
|
+
if (item.isAggregated) {
|
|
96858
|
+
return this.addParentNodePrefix(item.value, prefix);
|
|
96859
|
+
}
|
|
96860
|
+
return item.value;
|
|
96861
|
+
});
|
|
96862
|
+
}
|
|
96863
|
+
|
|
96864
|
+
/**
|
|
96865
|
+
* 获取聚合模式下的路径数组(只返回最终选中的路径,不包含被聚合的子项路径)
|
|
96866
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96867
|
+
* @param {Array} options - 选项数据
|
|
96868
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96869
|
+
* @returns {Array} 聚合后的路径数组
|
|
96870
|
+
*/
|
|
96871
|
+
static getAggregatedSelectedPaths(selectedValues, options, cascaderProps) {
|
|
96872
|
+
const aggregatedItems = this.getAggregatedSelectedItems(selectedValues, options, cascaderProps);
|
|
96873
|
+
return aggregatedItems.map(item => item.path);
|
|
96874
|
+
}
|
|
96875
|
+
|
|
96876
|
+
/**
|
|
96877
|
+
* 检查聚合模式下是否全选(所有可选的叶子节点都被选中)
|
|
96878
|
+
* @param {Array} selectedValues - 已选值数组
|
|
96879
|
+
* @param {Array} options - 选项数据
|
|
96880
|
+
* @param {Object} config - 禁用配置
|
|
96881
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96882
|
+
* @returns {Boolean} 是否全选
|
|
96883
|
+
*/
|
|
96884
|
+
static isAggregatedAllSelected(selectedValues, options, config, cascaderProps) {
|
|
96885
|
+
// 获取所有可选的叶子节点
|
|
96886
|
+
const allSelectableLeafValues = this.getAllLeafPaths(options, config, cascaderProps).map(path => path[path.length - 1]); // 获取叶子节点的值
|
|
96887
|
+
|
|
96888
|
+
// 获取当前选中的叶子节点值
|
|
96889
|
+
const selectedLeafValues = selectedValues.map(path => path[path.length - 1]);
|
|
96890
|
+
|
|
96891
|
+
// 检查所有可选的叶子节点是否都被选中
|
|
96892
|
+
return allSelectableLeafValues.every(leafValue => selectedLeafValues.includes(leafValue));
|
|
96893
|
+
}
|
|
96894
|
+
|
|
96895
|
+
/**
|
|
96896
|
+
* 检查值是否为非叶子节点标识
|
|
96897
|
+
* @param {*} value - 要检查的值
|
|
96898
|
+
* @param {String} prefix - 前缀标识
|
|
96899
|
+
* @returns {Boolean} 是否为非叶子节点标识
|
|
96900
|
+
*/
|
|
96901
|
+
static isParentNodeValue(value, prefix = '__parent__') {
|
|
96902
|
+
return typeof value === 'string' && value.startsWith(prefix);
|
|
96903
|
+
}
|
|
96904
|
+
|
|
96905
|
+
/**
|
|
96906
|
+
* 从非叶子节点标识中提取实际值
|
|
96907
|
+
* @param {String} parentValue - 非叶子节点标识值
|
|
96908
|
+
* @param {String} prefix - 前缀标识
|
|
96909
|
+
* @returns {String} 实际值
|
|
96910
|
+
*/
|
|
96911
|
+
static extractParentNodeValue(parentValue, prefix = '__parent__') {
|
|
96912
|
+
if (this.isParentNodeValue(parentValue, prefix)) {
|
|
96913
|
+
return parentValue.substring(prefix.length);
|
|
96914
|
+
}
|
|
96915
|
+
return parentValue;
|
|
96916
|
+
}
|
|
96917
|
+
|
|
96918
|
+
/**
|
|
96919
|
+
* 为非叶子节点值添加前缀标识
|
|
96920
|
+
* @param {String} value - 原始值
|
|
96921
|
+
* @param {String} prefix - 前缀标识
|
|
96922
|
+
* @returns {String} 带前缀的值
|
|
96923
|
+
*/
|
|
96924
|
+
static addParentNodePrefix(value, prefix = '__parent__') {
|
|
96925
|
+
return prefix + value;
|
|
96926
|
+
}
|
|
96927
|
+
|
|
96928
|
+
/**
|
|
96929
|
+
* 根据非叶子节点值获取其所有叶子节点的路径
|
|
96930
|
+
* @param {String} parentValue - 非叶子节点值
|
|
96931
|
+
* @param {Array} options - 选项数据
|
|
96932
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96933
|
+
* @returns {Array} 叶子节点路径数组
|
|
96934
|
+
*/
|
|
96935
|
+
static getLeafPathsByParentValue(parentValue, options, cascaderProps) {
|
|
96936
|
+
const paths = [];
|
|
96937
|
+
|
|
96938
|
+
// 查找非叶子节点
|
|
96939
|
+
const findParentNode = (nodes, currentPath = []) => {
|
|
96940
|
+
for (const node of nodes) {
|
|
96941
|
+
const newPath = [...currentPath, node[cascaderProps.value]];
|
|
96942
|
+
if (node[cascaderProps.value] == parentValue) {
|
|
96943
|
+
// 找到目标非叶子节点,获取其所有叶子节点路径
|
|
96944
|
+
this.getAllLeafPaths([node], {}, cascaderProps).forEach(leafPath => {
|
|
96945
|
+
// 将叶子节点路径与当前路径合并
|
|
96946
|
+
const fullPath = [...currentPath, ...leafPath];
|
|
96947
|
+
paths.push(fullPath);
|
|
96948
|
+
});
|
|
96949
|
+
return true;
|
|
96950
|
+
}
|
|
96951
|
+
|
|
96952
|
+
// 递归查找子节点
|
|
96953
|
+
if (node[cascaderProps.children] && node[cascaderProps.children].length > 0) {
|
|
96954
|
+
if (findParentNode(node[cascaderProps.children], newPath)) {
|
|
96955
|
+
return true;
|
|
96956
|
+
}
|
|
96957
|
+
}
|
|
96958
|
+
}
|
|
96959
|
+
return false;
|
|
96960
|
+
};
|
|
96961
|
+
findParentNode(options);
|
|
96962
|
+
return paths;
|
|
96963
|
+
}
|
|
96964
|
+
|
|
96965
|
+
/**
|
|
96966
|
+
* 处理包含非叶子节点的值数组,将非叶子节点转换为对应的叶子节点路径
|
|
96967
|
+
* @param {Array} values - 值数组(可能包含非叶子节点标识)
|
|
96968
|
+
* @param {Array} options - 选项数据
|
|
96969
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96970
|
+
* @param {String} prefix - 前缀标识
|
|
96971
|
+
* @returns {Array} 处理后的路径数组
|
|
96972
|
+
*/
|
|
96973
|
+
static processValuesWithParentNodes(values, options, cascaderProps, prefix = '__parent__') {
|
|
96974
|
+
const paths = [];
|
|
96975
|
+
for (const value of values) {
|
|
96976
|
+
if (this.isParentNodeValue(value, prefix)) {
|
|
96977
|
+
// 非叶子节点,获取其所有叶子节点路径
|
|
96978
|
+
const actualValue = this.extractParentNodeValue(value, prefix);
|
|
96979
|
+
const leafPaths = this.getLeafPathsByParentValue(actualValue, options, cascaderProps);
|
|
96980
|
+
paths.push(...leafPaths);
|
|
96981
|
+
} else {
|
|
96982
|
+
// 普通值,查找对应的路径
|
|
96983
|
+
const valuePaths = this.findPathsByValues([value], options, cascaderProps);
|
|
96984
|
+
paths.push(...valuePaths);
|
|
96985
|
+
}
|
|
96986
|
+
}
|
|
96987
|
+
return paths;
|
|
96988
|
+
}
|
|
96989
|
+
|
|
96990
|
+
/**
|
|
96991
|
+
* 根据values找到对应的路径(支持非叶子节点)
|
|
96992
|
+
* @param {Array} values - 值数组
|
|
96993
|
+
* @param {Array} options - 选项数据
|
|
96994
|
+
* @param {Object} cascaderProps - 级联配置
|
|
96995
|
+
* @returns {Array} 路径数组
|
|
96996
|
+
*/
|
|
96997
|
+
static findPathsByValues(values, options, cascaderProps) {
|
|
96998
|
+
const paths = [];
|
|
96999
|
+
const findPath = (nodes, targetValues, currentPath = []) => {
|
|
97000
|
+
for (const option of nodes) {
|
|
97001
|
+
const newPath = [...currentPath, option[cascaderProps.value]];
|
|
97002
|
+
if (targetValues.includes(option[cascaderProps.value])) {
|
|
97003
|
+
// 如果是叶子节点(没有children属性),添加到路径中
|
|
97004
|
+
if (!option[cascaderProps.children]) {
|
|
97005
|
+
paths.push(newPath);
|
|
97006
|
+
}
|
|
97007
|
+
}
|
|
97008
|
+
|
|
97009
|
+
// 递归查找子节点
|
|
97010
|
+
if (option[cascaderProps.children] && option[cascaderProps.children].length > 0) {
|
|
97011
|
+
findPath(option[cascaderProps.children], targetValues, newPath);
|
|
97012
|
+
}
|
|
97013
|
+
}
|
|
97014
|
+
};
|
|
97015
|
+
findPath(options, values);
|
|
97016
|
+
return paths;
|
|
97017
|
+
}
|
|
97018
|
+
}
|
|
97019
|
+
;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"8cd600e8-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/VirtualCascaderPanel.vue?vue&type=template&id=23086f90
|
|
97020
|
+
var VirtualCascaderPanelvue_type_template_id_23086f90_render = function render() {
|
|
97021
|
+
var _vm = this,
|
|
97022
|
+
_c = _vm._self._c;
|
|
97023
|
+
return _c('div', {
|
|
97024
|
+
staticClass: "el-cascader-panel vcp-panel is-bordered",
|
|
97025
|
+
style: {
|
|
97026
|
+
height: _vm.height + 'px'
|
|
97027
|
+
}
|
|
97028
|
+
}, _vm._l(_vm.columns, function (columnNodes, colIndex) {
|
|
97029
|
+
return _c('div', {
|
|
97030
|
+
key: 'col-' + colIndex,
|
|
97031
|
+
staticClass: "el-cascader-menu vcp-menu",
|
|
97032
|
+
class: {
|
|
97033
|
+
'is-last': colIndex === _vm.columns.length - 1
|
|
97034
|
+
},
|
|
97035
|
+
style: _vm.getColumnStyle(colIndex, columnNodes)
|
|
97036
|
+
}, [_c('VcpVirtualList', {
|
|
97037
|
+
attrs: {
|
|
97038
|
+
"items": columnNodes,
|
|
97039
|
+
"item-height": _vm.itemHeight,
|
|
97040
|
+
"height": _vm.height
|
|
97041
|
+
},
|
|
97042
|
+
scopedSlots: _vm._u([{
|
|
97043
|
+
key: "default",
|
|
97044
|
+
fn: function ({
|
|
97045
|
+
item
|
|
97046
|
+
}) {
|
|
97047
|
+
return [_c('li', {
|
|
97048
|
+
key: 'vcp-node-' + item.id,
|
|
97049
|
+
staticClass: "el-cascader-node",
|
|
97050
|
+
class: _vm.getNodeClass(item, colIndex),
|
|
97051
|
+
attrs: {
|
|
97052
|
+
"role": "menuitem",
|
|
97053
|
+
"id": 'vcp-node-' + item.id,
|
|
97054
|
+
"aria-expanded": !item.isLeaf && _vm.isExpanded(item, colIndex),
|
|
97055
|
+
"tabindex": _vm.isActive(item, colIndex) ? 0 : -1
|
|
97056
|
+
},
|
|
97057
|
+
on: {
|
|
97058
|
+
"click": function ($event) {
|
|
97059
|
+
return _vm.onNodeClick(item, colIndex);
|
|
97060
|
+
}
|
|
97061
|
+
}
|
|
97062
|
+
}, [_vm.multiple ? _c('span', {
|
|
97063
|
+
staticClass: "el-cascader-node__prefix"
|
|
97064
|
+
}, [_c('el-checkbox', {
|
|
97065
|
+
attrs: {
|
|
97066
|
+
"value": _vm.isChecked(item),
|
|
97067
|
+
"indeterminate": _vm.isIndeterminate(item),
|
|
97068
|
+
"disabled": item.disabled || _vm.isViewMode
|
|
97069
|
+
},
|
|
97070
|
+
on: {
|
|
97071
|
+
"change": function ($event) {
|
|
97072
|
+
return _vm.onCheckClick(item, $event);
|
|
97073
|
+
}
|
|
97074
|
+
},
|
|
97075
|
+
nativeOn: {
|
|
97076
|
+
"click": function ($event) {
|
|
97077
|
+
$event.stopPropagation();
|
|
97078
|
+
}
|
|
97079
|
+
}
|
|
97080
|
+
})], 1) : _vm.checkStrictly ? _c('span', {
|
|
97081
|
+
staticClass: "el-cascader-node__prefix",
|
|
97082
|
+
on: {
|
|
97083
|
+
"click": function ($event) {
|
|
97084
|
+
$event.stopPropagation();
|
|
97085
|
+
return _vm.onRadioClick(item);
|
|
97086
|
+
}
|
|
97087
|
+
}
|
|
97088
|
+
}, [_c('el-radio', {
|
|
97089
|
+
attrs: {
|
|
97090
|
+
"value": _vm.singleCheckedValue,
|
|
97091
|
+
"label": item.value,
|
|
97092
|
+
"disabled": item.disabled || _vm.isViewMode
|
|
97093
|
+
},
|
|
97094
|
+
on: {
|
|
97095
|
+
"input": function ($event) {
|
|
97096
|
+
return _vm.onRadioClick(item);
|
|
97097
|
+
}
|
|
97098
|
+
}
|
|
97099
|
+
}, [_c('span')])], 1) : _vm._e(), _c('span', {
|
|
97100
|
+
staticClass: "el-cascader-node__label"
|
|
97101
|
+
}, [_vm._v(_vm._s(item.label))]), !item.isLeaf ? _c('span', {
|
|
97102
|
+
staticClass: "el-cascader-node__postfix"
|
|
97103
|
+
}, [_c('i', {
|
|
97104
|
+
staticClass: "el-icon-arrow-right el-cascader-node__icon-arrow"
|
|
97105
|
+
})]) : _vm._e()])];
|
|
97106
|
+
}
|
|
97107
|
+
}], null, true)
|
|
97108
|
+
})], 1);
|
|
97109
|
+
}), 0);
|
|
97110
|
+
};
|
|
97111
|
+
var VirtualCascaderPanelvue_type_template_id_23086f90_staticRenderFns = [];
|
|
97112
|
+
|
|
97113
|
+
;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"8cd600e8-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/VirtualList.vue?vue&type=template&id=43cb1148
|
|
97114
|
+
var VirtualListvue_type_template_id_43cb1148_render = function render() {
|
|
97115
|
+
var _vm = this,
|
|
97116
|
+
_c = _vm._self._c;
|
|
97117
|
+
return _c('div', {
|
|
97118
|
+
ref: "scroller",
|
|
97119
|
+
staticClass: "vcp-virtual-scroller el-scrollbar__wrap",
|
|
97120
|
+
on: {
|
|
97121
|
+
"scroll": _vm.onScroll
|
|
97122
|
+
}
|
|
97123
|
+
}, [!_vm.enableVirtual ? _c('ul', {
|
|
97124
|
+
staticClass: "el-cascader-menu__list vcp-native-list"
|
|
97125
|
+
}, [_vm._l(_vm.items, function (item, index) {
|
|
97126
|
+
return [_vm._t("default", null, {
|
|
97127
|
+
"item": item,
|
|
97128
|
+
"index": index
|
|
97129
|
+
})];
|
|
97130
|
+
})], 2) : [_c('div', {
|
|
97131
|
+
staticClass: "vcp-virtual-phantom",
|
|
97132
|
+
style: {
|
|
97133
|
+
height: _vm.totalHeight + 'px'
|
|
97134
|
+
}
|
|
97135
|
+
}), _c('ul', {
|
|
97136
|
+
staticClass: "el-cascader-menu__list vcp-virtual-list",
|
|
97137
|
+
style: {
|
|
97138
|
+
transform: 'translateY(' + _vm.offsetY + 'px)'
|
|
97139
|
+
}
|
|
97140
|
+
}, [_vm._l(_vm.visibleItems, function (item, index) {
|
|
97141
|
+
return [_vm._t("default", null, {
|
|
97142
|
+
"item": item,
|
|
97143
|
+
"index": _vm.startIndex + index
|
|
97144
|
+
})];
|
|
97145
|
+
})], 2)]], 2);
|
|
97146
|
+
};
|
|
97147
|
+
var VirtualListvue_type_template_id_43cb1148_staticRenderFns = [];
|
|
97148
|
+
|
|
97149
|
+
;// ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/VirtualList.vue?vue&type=script&lang=js
|
|
97150
|
+
/* harmony default export */ var VirtualListvue_type_script_lang_js = ({
|
|
97151
|
+
name: 'VcpVirtualList',
|
|
97152
|
+
props: {
|
|
97153
|
+
items: {
|
|
97154
|
+
type: Array,
|
|
97155
|
+
default: () => []
|
|
97156
|
+
},
|
|
97157
|
+
itemHeight: {
|
|
97158
|
+
type: Number,
|
|
97159
|
+
default: 34
|
|
97160
|
+
},
|
|
97161
|
+
height: {
|
|
97162
|
+
type: Number,
|
|
97163
|
+
default: 200
|
|
97164
|
+
},
|
|
97165
|
+
overscan: {
|
|
97166
|
+
type: Number,
|
|
97167
|
+
default: 8
|
|
97168
|
+
},
|
|
97169
|
+
listPadding: {
|
|
97170
|
+
type: Number,
|
|
97171
|
+
default: 12
|
|
97172
|
+
}
|
|
97173
|
+
},
|
|
97174
|
+
data() {
|
|
97175
|
+
return {
|
|
97176
|
+
scrollTop: 0
|
|
97177
|
+
};
|
|
97178
|
+
},
|
|
97179
|
+
computed: {
|
|
97180
|
+
totalHeight() {
|
|
97181
|
+
return this.items.length * this.itemHeight + this.listPadding;
|
|
97182
|
+
},
|
|
97183
|
+
enableVirtual() {
|
|
97184
|
+
return this.totalHeight > this.height;
|
|
97185
|
+
},
|
|
97186
|
+
startIndex() {
|
|
97187
|
+
const index = Math.floor(this.scrollTop / this.itemHeight) - this.overscan;
|
|
97188
|
+
return Math.max(0, index);
|
|
97189
|
+
},
|
|
97190
|
+
endIndex() {
|
|
97191
|
+
const visibleCount = Math.ceil(this.height / this.itemHeight) + this.overscan * 2;
|
|
97192
|
+
return Math.min(this.items.length, this.startIndex + visibleCount);
|
|
97193
|
+
},
|
|
97194
|
+
offsetY() {
|
|
97195
|
+
return this.startIndex * this.itemHeight;
|
|
97196
|
+
},
|
|
97197
|
+
visibleItems() {
|
|
97198
|
+
return this.items.slice(this.startIndex, this.endIndex);
|
|
97199
|
+
}
|
|
97200
|
+
},
|
|
97201
|
+
watch: {
|
|
97202
|
+
items(newItems, oldItems) {
|
|
97203
|
+
if (!this.isSameItemList(newItems, oldItems)) {
|
|
97204
|
+
this.resetScroll();
|
|
97205
|
+
}
|
|
97206
|
+
},
|
|
97207
|
+
enableVirtual(newVal, oldVal) {
|
|
97208
|
+
if (newVal !== oldVal) {
|
|
97209
|
+
this.resetScroll();
|
|
97210
|
+
}
|
|
97211
|
+
}
|
|
97212
|
+
},
|
|
97213
|
+
methods: {
|
|
97214
|
+
isSameItemList(nextItems, prevItems) {
|
|
97215
|
+
if (!nextItems || !prevItems) {
|
|
97216
|
+
return false;
|
|
97217
|
+
}
|
|
97218
|
+
if (nextItems.length !== prevItems.length) {
|
|
97219
|
+
return false;
|
|
97220
|
+
}
|
|
97221
|
+
for (let i = 0; i < nextItems.length; i++) {
|
|
97222
|
+
if (this.getItemKey(nextItems[i]) !== this.getItemKey(prevItems[i])) {
|
|
97223
|
+
return false;
|
|
97224
|
+
}
|
|
97225
|
+
}
|
|
97226
|
+
return true;
|
|
97227
|
+
},
|
|
97228
|
+
getItemKey(item) {
|
|
97229
|
+
if (!item) {
|
|
97230
|
+
return '';
|
|
97231
|
+
}
|
|
97232
|
+
return item.id != null ? item.id : item.value;
|
|
97233
|
+
},
|
|
97234
|
+
onScroll(event) {
|
|
97235
|
+
this.scrollTop = event.target.scrollTop;
|
|
97236
|
+
},
|
|
97237
|
+
resetScroll() {
|
|
97238
|
+
this.scrollTop = 0;
|
|
97239
|
+
if (this.$refs.scroller) {
|
|
97240
|
+
this.$refs.scroller.scrollTop = 0;
|
|
97241
|
+
}
|
|
97242
|
+
}
|
|
97243
|
+
}
|
|
97244
|
+
});
|
|
97245
|
+
;// ./src/components/cascader-panel-pro/VirtualList.vue?vue&type=script&lang=js
|
|
97246
|
+
/* harmony default export */ var cascader_panel_pro_VirtualListvue_type_script_lang_js = (VirtualListvue_type_script_lang_js);
|
|
97247
|
+
;// ./src/components/cascader-panel-pro/VirtualList.vue
|
|
97248
|
+
|
|
97249
|
+
|
|
97250
|
+
|
|
97251
|
+
|
|
97252
|
+
|
|
97253
|
+
/* normalize component */
|
|
97254
|
+
;
|
|
97255
|
+
var VirtualList_component = normalizeComponent(
|
|
97256
|
+
cascader_panel_pro_VirtualListvue_type_script_lang_js,
|
|
97257
|
+
VirtualListvue_type_template_id_43cb1148_render,
|
|
97258
|
+
VirtualListvue_type_template_id_43cb1148_staticRenderFns,
|
|
97259
|
+
false,
|
|
97260
|
+
null,
|
|
97261
|
+
null,
|
|
97262
|
+
null
|
|
97263
|
+
|
|
97264
|
+
)
|
|
97265
|
+
|
|
97266
|
+
/* harmony default export */ var VirtualList = (VirtualList_component.exports);
|
|
97267
|
+
;// ./src/components/cascader-panel-pro/cascaderStorePro.js
|
|
97268
|
+
|
|
97269
|
+
|
|
97270
|
+
|
|
97271
|
+
|
|
97272
|
+
|
|
97273
|
+
|
|
97274
|
+
/**
|
|
97275
|
+
* 级联树扁平化存储,初始化时预计算子树叶子元数据,供 O(1) 级勾选/聚合
|
|
97276
|
+
*/
|
|
97277
|
+
|
|
97278
|
+
let nodeIdSeed = 0;
|
|
97279
|
+
function nextId() {
|
|
97280
|
+
nodeIdSeed += 1;
|
|
97281
|
+
return nodeIdSeed;
|
|
97282
|
+
}
|
|
97283
|
+
function resetCascaderStoreIdSeed() {
|
|
97284
|
+
nodeIdSeed = 0;
|
|
97285
|
+
}
|
|
97286
|
+
|
|
97287
|
+
/**
|
|
97288
|
+
* @param {Array} options
|
|
97289
|
+
* @param {Object} config - disabledField/disabledValue/disabledCheck
|
|
97290
|
+
* @param {Object} cascaderProps
|
|
97291
|
+
* @param {Object} utils - CascaderUtilsPro
|
|
97292
|
+
*/
|
|
97293
|
+
function buildCascaderStore(options, config, cascaderProps, utils) {
|
|
97294
|
+
resetCascaderStoreIdSeed();
|
|
97295
|
+
const valueKey = cascaderProps.value || 'value';
|
|
97296
|
+
const labelKey = cascaderProps.label || 'label';
|
|
97297
|
+
const childrenKey = cascaderProps.children || 'children';
|
|
97298
|
+
const disabledKey = cascaderProps.disabled || 'disabled';
|
|
97299
|
+
const nodes = [];
|
|
97300
|
+
const nodeById = new Map();
|
|
97301
|
+
const nodeByValue = new Map();
|
|
97302
|
+
const childrenByParentId = new Map();
|
|
97303
|
+
const rootIds = [];
|
|
97304
|
+
const pathByLeafValue = new Map();
|
|
97305
|
+
const allLeafValues = [];
|
|
97306
|
+
const allLeafPaths = [];
|
|
97307
|
+
const createNode = (raw, parentPath, level, parentId) => {
|
|
97308
|
+
const value = raw[valueKey];
|
|
97309
|
+
const children = raw[childrenKey];
|
|
97310
|
+
const hasChildren = Array.isArray(children) && children.length > 0;
|
|
97311
|
+
const id = nextId();
|
|
97312
|
+
const nodePath = parentId == null ? [value] : parentPath.concat(value);
|
|
97313
|
+
const node = {
|
|
97314
|
+
id,
|
|
97315
|
+
value,
|
|
97316
|
+
label: raw[labelKey],
|
|
97317
|
+
path: nodePath,
|
|
97318
|
+
level,
|
|
97319
|
+
parentId,
|
|
97320
|
+
childIds: [],
|
|
97321
|
+
isLeaf: !hasChildren,
|
|
97322
|
+
disabled: !!raw[disabledKey],
|
|
97323
|
+
raw,
|
|
97324
|
+
descendantLeafValues: [],
|
|
97325
|
+
descendantLeafCount: 0,
|
|
97326
|
+
descendantPaths: []
|
|
97327
|
+
};
|
|
97328
|
+
nodes.push(node);
|
|
97329
|
+
nodeById.set(id, node);
|
|
97330
|
+
if (!nodeByValue.has(value)) {
|
|
97331
|
+
nodeByValue.set(value, node);
|
|
97332
|
+
}
|
|
97333
|
+
if (parentId == null) {
|
|
97334
|
+
rootIds.push(id);
|
|
97335
|
+
} else {
|
|
97336
|
+
const siblings = childrenByParentId.get(parentId) || [];
|
|
97337
|
+
siblings.push(id);
|
|
97338
|
+
childrenByParentId.set(parentId, siblings);
|
|
97339
|
+
const parent = nodeById.get(parentId);
|
|
97340
|
+
if (parent) {
|
|
97341
|
+
parent.childIds.push(id);
|
|
97342
|
+
}
|
|
97343
|
+
}
|
|
97344
|
+
if (hasChildren) {
|
|
97345
|
+
children.forEach(child => {
|
|
97346
|
+
createNode(child, nodePath, level + 1, id);
|
|
97347
|
+
});
|
|
97348
|
+
} else if (!node.disabled) {
|
|
97349
|
+
pathByLeafValue.set(value, nodePath);
|
|
97350
|
+
allLeafValues.push(value);
|
|
97351
|
+
allLeafPaths.push(nodePath);
|
|
97352
|
+
}
|
|
97353
|
+
return node;
|
|
97354
|
+
};
|
|
97355
|
+
const walkRoots = (items, ancestorDisabled = false) => {
|
|
97356
|
+
items.forEach(item => {
|
|
97357
|
+
const isDisabled = ancestorDisabled || utils.isItemDisabled(item, config);
|
|
97358
|
+
const cloned = {
|
|
97359
|
+
...item
|
|
97360
|
+
};
|
|
97361
|
+
if (isDisabled) {
|
|
97362
|
+
cloned[disabledKey] = true;
|
|
97363
|
+
}
|
|
97364
|
+
createNode(cloned, [], 0, null);
|
|
97365
|
+
});
|
|
97366
|
+
};
|
|
97367
|
+
walkRoots(options || []);
|
|
97368
|
+
|
|
97369
|
+
// 自底向上汇总子树叶子
|
|
97370
|
+
const sorted = nodes.slice().sort((a, b) => b.level - a.level);
|
|
97371
|
+
sorted.forEach(node => {
|
|
97372
|
+
if (node.isLeaf) {
|
|
97373
|
+
if (!node.disabled) {
|
|
97374
|
+
node.descendantLeafValues = [node.value];
|
|
97375
|
+
node.descendantLeafCount = 1;
|
|
97376
|
+
node.descendantPaths = [node.path];
|
|
97377
|
+
}
|
|
97378
|
+
return;
|
|
97379
|
+
}
|
|
97380
|
+
const leafValues = [];
|
|
97381
|
+
const leafPaths = [];
|
|
97382
|
+
node.childIds.forEach(childId => {
|
|
97383
|
+
const child = nodeById.get(childId);
|
|
97384
|
+
if (!child || child.descendantLeafCount === 0) {
|
|
97385
|
+
return;
|
|
97386
|
+
}
|
|
97387
|
+
leafValues.push(...child.descendantLeafValues);
|
|
97388
|
+
leafPaths.push(...child.descendantPaths);
|
|
97389
|
+
});
|
|
97390
|
+
node.descendantLeafValues = leafValues;
|
|
97391
|
+
node.descendantLeafCount = leafValues.length;
|
|
97392
|
+
node.descendantPaths = leafPaths;
|
|
97393
|
+
});
|
|
97394
|
+
return {
|
|
97395
|
+
nodes,
|
|
97396
|
+
nodeById,
|
|
97397
|
+
nodeByValue,
|
|
97398
|
+
childrenByParentId,
|
|
97399
|
+
rootIds,
|
|
97400
|
+
pathByLeafValue,
|
|
97401
|
+
allLeafValues,
|
|
97402
|
+
allLeafPaths,
|
|
97403
|
+
totalLeafCount: allLeafPaths.length
|
|
97404
|
+
};
|
|
97405
|
+
}
|
|
97406
|
+
function getStoreChildren(store, parentId) {
|
|
97407
|
+
if (parentId == null) {
|
|
97408
|
+
return store.rootIds.map(id => store.nodeById.get(id)).filter(Boolean);
|
|
97409
|
+
}
|
|
97410
|
+
const childIds = store.childrenByParentId.get(parentId) || [];
|
|
97411
|
+
return childIds.map(id => store.nodeById.get(id)).filter(Boolean);
|
|
97412
|
+
}
|
|
97413
|
+
function findStoreNodeByPath(store, pathValues) {
|
|
97414
|
+
if (!pathValues || pathValues.length === 0) {
|
|
97415
|
+
return null;
|
|
97416
|
+
}
|
|
97417
|
+
let node = store.nodeByValue.get(pathValues[0]);
|
|
97418
|
+
if (!node || pathValues.length === 1) {
|
|
97419
|
+
return node;
|
|
97420
|
+
}
|
|
97421
|
+
for (let i = 1; i < pathValues.length; i++) {
|
|
97422
|
+
const target = pathValues[i];
|
|
97423
|
+
const children = getStoreChildren(store, node.id);
|
|
97424
|
+
node = children.find(child => child.value == target) || null;
|
|
97425
|
+
if (!node) {
|
|
97426
|
+
return null;
|
|
97427
|
+
}
|
|
97428
|
+
}
|
|
97429
|
+
return node;
|
|
97430
|
+
}
|
|
97431
|
+
;// ./src/components/cascader-panel-pro/selectionStatePro.js
|
|
97432
|
+
|
|
97433
|
+
|
|
97434
|
+
|
|
97435
|
+
|
|
97436
|
+
|
|
97437
|
+
|
|
97438
|
+
|
|
97439
|
+
|
|
97440
|
+
|
|
97441
|
+
|
|
97442
|
+
const COMPACT_EMIT_THRESHOLD = 300;
|
|
97443
|
+
|
|
97444
|
+
class SelectionStatePro {
|
|
97445
|
+
constructor(store) {
|
|
97446
|
+
this.store = store;
|
|
97447
|
+
this.selectedLeafSet = new Set();
|
|
97448
|
+
this.subtreeSelectedCount = new Map();
|
|
97449
|
+
}
|
|
97450
|
+
clear() {
|
|
97451
|
+
this.selectedLeafSet.clear();
|
|
97452
|
+
this.subtreeSelectedCount.clear();
|
|
97453
|
+
}
|
|
97454
|
+
isEmpty() {
|
|
97455
|
+
return this.selectedLeafSet.size === 0;
|
|
97456
|
+
}
|
|
97457
|
+
size() {
|
|
97458
|
+
return this.selectedLeafSet.size;
|
|
97459
|
+
}
|
|
97460
|
+
_incAncestors(nodeId, delta) {
|
|
97461
|
+
let current = this.store.nodeById.get(nodeId);
|
|
97462
|
+
while (current) {
|
|
97463
|
+
const prev = this.subtreeSelectedCount.get(current.id) || 0;
|
|
97464
|
+
const next = prev + delta;
|
|
97465
|
+
if (next <= 0) {
|
|
97466
|
+
this.subtreeSelectedCount.delete(current.id);
|
|
97467
|
+
} else {
|
|
97468
|
+
this.subtreeSelectedCount.set(current.id, next);
|
|
97469
|
+
}
|
|
97470
|
+
if (current.parentId == null) {
|
|
97471
|
+
break;
|
|
97472
|
+
}
|
|
97473
|
+
current = this.store.nodeById.get(current.parentId);
|
|
97474
|
+
}
|
|
97475
|
+
}
|
|
97476
|
+
|
|
97477
|
+
/**
|
|
97478
|
+
* 自底向上重算 nodeId 子树内各层选中数
|
|
97479
|
+
*/
|
|
97480
|
+
_reconcileSubtreeCounts(nodeId) {
|
|
97481
|
+
const node = this.store.nodeById.get(nodeId);
|
|
97482
|
+
if (!node) {
|
|
97483
|
+
return 0;
|
|
97484
|
+
}
|
|
97485
|
+
if (node.isLeaf) {
|
|
97486
|
+
return this.selectedLeafSet.has(node.value) ? 1 : 0;
|
|
97487
|
+
}
|
|
97488
|
+
let selected = 0;
|
|
97489
|
+
node.childIds.forEach(childId => {
|
|
97490
|
+
selected += this._reconcileSubtreeCounts(childId);
|
|
97491
|
+
});
|
|
97492
|
+
if (selected > 0) {
|
|
97493
|
+
this.subtreeSelectedCount.set(nodeId, selected);
|
|
97494
|
+
} else {
|
|
97495
|
+
this.subtreeSelectedCount.delete(nodeId);
|
|
97496
|
+
}
|
|
97497
|
+
return selected;
|
|
97498
|
+
}
|
|
97499
|
+
|
|
97500
|
+
/**
|
|
97501
|
+
* 从当前节点向上汇总祖先的选中数(勾选子节点后父级需半选/全选)
|
|
97502
|
+
*/
|
|
97503
|
+
_reconcileAncestors(nodeId) {
|
|
97504
|
+
var _this$store$nodeById$;
|
|
97505
|
+
let parentId = (_this$store$nodeById$ = this.store.nodeById.get(nodeId)) === null || _this$store$nodeById$ === void 0 ? void 0 : _this$store$nodeById$.parentId;
|
|
97506
|
+
while (parentId != null) {
|
|
97507
|
+
const parent = this.store.nodeById.get(parentId);
|
|
97508
|
+
if (!parent) {
|
|
97509
|
+
break;
|
|
97510
|
+
}
|
|
97511
|
+
let selected = 0;
|
|
97512
|
+
parent.childIds.forEach(childId => {
|
|
97513
|
+
const child = this.store.nodeById.get(childId);
|
|
97514
|
+
if (!child) {
|
|
97515
|
+
return;
|
|
97516
|
+
}
|
|
97517
|
+
if (child.isLeaf) {
|
|
97518
|
+
if (this.selectedLeafSet.has(child.value)) {
|
|
97519
|
+
selected++;
|
|
97520
|
+
}
|
|
97521
|
+
} else {
|
|
97522
|
+
selected += this.subtreeSelectedCount.get(childId) || 0;
|
|
97523
|
+
}
|
|
97524
|
+
});
|
|
97525
|
+
if (selected > 0) {
|
|
97526
|
+
this.subtreeSelectedCount.set(parentId, selected);
|
|
97527
|
+
} else {
|
|
97528
|
+
this.subtreeSelectedCount.delete(parentId);
|
|
97529
|
+
}
|
|
97530
|
+
parentId = parent.parentId;
|
|
97531
|
+
}
|
|
97532
|
+
}
|
|
97533
|
+
_reconcileAllRoots() {
|
|
97534
|
+
this.subtreeSelectedCount.clear();
|
|
97535
|
+
this.store.rootIds.forEach(rootId => {
|
|
97536
|
+
this._reconcileSubtreeCounts(rootId);
|
|
97537
|
+
});
|
|
97538
|
+
}
|
|
97539
|
+
_applyLeaf(value, checked) {
|
|
97540
|
+
const has = this.selectedLeafSet.has(value);
|
|
97541
|
+
if (checked && !has) {
|
|
97542
|
+
this.selectedLeafSet.add(value);
|
|
97543
|
+
const node = this.store.nodeByValue.get(value);
|
|
97544
|
+
if (node) {
|
|
97545
|
+
this._incAncestors(node.id, 1);
|
|
97546
|
+
}
|
|
97547
|
+
} else if (!checked && has) {
|
|
97548
|
+
this.selectedLeafSet.delete(value);
|
|
97549
|
+
const node = this.store.nodeByValue.get(value);
|
|
97550
|
+
if (node) {
|
|
97551
|
+
this._incAncestors(node.id, -1);
|
|
97552
|
+
}
|
|
97553
|
+
}
|
|
97554
|
+
}
|
|
97555
|
+
toggleNode(nodeId, checked) {
|
|
97556
|
+
const node = this.store.nodeById.get(nodeId);
|
|
97557
|
+
if (!node || node.disabled) {
|
|
97558
|
+
return;
|
|
97559
|
+
}
|
|
97560
|
+
if (node.isLeaf) {
|
|
97561
|
+
const had = this.selectedLeafSet.has(node.value);
|
|
97562
|
+
this._applyLeaf(node.value, checked);
|
|
97563
|
+
if (had !== this.selectedLeafSet.has(node.value)) {
|
|
97564
|
+
this._reconcileAncestors(node.id);
|
|
97565
|
+
}
|
|
97566
|
+
return;
|
|
97567
|
+
}
|
|
97568
|
+
const leaves = node.descendantLeafValues;
|
|
97569
|
+
if (leaves.length === 0) {
|
|
97570
|
+
return;
|
|
97571
|
+
}
|
|
97572
|
+
let changedCount = 0;
|
|
97573
|
+
leaves.forEach(v => {
|
|
97574
|
+
const has = this.selectedLeafSet.has(v);
|
|
97575
|
+
if (checked) {
|
|
97576
|
+
if (!has) {
|
|
97577
|
+
this.selectedLeafSet.add(v);
|
|
97578
|
+
changedCount++;
|
|
97579
|
+
}
|
|
97580
|
+
} else if (has) {
|
|
97581
|
+
this.selectedLeafSet.delete(v);
|
|
97582
|
+
changedCount++;
|
|
97583
|
+
}
|
|
97584
|
+
});
|
|
97585
|
+
if (changedCount > 0) {
|
|
97586
|
+
this._reconcileSubtreeCounts(nodeId);
|
|
97587
|
+
this._reconcileAncestors(nodeId);
|
|
97588
|
+
}
|
|
97589
|
+
}
|
|
97590
|
+
selectAll() {
|
|
97591
|
+
this.clear();
|
|
97592
|
+
const leaves = this.store.allLeafValues;
|
|
97593
|
+
leaves.forEach(v => this.selectedLeafSet.add(v));
|
|
97594
|
+
this._reconcileAllRoots();
|
|
97595
|
+
}
|
|
97596
|
+
syncFromPaths(paths) {
|
|
97597
|
+
this.clear();
|
|
97598
|
+
if (!Array.isArray(paths) || paths.length === 0) {
|
|
97599
|
+
return;
|
|
97600
|
+
}
|
|
97601
|
+
paths.forEach(path => {
|
|
97602
|
+
if (!Array.isArray(path) || path.length === 0) {
|
|
97603
|
+
return;
|
|
97604
|
+
}
|
|
97605
|
+
const leafValue = path[path.length - 1];
|
|
97606
|
+
if (this.store.pathByLeafValue.has(leafValue)) {
|
|
97607
|
+
this.selectedLeafSet.add(leafValue);
|
|
97608
|
+
}
|
|
97609
|
+
});
|
|
97610
|
+
this._reconcileAllRoots();
|
|
97611
|
+
}
|
|
97612
|
+
getCheckState(nodeId) {
|
|
97613
|
+
const node = this.store.nodeById.get(nodeId);
|
|
97614
|
+
if (!node || node.disabled) {
|
|
97615
|
+
return 'disabled';
|
|
97616
|
+
}
|
|
97617
|
+
if (node.isLeaf) {
|
|
97618
|
+
return this.selectedLeafSet.has(node.value) ? 'checked' : 'unchecked';
|
|
97619
|
+
}
|
|
97620
|
+
const total = node.descendantLeafCount;
|
|
97621
|
+
if (total === 0) {
|
|
97622
|
+
return 'unchecked';
|
|
97623
|
+
}
|
|
97624
|
+
const selected = this.subtreeSelectedCount.get(node.id) || 0;
|
|
97625
|
+
if (selected === 0) {
|
|
97626
|
+
return 'unchecked';
|
|
97627
|
+
}
|
|
97628
|
+
if (selected >= total) {
|
|
97629
|
+
return 'checked';
|
|
97630
|
+
}
|
|
97631
|
+
return 'indeterminate';
|
|
97632
|
+
}
|
|
97633
|
+
isChecked(nodeId) {
|
|
97634
|
+
return this.getCheckState(nodeId) === 'checked';
|
|
97635
|
+
}
|
|
97636
|
+
isIndeterminate(nodeId) {
|
|
97637
|
+
return this.getCheckState(nodeId) === 'indeterminate';
|
|
97638
|
+
}
|
|
97639
|
+
isPathInCheckedValues(path) {
|
|
97640
|
+
if (!path || path.length === 0) {
|
|
97641
|
+
return false;
|
|
97642
|
+
}
|
|
97643
|
+
const leafValue = path[path.length - 1];
|
|
97644
|
+
return this.selectedLeafSet.has(leafValue);
|
|
97645
|
+
}
|
|
97646
|
+
isNodeInCheckedPath(node) {
|
|
97647
|
+
if (!node) {
|
|
97648
|
+
return false;
|
|
97649
|
+
}
|
|
97650
|
+
return this.isPathInCheckedValues(node.path);
|
|
97651
|
+
}
|
|
97652
|
+
getCheckedPaths() {
|
|
97653
|
+
const paths = [];
|
|
97654
|
+
this.selectedLeafSet.forEach(leafValue => {
|
|
97655
|
+
const path = this.store.pathByLeafValue.get(leafValue);
|
|
97656
|
+
if (path) {
|
|
97657
|
+
paths.push(path);
|
|
97658
|
+
}
|
|
97659
|
+
});
|
|
97660
|
+
return paths;
|
|
97661
|
+
}
|
|
97662
|
+
isCompactSelection() {
|
|
97663
|
+
return this.selectedLeafSet.size >= COMPACT_EMIT_THRESHOLD;
|
|
97664
|
+
}
|
|
97665
|
+
|
|
97666
|
+
/** 从聚合父节点值快速同步(如 __parent__province_0) */
|
|
97667
|
+
syncFromParentValues(parentValues, prefix = '__parent__') {
|
|
97668
|
+
this.clear();
|
|
97669
|
+
if (!Array.isArray(parentValues) || parentValues.length === 0) {
|
|
97670
|
+
return;
|
|
97671
|
+
}
|
|
97672
|
+
parentValues.forEach(val => {
|
|
97673
|
+
let rootValue = val;
|
|
97674
|
+
if (typeof val === 'string' && val.startsWith(prefix)) {
|
|
97675
|
+
rootValue = val.substring(prefix.length);
|
|
97676
|
+
}
|
|
97677
|
+
const node = this.store.nodeByValue.get(rootValue);
|
|
97678
|
+
if (node && !node.isLeaf && !node.disabled) {
|
|
97679
|
+
node.descendantLeafValues.forEach(v => this.selectedLeafSet.add(v));
|
|
97680
|
+
}
|
|
97681
|
+
});
|
|
97682
|
+
this._reconcileAllRoots();
|
|
97683
|
+
}
|
|
97684
|
+
}
|
|
97685
|
+
;// ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/VirtualCascaderPanel.vue?vue&type=script&lang=js
|
|
97686
|
+
|
|
97687
|
+
|
|
97688
|
+
|
|
97689
|
+
|
|
97690
|
+
|
|
97691
|
+
|
|
97692
|
+
|
|
97693
|
+
|
|
97694
|
+
/* harmony default export */ var VirtualCascaderPanelvue_type_script_lang_js = ({
|
|
97695
|
+
name: 'VirtualCascaderPanel',
|
|
97696
|
+
components: {
|
|
97697
|
+
VcpVirtualList: VirtualList
|
|
97698
|
+
},
|
|
97699
|
+
props: {
|
|
97700
|
+
value: {
|
|
97701
|
+
type: [Array, String, Number],
|
|
97702
|
+
default: () => []
|
|
97703
|
+
},
|
|
97704
|
+
options: {
|
|
97705
|
+
type: Array,
|
|
97706
|
+
default: () => []
|
|
97707
|
+
},
|
|
97708
|
+
props: {
|
|
97709
|
+
type: Object,
|
|
97710
|
+
default: () => ({
|
|
97711
|
+
multiple: true,
|
|
97712
|
+
label: 'label',
|
|
97713
|
+
value: 'value',
|
|
97714
|
+
children: 'children',
|
|
97715
|
+
checkStrictly: false
|
|
97716
|
+
})
|
|
97717
|
+
},
|
|
97718
|
+
height: {
|
|
97719
|
+
type: Number,
|
|
97720
|
+
default: 280
|
|
97721
|
+
},
|
|
97722
|
+
columnMinWidth: {
|
|
97723
|
+
type: Number,
|
|
97724
|
+
default: 180
|
|
97725
|
+
},
|
|
97726
|
+
columnMaxWidth: {
|
|
97727
|
+
type: Number,
|
|
97728
|
+
default: 420
|
|
97729
|
+
},
|
|
97730
|
+
disabledConfig: {
|
|
97731
|
+
type: Object,
|
|
97732
|
+
default: () => ({})
|
|
97733
|
+
},
|
|
97734
|
+
isViewMode: {
|
|
97735
|
+
type: Boolean,
|
|
97736
|
+
default: false
|
|
97737
|
+
},
|
|
97738
|
+
autoExpandDeep: {
|
|
97739
|
+
type: Boolean,
|
|
97740
|
+
default: true
|
|
97741
|
+
},
|
|
97742
|
+
// 是否从 value prop 同步选中(紧凑模式下由面板内部维护选中状态)
|
|
97743
|
+
syncValueFromParent: {
|
|
97744
|
+
type: Boolean,
|
|
97745
|
+
default: true
|
|
97746
|
+
}
|
|
97747
|
+
},
|
|
97748
|
+
data() {
|
|
97749
|
+
return {
|
|
97750
|
+
store: null,
|
|
97751
|
+
selection: null,
|
|
97752
|
+
activePath: [],
|
|
97753
|
+
itemHeight: 34,
|
|
97754
|
+
syncingValue: false,
|
|
97755
|
+
suppressValueSync: false,
|
|
97756
|
+
selectionTick: 0
|
|
97757
|
+
};
|
|
97758
|
+
},
|
|
97759
|
+
computed: {
|
|
97760
|
+
multiple() {
|
|
97761
|
+
return this.props.multiple !== false;
|
|
97762
|
+
},
|
|
97763
|
+
checkStrictly() {
|
|
97764
|
+
return !!this.props.checkStrictly;
|
|
97765
|
+
},
|
|
97766
|
+
columns() {
|
|
97767
|
+
if (!this.store) {
|
|
97768
|
+
return [];
|
|
97769
|
+
}
|
|
97770
|
+
const cols = [getStoreChildren(this.store, null)];
|
|
97771
|
+
this.activePath.forEach(nodeId => {
|
|
97772
|
+
const node = this.store.nodeById.get(nodeId);
|
|
97773
|
+
if (!node || node.isLeaf) {
|
|
97774
|
+
return;
|
|
97775
|
+
}
|
|
97776
|
+
const children = getStoreChildren(this.store, nodeId);
|
|
97777
|
+
if (children.length > 0) {
|
|
97778
|
+
cols.push(children);
|
|
97779
|
+
}
|
|
97780
|
+
});
|
|
97781
|
+
return cols;
|
|
97782
|
+
},
|
|
97783
|
+
singleCheckedValue() {
|
|
97784
|
+
if (this.multiple || !Array.isArray(this.value) || this.value.length === 0) {
|
|
97785
|
+
return null;
|
|
97786
|
+
}
|
|
97787
|
+
const path = Array.isArray(this.value[0]) ? this.value[0] : this.value;
|
|
97788
|
+
return path[path.length - 1];
|
|
97789
|
+
}
|
|
97790
|
+
},
|
|
97791
|
+
watch: {
|
|
97792
|
+
options: {
|
|
97793
|
+
handler() {
|
|
97794
|
+
this.rebuildStore();
|
|
97795
|
+
}
|
|
97796
|
+
},
|
|
97797
|
+
value: {
|
|
97798
|
+
handler() {
|
|
97799
|
+
if (this.suppressValueSync || !this.syncValueFromParent) {
|
|
97800
|
+
return;
|
|
97801
|
+
}
|
|
97802
|
+
this.syncFromValue();
|
|
97803
|
+
},
|
|
97804
|
+
deep: false
|
|
97805
|
+
},
|
|
97806
|
+
activePath: {
|
|
97807
|
+
handler() {
|
|
97808
|
+
this.$nextTick(() => {
|
|
97809
|
+
this.syncHorizontalOverflow();
|
|
97810
|
+
});
|
|
97811
|
+
},
|
|
97812
|
+
deep: true
|
|
97813
|
+
}
|
|
97814
|
+
},
|
|
97815
|
+
created() {
|
|
97816
|
+
this.rebuildStore();
|
|
97817
|
+
},
|
|
97818
|
+
mounted() {
|
|
97819
|
+
this._onWindowResize = () => {
|
|
97820
|
+
this.syncHorizontalOverflow();
|
|
97821
|
+
};
|
|
97822
|
+
window.addEventListener('resize', this._onWindowResize, {
|
|
97823
|
+
passive: true
|
|
97824
|
+
});
|
|
97825
|
+
this.syncHorizontalOverflow();
|
|
97826
|
+
},
|
|
97827
|
+
beforeDestroy() {
|
|
97828
|
+
if (this._onWindowResize) {
|
|
97829
|
+
window.removeEventListener('resize', this._onWindowResize);
|
|
97830
|
+
this._onWindowResize = null;
|
|
97831
|
+
}
|
|
97832
|
+
if (this._hScrollRaf) {
|
|
97833
|
+
cancelAnimationFrame(this._hScrollRaf);
|
|
97834
|
+
this._hScrollRaf = null;
|
|
97835
|
+
}
|
|
97836
|
+
},
|
|
97837
|
+
methods: {
|
|
97838
|
+
syncHorizontalOverflow() {
|
|
97839
|
+
if (this._hScrollRaf) {
|
|
97840
|
+
cancelAnimationFrame(this._hScrollRaf);
|
|
97841
|
+
}
|
|
97842
|
+
this._hScrollRaf = requestAnimationFrame(() => {
|
|
97843
|
+
this._hScrollRaf = null;
|
|
97844
|
+
const panel = this.$el;
|
|
97845
|
+
const wrapper = panel && panel.closest('.cascader-content-wrapper');
|
|
97846
|
+
if (!panel || !wrapper) {
|
|
97847
|
+
return;
|
|
97848
|
+
}
|
|
97849
|
+
const overflow = panel.scrollWidth - wrapper.clientWidth;
|
|
97850
|
+
const hadScroll = wrapper.classList.contains('is-horizontal-scroll');
|
|
97851
|
+
// 滞回区间,避免边界宽度下 overflow 来回切换
|
|
97852
|
+
const needsScroll = hadScroll ? overflow > -4 : overflow > 1;
|
|
97853
|
+
if (needsScroll !== hadScroll) {
|
|
97854
|
+
wrapper.classList.toggle('is-horizontal-scroll', needsScroll);
|
|
97855
|
+
}
|
|
97856
|
+
});
|
|
97857
|
+
},
|
|
97858
|
+
getColumnStyle(colIndex, columnNodes) {
|
|
97859
|
+
const width = CascaderUtilsPro.getCascaderColumnWidth(columnNodes, {
|
|
97860
|
+
minWidth: this.columnMinWidth,
|
|
97861
|
+
maxWidth: this.columnMaxWidth,
|
|
97862
|
+
hasCheckbox: this.multiple || this.checkStrictly
|
|
97863
|
+
});
|
|
97864
|
+
return {
|
|
97865
|
+
width: width + 'px',
|
|
97866
|
+
minWidth: width + 'px',
|
|
97867
|
+
maxWidth: width + 'px'
|
|
97868
|
+
};
|
|
97869
|
+
},
|
|
97870
|
+
rebuildStore() {
|
|
97871
|
+
this.store = buildCascaderStore(this.options, this.disabledConfig, this.props, CascaderUtilsPro);
|
|
97872
|
+
this.selection = new SelectionStatePro(this.store);
|
|
97873
|
+
this.activePath = [];
|
|
97874
|
+
if (this.syncValueFromParent) {
|
|
97875
|
+
this.syncFromValue();
|
|
97876
|
+
}
|
|
97877
|
+
this.$nextTick(() => {
|
|
97878
|
+
this.syncHorizontalOverflow();
|
|
97879
|
+
});
|
|
97880
|
+
},
|
|
97881
|
+
syncFromValue() {
|
|
97882
|
+
if (!this.selection) {
|
|
97883
|
+
return;
|
|
97884
|
+
}
|
|
97885
|
+
this.syncingValue = true;
|
|
97886
|
+
if (this.multiple) {
|
|
97887
|
+
const paths = Array.isArray(this.value) ? this.value : [];
|
|
97888
|
+
this.selection.syncFromPaths(paths);
|
|
97889
|
+
} else {
|
|
97890
|
+
const path = this.normalizeSinglePath(this.value);
|
|
97891
|
+
this.selection.syncFromPaths(path ? [path] : []);
|
|
97892
|
+
if (path && path.length > 1) {
|
|
97893
|
+
this.expandPathValues(path.slice(0, -1), false);
|
|
97894
|
+
}
|
|
97895
|
+
}
|
|
97896
|
+
this.syncingValue = false;
|
|
97897
|
+
},
|
|
97898
|
+
normalizeSinglePath(val) {
|
|
97899
|
+
if (val == null || val === '') {
|
|
97900
|
+
return null;
|
|
97901
|
+
}
|
|
97902
|
+
if (Array.isArray(val)) {
|
|
97903
|
+
if (val.length === 0) {
|
|
97904
|
+
return null;
|
|
97905
|
+
}
|
|
97906
|
+
if (Array.isArray(val[0])) {
|
|
97907
|
+
return val[0];
|
|
97908
|
+
}
|
|
97909
|
+
return val;
|
|
97910
|
+
}
|
|
97911
|
+
const node = this.store && this.store.nodeByValue.get(val);
|
|
97912
|
+
if (node) {
|
|
97913
|
+
return node.path;
|
|
97914
|
+
}
|
|
97915
|
+
return [val];
|
|
97916
|
+
},
|
|
97917
|
+
emitValue() {
|
|
97918
|
+
if (this.syncingValue || !this.selection) {
|
|
97919
|
+
return;
|
|
97920
|
+
}
|
|
97921
|
+
if (this.selection.isCompactSelection()) {
|
|
97922
|
+
this.$emit('change', {
|
|
97923
|
+
compact: true,
|
|
97924
|
+
count: this.selection.size()
|
|
97925
|
+
});
|
|
97926
|
+
return;
|
|
97927
|
+
}
|
|
97928
|
+
let emitVal;
|
|
97929
|
+
if (this.multiple) {
|
|
97930
|
+
emitVal = this.selection.getCheckedPaths();
|
|
97931
|
+
} else {
|
|
97932
|
+
const paths = this.selection.getCheckedPaths();
|
|
97933
|
+
emitVal = paths.length > 0 ? paths[0] : [];
|
|
97934
|
+
}
|
|
97935
|
+
this.$emit('input', emitVal);
|
|
97936
|
+
this.$emit('change', emitVal);
|
|
97937
|
+
},
|
|
97938
|
+
isActive(node, colIndex) {
|
|
97939
|
+
return colIndex < this.activePath.length && this.activePath[colIndex] === node.id;
|
|
97940
|
+
},
|
|
97941
|
+
isExpanded(node, colIndex) {
|
|
97942
|
+
return this.activePath[colIndex] === node.id;
|
|
97943
|
+
},
|
|
97944
|
+
isInActivePath(node) {
|
|
97945
|
+
return this.activePath.includes(node.id);
|
|
97946
|
+
},
|
|
97947
|
+
getNodeClass(node, colIndex) {
|
|
97948
|
+
return {
|
|
97949
|
+
'is-selectable': this.checkStrictly,
|
|
97950
|
+
'is-disabled': node.disabled || this.isViewMode,
|
|
97951
|
+
'in-active-path': this.isInActivePath(node),
|
|
97952
|
+
'in-checked-path': this.checkStrictly && this.isInCheckedPath(node),
|
|
97953
|
+
'is-active': this.isNodeActive(node)
|
|
97954
|
+
};
|
|
97955
|
+
},
|
|
97956
|
+
isInCheckedPath(node) {
|
|
97957
|
+
void this.selectionTick;
|
|
97958
|
+
if (!this.selection || !this.checkStrictly) {
|
|
97959
|
+
return false;
|
|
97960
|
+
}
|
|
97961
|
+
return this.selection.isNodeInCheckedPath(node);
|
|
97962
|
+
},
|
|
97963
|
+
isNodeActive(node) {
|
|
97964
|
+
void this.selectionTick;
|
|
97965
|
+
if (!this.selection) {
|
|
97966
|
+
return false;
|
|
97967
|
+
}
|
|
97968
|
+
if (this.multiple) {
|
|
97969
|
+
if (this.checkStrictly) {
|
|
97970
|
+
return this.selection.isNodeInCheckedPath(node);
|
|
97971
|
+
}
|
|
97972
|
+
return node.isLeaf && this.selection.selectedLeafSet.has(node.value);
|
|
97973
|
+
}
|
|
97974
|
+
const paths = this.selection.getCheckedPaths();
|
|
97975
|
+
if (paths.length === 0) {
|
|
97976
|
+
return false;
|
|
97977
|
+
}
|
|
97978
|
+
const activePath = paths[0];
|
|
97979
|
+
return activePath[activePath.length - 1] === node.value;
|
|
97980
|
+
},
|
|
97981
|
+
isChecked(node) {
|
|
97982
|
+
void this.selectionTick;
|
|
97983
|
+
return this.selection ? this.selection.isChecked(node.id) : false;
|
|
97984
|
+
},
|
|
97985
|
+
isIndeterminate(node) {
|
|
97986
|
+
void this.selectionTick;
|
|
97987
|
+
return this.selection ? this.selection.isIndeterminate(node.id) : false;
|
|
97988
|
+
},
|
|
97989
|
+
bumpSelectionView() {
|
|
97990
|
+
this.selectionTick += 1;
|
|
97991
|
+
},
|
|
97992
|
+
// activePath 只保留非叶子,避免多出一列空菜单(空列仍有 min-width 会撑出横向滚动)
|
|
97993
|
+
sanitizeActivePath(pathIds) {
|
|
97994
|
+
if (!this.store || !Array.isArray(pathIds)) {
|
|
97995
|
+
return [];
|
|
97996
|
+
}
|
|
97997
|
+
return pathIds.filter(id => {
|
|
97998
|
+
const node = this.store.nodeById.get(id);
|
|
97999
|
+
return node && !node.isLeaf;
|
|
98000
|
+
});
|
|
98001
|
+
},
|
|
98002
|
+
expandNode(node, silent = false) {
|
|
98003
|
+
if (node.isLeaf) {
|
|
98004
|
+
return;
|
|
98005
|
+
}
|
|
98006
|
+
const pathIds = [];
|
|
98007
|
+
let current = node;
|
|
98008
|
+
while (current) {
|
|
98009
|
+
pathIds.unshift(current.id);
|
|
98010
|
+
if (current.parentId == null) {
|
|
98011
|
+
break;
|
|
98012
|
+
}
|
|
98013
|
+
current = this.store.nodeById.get(current.parentId);
|
|
98014
|
+
}
|
|
98015
|
+
this.activePath = this.sanitizeActivePath(pathIds);
|
|
98016
|
+
if (!silent) {
|
|
98017
|
+
const pathValues = pathIds.map(id => this.store.nodeById.get(id).value);
|
|
98018
|
+
this.$emit('expand-change', pathValues);
|
|
98019
|
+
if (this.autoExpandDeep) {
|
|
98020
|
+
this.$nextTick(() => {
|
|
98021
|
+
this.expandDeepFromNode(node);
|
|
98022
|
+
});
|
|
98023
|
+
}
|
|
98024
|
+
}
|
|
98025
|
+
},
|
|
98026
|
+
expandDeepFromNode(node) {
|
|
98027
|
+
if (!node || node.isLeaf) {
|
|
98028
|
+
return;
|
|
98029
|
+
}
|
|
98030
|
+
const children = getStoreChildren(this.store, node.id);
|
|
98031
|
+
if (children.length === 0) {
|
|
98032
|
+
return;
|
|
98033
|
+
}
|
|
98034
|
+
const firstChild = children[0];
|
|
98035
|
+
const pathIds = [];
|
|
98036
|
+
let cursor = firstChild;
|
|
98037
|
+
while (cursor) {
|
|
98038
|
+
pathIds.push(cursor.id);
|
|
98039
|
+
if (cursor.isLeaf) {
|
|
98040
|
+
break;
|
|
98041
|
+
}
|
|
98042
|
+
const kids = getStoreChildren(this.store, cursor.id);
|
|
98043
|
+
if (kids.length === 0) {
|
|
98044
|
+
break;
|
|
98045
|
+
}
|
|
98046
|
+
cursor = kids[0];
|
|
98047
|
+
}
|
|
98048
|
+
const basePath = [];
|
|
98049
|
+
let parent = node;
|
|
98050
|
+
while (parent) {
|
|
98051
|
+
basePath.unshift(parent.id);
|
|
98052
|
+
if (parent.parentId == null) {
|
|
98053
|
+
break;
|
|
98054
|
+
}
|
|
98055
|
+
parent = this.store.nodeById.get(parent.parentId);
|
|
98056
|
+
}
|
|
98057
|
+
this.activePath = this.sanitizeActivePath(basePath.concat(pathIds));
|
|
98058
|
+
},
|
|
98059
|
+
expandPathValues(pathValues, deep = true) {
|
|
98060
|
+
if (!pathValues || pathValues.length === 0 || !this.store) {
|
|
98061
|
+
return;
|
|
98062
|
+
}
|
|
98063
|
+
const node = findStoreNodeByPath(this.store, pathValues);
|
|
98064
|
+
if (!node) {
|
|
98065
|
+
return;
|
|
98066
|
+
}
|
|
98067
|
+
const pathIds = [];
|
|
98068
|
+
let current = node;
|
|
98069
|
+
while (current) {
|
|
98070
|
+
pathIds.unshift(current.id);
|
|
98071
|
+
if (current.parentId == null) {
|
|
98072
|
+
break;
|
|
98073
|
+
}
|
|
98074
|
+
current = this.store.nodeById.get(current.parentId);
|
|
98075
|
+
}
|
|
98076
|
+
this.activePath = this.sanitizeActivePath(pathIds);
|
|
98077
|
+
if (deep && this.autoExpandDeep) {
|
|
98078
|
+
this.$nextTick(() => {
|
|
98079
|
+
this.expandDeepFromNode(node);
|
|
98080
|
+
});
|
|
98081
|
+
}
|
|
98082
|
+
},
|
|
98083
|
+
onNodeClick(node, colIndex) {
|
|
98084
|
+
if (node.disabled || this.isViewMode) {
|
|
98085
|
+
return;
|
|
98086
|
+
}
|
|
98087
|
+
if (!this.multiple && !this.checkStrictly) {
|
|
98088
|
+
if (node.isLeaf) {
|
|
98089
|
+
this.selection.clear();
|
|
98090
|
+
this.selection.toggleNode(node.id, true);
|
|
98091
|
+
this.emitValue();
|
|
98092
|
+
} else {
|
|
98093
|
+
this.expandNode(node);
|
|
98094
|
+
}
|
|
98095
|
+
return;
|
|
98096
|
+
}
|
|
98097
|
+
this.expandNode(node);
|
|
98098
|
+
},
|
|
98099
|
+
onCheckClick(node, checked) {
|
|
98100
|
+
if (!this.multiple || node.disabled || this.isViewMode) {
|
|
98101
|
+
return;
|
|
98102
|
+
}
|
|
98103
|
+
const nextChecked = typeof checked === 'boolean' ? checked : !this.isChecked(node);
|
|
98104
|
+
this.selection.toggleNode(node.id, nextChecked);
|
|
98105
|
+
this.bumpSelectionView();
|
|
98106
|
+
this.emitValue();
|
|
98107
|
+
|
|
98108
|
+
// 与 el-cascader-panel 一致:非 checkStrictly 时勾选会同步展开当前节点
|
|
98109
|
+
if (!this.checkStrictly && !node.isLeaf) {
|
|
98110
|
+
this.expandNode(node);
|
|
98111
|
+
}
|
|
98112
|
+
},
|
|
98113
|
+
onRadioClick(node) {
|
|
98114
|
+
if (this.multiple || node.disabled || this.isViewMode) {
|
|
98115
|
+
return;
|
|
98116
|
+
}
|
|
98117
|
+
this.selection.clear();
|
|
98118
|
+
this.selection.toggleNode(node.id, true);
|
|
98119
|
+
this.emitValue();
|
|
98120
|
+
if (!node.isLeaf) {
|
|
98121
|
+
this.expandNode(node);
|
|
98122
|
+
}
|
|
98123
|
+
},
|
|
98124
|
+
clearCheckedNodes() {
|
|
98125
|
+
if (this.selection) {
|
|
98126
|
+
this.selection.clear();
|
|
98127
|
+
this.bumpSelectionView();
|
|
98128
|
+
this.$emit('input', this.multiple ? [] : []);
|
|
98129
|
+
this.$emit('change', this.multiple ? [] : []);
|
|
98130
|
+
}
|
|
98131
|
+
},
|
|
98132
|
+
selectAllLeaves() {
|
|
98133
|
+
if (this.selection) {
|
|
98134
|
+
this.selection.selectAll();
|
|
98135
|
+
this.bumpSelectionView();
|
|
98136
|
+
this.emitValue();
|
|
98137
|
+
}
|
|
98138
|
+
},
|
|
98139
|
+
syncCheckedValue() {
|
|
98140
|
+
this.syncFromValue();
|
|
98141
|
+
},
|
|
98142
|
+
syncFromParentValues(values, prefix) {
|
|
98143
|
+
if (!this.selection) {
|
|
98144
|
+
return;
|
|
98145
|
+
}
|
|
98146
|
+
this.suppressValueSync = true;
|
|
98147
|
+
this.selection.syncFromParentValues(values, prefix);
|
|
98148
|
+
this.bumpSelectionView();
|
|
98149
|
+
this.suppressValueSync = false;
|
|
98150
|
+
},
|
|
98151
|
+
getSelectionSnapshot() {
|
|
98152
|
+
if (!this.selection || !this.store) {
|
|
98153
|
+
return null;
|
|
98154
|
+
}
|
|
98155
|
+
return {
|
|
98156
|
+
store: this.store,
|
|
98157
|
+
selection: this.selection,
|
|
98158
|
+
isCompact: this.selection.isCompactSelection(),
|
|
98159
|
+
count: this.selection.size()
|
|
98160
|
+
};
|
|
98161
|
+
}
|
|
98162
|
+
}
|
|
98163
|
+
});
|
|
98164
|
+
;// ./src/components/cascader-panel-pro/VirtualCascaderPanel.vue?vue&type=script&lang=js
|
|
98165
|
+
/* harmony default export */ var cascader_panel_pro_VirtualCascaderPanelvue_type_script_lang_js = (VirtualCascaderPanelvue_type_script_lang_js);
|
|
98166
|
+
;// ./src/components/cascader-panel-pro/VirtualCascaderPanel.vue
|
|
98167
|
+
|
|
98168
|
+
|
|
98169
|
+
|
|
98170
|
+
|
|
98171
|
+
|
|
98172
|
+
/* normalize component */
|
|
98173
|
+
;
|
|
98174
|
+
var VirtualCascaderPanel_component = normalizeComponent(
|
|
98175
|
+
cascader_panel_pro_VirtualCascaderPanelvue_type_script_lang_js,
|
|
98176
|
+
VirtualCascaderPanelvue_type_template_id_23086f90_render,
|
|
98177
|
+
VirtualCascaderPanelvue_type_template_id_23086f90_staticRenderFns,
|
|
98178
|
+
false,
|
|
98179
|
+
null,
|
|
98180
|
+
null,
|
|
98181
|
+
null
|
|
98182
|
+
|
|
98183
|
+
)
|
|
98184
|
+
|
|
98185
|
+
/* harmony default export */ var VirtualCascaderPanel = (VirtualCascaderPanel_component.exports);
|
|
98186
|
+
;// ./node_modules/thread-loader/dist/cjs.js!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/cascader-panel-pro/ByCascaderPanelPro.vue?vue&type=script&lang=js
|
|
98187
|
+
|
|
98188
|
+
|
|
98189
|
+
|
|
98190
|
+
|
|
98191
|
+
|
|
98192
|
+
|
|
98193
|
+
|
|
98194
|
+
|
|
98195
|
+
|
|
98196
|
+
|
|
98197
|
+
|
|
98198
|
+
|
|
98199
|
+
|
|
98200
|
+
|
|
98201
|
+
|
|
98202
|
+
|
|
98203
|
+
|
|
98204
|
+
/* harmony default export */ var ByCascaderPanelProvue_type_script_lang_js = ({
|
|
98205
|
+
name: 'ByCascaderPanelPro',
|
|
98206
|
+
components: {
|
|
98207
|
+
VirtualCascaderPanel: VirtualCascaderPanel,
|
|
98208
|
+
VcpVirtualList: VirtualList
|
|
98209
|
+
},
|
|
98210
|
+
props: {
|
|
98211
|
+
// 级联数据源
|
|
98212
|
+
options: {
|
|
98213
|
+
type: Array,
|
|
98214
|
+
default: () => []
|
|
98215
|
+
},
|
|
98216
|
+
// 已选值
|
|
98217
|
+
value: {
|
|
98218
|
+
type: [Array, Number, String],
|
|
98219
|
+
default: () => []
|
|
98220
|
+
},
|
|
98221
|
+
// 级联面板配置
|
|
98222
|
+
cascaderProps: {
|
|
98223
|
+
type: Object,
|
|
98224
|
+
default: () => ({
|
|
98225
|
+
multiple: true,
|
|
98226
|
+
label: 'label',
|
|
98227
|
+
value: 'value',
|
|
98228
|
+
children: 'children'
|
|
98229
|
+
})
|
|
98230
|
+
},
|
|
98231
|
+
// 面板高度
|
|
98232
|
+
panelHeight: {
|
|
98233
|
+
type: [String, Number],
|
|
98234
|
+
default: 300,
|
|
98235
|
+
validator: value => {
|
|
98236
|
+
const numValue = Number(value);
|
|
98237
|
+
if (isNaN(numValue)) {
|
|
98238
|
+
console.warn(`[ByCascaderPanelPro] panelHeight 必须是数字,当前值: ${value}`);
|
|
98239
|
+
return false;
|
|
98240
|
+
}
|
|
98241
|
+
if (numValue < 200) {
|
|
98242
|
+
console.warn(`[ByCascaderPanelPro] panelHeight 不能小于 200px,当前值: ${value}px`);
|
|
98243
|
+
return false;
|
|
98244
|
+
}
|
|
98245
|
+
if (numValue > 800) {
|
|
98246
|
+
console.warn(`[ByCascaderPanelPro] panelHeight 不能大于 800px,当前值: ${value}px`);
|
|
98247
|
+
return false;
|
|
98248
|
+
}
|
|
98249
|
+
return true;
|
|
98250
|
+
}
|
|
98251
|
+
},
|
|
98252
|
+
// 搜索占位符
|
|
98253
|
+
searchPlaceholder: {
|
|
98254
|
+
type: String,
|
|
98255
|
+
default: '请输入名称搜索'
|
|
98256
|
+
},
|
|
98257
|
+
// 禁用字段名(只针对叶子节点,非叶子节点为disabled)
|
|
98258
|
+
disabledField: {
|
|
98259
|
+
type: String,
|
|
98260
|
+
default: 'disabled'
|
|
98261
|
+
},
|
|
98262
|
+
// 禁用值(只针对叶子节点,非叶子节点为disabled)
|
|
98263
|
+
disabledValue: {
|
|
98264
|
+
type: [String, Number, Boolean],
|
|
98265
|
+
default: true
|
|
98266
|
+
},
|
|
98267
|
+
// 自定义禁用判断函数
|
|
98268
|
+
disabledCheck: {
|
|
98269
|
+
type: Function,
|
|
98270
|
+
default: null
|
|
98271
|
+
},
|
|
98272
|
+
// 是否显示全选按钮
|
|
98273
|
+
showSelectAll: {
|
|
98274
|
+
type: Boolean,
|
|
98275
|
+
default: true
|
|
98276
|
+
},
|
|
98277
|
+
// 是否聚合模式 (聚合模式下如果子项全部选中,会直接返回父ID)
|
|
98278
|
+
aggregationMode: {
|
|
98279
|
+
type: Boolean,
|
|
98280
|
+
default: false
|
|
98281
|
+
},
|
|
98282
|
+
/**
|
|
98283
|
+
* 非叶子节点前缀标识 (聚合模式下用于标识非叶子节点)
|
|
98284
|
+
* 注意:聚合模式下,由于叶子节点和非叶子节点可能存在相同id,所以绑定数据中务必给非叶子节点加上parentNodePrefix前缀作为标识
|
|
98285
|
+
*/
|
|
98286
|
+
parentNodePrefix: {
|
|
98287
|
+
type: String,
|
|
98288
|
+
default: '__parent__'
|
|
98289
|
+
},
|
|
98290
|
+
// 是否为查看模式 (如果是查看模式,则组件中的操作交互将全部禁用,仅用于回显查看)
|
|
98291
|
+
isViewMode: {
|
|
98292
|
+
type: Boolean,
|
|
98293
|
+
default: false
|
|
98294
|
+
},
|
|
98295
|
+
// 是否显示子标题
|
|
98296
|
+
showSubtitle: {
|
|
98297
|
+
type: Boolean,
|
|
98298
|
+
default: false
|
|
98299
|
+
},
|
|
98300
|
+
// 子标题字段名
|
|
98301
|
+
subtitleField: {
|
|
98302
|
+
type: String,
|
|
98303
|
+
default: ''
|
|
98304
|
+
},
|
|
98305
|
+
// 级联列最小宽度(px)
|
|
98306
|
+
columnMinWidth: {
|
|
98307
|
+
type: Number,
|
|
98308
|
+
default: 180
|
|
98309
|
+
},
|
|
98310
|
+
// 级联列最大宽度(px),超出后显示省略号
|
|
98311
|
+
columnMaxWidth: {
|
|
98312
|
+
type: Number,
|
|
98313
|
+
default: 420
|
|
98314
|
+
}
|
|
98315
|
+
},
|
|
98316
|
+
data() {
|
|
98317
|
+
return {
|
|
98318
|
+
selectedValues: [],
|
|
98319
|
+
searchSelectedValues: [],
|
|
98320
|
+
filteredOptions: [],
|
|
98321
|
+
searchOptions: [],
|
|
98322
|
+
selectedItems: [],
|
|
98323
|
+
searchInput: '',
|
|
98324
|
+
isShow: true,
|
|
98325
|
+
isShowSearch: false,
|
|
98326
|
+
totalCount: 0,
|
|
98327
|
+
selectedCount: 0,
|
|
98328
|
+
isAllSelected: false,
|
|
98329
|
+
isInternalUpdate: false,
|
|
98330
|
+
// 防止循环更新的标志
|
|
98331
|
+
batchSearchVisible: false,
|
|
98332
|
+
// 批量搜索弹窗显示状态
|
|
98333
|
+
batchSearchContent: '',
|
|
98334
|
+
// 批量搜索输入内容
|
|
98335
|
+
compactPanelValue: [],
|
|
98336
|
+
// 紧凑模式下稳定的空 value 引用,避免 watch 误触发清空
|
|
98337
|
+
searchDebounceTimer: null,
|
|
98338
|
+
searchLeafSetCache: null
|
|
98339
|
+
};
|
|
98340
|
+
},
|
|
98341
|
+
computed: {
|
|
98342
|
+
disabledConfig() {
|
|
98343
|
+
return {
|
|
98344
|
+
disabledField: this.disabledField,
|
|
98345
|
+
disabledValue: this.disabledValue,
|
|
98346
|
+
disabledCheck: this.disabledCheck
|
|
98347
|
+
};
|
|
98348
|
+
},
|
|
98349
|
+
// 处理后的面板高度,确保在有效范围内
|
|
98350
|
+
computedPanelHeight() {
|
|
98351
|
+
const height = Number(this.panelHeight);
|
|
98352
|
+
if (isNaN(height)) {
|
|
98353
|
+
return 300; // 默认值
|
|
98354
|
+
}
|
|
98355
|
+
// 限制在 200px 到 800px 之间
|
|
98356
|
+
return Math.max(200, Math.min(800, height));
|
|
98357
|
+
},
|
|
98358
|
+
// 是否为多选模式
|
|
98359
|
+
isMultiple() {
|
|
98360
|
+
return this.cascaderProps.multiple !== false;
|
|
98361
|
+
},
|
|
98362
|
+
useCompactSelection() {
|
|
98363
|
+
return this.isMultiple && this.totalCount >= 300;
|
|
98364
|
+
},
|
|
98365
|
+
panelPresentationValue() {
|
|
98366
|
+
if (this.useCompactSelection) {
|
|
98367
|
+
return this.compactPanelValue;
|
|
98368
|
+
}
|
|
98369
|
+
if (this.isMultiple) {
|
|
98370
|
+
return this.selectedValues;
|
|
98371
|
+
}
|
|
98372
|
+
return this.selectedValues.length > 0 ? this.selectedValues[0] : [];
|
|
98373
|
+
},
|
|
98374
|
+
compactSearchPanelValue() {
|
|
98375
|
+
return this.compactPanelValue;
|
|
98376
|
+
},
|
|
98377
|
+
selectedItemHeight() {
|
|
98378
|
+
return 40;
|
|
98379
|
+
},
|
|
98380
|
+
selectedListHeight() {
|
|
98381
|
+
return Math.max(120, this.computedPanelHeight - 25);
|
|
98382
|
+
},
|
|
98383
|
+
// 当前选中的值(单选时返回单个值,多选时返回数组)
|
|
98384
|
+
currentValue() {
|
|
98385
|
+
if (this.isMultiple) {
|
|
98386
|
+
return this.selectedItems.map(item => item.value);
|
|
98387
|
+
} else {
|
|
98388
|
+
return this.selectedItems.length > 0 ? this.selectedItems[0].value : null;
|
|
98389
|
+
}
|
|
98390
|
+
},
|
|
98391
|
+
// 主面板的值(单选时返回单个路径,多选时返回路径数组)
|
|
98392
|
+
mainPanelValue: {
|
|
98393
|
+
get() {
|
|
98394
|
+
if (this.isMultiple) {
|
|
98395
|
+
return this.selectedValues;
|
|
98396
|
+
} else {
|
|
98397
|
+
return this.selectedValues.length > 0 ? this.selectedValues[0] : [];
|
|
98398
|
+
}
|
|
98399
|
+
},
|
|
98400
|
+
set(value) {
|
|
98401
|
+
if (this.isMultiple) {
|
|
98402
|
+
this.selectedValues = value || [];
|
|
98403
|
+
} else {
|
|
98404
|
+
this.selectedValues = value ? [value] : [];
|
|
98405
|
+
}
|
|
98406
|
+
}
|
|
98407
|
+
},
|
|
98408
|
+
// 搜索面板的值(单选时返回单个路径,多选时返回路径数组)
|
|
98409
|
+
searchPanelValue: {
|
|
98410
|
+
get() {
|
|
98411
|
+
if (this.isMultiple) {
|
|
98412
|
+
return this.searchSelectedValues;
|
|
98413
|
+
} else {
|
|
98414
|
+
return this.searchSelectedValues.length > 0 ? this.searchSelectedValues[0] : [];
|
|
98415
|
+
}
|
|
98416
|
+
},
|
|
98417
|
+
set(value) {
|
|
98418
|
+
if (this.isMultiple) {
|
|
98419
|
+
this.searchSelectedValues = value || [];
|
|
98420
|
+
} else {
|
|
98421
|
+
this.searchSelectedValues = value ? [value] : [];
|
|
98422
|
+
}
|
|
98423
|
+
}
|
|
98424
|
+
}
|
|
98425
|
+
},
|
|
98426
|
+
watch: {
|
|
98427
|
+
options: {
|
|
98428
|
+
handler(newVal) {
|
|
98429
|
+
this.initOptions();
|
|
98430
|
+
},
|
|
98431
|
+
deep: true,
|
|
98432
|
+
immediate: true
|
|
98433
|
+
},
|
|
98434
|
+
value: {
|
|
98435
|
+
handler(newVal) {
|
|
98436
|
+
// 如果是内部更新触发的,跳过处理
|
|
98437
|
+
if (this.isInternalUpdate) {
|
|
98438
|
+
this.isInternalUpdate = false;
|
|
98439
|
+
return;
|
|
98440
|
+
}
|
|
98441
|
+
this.processValue();
|
|
98442
|
+
},
|
|
98443
|
+
deep: true,
|
|
98444
|
+
immediate: true
|
|
98445
|
+
},
|
|
98446
|
+
searchInput(val) {
|
|
98447
|
+
if (!val) {
|
|
98448
|
+
this.clearSearchState();
|
|
98449
|
+
return;
|
|
98450
|
+
}
|
|
98451
|
+
this.scheduleSearch();
|
|
98452
|
+
},
|
|
98453
|
+
selectedItems: {
|
|
98454
|
+
handler(newVal) {
|
|
98455
|
+
if (this.isMultiple) {
|
|
98456
|
+
const panel = this.$refs.cascaderPanel;
|
|
98457
|
+
if (this.useCompactSelection && !this.aggregationMode && panel && panel.selection && panel.selection.isCompactSelection()) {
|
|
98458
|
+
this.selectedCount = panel.selection.size();
|
|
98459
|
+
} else {
|
|
98460
|
+
this.selectedCount = newVal.length;
|
|
98461
|
+
}
|
|
98462
|
+
if (!this.useCompactSelection) {
|
|
98463
|
+
if (this.aggregationMode) {
|
|
98464
|
+
const config = {
|
|
98465
|
+
disabledField: this.disabledField,
|
|
98466
|
+
disabledValue: this.disabledValue,
|
|
98467
|
+
disabledCheck: this.disabledCheck
|
|
98468
|
+
};
|
|
98469
|
+
this.isAllSelected = CascaderUtilsPro.isAggregatedAllSelected(this.selectedValues, this.filteredOptions, config, this.cascaderProps);
|
|
98470
|
+
} else {
|
|
98471
|
+
this.isAllSelected = this.selectedCount === this.totalCount;
|
|
96387
98472
|
}
|
|
96388
|
-
}
|
|
96389
|
-
}
|
|
96390
|
-
|
|
96391
|
-
|
|
98473
|
+
}
|
|
98474
|
+
} else {
|
|
98475
|
+
if (newVal.length > 1) {
|
|
98476
|
+
this.selectedItems = [newVal[newVal.length - 1]];
|
|
98477
|
+
}
|
|
98478
|
+
this.selectedCount = this.selectedItems.length;
|
|
98479
|
+
}
|
|
98480
|
+
},
|
|
98481
|
+
deep: false
|
|
98482
|
+
}
|
|
98483
|
+
},
|
|
98484
|
+
mounted() {
|
|
98485
|
+
this.initOptions();
|
|
98486
|
+
// 确保在 mounted 后处理默认值
|
|
98487
|
+
this.$nextTick(() => {
|
|
98488
|
+
this.processValue();
|
|
98489
|
+
});
|
|
98490
|
+
// 组件挂载后强制调整样式
|
|
98491
|
+
this.forceVerticalCenter();
|
|
98492
|
+
},
|
|
98493
|
+
beforeDestroy() {
|
|
98494
|
+
if (this.searchDebounceTimer) {
|
|
98495
|
+
clearTimeout(this.searchDebounceTimer);
|
|
98496
|
+
this.searchDebounceTimer = null;
|
|
98497
|
+
}
|
|
98498
|
+
},
|
|
98499
|
+
methods: {
|
|
98500
|
+
onMainPanelInput(value) {
|
|
98501
|
+
if (this.useCompactSelection && Array.isArray(value) && value.length >= 300) {
|
|
98502
|
+
return;
|
|
98503
|
+
}
|
|
98504
|
+
if (this.isMultiple) {
|
|
98505
|
+
this.selectedValues = Array.isArray(value) ? value : [];
|
|
98506
|
+
} else {
|
|
98507
|
+
this.selectedValues = value && value.length ? [value] : [];
|
|
96392
98508
|
}
|
|
96393
|
-
CascaderUtils.setDisabledItems(processedOptions, this.disabledConfig, this.cascaderProps);
|
|
96394
|
-
return processedOptions;
|
|
96395
98509
|
},
|
|
96396
|
-
|
|
96397
|
-
|
|
96398
|
-
|
|
96399
|
-
|
|
96400
|
-
|
|
96401
|
-
|
|
96402
|
-
|
|
96403
|
-
|
|
98510
|
+
applyPanelSelectionChange() {
|
|
98511
|
+
const panel = this.$refs.cascaderPanel;
|
|
98512
|
+
if (!panel || !panel.store || !panel.selection) {
|
|
98513
|
+
return;
|
|
98514
|
+
}
|
|
98515
|
+
const {
|
|
98516
|
+
store,
|
|
98517
|
+
selection
|
|
98518
|
+
} = panel;
|
|
98519
|
+
if (this.aggregationMode) {
|
|
98520
|
+
const items = CascaderUtilsPro.getAggregatedItemsFromSelection(store, selection, this.filteredOptions, this.cascaderProps);
|
|
98521
|
+
this.selectedItems = items;
|
|
98522
|
+
this.selectedCount = items.length;
|
|
98523
|
+
this.isAllSelected = selection.size() === store.totalLeafCount && store.totalLeafCount > 0;
|
|
98524
|
+
if (!selection.isCompactSelection()) {
|
|
98525
|
+
this.selectedValues = selection.getCheckedPaths();
|
|
98526
|
+
}
|
|
98527
|
+
this.isInternalUpdate = true;
|
|
98528
|
+
let emitValue = CascaderUtilsPro.getAggregatedEmitValues(items, this.parentNodePrefix);
|
|
98529
|
+
if (!this.isMultiple && emitValue.length > 0) {
|
|
98530
|
+
emitValue = emitValue[0];
|
|
98531
|
+
}
|
|
98532
|
+
this.$emit('input', emitValue);
|
|
98533
|
+
this.$emit('change', this.getSelectedData());
|
|
98534
|
+
panel.bumpSelectionView();
|
|
98535
|
+
return;
|
|
98536
|
+
}
|
|
98537
|
+
if (selection.isCompactSelection()) {
|
|
98538
|
+
this.selectedItems = this.buildSelectedItemsFromValuesLazy(panel);
|
|
98539
|
+
this.selectedCount = this.aggregationMode ? this.selectedItems.length : selection.size();
|
|
98540
|
+
this.isAllSelected = selection.size() === store.totalLeafCount;
|
|
98541
|
+
this.isInternalUpdate = true;
|
|
98542
|
+
this.$emit('input', this.currentValue);
|
|
98543
|
+
this.$emit('change', this.getSelectedData());
|
|
98544
|
+
panel.bumpSelectionView();
|
|
98545
|
+
return;
|
|
98546
|
+
}
|
|
98547
|
+
this.selectedValues = selection.getCheckedPaths();
|
|
98548
|
+
this.updateSelectedItems();
|
|
98549
|
+
panel.bumpSelectionView();
|
|
98550
|
+
this.$nextTick(() => {
|
|
98551
|
+
this.isInternalUpdate = true;
|
|
98552
|
+
let emitValue = this.currentValue;
|
|
98553
|
+
if (this.aggregationMode) {
|
|
98554
|
+
emitValue = CascaderUtilsPro.getAggregatedEmitValues(this.selectedItems, this.parentNodePrefix);
|
|
98555
|
+
if (!this.isMultiple && emitValue.length > 0) {
|
|
98556
|
+
emitValue = emitValue[0];
|
|
98557
|
+
}
|
|
98558
|
+
}
|
|
98559
|
+
this.$emit('input', emitValue);
|
|
98560
|
+
this.$emit('change', this.getSelectedData());
|
|
98561
|
+
});
|
|
98562
|
+
},
|
|
98563
|
+
buildSelectedItemsFromValuesLazy(panel) {
|
|
98564
|
+
if (!panel || !panel.selection) {
|
|
98565
|
+
return [];
|
|
98566
|
+
}
|
|
98567
|
+
if (!panel.selection.isCompactSelection()) {
|
|
98568
|
+
return this.buildSelectedItemsFromValues();
|
|
98569
|
+
}
|
|
98570
|
+
return CascaderUtilsPro.buildSelectedItemsFromSelection(panel.store, panel.selection, this.filteredOptions, this.cascaderProps);
|
|
98571
|
+
},
|
|
98572
|
+
syncPanelFromExternalValue() {
|
|
98573
|
+
const panel = this.$refs.cascaderPanel;
|
|
98574
|
+
if (!panel || !panel.selection || !panel.store) {
|
|
98575
|
+
return;
|
|
98576
|
+
}
|
|
98577
|
+
if (!Array.isArray(this.value) || this.value.length === 0) {
|
|
98578
|
+
panel.clearCheckedNodes();
|
|
98579
|
+
this.selectedItems = [];
|
|
98580
|
+
this.selectedValues = [];
|
|
98581
|
+
return;
|
|
98582
|
+
}
|
|
98583
|
+
const paths = this.resolveExternalValueToPaths();
|
|
98584
|
+
panel.selection.clear();
|
|
98585
|
+
paths.forEach(path => {
|
|
98586
|
+
const leafValue = path[path.length - 1];
|
|
98587
|
+
if (panel.store.pathByLeafValue.has(leafValue)) {
|
|
98588
|
+
panel.selection.selectedLeafSet.add(leafValue);
|
|
96404
98589
|
}
|
|
96405
|
-
return cloned;
|
|
96406
98590
|
});
|
|
98591
|
+
panel.selection._reconcileAllRoots();
|
|
98592
|
+
panel.bumpSelectionView();
|
|
98593
|
+
this.applyPanelSelectionChange();
|
|
98594
|
+
this.expandPanelToExternalValue(panel);
|
|
98595
|
+
},
|
|
98596
|
+
resolveExternalValueToPaths() {
|
|
98597
|
+
if (!Array.isArray(this.value) || this.value.length === 0) {
|
|
98598
|
+
return [];
|
|
98599
|
+
}
|
|
98600
|
+
if (typeof this.value[0] === 'string' || typeof this.value[0] === 'number') {
|
|
98601
|
+
if (this.aggregationMode) {
|
|
98602
|
+
return CascaderUtilsPro.processValuesWithParentNodes(this.value, this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
98603
|
+
}
|
|
98604
|
+
return this.findPathsByValues(this.value);
|
|
98605
|
+
}
|
|
98606
|
+
return [...this.value];
|
|
98607
|
+
},
|
|
98608
|
+
expandPanelToExternalValue(panel) {
|
|
98609
|
+
if (!panel || !panel.store || !Array.isArray(this.value) || this.value.length === 0) {
|
|
98610
|
+
return;
|
|
98611
|
+
}
|
|
98612
|
+
const firstValue = this.value[0];
|
|
98613
|
+
let pathValues = [];
|
|
98614
|
+
if (this.aggregationMode && CascaderUtilsPro.isParentNodeValue(firstValue, this.parentNodePrefix)) {
|
|
98615
|
+
const actualValue = CascaderUtilsPro.extractParentNodeValue(firstValue, this.parentNodePrefix);
|
|
98616
|
+
const node = panel.store.nodeByValue.get(actualValue);
|
|
98617
|
+
pathValues = node ? [...node.path] : [];
|
|
98618
|
+
} else if (panel.store.pathByLeafValue.has(firstValue)) {
|
|
98619
|
+
const path = panel.store.pathByLeafValue.get(firstValue);
|
|
98620
|
+
pathValues = path ? path.slice(0, -1) : [];
|
|
98621
|
+
} else {
|
|
98622
|
+
const node = panel.store.nodeByValue.get(firstValue);
|
|
98623
|
+
if (node) {
|
|
98624
|
+
pathValues = node.isLeaf ? node.path.slice(0, -1) : [...node.path];
|
|
98625
|
+
}
|
|
98626
|
+
}
|
|
98627
|
+
if (pathValues.length > 0) {
|
|
98628
|
+
this.$nextTick(() => {
|
|
98629
|
+
panel.expandPathValues(pathValues, true);
|
|
98630
|
+
});
|
|
98631
|
+
}
|
|
98632
|
+
},
|
|
98633
|
+
onSearchPanelInput(value) {
|
|
98634
|
+
if (this.useCompactSelection && Array.isArray(value) && value.length >= 300) {
|
|
98635
|
+
return;
|
|
98636
|
+
}
|
|
98637
|
+
if (this.isMultiple) {
|
|
98638
|
+
this.searchSelectedValues = Array.isArray(value) ? value : [];
|
|
98639
|
+
} else {
|
|
98640
|
+
this.searchSelectedValues = value && value.length ? [value] : [];
|
|
98641
|
+
}
|
|
98642
|
+
},
|
|
98643
|
+
// 处理 value 值
|
|
98644
|
+
processValue() {
|
|
98645
|
+
if (this.useCompactSelection && this.isMultiple) {
|
|
98646
|
+
this.selectedValues = [];
|
|
98647
|
+
this.$nextTick(() => {
|
|
98648
|
+
this.syncPanelFromExternalValue();
|
|
98649
|
+
});
|
|
98650
|
+
return;
|
|
98651
|
+
}
|
|
98652
|
+
if (this.isMultiple) {
|
|
98653
|
+
// 多选模式:支持直接传入value值或路径数组
|
|
98654
|
+
if (Array.isArray(this.value) && this.value.length > 0) {
|
|
98655
|
+
if (typeof this.value[0] === 'string' || typeof this.value[0] === 'number') {
|
|
98656
|
+
// 传入的是value值数组,需要转换为路径
|
|
98657
|
+
if (this.aggregationMode) {
|
|
98658
|
+
// 聚合模式下,支持非叶子节点标识
|
|
98659
|
+
this.selectedValues = CascaderUtilsPro.processValuesWithParentNodes(this.value, this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
98660
|
+
} else {
|
|
98661
|
+
// 普通模式下,只处理叶子节点
|
|
98662
|
+
this.selectedValues = this.findPathsByValues(this.value);
|
|
98663
|
+
}
|
|
98664
|
+
} else {
|
|
98665
|
+
// 传入的是路径数组
|
|
98666
|
+
this.selectedValues = [...this.value];
|
|
98667
|
+
}
|
|
98668
|
+
} else {
|
|
98669
|
+
this.selectedValues = [];
|
|
98670
|
+
}
|
|
98671
|
+
} else {
|
|
98672
|
+
// 单选模式:支持单个值或路径数组
|
|
98673
|
+
if (this.value !== null && this.value !== undefined && this.value !== '') {
|
|
98674
|
+
if (Array.isArray(this.value)) {
|
|
98675
|
+
// 传入的是路径数组
|
|
98676
|
+
this.selectedValues = [...this.value];
|
|
98677
|
+
} else {
|
|
98678
|
+
// 传入的是单个值,需要转换为路径
|
|
98679
|
+
if (this.aggregationMode) {
|
|
98680
|
+
// 聚合模式下,支持非叶子节点标识
|
|
98681
|
+
this.selectedValues = CascaderUtilsPro.processValuesWithParentNodes([this.value], this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
98682
|
+
} else {
|
|
98683
|
+
// 普通模式下,只处理叶子节点
|
|
98684
|
+
this.selectedValues = this.findPathsByValues([this.value]);
|
|
98685
|
+
}
|
|
98686
|
+
}
|
|
98687
|
+
} else {
|
|
98688
|
+
this.selectedValues = [];
|
|
98689
|
+
}
|
|
98690
|
+
}
|
|
98691
|
+
this.updateSelectedItems();
|
|
98692
|
+
|
|
98693
|
+
// 单选模式下,确保级联面板正确显示选中状态
|
|
98694
|
+
if (!this.isMultiple && this.selectedValues.length > 0) {
|
|
98695
|
+
this.$nextTick(() => {
|
|
98696
|
+
const panel = this.$refs.cascaderPanel;
|
|
98697
|
+
if (panel) {
|
|
98698
|
+
panel.syncCheckedValue();
|
|
98699
|
+
this.updateSelectedItems();
|
|
98700
|
+
}
|
|
98701
|
+
});
|
|
98702
|
+
}
|
|
96407
98703
|
},
|
|
98704
|
+
// 初始化选项数据
|
|
98705
|
+
initOptions() {
|
|
98706
|
+
this.filteredOptions = this.processOptions(this.options);
|
|
98707
|
+
this.countTotalItems();
|
|
98708
|
+
if (this.isMultiple && Array.isArray(this.value) && this.value.length > 0 && (this.useCompactSelection || this.$refs.cascaderPanel)) {
|
|
98709
|
+
this.$nextTick(() => {
|
|
98710
|
+
this.syncPanelFromExternalValue();
|
|
98711
|
+
});
|
|
98712
|
+
} else {
|
|
98713
|
+
this.updateSelectedItems();
|
|
98714
|
+
}
|
|
98715
|
+
},
|
|
98716
|
+
// 处理选项数据,添加禁用状态(浅拷贝,避免 JSON 深拷贝大数据卡顿)
|
|
98717
|
+
processOptions(options) {
|
|
98718
|
+
const childrenKey = this.cascaderProps && this.cascaderProps.children || 'children';
|
|
98719
|
+
const disabledKey = this.cascaderProps && this.cascaderProps.disabled || 'disabled';
|
|
98720
|
+
const config = this.disabledConfig;
|
|
98721
|
+
const cloneItems = (items, ancestorDisabled = false) => {
|
|
98722
|
+
return items.map(item => {
|
|
98723
|
+
const isDisabled = ancestorDisabled || CascaderUtilsPro.isItemDisabled(item, config);
|
|
98724
|
+
const children = item[childrenKey];
|
|
98725
|
+
const cloned = {
|
|
98726
|
+
...item
|
|
98727
|
+
};
|
|
98728
|
+
if (this.isViewMode || isDisabled) {
|
|
98729
|
+
cloned[disabledKey] = true;
|
|
98730
|
+
}
|
|
98731
|
+
if (children && children.length > 0) {
|
|
98732
|
+
cloned[childrenKey] = cloneItems(children, isDisabled || this.isViewMode);
|
|
98733
|
+
}
|
|
98734
|
+
return cloned;
|
|
98735
|
+
});
|
|
98736
|
+
};
|
|
98737
|
+
return cloneItems(options || []);
|
|
98738
|
+
},
|
|
98739
|
+
// 判断项目是否禁用
|
|
98740
|
+
isItemDisabled(item) {
|
|
98741
|
+
const config = {
|
|
98742
|
+
disabledField: this.disabledField,
|
|
98743
|
+
disabledValue: this.disabledValue,
|
|
98744
|
+
disabledCheck: this.disabledCheck
|
|
98745
|
+
};
|
|
98746
|
+
return CascaderUtilsPro.isItemDisabled(item, config);
|
|
98747
|
+
},
|
|
98748
|
+
// 统计总项目数
|
|
96408
98749
|
countTotalItems() {
|
|
96409
|
-
|
|
98750
|
+
const config = {
|
|
98751
|
+
disabledField: this.disabledField,
|
|
98752
|
+
disabledValue: this.disabledValue,
|
|
98753
|
+
disabledCheck: this.disabledCheck
|
|
98754
|
+
};
|
|
98755
|
+
this.totalCount = CascaderUtilsPro.countTotalItems(this.filteredOptions, config, this.cascaderProps);
|
|
96410
98756
|
},
|
|
96411
|
-
|
|
96412
|
-
|
|
96413
|
-
|
|
96414
|
-
|
|
96415
|
-
|
|
96416
|
-
|
|
96417
|
-
|
|
96418
|
-
} else {
|
|
96419
|
-
this.selectedValues = CascaderUtils.findPathsByValues(this.value, this.filteredOptions, this.cascaderProps);
|
|
96420
|
-
}
|
|
98757
|
+
// 更新已选项列表
|
|
98758
|
+
updateSelectedItems() {
|
|
98759
|
+
this.$nextTick(() => {
|
|
98760
|
+
const panel = this.$refs.cascaderPanel;
|
|
98761
|
+
if (this.aggregationMode) {
|
|
98762
|
+
if (panel && panel.store && panel.selection) {
|
|
98763
|
+
this.selectedItems = CascaderUtilsPro.getAggregatedItemsFromSelection(panel.store, panel.selection, this.filteredOptions, this.cascaderProps);
|
|
96421
98764
|
} else {
|
|
96422
|
-
this.
|
|
98765
|
+
this.selectedItems = CascaderUtilsPro.getAggregatedSelectedItems(this.selectedValues, this.filteredOptions, this.cascaderProps);
|
|
96423
98766
|
}
|
|
96424
98767
|
} else {
|
|
96425
|
-
this.
|
|
96426
|
-
}
|
|
96427
|
-
} else if (this.value !== null && this.value !== undefined && this.value !== '') {
|
|
96428
|
-
if (Array.isArray(this.value)) {
|
|
96429
|
-
this.selectedValues = [...this.value];
|
|
96430
|
-
} else if (this.aggregationMode) {
|
|
96431
|
-
this.selectedValues = CascaderUtils.processValuesWithParentNodes([this.value], this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
96432
|
-
} else {
|
|
96433
|
-
this.selectedValues = CascaderUtils.findPathsByValues([this.value], this.filteredOptions, this.cascaderProps);
|
|
98768
|
+
this.selectedItems = this.buildSelectedItemsFromValues();
|
|
96434
98769
|
}
|
|
96435
|
-
}
|
|
96436
|
-
this.selectedValues = [];
|
|
96437
|
-
}
|
|
96438
|
-
this.updateSelectedItems();
|
|
96439
|
-
this.syncTreeCheckedState();
|
|
98770
|
+
});
|
|
96440
98771
|
},
|
|
96441
|
-
|
|
96442
|
-
|
|
96443
|
-
|
|
96444
|
-
|
|
96445
|
-
|
|
98772
|
+
// 基于 selectedValues 构建已选项列表
|
|
98773
|
+
buildSelectedItemsFromValues() {
|
|
98774
|
+
return CascaderUtilsPro.buildSelectedItemsFromValues(this.selectedValues, this.filteredOptions, this.cascaderProps);
|
|
98775
|
+
},
|
|
98776
|
+
// 搜索处理(防抖,避免每次按键遍历整棵树)
|
|
98777
|
+
scheduleSearch() {
|
|
98778
|
+
if (this.searchDebounceTimer) {
|
|
98779
|
+
clearTimeout(this.searchDebounceTimer);
|
|
96446
98780
|
}
|
|
96447
|
-
this.
|
|
96448
|
-
|
|
98781
|
+
this.searchDebounceTimer = setTimeout(() => {
|
|
98782
|
+
this.searchDebounceTimer = null;
|
|
98783
|
+
this.runSearch();
|
|
98784
|
+
}, 100);
|
|
96449
98785
|
},
|
|
96450
|
-
|
|
96451
|
-
if (
|
|
96452
|
-
|
|
96453
|
-
this.
|
|
96454
|
-
} else {
|
|
96455
|
-
this.isAllSelected = this.selectedCount === this.totalCount && this.totalCount > 0;
|
|
98786
|
+
clearSearchState() {
|
|
98787
|
+
if (this.searchDebounceTimer) {
|
|
98788
|
+
clearTimeout(this.searchDebounceTimer);
|
|
98789
|
+
this.searchDebounceTimer = null;
|
|
96456
98790
|
}
|
|
98791
|
+
this.isShowSearch = false;
|
|
98792
|
+
this.searchOptions = [];
|
|
98793
|
+
this.searchLeafSetCache = null;
|
|
98794
|
+
this.searchSelectedValues = [];
|
|
96457
98795
|
},
|
|
96458
|
-
|
|
96459
|
-
const
|
|
96460
|
-
|
|
96461
|
-
|
|
96462
|
-
|
|
96463
|
-
if (tree && treeNode && typeof treeNode.level !== 'number') {
|
|
96464
|
-
treeNode = tree.getNode(treeNode);
|
|
98796
|
+
runSearch() {
|
|
98797
|
+
const keyword = this.searchInput.trim();
|
|
98798
|
+
if (!keyword) {
|
|
98799
|
+
this.clearSearchState();
|
|
98800
|
+
return;
|
|
96465
98801
|
}
|
|
96466
|
-
const
|
|
96467
|
-
|
|
96468
|
-
|
|
96469
|
-
|
|
96470
|
-
|
|
98802
|
+
const panel = this.$refs.cascaderPanel;
|
|
98803
|
+
if (panel && panel.store) {
|
|
98804
|
+
this.searchOptions = CascaderUtilsPro.searchFromStore(panel.store, keyword, this.cascaderProps);
|
|
98805
|
+
} else {
|
|
98806
|
+
this.searchOptions = CascaderUtilsPro.searchInTree(this.filteredOptions, keyword, this.cascaderProps);
|
|
96471
98807
|
}
|
|
96472
|
-
|
|
96473
|
-
|
|
96474
|
-
|
|
98808
|
+
this.searchLeafSetCache = new Set(CascaderUtilsPro.getLeafValues(this.searchOptions, this.cascaderProps));
|
|
98809
|
+
this.searchSelectedValues = this.getSearchSelectedPathsFromMain(this.searchLeafSetCache);
|
|
98810
|
+
this.isShowSearch = true;
|
|
96475
98811
|
this.$nextTick(() => {
|
|
96476
|
-
|
|
96477
|
-
|
|
96478
|
-
|
|
96479
|
-
if (this.isMultiple) {
|
|
96480
|
-
const leafKeys = this.selectedValues.map(path => path[path.length - 1]);
|
|
96481
|
-
tree.setCheckedKeys(leafKeys);
|
|
96482
|
-
} else if (this.selectedValues.length > 0) {
|
|
96483
|
-
const leafKey = this.selectedValues[0][this.selectedValues[0].length - 1];
|
|
96484
|
-
tree.setCurrentKey(leafKey);
|
|
96485
|
-
} else {
|
|
96486
|
-
tree.setCurrentKey(null);
|
|
98812
|
+
if (this.searchOptions.length > 0) {
|
|
98813
|
+
this.syncSearchPanelSelection();
|
|
98814
|
+
this.handleSearchExpand();
|
|
96487
98815
|
}
|
|
96488
|
-
this.$nextTick(() => {
|
|
96489
|
-
this.isSyncingTree = false;
|
|
96490
|
-
});
|
|
96491
98816
|
});
|
|
96492
98817
|
},
|
|
96493
|
-
|
|
96494
|
-
|
|
96495
|
-
|
|
96496
|
-
|
|
96497
|
-
|
|
96498
|
-
|
|
96499
|
-
|
|
96500
|
-
|
|
96501
|
-
|
|
96502
|
-
|
|
96503
|
-
|
|
96504
|
-
|
|
96505
|
-
|
|
96506
|
-
|
|
96507
|
-
this.selectedValues
|
|
96508
|
-
this.updateSelectedItems();
|
|
96509
|
-
this.emitInput();
|
|
98818
|
+
getSearchSelectedPathsFromMain(searchLeafSet) {
|
|
98819
|
+
const panel = this.$refs.cascaderPanel;
|
|
98820
|
+
if (panel && panel.selection && panel.store) {
|
|
98821
|
+
const paths = [];
|
|
98822
|
+
panel.selection.selectedLeafSet.forEach(leaf => {
|
|
98823
|
+
if (searchLeafSet.has(leaf)) {
|
|
98824
|
+
const path = panel.store.pathByLeafValue.get(leaf);
|
|
98825
|
+
if (path) {
|
|
98826
|
+
paths.push(path);
|
|
98827
|
+
}
|
|
98828
|
+
}
|
|
98829
|
+
});
|
|
98830
|
+
return paths;
|
|
98831
|
+
}
|
|
98832
|
+
return CascaderUtilsPro.getSearchSelectedValues(this.selectedValues, this.searchOptions, this.cascaderProps);
|
|
96510
98833
|
},
|
|
96511
|
-
|
|
96512
|
-
if (this.
|
|
96513
|
-
|
|
98834
|
+
getSearchLeafSet() {
|
|
98835
|
+
if (this.searchLeafSetCache) {
|
|
98836
|
+
return this.searchLeafSetCache;
|
|
96514
98837
|
}
|
|
96515
|
-
|
|
96516
|
-
const keyword = this.searchInput.trim();
|
|
96517
|
-
if (!keyword) {
|
|
96518
|
-
this.displayOptions = this.filteredOptions;
|
|
96519
|
-
this.$nextTick(() => this.syncTreeCheckedState());
|
|
96520
|
-
return;
|
|
96521
|
-
}
|
|
96522
|
-
this.displayOptions = CascaderUtils.searchInTree(this.filteredOptions, keyword, this.cascaderProps);
|
|
96523
|
-
this.$nextTick(() => {
|
|
96524
|
-
this.syncTreeCheckedState();
|
|
96525
|
-
this.expandAllNodes();
|
|
96526
|
-
});
|
|
96527
|
-
}, 300);
|
|
98838
|
+
return new Set(CascaderUtilsPro.getLeafValues(this.searchOptions, this.cascaderProps));
|
|
96528
98839
|
},
|
|
96529
|
-
|
|
96530
|
-
const
|
|
96531
|
-
|
|
96532
|
-
|
|
96533
|
-
|
|
96534
|
-
|
|
96535
|
-
|
|
98840
|
+
syncSearchPanelSelection() {
|
|
98841
|
+
const searchPanel = this.$refs.searchCascaderPanel;
|
|
98842
|
+
const mainPanel = this.$refs.cascaderPanel;
|
|
98843
|
+
if (!searchPanel || !mainPanel || !searchPanel.selection || !mainPanel.selection) {
|
|
98844
|
+
return;
|
|
98845
|
+
}
|
|
98846
|
+
const searchLeafSet = this.getSearchLeafSet();
|
|
98847
|
+
searchPanel.selection.clear();
|
|
98848
|
+
mainPanel.selection.selectedLeafSet.forEach(leaf => {
|
|
98849
|
+
if (searchLeafSet.has(leaf)) {
|
|
98850
|
+
searchPanel.selection.selectedLeafSet.add(leaf);
|
|
96536
98851
|
}
|
|
96537
|
-
};
|
|
96538
|
-
|
|
98852
|
+
});
|
|
98853
|
+
searchPanel.selection._reconcileAllRoots();
|
|
98854
|
+
searchPanel.bumpSelectionView();
|
|
96539
98855
|
},
|
|
96540
|
-
|
|
96541
|
-
|
|
98856
|
+
// 搜索模式下的展开处理
|
|
98857
|
+
handleSearchExpand() {
|
|
98858
|
+
if (this.$refs.searchCascaderPanel && this.searchOptions.length > 0) {
|
|
98859
|
+
const firstOption = this.searchOptions[0];
|
|
98860
|
+
const valueKey = this.cascaderProps.value || 'value';
|
|
98861
|
+
this.$refs.searchCascaderPanel.expandPathValues([firstOption[valueKey]], true);
|
|
98862
|
+
}
|
|
96542
98863
|
},
|
|
96543
|
-
|
|
96544
|
-
|
|
96545
|
-
|
|
96546
|
-
|
|
96547
|
-
|
|
96548
|
-
|
|
98864
|
+
// 值变化处理
|
|
98865
|
+
handleValueChange() {
|
|
98866
|
+
this.applyPanelSelectionChange();
|
|
98867
|
+
},
|
|
98868
|
+
// 搜索模式值变化处理
|
|
98869
|
+
handleSearchValueChange() {
|
|
98870
|
+
const searchPanel = this.$refs.searchCascaderPanel;
|
|
98871
|
+
const mainPanel = this.$refs.cascaderPanel;
|
|
98872
|
+
if (!searchPanel || !mainPanel || !searchPanel.selection || !mainPanel.selection) {
|
|
98873
|
+
return;
|
|
96549
98874
|
}
|
|
96550
|
-
this.
|
|
96551
|
-
|
|
96552
|
-
|
|
98875
|
+
const searchLeafSet = this.getSearchLeafSet();
|
|
98876
|
+
searchLeafSet.forEach(leaf => {
|
|
98877
|
+
const shouldSelect = searchPanel.selection.selectedLeafSet.has(leaf);
|
|
98878
|
+
const isSelected = mainPanel.selection.selectedLeafSet.has(leaf);
|
|
98879
|
+
if (shouldSelect && !isSelected) {
|
|
98880
|
+
mainPanel.selection.selectedLeafSet.add(leaf);
|
|
98881
|
+
} else if (!shouldSelect && isSelected) {
|
|
98882
|
+
mainPanel.selection.selectedLeafSet.delete(leaf);
|
|
98883
|
+
}
|
|
98884
|
+
});
|
|
98885
|
+
mainPanel.selection._reconcileAllRoots();
|
|
98886
|
+
mainPanel.bumpSelectionView();
|
|
98887
|
+
this.applyPanelSelectionChange();
|
|
96553
98888
|
},
|
|
96554
|
-
|
|
96555
|
-
|
|
96556
|
-
|
|
96557
|
-
|
|
96558
|
-
|
|
96559
|
-
|
|
96560
|
-
|
|
96561
|
-
|
|
98889
|
+
// 移除已选项
|
|
98890
|
+
removeItem(item, index) {
|
|
98891
|
+
const panel = this.$refs.cascaderPanel;
|
|
98892
|
+
if (panel && panel.selection) {
|
|
98893
|
+
if (item.isAggregated) {
|
|
98894
|
+
const node = panel.store.nodeByValue.get(item.value);
|
|
98895
|
+
if (node) {
|
|
98896
|
+
panel.selection.toggleNode(node.id, false);
|
|
98897
|
+
}
|
|
98898
|
+
} else if (item.path && item.path.length > 0) {
|
|
98899
|
+
const leafValue = item.path[item.path.length - 1];
|
|
98900
|
+
const leafNode = panel.store.nodeByValue.get(leafValue);
|
|
98901
|
+
if (leafNode) {
|
|
98902
|
+
panel.selection.toggleNode(leafNode.id, false);
|
|
98903
|
+
} else {
|
|
98904
|
+
const node = panel.store.nodeByValue.get(item.value);
|
|
98905
|
+
if (node) {
|
|
98906
|
+
panel.selection.toggleNode(node.id, false);
|
|
98907
|
+
}
|
|
98908
|
+
}
|
|
98909
|
+
} else {
|
|
98910
|
+
const node = panel.store.nodeByValue.get(item.value);
|
|
98911
|
+
if (node) {
|
|
98912
|
+
panel.selection.toggleNode(node.id, false);
|
|
98913
|
+
}
|
|
96562
98914
|
}
|
|
98915
|
+
this.applyPanelSelectionChange();
|
|
98916
|
+
if (this.isShowSearch) {
|
|
98917
|
+
this.syncSearchPanelSelection();
|
|
98918
|
+
}
|
|
98919
|
+
return;
|
|
96563
98920
|
}
|
|
96564
|
-
|
|
96565
|
-
this.
|
|
96566
|
-
|
|
96567
|
-
|
|
96568
|
-
this.
|
|
96569
|
-
|
|
96570
|
-
|
|
96571
|
-
this.
|
|
96572
|
-
},
|
|
96573
|
-
emitInput() {
|
|
98921
|
+
const valueToRemove = item.value;
|
|
98922
|
+
this.selectedValues = this.selectedValues.filter(path => {
|
|
98923
|
+
return !path.includes(valueToRemove);
|
|
98924
|
+
});
|
|
98925
|
+
this.searchSelectedValues = this.searchSelectedValues.filter(path => {
|
|
98926
|
+
return !path.includes(valueToRemove);
|
|
98927
|
+
});
|
|
98928
|
+
this.selectedItems.splice(index, 1);
|
|
96574
98929
|
this.$nextTick(() => {
|
|
96575
98930
|
this.isInternalUpdate = true;
|
|
96576
98931
|
let emitValue = this.currentValue;
|
|
96577
98932
|
if (this.aggregationMode) {
|
|
96578
|
-
emitValue =
|
|
98933
|
+
emitValue = CascaderUtilsPro.getAggregatedEmitValues(this.selectedItems, this.parentNodePrefix);
|
|
96579
98934
|
if (!this.isMultiple && emitValue.length > 0) {
|
|
96580
98935
|
emitValue = emitValue[0];
|
|
96581
98936
|
}
|
|
@@ -96583,12 +98938,43 @@ var ByTreePanelvue_type_template_id_af06ba0a_staticRenderFns = [];
|
|
|
96583
98938
|
this.$emit('input', emitValue);
|
|
96584
98939
|
});
|
|
96585
98940
|
},
|
|
98941
|
+
// 全选/取消全选
|
|
98942
|
+
handleSelectAll() {
|
|
98943
|
+
if (!this.isMultiple) {
|
|
98944
|
+
// 单选模式下不支持全选
|
|
98945
|
+
return;
|
|
98946
|
+
}
|
|
98947
|
+
if (this.isAllSelected) {
|
|
98948
|
+
const panel = this.$refs.cascaderPanel;
|
|
98949
|
+
if (panel) {
|
|
98950
|
+
panel.clearCheckedNodes();
|
|
98951
|
+
} else {
|
|
98952
|
+
this.selectedValues = [];
|
|
98953
|
+
this.selectedItems = [];
|
|
98954
|
+
this.searchSelectedValues = [];
|
|
98955
|
+
this.applyPanelSelectionChange();
|
|
98956
|
+
}
|
|
98957
|
+
} else {
|
|
98958
|
+
const panel = this.$refs.cascaderPanel;
|
|
98959
|
+
if (panel) {
|
|
98960
|
+
panel.selectAllLeaves();
|
|
98961
|
+
} else {
|
|
98962
|
+
this.selectedValues = CascaderUtilsPro.getAllLeafPaths(this.filteredOptions, this.disabledConfig, this.cascaderProps);
|
|
98963
|
+
this.updateSelectedItems();
|
|
98964
|
+
this.applyPanelSelectionChange();
|
|
98965
|
+
}
|
|
98966
|
+
}
|
|
98967
|
+
},
|
|
98968
|
+
// 获取选中的数据
|
|
96586
98969
|
getSelectedData() {
|
|
96587
98970
|
let values = this.currentValue;
|
|
96588
98971
|
let valuesPath = this.selectedValues;
|
|
98972
|
+
if (!this.aggregationMode && this.selectedItems.length > 0 && valuesPath.length === 0) {
|
|
98973
|
+
valuesPath = this.selectedItems.map(item => item.path);
|
|
98974
|
+
}
|
|
96589
98975
|
if (this.aggregationMode) {
|
|
96590
|
-
values =
|
|
96591
|
-
valuesPath =
|
|
98976
|
+
values = CascaderUtilsPro.getAggregatedEmitValues(this.selectedItems, this.parentNodePrefix);
|
|
98977
|
+
valuesPath = this.selectedItems.map(item => item.path);
|
|
96592
98978
|
if (!this.isMultiple && values.length > 0) {
|
|
96593
98979
|
values = values[0];
|
|
96594
98980
|
}
|
|
@@ -96600,102 +98986,208 @@ var ByTreePanelvue_type_template_id_af06ba0a_staticRenderFns = [];
|
|
|
96600
98986
|
count: this.selectedItems.length
|
|
96601
98987
|
};
|
|
96602
98988
|
},
|
|
98989
|
+
// 清空选择
|
|
98990
|
+
clearSelection() {
|
|
98991
|
+
const panel = this.$refs.cascaderPanel;
|
|
98992
|
+
if (panel) {
|
|
98993
|
+
panel.clearCheckedNodes();
|
|
98994
|
+
} else {
|
|
98995
|
+
this.selectedValues = [];
|
|
98996
|
+
this.selectedItems = [];
|
|
98997
|
+
this.searchSelectedValues = [];
|
|
98998
|
+
this.applyPanelSelectionChange();
|
|
98999
|
+
}
|
|
99000
|
+
},
|
|
99001
|
+
// 设置选择值
|
|
96603
99002
|
setValue(values) {
|
|
96604
99003
|
if (this.isMultiple) {
|
|
99004
|
+
// 多选模式:支持直接传入value值或路径数组
|
|
96605
99005
|
if (Array.isArray(values) && values.length > 0) {
|
|
96606
99006
|
if (typeof values[0] === 'string' || typeof values[0] === 'number') {
|
|
99007
|
+
// 传入的是value值数组,需要转换为路径
|
|
96607
99008
|
if (this.aggregationMode) {
|
|
96608
|
-
|
|
99009
|
+
// 聚合模式下,支持非叶子节点标识
|
|
99010
|
+
this.selectedValues = CascaderUtilsPro.processValuesWithParentNodes(values, this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
96609
99011
|
} else {
|
|
96610
|
-
|
|
99012
|
+
// 普通模式下,只处理叶子节点
|
|
99013
|
+
this.selectedValues = this.findPathsByValues(values);
|
|
96611
99014
|
}
|
|
96612
99015
|
} else {
|
|
99016
|
+
// 传入的是路径数组
|
|
96613
99017
|
this.selectedValues = [...values];
|
|
96614
99018
|
}
|
|
96615
99019
|
} else {
|
|
96616
99020
|
this.selectedValues = [];
|
|
96617
99021
|
}
|
|
96618
|
-
} else
|
|
96619
|
-
|
|
96620
|
-
|
|
96621
|
-
|
|
96622
|
-
|
|
99022
|
+
} else {
|
|
99023
|
+
// 单选模式:支持单个值或路径数组
|
|
99024
|
+
if (values !== null && values !== undefined && values !== '') {
|
|
99025
|
+
if (Array.isArray(values)) {
|
|
99026
|
+
// 传入的是路径数组
|
|
99027
|
+
this.selectedValues = [...values];
|
|
99028
|
+
} else {
|
|
99029
|
+
// 传入的是单个值,需要转换为路径
|
|
99030
|
+
if (this.aggregationMode) {
|
|
99031
|
+
// 聚合模式下,支持非叶子节点标识
|
|
99032
|
+
this.selectedValues = CascaderUtilsPro.processValuesWithParentNodes([values], this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
99033
|
+
} else {
|
|
99034
|
+
// 普通模式下,只处理叶子节点
|
|
99035
|
+
this.selectedValues = this.findPathsByValues([values]);
|
|
99036
|
+
}
|
|
99037
|
+
}
|
|
96623
99038
|
} else {
|
|
96624
|
-
this.selectedValues =
|
|
99039
|
+
this.selectedValues = [];
|
|
96625
99040
|
}
|
|
96626
|
-
} else {
|
|
96627
|
-
this.selectedValues = [];
|
|
96628
99041
|
}
|
|
96629
|
-
this.syncTreeCheckedState();
|
|
96630
99042
|
this.updateSelectedItems();
|
|
96631
99043
|
},
|
|
99044
|
+
// 根据values找到对应的路径
|
|
99045
|
+
findPathsByValues(values) {
|
|
99046
|
+
const paths = [];
|
|
99047
|
+
const findPath = (options, targetValues, currentPath = []) => {
|
|
99048
|
+
for (const option of options) {
|
|
99049
|
+
const newPath = [...currentPath, option[this.cascaderProps.value]];
|
|
99050
|
+
if (targetValues.includes(option[this.cascaderProps.value])) {
|
|
99051
|
+
// 如果是叶子节点(没有children属性),添加到路径中
|
|
99052
|
+
if (!option[this.cascaderProps.children]) {
|
|
99053
|
+
paths.push(newPath);
|
|
99054
|
+
}
|
|
99055
|
+
}
|
|
99056
|
+
|
|
99057
|
+
// 递归查找子节点
|
|
99058
|
+
if (option[this.cascaderProps.children] && option[this.cascaderProps.children].length > 0) {
|
|
99059
|
+
findPath(option[this.cascaderProps.children], targetValues, newPath);
|
|
99060
|
+
}
|
|
99061
|
+
}
|
|
99062
|
+
};
|
|
99063
|
+
|
|
99064
|
+
// 使用 filteredOptions 如果存在,否则使用原始 options
|
|
99065
|
+
const optionsToSearch = this.filteredOptions.length > 0 ? this.filteredOptions : this.options;
|
|
99066
|
+
findPath(optionsToSearch, values);
|
|
99067
|
+
return paths;
|
|
99068
|
+
},
|
|
99069
|
+
// 处理批量搜索弹窗显示
|
|
96632
99070
|
handleBatchSearchShow() {
|
|
96633
99071
|
if (this.searchInput) {
|
|
96634
99072
|
this.searchInput = '';
|
|
96635
|
-
this.displayOptions = this.filteredOptions;
|
|
96636
99073
|
}
|
|
96637
99074
|
},
|
|
99075
|
+
// 处理批量搜索
|
|
96638
99076
|
handleBatchSearch() {
|
|
96639
99077
|
if (!this.batchSearchContent.trim()) {
|
|
96640
99078
|
this.batchSearchVisible = false;
|
|
96641
99079
|
return;
|
|
96642
99080
|
}
|
|
99081
|
+
|
|
99082
|
+
// 分割输入内容(支持换行、逗号、分号等分隔符)
|
|
96643
99083
|
const inputNames = this.batchSearchContent.split(/[\n,;,;\s]+/).filter(item => item.trim()).map(item => item.trim());
|
|
96644
99084
|
if (inputNames.length === 0) {
|
|
96645
99085
|
this.batchSearchVisible = false;
|
|
96646
99086
|
return;
|
|
96647
99087
|
}
|
|
96648
|
-
|
|
99088
|
+
|
|
99089
|
+
// 在级联数据中搜索匹配的名称
|
|
99090
|
+
const matchedPaths = this.searchNamesInCascader(inputNames);
|
|
96649
99091
|
if (matchedPaths.length > 0) {
|
|
96650
|
-
const
|
|
96651
|
-
|
|
96652
|
-
|
|
96653
|
-
|
|
96654
|
-
|
|
96655
|
-
|
|
96656
|
-
|
|
96657
|
-
|
|
96658
|
-
|
|
96659
|
-
|
|
96660
|
-
|
|
99092
|
+
const panel = this.$refs.cascaderPanel;
|
|
99093
|
+
if (panel && panel.selection && panel.store) {
|
|
99094
|
+
matchedPaths.forEach(path => {
|
|
99095
|
+
const leafValue = path[path.length - 1];
|
|
99096
|
+
if (panel.store.pathByLeafValue.has(leafValue)) {
|
|
99097
|
+
panel.selection.selectedLeafSet.add(leafValue);
|
|
99098
|
+
}
|
|
99099
|
+
});
|
|
99100
|
+
panel.selection._reconcileAllRoots();
|
|
99101
|
+
panel.bumpSelectionView();
|
|
99102
|
+
this.applyPanelSelectionChange();
|
|
99103
|
+
} else {
|
|
99104
|
+
const newSelectedValues = [...this.selectedValues];
|
|
99105
|
+
matchedPaths.forEach(path => {
|
|
99106
|
+
const exists = newSelectedValues.some(existingPath => existingPath.length === path.length && existingPath.every((value, index) => value === path[index]));
|
|
99107
|
+
if (!exists) {
|
|
99108
|
+
newSelectedValues.push(path);
|
|
99109
|
+
}
|
|
99110
|
+
});
|
|
99111
|
+
this.selectedValues = newSelectedValues;
|
|
99112
|
+
this.updateSelectedItems();
|
|
99113
|
+
this.$nextTick(() => {
|
|
99114
|
+
this.isInternalUpdate = true;
|
|
99115
|
+
let emitValue = this.currentValue;
|
|
99116
|
+
if (this.aggregationMode) {
|
|
99117
|
+
emitValue = CascaderUtilsPro.getAggregatedSelectedValues(this.selectedValues, this.filteredOptions, this.cascaderProps, this.parentNodePrefix);
|
|
99118
|
+
if (!this.isMultiple && emitValue.length > 0) {
|
|
99119
|
+
emitValue = emitValue[0];
|
|
99120
|
+
}
|
|
99121
|
+
}
|
|
99122
|
+
this.$emit('input', emitValue);
|
|
99123
|
+
});
|
|
99124
|
+
}
|
|
96661
99125
|
}
|
|
99126
|
+
|
|
99127
|
+
// 关闭弹窗并清空内容
|
|
96662
99128
|
this.batchSearchVisible = false;
|
|
96663
99129
|
this.batchSearchContent = '';
|
|
96664
99130
|
},
|
|
96665
|
-
|
|
99131
|
+
// 在级联数据中搜索匹配的名称(全匹配,忽略空格,排除禁用项)
|
|
99132
|
+
searchNamesInCascader(names) {
|
|
96666
99133
|
const matchedPaths = [];
|
|
99134
|
+
const labelKey = this.cascaderProps.label || 'label';
|
|
96667
99135
|
const searchInOptions = (options, currentPath = []) => {
|
|
96668
99136
|
for (const option of options) {
|
|
96669
|
-
const newPath = [...currentPath, option[this.
|
|
96670
|
-
const optionLabel = String(option[
|
|
99137
|
+
const newPath = [...currentPath, option[this.cascaderProps.value]];
|
|
99138
|
+
const optionLabel = String(option[labelKey] || '').replace(/\s+/g, ''); // 去掉所有空格
|
|
99139
|
+
|
|
99140
|
+
// 检查是否全匹配任何输入的名称(去掉空格后比较)
|
|
96671
99141
|
const isMatched = names.some(name => {
|
|
96672
|
-
const cleanName = name.replace(/\s+/g, '');
|
|
99142
|
+
const cleanName = name.replace(/\s+/g, ''); // 去掉输入名称中的空格
|
|
96673
99143
|
return optionLabel.toLowerCase() === cleanName.toLowerCase();
|
|
96674
99144
|
});
|
|
96675
|
-
|
|
96676
|
-
|
|
99145
|
+
|
|
99146
|
+
// 检查是否为叶子节点且匹配且未禁用
|
|
99147
|
+
const isLeafNode = !option[this.cascaderProps.children];
|
|
99148
|
+
const isNotDisabled = !this.isItemDisabled(option);
|
|
96677
99149
|
if (isMatched && isLeafNode && isNotDisabled) {
|
|
99150
|
+
// 如果是叶子节点、匹配且未禁用,添加到结果中
|
|
96678
99151
|
matchedPaths.push(newPath);
|
|
96679
99152
|
}
|
|
96680
|
-
|
|
96681
|
-
|
|
99153
|
+
|
|
99154
|
+
// 递归搜索子节点
|
|
99155
|
+
if (option[this.cascaderProps.children] && option[this.cascaderProps.children].length > 0) {
|
|
99156
|
+
searchInOptions(option[this.cascaderProps.children], newPath);
|
|
96682
99157
|
}
|
|
96683
99158
|
}
|
|
96684
99159
|
};
|
|
96685
99160
|
searchInOptions(this.filteredOptions);
|
|
96686
99161
|
return matchedPaths;
|
|
96687
99162
|
},
|
|
96688
|
-
|
|
96689
|
-
|
|
96690
|
-
|
|
96691
|
-
|
|
96692
|
-
|
|
99163
|
+
// 强制调整已选项的垂直居中样式
|
|
99164
|
+
forceVerticalCenter() {
|
|
99165
|
+
this.$nextTick(() => {
|
|
99166
|
+
const itemLabels = this.$el.querySelectorAll('.item-label');
|
|
99167
|
+
itemLabels.forEach(label => {
|
|
99168
|
+
if (label) {
|
|
99169
|
+
// 使用JavaScript强制设置样式
|
|
99170
|
+
label.style.setProperty('display', 'flex', 'important');
|
|
99171
|
+
label.style.setProperty('align-items', 'center', 'important');
|
|
99172
|
+
label.style.setProperty('height', '36px', 'important');
|
|
99173
|
+
label.style.setProperty('line-height', '36px', 'important');
|
|
99174
|
+
label.style.setProperty('margin', '0', 'important');
|
|
99175
|
+
label.style.setProperty('padding', '0', 'important');
|
|
99176
|
+
label.style.setProperty('vertical-align', 'middle', 'important');
|
|
99177
|
+
label.style.setProperty('font-size', '14px', 'important');
|
|
99178
|
+
}
|
|
99179
|
+
});
|
|
99180
|
+
});
|
|
96693
99181
|
}
|
|
99182
|
+
},
|
|
99183
|
+
updated() {
|
|
99184
|
+
// 组件更新后强制调整样式
|
|
99185
|
+
this.forceVerticalCenter();
|
|
96694
99186
|
}
|
|
96695
99187
|
});
|
|
96696
|
-
;// ./src/components/
|
|
96697
|
-
/* harmony default export */ var
|
|
96698
|
-
;// ./src/components/
|
|
99188
|
+
;// ./src/components/cascader-panel-pro/ByCascaderPanelPro.vue?vue&type=script&lang=js
|
|
99189
|
+
/* harmony default export */ var cascader_panel_pro_ByCascaderPanelProvue_type_script_lang_js = (ByCascaderPanelProvue_type_script_lang_js);
|
|
99190
|
+
;// ./src/components/cascader-panel-pro/ByCascaderPanelPro.vue
|
|
96699
99191
|
|
|
96700
99192
|
|
|
96701
99193
|
|
|
@@ -96703,10 +99195,10 @@ var ByTreePanelvue_type_template_id_af06ba0a_staticRenderFns = [];
|
|
|
96703
99195
|
|
|
96704
99196
|
/* normalize component */
|
|
96705
99197
|
;
|
|
96706
|
-
var
|
|
96707
|
-
|
|
96708
|
-
|
|
96709
|
-
|
|
99198
|
+
var ByCascaderPanelPro_component = normalizeComponent(
|
|
99199
|
+
cascader_panel_pro_ByCascaderPanelProvue_type_script_lang_js,
|
|
99200
|
+
ByCascaderPanelProvue_type_template_id_4bdb9820_render,
|
|
99201
|
+
ByCascaderPanelProvue_type_template_id_4bdb9820_staticRenderFns,
|
|
96710
99202
|
false,
|
|
96711
99203
|
null,
|
|
96712
99204
|
null,
|
|
@@ -96714,7 +99206,7 @@ var ByTreePanel_component = normalizeComponent(
|
|
|
96714
99206
|
|
|
96715
99207
|
)
|
|
96716
99208
|
|
|
96717
|
-
/* harmony default export */ var
|
|
99209
|
+
/* harmony default export */ var ByCascaderPanelPro = (ByCascaderPanelPro_component.exports);
|
|
96718
99210
|
;// ./node_modules/cache-loader/dist/cjs.js?{"cacheDirectory":"node_modules/.cache/vue-loader","cacheIdentifier":"8cd600e8-vue-loader-template"}!./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[1]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/loaders/templateLoader.js??ruleSet[1].rules[3]!./node_modules/cache-loader/dist/cjs.js??ruleSet[0].use[0]!./node_modules/@vue/cli-service/node_modules/@vue/vue-loader-v15/lib/index.js??vue-loader-options!./src/components/floating-menu/ByFloatingMenu.vue?vue&type=template&id=04723f13
|
|
96719
99211
|
var ByFloatingMenuvue_type_template_id_04723f13_render = function render() {
|
|
96720
99212
|
var _vm = this,
|
|
@@ -99428,7 +101920,7 @@ const components = {
|
|
|
99428
101920
|
ByTreeSearch: ByTreeSearch,
|
|
99429
101921
|
ByDialog: ByDialog,
|
|
99430
101922
|
ByCascaderPanel: ByCascaderPanel,
|
|
99431
|
-
|
|
101923
|
+
ByCascaderPanelPro: ByCascaderPanelPro,
|
|
99432
101924
|
ByFloatingMenu: ByFloatingMenu,
|
|
99433
101925
|
ByPopoverSelector: ByPopoverSelector,
|
|
99434
101926
|
ByGridLayout: ByGridLayout,
|