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://nsjcy.hugeinfo.com.cn/nsjc-charge',
|
// url: 'http://1p885086k1.iok.la/nsjc-charge',
|
// url: 'http://localhost:6060/nsjc-charge',
|
imgUrl: 'https://nsjcy.hugeinfo.com.cn/nsjc-charge',
|
url: 'http://nsjc.vaiwan.com/nsjc-charge',
|
// imgUrl: 'http://nsjc.vaiwan.com/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) {
|
console.log(these)
|
console.log(path)
|
console.log(associateTypeId)
|
console.log(way)
|
console.log(id)
|
var status = these.data['status'];
|
var batch;
|
if (status == 4) {
|
batch = 1
|
} else {
|
batch = 0
|
}
|
console.log(batch)
|
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) {
|
console.log(res)
|
var evalList = these.data.evalList;
|
var evalListType = 'evalList' + associateTypeId;
|
var data = JSON.parse(res.data)
|
console.log(data)
|
console.log('path', path)
|
console.log('evalList', evalList)
|
console.log('associateTypeId', associateTypeId)
|
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;
|
},
|
|
//转换时间戳
|
formatDateday: 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;
|
},
|
|
// 页面正在开发中
|
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;
|
}
|
},
|
getPermission: function(url) {
|
wx.getLocation({
|
success: function(res) {
|
wx.navigateTo({
|
url,
|
})
|
},
|
fail: function() {
|
wx.getSetting({
|
success: function(res) {
|
var statu = res.authSetting;
|
if (!statu['scope.userLocation']) {
|
wx.showModal({
|
title: '是否授权当前位置',
|
content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
|
success: function(tip) {
|
if (tip.confirm) {
|
wx.openSetting({
|
success: function(data) {
|
if (data.authSetting["scope.userLocation"] === true) {
|
wx.showToast({
|
title: '授权成功',
|
icon: 'success',
|
duration: 1000
|
})
|
//授权成功之后,再调用chooseLocation选择地方
|
wx.getLocation({
|
success: function(res) {
|
wx.navigateTo({
|
url,
|
})
|
},
|
})
|
} else {
|
wx.showToast({
|
title: '授权失败',
|
icon: 'success',
|
duration: 1000
|
})
|
}
|
}
|
})
|
}
|
}
|
})
|
}
|
},
|
fail: function(res) {
|
wx.showToast({
|
title: '调用授权窗口失败',
|
icon: 'success',
|
duration: 1000
|
})
|
}
|
})
|
}
|
})
|
}
|
})
|