Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add post operation
- Loading branch information
Showing
7 changed files
with
392 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,220 @@ | ||
// pages/postEditor/postEditor.js | ||
var WxParse = require('../../wxParse/wxParse.js'); | ||
Page({ | ||
|
||
/** | ||
* The initial data of the page. | ||
*/ | ||
data: { | ||
tags: [], | ||
hidden:true | ||
|
||
}, | ||
|
||
/** | ||
* Life cycle function - listen to page load. | ||
*/ | ||
onLoad: function (options) { | ||
|
||
|
||
}, | ||
|
||
/** | ||
* Life cycle function - the first rendering of the listening page. | ||
*/ | ||
onReady: function () { | ||
|
||
}, | ||
|
||
/** | ||
* Life cycle function - monitor page display. | ||
*/ | ||
onShow: function () { | ||
|
||
}, | ||
|
||
/** | ||
* Life cycle function - the listening page is hidden. | ||
*/ | ||
onHide: function () { | ||
|
||
}, | ||
|
||
/** | ||
* Life cycle function - monitor page uninstall. | ||
*/ | ||
onUnload: function () { | ||
|
||
}, | ||
|
||
/** | ||
* Page correlation event handler - listen to the user to pull. | ||
*/ | ||
onPullDownRefresh: function () { | ||
|
||
}, | ||
|
||
/** | ||
* The handle function of the bottom event on the page. | ||
*/ | ||
onReachBottom: function () { | ||
|
||
}, | ||
|
||
/** | ||
*Users click the top right corner to share. | ||
*/ | ||
onShareAppMessage: function () { | ||
return { | ||
title: 'MicroSteemit', | ||
desc: "Steemit", | ||
path: '/pages/post/post' | ||
} | ||
|
||
}, | ||
|
||
/** | ||
*dynamically get the content of the post title | ||
*/ | ||
inputTitle: function (e) { | ||
var content = e.detail.value; | ||
if (content) { | ||
console.log(content); | ||
this.setData({ postTitle: content }) | ||
} | ||
else { | ||
// no content in the title box OR delete all content | ||
this.setData({ postTitle: "" }) | ||
|
||
} | ||
}, | ||
|
||
/** | ||
*dynamically get the content of the post content box | ||
*/ | ||
inputContent: function (e) { | ||
var content = e.detail.value; | ||
if (content) { | ||
console.log(content); | ||
WxParse.wxParse('postContentPreview', 'md', content, this, 5); | ||
this.setData({ postContent: content }) | ||
} | ||
else { | ||
this.setData({ postContent: "" }) | ||
} | ||
}, | ||
/** | ||
*input the tag | ||
*/ | ||
inputTag: function (e) { | ||
var content = e.detail.value; | ||
if (content) { | ||
console.log(content); | ||
this.setData({ postTag: content }) | ||
} | ||
else { | ||
|
||
} | ||
}, | ||
/** | ||
*add the specified tag to tags box | ||
*/ | ||
addTag: function (e) { | ||
var tag = this.data.postTag; | ||
var newTags = []; | ||
if (tag) { | ||
var firstStr = /[a-z]/; | ||
var endStr = /[0-9a-z]/; | ||
if (firstStr.test(tag.substring(0, 1)) && endStr.test(tag.substring(tag.length - 1, tag.length))) { | ||
if (this.data.tags.length == 0) { | ||
newTags.push(tag); | ||
} | ||
else { | ||
newTags = this.data.tags; | ||
newTags.push(tag); | ||
} | ||
this.setData({ tags: newTags }); | ||
} | ||
else { | ||
wx.showModal({ | ||
title: 'Error', | ||
content: 'Wrong tag', | ||
}) | ||
|
||
} | ||
} | ||
else { | ||
wx.showModal({ | ||
title: 'Error', | ||
content: 'Tag can`t be NULL', | ||
}) | ||
} | ||
this.setData({ newTag: "", postTag: "" }) | ||
}, | ||
/** | ||
*delete the tag from current tags | ||
*/ | ||
deleteTag: function (e) { | ||
var tagIndex = e.currentTarget.dataset.tagindex; | ||
var currentTags = this.data.tags; | ||
currentTags.splice(tagIndex, 1) | ||
this.setData({ tags: currentTags }) | ||
}, | ||
/** | ||
*submit the post | ||
*/ | ||
submitPost: function (e) { | ||
var postTitle = this.data.postTitle; | ||
var postContent = this.data.postContent; | ||
var tags = this.data.tags; | ||
if (postTitle && postContent && (tags.length>0)) { | ||
// all the necessary items have been with content. | ||
this.setData({ hidden:false}); | ||
var name = wx.getStorageSync('name'); | ||
var key = wx.getStorageSync('pass'); | ||
var that = this; | ||
wx.request({ | ||
url: 'https://openjoy.club/operation/post', | ||
method: 'POST', | ||
data: { | ||
account: name, | ||
tags:tags, | ||
key: key, | ||
title: postTitle, | ||
body: postContent, | ||
}, | ||
success: function (res) { | ||
console.log(res); | ||
that.setData({ hidden: true }) | ||
if (res.statusCode == '200' && res.data.message == 'success') { | ||
wx.showToast({ | ||
title: 'Post Success', | ||
icon: 'success', | ||
duration: 2000 | ||
}) | ||
} | ||
else { | ||
wx.showModal({ | ||
title: 'Error', | ||
content: 'Something error!', | ||
success: function (res) { | ||
if (res.confirm) { | ||
console.log('Something error!') | ||
} else if (res.cancel) { | ||
console.log('Something error!') | ||
} | ||
} | ||
}) | ||
|
||
} | ||
} | ||
}) | ||
} | ||
else{ | ||
wx.showModal({ | ||
title: 'Error', | ||
content: 'Pls fill in all contents', | ||
}) | ||
} | ||
} | ||
}) |
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,5 @@ | ||
{ | ||
"navigationBarTitleText": "Post editor", | ||
"navigationBarBackgroundColor": "#405f80", | ||
"navigationBarTextStyle": "dark" | ||
} |
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,37 @@ | ||
<!--pages/postEditor/postEditor.wxml--> | ||
<import src="../../wxParse/wxParse.wxml"/> | ||
<view class="postEditor"> | ||
<view class='postTitle'> | ||
<input bindinput="inputTitle" class="title" type="text" value="{{postTitle}}" placeholder="Post Title" placeholder-class="place-input" /> | ||
</view> | ||
<view class="postContent"> | ||
<textarea class="content" placeholder="Post Content" auto-focus bindinput="inputContent" value="{{postContent}}" maxlength="-1"></textarea> | ||
</view> | ||
<view class='inputTags'> | ||
<text class='tagsTitle'>Tags:</text> | ||
<input hidden='{{tags.length>4?true:false}}' bindinput="inputTag" class="inputTag" type="text" value="{{newTag}}" placeholder="Tag" placeholder-class="place-input" /> | ||
<image hidden='{{tags.length>4?true:false}}' mode="aspectFill" bindtap="addTag" class="icon" src="../../images/icon/add.png"></image> | ||
</view> | ||
<view class='postTags'> | ||
<view wx:for="{{tags}}" wx:for-item="tag" wx:key="tag" wx:for-index="tagIndex"> | ||
<view class="tag"> | ||
<text decode="true" class="tag-text"> {{tag}} </text> | ||
<image data-tagindex="{{tagIndex}}" bindtap='deleteTag' class="deleteTag" src="../../images/icon/close.png"></image> | ||
</view> | ||
</view> | ||
|
||
</view> | ||
<view class="commentButton"> | ||
<button class="submitButton" bindtap="submitPost">Post</button> | ||
<button class="cancelButton" bindtap="cancelPost">Cancel</button> | ||
</view> | ||
<view class="preview"> | ||
<text class="preview-title">Preview:</text> | ||
<scroll-view scroll-y class="preview-content"> | ||
<template is="wxParse" data="{{wxParseData:postContentPreview.nodes}}" /> | ||
</scroll-view> | ||
</view> | ||
</view> | ||
<loading hidden="{{hidden}}"> | ||
Loading... | ||
</loading> |
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,130 @@ | ||
/* pages/postEditor/postEditor.wxss */ | ||
@import "/wxParse/wxParse.wxss"; | ||
.postEditor{ | ||
padding: 20rpx; | ||
} | ||
.postTitle{ | ||
border-top-left-radius: 10rpx; | ||
border-top-right-radius: 10rpx; | ||
border-bottom-left-radius: 10rpx; | ||
border-bottom-right-radius: 10rpx; | ||
border-width: medium; | ||
border-style: solid; | ||
border-color:#E8E8EA; | ||
height: 5vh; | ||
margin:5rpx; | ||
margin-bottom: 10rpx; | ||
} | ||
.postContent{ | ||
border-top-left-radius: 10rpx; | ||
border-top-right-radius: 10rpx; | ||
border-bottom-left-radius: 10rpx; | ||
border-bottom-right-radius: 10rpx; | ||
border-width: medium; | ||
border-style: solid; | ||
border-color: #E8E8EA; | ||
height: 35vh; | ||
margin:5rpx; | ||
} | ||
.inputTags{ | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
.tagsTitle{ | ||
align-content: center; | ||
} | ||
.inputTag{ | ||
border-top-left-radius: 10rpx; | ||
border-top-right-radius: 10rpx; | ||
border-bottom-left-radius: 10rpx; | ||
border-bottom-right-radius: 10rpx; | ||
border-width: medium; | ||
border-style: solid; | ||
border-color:#E8E8EA; | ||
height: 5vh; | ||
width: 20vh; | ||
} | ||
.postTags{ | ||
border-top-left-radius: 10rpx; | ||
border-top-right-radius: 10rpx; | ||
border-bottom-left-radius: 10rpx; | ||
border-bottom-right-radius: 10rpx; | ||
border-width: medium; | ||
border-style: solid; | ||
border-color:#E8E8EA; | ||
margin:5rpx; | ||
margin-top: 10rpx; | ||
display: flex; | ||
flex-wrap:wrap; | ||
flex-direction: row; | ||
word-break: break-all; | ||
} | ||
.deleteTag{ | ||
margin-right:10rpx; | ||
width: 30rpx; | ||
height: 30rpx; | ||
} | ||
.tag{ | ||
margin-bottom: 5rpx; | ||
word-break: break-all; | ||
border-width: medium; | ||
border-style: solid; | ||
border-color: gray; | ||
border-top-left-radius: 30rpx; | ||
border-top-right-radius: 30rpx; | ||
border-bottom-left-radius: 30rpx; | ||
border-bottom-right-radius: 30rpx; | ||
} | ||
.icon{ | ||
width: 60rpx; | ||
height: 60rpx; | ||
align-content: center; | ||
margin-bottom:-8rpx; | ||
} | ||
.commentButton{ | ||
display:flex; | ||
flex-direction: row; | ||
width: 100%; | ||
} | ||
|
||
.submitButton { | ||
width: 30%; | ||
padding: 10px; | ||
font: 20px "microsoft yahei"; | ||
text-align: center; | ||
border-top: 1px solid #E8E8EA; | ||
color: #3CC51F; | ||
} | ||
|
||
.cancelButton { | ||
width: 30%; | ||
padding: 10px; | ||
font: 20px "microsoft yahei"; | ||
text-align: center; | ||
border-top: 1px solid #E8E8EA; | ||
color: #3CC51F; | ||
} | ||
|
||
.preview{ | ||
margin-top:20rpx; | ||
border-top-color: red; | ||
} | ||
|
||
.preview-title{ | ||
font: 20px "microsoft yahei"; | ||
font-weight: 500; | ||
margin-bottom: 10rpx; | ||
} | ||
|
||
.preview-content{ | ||
width: 100%; | ||
height:35vh; | ||
margin:5rpx; | ||
border-width:thin; | ||
border-style: solid; | ||
border-color: gray; | ||
border-top-left-radius: 10rpx; | ||
border-top-right-radius: 10rpx; | ||
border-bottom-left-radius: 10rpx; | ||
border-bottom-right-radius: 10rpx; | ||
} |