Commit 3b6d716f by 李嘉林

上传oss

parent 62ebe0f6
......@@ -11,7 +11,7 @@ export default {
let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
console.log(extConfig, "-----------extConfig");
if (JSON.stringify(extConfig) == "{}") {
extConfig = process.env.NODE_ENV == "development" ? { mixid: "antgood", shopid: 67}:{ "mixid":"XYKJ", "shopid":1153 };
extConfig = process.env.NODE_ENV == "development" ? { mixid: "CL", shopid: 1671}:{ "mixid":"CL", "shopid":1166 };
}
......
......@@ -76,6 +76,10 @@ console.log(process.env,'-----------------config------')
update_info(data) {
return requestPOST(`${process.env.OLSHOP_URL}/user/update_info`, data);
},
// 获取oss客户端直传配置
get_oss_config() {
return requestPOST(`${process.env.OLSHOP_URL}/common/getAliyunSign.htm`)
},
}
\ No newline at end of file
......@@ -40,7 +40,7 @@
<script>
import WeCropper from "we-cropper";
import index from "@/api/index";
export default {
name: "mpvue-cropper",
props: {
......@@ -52,6 +52,7 @@ export default {
return {
_wecropper: null,
selectImgUrl: "",
ossConfig: {},
};
},
computed: {
......@@ -94,7 +95,7 @@ export default {
return this._wecropper.getCropperImage(opt, fn);
},
init() {
console.log(this.option.src,'-----------97')
console.log(this.option.src, "-----------97");
this._wecropper = new WeCropper(
Object.assign(this.option, {
id: this._canvasId,
......@@ -119,25 +120,26 @@ export default {
let _this = this;
this._wecropper.getCropperImage().then((path) => {
console.log(path, "---path");
console.log(
`${process.env.ADMIN_URL}/innerApi/baseService/upload/uploadFile.htm`,
"-------url"
);
wx.showLoading({
title: "生成中...",
});
this.fileName = `${_this.ossConfig.dir}${path.split('/')[path.split('/').length-1]}`
wx.uploadFile({
url: `${process.env.ADMIN_URL}/innerApi/baseService/upload/uploadFile.htm`, //仅为示例,非真实的接口地址
url: `${ _this.ossConfig.host}`,
filePath: path,
name: "file",
formData: {
user: "test",
key: _this.fileName,
OSSAccessKeyId: _this.ossConfig.accessid,
policy: _this.ossConfig.policy,
signature: _this.ossConfig.signature,
success_action_status: "200",
},
success(res) {
const data = res.data ? JSON.parse(res.data) : {};
console.log(data, "-----------118--success");
if (data.code == 200) {
_this.selectImgUrl = data.data.imgUrl;
console.log(res, "-----------118--success");
if (res.statusCode == 200) {
let host = _this.ossConfig.host.substr(-1) == '/'?_this.ossConfig.host:`${_this.ossConfig.host}/`
_this.selectImgUrl = `${host}${_this.fileName}`;
wx.setStorageSync("wo-selectImgUrl", _this.selectImgUrl);
wx.hideLoading();
wx.showToast({
......@@ -148,11 +150,17 @@ export default {
setTimeout(() => {
wx.navigateBack();
}, 1000);
} else {
wx.showToast({
title: "生成失败",
icon: "error",
duration: 1000,
});
}
//do something
},
fail(res) {
console.log(res,'-----------------fail')
console.log(res, "-----------------fail");
wx.showToast({
title: "生成失败",
icon: "error",
......@@ -166,8 +174,27 @@ export default {
// this.$emit("cancelSelect");
wx.navigateBack();
},
get_oss_config() {
console.log("-----get_oss_config")
index.get_oss_config().then((res) => {
this.ossConfig = res.data;
console.log(this.ossConfig,'--ossConfig')
});
},
random_string(len) {
len = len || 32;
let chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
let maxPos = chars.length;
let pwd = "";
for (let i = 0; i < len; i++) {
pwd += chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
},
onLoad() {
console.log('------mc---onLoad')
this.get_oss_config();
if (!this.option) {
return console.warn(
"[mpvue-cropper] 请传入option参数\n参数配置见文档:https://we-plugin.github.io/we-cropper/#/api"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment