Files
dvcp_v2_wxcp_app/library/project/caw/AppCountryAlbum/AppCountryAlbum.vue
2024-10-31 14:34:57 +08:00

107 lines
2.3 KiB
Vue

<template>
<div class="form">
<component v-if="html2canvas" ref="TabPage" :is="component" @change="onChange" :params="params"/>
</div>
</template>
<script>
import Tabbar from './components/Tabbar.vue'
import {mapActions, mapState} from "vuex"
export default {
name: 'AppCountryAlbum',
appName: '工作相册',
data() {
return {
html2canvas: null,
component: 'Tabbar',
params: {}
}
},
components: {
Tabbar
},
onLoad() {
uni.setStorageSync('address', {
lat: '',
lng: '',
address: '',
weather: '',
cityCode: ``
})
this.$injectLib("https://cdn.cunwuyun.cn/html2canvas.min.js", () => {
this.html2canvas = window?.html2canvas
})
setTimeout(() => {
this.getLocation()
}, 600)
},
onShow() {
this.$refs?.TabPage?.show()
},
computed: {
...mapState(['wxwork'])
},
methods: {
...mapActions(['injectJWeixin', 'agentSign']),
onChange(e) {
this.params = e.params
this.component = e.type
},
getLocation() {
this.injectJWeixin(['getLocation']).then(() => {
wx.getLocation({
type: 'wgs84',
success: res => {
var lat = res.latitude
var lng = res.longitude
this.$http.post('/api/appdvcpconfig/apiForward', `https://apis.map.qq.com/ws/geocoder/v1/?location=${lat},${lng}&key=3RZBZ-LZUCF-CT6J5-NWKZH-FCWOQ-UUFKY&get_poi=1`).then(res => {
if (res.code === 0) {
const data = res.data.result
uni.setStorageSync('address', {
lat,
lng,
address: data.address,
cityCode: `${data.ad_info.adcode}`
})
this.getWeather(`${data.ad_info.adcode}`)
}
})
},
error: res => {
console.log(res)
}
})
}).catch(e => {
})
},
getWeather(code) {
this.$http.post(`/api/bdweather/wdata?districtId=${code}`).then(res => {
if (res.code === 0) {
const data = res.data.result.now
uni.setStorageSync('address', {
...uni.getStorageSync('address'),
weather: `${data.text} ${data.temp}°` || ''
})
}
})
}
}
}
</script>
<style lang="scss" scoped>
</style>