@netang/quasar 0.1.89 → 0.1.91

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.
@@ -277,11 +277,11 @@ export default {
277
277
  query: Object,
278
278
  // 附加请求数据
279
279
  data: Object,
280
- // 初始加载已选数据数组
280
+ // 加载已选数据数组
281
281
  // 如果有数组数据, 则初始化时从数组中选取已有的数据
282
- defaultLoadSelected: Array,
282
+ loadSelected: [Array, Function],
283
283
  // 初始是否不加载已选数据
284
- // true, 则初始时不加载数据(同时 defaultLoadSelected 无效)
284
+ // true, 则初始时不加载数据(同时 loadSelected 无效)
285
285
  noDefaultLoadSelected: Boolean,
286
286
  // 更新值时不加载已选数据
287
287
  noUpdateLoadSelected: Boolean,
@@ -503,7 +503,7 @@ export default {
503
503
  // 加载已选数据
504
504
  if (
505
505
  ! props.noDefaultLoadSelected
506
- && props.defaultLoadSelected === void 0
506
+ && props.loadSelected === void 0
507
507
  ) {
508
508
  loadSelected()
509
509
  .finally()
@@ -783,9 +783,8 @@ export default {
783
783
  isFirst
784
784
  // 如果初始加载已选数据方法
785
785
  && ! props.noDefaultLoadSelected
786
- // 如果有初始加载已选数据数组
787
- && props.defaultLoadSelected !== void 0
788
- && $n_isValidArray(props.defaultLoadSelected)
786
+ // 如果有初始加载已选数据
787
+ && props.loadSelected !== void 0
789
788
  ) {
790
789
  // 将值转为数组
791
790
  val = props.valueType === 'string' ? $n_split(val, props.valueSeparator) : val
@@ -794,19 +793,10 @@ export default {
794
793
  if ($n_isValidArray(val)) {
795
794
  val = val.filter(e => $n_isValidValue(e))
796
795
  if (val.length) {
797
- const _selected = []
798
- for (const item of props.defaultLoadSelected) {
799
- if (
800
- $n_has(item, props.valueKey)
801
- && $n_indexOf(val, item[props.valueKey]) > -1
802
- ) {
803
- _selected.push($n_cloneDeep(item))
804
- }
805
- }
806
-
807
- return _selected
796
+ return onLoadSelected(val, isFirst)
808
797
  }
809
798
  }
799
+ return []
810
800
  }
811
801
 
812
802
  if (
@@ -866,11 +856,69 @@ export default {
866
856
  return $n_numberDeep($n_join(values, props.valueSeparator))
867
857
  }
868
858
 
859
+ /**
860
+ * 加载已选数据
861
+ */
862
+ function onLoadSelected(values, isFirst) {
863
+
864
+ function next(lists) {
865
+ const _selected = []
866
+ $n_forEach(lists, function (item) {
867
+ if (
868
+ $n_has(item, props.valueKey)
869
+ && $n_indexOf(values, item[props.valueKey]) > -1
870
+ ) {
871
+ _selected.push($n_cloneDeep(item))
872
+ }
873
+ })
874
+ return _selected
875
+ }
876
+
877
+ // 如果是加载已选数据方法
878
+ if ($n_isFunction(props.loadSelected)) {
879
+ const res = props.loadSelected(values, next, isFirst)
880
+ if ($n_isValidArray(res)) {
881
+ return res
882
+ }
883
+ return []
884
+ }
885
+
886
+ return next(props.loadSelected)
887
+ }
888
+
869
889
  /**
870
890
  * 请求选择数据
871
891
  */
872
892
  async function onRequestSelected(value) {
873
893
 
894
+ let requestValues = value
895
+
896
+ const all = {}
897
+ let hasAll = false
898
+
899
+ // 如果有初始加载已选数据数组
900
+ if (props.loadSelected !== void 0) {
901
+ const rows = onLoadSelected(value, false)
902
+ if ($n.isValidArray(rows)) {
903
+
904
+ requestValues = []
905
+
906
+ for (const item of rows) {
907
+ all[item[props.valueKey]] = item
908
+ }
909
+ for (const val of value) {
910
+ if (! $n_has(all, val)) {
911
+ requestValues.push(val)
912
+ }
913
+ }
914
+ if (! requestValues.length) {
915
+ return rows
916
+ }
917
+
918
+ hasAll = true
919
+ }
920
+ }
921
+
874
922
  // 请求参数
875
923
  const httpOptions = {
876
924
  url: $table.routePath,
@@ -895,7 +943,7 @@ export default {
895
943
  // 查看字段
896
944
  field: props.valueKey,
897
945
  // 查看值
898
- value,
946
+ value: requestValues,
899
947
  },
900
948
  }
901
949
  ),
@@ -915,7 +963,24 @@ export default {
915
963
  // 否则请求数据
916
964
  await $n_http(httpOptions)
917
965
 
918
- return status && $n_isValidArray($n_get(data, 'rows')) ? data.rows : []
966
+ if (status) {
967
+ if ($n_isValidArray($n_get(data, 'rows'))) {
968
+ if (! hasAll) {
969
+ return data.rows
970
+ }
971
+ for (const item of data.rows) {
972
+ all[item[props.valueKey]] = item
973
+ }
974
+ }
975
+ }
976
+
977
+ const newRows = []
978
+ for (const val of value) {
979
+ if ($n_has(all, val)) {
980
+ newRows.push(all[val])
981
+ }
982
+ }
983
+ return newRows
919
984
  }
920
985
 
921
986
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netang/quasar",
3
- "version": "0.1.89",
3
+ "version": "0.1.91",
4
4
  "description": "netang-quasar",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/utils/$tree.js CHANGED
@@ -573,23 +573,41 @@ function create(options) {
573
573
  let dropIndex = $n_findIndex(children, e => e.id === draggingNode.id)
574
574
  if (dropIndex > -1) {
575
575
 
576
- if (
577
- // 如果拖拽到目标节点下方
578
- dropType === 'bottom'
579
- // 并且拖拽节点当前的位置不是第一个
580
- && dropIndex > 0
581
- ) {
582
- dropIndex--
583
- }
584
-
585
- for (let i = dropIndex; i < children.length; i++) {
576
+ // if (
577
+ // // 如果拖拽到目标节点下方
578
+ // dropType === 'bottom'
579
+ // // 并且拖拽节点当前的位置不是第一个
580
+ // && dropIndex > 0
581
+ // ) {
582
+ // dropIndex--
583
+ // }
584
+ // for (let i = dropIndex; i < children.length; i++) {
585
+ // const { attr } = children[i]
586
+ // attr.sort = i + 1
587
+ // moveLists.push({
588
+ // id: attr.id,
589
+ // pid: attr.pid,
590
+ // sort: attr.sort,
591
+ // })
592
+ // }
593
+
594
+ for (let i = 0, len = children.length; i < len; i++) {
586
595
  const { attr } = children[i]
587
- attr.sort = i + 1
588
- moveLists.push({
589
- id: attr.id,
590
- pid: attr.pid,
591
- sort: attr.sort,
592
- })
596
+
597
+ // 新排序号
598
+ const newSort = i + 1
599
+
600
+ if (
601
+ i >= dropIndex
602
+ || newSort !== attr.sort
603
+ ) {
604
+ attr.sort = newSort
605
+ moveLists.push({
606
+ id: attr.id,
607
+ pid: attr.pid,
608
+ sort: attr.sort,
609
+ })
610
+ }
593
611
  }
594
612
 
595
613
  // 如果有移动列表