copy.nvue
4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<template>
<view class="h-page">
<CustomNavBar :title="t('asis.HeatMap')" />
<PageOptions style="position: sticky;" :options="indicatorsList" :options-props="indicatorsOptions" @change="handleChange"></PageOptions>
<!-- #ifndef APP-PLUS -->
<view class="h-c-container">
<web-view @onPostMessage="handleMessage" class="web-view" :fullscreen="false" :frameBorder="0" :src="webUrl"
:style="`width:710rpx;height: ${webviewHeight}px;borderRadius:16rpx;overflow:hidden; background-color: #fff;`"></web-view>
</view>
<!-- #endif -->
</view>
</template>
<script setup>
import {
ref,
onMounted
} from 'vue'
import {
getUserIndicatorIndexApi
} from '@/api'
import {
onBackPress
} from '@dcloudio/uni-app'
import PageOptions from '@/components/PageOptions.vue'
import CardNvue from '@/pages/flow/components/Card.nvue'
import CustomNavBar from '@/components/CustomNav.nvue'
import {
t
} from '@/plugins/index.js'
const handleMessage = (e) => {
const data = e.detail.data[0]
if (data.type === 'setHeight') {
webviewHeight.value = data.height + 10
return
}
if (!data.gateId) return
uni.showToast({
title: `${data.gateName}\n${data.val}`,
icon: 'none'
})
}
const webviewHeight = ref(650)
// #ifdef H5
onMounted(() => {
window.onmessage = e => {
const {
type,
height
} = e.data?.data?.arg || {}
if (type === 'setHeight') {
webviewHeight.value = (height || 650) + 10
}
}
})
// #endif
const params = ref({})
const flag = ref(false) // 是否初始化完成
const handleChange = (e) => {
params.value = e
currentKey.value = e.indicatorKey
if (flag.value) {
// #ifdef APP-PLUS
initHeatMapApp()
// #endif
// #ifndef APP-PLUS
initHeatMapH5()
// #endif
}
}
const filterList = ref([])
const webUrl = ref('')
const webview = ref(null)
const initHeatMapH5 = () => {
const {
startDate,
endDate,
storeId,
indicatorKey
} = params.value
const token = uni.getStorageSync('Authorization')
webUrl.value =
`https://store.keliuyun.com/apph5/areaHeatMap?token=${token}&mallId=${storeId}&startDate=${startDate}&endDate=${endDate}&key=${currentKey.value}`
// `http://192.168.1.20:3000/apph5/areaHeatMap?token=${token}&mallId=${storeId}&startDate=${startDate}&endDate=${endDate}&key=${currentKey.value}`
console.log(webUrl.value);
}
// 使用plus.webview解决ios异常崩溃的问题
onBackPress(()=>{
// #ifdef APP-PLUS
closeWebviewApp()
// #endif
})
const initHeatMapApp = () => {
if(webview.value){
plus.webview.close(webview.value)
webview.value = null
}
webview.value = plus.webview.create(
`https://store.keliuyun.com/apph5/areaHeatMap?token=${token}&mallId=${storeId}&startDate=${startDate}&endDate=${endDate}&key=${currentKey.value}`
"area-heatmap",
{
top: `${top+100}px`, // 关键:从导航栏下方开始
bottom: "0px",
left: "0px",
right: "0px",
'uni-app': 'none',
popGesture:'close',
// backButtonAutoControl:'close',
hardwareAccelerated: true,
wkwebview: true,
}
)
webview.value.show()
}
const closeWebviewApp = ()=>{
if(webview.value){
webview.value.hide()
webview.value.close()
webview.value = null
}
}
/********** 指标相关 *********/
const indicatorsOptions = {
label: 'indexName',
value: 'indexKey'
}
onMounted(() => {
initIndicatorList()
flag.value = true
})
const currentKey = ref('')
const indicatorsList = ref([])
const initIndicatorList = async () => {
try {
const {
data
} = await getUserIndicatorIndexApi({
id: params.value.storeId
})
indicatorsList.value = data?.filter(item => item.status === 1) || []
currentKey.value = data.length > 0 ? data[0].indexKey : ''
initHeatMap()
} catch (e) {
console.log(e);
}
}
</script>
<style lang="scss">
.h-page {
/* #ifdef H5 */
min-height: calc(100vh - 44px);
/* #endif */
/* #ifndef H5 */
min-height: 100vh;
/* #endif */
background-color: #f2f3f6;
.h-c-container {
border-radius: 12rpx;
overflow: hidden;
padding: 0 20rpx 20rpx;
}
}
.web-view {
position: relative;
}
</style>