Commit c591a6d4 authored by ziyu's avatar ziyu

feat: 删除不必要的

parent 66e309a5
......@@ -9,4 +9,4 @@
"navigationBarTextStyle": "black"
},
"sitemapLocation": "sitemap.json"
}
\ No newline at end of file
}
Component({
data: {
text: '00:00.000'
},
methods: {
start: function() {
var convertTimeStampToString = function(ts) {
var ms = String(1000 + Math.floor(ts) % 1000).slice(1)
var s = String(100 + Math.floor(ts / 1000) % 60).slice(1)
var m = Math.floor(ts / 60000)
if (m < 10) m = '0' + m
return m + ':' + s + '.' + ms
}
this.setData({
text: convertTimeStampToString(0)
})
var startTime = Date.now()
var self = this
this._interval = setInterval(function() {
self.setData({
text: convertTimeStampToString(Date.now() - startTime)
})
}, 33)
},
stop: function() {
clearInterval(this._interval)
}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
{{text}}
\ No newline at end of file
/* components/stopwatch.wxss */
\ No newline at end of file
const app = getApp()
Page({
data: {
started: false
},
start: function() {
this.setData({
started: true
})
this.selectComponent('#stopwatch').start()
},
stop: function() {
this.setData({
started: false
})
this.selectComponent('#stopwatch').stop()
}
})
{
"usingComponents": {
"stopwatch": "../components/stopwatch"
}
}
\ No newline at end of file
<view>
<stopwatch id="stopwatch" class="stopwatch" />
<button class="btn" wx:if="{{!started}}" bindtap="start">开始计时</button>
<button class="btn" wx:if="{{started}}" bindtap="stop">停止计时</button>
</view>
\ No newline at end of file
.stopwatch {
font-family: monospace;
font-size: 32px;
text-align: center;
display: block;
margin: 60rpx;
}
.btn {
margin: 60rpx;
}
// page/index.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
\ No newline at end of file
{
"usingComponents": {}
}
\ No newline at end of file
<!--page/index.wxml-->
<text>page/index.wxml</text>
/* page/index.wxss */
\ No newline at end of file
<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/core';
import eventHub from './common/eventHub';
......@@ -20,38 +9,39 @@ wepy.app({
hooks: {
// App 级别 hook,对整个 App 生效
// 同时存在 Page hook 和 App hook 时,优先执行 Page hook,返回值再交由 App hook 处
'before-setData': function (dirty) {
console.log('setData dirty: ', dirty);
return dirty;
}
},
globalData: {
userInfo: null
},
onLaunch() {
this.testAsync();
eventHub.$on('app-launch', (...args) => {
console.log('app-launch event emitted, the params are:');
console.log(args);
});
},
let that= this;
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
that.globalData.userInfo = res.userInfo
methods: {
sleep (s) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('promise resolved');
}, s * 1000);
});
},
async testAsync () {
let d = await this.sleep(3);
console.log(d);
}
}
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (that.userInfoReadyCallback) {
that.userInfoReadyCallback(res)
}
}
})
}else{
// 未授权,跳转到授权页面
wx.reLaunch({
url: '/pages/auth/auth',
})
}
}
})
},
methods: {}
});
</script>
<config>
......@@ -60,6 +50,7 @@ wepy.app({
'pages/index'
],
window: {
navigationStyle: "custom",
backgroundTextStyle: 'light',
navigationBarBackgroundColor: '#fff',
navigationBarTitleText: 'WeChat',
......
<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>
<div class="counter {{style}}">
<button @tap="plus" size="mini"> + </button>
<button @tap="minus" size="mini"> - </button>
<button @tap="increment" size="mini"> INCREMENT </button>
<button @tap="decrement" size="mini"> DECREMENT </button>
<button @tap="incrementAsync" size="mini"> ASYNC INCREMENT </button>
<span class="count"> {{counter}} </span>
</div>
</template>
<script>
import wepy from '@wepy/core';
import store from '../store';
import { mapState, mapActions } from '@wepy/x';
wepy.component({
store,
props: {
num: {
type: [Number, String],
coerce: function (v) {
return +v;
},
default: 50
}
},
computed: mapState([ 'counter' ]),
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: {
...mapActions([
'increment',
'decrement',
'incrementAsync'
]),
plus () {
this.num = this.num + 1;
console.log('plus tapped in component');
this.$emit('index-emit', this.num);
},
minus () {
this.num = this.num - 1;
console.log(this.$name + ' minus tap');
}
}
});
</script>
<style type="less">
.group {}
</style>
<template>
<div class="group">
<span class="id">{{grouplist.id}}. </span>
<span class="name" @tap="tap">{{grouplist.name}}</span>
<div>
<div v-for="item in grouplist.list">
<groupitem :gitem="item"></groupitem>
</div>
</div>
</div>
</template>
<script>
import wepy from '@wepy/core';
// import GroupItem from './groupitem'
wepy.component({
props: {
grouplist: {},
index: {}
},
methods: {
tap () {
this.grouplist.name = `Parent Random(${Math.random()})`;
let groups = this.$parent.$children.filter(com => com.$is === 'components/group');
let index = groups.indexOf(this);
console.log(`Clicked Group ${index}, ID is ${this.grouplist.id}`);
}
}
});
</script>
<config>
{
usingComponents: {
'groupitem': './groupitem'
}
}
</config>
<style type="less">
.groupitem {
}
</style>
<template>
<div class="groupitem">
--<span class="id">{{gitem.childid}}.</span>
<span class="name" @tap="tap"> {{gitem.childname}}</span>
</div>
</template>
<script>
import wepy from '@wepy/core';
wepy.component({
props: {
gitem: {}
},
data: {
},
methods: {
tap () {
this.gitem.childname = `Child Random(${Math.random()})`;
let index = this.$parent.$children.indexOf(this);
console.log(`Item ${index}, ID is ${this.gitem.childid}`);
}
}
});
</script>
<style lang="less">
.mylist:odd {
color: red;
}
.mylist:even {
color: green;
}
</style>
<template>
<div class="list">
This component is not used. because list is an aliasField in package.json
</div>
</template>
<script>
import wepy from '@wepy/core';
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});
}
}
});
</script>
<style lang="less">
panel {
width: 100%;
}
.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>
<div class="panel">
<slot name="title">
Title
</slot>
<slot>
</slot>
</div>
</template>
<style lang="less">
.mylist:odd {
color: red;
}
.mylist:even {
color: green;
}
</style>
<template>
<div class="wepy-list">
<div>
<button @tap="add" size="mini">添加列表another</button>
</div>
<div v-for="(item, index) in list">
<div @tap="tap" class="mylist">
<span>{{item.id}}</span>: {{item.title}} <span @tap="remove(index)"> X </span>
</div>
</div>
</div>
</template>
<script>
import wepy from '@wepy/core';
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});
},
remove (index) {
this.$delete(this.list, index);
}
},
onLoad () {
}
});
</script>
<style lang="less">
input {
border: 1rpx solid #ccc;
display: inline-block;
width: 200rpx;
border-radius: 5rpx;
}
.info {
padding-right: 10rpx;
}
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
}
.userinfo-avatar {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
}
.userinfo-nickname {
color: #aaa;
}
.slide {
width: 640rpx;
display: flex;
border: 1rpx solid #ccc;
font-size: 28rpx;
align-items: center;
box-sizing: border-box;
.left {
width: 750rpx;
padding: 20rpx;
}
.right {
display: flex;
.right-item {
padding: 20rpx 30rpx;
background-color: red;
color: #fff;
}
}
}
</style>
<wxs module="m1" lang="babel">
const getTime = (time) => {
let date = getDate(time);
let hour = date.getHours();
let mins = date.getMinutes();
let sec = date.getSeconds();
let milli = date.getMilliseconds();
return `${hour}:${mins}:${sec}.${milli}`;
}
module.exports.getTime = getTime;
</wxs>
<template>
<div class="container">
<div class="userinfo" @tap="handleViewTap">
<image class="userinfo-avatar" src="{{ userInfo.avatarUrl }}" background-size="cover"/>
<div class="userinfo-nickname">{{ userInfo.nickName }}</div>
</div>
<div>
<div class="title" slot="title">测试数据绑定</div>
<text class="info" @tap="currentTime = +new Date()">{{m1.getTime(currentTime)}}</text>
<text class="info">{{setTimeoutTitle}}</text>
<text class="info" @tap="mixintap">{{mixin}}</text>
<text class="info">{{testcomputed}}</text>
<text class="info">{{counter}}</text>
</div>
<div>
<div class="title" slot="title">其它测试</div>
<!--button @tap="toast" size="mini">第三方组件</button-->
<button @tap="communicate" size="mini">组件通信</button>
<button @tap="tap" size="mini">混合TAP事件</button>
</div>
<div>
<div class="title" slot="title">测试并发网络请求</div>
<div>返回结果: <text>{{netrst}}</text></div>
<button @tap="request" size="mini"> 点我发起10个请求 </button>
</div>
<div>
<div class="title" slot="title">测试 v-model</div>
<div style="display: flex; align-items: center;">
<input v-model="inputmodel" />
<text style="margin-left: 30rpx;">Value: {{inputmodel}}</text>
</div>
</div>
<div>
<div class="title" slot="title">测试组件</div>
<text class="testcounter">全局计数器:</text>
<div class="counterview">
<button @tap="mynum++" size="mini">全局计数器: {{mynum}}</button>
</div>
<text class="testcounter">计数组件1 - num: </text>
<div class="counterview">
// <counter @index-emit.user="counterEmit" />
</div>
<text class="testcounter">计数组件2 - num.sync: </text>
<div class="counterview">
// <counter :num.sync="mynum"></counter>
</div>
</div>
<div>
<div class="title" slot="title">测试组件Repeat</div>
<div v-for="(item, index) in groupList">
<text>{{item.name}}</text>
//<group :grouplist="item" :index="index"></group>
</div>
</div>
<div>
<div class="title" slot="title">测试列表</div>
// <list></list>
</div>
<div>
<div class="title" slot="title">测试引用vant组件</div>
<van-button type="danger">默认按钮</van-button>
</div>
<!--toast /-->
</div>
</template>
<script>
import wepy from '@wepy/core';
import eventHub from '../common/eventHub';
import { mapState } from '@wepy/x';
import store from '../store';
import testMixin from '../mixins/test';
wepy.page({
store,
config: {
navigationBarTitleText: 'test'
},
hooks: {
// Page 级别 hook, 只对当前 Page 的 setData 生效。
'before-setData': function (dirty) {
if (Math.random() < 0.2) {
console.log('setData canceled');
return false; // Cancel setData
}
dirty.time = +new Date();
return dirty;
}
},
mixins: [testMixin],
data: {
inputmodel: 'v-model',
mynum: 20,
userInfo: {
nickName: '加载中...'
},
currentTime: +new Date(),
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: {
...mapState([ 'counter' ]),
testcomputed () {
return 'computed - ' + this.mynum;
}
},
methods: {
handleViewTap () {
console.log('handleVieTap clicked');
},
tap () {
throw new Error('can not go here');
},
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');
});
},
mixintap () {
console.log('do noting from ' + this.$is);
},
communicate () {
let counters = this.$children.filter((com) => com.$is === 'components/counter');
// Get children counter
counters[0].num++;
counters[1].num--;
eventHub.$emit('app-launch', {a: 1}, {b: 2});
},
request () {
let self = this;
let i = 10;
let map = ['MA==', 'MQo=', 'Mg==', 'Mw==', 'NA==', 'NQ==', 'Ng==', 'Nw==', 'OA==', 'OQ=='];
while (i--) {
wx.request({
url: 'https://www.madcoder.cn/tests/sleep.php?time=1&t=css&c=' + map[i] + '&i=' + i,
success: function (d) {
if (d.statusCode !== 200) {
self.netrst += d.statusCode + '.';
} else {
self.netrst += d.data + '.';
}
}
});
}
},
counterEmit (num) {
console.log(`${this.$is} receive event, the number is: ${num}`);
}
},
created () {
let self = this;
self.currentTime = +new Date();
self.setTimeoutTitle = '标题三秒后会被修改';
setTimeout(() => {
self.setTimeoutTitle = '到三秒了';
}, 3000);
wx.getUserInfo({
success (res) {
self.userInfo = res.userInfo;
}
});
}
});
</script>
<config>
{
navigationBarTitleText: 'WePY 2.0 Feature Demo',
usingComponents: {
'van-button': '../components/vant/button/index'
}
}
</config>
......@@ -62,7 +62,7 @@ module.exports.getTime = getTime;
<div class="userinfo-nickname">{{ userInfo.nickName }}</div>
</div>
<panel>
<div>
<div class="title" slot="title">测试数据绑定</div>
<text class="info" @tap="currentTime = +new Date()">{{m1.getTime(currentTime)}}</text>
......@@ -70,30 +70,30 @@ module.exports.getTime = getTime;
<text class="info" @tap="mixintap">{{mixin}}</text>
<text class="info">{{testcomputed}}</text>
<text class="info">{{counter}}</text>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">其它测试</div>
<!--button @tap="toast" size="mini">第三方组件</button-->
<button @tap="communicate" size="mini">组件通信</button>
<button @tap="tap" size="mini">混合TAP事件</button>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">测试并发网络请求</div>
<div>返回结果: <text>{{netrst}}</text></div>
<button @tap="request" size="mini"> 点我发起10个请求 </button>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">测试 v-model</div>
<div style="display: flex; align-items: center;">
<input v-model="inputmodel" />
<text style="margin-left: 30rpx;">Value: {{inputmodel}}</text>
</div>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">测试组件</div>
<text class="testcounter">全局计数器:</text>
......@@ -104,32 +104,33 @@ module.exports.getTime = getTime;
<text class="testcounter">计数组件1 - num: </text>
<div class="counterview">
<counter @index-emit.user="counterEmit" />
// <counter @index-emit.user="counterEmit" />
</div>
<text class="testcounter">计数组件2 - num.sync: </text>
<div class="counterview">
<counter :num.sync="mynum"></counter>
// <counter :num.sync="mynum"></counter>
</div>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">测试组件Repeat</div>
<div v-for="(item, index) in groupList">
<group :grouplist="item" :index="index"></group>
<text>{{item.name}}</text>
//<group :grouplist="item" :index="index"></group>
</div>
</panel>
</div>
<panel>
<div>
<div class="title" slot="title">测试列表</div>
<list></list>
</panel>
// <list></list>
</div>
<panel>
<div>
<div class="title" slot="title">测试引用vant组件</div>
<van-button type="danger">默认按钮</van-button>
</panel>
</div>
<!--toast /-->
</div>
</template>
......@@ -299,10 +300,10 @@ module.exports.getTime = getTime;
{
navigationBarTitleText: 'WePY 2.0 Feature Demo',
usingComponents: {
panel: '~@/components/panel',
counter: '~counter',
list: '../components/list',
group: '../components/group',
// panel: '~@/components/panel',
// counter: '~counter',
// list: '../components/list',
// group: '../components/group',
'van-button': '../components/vant/button/index'
}
}
......
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