@skyservice-developers/vue-dev-kit 1.2.8 → 1.3.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/package.json
CHANGED
|
@@ -2,11 +2,36 @@ import { isInIframe } from './webviewCheck'
|
|
|
2
2
|
|
|
3
3
|
const TIMEOUT = 3000
|
|
4
4
|
let counter = 0
|
|
5
|
+
let _senderId = null
|
|
5
6
|
|
|
6
7
|
function generateRequestId() {
|
|
7
8
|
return `req_${++counter}_${Date.now()}`
|
|
8
9
|
}
|
|
9
10
|
|
|
11
|
+
function generateAppId() {
|
|
12
|
+
return 'APP_' + Math.random().toString(36).slice(2, 10)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function setSenderId(id) {
|
|
16
|
+
_senderId = id
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getSenderId() {
|
|
20
|
+
if (!_senderId) {
|
|
21
|
+
_senderId = generateAppId()
|
|
22
|
+
}
|
|
23
|
+
return _senderId
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function sendToParent(message) {
|
|
27
|
+
if (!isInIframe()) return
|
|
28
|
+
window.parent.postMessage({
|
|
29
|
+
...message,
|
|
30
|
+
sender: getSenderId(),
|
|
31
|
+
target: message.target || 'DASHBOARD',
|
|
32
|
+
}, '*')
|
|
33
|
+
}
|
|
34
|
+
|
|
10
35
|
function requestFromParent(source, key) {
|
|
11
36
|
if (!isInIframe()) return Promise.resolve(null)
|
|
12
37
|
|
|
@@ -19,22 +44,26 @@ function requestFromParent(source, key) {
|
|
|
19
44
|
}, TIMEOUT)
|
|
20
45
|
|
|
21
46
|
function handler(event) {
|
|
47
|
+
const d = event.data
|
|
22
48
|
if (
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
d?.type === 'DATA_RESPONSE' &&
|
|
50
|
+
d?.requestId === requestId &&
|
|
51
|
+
(!d.target || d.target === getSenderId())
|
|
25
52
|
) {
|
|
26
53
|
clearTimeout(timeout)
|
|
27
54
|
window.removeEventListener('message', handler)
|
|
28
|
-
resolve(
|
|
55
|
+
resolve(d.data ?? null)
|
|
29
56
|
}
|
|
30
57
|
}
|
|
31
58
|
|
|
32
59
|
window.addEventListener('message', handler)
|
|
33
60
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
61
|
+
sendToParent({
|
|
62
|
+
type: 'DATA_REQUEST',
|
|
63
|
+
requestId,
|
|
64
|
+
source,
|
|
65
|
+
key,
|
|
66
|
+
})
|
|
38
67
|
})
|
|
39
68
|
}
|
|
40
69
|
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
<script setup>
|
|
81
81
|
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
|
82
82
|
import { isInIframe } from '../../shared/utils/webviewCheck'
|
|
83
|
-
import { getParentLocalStorage, getParentWindowValue } from '../../shared/utils/parentBridge'
|
|
83
|
+
import { getParentLocalStorage, getParentWindowValue, sendToParent, setSenderId, getSenderId } from '../../shared/utils/parentBridge'
|
|
84
84
|
|
|
85
85
|
const props = defineProps({
|
|
86
86
|
title: {
|
|
@@ -123,8 +123,15 @@ const props = defineProps({
|
|
|
123
123
|
type: String,
|
|
124
124
|
default: "",
|
|
125
125
|
},
|
|
126
|
+
appId: {
|
|
127
|
+
type: String,
|
|
128
|
+
default: "",
|
|
129
|
+
},
|
|
126
130
|
});
|
|
127
131
|
|
|
132
|
+
// Initialize sender ID from prop or generate
|
|
133
|
+
setSenderId(props.appId || getSenderId())
|
|
134
|
+
|
|
128
135
|
const emit = defineEmits(['back', 'navigate'])
|
|
129
136
|
|
|
130
137
|
const dropdownRef = ref(null)
|
|
@@ -134,15 +141,17 @@ const localStorageItems = ref([])
|
|
|
134
141
|
const parentLang = ref({})
|
|
135
142
|
|
|
136
143
|
// Track page visit in parent's componentStats
|
|
137
|
-
console.log('[Header] trackPageName:', props.trackPageName, 'isInIframe:', isInIframe())
|
|
138
144
|
if (isInIframe() && props.trackPageName) {
|
|
139
|
-
|
|
145
|
+
sendToParent({
|
|
140
146
|
type: 'trackVisit',
|
|
141
147
|
name: props.trackPageName,
|
|
142
148
|
path: props.trackPagePath || `/${props.trackPageName}`,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Set rocketMode in parent
|
|
153
|
+
if (isInIframe()) {
|
|
154
|
+
sendToParent({ type: 'setRocketMode', value: true })
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
// Load translations from parent
|
|
@@ -195,7 +204,7 @@ const closeDropdown = () => {
|
|
|
195
204
|
const selectItem = (item) => {
|
|
196
205
|
emit('navigate', item.path)
|
|
197
206
|
if (isInIframe()) {
|
|
198
|
-
|
|
207
|
+
sendToParent({ type: 'navigate', path: item.path })
|
|
199
208
|
}
|
|
200
209
|
closeDropdown()
|
|
201
210
|
}
|
|
@@ -243,7 +252,7 @@ const shouldShowBackButton = computed(() => {
|
|
|
243
252
|
const handleBack = () => {
|
|
244
253
|
if (props.backEvent) return props.backEvent()
|
|
245
254
|
|
|
246
|
-
|
|
255
|
+
sendToParent({ type: 'exit' })
|
|
247
256
|
}
|
|
248
257
|
</script>
|
|
249
258
|
|