Commit 3b6d716f by 李嘉林

上传oss

parent 62ebe0f6
...@@ -11,7 +11,7 @@ export default { ...@@ -11,7 +11,7 @@ export default {
let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}; let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
console.log(extConfig, "-----------extConfig"); console.log(extConfig, "-----------extConfig");
if (JSON.stringify(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------') ...@@ -76,6 +76,10 @@ console.log(process.env,'-----------------config------')
update_info(data) { update_info(data) {
return requestPOST(`${process.env.OLSHOP_URL}/user/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 @@ ...@@ -40,7 +40,7 @@
<script> <script>
import WeCropper from "we-cropper"; import WeCropper from "we-cropper";
import index from "@/api/index";
export default { export default {
name: "mpvue-cropper", name: "mpvue-cropper",
props: { props: {
...@@ -52,6 +52,7 @@ export default { ...@@ -52,6 +52,7 @@ export default {
return { return {
_wecropper: null, _wecropper: null,
selectImgUrl: "", selectImgUrl: "",
ossConfig: {},
}; };
}, },
computed: { computed: {
...@@ -94,7 +95,7 @@ export default { ...@@ -94,7 +95,7 @@ export default {
return this._wecropper.getCropperImage(opt, fn); return this._wecropper.getCropperImage(opt, fn);
}, },
init() { init() {
console.log(this.option.src,'-----------97') console.log(this.option.src, "-----------97");
this._wecropper = new WeCropper( this._wecropper = new WeCropper(
Object.assign(this.option, { Object.assign(this.option, {
id: this._canvasId, id: this._canvasId,
...@@ -119,25 +120,26 @@ export default { ...@@ -119,25 +120,26 @@ export default {
let _this = this; let _this = this;
this._wecropper.getCropperImage().then((path) => { this._wecropper.getCropperImage().then((path) => {
console.log(path, "---path"); console.log(path, "---path");
console.log(
`${process.env.ADMIN_URL}/innerApi/baseService/upload/uploadFile.htm`,
"-------url"
);
wx.showLoading({ wx.showLoading({
title: "生成中...", title: "生成中...",
}); });
this.fileName = `${_this.ossConfig.dir}${path.split('/')[path.split('/').length-1]}`
wx.uploadFile({ wx.uploadFile({
url: `${process.env.ADMIN_URL}/innerApi/baseService/upload/uploadFile.htm`, //仅为示例,非真实的接口地址 url: `${ _this.ossConfig.host}`,
filePath: path, filePath: path,
name: "file", name: "file",
formData: { formData: {
user: "test", key: _this.fileName,
OSSAccessKeyId: _this.ossConfig.accessid,
policy: _this.ossConfig.policy,
signature: _this.ossConfig.signature,
success_action_status: "200",
}, },
success(res) { success(res) {
const data = res.data ? JSON.parse(res.data) : {}; console.log(res, "-----------118--success");
console.log(data, "-----------118--success"); if (res.statusCode == 200) {
if (data.code == 200) { let host = _this.ossConfig.host.substr(-1) == '/'?_this.ossConfig.host:`${_this.ossConfig.host}/`
_this.selectImgUrl = data.data.imgUrl; _this.selectImgUrl = `${host}${_this.fileName}`;
wx.setStorageSync("wo-selectImgUrl", _this.selectImgUrl); wx.setStorageSync("wo-selectImgUrl", _this.selectImgUrl);
wx.hideLoading(); wx.hideLoading();
wx.showToast({ wx.showToast({
...@@ -148,11 +150,17 @@ export default { ...@@ -148,11 +150,17 @@ export default {
setTimeout(() => { setTimeout(() => {
wx.navigateBack(); wx.navigateBack();
}, 1000); }, 1000);
} else {
wx.showToast({
title: "生成失败",
icon: "error",
duration: 1000,
});
} }
//do something //do something
}, },
fail(res) { fail(res) {
console.log(res,'-----------------fail') console.log(res, "-----------------fail");
wx.showToast({ wx.showToast({
title: "生成失败", title: "生成失败",
icon: "error", icon: "error",
...@@ -166,8 +174,27 @@ export default { ...@@ -166,8 +174,27 @@ export default {
// this.$emit("cancelSelect"); // this.$emit("cancelSelect");
wx.navigateBack(); 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() { onLoad() {
console.log('------mc---onLoad')
this.get_oss_config();
if (!this.option) { if (!this.option) {
return console.warn( return console.warn(
"[mpvue-cropper] 请传入option参数\n参数配置见文档:https://we-plugin.github.io/we-cropper/#/api" "[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