n20-project-component 1.0.5 → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n20-project-component",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "PC 端 Vue 2 + Element UI 组件库",
5
5
  "main": "dist/n20-project-component.umd.min.js",
6
6
  "module": "dist/n20-project-component.common.js",
@@ -529,7 +529,11 @@ export default {
529
529
  resolve({ code: 500 }) // 返回一个成功状态的 Promise
530
530
  return
531
531
  }
532
-
532
+
533
+ let _data = JSON.parse(JSON.stringify(data))
534
+ _data.forEach((item) => {
535
+ if(this.optionsMap[item[this.onlyKey]]) item.options = []
536
+ })
533
537
  axios
534
538
  .post(
535
539
  `/bems/prod_1.0/user/pageHabit?t=${Date.now()}`,
@@ -143,7 +143,7 @@
143
143
  :name="filter.slotName"
144
144
  :model="model"
145
145
  :value="searchForm[filter.value]"
146
- :input="val => (searchForm[filter.value] = val)"
146
+ :input="val => $set(searchForm, filter.value, val)"
147
147
  ></slot>
148
148
  <!-- 无 value 的 slot(如 startDate/endDate 多值绑定),传递 searchForm 让父组件自行管理 -->
149
149
  <slot
@@ -262,17 +262,18 @@ export default {
262
262
  },
263
263
  filterObj() {
264
264
  // 合并 slot 类型筛选器的值(来自 initialValue)到 searchValue 中
265
+ // 注意:searchValue 优先级高于 slotValues,避免用户已选值被初始值覆盖
265
266
  const slotValues = {};
266
267
  this.filterList
267
268
  .filter(item => item.type === 'slot' && item.value)
268
269
  .forEach(item => {
269
270
  if (this.initialValue && this.initialValue[item.value] !== undefined) {
270
- slotValues[item.value] = this.initialValue[item.value];
271
+ slotValues[item.value] = JSON.parse(JSON.stringify(this.initialValue[item.value]));
271
272
  }
272
273
  });
273
274
  return {
274
- // 筛选条件(合并 slot 类型的值)
275
- searchValue: { ...this.searchValue, ...slotValues },
275
+ // 筛选条件:slotValues 兜底,searchValue 优先级更高
276
+ searchValue: { ...slotValues, ...this.searchValue },
276
277
  // 视图id
277
278
  viewId: this.selectItem ? this.selectItem.viewId : null,
278
279
  };
@@ -280,11 +281,13 @@ export default {
280
281
  },
281
282
  watch: {
282
283
  initialValue: {
283
- handler(newVal) {
284
+ handler(newVal, oldVal) {
284
285
  if (!newVal) return;
285
-
286
+ // 深度比较,避免引用变化但值相同时误触发重置
287
+ if (JSON.stringify(newVal) === JSON.stringify(oldVal)) return;
288
+
286
289
  // 浅拷贝,避免修改 searchValue 时污染外部 initialValue
287
- this.searchValue = { ...newVal };
290
+ this.searchValue = JSON.parse(JSON.stringify(newVal));
288
291
  },
289
292
  deep: true,
290
293
  immediate: false,
@@ -306,17 +309,17 @@ export default {
306
309
  this.getFilterList();
307
310
  }
308
311
  // 合并初始筛选值:slot 字段使用默认值,其他字段使用 initialValue 传入的值
309
- this.searchValue = { ...this.getInitialSearchValue, ...this.initialValue };
312
+ this.searchValue = { ...this.getInitialSearchValue, ...JSON.parse(JSON.stringify(this.initialValue || {})) };
310
313
  },
311
314
  methods: {
312
- // 处理 slot 类型字段的输入事件,同时更新 searchValue 和 initialValue
315
+ // 处理 slot 类型字段的输入事件,同时更新 searchValue
313
316
  handleSlotInput(fieldName, val) {
314
317
  // 防御性检查:如果 fieldName 无效,不执行任何操作
315
318
  if (!fieldName) return;
316
319
  // 更新 searchValue
317
- this.searchValue[fieldName] = val;
318
- // 同步更新 initialValue,确保双向绑定生效
319
- this.$set(this.initialValue, fieldName, val);
320
+ this.$set(this.searchValue, fieldName, val);
321
+ // 值改变时实时同步到父组件(不刷新数据)
322
+ this.$emit('filter', this.filterObj, 'change');
320
323
  },
321
324
  handleCommand(command, item) {
322
325
  const commandMap = {
@@ -349,12 +352,15 @@ export default {
349
352
  };
350
353
  }
351
354
  this.$emit('changeFn', obj);
355
+ // 值改变时实时同步到父组件(不刷新数据)
356
+ this.$emit('filter', this.filterObj, 'change');
352
357
  },
353
358
  filterFn() {
354
359
  this.$emit('filter', this.filterObj, 'filter');
355
360
  },
356
361
  handleClean() {
357
- this.$emit('filter', this.filterObj, 'clean');
362
+ // 统一走 change 类型,父组件无需单独处理 clean
363
+ this.$emit('filter', this.filterObj, 'change');
358
364
  },
359
365
  handleClear() {
360
366
  // 收集不需要清空的字段 key(required / isNotClose / initialValue 中的额外 key)
@@ -440,6 +446,8 @@ export default {
440
446
  },
441
447
  // 新增
442
448
  add() {
449
+ let keyIds = this.filterList.filter(v => v.required).map(v => v.id);
450
+
443
451
  this.isRefresh = false;
444
452
  this.viewPopoverVisible = false;
445
453
  this.visible = true;
@@ -447,7 +455,7 @@ export default {
447
455
  this.form = {
448
456
  userNo: sessionStorage.getItem('userNo'),
449
457
  pageNo: this.filterId,
450
- keyIds: [],
458
+ keyIds: keyIds || [],
451
459
  };
452
460
  this.viewId = undefined;
453
461
  this.searchForm = {
@@ -544,7 +552,7 @@ export default {
544
552
  this.selectedItem = item.viewName;
545
553
  if (item.viewName === '无视图') {
546
554
  this.selectItem = '';
547
- this.searchValue = { ...this.getInitialSearchValue, ...this.initialValue };
555
+ this.searchValue = { ...this.getInitialSearchValue, ...JSON.parse(JSON.stringify(this.initialValue || {})) };
548
556
  // 无视图时恢复原来的筛选逻辑
549
557
  this.$nextTick(() => {
550
558
  const filterRef = this.$refs.filter;
@@ -559,6 +567,7 @@ export default {
559
567
  } else {
560
568
  const config = this.safeParse(item.viewConfig);
561
569
  this.searchForm = config;
570
+
562
571
  this.searchValue = config;
563
572
  // 按视图保存的 keyIds 更新展示字段
564
573
  this.$nextTick(() => {
@@ -610,7 +619,7 @@ export default {
610
619
  this.searchKeyword = '';
611
620
  this.selectedItem = '无视图';
612
621
  this.selectItem = '';
613
- this.searchValue = { ...this.getInitialSearchValue, ...this.initialValue };
622
+ this.searchValue = { ...this.getInitialSearchValue, ...JSON.parse(JSON.stringify(this.initialValue || {})) };
614
623
  this.searchForm = { ...this.getInitialSearchValue };
615
624
  this.filterExpanded = this.defaultExpanded;
616
625
  this.viewId = undefined;