async
getImageFile
()
{
let
that
=
this
;
return
new
Promise
(
async
resolve
=>
{
this
.
$refs
.
cropper
.
getCropData
(
async
data
=>
{
this
.
model
=
true
;
this
.
modelSrc
=
data
;
function
dataURLtoFile
(
dataurl
,
filename
)
{
//將base64轉換爲文件
return
new
Promise
(
async
resolve
=>
{
var
arr
=
dataurl
.
split
(
"
,
"
),
mime
=
arr
[
0
].
match
(
/
:(.
*?
);
/
)
[
1
]
,
bstr
=
atob
(
arr
[
1
]
),
n
=
bstr
.
length
,
u8arr
=
new
Uint8Array
(
n
);
while
(
n
--
)
{
u8arr
[
n
]
=
bstr
.
charCodeAt
(
n
);
}
let
image
=
new
File
(
[
u8arr
]
,
filename
,
{
type:
mime
});
resolve
(
image
);
});
}
let
file
=
await
dataURLtoFile
(
data
,
"
filename.png
"
);
console
.
log
(
file
);
var
image
=
new
FormData
();
image
.
append
(
"
file
"
,
file
);
image
.
append
(
"
contents
"
,
"
redOrgman
"
);
that
.
API
.
getResultApi
({
url:
"
/file/upload
"
,
data:
image
,
method:
"
POST
"
,
headers:
{},
transfer:
3
,
isBody:
2
,
callback
:
function
(
result
)
{
that
.
endLoad
();
let
res
=
result
.
data
;
if
(
res
.
code
===
200
)
{
console
.
log
(
res
);
that
.
$toast
(
"
上傳圖片成功
"
);
that
.
popupVisibles
=
false
;
that
.
from
.
companyLogo
=
"
redOrgman/
"
+
res
.
data
[
0
].
fileName
;
lscache
.
set
(
"
redOrgFrom
"
,
that
.
from
);
}
else
{
that
.
$toast
(
"
上傳圖片失敗
"
);
}
}
});
});
});
}