修改地图也页面登录跳转问题

This commit is contained in:
978184212@qq.com 2026-08-21 17:28:44 +08:00
parent 1337f99702
commit feac3406f9
3 changed files with 596 additions and 423 deletions

View File

@ -87,6 +87,7 @@
pageNo:1,
pageSize:4,
isRefresher: false, //
isLoading: false, //
}
},
onLoad() {
@ -111,62 +112,68 @@
refresherpullingFun() {
this.isRefresher= true
},
getList(){
let params = {}
params.pageNo = this.pageNo
params.pageSize = this.pageSize
uni.showLoading({
title: '加载中'
});
getList(isRefresh = false) {
//
if (this.isLoading) return
this.isLoading = true
let params = {
pageNo: this.pageNo,
pageSize: this.pageSize
}
// loading
if (this.pageNo === 1 && !isRefresh) {
uni.showLoading({ title: '加载中' })
}
//
if (this.pageNo === 1 && !isRefresh) {
this.List = []
this.$http.get('/applet/survStationInfo/page',{params:params}).then(res =>{
if(res.data.code == 0){
var data = res.data.data.records
}
this.$http.get('/applet/survStationInfo/page', { params }).then(res => {
this.isLoading = false
uni.hideLoading()
this.isRefresher = false
if (res.data.code === 0) {
let data = res.data.data.records || []
if (this.pageNo === 1) {
this.List = data
} else {
this.List = this.List.concat(data)
for(var i=0;i<this.List.length;i++){
if(this.List[i].deviceCount >= 10000 && this.List[i].deviceCount < 100000000){
this.List[i].deviceCount = (this.List[i].deviceCount /10000).toFixed(1) + '万'
}
if(this.List[i].deviceCount >= 100000000){
this.List[i].deviceCount = (this.List[i].deviceCount /100000000).toFixed(1) + '亿'
//
this.formatData()
//
this.updatePaginationStatus(res.data.data.total)
}
if(this.List[i].survObj.length >= 10000 && this.List[i].survObj.length < 100000000){
this.List[i].survObj.length = (this.List[i].survObj.length /10000).toFixed(1) + '万'
}
if(this.List[i].survObj.length >= 100000000){
this.List[i].survObj.length = (this.List[i].survObj.length /100000000).toFixed(1) + '亿'
}
if(this.List[i].survDataCount >= 10000 && this.List[i].survDataCount < 100000000){
this.List[i].survDataCount = (this.List[i].survDataCount /10000).toFixed(1) + '万'
}
if(this.List[i].survDataCount >= 100000000){
this.List[i].survDataCount = (this.List[i].survDataCount /100000000).toFixed(1) + '亿'
}
}
if(res.data.data.total != 0){
this.allNum = Number(res.data.data.total)/Number(this.pageSize)+'';
if(this.allNum.indexOf('.') == -1) {
this.allNum = this.allNum;
} else {
this.allNum = parseInt(Number(this.allNum)+1);
}
if(this.pageNo == this.allNum) {
this.isLastpage = true;
this.loadStatus='nomore'
} else {
this.isLastpage = false;
// this.isLoadMore=true
this.loadStatus = 'more'
}
}else{
this.isLastpage = true;
this.loadStatus='nomore'
}
}
uni.hideLoading();
this.isRefresher= false
}).catch(err => {
this.isLoading = false
uni.hideLoading()
this.isRefresher = false
})
},
formatData() {
//
this.List.forEach(item => {
item.deviceCount = this.formatNumber(item.deviceCount)
item.survObj.length = this.formatNumber(item.survObj.length)
item.survDataCount = this.formatNumber(item.survDataCount)
})
},
formatNumber(num) {
if (num >= 100000000) {
return (num / 100000000).toFixed(1) + '亿'
} else if (num >= 10000) {
return (num / 10000).toFixed(1) + '万'
}
return num || 0
},
lower() {
//
if (this.isLastpage) {

View File

@ -97,24 +97,28 @@ export default {
this.CustomTop = this.Custom.top
},
onShow() {
var that = this
//
const token = uni.getStorageSync('constant');
if (token) {
//
uni.reLaunch({
url: '/pages/index/index'
});
return;
}
//
var that = this;
uni.login({
success: function (res) {
that.code = res.code
let params = {}
params.jsCode = that.code
that.code = res.code;
let params = {};
params.jsCode = that.code;
api.wxlogin(params).then(res => {
let userInfo = res.data.data;
uni.setStorageSync('third_session', userInfo.thirdSession);
// api.loginCallback(res, ()=>{
// that.login = false
// uni.reLaunch({
// url: '/pages/index/index'
// })
// }, ()=>{
// that.login = true
// });
})
// session
});
}
});
},

View File

@ -50,9 +50,10 @@
</template>
<script>
import api from '@/api/api'
import selectSwitch from "@/components/xuan-switch/xuan-switch.vue";
export default {
import api from '@/api/api'
import selectSwitch from "@/components/xuan-switch/xuan-switch.vue";
export default {
components: {
selectSwitch
},
@ -72,118 +73,277 @@
stationInfo: [],
pestlightMarker: null,
stationlist: [],
timerSet: null
timerSet: null,
isDataLoaded: false,
isCheckingLogin: false, //
};
},
onLoad() {
// this.isscd = true
// this.getList()
this.$nextTick(() => {
this.getList()
})
},
onShow() {
var that = this
if (uni.getStorageSync('third_session')) {
uni.login({
success: function(res) {
console.log(res.code)
this.code = res.code
let params = {}
params.jsCode = this.code
console.log(params, 152)
api.wxlogin(params).then(res => {
console.log(res, 165)
if (res.data.code == 0) {
let userInfo = res.data.data;
// uni.setStorageSync('third_session', userInfo.thirdSession);
if (!userInfo.id) {
uni.reLaunch({
url: '/packDetail/pages/login/login'
})
} else {
// that.isscd = true
//
}
}
})
}
});
} else if (!uni.getStorageSync('third_session')) {
uni.reLaunch({
url: '/pages/loginindex'
})
}
onLoad() {
console.log('地图页面加载');
//
},
onShow() {
console.log('地图页面显示');
//
if (this.isCheckingLogin) {
return;
}
this.checkLoginStatus();
},
onReady() {
// 1.mapmapid
this.mapContext = uni.createMapContext("alarm_map", this);
},
methods: {
//
checkLoginStatus() {
this.isCheckingLogin = true;
const token = uni.getStorageSync('constant');
const session = uni.getStorageSync('third_session');
console.log('登录检查 - token:', !!token, 'session:', !!session);
// 1 ->
if (!token && !session) {
console.log('无登录凭证,跳转欢迎页');
this.isCheckingLogin = false;
uni.reLaunch({
url: '/pages/loginindex'
});
return;
}
// 2 third_session ->
if (session && !token) {
console.log('有session无token验证用户');
this.verifyUserInfo();
return;
}
// 3 ->
if (token) {
console.log('有完整登录信息,加载地图数据');
this.isCheckingLogin = false;
if (!this.isDataLoaded) {
this.getList();
}
}
},
//
verifyUserInfo() {
const that = this;
uni.login({
success: (res) => {
console.log('微信登录成功code:', res.code);
const params = {
jsCode: res.code
};
api.wxlogin(params).then(res => {
console.log('wxlogin接口返回:', res.data);
//
if (res.data.code === 0 && res.data.data) {
const userInfo = res.data.data;
//
if (userInfo.id && userInfo.id !== null && userInfo.id !== 'null') {
//
uni.setStorageSync('constant', userInfo);
console.log('用户验证通过保存token');
that.isCheckingLogin = false;
//
if (!that.isDataLoaded) {
that.getList();
}
} else {
//
console.log('用户信息不完整,跳转登录页');
that.isCheckingLogin = false;
that.clearCacheAndGoLogin();
}
} else {
//
console.log('接口返回错误:', res.data.msg || '未知错误');
that.isCheckingLogin = false;
that.clearCacheAndGoLogin();
}
}).catch((err) => {
console.error('wxlogin请求失败:', err);
that.isCheckingLogin = false;
that.clearCacheAndGoLogin();
});
},
fail: (err) => {
console.error('微信登录失败:', err);
that.isCheckingLogin = false;
that.clearCacheAndGoLogin();
}
});
},
// token
verifyToken() {
this.isCheckingLogin = false;
if (!this.isDataLoaded) {
this.getList();
}
},
//
clearCacheAndGoLogin() {
const keys = ['constant', 'third_session', 'userName', 'password'];
keys.forEach(key => {
uni.removeStorageSync(key);
});
uni.reLaunch({
url: '/packDetail/pages/login/login'
});
},
//
getList() {
this.markers = []
this.markersNoPest = []
this.pointers = []
this.list = []
//
if (this.isDataLoaded) {
console.log('数据已加载,跳过');
return;
}
//
const token = uni.getStorageSync('constant');
if (!token) {
console.log('没有登录token不加载数据');
return;
}
console.log('开始加载地图数据');
this.markers = [];
this.markersNoPest = [];
this.pointers = [];
this.list = [];
this.pestlight = [];
this.cusLocation = [];
this.stationInfo = [];
uni.showLoading({
title: '加载中'
});
this.$http.get('/applet/survStationInfo/stationMap').then(res => {
this.stationlist = [...res.data.data.pestlight, ...res.data.data.cusLocation, ...res.data.data.stationInfo]
this.stationlist.forEach((item,index) => {
console.log('地图接口返回:', res.data);
//
if (!res.data || res.data.code !== 0) {
console.error('地图数据加载失败:', res.data?.msg || '数据格式错误');
uni.hideLoading();
uni.showToast({
title: res.data?.msg || '加载失败',
icon: 'none'
});
//
if (res.data?.code === 401 || res.data?.code === 1001) {
this.clearCacheAndGoLogin();
}
return;
}
// data
if (!res.data.data) {
console.error('地图数据为空');
uni.hideLoading();
uni.showToast({
title: '暂无数据',
icon: 'none'
});
return;
}
//
const data = res.data.data;
const pestlightData = data.pestlight || [];
const cusLocationData = data.cusLocation || [];
const stationInfoData = data.stationInfo || [];
this.stationlist = [...pestlightData, ...cusLocationData, ...stationInfoData];
if (this.stationlist.length === 0) {
console.log('没有站点数据');
uni.hideLoading();
return;
}
this.stationlist.forEach((item, index) => {
item.id = index;
if(item.inType == 'pestlight'){
this.pestlight.push(item)
if (item.inType == 'pestlight') {
this.pestlight.push(item);
}
if(item.stationType == 'cusLocaltion'){
this.cusLocation.push(item)
if (item.stationType == 'cusLocaltion') {
this.cusLocation.push(item);
}
if(item.stationType == 'orient' || item.stationType == 'livestock'){
this.stationInfo.push(item)
if (item.stationType == 'orient' || item.stationType == 'livestock') {
this.stationInfo.push(item);
}
this.list.push({
latitude:Number(item.stationLatitude),
latitude: Number(item.stationLatitude),
longitude: Number(item.stationLongitude),
stationType:item.stationType,
stationType: item.stationType,
sortNo: item.sortNo,
stationName: item.stationName,
stationCode: item.stationCode
})
})
this.issscd = false
this.isssscd = false
this.qiyeChange()
this.list1query()
this.list2query()
});
});
this.issscd = false;
this.isssscd = false;
this.qiyeChange();
this.list1query();
this.list2query();
this.isDataLoaded = true;
uni.hideLoading();
})
console.log('地图数据加载完成,共', this.stationlist.length, '个站点');
}).catch(err => {
console.error('加载地图数据失败:', err);
uni.hideLoading();
//
uni.showToast({
title: '网络异常,请重试',
icon: 'none'
});
});
},
// stationlist
processStationList(stationlist) {
if (stationlist) {
if (stationlist && Array.isArray(stationlist)) {
stationlist.forEach(item => {
this.list.push({
latitude: item.inType === 'pestlight' ? Number(item.latitude) : Number(item
.stationLatitude),
longitude: item.inType === 'pestlight' ? Number(item.longitude) : Number(item
.stationLongitude),
latitude: item.inType === 'pestlight' ? Number(item.latitude) : Number(item.stationLatitude),
longitude: item.inType === 'pestlight' ? Number(item.longitude) : Number(item.stationLongitude),
stationType: item.inType === 'pestlight' ? 'pestlight' : item.stationType,
sortNo: item.sortNo,
stationName: item.stationName,
stationCode: item.stationCode
})
})
});
});
}
},
// pointers
generatePointers() {
const iconConfig = {
// pestlight: {
// iconPath: '/static/zhandian_sahchong_dingwei.png',
// width: 15,
// height: 20
// },
orient: {
iconPath: '/static/zhandian_nongtian_dingwei.png',
width: 35,
@ -199,12 +359,13 @@
width: 35,
height: 52
}
}
};
this.list.forEach((item, i) => {
const config = iconConfig[item.stationType] || {}
item.iconPath = config.iconPath || ''
item.width = config.width || 0
item.height = config.height || 0
const config = iconConfig[item.stationType] || {};
item.iconPath = config.iconPath || '';
item.width = config.width || 0;
item.height = config.height || 0;
this.pointers.push({
id: i,
iconPath: item.iconPath,
@ -213,37 +374,40 @@
width: item.width,
height: item.height,
customCallout: {
anchorY: 0, // Y
anchorX: 0, // X
display: 'ALWAYS' //
anchorY: 0,
anchorX: 0,
display: 'ALWAYS'
},
stationType: item.stationType,
stationName: item.stationName,
stationCode: item.stationCode,
joinCluster: true //
})
})
joinCluster: true
});
});
},
markertap(e) {
const index = e.detail.markerId
console.log(e.detail,'index')
if (['orient', 'livestock'].includes(this.list[index].stationType)) {
const index = e.detail.markerId;
if (this.list[index] && ['orient', 'livestock'].includes(this.list[index].stationType)) {
uni.navigateTo({
url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}`
})
});
}
},
callouttap(e) {
const index = e.detail.markerId
if (['orient', 'livestock'].includes(this.list[index].stationType)) {
const index = e.detail.markerId;
if (this.list[index] && ['orient', 'livestock'].includes(this.list[index].stationType)) {
uni.navigateTo({
url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}`
})
});
}
},
todetails(item) {
console.log(item, '还是个然后')
console.log(item, '还是个然后');
},
switch1Change() {
this.isscd = !this.isscd;
let index = 0;
@ -257,7 +421,6 @@
item.longitude = Number(item.longitude);
item.width = 15;
item.height = 20;
// markers
const markerItem = {
id: item.id,
iconPath: item.iconPath,
@ -266,32 +429,30 @@
width: item.width,
height: item.height,
customCallout: {
anchorY: 0, // Y
anchorX: 0, // X
display: 'ALWAYS' //
anchorY: 0,
anchorX: 0,
display: 'ALWAYS'
},
// stationType: item.stationType,
inType: item.inType,
stationName: item.stationName,
stationCode: item.stationCode,
joinCluster: false //
joinCluster: false
};
this.markers.push(markerItem);
index++;
}
// this.markers = this.markers.concat(aa);
if (index >= this.pestlight.length) {
clearInterval(this.timerSet);
}
}, 1000);
} else {
clearInterval(this.timerSet);
this.markers = this.markers.filter((item)=>{
return item.inType !== 'pestlight'
})
this.markers = this.markers.filter((item) => {
return item.inType !== 'pestlight';
});
}
},
qiyeChange() {
for (let i = 0; i < this.cusLocation.length; i++) {
const item = this.cusLocation[i];
@ -301,14 +462,13 @@
item.width = 35;
item.height = 52;
this.list.push({
latitude:Number(item.stationLatitude),
latitude: Number(item.stationLatitude),
longitude: Number(item.stationLongitude),
stationType:item.stationType,
stationType: item.stationType,
sortNo: item.sortNo,
stationName: item.stationName,
stationCode: item.stationCode
})
// markers
});
const markerItem = {
id: item.id,
iconPath: item.iconPath,
@ -317,37 +477,39 @@
width: item.width,
height: item.height,
customCallout: {
anchorY: 0, // Y
anchorX: 0, // X
display: 'ALWAYS' //
anchorY: 0,
anchorX: 0,
display: 'ALWAYS'
},
stationType: item.stationType,
stationName: item.stationName,
stationCode: item.stationCode,
joinCluster: true //
joinCluster: true
};
this.markers.push(markerItem);
}
},
switch2Change() {
this.issscd = !this.issscd
this.list1query()
this.issscd = !this.issscd;
this.list1query();
},
switch3Change() {
this.isssscd = !this.isssscd
this.list2query()
this.isssscd = !this.isssscd;
this.list2query();
},
list1query(){
list1query() {
if (!this.issscd) {
for (let i = 0; i < this.stationInfo.length; i++) {
const item = this.stationInfo[i];
if(item.stationType === 'orient'){
if (item.stationType === 'orient') {
item.iconPath = '/static/zhandian_nongtian_dingwei.png';
item.latitude = Number(item.stationLatitude);
item.longitude = Number(item.stationLongitude);
item.width = 35;
item.height = 52;
// markers
const markerItem = {
id: item.id,
iconPath: item.iconPath,
@ -356,35 +518,35 @@
width: item.width,
height: item.height,
customCallout: {
anchorY: 0, // Y
anchorX: 0, // X
display: 'ALWAYS' //
anchorY: 0,
anchorX: 0,
display: 'ALWAYS'
},
stationType: item.stationType,
stationName: item.stationName,
stationCode: item.stationCode,
joinCluster: true //
joinCluster: true
};
this.markers.push(markerItem);
}
}
} else {
this.markers = this.markers.filter((item)=>{
return item.stationType !== 'orient'
})
this.markers = this.markers.filter((item) => {
return item.stationType !== 'orient';
});
}
},
list2query(){
list2query() {
if (!this.isssscd) {
for (let i = 0; i < this.stationInfo.length; i++) {
const item = this.stationInfo[i];
if(item.stationType === 'livestock'){
if (item.stationType === 'livestock') {
item.iconPath = '/static/zhandian_xuqin_dingwei.png';
item.latitude = Number(item.stationLatitude);
item.longitude = Number(item.stationLongitude);
item.width = 35;
item.height = 52;
// markers
const markerItem = {
id: item.id,
iconPath: item.iconPath,
@ -393,26 +555,26 @@
width: item.width,
height: item.height,
customCallout: {
anchorY: 0, // Y
anchorX: 0, // X
display: 'ALWAYS' //
anchorY: 0,
anchorX: 0,
display: 'ALWAYS'
},
stationType: item.stationType,
stationName: item.stationName,
stationCode: item.stationCode,
joinCluster: true //
joinCluster: true
};
this.markers.push(markerItem);
}
}
} else {
this.markers = this.markers.filter((item)=>{
return item.stationType !== 'livestock'
})
}
this.markers = this.markers.filter((item) => {
return item.stationType !== 'livestock';
});
}
}
}
}
</script>
<style lang="scss">