diff --git a/api/other.js b/api/other.js new file mode 100644 index 0000000..7fbc362 --- /dev/null +++ b/api/other.js @@ -0,0 +1,12 @@ +/** + * 阿里云文件上传STS + * @param {Object} data + */ +export function getSTS(data) { + + return request({ + url: `${host}/other/get-aliyun-sts`, + method: "get", + data + }); +} \ No newline at end of file diff --git a/config/host.js b/config/host.js index b6fbb95..caf77c6 100644 --- a/config/host.js +++ b/config/host.js @@ -4,5 +4,6 @@ const host='http://47.109.60.201:9501/api' // const host='http://192.168.2.92:9503/api' const imghost='http://live.admin.jinghkb.com' const title = '汪汪行天下' +const oss = 'https://fanyi-guanjia-1.'+'oss-cn-chengdu.aliyuncs.com' // const codehost='http://code.baomingle.cn' -export {host,imghost,title} \ No newline at end of file +export {host,imghost,title,oss} \ No newline at end of file diff --git a/utils/functions.js b/utils/functions.js index 8065b61..db1eadc 100644 --- a/utils/functions.js +++ b/utils/functions.js @@ -5,6 +5,7 @@ import log from "@/utils/log"; const QQMapWX=require('./qqmap-wx-jssdk.min.js') import * as QQMapwx from '@/utils/qqmap-wx-jssdk.min.js' +import {getSTS} from "@/api/other"; var qqmapsdk; import { imghost,host } from '@/config/host.js' const api = { @@ -282,6 +283,47 @@ const api = { uni.setStorageSync('sysInfo',data); resolve(data); }) - } + }, + uploadOssFile:(file)=>{ + return new Promise((resolve, reject) => { + getSTS({}).then(res => { + // const client = new OSS(res.data); + // console.log(file); + uni.showLoading({ + title:'上传中' + }) + let timer = new Date(); + let address = timer.getFullYear() + '' + (timer.getMonth() + 1) + '' + timer.getDate(); + address = 'upload/' + address + '/'; + var imageSrc = file; + let str = file.substr(file.lastIndexOf('.')); + let nameStr = address + timer.getTime() + str; + uni.uploadFile({ + url: `${oss}`, //仅为示例,非真实的接口地址 + filePath:file, + name: 'file', + header: { + "content-type": "application/json;charset=utf-8", + }, + formData:Object.assign({ + name:nameStr, + key:nameStr, + success_action_status: '200', + },res.data), + success: (uploadFileRes) => { + uni.hideLoading() + resolve ({show_path:oss+'/' + nameStr}); + // relove(JSON.parse(uploadFileRes.data).data) + // console.log(JSON.parse(uploadFileRes.data).data); + }, + fail:(res) =>{ + uni.hideLoading() + console.log(res) + return {}; + } + }); + }); + }) + }, } export default api;