@94ai/nf-table 3.2.47 → 3.2.49

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.
@@ -468,7 +468,7 @@
468
468
  v-if="nfColumCheckDialogVisible && checkMode === 'dialog'"
469
469
  :show.sync="nfColumCheckDialogVisible"
470
470
  :table-columns="columns"
471
- :show-column="localShowColumn"
471
+ :column-edit="columnEdit"
472
472
  :storage-key="storageKey"
473
473
  @save="fieldsConfirm"
474
474
  :title="columnCheckTitle"
@@ -489,6 +489,7 @@
489
489
  :center="columnCheckCenter"
490
490
  :destroy-on-close="columnCheckDestroyOnClose"
491
491
  ref="columnCheckDialog"
492
+ :operation-prop-key="operationPropKey"
492
493
  >
493
494
  <slot slot="tableColumnEditDialogTitle" name="title"></slot>
494
495
  <slot slot="tableColumnEditDialogFooter" name="footer"></slot>
@@ -515,6 +516,7 @@
515
516
  :fixed-left-desc="columnCheckFixedLeftDesc"
516
517
  :clear-desc="columnCheckClearDesc"
517
518
  :no-fixed-desc="columnCheckNoFixedDesc"
519
+ :column-edit="columnEdit"
518
520
  :get-checked-length-desc="columnCheckGetCheckedLengthDesc"
519
521
  :get-all-check-desc="columnCheckGetAllCheckDesc"
520
522
  :operation-prop-key="operationPropKey"
@@ -547,7 +549,8 @@ import {
547
549
  onMounted,
548
550
  onBeforeMount,
549
551
  ref,
550
- watch
552
+ watch,
553
+ set
551
554
  } from 'vue-demi'
552
555
  import {
553
556
  NfTableColumnAttributes,
@@ -561,6 +564,7 @@ import {
561
564
  NfTableActionBtnAttributes
562
565
  } from './types'
563
566
  import { ITabItem } from '@94ai/nf-drawer/lib/types'
567
+ import { CachedManager } from '@94ai/common-utils'
564
568
 
565
569
  const props = withDefaults(defineProps<{
566
570
  data?: Record<string, any>[],
@@ -803,8 +807,10 @@ watch(() => {
803
807
  immediate: true
804
808
  })
805
809
  // 同步用户参数
806
- const initLocalShow = () => {
807
- props.columns._skip = true
810
+ const initLocalShow = (init = false) => {
811
+ if (!init) {
812
+ props.columns._skip = true
813
+ }
808
814
  const result = props.columns.filter(item => {
809
815
  const prop = item.prop || item.attr?.prop
810
816
  if (props.showColumn?.includes(prop!)) {
@@ -812,13 +818,17 @@ const initLocalShow = () => {
812
818
  }
813
819
  return !item.initHidden
814
820
  }).map(item => item.prop! || item.attr?.prop!)
815
- props.columns._skip = false
821
+ if (!init) {
822
+ nextTick(() => {
823
+ props.columns._skip = false
824
+ })
825
+ }
816
826
  if (result.length) {
817
827
  return result
818
828
  }
819
829
  return props.columns.map(item => item.prop! || item.attr?.prop!)
820
830
  }
821
- const localShowColumn = ref<string[]>(initLocalShow())
831
+ const localShowColumn = ref<string[]>(initLocalShow(true))
822
832
  watch(() => localShowColumn.value?.length, () => {
823
833
  emit('update:showColumn', localShowColumn.value)
824
834
  }, {
@@ -837,8 +847,7 @@ const syncLocalShowColumnToCookies = () => {
837
847
  index
838
848
  }
839
849
  })
840
- instance?.$cookies?.remove(props.storageKey)
841
- instance?.$cookies?.set(props.storageKey, JSON.stringify(columnState), -1, '/xxxx/xxxx/xxxx')
850
+ CachedManager.syncCachedSet(props.storageKey, columnState)
842
851
  }
843
852
  }
844
853
 
@@ -852,40 +861,61 @@ const syncShowItemToInitHidden = () => {
852
861
  item.initHidden = true
853
862
  }
854
863
  })
855
- props.columns._skip = false
864
+ nextTick(() => {
865
+ props.columns._skip = false
866
+ })
856
867
  }
857
- const syncCookiesToLocalShowColumn = () => {
868
+ const syncCookiesToLocalShowColumn = async () => {
858
869
  if (props.columnEdit) {
859
- let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
860
- if (columnState) {
861
- if (typeof columnState === 'string') {
862
- columnState = JSON.parse(columnState)
870
+ try {
871
+ let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
872
+ if (!columnState) {
873
+ columnState = await CachedManager.asyncCachedGet(props.storageKey)
863
874
  }
864
- const showColumnItems: string[] = []
865
- for (const key in columnState as NfTableColumnAttributes) {
866
- if (!columnState![key].initHidden) {
867
- showColumnItems.push(columnState![key].prop)
875
+ if (columnState) {
876
+ if (typeof columnState === 'string') {
877
+ columnState = JSON.parse(columnState)
868
878
  }
879
+ const showColumnItems: string[] = []
880
+ for (const key in columnState as NfTableColumnAttributes) {
881
+ if (!columnState![key].initHidden) {
882
+ showColumnItems.push(columnState![key].prop)
883
+ }
884
+ }
885
+ localShowColumn.value = showColumnItems
886
+ syncShowItemToInitHidden()
869
887
  }
870
- localShowColumn.value = showColumnItems
871
- syncShowItemToInitHidden()
888
+ } catch (e) {
889
+ console.log(e)
872
890
  }
873
891
  }
874
892
  }
875
- if (props.columnEdit) {
876
- // 同步缓存参数
877
- const cached = instance?.$cookies?.get(props.storageKey)
878
- const cachedPriority = props.priority === 'cached'
879
- if (cachedPriority ? cached : localShowColumn.value?.length) {
880
- cachedPriority ? syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
881
- } else if (cachedPriority ? localShowColumn.value?.length : cached) {
882
- cachedPriority ? syncLocalShowColumnToCookies() : syncCookiesToLocalShowColumn()
893
+
894
+ const initCachedData = async () => {
895
+ if (props.columnEdit) {
896
+ // 同步缓存参数
897
+ try {
898
+ let cached: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
899
+ if (!cached) {
900
+ cached = await CachedManager.asyncCachedGet(props.storageKey)
901
+ }
902
+ const cachedPriority = props.priority === 'cached'
903
+ if (cachedPriority ? cached : localShowColumn.value?.length) {
904
+ cachedPriority ? await syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
905
+ } else if (cachedPriority ? localShowColumn.value?.length : cached) {
906
+ cachedPriority ? syncLocalShowColumnToCookies() : await syncCookiesToLocalShowColumn()
907
+ }
908
+ } catch (e) {
909
+ console.log(e)
910
+ }
883
911
  }
884
912
  }
885
913
 
914
+ initCachedData()
915
+
886
916
  const tableColumns = ref<NfTableColumnAttributes[]>([])
887
917
  const elTableRefKey = ref(Date.now())
888
- const syncCookiesToTableColumn = (readCached = true) => {
918
+ const syncCookiesToTableColumn = async (readCached = true) => {
889
919
  props.columns._skip = true
890
920
  const columns = props.columns!.map((item, index) => {
891
921
  const len = item.label?.length || 0
@@ -913,32 +943,44 @@ const syncCookiesToTableColumn = (readCached = true) => {
913
943
  delete item.attr.prop
914
944
  delete item.attr.label
915
945
  item._index = index
946
+ set(item, 'initHidden', item.initHidden)
947
+ set(item, 'destory', item.destory)
916
948
  item.__index = index
917
949
  return item
918
950
  })
919
951
  if (readCached && props.columnEdit) {
920
952
  // 读取缓存 Column 配置
921
- let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
922
- if (columnState) {
923
- if (typeof columnState === 'string') {
924
- columnState = JSON.parse(columnState)
953
+ try {
954
+ let columnState: string | NfTableColumnAttributes | undefined = CachedManager.syncCachedGet(props.storageKey)
955
+ if (!columnState) {
956
+ columnState = await CachedManager.asyncCachedGet(props.storageKey)
925
957
  }
926
- for (const key in columnState as NfTableColumnAttributes) {
927
- const state = columnState![key]
928
- columns.every(i => {
929
- if (i.prop === key) {
930
- i.initHidden = state.initHidden
931
- i.attr ? i.attr['fixed'] = state.fixed : i.attr = { fixed: state.fixed }
932
- i._index = state.index
933
- return false
934
- }
935
- return true
936
- })
958
+ props.columns._skip = true
959
+ if (columnState) {
960
+ if (typeof columnState === 'string') {
961
+ columnState = JSON.parse(columnState)
962
+ }
963
+ for (const key in columnState as NfTableColumnAttributes) {
964
+ const state = columnState![key]
965
+ columns.every(i => {
966
+ if (i.prop === key) {
967
+ i.initHidden = state.initHidden
968
+ i.attr ? i.attr['fixed'] = state.fixed : i.attr = { fixed: state.fixed }
969
+ i._index = state.index
970
+ return false
971
+ }
972
+ return true
973
+ })
974
+ }
937
975
  }
976
+ } catch (e) {
977
+ console.log(e)
938
978
  }
939
979
  }
940
- props.columns._skip = true
941
980
  tableColumns.value = columns.sort((a, b) => a._index! - b._index! < 0 ? -1 : a._index! - b._index! > 0 ? 1 : 0)
981
+ nextTick(() => {
982
+ props.columns._skip = false
983
+ })
942
984
  elTableRefKey.value = Date.now()
943
985
  }
944
986
 
@@ -947,11 +989,12 @@ syncCookiesToTableColumn()
947
989
  onBeforeMount(() => {
948
990
  watch(() => {
949
991
  return props.columns
950
- }, () => {
992
+ }, async () => {
951
993
  if (props.columns._skip) {
952
994
  return
953
995
  }
954
- syncCookiesToTableColumn(false)
996
+ localShowColumn.value = initLocalShow()
997
+ await syncCookiesToTableColumn()
955
998
  }, {
956
999
  deep: true
957
1000
  })
@@ -965,6 +1008,7 @@ const tableAttrer = computed(() => {
965
1008
  'height': '48px',
966
1009
  'color': '#303133',
967
1010
  'font-size': '14px'
1011
+
968
1012
  },
969
1013
  'cell-style': { 'text-align': 'left' },
970
1014
  resizable: true,
@@ -1015,10 +1059,7 @@ const isShow = (row: Record<string, any>) => {
1015
1059
  if (row.type) {
1016
1060
  return true
1017
1061
  }
1018
- if (!localShowColumn.value?.length) {
1019
- return !row.initHidden && !row.destory
1020
- }
1021
- return localShowColumn.value.includes(row.prop) && !row.initHidden && !row.destory
1062
+ return !row.initHidden && !row.destory
1022
1063
  }
1023
1064
 
1024
1065
  const resetNfSearchFormModel = () => {
@@ -1088,10 +1129,10 @@ const columnCheckConfirmFeedback = (value: Record<string, any>) => {
1088
1129
  * 弹框确定
1089
1130
  * @param { Object } value
1090
1131
  */
1091
- const fieldsConfirm = (value) => {
1132
+ const fieldsConfirm = async (value) => {
1092
1133
  columnCheckConfirmFeedback(value)
1093
- syncCookiesToLocalShowColumn()
1094
- syncCookiesToTableColumn()
1134
+ await syncCookiesToLocalShowColumn()
1135
+ await syncCookiesToTableColumn()
1095
1136
  emit('fieldsChange', localShowColumn.value)
1096
1137
  }
1097
1138
  /**
@@ -1099,12 +1140,12 @@ const fieldsConfirm = (value) => {
1099
1140
  * @param { Function } cb
1100
1141
  * @param { Function } error
1101
1142
  */
1102
- const columnCheckConfirm = (cb, error) => {
1143
+ const columnCheckConfirm = async (cb, error) => {
1103
1144
  try {
1104
1145
  const value = columnCheckDrawer.value.syncTableColumnsToCookies()
1105
1146
  columnCheckConfirmFeedback(value)
1106
- syncCookiesToLocalShowColumn()
1107
- syncCookiesToTableColumn()
1147
+ await syncCookiesToLocalShowColumn()
1148
+ await syncCookiesToTableColumn()
1108
1149
  emit('fieldsChange', localShowColumn.value)
1109
1150
  cb()
1110
1151
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-table",
3
- "version": "3.2.47",
3
+ "version": "3.2.49",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,11 +14,12 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-drawer": "^3.2.47",
18
- "@94ai/nf-message": "^3.2.47",
19
- "@94ai/nf-search-form": "^3.2.47",
20
- "@94ai/nf-theme-chalk": "^3.2.47",
21
- "vue-cookies": "^1.8.3",
17
+ "@94ai/common-utils": "^3.2.49",
18
+ "@94ai/nf-drawer": "^3.2.49",
19
+ "@94ai/nf-message": "^3.2.49",
20
+ "@94ai/nf-search-form": "^3.2.49",
21
+ "@94ai/nf-theme-chalk": "^3.2.49",
22
+ "idb-keyval": "^6.2.1",
22
23
  "vue-demi": "^0.14.5",
23
24
  "vuedraggable": "^2.24.3"
24
25
  },
@@ -35,5 +36,5 @@
35
36
  "types": "lib/index.d.ts",
36
37
  "main": "lib/nf-table.cjs.js",
37
38
  "module": "lib/nf-table.esm-bundler.js",
38
- "gitHead": "91145bb7df8dad2c0cb3eefb101c6158ec854269"
39
+ "gitHead": "8cbd9254da4ec43f46b29198c0839bf2ba19132d"
39
40
  }
package/lib/utils.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function deepClone(source: any): Record<string, any> | Record<string, any>[];
package/package/utils.ts DELETED
@@ -1,15 +0,0 @@
1
- export function deepClone(source) {
2
- if (!source && typeof source !== 'object') {
3
- throw new Error('error arguments shallowClone')
4
- }
5
- const targetObj: Record<string, any> | Record<string, any>[] = source.constructor === Array ? [] : {}
6
- Object.keys(source).forEach((keys) => {
7
- if (source[keys] && typeof source[keys] === 'object') {
8
- targetObj[keys] = source[keys].constructor === Array ? [] : {}
9
- targetObj[keys] = deepClone(source[keys])
10
- } else {
11
- targetObj[keys] = source[keys]
12
- }
13
- })
14
- return targetObj
15
- }