daofu-applet/app.js
2024-01-29 17:42:38 +08:00

174 lines
4.7 KiB
JavaScript

// app.js
App({
onLaunch: function () {
wx.getSystemInfo({
success: e => {
this.globalData.StatusBar = e.statusBarHeight;
let capsule = wx.getMenuButtonBoundingClientRect();
if (capsule) {
this.globalData.Custom = capsule;
this.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
} else {
this.globalData.CustomBar = e.statusBarHeight + 50;
}
}
})
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,请重启应用。',
showCancel: false,
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦,请您删除当前小程序,重新搜索打开',
showCancel: false,
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
}
})
}
},
globalData: {
versionCode: 'V1',
userInfo: {},
headerUrl: "http://42.193.40.239:8017/"
},
// 文件服务器地址
FILE_SERVER_URL: "http://42.193.40.239:8888", //查看
FILE_SERVER_UP_URL: "http://42.193.40.239:8017/", //上传
// 文件类型
FileType: {
avatar: "SysPhoto", // 用户头像
resumptionAcs: "WorkFile", // 履职附件
taskAcs: "TaskAttachment", // 任务附件
msgAcs: "MsgAcs", // 消息附件
checkMethodPic: "checkMethodPic", //检查方法图片
userSign: "UserSign", //用户签名
entSign: "entSign", //企业签名
buildImg: "buildImg", //建筑体图片
buildDesignImg: "buildDesignImg", //建筑体总平图
dangerBefore: "APPRectifyImgBefore", //整改前
dangerAfter: "APPRectifyImgAfter", //整改后
entEmResourse: "entEmResourse", //应急物资台账
EmergencyImg: "Content", // 应急预案---一图一表
EmergencyFile: "EmergencyFile", // 应急预案---文件
EmergencyPlanFile: "EmergencyPlanFile", // 应急演练---文件
checkEnclosure: "CheckEnclosure", // 检查附件
},
// 接口类型
ApiFileType: {
GET: "/getFile",
POST: "/uploadFile",
DELETE: "/delFile",
},
// 请求函数封装
axios: function (type, con, url, data, showLoading) {
try {
if (showLoading) {
wx.showLoading({
title: '加载中...',
icon: 'none'
})
}
return new Promise((resolve, reject) => {
wx.request({
url: `${this.globalData.headerUrl}${con}${url}`,
method: type,
data: data,
header: {
'content-type': 'application/json;charset=UTF-8',
'userToken': this.globalData.userInfo.userToken || ""
},
success: function (res) {
var data = res.data
resolve(data)
},
fail: function (err) {
reject(err)
},
complete: function (params) {
if (showLoading) wx.hideLoading();
}
})
})
} catch {}
},
/** 上传文件 */
uploadFile: function (OTCId, OTCType, filePath) {
let params = {
OTCId,
OTCType,
userId: this.globalData.userInfo.userId,
}
console.info(params)
return new Promise((resolve, reject) => {
wx.uploadFile({
url: this.FILE_SERVER_UP_URL + this.ApiFileType.POST,
filePath: filePath,
name: 'file',
formData: params,
success: function (res) {
if (res.statusCode === 200) {
resolve(res.data);
} else {
reject()
}
},
fail: function (err) {
reject(err);
}
})
}).catch()
},
// 设置监听器
watch: function (ctx, obj) {
Object.keys(obj).forEach(key => {
this.observer(ctx.data, key, ctx.data[key], function (value) {
obj[key].call(ctx, value)
})
})
},
// 监听属性,并执行监听函数
observer: function (data, key, val, fn) {
Object.defineProperty(data, key, {
configurable: true,
enumerable: true,
get: function () {
return val
},
set: function (newVal) {
if (newVal === val) return
fn && fn(newVal)
val = newVal
},
})
}
})