优化项目配置,重构项目URL管理逻辑,改为使用动态配置;更新灌溉组详情页面,添加详细信息展示和请求逻辑,提升用户体验;更新首页项目选择器,支持动态项目列表展示。
| | |
| | | const { |
| | | ENV |
| | | } = require('./env') |
| | | const { PROJECT_CONFIG } = require('../utils/projectConfig') |
| | | let BASEURL |
| | | |
| | | const PROJECT_URLS = { |
| | | JYG: 'https://irrigate.dayuyanjiuyuan.top/', // 嘉峪关项目 |
| | | MQ: 'https://shifanqu1.dayuyanjiuyuan.top/', // 民勤项目 |
| | | TEST: 'https://no253541tf71.vicp.fun/', // test项目 |
| | | SCHOOL: 'https://school.dayuyanjiuyuan.top/', // 学校项目 |
| | | JC:'https://shifanqu1.dayuyanjiuyuan.top/', |
| | | GSCLT:'https://irrigate.dayuyanjiuyuan.top/'//甘肃农科院崔龙天 |
| | | // TEST:'http://192.168.40.182:8087/'// test项目 |
| | | // MQ: 'https://no253541tf71.vicp.fun/' // 民勤项目 |
| | | // TEST: 'http://192.168.40.166:54321/' |
| | | } |
| | | |
| | | // 尝试从本地存储获取已选择的项目 |
| | | let selectedProject = 'JYG'; // 默认为嘉峪关项目 |
| | |
| | | console.error('获取已选择项目失败:', e); |
| | | } |
| | | |
| | | switch (ENV) { |
| | | case 'production': |
| | | BASEURL = PROJECT_URLS[selectedProject] || PROJECT_URLS.JYG; |
| | | break; |
| | | case 'test': |
| | | // BASEURL 将根据用户选择的项目动态设置 |
| | | BASEURL = PROJECT_URLS[selectedProject] || PROJECT_URLS.JYG; |
| | | break; |
| | | default: |
| | | BASEURL = PROJECT_URLS[selectedProject] || PROJECT_URLS.JYG; |
| | | break; |
| | | } |
| | | // 根据环境和项目设置BASEURL |
| | | BASEURL = PROJECT_CONFIG[selectedProject]?.serverUrl || PROJECT_CONFIG.JYG.serverUrl; |
| | | |
| | | // 导出动态设置 BASEURL 的函数 |
| | | function setBaseUrl(project) { |
| | | if (PROJECT_URLS[project]) { |
| | | BASEURL = PROJECT_URLS[project]; |
| | | const serverUrl = PROJECT_CONFIG[project]?.serverUrl; |
| | | if (serverUrl) { |
| | | BASEURL = serverUrl; |
| | | console.log('动态设置 BASEURL:', BASEURL); |
| | | return true; |
| | | } |
| | | console.error('项目配置不存在或未设置服务器地址:', project); |
| | | return false; |
| | | } |
| | | |
| | | module.exports = { |
| | | BASEURL, // 项目接口地址,支持多域名 |
| | | PROJECT_URLS, |
| | | setBaseUrl |
| | | } |
| | |
| | | * 跳转到轮灌组详情页 |
| | | */ |
| | | navigateToGroupDetail: function (e) { |
| | | const { |
| | | groupIndex |
| | | } = e.currentTarget.dataset; |
| | | // TODO: 实现跳转逻辑 |
| | | const { groupIndex } = e.currentTarget.dataset; |
| | | const group = this.data.selectedProject.groups[groupIndex]; |
| | | |
| | | // 构建URL参数 |
| | | const params = { |
| | | projectName: this.data.selectedProject.name, |
| | | groupName: group.name, |
| | | groupId: group.id |
| | | }; |
| | | |
| | | // 构建URL查询字符串 |
| | | const queryString = Object.keys(params) |
| | | .map(key => `${key}=${encodeURIComponent(params[key])}`) |
| | | .join('&'); |
| | | |
| | | // 跳转到轮灌组详情页 |
| | | wx.navigateTo({ |
| | | url: `/pages/groupDetail/groupDetail?${queryString}` |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | |
| | | refreshing: true |
| | | }); |
| | | |
| | | console.log('加载取水口数据,灌溉状态:', this.data.isIrrigating); |
| | | console.log('开始加载轮灌组详情,groupId:', this.data.groupId); |
| | | |
| | | // 模拟数据 |
| | | let mockData = { |
| | | waterOutlets: [] |
| | | }; |
| | | |
| | | // 生成取水口数据,所有取水口都有命令状态 |
| | | mockData.waterOutlets = [ |
| | | { |
| | | id: 1, |
| | | name: '取水口 A-1', |
| | | status: 'online', |
| | | commandStatus: 'sent' // 命令已下发 |
| | | }, |
| | | { |
| | | id: 2, |
| | | name: '取水口 A-2', |
| | | status: 'online', |
| | | commandStatus: 'unsent' // 命令未下发 |
| | | }, |
| | | { |
| | | id: 3, |
| | | name: '取水口 A-3', |
| | | status: 'offline', |
| | | commandStatus: 'unsent' // 命令未下发 |
| | | // 检查apiBaseUrl是否存在 |
| | | if (!app.globalData.apiBaseUrl) { |
| | | try { |
| | | // 从config模块获取基础URL |
| | | const config = require('../../api/config'); |
| | | const { PROJECT_CONFIG } = require('../../utils/projectConfig'); |
| | | |
| | | // 获取当前选中的项目标识 |
| | | const tag = wx.getStorageSync('projectTag') || app.globalData.tag || 'mq'; |
| | | |
| | | // 根据tag找到对应项目配置 |
| | | let selectedProject = 'MQ'; // 默认为民勤项目 |
| | | for (const key in PROJECT_CONFIG) { |
| | | if (PROJECT_CONFIG[key].tag === tag) { |
| | | selectedProject = key; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 设置apiBaseUrl |
| | | app.globalData.apiBaseUrl = PROJECT_CONFIG[selectedProject].serverUrl; |
| | | console.log('从配置中获取apiBaseUrl:', app.globalData.apiBaseUrl); |
| | | } catch (error) { |
| | | console.error('获取apiBaseUrl失败:', error); |
| | | // 使用请求库中的方法 |
| | | const { get } = require('../../api/request'); |
| | | |
| | | get({ |
| | | url: '/wx/irrigation/getGroupDetails', |
| | | data: { groupId: this.data.groupId }, |
| | | isShowLoding: true |
| | | }).then(res => { |
| | | if (res.success) { |
| | | this.handleGroupDetailsResponse(res); |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.msg || '获取数据失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }).catch(err => { |
| | | console.error('请求失败:', err); |
| | | wx.showToast({ |
| | | title: '网络错误', |
| | | icon: 'none' |
| | | }); |
| | | }).finally(() => { |
| | | this.setData({ |
| | | refreshing: false |
| | | }); |
| | | }); |
| | | |
| | | return; // 已经使用请求库处理,直接返回 |
| | | } |
| | | ]; |
| | | } |
| | | |
| | | // 模拟网络请求延迟 |
| | | setTimeout(() => { |
| | | // 使用wx.request发送请求 |
| | | wx.request({ |
| | | url: `${app.globalData.apiBaseUrl}/wx/irrigation/getGroupDetails`, |
| | | method: 'GET', |
| | | data: { |
| | | groupId: this.data.groupId |
| | | }, |
| | | header: { |
| | | 'content-type': 'application/json', |
| | | 'Authorization': wx.getStorageSync('token') || '', |
| | | 'tag': wx.getStorageSync('projectTag') || app.globalData.tag || '', |
| | | 'appId': app.globalData.AppID || '' |
| | | }, |
| | | success: (res) => { |
| | | console.log('轮灌组详情接口返回:', res.data); |
| | | |
| | | if (res.data && res.data.success) { |
| | | this.handleGroupDetailsResponse(res.data); |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.data.msg || '获取数据失败', |
| | | icon: 'none' |
| | | }); |
| | | this.setData({ |
| | | refreshing: false |
| | | }); |
| | | } |
| | | }, |
| | | fail: (err) => { |
| | | console.error('请求失败:', err); |
| | | // 尝试使用请求库重试 |
| | | this.retryUsingRequestLib(); |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 使用请求库重试获取数据 |
| | | */ |
| | | retryUsingRequestLib: function() { |
| | | console.log('使用请求库重试获取数据'); |
| | | const { get } = require('../../api/request'); |
| | | |
| | | get({ |
| | | url: '/wx/irrigation/getGroupDetails', |
| | | data: { groupId: this.data.groupId }, |
| | | isShowLoding: true |
| | | }).then(res => { |
| | | if (res.success) { |
| | | this.handleGroupDetailsResponse(res); |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.msg || '获取数据失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }).catch(err => { |
| | | console.error('请求库重试失败:', err); |
| | | wx.showToast({ |
| | | title: '网络错误', |
| | | icon: 'none' |
| | | }); |
| | | }).finally(() => { |
| | | this.setData({ |
| | | waterOutletList: mockData.waterOutlets, |
| | | refreshing: false |
| | | }); |
| | | console.log('设置取水口数据完成:', this.data.waterOutletList); |
| | | }, 1000); |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 处理轮灌组详情响应数据 |
| | | */ |
| | | handleGroupDetailsResponse: function(response) { |
| | | const data = response.content; |
| | | |
| | | // 实际项目中应该使用wx.request获取数据 |
| | | // wx.request({ |
| | | // url: `https://your-api-url/groups/${this.data.groupId}/waterOutlets`, |
| | | // method: 'GET', |
| | | // success: (res) => { |
| | | // if (res.data && res.data.code === 0) { |
| | | // this.setData({ |
| | | // waterOutletList: res.data.data.waterOutlets, |
| | | // refreshing: false |
| | | // }); |
| | | // } else { |
| | | // wx.showToast({ |
| | | // title: '获取数据失败', |
| | | // icon: 'none' |
| | | // }); |
| | | // this.setData({ |
| | | // refreshing: false |
| | | // }); |
| | | // } |
| | | // }, |
| | | // fail: () => { |
| | | // wx.showToast({ |
| | | // title: '网络错误', |
| | | // icon: 'none' |
| | | // }); |
| | | // this.setData({ |
| | | // refreshing: false |
| | | // }); |
| | | // } |
| | | // }); |
| | | // 处理取水口数据 |
| | | const waterOutletList = data.intakes.map(item => { |
| | | return { |
| | | id: item.rtuAddr, // 使用rtuAddr作为ID |
| | | name: item.intakeName, |
| | | rtuAddr: item.rtuAddr, |
| | | status: item.isOnLine ? 'online' : 'offline' |
| | | }; |
| | | }); |
| | | |
| | | this.setData({ |
| | | projectName: data.projectName || this.data.projectName, |
| | | groupName: data.groupName || this.data.groupName, |
| | | waterOutletList: waterOutletList, |
| | | refreshing: false |
| | | }); |
| | | |
| | | console.log('设置取水口数据完成:', this.data.waterOutletList); |
| | | }, |
| | | |
| | | /** |
| | |
| | | <view class="page-header"> |
| | | <view class="header-content"> |
| | | <view class="project-info"> |
| | | <view class="project-name">{{projectName}}</view> |
| | | <view class="project-name"> |
| | | <text class="project-label">所属项目:</text> |
| | | <text>{{projectName}}</text> |
| | | </view> |
| | | <view class="group-name">{{groupName}}</view> |
| | | </view> |
| | | </view> |
| | |
| | | <block wx:for="{{waterOutletList}}" wx:key="id"> |
| | | <view class="valve-item"> |
| | | <view class="valve-info"> |
| | | <view class="valve-name"> |
| | | <text>{{item.name}}</text> |
| | | <view class="valve-status-inline {{item.status === 'online' ? 'online' : 'offline'}}"> |
| | | {{item.status === 'online' ? '在线' : '离线'}} |
| | | </view> |
| | | <view class="valve-name-container"> |
| | | <text class="name-text">{{item.name}}</text> |
| | | </view> |
| | | <view class="valve-rtu-addr"> |
| | | <text class="rtu-label">设备地址: </text> |
| | | <text class="rtu-value">{{item.rtuAddr}}</text> |
| | | </view> |
| | | </view> |
| | | <view class="command-status {{item.commandStatus}}"> |
| | | {{item.commandStatus === 'sent' ? '命令已下发' : '命令未下发'}} |
| | | <view class="valve-status-container"> |
| | | <view class="valve-status-inline {{item.status === 'online' ? 'online' : 'offline'}}"> |
| | | {{item.status === 'online' ? '在线' : '离线'}} |
| | | </view> |
| | | </view> |
| | | </view> |
| | | </block> |
| | |
| | | font-size: 28rpx; |
| | | color: #666666; |
| | | margin-bottom: 10rpx; |
| | | display: flex; |
| | | align-items: center; |
| | | } |
| | | |
| | | .project-label { |
| | | color: #999999; |
| | | margin-right: 8rpx; |
| | | } |
| | | |
| | | .group-name { |
| | |
| | | |
| | | .valve-info { |
| | | flex: 1; |
| | | margin-right: 20rpx; |
| | | overflow: hidden; |
| | | } |
| | | |
| | | .valve-name { |
| | | .valve-name-container { |
| | | font-size: 32rpx; |
| | | font-weight: 500; |
| | | color: #333333; |
| | | margin-bottom: 12rpx; |
| | | width: 100%; |
| | | overflow: hidden; |
| | | } |
| | | |
| | | .name-text { |
| | | display: inline-block; |
| | | max-width: 100%; |
| | | overflow: hidden; |
| | | text-overflow: ellipsis; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | .valve-rtu-addr { |
| | | font-size: 24rpx; |
| | | color: #666666; |
| | | display: flex; |
| | | align-items: center; |
| | | flex-wrap: wrap; |
| | | } |
| | | |
| | | .rtu-label { |
| | | color: #999999; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | .rtu-value { |
| | | overflow: hidden; |
| | | text-overflow: ellipsis; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | .valve-status-container { |
| | | display: flex; |
| | | flex-direction: column; |
| | | align-items: flex-end; |
| | | justify-content: center; |
| | | min-width: 100rpx; |
| | | } |
| | | |
| | | .valve-status { |
| | |
| | | .valve-status-inline { |
| | | font-size: 24rpx; |
| | | font-weight: 500; |
| | | padding: 4rpx 12rpx; |
| | | border-radius: 20rpx; |
| | | margin-left: 12rpx; |
| | | display: inline-flex; |
| | | padding: 8rpx 20rpx; |
| | | border-radius: 30rpx; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | height: 32rpx; |
| | | height: 36rpx; |
| | | line-height: 1; |
| | | min-width: 80rpx; |
| | | text-align: center; |
| | | white-space: nowrap; |
| | | } |
| | | |
| | | .valve-status-inline.online { |
| | | background-color: rgba(82, 196, 26, 0.1); |
| | | color: #52C41A; |
| | | border: 1rpx solid rgba(82, 196, 26, 0.3); |
| | | } |
| | | |
| | | .valve-status-inline.offline { |
| | | background-color: rgba(245, 34, 45, 0.1); |
| | | color: #F5222D; |
| | | border: 1rpx solid rgba(245, 34, 45, 0.3); |
| | | } |
| | | |
| | | /* 命令状态样式 */ |
| | |
| | | get, |
| | | post |
| | | } = require('../../api/request.js'); |
| | | const { |
| | | PROJECT_URLS |
| | | } = require('../../api/config.js'); |
| | | const config = require('../../api/config.js'); |
| | | const { |
| | | PROJECT_CONFIG |
| | | } = require('../../utils/projectConfig.js'); |
| | | const { |
| | | ENV |
| | | } = require('../../api/env.js'); |
| | | |
| | | Page({ |
| | | |
| | |
| | | isFromLogin: false, |
| | | showTipDialog: '', |
| | | projectConfig: PROJECT_CONFIG, // 添加项目配置到data中 |
| | | showInfoDialog: false |
| | | showInfoDialog: false, |
| | | projectList: [] |
| | | }, |
| | | |
| | | openValve: function (e) { |
| | |
| | | */ |
| | | onLoad(options) { |
| | | console.log('home页面onLoad开始,参数:', options); |
| | | |
| | | // 初始化项目列表数据 |
| | | this.initProjectList(); |
| | | |
| | | //当开阀成功后调用刷新 |
| | | if (options.param === "1" || options.param === "2") { |
| | | this.setData({ |
| | |
| | | }, 100); |
| | | }, |
| | | |
| | | // 初始化项目列表数据 |
| | | initProjectList() { |
| | | // 将PROJECT_CONFIG对象转换为数组,方便在视图中遍历 |
| | | const projectList = Object.entries(PROJECT_CONFIG).map(([key, config]) => ({ |
| | | key: key, // 使用key作为项目标识(JYG、MQ等) |
| | | tag: config.tag, // 保留tag字段(原配置中已有的标识,如ym、mq等) |
| | | displayName: config.displayName, // 显示名称 |
| | | ...config // 其他配置属性 |
| | | })); |
| | | |
| | | // 获取当前已选择的项目,默认为JYG |
| | | let currentSelectedProject = 'JYG'; |
| | | |
| | | // 尝试从全局变量获取 |
| | | const app = getApp(); |
| | | if (app && app.globalData && app.globalData.selectedProject) { |
| | | currentSelectedProject = app.globalData.selectedProject; |
| | | } else { |
| | | // 尝试从本地存储获取 |
| | | try { |
| | | const savedProject = wx.getStorageSync('selectedProject'); |
| | | if (savedProject) { |
| | | currentSelectedProject = savedProject; |
| | | } |
| | | } catch (e) { |
| | | console.error('从本地存储获取项目失败:', e); |
| | | } |
| | | } |
| | | |
| | | // 设置到页面数据中 |
| | | this.setData({ |
| | | projectList, |
| | | selectedProject: currentSelectedProject |
| | | }); |
| | | |
| | | console.log('项目列表已初始化:', projectList, '当前选中项目:', currentSelectedProject); |
| | | }, |
| | | |
| | | // 新增的初始化页面辅助函数,分离出onLoad中的逻辑以便延迟执行 |
| | | initializePage(options, fromLogin) { |
| | | // 检查是否已选择项目 |
| | |
| | | }); |
| | | |
| | | // 设置 baseUrl |
| | | const baseUrl = PROJECT_URLS[project]; |
| | | getApp().globalData.baseUrl = baseUrl; |
| | | getApp().globalData.selectedProject = project; |
| | | const serverUrl = PROJECT_CONFIG[project]?.serverUrl; |
| | | if (serverUrl) { |
| | | getApp().globalData.baseUrl = serverUrl; |
| | | getApp().globalData.selectedProject = project; |
| | | console.log('设置baseUrl:', serverUrl); |
| | | } |
| | | |
| | | // 根据项目设置对应的tag |
| | | const projectConfig = PROJECT_CONFIG[project]; |
| | |
| | | const currentProject = getApp().globalData.selectedProject; |
| | | const projectConfig = PROJECT_CONFIG[currentProject]; |
| | | |
| | | // 如果当前项目配置为不需要登录,则提示用户不可解绑 |
| | | // 如果当前项目配置为不需要登录,则提示用户并打开项目选择弹窗 |
| | | if (projectConfig && !projectConfig.needLogin) { |
| | | wx.showToast({ |
| | | title: '当前用户不可解绑', |
| | | icon: 'none', |
| | | duration: 2000 |
| | | wx.showModal({ |
| | | title: '切换项目', |
| | | content: '是否确定解绑?', |
| | | confirmText: '确认', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 显示项目选择弹窗 |
| | | this.setData({ |
| | | showProjectDialog: true |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | // 如果已登录,显示解绑确认对话框 |
| | | if (getApp().globalData.isLoggedIn) { |
| | | wx.showModal({ |
| | | title: '解绑确认', |
| | | content: '确定要解绑当前账号吗?', |
| | | content: '确定要解绑当前账号吗?解绑后将无法使用相关功能,需重新绑定。', |
| | | confirmText: '确认解绑', |
| | | confirmColor: '#e34d59', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | this.unBindPost() |
| | | this.unBindPost(); |
| | | } |
| | | } |
| | | }); |
| | |
| | | wx.showToast({ |
| | | title: '还未绑定', |
| | | icon: 'error' |
| | | }) |
| | | }); |
| | | } |
| | | }, |
| | | //轮灌 |
| | |
| | | |
| | | // 处理项目选择确认 |
| | | handleProjectConfirm() { |
| | | console.log('开始处理项目选择确认', this.data.selectedProject, this.data.projectList); |
| | | |
| | | if (!this.data.selectedProject) { |
| | | wx.showToast({ |
| | | title: '请选择项目', |
| | |
| | | // 获取当前已选项目和新选择的项目 |
| | | const currentProject = getApp().globalData.selectedProject; |
| | | const newProject = this.data.selectedProject; |
| | | console.log('当前项目:', currentProject, '新选择项目:', newProject); |
| | | console.log('PROJECT_CONFIG 内容:', PROJECT_CONFIG); |
| | | |
| | | const projectConfig = PROJECT_CONFIG[newProject]; |
| | | console.log('选择的项目配置:', projectConfig); |
| | | |
| | | if (!projectConfig) { |
| | | wx.showToast({ |
| | |
| | | // 检查是否切换了项目(如果当前项目不同于新选择的项目) |
| | | const isProjectChanged = currentProject && currentProject !== newProject; |
| | | |
| | | // 添加二次确认 |
| | | const confirmText = isProjectChanged |
| | | ? `确定要将项目从"${PROJECT_CONFIG[currentProject]?.displayName || '当前项目'}"切换到"${projectConfig.displayName}"吗?` |
| | | : `确定选择"${projectConfig.displayName}"项目吗?`; |
| | | |
| | | wx.showModal({ |
| | | title: isProjectChanged ? '确认切换项目' : '确认选择项目', |
| | | content: confirmText, |
| | | confirmText: isProjectChanged ? '确认切换' : '确认', |
| | | cancelText: '取消', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | // 用户确认选择,继续处理 |
| | | this.processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged); |
| | | } else { |
| | | // 用户取消,不进行任何操作 |
| | | console.log('用户取消了项目选择'); |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 处理项目选择的后续操作 |
| | | processProjectSelection(currentProject, newProject, projectConfig, isProjectChanged) { |
| | | // 如果切换了项目,先清除登录状态 |
| | | if (isProjectChanged) { |
| | | console.log(`正在从项目 ${currentProject} 切换到 ${newProject},将清除登录状态`); |
| | |
| | | |
| | | // 保存项目选择到本地存储 |
| | | storage.setItem('selectedProject', newProject).then(() => { |
| | | // 更新 BASEURL |
| | | const baseUrl = PROJECT_URLS[newProject]; |
| | | |
| | | // 调用setBaseUrl来更新基础URL |
| | | try { |
| | | console.log('尝试设置基础URL,项目:', newProject); |
| | | const result = config.setBaseUrl(newProject); |
| | | console.log('设置基础URL结果:', result); |
| | | } catch (error) { |
| | | console.error('设置基础URL出错:', error); |
| | | // 继续执行,不中断流程 |
| | | } |
| | | |
| | | // 更新全局变量 |
| | | getApp().globalData = getApp().globalData || {}; |
| | | getApp().globalData.baseUrl = baseUrl; |
| | | getApp().globalData.selectedProject = newProject; |
| | | getApp().globalData.baseUrl = projectConfig.serverUrl; |
| | | getApp().globalData.serverId = projectConfig.serverId; |
| | | |
| | | // 通过配置对象统一设置项目参数 |
| | | getApp().globalData.tag = projectConfig.tag; |
| | |
| | | storage.setItem(`${newProject}_params`, params); |
| | | } |
| | | |
| | | console.log('已切换到项目:', projectConfig.displayName, '域名:', baseUrl, 'tag:', getApp().globalData.tag); |
| | | console.log('已切换到项目:', projectConfig.displayName, '服务器:', projectConfig.serverId, 'tag:', getApp().globalData.tag); |
| | | |
| | | this.setData({ |
| | | showProjectDialog: false |
| | |
| | | return `${hours}:${minutes}:${seconds}`; |
| | | }, |
| | | |
| | | // 切换项目 |
| | | switchProject(e) { |
| | | const project = e.currentTarget.dataset.project; |
| | | |
| | | if (config.setBaseUrl(project)) { |
| | | this.setData({ |
| | | selectedProject: project |
| | | }); |
| | | |
| | | // 保存选择到本地存储 |
| | | try { |
| | | wx.setStorageSync('selectedProject', project); |
| | | } catch (e) { |
| | | console.error('保存项目选择失败:', e); |
| | | } |
| | | |
| | | // 更新全局变量 |
| | | const app = getApp(); |
| | | if (app && app.globalData) { |
| | | app.globalData.selectedProject = project; |
| | | |
| | | // 根据项目配置设置相关参数 |
| | | const projectConfig = PROJECT_CONFIG[project]; |
| | | if (projectConfig) { |
| | | app.globalData.tag = projectConfig.tag; |
| | | if (!projectConfig.needLogin) { |
| | | app.globalData.operator = projectConfig.operatorId; |
| | | app.globalData.clientId = projectConfig.operatorId; |
| | | app.globalData.isLoggedIn = true; |
| | | app.globalData.sessionId = projectConfig.operatorId; |
| | | // 如果有vcId,也设置 |
| | | if (projectConfig.vcId) { |
| | | app.globalData.vcId = projectConfig.vcId; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 重新加载页面数据 |
| | | this.initData(); |
| | | } else { |
| | | wx.showToast({ |
| | | title: '切换项目失败', |
| | | icon: 'none' |
| | | }); |
| | | } |
| | | }, |
| | | }) |
| | |
| | | <text class="project-modal-title">请选择项目</text> |
| | | </view> |
| | | <view class="project-modal-body"> |
| | | |
| | | <radio-group class="project-radio-group" bindchange="onProjectChange"> |
| | | <label class="project-radio {{selectedProject === 'JYG' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="JYG" checked="{{selectedProject === 'JYG'}}" color="#1890FF" /> |
| | | <text>嘉峪关项目</text> |
| | | </label> |
| | | <label class="project-radio {{selectedProject === 'MQ' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="MQ" checked="{{selectedProject === 'MQ'}}" color="#1890FF" /> |
| | | <text>民勤项目</text> |
| | | </label> |
| | | <label class="project-radio {{selectedProject === 'TEST' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="TEST" checked="{{selectedProject === 'TEST'}}" color="#1890FF" /> |
| | | <text>测试项目</text> |
| | | </label> |
| | | <label class="project-radio {{selectedProject === 'SCHOOL' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="SCHOOL" checked="{{selectedProject === 'SCHOOL'}}" color="#1890FF" /> |
| | | <text>学校项目</text> |
| | | </label> |
| | | <label class="project-radio {{selectedProject === 'JC' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="JC" checked="{{selectedProject === 'JC'}}" color="#1890FF" /> |
| | | <text>金昌项目</text> |
| | | </label> |
| | | <label class="project-radio {{selectedProject === 'GSCLT' ? 'project-radio-selected' : ''}}"> |
| | | <radio value="GSCLT" checked="{{selectedProject === 'GSCLT'}}" color="#1890FF" /> |
| | | <text>甘肃农科院-崔</text> |
| | | </label> |
| | | </radio-group> |
| | | <scroll-view scroll-y class="project-scroll-view"> |
| | | <radio-group class="project-radio-group" bindchange="onProjectChange"> |
| | | <label wx:for="{{projectList}}" wx:key="index" class="project-radio {{selectedProject === item.key ? 'project-radio-selected' : ''}}"> |
| | | <radio value="{{item.key}}" checked="{{selectedProject === item.key}}" color="#1890FF" /> |
| | | <text>{{item.displayName}}</text> |
| | | </label> |
| | | </radio-group> |
| | | </scroll-view> |
| | | </view> |
| | | <view class="project-modal-footer"> |
| | | <button class="project-modal-btn" disabled="{{!selectedProject}}" bindtap="handleProjectConfirm">确认</button> |
| | |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | z-index: 9999; |
| | | display: flex; |
| | | align-items: center; |
| | | justify-content: center; |
| | | z-index: 999; |
| | | } |
| | | |
| | | .project-modal-mask { |
| | |
| | | left: 0; |
| | | right: 0; |
| | | bottom: 0; |
| | | background-color: rgba(0, 0, 0, 0.6); |
| | | background-color: rgba(0, 0, 0, 0.5); |
| | | } |
| | | |
| | | .project-modal-content { |
| | | position: relative; |
| | | width: 80%; |
| | | position: absolute; |
| | | top: 50%; |
| | | left: 50%; |
| | | transform: translate(-50%, -50%); |
| | | width: 85%; |
| | | max-width: 600rpx; |
| | | background-color: #fff; |
| | | border-radius: 16rpx; |
| | |
| | | } |
| | | |
| | | .project-modal-header { |
| | | padding: 30rpx; |
| | | padding: 24rpx; |
| | | text-align: center; |
| | | border-bottom: 1rpx solid #f0f0f0; |
| | | } |
| | | |
| | | .project-modal-title { |
| | | font-size: 36rpx; |
| | | font-size: 32rpx; |
| | | font-weight: bold; |
| | | color: #333; |
| | | border-bottom: 1rpx solid #eee; |
| | | } |
| | | |
| | | .project-modal-body { |
| | | padding: 30rpx; |
| | | padding: 0; |
| | | max-height: 60vh; |
| | | } |
| | | |
| | | .project-modal-tip { |
| | | display: block; |
| | | font-size: 28rpx; |
| | | color: #999; |
| | | margin-bottom: 30rpx; |
| | | text-align: center; |
| | | .project-scroll-view { |
| | | max-height: 55vh; /* 稍微减小高度,确保在小屏幕上也能看到底部按钮 */ |
| | | height: auto; |
| | | } |
| | | |
| | | .project-radio-group { |
| | | display: flex; |
| | | flex-direction: column; |
| | | gap: 20rpx; |
| | | width: 100%; |
| | | } |
| | | |
| | | .project-radio { |
| | | padding: 24rpx; |
| | | display: flex; |
| | | align-items: center; |
| | | padding: 20rpx; |
| | | background-color: #f5f5f5; |
| | | border-radius: 8rpx; |
| | | border-bottom: 1rpx solid #f5f5f5; |
| | | width: 100%; |
| | | box-sizing: border-box; |
| | | } |
| | | |
| | | .project-radio-selected { |
| | | background-color: #e6f4ff; |
| | | border: 2rpx solid #1890FF; |
| | | .project-radio radio { |
| | | margin-right: 16rpx; |
| | | } |
| | | |
| | | .project-radio text { |
| | | margin-left: 10rpx; |
| | | font-size: 32rpx; |
| | | font-size: 30rpx; |
| | | color: #333; |
| | | } |
| | | |
| | | .project-radio-selected { |
| | | background-color: #f0f9ff; |
| | | } |
| | | |
| | | .project-modal-footer { |
| | | padding: 30rpx; |
| | | border-top: 1rpx solid #f0f0f0; |
| | | padding: 24rpx; |
| | | border-top: 1rpx solid #eee; |
| | | } |
| | | |
| | | .project-modal-btn { |
| | | width: 100%; |
| | | height: 80rpx; |
| | | line-height: 80rpx; |
| | | text-align: center; |
| | | background-color: #1890FF; |
| | | color: #fff; |
| | | font-size: 32rpx; |
| | | color: white; |
| | | border-radius: 8rpx; |
| | | font-size: 28rpx; |
| | | padding: 16rpx 0; |
| | | } |
| | | |
| | | .project-modal-btn[disabled] { |
| | | background-color: #cccccc; |
| | | color: #ffffff; |
| | | color: #666666; |
| | | } |
| | | |
| | | .info-img { |
| | |
| | | // 项目配置,包含各项目的专有设置 |
| | | // 服务器地址配置 |
| | | const SERVER_INFO = { |
| | | URL_233: 'https://sp.dayuyanjiuyuan.top/', |
| | | URL_55: 'https://irrigate.dayuyanjiuyuan.top/', |
| | | URL_166: 'https://no253541tf71.vicp.fun/', |
| | | URL_121: 'https://shifanqu1.dayuyanjiuyuan.top/' |
| | | }; |
| | | |
| | | const PROJECT_CONFIG = { |
| | | JYG: { |
| | | tag: 'ym', |
| | | displayName: '嘉峪关项目', |
| | | operatorId: '2025040415305200007', // 统一ID用于operator和clientId |
| | | needLogin: false // 不需要登录 |
| | | }, |
| | | MQ: { |
| | | tag: 'mq', |
| | | displayName: '民勤项目', |
| | | operatorId: '2025033115305200006', // 统一ID用于operator和clientId |
| | | needLogin: false // 不需要登录 |
| | | }, |
| | | TEST: { |
| | | tag: 'ym', |
| | | displayName: '测试项目', |
| | | operatorId: '2024122617295800009', // 统一ID用于operator和clientId |
| | | vcId: '2024122617295800009', |
| | | needLogin: false // 不需要登录 |
| | | }, |
| | | SCHOOL: { |
| | | tag: 'XX', |
| | | displayName: '学校项目', |
| | | operatorId: '2025040215305200006', // 统一ID用于operator和clientId |
| | | needLogin: false // 不需要登录 |
| | | }, |
| | | JC: { |
| | | tag: 'jc', |
| | | displayName: '金昌项目', |
| | | operatorId: '2025041710412400006', // 统一ID用于operator和clientId |
| | | needLogin: false // 不需要登录 |
| | | }, |
| | | GSCLT:{ |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-崔', |
| | | operatorId: '2025041912201400006', // 统一ID用于operator和clientId |
| | | needLogin: false // 不需要登录 |
| | | JYG: { |
| | | tag: 'ym', |
| | | displayName: '嘉峪关项目', |
| | | operatorId: '2025040415305200007', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '55', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_55; |
| | | } |
| | | }, |
| | | MQ: { |
| | | tag: 'mq', |
| | | displayName: '民勤项目', |
| | | operatorId: '2025033115305200006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '121', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_121; |
| | | } |
| | | }, |
| | | TEST: { |
| | | tag: 'ym', |
| | | displayName: '测试项目', |
| | | operatorId: '2024122617295800009', // 统一ID用于operator和clientId |
| | | vcId: '2024122617295800009', |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '166', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_166; |
| | | } |
| | | }, |
| | | JC: { |
| | | tag: 'jc', |
| | | displayName: '金昌项目', |
| | | operatorId: '2025041710412400006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '121', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_121; |
| | | } |
| | | }, |
| | | GSCLT: { |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-崔龙天', |
| | | operatorId: '2025041912201400006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | }, |
| | | GSWJ: { |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-王娟', |
| | | operatorId: '2025042115424500006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | }, |
| | | GSCLT2: { |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-晁玉亮', |
| | | operatorId: '2025042115452400006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | }, |
| | | GSCLT3: { |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-黄虎生', |
| | | operatorId: '2025042115454100006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | }, |
| | | GSCLT4: { |
| | | tag: 'test', |
| | | displayName: '甘肃农科院-朱兆宝', |
| | | operatorId: '2025042115455900006', // 统一ID用于operator和clientId |
| | | needLogin: false, // 不需要登录 |
| | | serverId: '233', |
| | | get serverUrl() { |
| | | return SERVER_INFO.URL_233; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | module.exports = { |
| | | PROJECT_CONFIG |
| | | }; |
| | | PROJECT_CONFIG, |
| | | SERVER_INFO |
| | | }; |