|
@@ -1,13 +1,16 @@
|
|
// pages/pyip/pyip.js
|
|
// pages/pyip/pyip.js
|
|
const COS = require('../../utils/cos.js');
|
|
const COS = require('../../utils/cos.js');
|
|
const app = require('../../utils/util.js');
|
|
const app = require('../../utils/util.js');
|
|
|
|
+const tools = require('../../utils/tools.js');
|
|
Page({
|
|
Page({
|
|
/**
|
|
/**
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
*/
|
|
*/
|
|
data: {
|
|
data: {
|
|
carWin_img_hidden: true, //展示照片的view是否隐藏
|
|
carWin_img_hidden: true, //展示照片的view是否隐藏
|
|
- carWin_img: '' //存放照片路径的
|
|
|
|
|
|
+ carWin_img: '', //存放照片路径的
|
|
|
|
+ carWin_img_type: 2, //是图片还是视频
|
|
|
|
+ cosPath: "" //腾讯云上传的路径
|
|
},
|
|
},
|
|
openCamera() {
|
|
openCamera() {
|
|
wx.chooseMedia({
|
|
wx.chooseMedia({
|
|
@@ -17,12 +20,22 @@ Page({
|
|
maxDuration: 30,
|
|
maxDuration: 30,
|
|
camera: 'back',
|
|
camera: 'back',
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- console.log(res.tempFiles[0].tempFilePath)
|
|
|
|
- console.log(res.tempFiles[0].size)
|
|
|
|
- this.setData({
|
|
|
|
- carWin_img: res.tempFiles[0].tempFilePath,
|
|
|
|
- carWin_img_hidden: false,
|
|
|
|
- })
|
|
|
|
|
|
+ console.log(res, "9999999999999999")
|
|
|
|
+ let path = res.tempFiles[0].tempFilePath
|
|
|
|
+ let uploadType = path.substring(path.length - 3)
|
|
|
|
+ if (uploadType == "jpg" || uploadType == "png") {
|
|
|
|
+ this.setData({
|
|
|
|
+ carWin_img: path,
|
|
|
|
+ carWin_img_hidden: false,
|
|
|
|
+ carWin_img_type: 0
|
|
|
|
+ })
|
|
|
|
+ } else if (uploadType == "mp4") {
|
|
|
|
+ this.setData({
|
|
|
|
+ carWin_img: path,
|
|
|
|
+ carWin_img_hidden: false,
|
|
|
|
+ carWin_img_type: 1
|
|
|
|
+ })
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
@@ -50,14 +63,14 @@ Page({
|
|
prefix = 'https://cos.' + Region + '.myqcloud.com/' + Bucket + '/';
|
|
prefix = 'https://cos.' + Region + '.myqcloud.com/' + Bucket + '/';
|
|
}
|
|
}
|
|
// 对更多字符编码的 url encode 格式
|
|
// 对更多字符编码的 url encode 格式
|
|
- var camSafeUrlEncode = function (str) {
|
|
|
|
- return encodeURIComponent(str)
|
|
|
|
- .replace(/!/g, '%21')
|
|
|
|
- .replace(/'/g, '%27')
|
|
|
|
- .replace(/\(/g, '%28')
|
|
|
|
- .replace(/\)/g, '%29')
|
|
|
|
- .replace(/\*/g, '%2A');
|
|
|
|
- };
|
|
|
|
|
|
+ // var camSafeUrlEncode = function (str) {
|
|
|
|
+ // return encodeURIComponent(str)
|
|
|
|
+ // .replace(/!/g, '%21')
|
|
|
|
+ // .replace(/'/g, '%27')
|
|
|
|
+ // .replace(/\(/g, '%28')
|
|
|
|
+ // .replace(/\)/g, '%29')
|
|
|
|
+ // .replace(/\*/g, '%2A');
|
|
|
|
+ // };
|
|
// 获取临时密钥
|
|
// 获取临时密钥
|
|
var stsCache;
|
|
var stsCache;
|
|
var getCredentials = function (callback) {
|
|
var getCredentials = function (callback) {
|
|
@@ -70,7 +83,6 @@ Page({
|
|
url: app.globalData.publicUrl + '/wx/course/getSts', // 服务端签名,参考上文说的获取临时密钥
|
|
url: app.globalData.publicUrl + '/wx/course/getSts', // 服务端签名,参考上文说的获取临时密钥
|
|
// dataType: 'json',
|
|
// dataType: 'json',
|
|
success: function (result) {
|
|
success: function (result) {
|
|
- console.log(result, "000000000000")
|
|
|
|
var credentials = result.data.credential.credentials;
|
|
var credentials = result.data.credential.credentials;
|
|
if (credentials) {
|
|
if (credentials) {
|
|
stsCache = result.data.credential
|
|
stsCache = result.data.credential
|
|
@@ -124,41 +136,58 @@ Page({
|
|
name: 'file',
|
|
name: 'file',
|
|
filePath: this.data.carWin_img,
|
|
filePath: this.data.carWin_img,
|
|
formData: {
|
|
formData: {
|
|
- 'key': "paiyipai/"+Key,
|
|
|
|
|
|
+ 'key': "paiyipai/" + Key,
|
|
'success_action_status': 200,
|
|
'success_action_status': 200,
|
|
'Signature': AuthData.Authorization,
|
|
'Signature': AuthData.Authorization,
|
|
'x-cos-security-token': AuthData.XCosSecurityToken,
|
|
'x-cos-security-token': AuthData.XCosSecurityToken,
|
|
'Content-Type': '',
|
|
'Content-Type': '',
|
|
},
|
|
},
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- var url = prefix + camSafeUrlEncode(Key).replace(/%2F/g, '/');
|
|
|
|
- console.log('prefix' + prefix);
|
|
|
|
- console.log('Key' + Key);
|
|
|
|
- console.log('4564564654654');
|
|
|
|
- console.log(res.statusCode);
|
|
|
|
- console.log(url);
|
|
|
|
|
|
+ console.log(res.header.Location, "11111111111111")
|
|
|
|
+ // var url = prefix + camSafeUrlEncode(Key).replace(/%2F/g, '/');
|
|
if (/^2\d\d$/.test('' + res.statusCode)) {
|
|
if (/^2\d\d$/.test('' + res.statusCode)) {
|
|
- wx.showModal({
|
|
|
|
- title: '上传成功',
|
|
|
|
- showCancel: false
|
|
|
|
|
|
+ wx.request({
|
|
|
|
+ method: 'PUT',
|
|
|
|
+ url: app.globalData.publicUrl + '/wx/shoot',
|
|
|
|
+ data: {
|
|
|
|
+ shootName: this.data.carWin_img,
|
|
|
|
+ shootCosName: Key,
|
|
|
|
+ sessionKey: this.data.sessionKey,
|
|
|
|
+ shootType: this.data.carWin_img_type
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ if (res.data.code == 0) {
|
|
|
|
+ console.log(res, "我把照片路径传到服务器啦")
|
|
|
|
+ wx.showModal({
|
|
|
|
+ title: '上传成功',
|
|
|
|
+ showCancel: false
|
|
|
|
+ });
|
|
|
|
+ this.setData({
|
|
|
|
+ // cosPath: res.header.Location,
|
|
|
|
+ carWin_img: "",
|
|
|
|
+ carWin_img_type: 2,
|
|
|
|
+ carWin_img_hidden: true
|
|
|
|
+ })
|
|
|
|
+ this.getArr(this.data.sessionKey)
|
|
|
|
+ } else {
|
|
|
|
+ wx.showModal({
|
|
|
|
+ title: "上传失败啦",
|
|
|
|
+ showCancel: false
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|
|
- this.setData({
|
|
|
|
- carWin_img: "",
|
|
|
|
- carWin_img_hidden:true
|
|
|
|
- })
|
|
|
|
} else {
|
|
} else {
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '上传失败',
|
|
title: '上传失败',
|
|
- // content: JSON.stringify(res),
|
|
|
|
showCancel: false
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- fail: function (res) {
|
|
|
|
|
|
+ fail: function () {
|
|
wx.hideLoading();
|
|
wx.hideLoading();
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '上传失败',
|
|
title: '上传失败',
|
|
- // content: JSON.stringify(res),
|
|
|
|
showCancel: false
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -170,16 +199,35 @@ Page({
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
});
|
|
- // };
|
|
|
|
- // }
|
|
|
|
|
|
+ },
|
|
|
|
+ getArr(sessionKey) {
|
|
|
|
+ wx.request({
|
|
|
|
+ url: app.globalData.publicUrl + '/wx/shoot',
|
|
|
|
+ method: "get",
|
|
|
|
+ data: {
|
|
|
|
+ sessionKey
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ console.log(res.data.imgList, "我是查到的照片视频列表")
|
|
|
|
+ console.log(res.data.videoList, "我是查到的照片视频列表")
|
|
|
|
+ this.setData({
|
|
|
|
+ imgList: res.data.imgList,
|
|
|
|
+ videoList: res.data.videoList
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ })
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
- onLoad: function () {
|
|
|
|
-
|
|
|
|
|
|
+ async onLoad() {
|
|
|
|
+ const sessionKey = await tools.checkSessionAndLogin();
|
|
|
|
+ this.setData({
|
|
|
|
+ sessionKey
|
|
|
|
+ })
|
|
|
|
+ this.getArr(sessionKey)
|
|
|
|
+ // this.getArr(sessionKey);
|
|
},
|
|
},
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
*/
|
|
@@ -189,7 +237,6 @@ Page({
|
|
carWin_img: ''
|
|
carWin_img: ''
|
|
});
|
|
});
|
|
},
|
|
},
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
*/
|