Skip to content

Commit

Permalink
日记内容可以从相册选择视频文件
Browse files Browse the repository at this point in the history
  • Loading branch information
小闹钟 committed Oct 14, 2016
1 parent 73f1a8b commit 53910a1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
43 changes: 32 additions & 11 deletions pages/new/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const layoutColumnSize = 3;

// 日记内容类型
const TEXT = 'TEXT';
const IMAGE = 'IMAGE'
const IMAGE = 'IMAGE';
const VIDEO = 'VIDEO';

const mediaActionSheetItems = ['拍照', '选择照片', '选择视频'];
const mediaActionSheetBinds = ['chooseImage', 'chooseImage', 'chooseImage']
const mediaActionSheetBinds = ['chooseImage', 'chooseImage', 'chooseVideo'];

var app = getApp();

Expand Down Expand Up @@ -263,6 +264,22 @@ Page({
})
},

// 将内容写入至日记对象
writeContent(res, type) {
let diary = this.data.diary;

if (type === IMAGE || type === VIDEO) {
res.tempFilePaths.forEach((element, index, array) => {
// TODO 内容上传至服务器
diary.list.push(this.makeContent(type, element, ''))
});
}

this.setDiary(diary);
this.hideLoading();
this.showTab();
},

// 从相册选择照片或拍摄照片
chooseImage() {
let that = this;
Expand All @@ -275,17 +292,21 @@ Page({
success: (res) => {
this.setData({mediaActionSheetHidden: true});
this.showLoading('图片处理中...');
that.writeContent(res, IMAGE);
}
})
},

console.log('图片:', res);
// TODO 图片上传至服务器
let diary = this.data.diary;
res.tempFilePaths.forEach((element, index, array) => {
diary.list.push(that.makeContent(IMAGE, element, ''))
});
// 从相册选择视频文件
chooseVideo() {
let that = this;

that.setDiary(diary);
that.hideLoading();
that.showTab();
wx.chooseVideo({
sourceType: ['album'], // 仅从相册选择
success: (res) => {
this.setData({mediaActionSheetHidden: true});
this.showLoading('视频处理中...');
that.writeContent(res, VIDEO);
}
})
},
Expand Down
3 changes: 3 additions & 0 deletions pages/new/new.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<block wx:elif="{{item.type == 'IMAGE'}}">
<image src="{{item.content}}" class="album-item" mode="aspectFill"></image>
</block>
<block wx:elif="{{item.type == 'VIDEO'}}">
<video class="album-item" src="{{item.content}}"></video>
</block>
</block>
</view>
</view>
Expand Down

0 comments on commit 53910a1

Please sign in to comment.