Skip to content

Commit f7b3934

Browse files
committed
init
0 parents  commit f7b3934

35 files changed

+2674
-0
lines changed

.babelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sourceMap": "inline",
3+
"presets": ["es2015"],
4+
"plugins": [
5+
"add-module-exports"
6+
]
7+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dest

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src
2+
test
3+
example

Readme.md

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# wept-sdk
2+
3+
小程序 native 组件 web 端实现
4+
5+
## 模块
6+
7+
* `compass` 罗盘模块,提供 `watch``unwatch` 方法
8+
9+
``` js
10+
let id = compass.watch(direction => {
11+
// direction 为面对的方向度数
12+
})
13+
Compass.unwatch(id)
14+
```
15+
16+
* `actionSheet` 模块,返回 promise
17+
18+
``` js
19+
actionSheet( {
20+
itemList: ['a', 'b', 'c'],
21+
itemColor: '#000000'
22+
}).then(res => {
23+
if(res.cancel) {
24+
// user cancel
25+
} else {
26+
console.log(res.tapIndex) // index from 0
27+
}
28+
})
29+
```
30+
31+
* `DatePicker` 模块,日期选择
32+
33+
``` js
34+
let picker = new DatePicker({
35+
range: {
36+
start: '2016-01-01',
37+
end: '2018-01-01'
38+
},
39+
})
40+
picker.show()
41+
picker.hide()
42+
picker.on('select', val => {
43+
console.log(val) // yyyy-mm-dd
44+
})
45+
```
46+
47+
* `FileManage` 模块,本地文件管理,使用 IndexDB
48+
49+
``` js
50+
let fileManage = new FileManage({
51+
key: __wxConfig.directory // key for weapp
52+
})
53+
// save to db
54+
fileManage.save(tempFilePath).then(savedPath => {
55+
56+
})
57+
fileManage.getFileList().then(arr => {
58+
// list of file info
59+
})
60+
fileManage.getFileInfo(savedPath).then(info => {
61+
// info.size
62+
// info.createTime
63+
})
64+
fileManage.remove(savedPath).then(() => {
65+
// remove from db
66+
})
67+
```
68+
69+
* `imageInfo` 模块,获取图片大小
70+
71+
``` js
72+
ImageInfo(tempFilePath).then(obj => {
73+
// obj.width
74+
// obj.height
75+
})
76+
```
77+
78+
* `modal` 模块, 弹出窗口
79+
80+
``` js
81+
model({
82+
title: '',
83+
content: '',
84+
imgUrl: ''
85+
}).then(confirm => {
86+
if (confirm) {
87+
} else {
88+
}
89+
})
90+
```
91+
* `mask` 模块,透明遮罩,返回隐藏函数
92+
93+
``` js
94+
let hide = mask()
95+
hide()
96+
```
97+
98+
* `Picker` 模块,弹出选择组件
99+
100+
``` js
101+
let picker = new Picker({
102+
array: ['a', 'b', 'c'],
103+
current: 2
104+
})
105+
picker.show()
106+
picker.hide()
107+
picker.on('select', index => {
108+
// selected index
109+
})
110+
picker.on('hide', () => {
111+
// on picker hide
112+
})
113+
```
114+
115+
* `record` 模块,提供录音功能, 需要全局 `Recorder` 对象支持
116+
117+
``` js
118+
record.startRecord({
119+
fail: function(err) {
120+
},
121+
success: function(url) {
122+
// object url for wav file
123+
}
124+
})
125+
record.stopRecord()
126+
```
127+
128+
* `storage` 模块,提供缓存支持,使用 localStorage
129+
130+
``` js
131+
storage.set(key, value, dataType)
132+
storage.get(key)
133+
storage.remove(key)
134+
storage.clear()
135+
let obj = storage.getAll()
136+
// each key of obj contains data & dataType
137+
let info = storage.info()
138+
// info.keys
139+
// info.limitSize
140+
// info.currentSize
141+
```
142+
143+
* `Timepicker` 模块,时间选择功能
144+
145+
``` js
146+
let picker = new TimePicker({
147+
current: '11:11'
148+
})
149+
picker.show()
150+
picker.hide()
151+
picker.on('select', str => {
152+
// selected time string mm:ss
153+
})
154+
picker.on('cancel', () => {
155+
// on picker cancel
156+
})
157+
```
158+
159+
* `toast` 模块,轻提醒组件
160+
161+
``` js
162+
toast.show({
163+
duration: 1000,
164+
icon: 'waiting',
165+
title: 'wait',
166+
mask: true
167+
})
168+
toast.hide()
169+
```
170+
171+
* `motion` 模块
172+
173+
``` js
174+
motion.watch(res => {
175+
//res.x
176+
//res.y
177+
//res.z
178+
})
179+
motion.unwatch()
180+
```
181+
182+
* `voice` 模块
183+
184+
``` js
185+
voice.play(url).then(res => {
186+
}, err => {
187+
})
188+
voice.pause()
189+
voice.stop()
190+
```
191+
192+
* `music` 模块
193+
194+
``` js
195+
let obj = music.getStatus()
196+
music.on('error', e => {
197+
})
198+
music.play()
199+
music.pause()
200+
music.seek()
201+
music.stop()
202+
```
203+
204+
* `uploadFile` 模块
205+
206+
``` js
207+
uploadFile({
208+
filePath: url,
209+
url: '/'
210+
name: 'file',
211+
headers: {},
212+
formData: {}
213+
}).then(res => {
214+
console.log(res)
215+
done()
216+
})
217+
```
218+
219+
* `downloadFile` 模块
220+
221+
``` js
222+
downloadFile(url, headers, '/remoteProxy').then(res => {
223+
// res.statusCode
224+
// res.tempFilePath
225+
}, err => {
226+
// request error
227+
// err.status for statusCode
228+
})
229+
```
230+
231+
## LICENSE
232+
233+
Copyright 2016 chemzqm@gmail.com
234+
235+
Permission is hereby granted, free of charge, to any person obtaining
236+
a copy of this software and associated documentation files (the "Software"),
237+
to deal in the Software without restriction, including without limitation
238+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
239+
and/or sell copies of the Software, and to permit persons to whom the
240+
Software is furnished to do so, subject to the following conditions:
241+
242+
The above copyright notice and this permission notice shall be included
243+
in all copies or substantial portions of the Software.
244+
245+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
246+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
247+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
248+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
249+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
250+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
251+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

example/index.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
html * {
2+
-webkit-font-smoothing: antialiased;
3+
-moz-osx-font-smoothing: grayscale;
4+
}
5+
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
6+
margin: 0;
7+
padding: 0;
8+
border: 0;
9+
font-size: 100%;
10+
vertical-align: baseline;
11+
text-decoration: none;
12+
}
13+
html, body {
14+
height: 100%;
15+
}
16+
body {
17+
line-height: 1;
18+
overflow-y: hidden;
19+
overflow-x: hidden;
20+
}
21+
*, ::after, ::before {
22+
box-sizing: border-box;
23+
}

example/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="zh-CN">
3+
<head>
4+
<link href="https://res.wx.qq.com/mpres/htmledition/images/favicon218877.ico" rel="Shortcut Icon">
5+
<meta charset="UTF-8" />
6+
<link rel="stylesheet" type="text/css" href="/index.css">
7+
<link rel="stylesheet" type="text/css" href="/style.css">
8+
<meta name="viewport" content="width=device-width, height=device-height,user-scalable=no, initial-scale=1.0" />
9+
<script src="/recorder.js"></script>
10+
</head>
11+
<body>
12+
<audio id="audio" type="audio/mp3" style="display:none;"></audio>
13+
<audio id="background-audio" type="audio/mp3" style="display:none;"></audio>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)