daofu-applet/app.js
2024-01-30 16:35:55 +08:00

161 lines
4.3 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", // 消息附件
eventAcs: "eventAcs", //突发事件上报
userSign: "UserSign", //用户签名
EmergencyImg: "Content", // 应急预案---一图一表
EmergencyFile: "EmergencyFile", // 应急预案---文件
EmergencyPlanFile: "EmergencyPlanFile", // 应急演练---文件
},
// 请求函数封装
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 + 'common/upload/uploadFile',
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
},
})
}
})