Skip to content

Commit 67807c7

Browse files
committed
微信小程序
wepy wept
1 parent 22c70a8 commit 67807c7

36 files changed

+1556
-0
lines changed

mypractice/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

mypractice/.eslintignore

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

mypractice/.eslintrc.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
root: true,
3+
parser: 'babel-eslint',
4+
parserOptions: {
5+
sourceType: 'module'
6+
},
7+
env: {
8+
browser: true
9+
},
10+
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
11+
extends: 'standard',
12+
// required to lint *.wpy files
13+
plugins: [
14+
'html'
15+
],
16+
settings: {
17+
'html/html-extensions': ['.html', '.wpy']
18+
},
19+
// add your custom rules here
20+
'rules': {
21+
// allow paren-less arrow functions
22+
'arrow-parens': 0,
23+
// allow async-await
24+
'generator-star-spacing': 0,
25+
// allow debugger during development
26+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
27+
'space-before-function-paren': 0
28+
}
29+
}

mypractice/.wepycache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\wepy.js":1509350107922,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy-async-function\\index.js":1509350107430,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy-com-toast\\toast.wpy":1509350107533,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\app.js":1509350107534,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\page.js":1509350107784,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\component.js":1509350107634,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\event.js":1509350107687,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\base.js":1509350107591,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\util.js":1509350107865,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\mixin.js":1509350107728,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy-async-function\\global.js":1509350107412,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\promise-polyfill\\promise.js":1509350107687,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\regenerator-runtime\\runtime.js":1509350107541,"C:\\SELFWORKSPACE\\xiaochengxu\\mypractice\\node_modules\\wepy\\lib\\native.js":1509350107761}

mypractice/.wepyignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.DB_store
4+
*.wpy___jb_tmp___

mypractice/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<scroll-view scroll-x="false" scroll-y="false" upper-threshold="50" lower-threshold="50" scroll-top="{{}}" scroll-left="{{}}" scroll-into-view="{{}}" bindscrolltoupper="" bindscrolltolower="" bindscroll="">
2+
3+
</scroll-view>

mypractice/package.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "mypractice",
3+
"version": "1.2.8",
4+
"description": "",
5+
"main": "dist/app.js",
6+
"scripts": {
7+
"dev": "wepy build --watch",
8+
"build": "cross-env NODE_ENV=production wepy build --no-cache",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "",
12+
"license": "MIT",
13+
"dependencies": {
14+
"wepy": "^1.6.0",
15+
"wepy-async-function": "^1.4.4",
16+
"wepy-com-toast": "^1.0.2"
17+
},
18+
"devDependencies": {
19+
"babel-eslint": "^7.2.1",
20+
"babel-plugin-syntax-export-extensions": "^6.13.0",
21+
"babel-plugin-transform-class-properties": "^6.24.1",
22+
"babel-plugin-transform-decorators-legacy": "^1.3.4",
23+
"babel-plugin-transform-export-extensions": "^6.22.0",
24+
"babel-preset-env": "^1.6.1",
25+
"cross-env": "^5.1.1",
26+
"eslint": "^3.18.0",
27+
"eslint-config-standard": "^7.1.0",
28+
"eslint-friendly-formatter": "^2.0.7",
29+
"eslint-plugin-html": "^2.0.1",
30+
"eslint-plugin-promise": "^3.5.0",
31+
"eslint-plugin-standard": "^2.0.1",
32+
"wepy-compiler-babel": "^1.5.1",
33+
"wepy-compiler-less": "^1.3.10",
34+
"wepy-eslint": "^1.5.2"
35+
}
36+
}

mypractice/src/app.wpy

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<style lang="less">
2+
.container {
3+
height: 100%;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: space-between;
8+
box-sizing: border-box;
9+
}
10+
</style>
11+
12+
<script>
13+
import wepy from 'wepy'
14+
import 'wepy-async-function'
15+
16+
export default class extends wepy.app {
17+
config = {
18+
pages: [
19+
'pages/my',
20+
'pages/home'
21+
],
22+
window: {
23+
backgroundTextStyle: 'light',
24+
navigationBarBackgroundColor: '#fff',
25+
navigationBarTitleText: 'WeChat',
26+
navigationBarTextStyle: 'black'
27+
}
28+
}
29+
30+
globalData = {
31+
userInfo: null
32+
}
33+
34+
constructor () {
35+
super()
36+
this.use('requestfix')
37+
}
38+
39+
onLaunch() {
40+
this.testAsync()
41+
}
42+
43+
sleep (s) {
44+
return new Promise((resolve, reject) => {
45+
setTimeout(() => {
46+
resolve('promise resolved')
47+
}, s * 1000)
48+
})
49+
}
50+
51+
async testAsync () {
52+
const data = await this.sleep(3)
53+
console.log(data)
54+
}
55+
56+
getUserInfo(cb) {
57+
const that = this
58+
if (this.globalData.userInfo) {
59+
return this.globalData.userInfo
60+
}
61+
wepy.getUserInfo({
62+
success (res) {
63+
that.globalData.userInfo = res.userInfo
64+
cb && cb(res.userInfo)
65+
}
66+
})
67+
}
68+
}
69+
</script>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<style lang="less">
2+
.counter {
3+
text-align: left;
4+
font-size: 12px;
5+
}
6+
.count {
7+
font-size: 18px;
8+
font-weight: bold;
9+
&.red {
10+
color: red;
11+
}
12+
&.green {
13+
color: green;
14+
}
15+
}
16+
</style>
17+
<template>
18+
<view class="counter {{style}}">
19+
<button @tap="plus" size="mini"> + </button>
20+
<button @tap="minus" size="mini"> - </button>
21+
<text class="count" :class="{red: num > 55, green: num < 45}"> {{num}} </text>
22+
</view>
23+
</template>
24+
<script>
25+
import wepy from 'wepy'
26+
// import abc from 'abc'
27+
28+
export default class Counter extends wepy.component {
29+
props = {
30+
num: {
31+
type: [Number, String],
32+
coerce: function (v) {
33+
return +v
34+
},
35+
default: 50
36+
}
37+
}
38+
39+
data = {
40+
}
41+
events = {
42+
'index-broadcast': (...args) => {
43+
let $event = args[args.length - 1]
44+
console.log(`${this.$name} receive ${$event.name} from ${$event.source.$name}`)
45+
}
46+
}
47+
48+
watch = {
49+
num (curVal, oldVal) {
50+
console.log(`旧值:${oldVal},新值:${curVal}`)
51+
}
52+
}
53+
54+
methods = {
55+
plus () {
56+
this.num = this.num + 1
57+
console.log(this.$name + ' plus tap')
58+
59+
this.$emit('index-emit', 1, 2, 3)
60+
},
61+
minus () {
62+
this.num = this.num - 1
63+
console.log(this.$name + ' minus tap')
64+
}
65+
}
66+
}
67+
</script>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<style type="less">
2+
.group {}
3+
</style>
4+
<template>
5+
<view class="group">
6+
<text class="id">{{grouplist.id}}. </text>
7+
<text class="name" @tap="tap">{{grouplist.name}}</text>
8+
<view>
9+
<repeat for="{{grouplist.list}}" item="item">
10+
<groupitem :gitem="item"></groupitem>
11+
</repeat>
12+
</view>
13+
</view>
14+
</template>
15+
<script>
16+
import wepy from 'wepy'
17+
import GroupItem from './groupitem'
18+
19+
export default class Group extends wepy.component {
20+
props = {
21+
grouplist: {},
22+
index: {}
23+
}
24+
25+
components = {
26+
groupitem: GroupItem
27+
}
28+
methods = {
29+
tap () {
30+
this.grouplist.name = `Parent Random(${Math.random()})`
31+
console.log(`Clicked Group ${this.$index}, ID is ${this.grouplist.id}`)
32+
}
33+
}
34+
}
35+
</script>

0 commit comments

Comments
 (0)