Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xiaomai-cloud-class-web
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
xiaomai-cloud-class
xiaomai-cloud-class-web
Commits
191c33c9
Commit
191c33c9
authored
Jul 04, 2021
by
zhangleyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:处理图片裁剪
parent
47bf5707
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
172 additions
and
3 deletions
+172
-3
src/core/downloads.js
+168
-0
src/index.html
+2
-2
src/index.tsx
+2
-1
No files found.
src/core/downloads.js
0 → 100644
View file @
191c33c9
/*
* @Author: your name
* @Date: 2021-07-02 17:15:50
* @LastEditTime: 2021-07-02 17:23:47
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /xiaomai-cloud-class-web/src/core/downLoad.js
*/
(
function
(
root
,
factory
)
{
if
(
typeof
define
===
'function'
&&
define
.
amd
)
{
// AMD. Register as an anonymous module.
define
([],
factory
);
}
else
if
(
typeof
exports
===
'object'
)
{
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module
.
exports
=
factory
();
}
else
{
// Browser globals (root is window)
root
.
download
=
factory
();
}
})(
this
,
function
()
{
return
function
download
(
data
,
strFileName
,
strMimeType
)
{
var
self
=
window
,
// this script is only for browsers anyway...
defaultMime
=
'application/octet-stream'
,
// this default mime also triggers iframe downloads
mimeType
=
strMimeType
||
defaultMime
,
payload
=
data
,
url
=
!
strFileName
&&
!
strMimeType
&&
payload
,
anchor
=
document
.
createElement
(
'a'
),
toString
=
function
(
a
)
{
return
String
(
a
);
},
myBlob
=
self
.
Blob
||
self
.
MozBlob
||
self
.
WebKitBlob
||
toString
,
fileName
=
strFileName
||
'download'
,
blob
,
reader
;
myBlob
=
myBlob
.
call
?
myBlob
.
bind
(
self
)
:
Blob
;
if
(
String
(
this
)
===
'true'
)
{
//reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
payload
=
[
payload
,
mimeType
];
mimeType
=
payload
[
0
];
payload
=
payload
[
1
];
}
if
(
url
&&
url
.
length
<
2048
)
{
// if no filename and no mime, assume a url was passed as the only argument
fileName
=
url
.
split
(
'/'
).
pop
().
split
(
'?'
)[
0
];
anchor
.
href
=
url
;
// assign href prop to temp anchor
if
(
anchor
.
href
.
indexOf
(
url
)
!==
-
1
)
{
// if the browser determines that it's a potentially valid url path:
var
ajax
=
new
XMLHttpRequest
();
ajax
.
open
(
'GET'
,
url
,
true
);
ajax
.
responseType
=
'blob'
;
ajax
.
onload
=
function
(
e
)
{
download
(
e
.
target
.
response
,
fileName
,
defaultMime
);
};
setTimeout
(
function
()
{
ajax
.
send
();
},
0
);
// allows setting custom ajax headers using the return:
return
ajax
;
}
// end if valid url?
}
// end if url?
//go ahead and download dataURLs right away
if
(
/^data
\:[\w
+
\-]
+
\/[\w
+
\-]
+
[
,;
]
/
.
test
(
payload
))
{
if
(
payload
.
length
>
1024
*
1024
*
1.999
&&
myBlob
!==
toString
)
{
payload
=
dataUrlToBlob
(
payload
);
mimeType
=
payload
.
type
||
defaultMime
;
}
else
{
return
navigator
.
msSaveBlob
// IE10 can't do a[download], only Blobs:
?
navigator
.
msSaveBlob
(
dataUrlToBlob
(
payload
),
fileName
)
:
saver
(
payload
);
// everyone else can save dataURLs un-processed
}
}
//end if dataURL passed?
blob
=
payload
instanceof
myBlob
?
payload
:
new
myBlob
([
payload
],
{
type
:
mimeType
});
function
dataUrlToBlob
(
strUrl
)
{
var
parts
=
strUrl
.
split
(
/
[
:;,
]
/
),
type
=
parts
[
1
],
decoder
=
parts
[
2
]
==
'base64'
?
atob
:
decodeURIComponent
,
binData
=
decoder
(
parts
.
pop
()),
mx
=
binData
.
length
,
i
=
0
,
uiArr
=
new
Uint8Array
(
mx
);
for
(
i
;
i
<
mx
;
++
i
)
uiArr
[
i
]
=
binData
.
charCodeAt
(
i
);
return
new
myBlob
([
uiArr
],
{
type
:
type
});
}
function
saver
(
url
,
winMode
)
{
if
(
'download'
in
anchor
)
{
//html5 A[download]
anchor
.
href
=
url
;
anchor
.
setAttribute
(
'download'
,
fileName
);
anchor
.
className
=
'download-js-link'
;
anchor
.
innerHTML
=
'downloading...'
;
anchor
.
style
.
display
=
'none'
;
document
.
body
.
appendChild
(
anchor
);
setTimeout
(
function
()
{
anchor
.
click
();
document
.
body
.
removeChild
(
anchor
);
if
(
winMode
===
true
)
{
setTimeout
(
function
()
{
self
.
URL
.
revokeObjectURL
(
anchor
.
href
);
},
250
);
}
},
66
);
return
true
;
}
// handle non-a[download] safari as best we can:
if
(
/
(
Version
)\/(\d
+
)\.(\d
+
)(?:\.(\d
+
))?
.*Safari
\/
/
.
test
(
navigator
.
userAgent
))
{
url
=
url
.
replace
(
/^data:
([\w\/\-\+]
+
)
/
,
defaultMime
);
if
(
!
window
.
open
(
url
))
{
// popup blocked, offer direct download:
if
(
confirm
(
'Displaying New Document
\
n
\
nUse Save As... to download, then click back to return to this page.'
))
{
location
.
href
=
url
;
}
}
return
true
;
}
//do iframe dataURL download (old ch+FF):
var
f
=
document
.
createElement
(
'iframe'
);
document
.
body
.
appendChild
(
f
);
if
(
!
winMode
)
{
// force a mime that will download:
url
=
'data:'
+
url
.
replace
(
/^data:
([\w\/\-\+]
+
)
/
,
defaultMime
);
}
f
.
src
=
url
;
setTimeout
(
function
()
{
document
.
body
.
removeChild
(
f
);
},
333
);
}
//end saver
if
(
navigator
.
msSaveBlob
)
{
// IE10+ : (has Blob, but not a[download] or URL)
return
navigator
.
msSaveBlob
(
blob
,
fileName
);
}
if
(
self
.
URL
)
{
// simple fast and modern way using Blob and URL:
saver
(
self
.
URL
.
createObjectURL
(
blob
),
true
);
}
else
{
// handle non-Blob()+non-URL browsers:
if
(
typeof
blob
===
'string'
||
blob
.
constructor
===
toString
)
{
try
{
return
saver
(
'data:'
+
mimeType
+
';base64,'
+
self
.
btoa
(
blob
));
}
catch
(
y
)
{
return
saver
(
'data:'
+
mimeType
+
','
+
encodeURIComponent
(
blob
));
}
}
// Blob but not URL support:
reader
=
new
FileReader
();
reader
.
onload
=
function
(
e
)
{
saver
(
this
.
result
);
};
reader
.
readAsDataURL
(
blob
);
}
return
true
;
};
/* end download() */
});
\ No newline at end of file
src/index.html
View file @
191c33c9
<!--
<!--
* @Author: 吴文洁
* @Author: 吴文洁
* @Date: 2020-08-24 12:20:57
* @Date: 2020-08-24 12:20:57
* @LastEditors:
fusanqiasng
* @LastEditors:
Please set LastEditors
* @LastEditTime: 2021-0
6-21 15:06:27
* @LastEditTime: 2021-0
7-04 09:52:31
* @Description:
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
* @Copyright: 杭州杰竞科技有限公司 版权所有
-->
-->
...
...
src/index.tsx
View file @
191c33c9
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Author: 吴文洁
* @Date: 2020-04-27 20:35:34
* @Date: 2020-04-27 20:35:34
* @LastEditors: Please set LastEditors
* @LastEditors: Please set LastEditors
* @LastEditTime: 2021-0
6-23 14:14:20
* @LastEditTime: 2021-0
7-04 09:52:45
* @Description:
* @Description:
*/
*/
...
@@ -18,6 +18,7 @@ import 'antd/dist/antd.less';
...
@@ -18,6 +18,7 @@ import 'antd/dist/antd.less';
import
'video-react/dist/video-react.css'
;
import
'video-react/dist/video-react.css'
;
import
'@/common/less/index.less'
;
import
'@/common/less/index.less'
;
import
'@/core/function'
;
import
'@/core/function'
;
// import '@/core/downloads';
import
'@/core/xmTD'
;
import
'@/core/xmTD'
;
import
User
from
'@/common/js/user'
;
import
User
from
'@/common/js/user'
;
import
Service
from
"@/common/js/service"
;
import
Service
from
"@/common/js/service"
;
...
...
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