|
@@ -1,5 +1,6 @@
|
|
// pages/pyip/pyip.js
|
|
// pages/pyip/pyip.js
|
|
-const COS = require('../../utils/cos-wx-v5.js');
|
|
|
|
|
|
+const COS = require('../../utils/cos.js');
|
|
|
|
+const app = require('../../utils/util.js');
|
|
Page({
|
|
Page({
|
|
/**
|
|
/**
|
|
* 页面的初始数据
|
|
* 页面的初始数据
|
|
@@ -9,35 +10,34 @@ Page({
|
|
carWin_img: '' //存放照片路径的
|
|
carWin_img: '' //存放照片路径的
|
|
},
|
|
},
|
|
openCamera() {
|
|
openCamera() {
|
|
- var that = this;
|
|
|
|
- wx.chooseImage({
|
|
|
|
|
|
+ wx.chooseMedia({
|
|
count: 1,
|
|
count: 1,
|
|
|
|
+ mediaType: ['image', 'video'],
|
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
|
+ maxDuration: 30,
|
|
|
|
+ camera: 'back',
|
|
success: (res) => {
|
|
success: (res) => {
|
|
- var filePath = res.tempFilePaths[0];
|
|
|
|
- that.setData({
|
|
|
|
- carWin_img: filePath, //把照片路径存到变量中,
|
|
|
|
- carWin_img_hidden: false //让展示照片的view显示
|
|
|
|
- });
|
|
|
|
- console.log(this.data.carWin_img)
|
|
|
|
- // 这个是使用微信接口保存文件到数据库
|
|
|
|
- // wx.uploadFile({
|
|
|
|
- // url: "",
|
|
|
|
- // filePath: filePath,
|
|
|
|
- // name: 'file',
|
|
|
|
- // success: function (res) {
|
|
|
|
- // }
|
|
|
|
- // })
|
|
|
|
- },
|
|
|
|
- fail: function (error) {
|
|
|
|
- console.error("调用本地相册文件时出错")
|
|
|
|
- console.warn(error)
|
|
|
|
- },
|
|
|
|
- complete: function () {
|
|
|
|
-
|
|
|
|
|
|
+ console.log(res.tempFiles[0].tempFilePath)
|
|
|
|
+ console.log(res.tempFiles[0].size)
|
|
|
|
+ this.setData({
|
|
|
|
+ carWin_img: res.tempFiles[0].tempFilePath,
|
|
|
|
+ carWin_img_hidden: false,
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ })
|
|
},
|
|
},
|
|
submitImgToTxy() {
|
|
submitImgToTxy() {
|
|
|
|
+ if (this.data.carWin_img == "" || this.data.carWin_img == null) {
|
|
|
|
+ wx.showModal({
|
|
|
|
+ title: '请点击上方选择照片或者视频哦',
|
|
|
|
+ showCancel: false
|
|
|
|
+ });
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ wx.showLoading({
|
|
|
|
+ mask: true,
|
|
|
|
+ title: '加载中',
|
|
|
|
+ })
|
|
// var CosAuth = require('./cos-auth'); // COS 签名方法 https://unpkg.com/cos-js-sdk-v5/demo/common/cos-auth.min.js
|
|
// var CosAuth = require('./cos-auth'); // COS 签名方法 https://unpkg.com/cos-js-sdk-v5/demo/common/cos-auth.min.js
|
|
var Bucket = 'bucketnj1-1254259530';
|
|
var Bucket = 'bucketnj1-1254259530';
|
|
var Region = 'ap-nanjing';
|
|
var Region = 'ap-nanjing';
|
|
@@ -66,15 +66,14 @@ Page({
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
wx.request({
|
|
wx.request({
|
|
- method: 'GET',
|
|
|
|
- url: 'https://example.com/sts.php', // 服务端签名,参考上文说的获取临时密钥
|
|
|
|
- dataType: 'json',
|
|
|
|
|
|
+ method: 'POST',
|
|
|
|
+ url: app.globalData.publicUrl + '/wx/course/getSts', // 服务端签名,参考上文说的获取临时密钥
|
|
|
|
+ // dataType: 'json',
|
|
success: function (result) {
|
|
success: function (result) {
|
|
- console.log(result)
|
|
|
|
- var data = result.data;
|
|
|
|
- var credentials = data.credentials;
|
|
|
|
|
|
+ console.log(result, "000000000000")
|
|
|
|
+ var credentials = result.data.credential.credentials;
|
|
if (credentials) {
|
|
if (credentials) {
|
|
- stsCache = data
|
|
|
|
|
|
+ stsCache = result.data.credential
|
|
} else {
|
|
} else {
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '临时密钥获取失败',
|
|
title: '临时密钥获取失败',
|
|
@@ -110,6 +109,7 @@ Page({
|
|
// 上传文件
|
|
// 上传文件
|
|
// var uploadFile = function (filePath) {
|
|
// var uploadFile = function (filePath) {
|
|
var Key = this.data.carWin_img.substr(this.data.carWin_img.lastIndexOf('/') + 1); // 这里指定上传的文件名
|
|
var Key = this.data.carWin_img.substr(this.data.carWin_img.lastIndexOf('/') + 1); // 这里指定上传的文件名
|
|
|
|
+ // var Key = '456abcd.png';
|
|
var signPathname = '/'; // PostObject 接口 Key 是放在 Body 传输,所以请求路径和签名路径是 /
|
|
var signPathname = '/'; // PostObject 接口 Key 是放在 Body 传输,所以请求路径和签名路径是 /
|
|
if (ForcePathStyle) {
|
|
if (ForcePathStyle) {
|
|
// 后缀式请求在签名时用的路径,要包含存储桶名称,具体说明见本文上述“3.后缀式请求”
|
|
// 后缀式请求在签名时用的路径,要包含存储桶名称,具体说明见本文上述“3.后缀式请求”
|
|
@@ -118,46 +118,56 @@ Page({
|
|
getAuthorization({
|
|
getAuthorization({
|
|
Method: 'POST',
|
|
Method: 'POST',
|
|
Pathname: signPathname
|
|
Pathname: signPathname
|
|
- }, function (AuthData) {
|
|
|
|
|
|
+ }, (AuthData) => {
|
|
var requestTask = wx.uploadFile({
|
|
var requestTask = wx.uploadFile({
|
|
url: prefix,
|
|
url: prefix,
|
|
name: 'file',
|
|
name: 'file',
|
|
filePath: this.data.carWin_img,
|
|
filePath: this.data.carWin_img,
|
|
formData: {
|
|
formData: {
|
|
- 'key': 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: function (res) {
|
|
|
|
|
|
+ success: (res) => {
|
|
var url = prefix + camSafeUrlEncode(Key).replace(/%2F/g, '/');
|
|
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(res.statusCode);
|
|
console.log(url);
|
|
console.log(url);
|
|
if (/^2\d\d$/.test('' + res.statusCode)) {
|
|
if (/^2\d\d$/.test('' + res.statusCode)) {
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '上传成功',
|
|
title: '上传成功',
|
|
- content: url,
|
|
|
|
showCancel: false
|
|
showCancel: false
|
|
});
|
|
});
|
|
|
|
+ this.setData({
|
|
|
|
+ carWin_img: "",
|
|
|
|
+ carWin_img_hidden:true
|
|
|
|
+ })
|
|
} else {
|
|
} else {
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '上传失败',
|
|
title: '上传失败',
|
|
- content: JSON.stringify(res),
|
|
|
|
|
|
+ // content: JSON.stringify(res),
|
|
showCancel: false
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
}
|
|
},
|
|
},
|
|
fail: function (res) {
|
|
fail: function (res) {
|
|
|
|
+ wx.hideLoading();
|
|
wx.showModal({
|
|
wx.showModal({
|
|
title: '上传失败',
|
|
title: '上传失败',
|
|
- content: JSON.stringify(res),
|
|
|
|
|
|
+ // content: JSON.stringify(res),
|
|
showCancel: false
|
|
showCancel: false
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
requestTask.onProgressUpdate(function (res) {
|
|
requestTask.onProgressUpdate(function (res) {
|
|
console.log('进度:', res);
|
|
console.log('进度:', res);
|
|
|
|
+ if (res.progress == 100) {
|
|
|
|
+ wx.hideLoading();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
});
|
|
});
|
|
// };
|
|
// };
|
|
@@ -166,7 +176,7 @@ Page({
|
|
/**
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
*/
|
|
- onLoad: function (options) {
|
|
|
|
|
|
+ onLoad: function () {
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|