|
@@ -1,6 +1,7 @@
|
|
|
// pages/upload/upload.js
|
|
|
const app = getApp()
|
|
|
const $api = require('../../utils/api.js').API;
|
|
|
+const baseURL = 'https://test.hunanwanzhu.com';
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
@@ -199,43 +200,73 @@ Page({
|
|
|
is_markt: Number(e.detail.value)
|
|
|
})
|
|
|
},
|
|
|
- uploadImg() {
|
|
|
- var today_stock_img = this.data.today_stock_img;
|
|
|
- wx.chooseImage({
|
|
|
- success: res => {
|
|
|
+
|
|
|
+ // oss验签上传图片
|
|
|
+ upload() {
|
|
|
+ const that = this
|
|
|
+ var today_stock_img = that.data.today_stock_img;
|
|
|
+ wx.chooseMedia({
|
|
|
+ mediaType: ['image'], // 只能上传图片 还有个属性是可以上传视频
|
|
|
+ success(res) {
|
|
|
wx.showLoading({
|
|
|
- title: '正在上传',
|
|
|
+ title: '上传中',
|
|
|
+ mask: true
|
|
|
})
|
|
|
-
|
|
|
- const tempFilePaths = res.tempFiles
|
|
|
- for (let i = 0; i < tempFilePaths.length; i++) {
|
|
|
- $api.upload(tempFilePaths[i].path, 'file').then(res => {
|
|
|
- wx.hideLoading()
|
|
|
- if (res.code == 0) {
|
|
|
- console.log(res.data)
|
|
|
- today_stock_img.push(res.data.url)
|
|
|
- this.setData({
|
|
|
- today_stock_img: today_stock_img
|
|
|
- })
|
|
|
- console.log(this.data.today_stock_img,22222222222)
|
|
|
- if (i==0 && today_stock_img.length == 1){
|
|
|
- this.loadOcr(tempFilePaths[i].path,res.data.url)
|
|
|
- }
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '上传失败',
|
|
|
- })
|
|
|
- }
|
|
|
+ let imgs = []
|
|
|
+ let valueArr = []
|
|
|
+ // 需要oss 验签 此处是调取验签的接口
|
|
|
+ $api.getOssSign(res).then((r) => {
|
|
|
+ wx.hideLoading()
|
|
|
+ const arr = res.tempFiles
|
|
|
+ // arr 是为了获取上传图片反的数组
|
|
|
+ arr.forEach((e) => {
|
|
|
+ return imgs.push(e.tempFilePath)
|
|
|
})
|
|
|
- .catch(err => {
|
|
|
- wx.hideLoading()
|
|
|
+ for (var i = 0; i < imgs.length; i++) {
|
|
|
+ let only = imgs[i].split('.')
|
|
|
+ valueArr.push(
|
|
|
+ only[only.length - 1]
|
|
|
+ )
|
|
|
+ let filename = parseInt(Math.random() * 1000000 + new Date().getTime()) + '.' + valueArr[valueArr.length - 1]
|
|
|
+ let httpData = {
|
|
|
+ Key: r.data.dir + filename,
|
|
|
+ OSSAccessKeyId: r.data.AccessKeyID,
|
|
|
+ Policy: r.data.policy_encode,
|
|
|
+ Signature: r.data.signature,
|
|
|
+ }
|
|
|
+ wx.uploadFile({
|
|
|
+ url: baseURL+'/api/wx/uploadfile',
|
|
|
+ filePath: imgs[i],
|
|
|
+ formData: httpData,
|
|
|
+ fileType: 'image',
|
|
|
+ name: 'file',
|
|
|
+ timeout: 15000,
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
+ },
|
|
|
+ success: (res) => {
|
|
|
+ if (res.statusCode == 200) {
|
|
|
+ var data=JSON.parse(res.data)
|
|
|
+ today_stock_img.push(data.data.url)
|
|
|
+ that.setData({
|
|
|
+ today_stock_img: today_stock_img
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 返回错误信息
|
|
|
+ console.log('error')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ console.log(res);
|
|
|
+ }
|
|
|
})
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
})
|
|
|
+
|
|
|
},
|
|
|
+
|
|
|
loadOcr(path,url){
|
|
|
var _this = this
|
|
|
|