@skyservice-developers/vue-dev-kit 1.2.9 → 1.3.1
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,41 @@ 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()) {
|
|
28
|
+
console.log('[parentBridge] not in iframe, skip sendToParent')
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
const msg = {
|
|
32
|
+
...message,
|
|
33
|
+
sender: getSenderId(),
|
|
34
|
+
target: message.target || 'DASHBOARD',
|
|
35
|
+
}
|
|
36
|
+
console.log('[parentBridge] sendToParent:', msg)
|
|
37
|
+
window.parent.postMessage(msg, '*')
|
|
38
|
+
}
|
|
39
|
+
|
|
10
40
|
function requestFromParent(source, key) {
|
|
11
41
|
if (!isInIframe()) return Promise.resolve(null)
|
|
12
42
|
|
|
@@ -19,22 +49,29 @@ function requestFromParent(source, key) {
|
|
|
19
49
|
}, TIMEOUT)
|
|
20
50
|
|
|
21
51
|
function handler(event) {
|
|
52
|
+
const d = event.data
|
|
53
|
+
if (d?.type === 'DATA_RESPONSE') {
|
|
54
|
+
console.log('[parentBridge] DATA_RESPONSE received:', { requestId: d.requestId, expectedId: requestId, target: d.target, sender: d.sender, hasData: d.data != null })
|
|
55
|
+
}
|
|
22
56
|
if (
|
|
23
|
-
|
|
24
|
-
|
|
57
|
+
d?.type === 'DATA_RESPONSE' &&
|
|
58
|
+
d?.requestId === requestId &&
|
|
59
|
+
(!d.target || d.target === getSenderId())
|
|
25
60
|
) {
|
|
26
61
|
clearTimeout(timeout)
|
|
27
62
|
window.removeEventListener('message', handler)
|
|
28
|
-
resolve(
|
|
63
|
+
resolve(d.data ?? null)
|
|
29
64
|
}
|
|
30
65
|
}
|
|
31
66
|
|
|
32
67
|
window.addEventListener('message', handler)
|
|
33
68
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
69
|
+
sendToParent({
|
|
70
|
+
type: 'DATA_REQUEST',
|
|
71
|
+
requestId,
|
|
72
|
+
source,
|
|
73
|
+
key,
|
|
74
|
+
})
|
|
38
75
|
})
|
|
39
76
|
}
|
|
40
77
|
|
|
@@ -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)
|
|
@@ -135,16 +142,16 @@ const parentLang = ref({})
|
|
|
135
142
|
|
|
136
143
|
// Track page visit in parent's componentStats
|
|
137
144
|
if (isInIframe() && props.trackPageName) {
|
|
138
|
-
|
|
145
|
+
sendToParent({
|
|
139
146
|
type: 'trackVisit',
|
|
140
147
|
name: props.trackPageName,
|
|
141
148
|
path: props.trackPagePath || `/${props.trackPageName}`,
|
|
142
|
-
}
|
|
149
|
+
})
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
// Set rocketMode in parent
|
|
146
153
|
if (isInIframe()) {
|
|
147
|
-
|
|
154
|
+
sendToParent({ type: 'setRocketMode', value: true })
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
// Load translations from parent
|
|
@@ -197,7 +204,7 @@ const closeDropdown = () => {
|
|
|
197
204
|
const selectItem = (item) => {
|
|
198
205
|
emit('navigate', item.path)
|
|
199
206
|
if (isInIframe()) {
|
|
200
|
-
|
|
207
|
+
sendToParent({ type: 'navigate', path: item.path })
|
|
201
208
|
}
|
|
202
209
|
closeDropdown()
|
|
203
210
|
}
|
|
@@ -245,7 +252,7 @@ const shouldShowBackButton = computed(() => {
|
|
|
245
252
|
const handleBack = () => {
|
|
246
253
|
if (props.backEvent) return props.backEvent()
|
|
247
254
|
|
|
248
|
-
|
|
255
|
+
sendToParent({ type: 'exit' })
|
|
249
256
|
}
|
|
250
257
|
</script>
|
|
251
258
|
|