adtec-core-package 3.0.4 → 3.0.5

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.
@@ -1,35 +1,59 @@
1
+ /** TipTap focus 选项:不触发 ProseMirror scrollIntoView */
2
+ export const FOCUS_WITHOUT_SCROLL = { scrollIntoView: false }
3
+
4
+ function pushScrollPosition(positions, seen, el) {
5
+ if (!el || seen.has(el)) return
6
+ seen.add(el)
7
+ positions.push({
8
+ el,
9
+ top: el.scrollTop,
10
+ left: el.scrollLeft,
11
+ })
12
+ }
13
+
1
14
  /**
2
- * 保存/恢复编辑器及外层滚动位置,避免 setBlockType 等命令触发 scrollIntoView 导致页面跳动。
15
+ * 保存/恢复编辑器及外层滚动位置,避免 toolbar focus / setBlockType 等触发 scrollIntoView 导致页面跳动。
3
16
  */
4
17
  export function captureScrollPositions(container) {
5
18
  const positions = []
19
+ const seen = new Set()
6
20
  const pageContainer = document.querySelector(
7
21
  `${container} .umo-zoomable-container`,
8
22
  )
9
- if (pageContainer) {
10
- positions.push({
11
- el: pageContainer,
12
- top: pageContainer.scrollTop,
13
- left: pageContainer.scrollLeft,
14
- })
15
- }
23
+ pushScrollPosition(positions, seen, pageContainer)
16
24
 
17
- let node = pageContainer?.parentElement ?? null
25
+ let node =
26
+ pageContainer?.parentElement ??
27
+ document.querySelector(container)?.parentElement ??
28
+ null
18
29
  while (node && node !== document.documentElement) {
19
30
  if (node.classList?.contains('el-scrollbar__wrap')) {
20
- positions.push({
21
- el: node,
22
- top: node.scrollTop,
23
- left: node.scrollLeft,
24
- })
25
- break
31
+ pushScrollPosition(positions, seen, node)
32
+ } else {
33
+ const style = getComputedStyle(node)
34
+ const overflow = `${style.overflow}${style.overflowY}${style.overflowX}`
35
+ if (/auto|scroll/.test(overflow)) {
36
+ pushScrollPosition(positions, seen, node)
37
+ }
26
38
  }
27
39
  node = node.parentElement
28
40
  }
29
41
 
42
+ pushScrollPosition(positions, seen, document.documentElement)
43
+ pushScrollPosition(positions, seen, document.body)
44
+
30
45
  return positions
31
46
  }
32
47
 
48
+ export function runPreservingScroll(container, fn) {
49
+ const scrollPositions = captureScrollPositions(container)
50
+ try {
51
+ return fn()
52
+ } finally {
53
+ restoreScrollPositions(scrollPositions)
54
+ }
55
+ }
56
+
33
57
  export function restoreScrollPositions(positions) {
34
58
  if (!positions.length) return
35
59
  const apply = () => {
@@ -7,14 +7,15 @@
7
7
  <script setup lang="ts">
8
8
  //@ts-ignore
9
9
  import { components, initVxeTableInPage } from 'adtec-core-package/src/config/VxeTableConfig'
10
- // 导入默认的语言
11
10
  import { defineComponent, getCurrentInstance, h } from 'vue'
11
+
12
12
  const { VxeGrid } = components
13
13
  defineComponent({
14
14
  components: {
15
15
  VxeGrid,
16
16
  },
17
17
  })
18
+
18
19
  const { renderComponent = { enableElementPlus: true, enableExcel: false, enablePdf: false } } =
19
20
  defineProps<{
20
21
  renderComponent?: {
@@ -24,12 +25,18 @@ const { renderComponent = { enableElementPlus: true, enableExcel: false, enableP
24
25
  }
25
26
  }>()
26
27
 
27
- initVxeTableInPage(renderComponent.enableExcel,renderComponent.enablePdf)
28
+ initVxeTableInPage(
29
+ renderComponent.enableExcel,
30
+ renderComponent.enablePdf,
31
+ renderComponent.enableElementPlus ?? true,
32
+ )
28
33
 
29
34
  const vm = getCurrentInstance()
30
35
 
31
- const changeRef = (exposed: any) => {
32
- vm && (vm.exposed = exposed)
36
+ const changeRef = (exposed: unknown) => {
37
+ if (vm) {
38
+ vm.exposed = exposed
39
+ }
33
40
  }
34
41
  </script>
35
42
 
@@ -1,6 +1,9 @@
1
1
  import { defineStore } from 'pinia'
2
- import { ref } from 'vue'
2
+ import { ref, type Ref } from 'vue'
3
+ import Base64 from 'crypto-js/enc-base64'
4
+ import Utf8 from 'crypto-js/enc-utf8'
3
5
  import type { ISysDictDataCacheVo } from '../interface/ISysDictDataCacheVo'
6
+
4
7
  // 定义包含map的整体类型
5
8
  export interface dictMapType {
6
9
  [key: string]: ISysDictDataCacheVo[]
@@ -14,12 +17,76 @@ export interface dictDataMapType {
14
17
  [key: string]: { [key: string]: ISysDictDataCacheVo }
15
18
  }
16
19
 
20
+ const DICT_STORAGE_KEY = 'dictStore'
21
+
22
+ export interface SharedDictState {
23
+ dictMap: Ref<dictMapType>
24
+ dictDataMap: Ref<dictDataMapType>
25
+ dictDefaultValueMap: Ref<dictMapType>
26
+ }
27
+
28
+ declare global {
29
+ interface Window {
30
+ __ADTEC_SHARED_DICT__?: SharedDictState
31
+ }
32
+ }
33
+
34
+ /** wujie 子应用走 parent,宿主/独立 dev 走自身 window —— 全应用共享同一份 ref */
35
+ function getRootWindow(): Window {
36
+ if (typeof window === 'undefined') return window
37
+ const w = window as Window & { __POWERED_BY_WUJIE__?: boolean }
38
+ return w.__POWERED_BY_WUJIE__ ? window.parent : window
39
+ }
40
+
41
+ function hydrateFromSessionStorage(state: SharedDictState) {
42
+ const raw = sessionStorage.getItem(DICT_STORAGE_KEY)
43
+ if (!raw) return
44
+ try {
45
+ const parsed = JSON.parse(Base64.parse(raw).toString(Utf8)) as {
46
+ dictMap?: dictMapType
47
+ dictDataMap?: dictDataMapType
48
+ dictDefaultValueMap?: dictMapType
49
+ }
50
+ if (parsed.dictMap) {
51
+ state.dictMap.value = { ...parsed.dictMap, ...state.dictMap.value }
52
+ }
53
+ if (parsed.dictDataMap) {
54
+ state.dictDataMap.value = { ...parsed.dictDataMap, ...state.dictDataMap.value }
55
+ }
56
+ if (parsed.dictDefaultValueMap) {
57
+ state.dictDefaultValueMap.value = {
58
+ ...parsed.dictDefaultValueMap,
59
+ ...state.dictDefaultValueMap.value,
60
+ }
61
+ }
62
+ } catch {
63
+ // ignore corrupt session data
64
+ }
65
+ }
66
+
67
+ /** 宿主 window 单例:alive 子应用与宿主读写同一组 Vue ref(刷新时仍由 sessionStorage 恢复) */
68
+ export function getSharedDictRefs(): SharedDictState {
69
+ const root = getRootWindow()
70
+ if (!root.__ADTEC_SHARED_DICT__) {
71
+ root.__ADTEC_SHARED_DICT__ = {
72
+ dictMap: ref<dictMapType>({}),
73
+ dictDataMap: ref<dictDataMapType>({}),
74
+ dictDefaultValueMap: ref<dictMapType>({}),
75
+ }
76
+ hydrateFromSessionStorage(root.__ADTEC_SHARED_DICT__)
77
+ }
78
+ return root.__ADTEC_SHARED_DICT__
79
+ }
80
+
81
+ /** @deprecated 已由 getSharedDictRefs 在初始化时 hydrate;保留兼容旧调用 */
82
+ export function syncDictFromSessionStorage(target: SharedDictState) {
83
+ hydrateFromSessionStorage(target)
84
+ }
85
+
17
86
  export const dictStore = defineStore('dictStore', () => {
18
- const dictMap = ref<dictMapType>({})
19
- const dictDataMap = ref<dictDataMapType>({})
20
- const dictDefaultValueMap = ref<dictMapType>({})
87
+ const { dictMap, dictDataMap, dictDefaultValueMap } = getSharedDictRefs()
21
88
 
22
- const clearDictCache = (dictType?: string[],userOrgId?: string, orgId?: string, all?: Boolean) => {
89
+ const clearDictCache = (dictType?: string[], userOrgId?: string, orgId?: string, all?: Boolean) => {
23
90
  if (dictType && dictType.length > 0) {
24
91
  dictType.forEach((item) => {
25
92
  if (orgId) {