Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mayi-mp-shop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
程默
mayi-mp-shop
Commits
3b6d716f
Commit
3b6d716f
authored
Nov 14, 2021
by
李嘉林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传oss
parent
62ebe0f6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
14 deletions
+46
-14
src/App.vue
+1
-1
src/api/index.js
+5
-0
src/components/mpvue-cropper.vue
+40
-13
No files found.
src/App.vue
View file @
3b6d716f
...
...
@@ -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
};
}
...
...
src/api/index.js
View file @
3b6d716f
...
...
@@ -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
src/components/mpvue-cropper.vue
View file @
3b6d716f
...
...
@@ -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
)
{
cons
t
data
=
res
.
data
?
JSON
.
parse
(
res
.
data
)
:
{}
;
console
.
log
(
data
,
"-----------118--success"
);
if
(
data
.
code
==
200
)
{
_this
.
selectImgUrl
=
data
.
data
.
imgUrl
;
cons
ole
.
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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment