|
@@ -118,119 +118,115 @@ let service = {
|
|
|
data: requestData.data,
|
|
|
file_name: requestData.data.file_name || 'user/' + store.state.user.userInfo.uid
|
|
|
}
|
|
|
- uni.showLoading({
|
|
|
- title: '请求key中',
|
|
|
- mark: true,
|
|
|
- })
|
|
|
+ // uni.showLoading({
|
|
|
+ // title: '请求key中',
|
|
|
+ // mark: true,
|
|
|
+ // })
|
|
|
try {
|
|
|
- const {
|
|
|
- data
|
|
|
- } = await getUpimgKey({
|
|
|
- file_name: config.file_name
|
|
|
- })
|
|
|
- uni.hideLoading()
|
|
|
- setTimeout(()=>{
|
|
|
- uni.chooseImage({
|
|
|
- count: 1,
|
|
|
- sizeType: ['compressed'],
|
|
|
- sourceType: ['camera', 'album'],
|
|
|
- success(res) {
|
|
|
- uni.showLoading({
|
|
|
- title: '上传中',
|
|
|
- mark: true,
|
|
|
- })
|
|
|
- try{
|
|
|
- // console.log(res, '选中图片');
|
|
|
- const time = (new Date()).getTime();
|
|
|
- // #ifdef H5
|
|
|
- const formData = {
|
|
|
- "policy": data.sign.policy,
|
|
|
- "OSSAccessKeyId": data.sign.accessid,
|
|
|
- 'success_action_status': 200,
|
|
|
- "signature": data.sign.signature,
|
|
|
- "key": config.file_name + '/' + time + res.tempFiles[0]
|
|
|
- .name
|
|
|
- }
|
|
|
- // #endif
|
|
|
- // #ifndef H5
|
|
|
- const formData = {
|
|
|
- "policy": data.sign.policy,
|
|
|
- "OSSAccessKeyId": data.sign.accessid,
|
|
|
- 'success_action_status': 200,
|
|
|
- "signature": data.sign.signature,
|
|
|
- "key": config.file_name + '/' + time + '.png'
|
|
|
- }
|
|
|
- // #endif
|
|
|
- // console.log(formData,'formData');
|
|
|
- uni.uploadFile({
|
|
|
- url: data.sign.host, //仅为示例,非真实的接口地址
|
|
|
- filePath: res.tempFilePaths[0],
|
|
|
- formData,
|
|
|
- name: 'file',
|
|
|
- header: {
|
|
|
- "Authori-zation": 'Bearer ' + uni
|
|
|
- .getStorageSync('token')
|
|
|
- },
|
|
|
- success: (suc) => {
|
|
|
- if (suc.statusCode == 200) {
|
|
|
- // #ifdef H5
|
|
|
- const imgurl = [{
|
|
|
- url: data.sign.host + '/' +
|
|
|
- config.file_name + '/' +
|
|
|
- time + res.tempFiles[0]
|
|
|
- .name
|
|
|
- }];
|
|
|
- // #endif
|
|
|
- // #ifndef H5
|
|
|
- const imgurl = [{
|
|
|
- url: data.sign.host + '/' +
|
|
|
- config.file_name + '/' +
|
|
|
- time + '.png'
|
|
|
- }];
|
|
|
- // #endif
|
|
|
- resolve(imgurl)
|
|
|
- }
|
|
|
- uni.hideLoading()
|
|
|
- },
|
|
|
- file(res) {
|
|
|
- uni.hideLoading()
|
|
|
- // console.log(res, '图片上传错误');
|
|
|
- reject(res)
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
- }catch(e){
|
|
|
- uni.showModal({
|
|
|
- title: '错误',
|
|
|
- content: e.message,
|
|
|
- showCancel: false
|
|
|
- });
|
|
|
+ // const {
|
|
|
+ // data
|
|
|
+ // } = await getUpimgKey({
|
|
|
+ // file_name: config.file_name
|
|
|
+ // })
|
|
|
+ // uni.hideLoading()
|
|
|
+ // setTimeout(()=>{
|
|
|
+ uni.chooseImage({
|
|
|
+ count: 1,
|
|
|
+ sizeType: ['compressed'],
|
|
|
+ sourceType: ['camera', 'album'],
|
|
|
+ success(res) {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '上传中',
|
|
|
+ mark: true,
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ // console.log(res, '选中图片');
|
|
|
+ const time = (new Date()).getTime();
|
|
|
+ // #ifdef H5
|
|
|
+ const formData = {
|
|
|
+ // "policy": data.sign.policy,
|
|
|
+ // "OSSAccessKeyId": data.sign.accessid,
|
|
|
+ // 'success_action_status': 200,
|
|
|
+ // "signature": data.sign.signature,
|
|
|
+ "key": config.file_name + '/' + time + res.tempFiles[0]
|
|
|
+ .name
|
|
|
}
|
|
|
-
|
|
|
- },
|
|
|
- fail(err) {
|
|
|
- if (err.errCode == 0) {
|
|
|
- uni.showToast({
|
|
|
- title: '已取消',
|
|
|
- icon: "error"
|
|
|
- });
|
|
|
- } else if (err.errCode == 12) {
|
|
|
- uni.showToast({
|
|
|
- title: '已返回',
|
|
|
- icon: "error"
|
|
|
- });
|
|
|
- } else {
|
|
|
- console.log(err, '图片上传错误');
|
|
|
- uni.showToast({
|
|
|
- title: '请重新上传',
|
|
|
- icon: "error"
|
|
|
- });
|
|
|
+ // #endif
|
|
|
+ // #ifndef H5
|
|
|
+ const formData = {
|
|
|
+ // "policy": data.sign.policy,
|
|
|
+ // "OSSAccessKeyId": data.sign.accessid,
|
|
|
+ // 'success_action_status': 200,
|
|
|
+ // "signature": data.sign.signature,
|
|
|
+ "key": config.file_name + '/' + time + '.png'
|
|
|
}
|
|
|
- uni.hideLoading()
|
|
|
- reject(err)
|
|
|
+ // #endif
|
|
|
+ // console.log(formData,'formData');
|
|
|
+ uni.uploadFile({
|
|
|
+ url: url, //仅为示例,非真实的接口地址
|
|
|
+ filePath: res.tempFilePaths[0],
|
|
|
+ formData,
|
|
|
+ name: 'file',
|
|
|
+ header: {
|
|
|
+ "Authori-zation": 'Bearer ' + uni
|
|
|
+ .getStorageSync('token')
|
|
|
+ },
|
|
|
+ success: (suc) => {
|
|
|
+ if (suc.statusCode == 200) {
|
|
|
+ suc.data = JSON.parse(suc.data).data;
|
|
|
+ // #ifdef H5
|
|
|
+ const imgurl = [{
|
|
|
+ url:suc.data.url
|
|
|
+ }];
|
|
|
+ // #endif
|
|
|
+ // #ifndef H5
|
|
|
+ const imgurl = [{
|
|
|
+ url:suc.data.url
|
|
|
+ }];
|
|
|
+ // #endif
|
|
|
+ resolve(imgurl)
|
|
|
+ }
|
|
|
+ uni.hideLoading()
|
|
|
+ },
|
|
|
+ file(res) {
|
|
|
+ uni.hideLoading()
|
|
|
+ // console.log(res, '图片上传错误');
|
|
|
+ reject(res)
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '错误',
|
|
|
+ content: e.message,
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
}
|
|
|
- })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail(err) {
|
|
|
+ if (err.errCode == 0) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '已取消',
|
|
|
+ icon: "error"
|
|
|
+ });
|
|
|
+ } else if (err.errCode == 12) {
|
|
|
+ uni.showToast({
|
|
|
+ title: '已返回',
|
|
|
+ icon: "error"
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ console.log(err, '图片上传错误');
|
|
|
+ uni.showToast({
|
|
|
+ title: '请重新上传',
|
|
|
+ icon: "error"
|
|
|
+ });
|
|
|
+ }
|
|
|
+ uni.hideLoading()
|
|
|
+ reject(err)
|
|
|
+ }
|
|
|
})
|
|
|
+ // })
|
|
|
} catch (e) {
|
|
|
uni.hideLoading()
|
|
|
uni.showToast({
|