398 lines
13 KiB
JavaScript
Raw Normal View History

2024-02-21 17:43:11 +08:00
App({
2024-07-30 16:33:21 +08:00
// 配置信息
2024-09-05 16:10:16 +08:00
APPID: 'wxe043ce243cd9de5b',
APPSECRET: '5e7211116d2e183d997a01476a523744',
2024-08-05 10:04:26 +08:00
// tenantId : '12', // 地区
// parkId : '26', // 园区id
// parkName : '长阳智会云控', // 园区名称
2024-05-06 15:24:42 +08:00
// 本地测试
// DOMAIN_NAME_PREFIX: 'http://192.168.0.17:9227',
// DOMAIN_NAME: 'http://192.168.0.17:9227', //接口域名
// IMG_NAME: 'http://192.168.0.17:9227',
2025-05-28 09:27:40 +08:00
// DOMAIN_NAME_PREFIX: 'http://127.0.0.1:9227',
// DOMAIN_NAME: 'http://127.0.0.1:9227', //接口域名
// IMG_NAME: 'http://127.0.0.1:9227',
2024-05-06 15:24:42 +08:00
// 生产
2024-12-25 21:40:58 +08:00
DOMAIN_NAME_PREFIX: 'https://www.hajgfwzx.cn/shoot-hand',
DOMAIN_NAME: 'https://www.hajgfwzx.cn/shoot-hand', //接口域名
IMG_NAME: 'https://www.hajgfwzx.cn/shoot-hand',
// DOMAIN_NAME_PREFIX: 'https://company.haxy.com.cn:4443/shoot-hand',
// DOMAIN_NAME: 'https://company.haxy.com.cn:4443/shoot-hand', //接口域名
// IMG_NAME: 'https://company.haxy.com.cn:4443/shoot-hand',
2024-02-26 15:34:59 +08:00
globals: {
refreshMyPages: false,
homedata: {},
editPro: {
projectId: 0, //项目ID
isedit: 0, //是否编辑
json: {} //项目编辑后的详细数据
},
trainBeginCity: ''
2024-02-21 17:43:11 +08:00
},
2024-02-26 15:34:59 +08:00
onLaunch(res) {
var that = this
// 初始化通知状态监听器列表
this.notificationStatusListeners = [];
2024-02-26 15:34:59 +08:00
},
// 注册通知状态更新监听器
registerNotificationStatusChange(callback) {
if (typeof callback === 'function') {
this.notificationStatusListeners = this.notificationStatusListeners || [];
this.notificationStatusListeners.push(callback);
console.log('注册通知状态更新监听器成功,当前监听器数量:', this.notificationStatusListeners.length);
return true;
}
return false;
},
// 取消注册通知状态更新监听器
unregisterNotificationStatusChange(callback) {
if (!this.notificationStatusListeners || !callback) return false;
const index = this.notificationStatusListeners.indexOf(callback);
if (index > -1) {
this.notificationStatusListeners.splice(index, 1);
console.log('取消注册通知状态更新监听器成功,当前监听器数量:', this.notificationStatusListeners.length);
return true;
}
return false;
},
// 通知所有监听器状态更新
notifyNotificationStatusChange(data) {
if (!this.notificationStatusListeners) return;
console.log('通知所有监听器状态更新:', data);
this.notificationStatusListeners.forEach(callback => {
try {
callback(data);
} catch (err) {
console.error('执行通知状态更新回调出错:', err);
}
});
},
2024-02-26 15:34:59 +08:00
///////////////////////////////////////////////////////////////////////////
//获取当前用户的openid
Getopenid: function () {
var token = wx.getStorageSync('token');
return token;
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
/**
* 对象转URL
*/
urlEncode(data) {
var _result = [];
for (var key in data) {
var value = data[key];
if (value.constructor == Array) {
value.forEach(_value => {
_result.push(key + "=" + _value);
});
} else {
_result.push(key + '=' + value);
}
}
return _result.join('&');
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
/**
* 显示失败提示框
*/
showError(msg, callback) {
wx.showModal({
title: '友情提示',
content: msg,
showCancel: false,
success(res) {
// callback && (setTimeout(() => {
// callback();
// }, 1500));
callback && callback();
}
});
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
/**
* 显示成功提示框
*/
showSuccess(msg, callback) {
wx.showToast({
title: msg,
icon: 'success',
success() {
callback && (setTimeout(() => {
callback();
}, 1500));
}
});
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
// 根据出生日期计算年龄周岁 传参格式为1996-06-08
getAge: function (strBirthday) {
var returnAge = '';
var mouthAge = '';
var strBirthdayArr = strBirthday.split("-");
var birthYear = strBirthdayArr[0];
var birthMonth = strBirthdayArr[1];
var birthDay = strBirthdayArr[2];
var d = new Date();
var nowYear = d.getFullYear();
var nowMonth = d.getMonth() + 1;
var nowDay = d.getDate();
if (nowYear == birthYear) {
// returnAge = 0; //同年 则为0岁
var monthDiff = nowMonth - birthMonth; //月之差
if (monthDiff < 0) {} else {
mouthAge = monthDiff + '个月';
}
2024-02-21 17:43:11 +08:00
} else {
2024-02-26 15:34:59 +08:00
var ageDiff = nowYear - birthYear; //年之差
if (ageDiff > 0) {
if (nowMonth == birthMonth) {
var dayDiff = nowDay - birthDay; //日之差
if (dayDiff < 0) {
returnAge = ageDiff - 1 + '岁';
} else {
returnAge = ageDiff + '岁';
}
} else {
var monthDiff = nowMonth - birthMonth; //月之差
if (monthDiff < 0) {
returnAge = ageDiff - 1 + '岁';
} else {
mouthAge = monthDiff + '个月';
returnAge = ageDiff + '岁';
}
}
} else {
returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
2024-02-21 17:43:11 +08:00
}
}
2024-02-26 15:34:59 +08:00
return returnAge + mouthAge; //返回周岁年龄+月份
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
Upload: function (tempFilePaths, call) {
wx.showLoading({
mask: true,
title: '正在上传'
});
var that = this
wx.uploadFile({
2024-03-13 15:14:37 +08:00
url: that.DOMAIN_NAME + '/api/dfs/upload',
2024-02-26 15:34:59 +08:00
header: {
'Authorization': 'Bearer ' + that.Getopenid()
},
filePath: tempFilePaths,
name: 'file',
success(res) {
var deta = JSON.parse(res.data)
if (call) call(deta);
if (deta.code == 401) {
wx.hideLoading()
wx.showModal({
confirmText: '好的',
content: deta.msg || '身份已过期,需重登录',
success: res => {
wx.reLaunch({
url: '/pages/login/login',
})
}
});
} else if (deta.code != 0) {
wx.hideLoading()
wx.showModal({
confirmText: '好的',
content: '服务器开小差去了,请重试',
showCancel: false
})
} else if (deta.code == 0) {
wx.hideLoading()
}
},
fail: function (ret) {
wx.hideLoading()
wx.showModal({
confirmText: '再试一次',
content: '无法连接网络',
showCancel: false,
success: function () {
if (res.confirm) {
that.Upload(tempFilePaths, call);
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
2024-02-21 17:43:11 +08:00
})
2024-02-26 15:34:59 +08:00
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
getParkid() {
var token = wx.getStorageSync('token');
return token
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
getlogin() {
wx.showModal({
confirmText: '好的',
content: '请先登录后再点击查看',
success: res => {
2024-04-09 15:19:40 +08:00
wx.navigateTo({
2024-02-26 15:34:59 +08:00
url: '/pages/login/login',
2024-02-21 17:43:11 +08:00
})
}
2024-02-26 15:34:59 +08:00
})
},
//统一请求封装
//mandate 接口值
//data 传值已自动转换为JSON
//call 请求成功后回调的方法
AjaxRequest: function (methods, header, url, data, call) {
var token = wx.getStorageSync('token');
if (wx.getStorageSync('parkId')) {
data.parkId = wx.getStorageSync('parkId')
}
wx.showLoading({
mask: true,
title: '正在加载'
})
var that = this
//发送请求
wx.request({
header: header,
method: methods,
url: that.DOMAIN_NAME + url,
data: data,
success: function (ret) {
if (call) call(ret.data);
if (ret.data.code == 402 || ret.data.code == 401) {
wx.hideLoading()
wx.showModal({
confirmText: '确认',
content: '身份已过期,需重登录',
success(res) {
wx.removeStorageSync('MemberInfo')
wx.removeStorageSync('token')
if (res.confirm) {
wx.reLaunch({
url: '/pages/login/login',
})
}
}
})
} else if (ret.data.code != 0) {
wx.hideLoading()
wx.showModal({
confirmText: '好的',
content: ret.data.msg || '服务器开小差去了,请重试',
showCancel: false,
success(res) {
if (res.confirm) {
if (!wx.getStorageSync('parkId')) {
if (ret.data.msg == '请选择园区!!') {
wx.reLaunch({
url: '../index/parkList/parkList'
})
}
}
}
}
2024-02-21 17:43:11 +08:00
})
2024-02-26 15:34:59 +08:00
} else if (ret.data.code == 0) {
wx.hideLoading()
2024-02-21 17:43:11 +08:00
}
2024-02-26 15:34:59 +08:00
},
fail: function (ret) {
wx.hideLoading();
wx.showModal({
confirmText: '再试一次',
content: '无法连接网络',
success(res) {
if (res.confirm) {
that.AjaxRequest(methods, header, url, data, call);
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
2024-02-21 17:43:11 +08:00
}
})
2024-02-26 15:34:59 +08:00
},
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
ToWebURL(url) {
wx.navigateTo({
url: pages / outer / outer, //要跳转的页面需要新建立一个page页面
success: () => {
2024-02-21 17:43:11 +08:00
2024-02-26 15:34:59 +08:00
}
})
},
2024-04-18 09:19:46 +08:00
selfShowMsg(content, url) {
wx.showModal({
title: '提示',
content: content,
confirmText: '确认',
showCancel: false,
success: res => {
if (url) {
wx.navigateTo({
url
})
}
}
})
},
2024-08-14 10:21:46 +08:00
// 消息提示
2024-08-14 15:12:02 +08:00
vantNotify(Notify, msg, type, top) {
let data = {
type,
message: msg,
}
2024-08-14 10:21:46 +08:00
if (!type) {
2024-08-14 15:12:02 +08:00
data.type = 'primary'
2024-08-14 10:21:46 +08:00
}
2024-08-14 15:12:02 +08:00
if (top) {
data.top = top
}
Notify(data);
2024-08-14 10:21:46 +08:00
},
// 消息提示
vantNotifySuccess(Notify, msg) {
2024-08-14 15:12:02 +08:00
this.vantNotify(Notify, msg, 'primary')
2024-08-14 10:21:46 +08:00
},
// 消息提示
vantNotifyErr(Notify, msg) {
2024-08-14 15:12:02 +08:00
this.vantNotify(Notify, msg, 'danger')
},
// 消息提示
vantNotifySuccessTop(Notify, msg) {
this.vantNotify(Notify, msg, 'primary', 90)
},
// 消息提示
vantNotifyErrTop(Notify, msg) {
this.vantNotify(Notify, msg, 'danger', 90)
},
2024-08-15 14:59:35 +08:00
// 自定义后退
selfBackPage(step) {
let currentPages = getCurrentPages();
// 大于就后退,否则直接跳转首页
if (currentPages.length > step) {
wx.navigateBack({
delta: step
})
} else {
// 跳转首页
wx.reLaunch({
url: '/pages/index/index',
})
}
}
2024-02-21 17:43:11 +08:00
})