Skip to content

Commit

Permalink
Merge pull request #1117 from linkzw/master
Browse files Browse the repository at this point in the history
#7 实验7 之前pull request的文件有误
  • Loading branch information
zengsn authored Dec 3, 2018
2 parents ae9fcce + 1117178 commit 6cae54b
Show file tree
Hide file tree
Showing 54 changed files with 1,777 additions and 268 deletions.
39 changes: 39 additions & 0 deletions 1614080902125/memorandum/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//app.js
App({
onLaunch: function () {
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)

// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo

// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
userInfo: null
}
})
32 changes: 32 additions & 0 deletions 1614080902125/memorandum/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"pages": [
"pages/index/index",
"pages/edit/edit",
"pages/logs/logs",
"pages/main/main",
"pages/list",
"pages/list/list"
],
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "记事本",
"navigationBarTextStyle": "black"
},
"tabBar": {
"list": [
{
"pagePath": "pages/index/index",
"selectedIconPath": "pages/img/main2.png",
"iconPath": "pages/img/main1.png",
"text": "主页"
},
{
"selectedIconPath": "pages/img/per2.png",
"iconPath": "pages/img/per1.png",
"pagePath": "pages/logs/logs",
"text": "个人"
}
]
}
}
10 changes: 10 additions & 0 deletions 1614080902125/memorandum/app.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**app.wxss**/
.container {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 200rpx 0;
box-sizing: border-box;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
// pages/add/add.js
// pages/edit/edit.js
Page({

/**
* 页面的初始数据
*/
* 页面的初始数据
*/
data: {
content: ''
},
content: '',
annal_name:'',
hiddenmodalput: true

},
/**
* 生命周期函数--监听页面加载
*/
* 生命周期函数--监听页面加载
*/
onLoad: function (e) {
var id = e.id;
if (id) {
Expand All @@ -22,48 +23,76 @@ Page({
}
},

/**
* input change事件
*/
//input change事件
change(e) {
var val = e.detail.value;
this.setData({
content: val
});
},

/**
* cancel 事件
*/
cancel() {
wx.navigateBack();
//annal_NameInput事件
annal_NameInput: function (e) {
this.setData({
annal_name: e.detail.value
})
},

//cancel 事件
submit() {
var reg = /^\s*$/g;
if (!this.data.content || reg.test(this.data.content)) {
console.log('不能为空');
wx.showModal({
content: '输入为空',
showCancel:false,
success: function (res) {
}
});
return;
}else{
this.setData({
hiddenmodalput: !this.data.hiddenmodalput
})

}
},
//弹框取消
cancel: function () {
this.setData({
hiddenmodalput: true
});
},

//弹框确认事件
confirm: function () {
var reg = /^\s*$/g;
if (!this.data.annal_name || reg.test(this.data.annal_name)){
wx.showModal({
content: '输入为空',
showCancel: false,
success: function (res) {
}
});
return;
}
this.setData({
hiddenmodalput: true,
time: Date.now()
});
setValue(this);
wx.navigateBack();
}
}
})

/**
* 根据跳转的url中的id获取编辑信息回填
*/
function getData(id, page) {
var arr = wx.getStorageSync('txt');
if (arr.length) {
arr.forEach((item) => {
if (item.id == id) {
page.setData({
id: item.id,
content: item.content
content: item.content,
annal_name: item.annal_name
})
}
})
Expand All @@ -75,12 +104,14 @@ function getData(id, page) {
*/
function setValue(page) {
var arr = wx.getStorageSync('txt');
console.log(arr);
var data = [], flag = true;
if (arr.length) {
arr.forEach(item => {
if (item.id == page.data.id) {
item.time = Date.now();
item.content = page.data.content;
item.annal_name = page.data.annal_name;
flag = false;
}
data.push(item);
Expand All @@ -90,4 +121,7 @@ function setValue(page) {
data.push(page.data);
}
wx.setStorageSync('txt', data);
}
}



File renamed without changes.
18 changes: 18 additions & 0 deletions 1614080902125/memorandum/pages/edit/edit.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--pages/edit/edit.wxml-->
<view class="page">
<view style='margin-bottom: 3px;'>
<view class="top">
<button style='border: 0' size="mini" ></button>
<text style='align-items: center;'>编辑备忘录</text>
<button style='border: 0' size="mini" type="primary" plain="true" class="submit" bindtap="submit">保存</button>
</view>
</view>
<view class="page-t">
<textarea class="content" placeholder="请输入文字,不能为空" bindinput="change" value="{{content}}" maxlength="-1"></textarea>
</view>
<modal hidden="{{hiddenmodalput}}" title="请输入记录名称" confirm-text="确定" cancel-text="取消" bindcancel="cancel" bindconfirm="confirm">
<input type='text' placeholder="请输入内容" value='{{annal_name}}' bindinput ="annal_NameInput" auto-focus/>
</modal>


</view>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* pages/demo/demo.wxss */
/* pages/edit/edit.wxss */
.page {
display: flex;
flex-direction: column;
Expand All @@ -11,17 +11,15 @@
.content {
margin: 10rpx;
height: 90%;
border-bottom: 1px solid rgb(65, 250, 250);
border-left: 1px solid rgb(65, 250, 250);
border-right: 1px solid rgb(65, 250, 250);
border-top: 1px solid rgb(65, 250, 250);
width: auto;
}
.btns {
.top {
flex: 1;
display: flex;
align-items: center;
border-bottom: 2px solid rgb(65, 250, 250);
justify-content: space-around;
margin-bottom: 3px;
}
.button-sp-area{
margin: 0 auto;
Expand All @@ -30,4 +28,4 @@
}
.mini-btn{
margin-right: 5px;
}
}
Binary file added 1614080902125/memorandum/pages/img/confirm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/edit1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/edit2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/main1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/main2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/per1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 1614080902125/memorandum/pages/img/per2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions 1614080902125/memorandum/pages/index/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//index.js
//获取应用实例
var util = require('../../utils/util');
Page({
data: {
lists:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
initData(this);
},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
initData(this);
},

bindTouchStart: function (e) {
this.startTime = e.timeStamp;
},
bindTouchEnd: function (e) {
this.endTime = e.timeStamp;
},

edit(e) {
if (this.endTime - this.startTime < 350) {
var id = e.currentTarget.dataset.id;
// 跳转 navigateTo
wx.navigateTo({
url: '../edit/edit?id=' + id
})
}
},
add:function() {
wx.navigateTo({
url: '../edit/edit'
});
},
delete:function(e){
var id = e.currentTarget.dataset.id;
var arr = wx.getStorageSync('txt');
var arrs;
var that = this;
var f = 1;
wx.showModal({
content: '确认删除该记录?',
success: function (res) {
console.log(id)
arr.forEach((item, i) => {
if ((item.id) == id && f == 1) {
console.log(i);
arr.splice(i, 1);
wx.setStorageSync('txt', arr);
f = 0;
}
})
arrs = wx.getStorageSync('txt');
arrs.forEach((item, i) => {
var t = new Date(Number(item.time));
item.time = util.dateFormate(t);
})
that.setData({
lists: arrs
})
}
});
}


})

function initData(page) {
var arr = wx.getStorageSync('txt');
if (arr.length) {
arr.forEach((item, i) => {
var t = new Date(Number(item.time));
item.time = util.dateFormate(t);
})
page.setData({
lists: arr
})
}
}

19 changes: 19 additions & 0 deletions 1614080902125/memorandum/pages/index/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--index.wxml-->
<view class='index-container'>
<view class="weui-search-bar">
<view class="weui-search-bar__form">

<label class="weui-search-bar__label" hidden="{{inputShowed}}" bindtap="toSearch">
<icon class="weui-icon-search" type="search" size="14"></icon>
<view class="weui-search-bar__text">搜索</view>
</label>
</view>
<view class="weui-search-bar__cancel-btn" bindtap="add">新建记录</view>
</view>
<block wx:for="{{lists}}" wx:key="*this.id">
<view class="list_recording" bindtouchstart="bindTouchStart" bindtouchend="bindTouchEnd" bindlongtap="delete" bindtap="edit" data-id="{{item.id}}">
<view class="content">{{item.annal_name}}</view>
<view class="time">创建时间:{{item.time}}</view>
</view>
</block>
</view>
Loading

0 comments on commit 6cae54b

Please sign in to comment.