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

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, pageNo:1,
pageSize:4, pageSize:4,
isRefresher: false, // isRefresher: false, //
isLoading: false, //
} }
}, },
onLoad() { onLoad() {
@ -111,62 +112,68 @@
refresherpullingFun() { refresherpullingFun() {
this.isRefresher= true this.isRefresher= true
}, },
getList(){ getList(isRefresh = false) {
let params = {} //
params.pageNo = this.pageNo if (this.isLoading) return
params.pageSize = this.pageSize this.isLoading = true
uni.showLoading({
title: '加载中' 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.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) 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){ }).catch(err => {
this.List[i].survObj.length = (this.List[i].survObj.length /10000).toFixed(1) + '万' this.isLoading = false
} uni.hideLoading()
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 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() { lower() {
// //
if (this.isLastpage) { if (this.isLastpage) {

View File

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

View File

@ -52,6 +52,7 @@
<script> <script>
import api from '@/api/api' import api from '@/api/api'
import selectSwitch from "@/components/xuan-switch/xuan-switch.vue"; import selectSwitch from "@/components/xuan-switch/xuan-switch.vue";
export default { export default {
components: { components: {
selectSwitch selectSwitch
@ -72,75 +73,224 @@
stationInfo: [], stationInfo: [],
pestlightMarker: null, pestlightMarker: null,
stationlist: [], 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() { onReady() {
// 1.mapmapid
this.mapContext = uni.createMapContext("alarm_map", this); this.mapContext = uni.createMapContext("alarm_map", this);
}, },
methods: { 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() { getList() {
this.markers = [] //
this.markersNoPest = [] if (this.isDataLoaded) {
this.pointers = [] console.log('数据已加载,跳过');
this.list = [] 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({ uni.showLoading({
title: '加载中' title: '加载中'
}); });
this.$http.get('/applet/survStationInfo/stationMap').then(res => { this.$http.get('/applet/survStationInfo/stationMap').then(res => {
this.stationlist = [...res.data.data.pestlight, ...res.data.data.cusLocation, ...res.data.data.stationInfo] 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) => { this.stationlist.forEach((item, index) => {
item.id = index; item.id = index;
if (item.inType == 'pestlight') { if (item.inType == 'pestlight') {
this.pestlight.push(item) this.pestlight.push(item);
} }
if (item.stationType == 'cusLocaltion') { if (item.stationType == 'cusLocaltion') {
this.cusLocation.push(item) this.cusLocation.push(item);
} }
if (item.stationType == 'orient' || item.stationType == 'livestock') { if (item.stationType == 'orient' || item.stationType == 'livestock') {
this.stationInfo.push(item) this.stationInfo.push(item);
} }
this.list.push({ this.list.push({
latitude: Number(item.stationLatitude), latitude: Number(item.stationLatitude),
@ -149,41 +299,51 @@
sortNo: item.sortNo, sortNo: item.sortNo,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode stationCode: item.stationCode
}) });
}) });
this.issscd = false
this.isssscd = false this.issscd = false;
this.qiyeChange() this.isssscd = false;
this.list1query() this.qiyeChange();
this.list2query() this.list1query();
this.list2query();
this.isDataLoaded = true;
uni.hideLoading(); uni.hideLoading();
}) console.log('地图数据加载完成,共', this.stationlist.length, '个站点');
}).catch(err => {
console.error('加载地图数据失败:', err);
uni.hideLoading();
//
uni.showToast({
title: '网络异常,请重试',
icon: 'none'
});
});
}, },
// stationlist // stationlist
processStationList(stationlist) { processStationList(stationlist) {
if (stationlist) { if (stationlist && Array.isArray(stationlist)) {
stationlist.forEach(item => { stationlist.forEach(item => {
this.list.push({ this.list.push({
latitude: item.inType === 'pestlight' ? Number(item.latitude) : Number(item latitude: item.inType === 'pestlight' ? Number(item.latitude) : Number(item.stationLatitude),
.stationLatitude), longitude: item.inType === 'pestlight' ? Number(item.longitude) : Number(item.stationLongitude),
longitude: item.inType === 'pestlight' ? Number(item.longitude) : Number(item
.stationLongitude),
stationType: item.inType === 'pestlight' ? 'pestlight' : item.stationType, stationType: item.inType === 'pestlight' ? 'pestlight' : item.stationType,
sortNo: item.sortNo, sortNo: item.sortNo,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode stationCode: item.stationCode
}) });
}) });
} }
}, },
// pointers // pointers
generatePointers() { generatePointers() {
const iconConfig = { const iconConfig = {
// pestlight: {
// iconPath: '/static/zhandian_sahchong_dingwei.png',
// width: 15,
// height: 20
// },
orient: { orient: {
iconPath: '/static/zhandian_nongtian_dingwei.png', iconPath: '/static/zhandian_nongtian_dingwei.png',
width: 35, width: 35,
@ -199,12 +359,13 @@
width: 35, width: 35,
height: 52 height: 52
} }
} };
this.list.forEach((item, i) => { this.list.forEach((item, i) => {
const config = iconConfig[item.stationType] || {} const config = iconConfig[item.stationType] || {};
item.iconPath = config.iconPath || '' item.iconPath = config.iconPath || '';
item.width = config.width || 0 item.width = config.width || 0;
item.height = config.height || 0 item.height = config.height || 0;
this.pointers.push({ this.pointers.push({
id: i, id: i,
iconPath: item.iconPath, iconPath: item.iconPath,
@ -213,37 +374,40 @@
width: item.width, width: item.width,
height: item.height, height: item.height,
customCallout: { customCallout: {
anchorY: 0, // Y anchorY: 0,
anchorX: 0, // X anchorX: 0,
display: 'ALWAYS' // display: 'ALWAYS'
}, },
stationType: item.stationType, stationType: item.stationType,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode, stationCode: item.stationCode,
joinCluster: true // joinCluster: true
}) });
}) });
}, },
markertap(e) { markertap(e) {
const index = e.detail.markerId const index = e.detail.markerId;
console.log(e.detail,'index') if (this.list[index] && ['orient', 'livestock'].includes(this.list[index].stationType)) {
if (['orient', 'livestock'].includes(this.list[index].stationType)) {
uni.navigateTo({ uni.navigateTo({
url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}` url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}`
}) });
} }
}, },
callouttap(e) { callouttap(e) {
const index = e.detail.markerId const index = e.detail.markerId;
if (['orient', 'livestock'].includes(this.list[index].stationType)) { if (this.list[index] && ['orient', 'livestock'].includes(this.list[index].stationType)) {
uni.navigateTo({ uni.navigateTo({
url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}` url: `/packDetail/pages/Site/detail?item=${encodeURIComponent(JSON.stringify(this.list[index]))}`
}) });
} }
}, },
todetails(item) { todetails(item) {
console.log(item, '还是个然后') console.log(item, '还是个然后');
}, },
switch1Change() { switch1Change() {
this.isscd = !this.isscd; this.isscd = !this.isscd;
let index = 0; let index = 0;
@ -257,7 +421,6 @@
item.longitude = Number(item.longitude); item.longitude = Number(item.longitude);
item.width = 15; item.width = 15;
item.height = 20; item.height = 20;
// markers
const markerItem = { const markerItem = {
id: item.id, id: item.id,
iconPath: item.iconPath, iconPath: item.iconPath,
@ -266,32 +429,30 @@
width: item.width, width: item.width,
height: item.height, height: item.height,
customCallout: { customCallout: {
anchorY: 0, // Y anchorY: 0,
anchorX: 0, // X anchorX: 0,
display: 'ALWAYS' // display: 'ALWAYS'
}, },
// stationType: item.stationType,
inType: item.inType, inType: item.inType,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode, stationCode: item.stationCode,
joinCluster: false // joinCluster: false
}; };
this.markers.push(markerItem); this.markers.push(markerItem);
index++; index++;
} }
// this.markers = this.markers.concat(aa);
if (index >= this.pestlight.length) { if (index >= this.pestlight.length) {
clearInterval(this.timerSet); clearInterval(this.timerSet);
} }
}, 1000); }, 1000);
} else { } else {
clearInterval(this.timerSet); clearInterval(this.timerSet);
this.markers = this.markers.filter((item) => { this.markers = this.markers.filter((item) => {
return item.inType !== 'pestlight' return item.inType !== 'pestlight';
}) });
} }
}, },
qiyeChange() { qiyeChange() {
for (let i = 0; i < this.cusLocation.length; i++) { for (let i = 0; i < this.cusLocation.length; i++) {
const item = this.cusLocation[i]; const item = this.cusLocation[i];
@ -307,8 +468,7 @@
sortNo: item.sortNo, sortNo: item.sortNo,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode stationCode: item.stationCode
}) });
// markers
const markerItem = { const markerItem = {
id: item.id, id: item.id,
iconPath: item.iconPath, iconPath: item.iconPath,
@ -317,26 +477,29 @@
width: item.width, width: item.width,
height: item.height, height: item.height,
customCallout: { customCallout: {
anchorY: 0, // Y anchorY: 0,
anchorX: 0, // X anchorX: 0,
display: 'ALWAYS' // display: 'ALWAYS'
}, },
stationType: item.stationType, stationType: item.stationType,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode, stationCode: item.stationCode,
joinCluster: true // joinCluster: true
}; };
this.markers.push(markerItem); this.markers.push(markerItem);
} }
}, },
switch2Change() { switch2Change() {
this.issscd = !this.issscd this.issscd = !this.issscd;
this.list1query() this.list1query();
}, },
switch3Change() { switch3Change() {
this.isssscd = !this.isssscd this.isssscd = !this.isssscd;
this.list2query() this.list2query();
}, },
list1query() { list1query() {
if (!this.issscd) { if (!this.issscd) {
for (let i = 0; i < this.stationInfo.length; i++) { for (let i = 0; i < this.stationInfo.length; i++) {
@ -347,7 +510,6 @@
item.longitude = Number(item.stationLongitude); item.longitude = Number(item.stationLongitude);
item.width = 35; item.width = 35;
item.height = 52; item.height = 52;
// markers
const markerItem = { const markerItem = {
id: item.id, id: item.id,
iconPath: item.iconPath, iconPath: item.iconPath,
@ -356,24 +518,25 @@
width: item.width, width: item.width,
height: item.height, height: item.height,
customCallout: { customCallout: {
anchorY: 0, // Y anchorY: 0,
anchorX: 0, // X anchorX: 0,
display: 'ALWAYS' // display: 'ALWAYS'
}, },
stationType: item.stationType, stationType: item.stationType,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode, stationCode: item.stationCode,
joinCluster: true // joinCluster: true
}; };
this.markers.push(markerItem); this.markers.push(markerItem);
} }
} }
} else { } else {
this.markers = this.markers.filter((item) => { this.markers = this.markers.filter((item) => {
return item.stationType !== 'orient' return item.stationType !== 'orient';
}) });
} }
}, },
list2query() { list2query() {
if (!this.isssscd) { if (!this.isssscd) {
for (let i = 0; i < this.stationInfo.length; i++) { for (let i = 0; i < this.stationInfo.length; i++) {
@ -384,7 +547,6 @@
item.longitude = Number(item.stationLongitude); item.longitude = Number(item.stationLongitude);
item.width = 35; item.width = 35;
item.height = 52; item.height = 52;
// markers
const markerItem = { const markerItem = {
id: item.id, id: item.id,
iconPath: item.iconPath, iconPath: item.iconPath,
@ -393,22 +555,22 @@
width: item.width, width: item.width,
height: item.height, height: item.height,
customCallout: { customCallout: {
anchorY: 0, // Y anchorY: 0,
anchorX: 0, // X anchorX: 0,
display: 'ALWAYS' // display: 'ALWAYS'
}, },
stationType: item.stationType, stationType: item.stationType,
stationName: item.stationName, stationName: item.stationName,
stationCode: item.stationCode, stationCode: item.stationCode,
joinCluster: true // joinCluster: true
}; };
this.markers.push(markerItem); this.markers.push(markerItem);
} }
} }
} else { } else {
this.markers = this.markers.filter((item) => { this.markers = this.markers.filter((item) => {
return item.stationType !== 'livestock' return item.stationType !== 'livestock';
}) });
} }
} }
} }