var qcloud = require('./lib/index'); //app.js App({ onLaunch: function() { // 展示本地存储能力 var logs = wx.getStorageSync('logs') || [] logs.unshift(Date.now()) wx.setStorageSync('logs', logs) }, globalData: { userInfo: null, pageData: {}, //url: 'https://hugeinfo.com.cn/nsjc-charge', //url: 'http://192.168.0.31:8085/nsjc-charge', //imgUrl: 'https://hugeinfo.com.cn/nsjc-charge', url: 'https://xnwj.gznsjc.gov.cn/nsjc-charge', imgUrl: 'https://xnwj.gznsjc.gov.cn/nsjc-charge' }, // 过滤数组 where: (collection, source) => { var sourceKeys = Object.keys(source); return collection.filter(function(obj) { for (var i = 0; i < sourceKeys.length; i++) { if (!obj.hasOwnProperty(sourceKeys[i]) || obj[sourceKeys[i]] !== source[sourceKeys[i]]) { return false; } return true } }) }, //控制是否能够编辑 judgeDisable: function(status) { if (status == null || status == 0 || status == 4) { return false; //可以 } else { return true; //不可以 } }, //提示弹窗 showModal: function(warn) { wx.showModal({ title: '提示', content: warn }) }, //添加图片 joinPicture: function(e, these, associateTypeId, attId) { var th = this; var index = e.currentTarget.dataset.index; var associateTypeId = e.currentTarget.dataset.associatetypeid || associateTypeId; var evalListType = 'evalList' + associateTypeId; var evalList = these.data.evalList; var that = these; var attId = attId || these.data.id; var imgNumber = evalList[evalListType]; wx.chooseImage({ count: 9, sizeType: ["original", "compressed"], sourceType: ["album", "camera"], success: (res) => { console.log(res) for (var i = 0; i < res.tempFilePaths.length; i++) { console.log(res.tempFilePaths[i]) if (associateTypeId == 1015) { th.upload(these, res.tempFilePaths[i], associateTypeId, 'materialsDisk', attId); } else { th.upload(these, res.tempFilePaths[i], associateTypeId, 'materials', attId); } } }, }) }, // 上传视频 joinVideo: function(e, these, associateTypeId, attId) { var th = this; var index = e.currentTarget.dataset.index; var associateTypeId = e.currentTarget.dataset.associatetypeid || associateTypeId; var evalListType = 'evalList' + associateTypeId; var evalList = these.data.evalList; var that = these; var attId = attId || these.data.id; wx.chooseVideo({ sizeType: ["original", "compressed"], sourceType: ["album", "camera"], success: (res) => { th.upload(these, res.tempFilePath, associateTypeId, 'materialsDisk', attId); }, }) }, //上传文件 upload: function(these, path, associateTypeId, way, id) { var status = these.data['status']; var batch; if (status == 4) { batch = 1 } else { batch = 0 } wx.showToast({ icon: "loading", title: "正在上传" }); wx.uploadFile({ url: this.globalData.url + '/api/v1/attachment/' + way, //接口处理在下面有写 filePath: path, name: 'file', header: { "Content-Type": "multipart/form-data" }, formData: { entityId: id, associateTypeId: associateTypeId, batch }, success: function(res) { var evalList = these.data.evalList; var evalListType = 'evalList' + associateTypeId; var data = JSON.parse(res.data) these.setData({ evalList: { ...evalList, [evalListType]: evalList[evalListType].concat({ id: data.data[0].id, pic: path }) }, }) }, complete: function() { wx.hideToast(); //隐藏Toast } }) // } }, //删除图片 clearImg: function(e, these) { var id = e.currentTarget.id; var index = e.currentTarget.dataset.index; var associateTypeId = e.currentTarget.dataset.associatetypeid; var evalListType = 'evalList' + associateTypeId; var evalList = these.data.evalList; var img = evalList[evalListType]; wx.showToast({ icon: "loading", title: "正在删除" }), wx.request({ url: this.globalData.url + '/api/v1/attachment/delete/' + id, success: function(res) { if (res.data.code == 0) { console.log('删除成功!') } }, complete: function() { wx.hideToast(); //隐藏Toast } }) img.splice(index, 1); these.setData({ evalList: { ...evalList, [evalListType]: img } }) }, // 预览图片 previewImage: function(e) { wx.previewImage({ current: e.currentTarget.dataset.src, // 当前显示图片的http链接 urls: [e.currentTarget.dataset.src] // 需要预览的图片http链接列表 }) }, //转换时间戳 formatDate: function(ts) { var now = new Date(ts); var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate(); var hour = now.getHours() < 10 ? '0' + now.getHours() : now.getHours(); var minute = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes(); var second = now.getSeconds(); return year + "-" + month + "-" + date + " " + hour + ":" + minute; }, // 页面正在开发中 developIng: function() { wx.navigateTo({ url: '../developIng/developIng', }) }, // 判断时间段 period: function() { var now = new Date(), hour = now.getHours(), word = '';; if (hour < 6) { word = "凌晨好!" } else if (hour < 9) { word = "早上好!" } else if (hour < 12) { word = "上午好!" } else if (hour < 14) { word = "中午好!" } else if (hour < 17) { word = "下午好!" } else if (hour < 19) { word = "傍晚好!" } else if (hour < 22) { word = "晚上好!" } else { word = "夜里好!" } return word; }, // 根据身份证获取生日,性别,年龄 IdCard: function(UUserCard, num) { if (num == 1) { //获取出生日期 var birth = UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14); return birth; } if (num == 2) { //获取性别 if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) { //男 return 1; } else { //女 return 2; } } if (num == 3) { //获取年龄 var myDate = new Date(); var month = myDate.getMonth() + 1; var day = myDate.getDate(); var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1; if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) { age++; } return age; } } })