Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ElectricitySheep
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄媛媛
ElectricitySheep
Commits
31bdc10b
Commit
31bdc10b
authored
Aug 13, 2020
by
罗超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
处理图片压缩
parent
bf46523b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
1 deletion
+17
-1
index.js
src/plug/index.js
+17
-1
No files found.
src/plug/index.js
View file @
31bdc10b
...
@@ -138,6 +138,7 @@ export default {
...
@@ -138,6 +138,7 @@ export default {
// debugger;
// debugger;
console
.
log
(
'filein...'
)
console
.
log
(
'filein...'
)
if
(
fileObj
.
type
==
"image/png"
||
fileObj
.
type
==
"image/jpeg"
)
{
if
(
fileObj
.
type
==
"image/png"
||
fileObj
.
type
==
"image/jpeg"
)
{
let
that
=
this
lrz
(
fileObj
,
{
lrz
(
fileObj
,
{
width
:
750
,
width
:
750
,
quality
:
0.8
quality
:
0.8
...
@@ -145,8 +146,20 @@ export default {
...
@@ -145,8 +146,20 @@ export default {
.
then
(
function
(
rst
)
{
.
then
(
function
(
rst
)
{
//成功时执行
//成功时执行
console
.
log
(
rst
)
console
.
log
(
rst
)
var
arr
=
rst
.
base64
.
split
(
','
);
var
mime
=
arr
[
0
].
match
(
/:
(
.*
?)
;/
)[
1
];
var
bstr
=
atob
(
arr
[
1
]);
var
n
=
bstr
.
length
;
var
u8arr
=
new
Uint8Array
(
n
);
while
(
n
--
)
{
u8arr
[
n
]
=
bstr
.
charCodeAt
(
n
);
}
var
newFile
=
new
File
([
u8arr
],
fileObj
.
name
,
{
type
:
mime
});
debugger
;
console
.
log
(
newFile
);
that
.
uploadStart
(
path
,
newFile
,
callback
)
}).
catch
(
function
(
error
)
{
}).
catch
(
function
(
error
)
{
th
is
.
uploadStart
(
path
,
fileObj
,
callback
)
th
at
.
uploadStart
(
path
,
fileObj
,
callback
)
}).
always
(
function
()
{
}).
always
(
function
()
{
//不管成功或失败,都会执行
//不管成功或失败,都会执行
})
})
...
@@ -154,6 +167,8 @@ export default {
...
@@ -154,6 +167,8 @@ export default {
},
},
Vue
.
prototype
.
uploadStart
=
function
(
path
,
fileObj
,
callback
)
{
Vue
.
prototype
.
uploadStart
=
function
(
path
,
fileObj
,
callback
)
{
console
.
log
(
fileObj
)
debugger
;
//获取文件扩展名
//获取文件扩展名
var
filename
=
fileObj
.
name
;
var
filename
=
fileObj
.
name
;
var
index
=
filename
.
lastIndexOf
(
"."
);
var
index
=
filename
.
lastIndexOf
(
"."
);
...
@@ -185,6 +200,7 @@ export default {
...
@@ -185,6 +200,7 @@ export default {
Body
:
fileObj
,
// 上传文件对象
Body
:
fileObj
,
// 上传文件对象
onProgress
:
function
(
progressData
)
{}
onProgress
:
function
(
progressData
)
{}
},
function
(
err
,
data
)
{
},
function
(
err
,
data
)
{
debugger
;
if
(
data
&&
data
.
statusCode
==
200
)
{
if
(
data
&&
data
.
statusCode
==
200
)
{
var
uploadResult
=
{
var
uploadResult
=
{
resultCode
:
1
,
resultCode
:
1
,
...
...
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