You need to sign in or sign up before continuing.
Commit 05e8ea97 by LinChengbiao

Initial commit

parents
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true
},
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
// required to lint *.wpy files
plugins: [
'html'
],
settings: {
'html/html-extensions': ['.html', '.wpy']
},
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'space-before-function-paren': 0
}
}
node_modules
dist
.DS_Store
{
"singleQuote": true
}
node_modules
dist
.DS_Store
*.wpy___jb_tmp___
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "brand-event-library-mini-program",
"version": "0.0.2",
"description": "品牌事件库 for Mini Program",
"main": "dist/app.js",
"scripts": {
"dev": "wepy build --watch",
"build": "cross-env NODE_ENV=production wepy build --no-cache",
"dev:web": "wepy build --output web",
"clean": "find ./dist -maxdepth 1 -not -name 'project.config.json' -not -name 'dist' | xargs rm -rf",
"test": "echo \"Error: no test specified\" && exit 1"
},
"wepy": {
"module-a": false,
"./src/components/list": "./src/components/wepy-list.wpy"
},
"author": "LinChengbiao <1072907338@qq.com>",
"license": "MIT",
"dependencies": {
"redux": "^3.7.2",
"redux-actions": "^2.2.1",
"redux-promise": "^0.5.3",
"wepy-redux": "^1.5.3",
"wepy": "^1.6.0",
"wepy-async-function": "^1.4.4",
"wepy-com-toast": "^1.0.2"
},
"devDependencies": {
"babel-eslint": "^7.2.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"cross-env": "^5.1.3",
"eslint": "^3.18.0",
"eslint-config-standard": "^7.1.0",
"eslint-friendly-formatter": "^2.0.7",
"eslint-plugin-html": "^2.0.1",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^2.0.1",
"wepy-eslint": "^1.5.3",
"wepy-compiler-babel": "^1.5.1",
"wepy-compiler-less": "^1.3.10"
}
}
{
"description": "品牌事件库 for Mini Program",
"setting": {
"urlCheck": true,
"es6": false,
"postcss": false,
"minified": false
},
"compileType": "miniprogram",
"appid": "wx7d6fd5c69f342842",
"projectname": "brand-event-library-mini-program",
"miniprogramRoot": "./dist"
}
<style lang="less">
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
box-sizing: border-box;
}
</style>
<script>
import wepy from 'wepy'
import 'wepy-async-function'
import { setStore } from 'wepy-redux'
import configStore from './store'
const store = configStore()
setStore(store)
export default class extends wepy.app {
config = {
pages: [
'pages/index'
],
window: {
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
navigationBarTextStyle: 'black'
}
}
globalData = {
userInfo: null
}
constructor () {
super()
this.use('requestfix')
}
onLaunch() {
this.testAsync()
}
sleep (s) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('promise resolved')
}, s * 1000)
})
}
async testAsync () {
const data = await this.sleep(3)
console.log(data)
}
getUserInfo(cb) {
const that = this
if (this.globalData.userInfo) {
return this.globalData.userInfo
}
wepy.getUserInfo({
success (res) {
that.globalData.userInfo = res.userInfo
cb && cb(res.userInfo)
}
})
}
}
</script>
<style lang="less">
.counter {
text-align: left;
font-size: 12px;
}
.count {
font-size: 18px;
font-weight: bold;
&.red {
color: red;
}
&.green {
color: green;
}
}
</style>
<template>
<view class="counter {{style}}">
<button @tap="plus" size="mini"> + </button>
<button @tap="minus" size="mini"> - </button>
<button @tap="incNum" size="mini"> INCREMENT </button>
<button @tap="decNum" size="mini"> DECREMENT </button>
<button @tap="asyncInc" size="mini"> ASYNC INCREMENT </button>
<text class="count"> {{num}} </text>
<text class="count"> {{stateNum}} </text>
<text class="count"> {{asyncNum}} </text>
</view>
</template>
<script>
import wepy from 'wepy'
import { connect } from 'wepy-redux'
import { INCREMENT, DECREMENT } from '../store/types/counter'
import { asyncInc } from '../store/actions'
@connect({
stateNum (state) {
return state.counter.num
},
asyncNum (state) {
return state.counter.asyncNum
}
}, {
incNum: INCREMENT,
decNum: DECREMENT,
asyncInc
})
export default class Counter extends wepy.component {
props = {
num: {
type: [Number, String],
coerce: function (v) {
return +v
},
default: 50
}
}
data = {
}
events = {
'index-broadcast': (...args) => {
let $event = args[args.length - 1]
console.log(`${this.$name} receive ${$event.name} from ${$event.source.$name}`)
}
}
watch = {
num (curVal, oldVal) {
console.log(`旧值:${oldVal},新值:${curVal}`)
}
}
methods = {
plus () {
this.num = this.num + 1
console.log(this.$name + ' plus tap')
this.$emit('index-emit', 1, 2, 3)
},
minus () {
this.num = this.num - 1
console.log(this.$name + ' minus tap')
}
}
}
</script>
<style type="less">
.group {}
</style>
<template>
<view class="group">
<text class="id">{{grouplist.id}}. </text>
<text class="name" @tap="tap">{{grouplist.name}}</text>
<view>
<repeat for="{{grouplist.list}}" item="item">
<groupitem :gitem="item"></groupitem>
</repeat>
</view>
</view>
</template>
<script>
import wepy from 'wepy'
import GroupItem from './groupitem'
export default class Group extends wepy.component {
props = {
grouplist: {},
index: {}
}
components = {
groupitem: GroupItem
}
methods = {
tap () {
this.grouplist.name = `Parent Random(${Math.random()})`
console.log(`Clicked Group ${this.$index}, ID is ${this.grouplist.id}`)
}
}
}
</script>
<style type="less">
.groupitem {
}
</style>
<template>
<view class="groupitem">
--<text class="id">{{gitem.childid}}.</text>
<text class="name" @tap="tap"> {{gitem.childname}}</text>
</view>
</template>
<script>
import wepy from 'wepy'
export default class GroupItem extends wepy.component {
props = {
gitem: {}
}
data = {
}
methods = {
tap () {
this.gitem.childname = `Child Random(${Math.random()})`
console.log(`Clicked Group ${this.$parent.$index}. Item ${this.$index}, ID is ${this.gitem.childid}`)
}
}
}
</script>
<style lang="less">
.mylist:odd {
color: red;
}
.mylist:even {
color: green;
}
</style>
<template>
<view class="list">
<view>
<button @tap="add" size="mini">添加列表</button>
</view>
<block wx:for-items="{{list}}" wx:for-index="index" wx:for-item="item" wx:key="id">
<view @tap="tap" class="mylist">
<text>{{item.id}}</text>: {{item.title}}
</view>
</block>
</view>
</template>
<script>
import wepy from 'wepy'
export default class List extends wepy.component {
data = {
list: [
{
id: '0',
title: 'loading'
}
]
}
events = {
'index-broadcast': (...args) => {
let $event = args[args.length - 1]
console.log(`${this.$name} receive ${$event.name} from ${$event.source.name}`)
}
}
methods = {
tap () {
// this.num = this.num + 1
console.log(this.$name + ' tap')
},
add () {
let len = this.list.length
this.list.push({id: len + 1, title: 'title_' + len})
}
}
onLoad () {
}
}
</script>
<style lang="less">
.panel {
width: 100%;
margin-top: 20rpx;
text-align: left;
font-size: 12px;
padding-top: 20rpx;
padding-left: 50rpx;
padding-bottom: 20rpx;
border: 1px solid #ccc;
.title {
padding-bottom: 20rpx;
font-size: 14px;
font-weight: bold;
}
.info {
padding: 15rpx;
}
.testcounter {
margin-top: 15rpx;
position: absolute;
}
.counterview {
margin-left: 120rpx;
}
}
</style>
<template>
<view class="panel">
<slot name="title">
Title
</slot>
<slot>
</slot>
</view>
</template>
<script>
import wepy from 'wepy'
export default class Panel extends wepy.component {
}
</script>
<style lang="less">
.mylist:odd {
color: red;
}
.mylist:even {
color: green;
}
</style>
<template>
<view class="wepy-list">
<view>
<button @tap="add" size="mini">添加列表another</button>
</view>
<block wx:for-items="{{list}}" wx:for-index="index" wx:for-item="item" wx:key="id">
<view @tap="tap" class="mylist">
<text>{{item.id}}</text>: {{item.title}}
</view>
</block>
</view>
</template>
<script>
import wepy from 'wepy'
export default class ListAnother extends wepy.component {
data = {
list: [
{
id: '0',
title: 'loading'
}
]
}
events = {
'index-broadcast': (...args) => {
let $event = args[args.length - 1]
console.log(`${this.$name} receive ${$event.name} from ${$event.source.name}`)
}
}
methods = {
tap () {
// this.num = this.num + 1
console.log(this.$name + ' tap')
},
add () {
let len = this.list.length
this.list.push({id: len + 1, title: 'title_' + len})
}
}
onLoad () {
}
}
</script>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta content="telephone=no" name="format-detection">
<title>转 WEB DEMO</title>
<style>
html, body, #app {height: 100%;}
</style>
</head>
<body>
<div id="app">
<router-view></router-view>
<script src="./index.js"></script>
</div>
</body>
</html>
import wepy from 'wepy'
export default class testMixin extends wepy.mixin {
data = {
mixin: 'This is mixin data.'
}
methods = {
tap () {
this.mixin = 'mixin data was changed'
console.log('mixin method tap')
}
}
onShow() {
console.log('mixin onShow')
}
onLoad() {
console.log('mixin onLoad')
}
}
<style lang="less">
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
</style>
<template>
<view class="container">
<view class="userinfo" @tap="handleViewTap">
<image class="userinfo-avatar" src="{{ userInfo.avatarUrl }}" background-size="cover"/>
<view class="userinfo-nickname">{{ userInfo.nickName }}</view>
</view>
<panel>
<view class="title" slot="title">测试数据绑定</view>
<text class="info">{{normalTitle}}</text>
<text class="info">{{setTimeoutTitle}}</text>
<text class="info">{{mixin}}</text>
<text class="info">{{mynum}}</text>
<text class="info">{{now}}</text>
<text class="info">{{num}}</text>
<text class="info">{{asyncNum}}</text>
<text class="info">{{sumNum}}</text>
<button @tap="plus('a')" size="mini"> + </button>
</panel>
<panel>
<view class="title" slot="title">其它测试</view>
<button @tap="toast" size="mini">第三方组件</button>
<button @tap="communicate" size="mini">组件通信</button>
<button @tap="tap" size="mini">混合TAP事件</button>
</panel>
<panel>
<view class="title" slot="title">测试并发网络请求</view>
<view>返回结果: <text>{{netrst}}</text></view>
<button @tap="request" size="mini"> 点我发起10个请求 </button>
</panel>
<panel>
<view class="title" slot="title">测试组件</view>
<text class="testcounter">计数组件1: </text>
<view class="counterview">
<counter1 @index-emit.user="counterEmit" />
</view>
<text class="testcounter">计数组件2: </text>
<view class="counterview">
<counter2 :num.sync="mynum"></counter2>
</view>
</panel>
<panel>
<view class="title" slot="title">测试组件Repeat</view>
<repeat for="" index="index" item="item" key="key">
<group :grouplist="item" :indexa="index"></group>
</repeat>
</panel>
<panel>
<view class="title" slot="title">测试列表</view>
<list></list>
</panel>
<toast />
</view>
</template>
<script>
import wepy from 'wepy'
import { connect } from 'wepy-redux'
import Panel from '@/components/panel' // alias example
import Counter from 'counter' // alias example
import List from '../components/list' // aliasFields example
import moduleA from 'module-a' // aliasFields ignore module example
import Group from '../components/group'
import Toast from 'wepy-com-toast'
import testMixin from '../mixins/test'
console.log('moduleA ignored: ', moduleA) // => moduleA ignored: {}
@connect({
num (state) {
return state.counter.num
},
asyncNum (state) {
return state.counter.asyncNum
},
sumNum (state) {
return state.counter.num + state.counter.asyncNum
}
})
export default class Index extends wepy.page {
config = {
navigationBarTitleText: 'test'
}
components = {
panel: Panel,
counter1: Counter,
counter2: Counter,
list: List,
group: Group,
toast: Toast
}
mixins = [testMixin]
data = {
mynum: 20,
userInfo: {
nickName: '加载中...'
},
normalTitle: '原始标题',
setTimeoutTitle: '标题三秒后会被修改',
count: 0,
netrst: '',
groupList: [
{
id: 1,
name: '点击改变',
list: [
{
childid: '1.1',
childname: '子项,点我改变'
}, {
childid: '1.2',
childname: '子项,点我改变'
}, {
childid: '1.3',
childname: '子项,点我改变'
}
]
},
{
id: 2,
name: '点击改变',
list: [
{
childid: '2.1',
childname: '子项,点我改变'
}, {
childid: '2.2',
childname: '子项,点我改变'
}, {
childid: '2.3',
childname: '子项,点我改变'
}
]
},
{
id: 3,
name: '点击改变',
list: [
{
childid: '3.1',
childname: '子项,点我改变'
}
]
}
]
}
computed = {
now () {
return +new Date()
}
}
methods = {
plus () {
this.mynum++
},
toast () {
let promise = this.$invoke('toast', 'show', {
title: '自定义标题',
img: 'https://raw.githubusercontent.com/kiinlam/wetoast/master/images/star.png'
})
promise.then((d) => {
console.log('toast done')
})
},
tap () {
console.log('do noting from ' + this.$name)
},
communicate () {
console.log(this.$name + ' tap')
this.$invoke('counter2', 'minus', 45, 6)
this.$invoke('counter1', 'plus', 45, 6)
this.$broadcast('index-broadcast', 1, 3, 4)
},
request () {
let self = this
let i = 10
let map = ['MA==', 'MQo=', 'Mg==', 'Mw==', 'NA==', 'NQ==', 'Ng==', 'Nw==', 'OA==', 'OQ==']
while (i--) {
wepy.request({
url: 'https://www.madcoder.cn/tests/sleep.php?time=1&t=css&c=' + map[i] + '&i=' + i,
success: function (d) {
self.netrst += d.data + '.'
self.$apply()
}
})
}
},
counterEmit (...args) {
let $event = args[args.length - 1]
console.log(`${this.$name} receive ${$event.name} from ${$event.source.$name}`)
}
}
events = {
'index-emit': (...args) => {
let $event = args[args.length - 1]
console.log(`${this.$name} receive ${$event.name} from ${$event.source.$name}`)
}
}
onLoad() {
let self = this
this.$parent.getUserInfo(function (userInfo) {
if (userInfo) {
self.userInfo = userInfo
}
self.normalTitle = '标题已被修改'
self.setTimeoutTitle = '标题三秒后会被修改'
setTimeout(() => {
self.setTimeoutTitle = '到三秒了'
self.$apply()
}, 3000)
self.$apply()
})
}
}
</script>
import { ASYNC_INCREMENT } from '../types/counter'
import { createAction } from 'redux-actions'
export const asyncInc = createAction(ASYNC_INCREMENT, () => {
return new Promise(resolve => {
setTimeout(() => {
resolve(1)
}, 1000)
})
})
\ No newline at end of file
export * from './counter'
\ No newline at end of file
import { createStore, applyMiddleware } from 'redux'
import promiseMiddleware from 'redux-promise'
import rootReducer from './reducers'
export default function configStore () {
const store = createStore(rootReducer, applyMiddleware(promiseMiddleware))
return store
}
\ No newline at end of file
import { handleActions } from 'redux-actions'
import { INCREMENT, DECREMENT, ASYNC_INCREMENT } from '../types/counter'
export default handleActions({
[INCREMENT] (state) {
return {
...state,
num: state.num + 1
}
},
[DECREMENT] (state) {
return {
...state,
num: state.num - 1
}
},
[ASYNC_INCREMENT] (state, action) {
return {
...state,
asyncNum: state.asyncNum + action.payload
}
}
}, {
num: 0,
asyncNum: 0
})
\ No newline at end of file
import { combineReducers } from 'redux'
import counter from './counter'
export default combineReducers({
counter
})
\ No newline at end of file
export const INCREMENT = 'INCREMENT'
export const DECREMENT = 'DECREMENT'
export const ASYNC_INCREMENT = 'ASYNC_INCREMENT'
\ No newline at end of file
export * from './counter'
\ No newline at end of file
const path = require('path');
var prod = process.env.NODE_ENV === 'production';
module.exports = {
wpyExt: '.wpy',
eslint: true,
cliLogs: !prod,
build: {
web: {
htmlTemplate: path.join('src', 'index.template.html'),
htmlOutput: path.join('web', 'index.html'),
jsOutput: path.join('web', 'index.js')
}
},
resolve: {
alias: {
counter: path.join(__dirname, 'src/components/counter'),
'@': path.join(__dirname, 'src')
},
aliasFields: ['wepy', 'weapp'],
modules: ['node_modules']
},
compilers: {
less: {
compress: prod
},
/*sass: {
outputStyle: 'compressed'
},*/
babel: {
sourceMap: true,
presets: [
'env'
],
plugins: [
'transform-class-properties',
'transform-decorators-legacy',
'transform-object-rest-spread',
'transform-export-extensions',
]
}
},
plugins: {
},
appConfig: {
noPromiseAPI: ['createSelectorQuery']
}
}
if (prod) {
// 压缩sass
// module.exports.compilers['sass'] = {outputStyle: 'compressed'}
// 压缩js
module.exports.plugins = {
uglifyjs: {
filter: /\.js$/,
config: {
}
},
imagemin: {
filter: /\.(jpg|png|jpeg)$/,
config: {
jpg: {
quality: 80
},
png: {
quality: 80
}
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment