import React, { Component } from 'react'
import { connect } from 'react-redux'
import { View, Button, Text,ScrollView } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import Taro from '@tarojs/taro'
import './index.less'
import TopSearch from '../../components/common/topSearch'
import Banner from '../../components/common/banner'
import Grid from './child/grid'
import New from './child/new'
import Hot from './child/hot'
import Tabs from './child/tabs'
import {api} from '../../utils/api'
class Index extends Component {
componentWillReceiveProps (nextProps) {
console.log(this.props, nextProps)
}
state={
show:true
}
componentWillUnmount () { }
componentDidShow () { }
componentDidHide () { }
async componentDidMount()
{
this.getLocationAuthorize();
}
getLocationAuthorize=()=>{
let that=this;
Taro.getSetting({
success: function (res) {
console.log(res.authSetting)
if(!res.authSetting['scope.userLocation'])
{
Taro.authorize({
scope: 'scope.userLocation',
success: function () {
that.getLocation();
},
fail:function()
{
Taro.showToast({
title:'获取位置信息失败',
icon:'none'
})
Taro.showModal({
title: '提示!',
confirmText: '去设置',
showCancel: false,
content: '获取地理位置信息',
success: function(res) {
if (res.confirm) {
Taro.openSetting({
success: function (res) {
console.log(res.authSetting)
}
})
}
}
})
}
})
}
}
})
}
getLocation=()=>{
Taro.getLocation({
type: 'gcj02',
success: function (res) {
const latitude = res.latitude
const longitude = res.longitude
var QQMapWX = require('../..//utils/sdk/qqmap-wx-jssdk.min.js');
var qqmapsdk = new QQMapWX({
key: '腾讯地图密钥'
});
console.log(latitude,longitude);
qqmapsdk.reverseGeocoder({
location:{latitude,longitude},
success: function(res){
Taro.showToast({
title:res.result.address_component.city
})
}
})
}
})
}
render () {
return (
<View className='index'>
<TopSearch />
<View className='i-c'>
<ScrollView
scrollY
style='height:100%'
>
<Banner />
<Grid />
<New />
<Hot />
<Tabs />
</ScrollView>
</View>
</View>
)
}
}
export default Index
转载请注明原文地址:https://blackberry.8miu.com/read-16423.html