From b6f4e0efc246994b29f37c61769e94fae03f41ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E9=97=B9=E9=92=9F?= Date: Thu, 13 Oct 2016 17:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E8=BE=91=E9=A1=B5=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=BC=A9=E7=95=A5=E4=B8=80=E8=A7=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ pages/new/new.js | 48 ++++++++++++++++++++++++++++++++++++++++------ pages/new/new.wxml | 20 ++++++++++++++++--- pages/new/new.wxss | 33 +++++++++++++++++++++++++++++-- utils/util.js | 19 +++++++++++++++++- 5 files changed, 112 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f2a3f4..d87e9d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,7 @@ * 更新开发者工具至`v0.10.101100` * 修改`new`页的数据绑定方式 & 修改多行文本框输入时的bug + +# 2016-10-13 + +* 完善日志编辑页 diff --git a/pages/new/new.js b/pages/new/new.js index 60073c7..c9de658 100644 --- a/pages/new/new.js +++ b/pages/new/new.js @@ -2,16 +2,22 @@ // TODO 并不是所有非中文字符宽度都为中文字符宽度一半,需特殊处理 // TODO 由于文本框聚焦存在bug,故编辑模式待实现 -const input = require('../../utils/input.js'); -const config = require('../../config.js'); -const geo = require('../../services/geo.js'); +const input = require('../../utils/input'); +const config = require('../../config'); +const geo = require('../../services/geo'); +const util = require('../../utils/util'); const RESOLUTION = 750; // 微信规定屏幕宽度为750rpx const MARGIN = 10; // 写字面板左右margin const ROW_CHARS = Math.floor((RESOLUTION - 2 * MARGIN) / config.input.charWidth); const MAX_CHAR = 1000; // 最多输1000字符 +// 内容布局 +const layoutColumnSize = 3; + +// 日记内容类型 const TEXT = 'TEXT'; +const IMAGE = 'IMAGE' const mediaActionSheetItems = ['拍照', '选择照片', '选择视频']; const mediaActionSheetBinds = ['chooseImage', 'chooseImage', 'chooseImage'] @@ -25,6 +31,9 @@ Page({ list: [], }, + // 日记内容布局列表(2x2矩阵) + layoutList: [], + // 是否显示loading showLoading: false, @@ -59,6 +68,16 @@ Page({ showTab: true, }, + // 显示底部tab + showTab() { + this.setData({showTab: true}); + }, + + // 隐藏底部tab + hideTab() { + this.setData({showTab: false}); + }, + // 显示loading提示 showLoading(loadingMessage) { this.setData({showLoading: true, loadingMessage}); @@ -74,6 +93,12 @@ Page({ this.getPoi(); }, + // 设置日记数据 + setDiary(diary) { + let layout = util.listToMatrix(diary.list, layoutColumnSize); + this.setData({diary: diary, layoutList: layout}); + }, + // 页面初始化 onLoad: function(options) { if (options) { @@ -119,7 +144,7 @@ Page({ if (text) { diary.list.push(this.makeContent(TEXT, text, '')); - this.setData({diary: diary}); + this.setDiary(diary); } this.inputCancel(); @@ -224,6 +249,8 @@ Page({ // 从相册选择照片或拍摄照片 chooseImage() { + let that = this; + wx.chooseImage({ count: 9, // 最多选9张 sizeType: ['origin', 'compressed'], @@ -233,7 +260,16 @@ Page({ this.setData({mediaActionSheetHidden: true}); this.showLoading('图片处理中...'); - console.log(res); + console.log('图片:', res); + // TODO 图片上传至服务器 + let diary = this.data.diary; + res.tempFilePaths.forEach((element, index, array) => { + diary.list.push(that.makeContent(IMAGE, element, '')) + }); + + that.setDiary(diary); + that.hideLoading(); + that.showTab(); } }) }, @@ -266,6 +302,6 @@ Page({ content: content, description: description, poi: this.data.poi, - } + }; } }) diff --git a/pages/new/new.wxml b/pages/new/new.wxml index 8d00e4f..3446ce4 100644 --- a/pages/new/new.wxml +++ b/pages/new/new.wxml @@ -1,8 +1,22 @@