/
ex-downloadFile.html
77 lines (60 loc) · 2.35 KB
/
ex-downloadFile.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-tw">
<head>
<meta http-equiv="content-type" content="text/html charset=UTF-8" />
<title>downloadFile</title>
<!-- @babel/polyfill已廢棄 -->
<script nomodule src="https://cdn.jsdelivr.net/npm/@babel/polyfill@7.12.1/dist/polyfill.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/wsemi/dist/wsemi.umd.js"></script>
<script src="https://cdn.jsdelivr.net/npm/w-ui-dwload@1.0.10/dist/w-ui-dwload.umd.js"></script>
</head>
<body>
<div style="padding:10px;">
<button onclick="dw()">download</button>
</div>
<script>
let WUiDwload = window['w-ui-dwload']
// console.log(WUiDwload)
let file = {
'id': 'id-for-file',
}
//wuidw
let vo = {
updateLoading: (v)=>{
console.log('updateLoading', v)
},
alert: (v, t)=>{
console.log('alert', v, t)
},
downloadFileById: (fileId)=>{
//記得添加BOM
let u8a = wsemi.str2u8arr(`\ufeff中文測試
Plain text, unformatted text
Text file, a type of computer file opened by most text software
Text string, a sequence of characters manipulated by software
Text message, a short electronic message designed for communication between mobile phone users
Text (Chrome app), a text editor for the Google Chrome web browser`)
return {
fileName:'name-for-file',
u8a,
type:'text/plain',
}
},
}
let wuidw = WUiDwload(vo, {
keyFunDownloadFileById: 'downloadFileById',
keyFunUpdateLoading: 'updateLoading',
keyFunAlert: 'alert',
})
console.log(wuidw)
function dw(){
wuidw.downloadFile(file)
}
</script>
<pre id="container" style="border:1px solid #333;"></pre>
<script>
let eleTar = document.querySelector('#container')
eleTar.innerHTML = JSON.stringify(file, null, 2)
</script>
</body>
</html>