完成:黄家明项目的开发并存档
This commit is contained in:
@@ -24,12 +24,13 @@ export interface Market {
|
||||
|
||||
function Home() {
|
||||
const [IsLogin, setIsLogin] = useState<boolean>(true)
|
||||
const [isAdmin, setIsAdmin] = useState<boolean>(false)
|
||||
const [search, setSearch] = useState(false)
|
||||
const [userInfo, setUserInfo] = useState<User>()
|
||||
const [longitude, setLongitude] = useState<any>(108.374959)
|
||||
const [latitude, setLatitude] = useState<any>(22.767024)
|
||||
const [markers, setMarkers] = useState<Market[]>([])
|
||||
const [scale, setScale] = useState<any>(16)
|
||||
const [scale, setScale] = useState<any>(12)
|
||||
const [keywords, setKeywords] = useState<string>('')
|
||||
const [list, setList] = useState<HjmCar[]>([])
|
||||
|
||||
@@ -108,56 +109,163 @@ function Home() {
|
||||
const res = await Taro.getLocation({
|
||||
type: 'gcj02' //返回可以用于wx.openLocation的经纬度
|
||||
})
|
||||
pageByQQMap({
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude,
|
||||
}).then(res => {
|
||||
if (res?.list && res?.list.length > 0) {
|
||||
const data = res?.list;
|
||||
const arr = []
|
||||
data?.map((item: HjmCar) => {
|
||||
// @ts-ignore
|
||||
arr.push({
|
||||
id: item.id,
|
||||
latitude: item.latitude,
|
||||
longitude: item.longitude,
|
||||
title: `${item.organization}`,
|
||||
name: item.organization
|
||||
})
|
||||
})
|
||||
setMarkers(arr)
|
||||
}
|
||||
})
|
||||
if (res.latitude) {
|
||||
setLatitude(res.latitude)
|
||||
}
|
||||
if (res.longitude) {
|
||||
setLongitude(res.longitude)
|
||||
}
|
||||
console.log(res)
|
||||
console.log('当前位置:', res.latitude, res.longitude);
|
||||
|
||||
// 已认证用户
|
||||
if(Taro.getStorageSync('Certification')){
|
||||
setIsAdmin(true)
|
||||
setScale(11)
|
||||
pageHjmCarByMap(res.latitude,res.longitude)
|
||||
}
|
||||
|
||||
// 游客
|
||||
if(!Taro.getStorageSync('access_token')){
|
||||
setScale(15)
|
||||
const arr = []
|
||||
// @ts-ignore
|
||||
arr.push({
|
||||
id: 10001,
|
||||
latitude: res.latitude,
|
||||
longitude: res.longitude,
|
||||
title: '当前位置',
|
||||
name: '当前位置'
|
||||
})
|
||||
setMarkers(arr)
|
||||
}
|
||||
return res;
|
||||
} catch (err) {
|
||||
console.error('获取位置失败:', err);
|
||||
}
|
||||
}
|
||||
|
||||
const onQuery = () => {
|
||||
if(!keywords){
|
||||
Taro.showToast({
|
||||
title: '请输入关键字',
|
||||
icon: 'none'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
reload();
|
||||
}
|
||||
|
||||
const pageHjmCarByMap = (latitude?: any,longitude?: any) => {
|
||||
// 搜索条件
|
||||
const where = {}
|
||||
|
||||
if(latitude){
|
||||
// @ts-ignore
|
||||
where.latitude = latitude
|
||||
}
|
||||
if(longitude){
|
||||
// @ts-ignore
|
||||
where.longitude = longitude
|
||||
}
|
||||
// 判断身份
|
||||
const roleCode = Taro.getStorageSync('RoleCode');
|
||||
if(roleCode == 'kuaidiyuan'){
|
||||
// @ts-ignore
|
||||
where.driverId = Taro.getStorageSync('UserId')
|
||||
}
|
||||
if(roleCode == 'zhandian'){
|
||||
// @ts-ignore
|
||||
where.organizationId = Taro.getStorageSync('OrganizationId');
|
||||
}
|
||||
if(roleCode == 'kuaidi'){
|
||||
// @ts-ignore
|
||||
where.organizationParentId = Taro.getStorageSync('OrganizationParentId');
|
||||
}
|
||||
|
||||
pageByQQMap(where).then(res => {
|
||||
console.log(res,'pageByQQMap')
|
||||
if(res?.count == 0){
|
||||
const arr = []
|
||||
// @ts-ignore
|
||||
arr.push({
|
||||
id: 10001,
|
||||
latitude: 22.813371,
|
||||
longitude: 108.323885,
|
||||
title: '当前位置',
|
||||
name: '当前位置'
|
||||
})
|
||||
setMarkers(arr)
|
||||
return false
|
||||
}
|
||||
if (res?.list && res?.list.length > 0) {
|
||||
const data = res?.list;
|
||||
const arr = []
|
||||
data?.map((item: HjmCar) => {
|
||||
// @ts-ignore
|
||||
arr.push({
|
||||
id: item.id,
|
||||
latitude: item.latitude,
|
||||
longitude: item.longitude,
|
||||
label: {
|
||||
content: `${item?.code}`,
|
||||
color: '#000000',
|
||||
fontSize: 12,
|
||||
borderRadius: 5,
|
||||
bgColor: '#FFFFFF',
|
||||
// @ts-ignore
|
||||
padding: '5px 5px',
|
||||
borderWidth: 1
|
||||
},
|
||||
title: `${item.organization}`,
|
||||
name: item.organization
|
||||
})
|
||||
})
|
||||
setMarkers(arr)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const reload = () => {
|
||||
if(!Taro.getStorageSync('access_token')){
|
||||
return false;
|
||||
}
|
||||
if(!isAdmin){
|
||||
return false;
|
||||
}
|
||||
setMarkers([])
|
||||
setScale(12)
|
||||
pageHjmCar({keywords,deleted: 0}).then(res => {
|
||||
if(res?.count == 0){
|
||||
Taro.showToast({
|
||||
title: '没有搜索结果',
|
||||
icon: 'none'
|
||||
});
|
||||
return false
|
||||
}
|
||||
setList(res?.list || [])
|
||||
if (res?.list && res?.list.length > 0) {
|
||||
setScale(16)
|
||||
const data = res?.list[0];
|
||||
setLongitude(data?.longitude)
|
||||
setLatitude(data?.latitude)
|
||||
setMarkers([{
|
||||
id: data.id,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
title: `${data.organization}`,
|
||||
name: `${data.organization}`
|
||||
}])
|
||||
if(isAdmin){
|
||||
setMarkers([{
|
||||
id: data.id,
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
// @ts-ignore
|
||||
label: {
|
||||
content: `${data?.code}`,
|
||||
color: '#000000',
|
||||
fontSize: 12,
|
||||
borderRadius: 5,
|
||||
bgColor: '#FFFFFF',
|
||||
// @ts-ignore
|
||||
padding: '5px 5px',
|
||||
borderWidth: 1
|
||||
},
|
||||
title: `${data.organization}`,
|
||||
name: `${data.organization}`
|
||||
}])
|
||||
}
|
||||
}
|
||||
console.log(list.length,'carList.length')
|
||||
})
|
||||
@@ -165,7 +273,6 @@ function Home() {
|
||||
|
||||
useEffect(() => {
|
||||
// Taro.hideTabBar()
|
||||
setScale(14)
|
||||
getLocation().then()
|
||||
// 获取站点信息
|
||||
getSiteInfo().then((data) => {
|
||||
@@ -199,6 +306,11 @@ function Home() {
|
||||
})
|
||||
getUserInfo().then((data) => {
|
||||
if (data) {
|
||||
// 是否管理员
|
||||
console.log(data.certification, 'certification')
|
||||
if(data.certification){
|
||||
setIsAdmin(true)
|
||||
}
|
||||
setUserInfo(data)
|
||||
setIsLogin(true);
|
||||
Taro.setStorageSync('UserId', data.userId)
|
||||
@@ -241,12 +353,12 @@ function Home() {
|
||||
placeholder="车辆编号"
|
||||
value={keywords}
|
||||
onChange={onKeywords}
|
||||
onConfirm={reload}
|
||||
onConfirm={onQuery}
|
||||
/>
|
||||
<div
|
||||
className={'flex items-center'}
|
||||
>
|
||||
<Button type="warning" onClick={reload}>
|
||||
<Button type="warning" onClick={onQuery}>
|
||||
查询
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user