diff --git a/app.js b/app.js index 2baa119..31a6b41 100644 --- a/app.js +++ b/app.js @@ -1,13 +1,27 @@ // app.js +const config = require('config'); + App({ onLaunch: function () { + this.getDiaryList(); }, getUserInfo:function(cb){ }, + getDiaryList() { + var that = this; + + wx.getStorage({ + key: config.storage.diaryListKey, + success: (res) => { + this.globalData.diaryList = res.data; + } + }) + }, + getDeviceInfo: function(callback) { var that = this; @@ -25,6 +39,7 @@ App({ globalData: { deviceInfo: null, + diaryList: null, } }) diff --git a/config.js b/config.js index a296528..2140cb4 100644 --- a/config.js +++ b/config.js @@ -11,4 +11,10 @@ module.exports = { input: { charWidth: 14, // 单个字符的宽度,in rpx }, + + /** 本地存储 **/ + // TODO 数据通过API全部存储于服务端 + storage: { + diaryListKey: 'bearDiaryList', + } }; diff --git a/pages/new/new.js b/pages/new/new.js index c9de658..dd9099b 100644 --- a/pages/new/new.js +++ b/pages/new/new.js @@ -22,6 +22,8 @@ const IMAGE = 'IMAGE' const mediaActionSheetItems = ['拍照', '选择照片', '选择视频']; const mediaActionSheetBinds = ['chooseImage', 'chooseImage', 'chooseImage'] +var app = getApp(); + Page({ data: { @@ -97,13 +99,27 @@ Page({ setDiary(diary) { let layout = util.listToMatrix(diary.list, layoutColumnSize); this.setData({diary: diary, layoutList: layout}); + this.saveDiary(diary); + }, + + // 保存日记 + // TODO sync to server + saveDiary(diary) { + const key = config.storage.diaryListKey; + let diaryList = app.globalData.diaryList || {}; + diaryList[diary.meta.title] = diary; + + wx.setStorage({key: key, data: diaryList}); }, // 页面初始化 onLoad: function(options) { if (options) { let title = options.title; - if (title) {this.setData({'diary.title': title});} + if (title) {this.setData({ + 'diary.meta.title': title, + 'diary.meta.create_time': util.formatTime(new Date()) + });} } this.init();