forked from hzuapps/web-wechat-2017
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d86dec
commit bf152ca
Showing
6 changed files
with
203 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// pages/form/form.js | ||
Page({ | ||
|
||
/** | ||
* 页面的初始数据 | ||
*/ | ||
data: { | ||
text: 'title', | ||
area: 'content', | ||
count: 'content'.length | ||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面加载 | ||
*/ | ||
onLoad: function (options) { | ||
var that = this; | ||
wx.getStorage({ | ||
key: 'input', | ||
success: function (res) { | ||
console.log(res.data.area.length) | ||
|
||
that.setData({ | ||
text: res.data.text, | ||
area: res.data.area, | ||
count: res.data.area.length | ||
}) | ||
} | ||
}) | ||
|
||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面初次渲染完成 | ||
*/ | ||
onReady: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面显示 | ||
*/ | ||
onShow: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面隐藏 | ||
*/ | ||
onHide: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 生命周期函数--监听页面卸载 | ||
*/ | ||
onUnload: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 页面相关事件处理函数--监听用户下拉动作 | ||
*/ | ||
onPullDownRefresh: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 页面上拉触底事件的处理函数 | ||
*/ | ||
onReachBottom: function () { | ||
|
||
}, | ||
|
||
/** | ||
* 用户点击右上角分享 | ||
*/ | ||
onShareAppMessage: function () { | ||
|
||
}, | ||
|
||
onSubmit: function (event) { | ||
console.dir(event) | ||
var that = this | ||
var text = event.detail.value.text | ||
if (!text) { | ||
console.dir(text) | ||
that.setData({ | ||
hasError: true, | ||
errorText: '标题不能为空!' | ||
}) | ||
} else { | ||
that.setData({ | ||
hasError: false | ||
}) | ||
wx.setStorage({ | ||
key: "input", | ||
data: event.detail.value, | ||
success: function (res) { | ||
wx.showToast({ | ||
title: '添加成功', | ||
icon: 'success', | ||
duration: 2000 | ||
}) | ||
|
||
} | ||
}) | ||
} | ||
}, | ||
|
||
onTextChange: function (e) { | ||
var that = this; | ||
console.dir(e) | ||
var text = e.detail.value | ||
console.dir(text); | ||
if (!text) { | ||
that.setData({ | ||
hasError: true, | ||
errorText: '标题不能为空!' | ||
}) | ||
} else { | ||
that.setData({ | ||
hasError: false | ||
}) | ||
} | ||
}, | ||
|
||
onChange: function (e) { | ||
var that = this; | ||
var value = e.detail.value; | ||
console.dir(value) | ||
that.setData({ | ||
count: value.length | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!--pages/form/form.wxml--> | ||
<view class="page" > | ||
<view class="page__hd"> | ||
<view class="page__title">事项表单</view> | ||
</view> | ||
<view class="page__bd"> | ||
<form bindsubmit='onSubmit'> | ||
<view class="weui-toptips weui-toptips_warn" | ||
wx:if="{{hasError}}">{{errorText}}</view> | ||
|
||
<view class="weui-cells__title">请输入事项标题</view> | ||
<view class="weui-cells weui-cells_after-title"> | ||
<view class="weui-cell weui-cell_input"> | ||
<view class="weui-cell__bd"> | ||
<input class="weui-input" name="text" | ||
value='{{text}}' placeholder="请输入文本" bindinput='onTextChange'/> | ||
</view> | ||
</view> | ||
</view> | ||
|
||
<view class="weui-cells__title">请输入事项内容</view> | ||
<view class="weui-cells weui-cells_after-title"> | ||
<view class="weui-cell"> | ||
<view class="weui-cell__bd"> | ||
<textarea class="weui-textarea" name="area" placeholder="请输入文本" style="height: 4.4em" value='{{area}}' bindinput='onChange'/> | ||
<view class="weui-textarea-counter">{{count}}/300</view> | ||
</view> | ||
</view> | ||
</view> | ||
|
||
<view class="weui-btn-area"> | ||
<button class="weui-btn" type="primary" form-type='submit'>确定</button> | ||
</view> | ||
</form> | ||
</view> | ||
</view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* pages/form/form.wxss */ | ||
.page__hd { | ||
font-size: 18px ; | ||
color:whitesmoke; | ||
text-align: center; | ||
|
||
} | ||
.page__bd{ | ||
font-size: 15px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters