add: editor demo

master
jiangxue 2021-01-27 12:42:41 +08:00
parent 86a192e36b
commit 490d5527c8
6 changed files with 705 additions and 1 deletions

View File

@ -21,6 +21,7 @@
"pages/component/picker/picker",
"pages/component/picker-view/picker-view",
"pages/component/input/input",
"pages/component/editor/editor",
"pages/component/textarea/textarea",
"pages/component/form/form",
"pages/component/rich-text/rich-text",

View File

@ -0,0 +1,259 @@
Page({
data: {
formats: {},
bottom: 0,
readOnly: false,
placeholder: '开始输入...',
_focus: false,
},
readOnlyChange() {
this.setData({
readOnly: !this.data.readOnly
})
},
onLoad() {
},
onEditorReady(opt) {
console.log(opt)
const that = this
wx.createSelectorQuery().select('#editor').context(function (res) {
console.log('~~~~~createSelectorQuery~~~res~~~', res);
that.editorCtx = res.context
}).exec()
},
blurEditor() {
this.editorCtx.blur({
success(res) {
console.log('editor blur success', res);
},
fail(res) {
console.log('editor blur fail', res);
},
complete(res) {
console.log('editor blur complete', res);
}
})
},
clearEditor() {
this.editorCtx.clear({
success(res) {
console.log('editor clear success', res);
},
fail(res) {
console.log('editor clear fail', res);
},
complete(res) {
console.log('editor clear complete', res);
}
})
},
setColor() {
const that = this
that.editorCtx.format('color', 'red')
},
setColorGreen() {
const that = this
that.editorCtx.format('color', 'green')
},
getContents() {
this.editorCtx.getContents({
success(res) {
console.log('editor getContents success', res);
},
fail(res) {
console.log('editor getContents fail', res);
},
complete(res) {
console.log('editor getContents complete', res);
}
})
},
getSelectionText() {
this.editorCtx.getSelectionText({
success(res) {
console.log('editor getSelectionText success', res);
},
fail(res) {
console.log('editor getSelectionText fail', res);
},
complete(res) {
console.log('editor getSelectionText complete', res);
}
})
},
insertDivider() {
this.editorCtx.insertDivider({
success(res) {
console.log('editor insertDivider success', res);
},
fail(res) {
console.log('editor insertDivider fail', res);
},
complete(res) {
console.log('editor insertDivider complete', res);
}
})
},
insertImage() {
const that = this
wx.chooseImage({
sourceType: ['album', 'camera'],
count: 1,
success: function (res) {
var tempFilePaths = res.tempFilePaths[0];
console.log("tempFilePaths", tempFilePaths)
that.editorCtx.insertImage({
src: tempFilePaths,
mode: 'aspectFit',
success(res) {
console.log('editor insertImage success', res);
},
fail(res) {
console.log('editor insertImage fail', res);
},
complete(res) {
console.log('editor insertImage complete', res);
}
})
}
})
},
insertImageOnline() {
this.editorCtx.insertImage({
src: 'https://mp.finogeeks.com/img/banner_img_new.4877d96a.png',
mode: 'aspectFit',
success(res) {
console.log('editor insertImage success', res);
},
fail(res) {
console.log('editor insertImage fail', res);
},
complete(res) {
console.log('editor insertImage complete', res);
}
})
},
insertText() {
this.editorCtx.insertText({
text: 'insertText ',
success(res) {
console.log('editor insertText success', res);
},
fail(res) {
console.log('editor insertText fail', res);
},
complete(res) {
console.log('editor insertText complete', res);
}
})
},
redo() {
this.editorCtx.redo({
success(res) {
console.log('editor redo success', res);
},
fail(res) {
console.log('editor redo fail', res);
},
complete(res) {
console.log('editor redo complete', res);
}
})
},
removeFormat() {
this.editorCtx.removeFormat({
success(res) {
console.log('editor removeFormat success', res);
},
fail(res) {
console.log('editor removeFormat fail', res);
},
complete(res) {
console.log('editor removeFormat complete', res);
}
})
},
scrollIntoView() {
console.log('scrollIntoView')
this.editorCtx.scrollIntoView()
},
setContents() {
this.editorCtx.setContents({
delta: [
{ insert: 'Hello ' },
{ insert: 'World!', attributes: { bold: true } },
{ insert: '\n' }
],
success(res) {
console.log('editor setContents success', res);
},
fail(res) {
console.log('editor setContents fail', res);
},
complete(res) {
console.log('editor setContents complete', res);
}
})
},
undo() {
this.editorCtx.undo({
success(res) {
console.log('editor undo success', res);
},
fail(res) {
console.log('editor undo fail', res);
},
complete(res) {
console.log('editor undo complete', res);
}
})
},
format(e) {
let { name, value } = e.target.dataset
if (!name) return
this.editorCtx.format(name, value)
},
onStatusChange(e) {
const formats = e.detail
this.setData({ formats })
},
clear() {
this.editorCtx.clear({
success: function (res) {
console.log("clear success")
}
})
},
complete(){
const that = this
console.log("富文本内容", that.editorCtx.getContents({
success: function (res) {
console.log('富文本内容', res.html)
wx.setStorageSync('richtext', res.html)
wx.navigateTo({
url: '/richtextpage/richtextpage',
})
}
}))
},
removeColor() {
const that = this
that.editorCtx.removeFormat({
success(res) {
console.log('removeFormat success', res)
}
})
},
setBlod() {
console.log('setBlod')
this.editorCtx.format('bold')
},
setFormat(event) {
const {changename, chanvevalue=null} = event.target.dataset;
this.editorCtx.format(changename, chanvevalue);
}
})

View File

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

View File

@ -0,0 +1,59 @@
<view class="">
<view class="page-body">
<view class='wrapper'>
<editor style="height:77px" id="editor" class="ql-container" placeholder="{{placeholder}}" showImgSize showImgToolbar showImgResize bindstatuschange="onStatusChange" read-only="{{readOnly}}" bindready="onEditorReady">
</editor>
</view>
</view>
<scroll-view scroll-y="true" style="height: 350px;">
<button bindtap="blurEditor">blur</button>
<button bindtap="clearEditor">清空clear</button>
<button bindtap="setColor">设置颜色 red</button>
<button bindtap="setBlod">设置bold</button>
<button bindtap="setColorGreen">设置绿色</button>
<button bindtap="getContents">getContents</button>
<button bindtap="getSelectionText">getSelectionText</button>
<!-- <button bindtap="insertDivider">insertDivider</button> -->
<button bindtap="insertImage">insertImage</button>
<button bindtap="insertImageOnline">insertImage online</button>
<button bindtap="insertText">insertText</button>
<button bindtap="redo">redo</button>
<button bindtap="removeFormat">removeFormat</button>
<button bindtap="scrollIntoView">scrollIntoView</button>
<button bindtap="setContents">setContents</button>
<button bindtap="undo">undo</button>
<view>以下是format细节功能</view>
<button bindtap="setFormat" data-changename='italic'>italic</button>
<button bindtap="setFormat" data-changename='underline'>underline</button>
<button bindtap="setFormat" data-changename='strike'>strike</button>
<!-- <button bindtap="setFormat" data-changename='ins'>ins</button> -->
<button bindtap="setFormat" data-changename='script' data-chanvevalue="sub">script sub</button>
<button bindtap="setFormat" data-changename='script' data-chanvevalue="super">script super</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H1">header H1</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H2">header H2</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H3">header H3</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H4">header H4</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H5">header H5</button>
<button bindtap="setFormat" data-changename='header' data-chanvevalue="H6">header H6</button>
<button bindtap="setFormat" data-changename='align' data-chanvevalue="left">align left</button>
<button bindtap="setFormat" data-changename='align' data-chanvevalue="center">align center</button>
<button bindtap="setFormat" data-changename='align' data-chanvevalue="right">align right</button>
<button bindtap="setFormat" data-changename='align' data-chanvevalue="justify">align justify</button>
<button bindtap="setFormat" data-changename='direction' data-chanvevalue="rtl">direction</button>
<button bindtap="setFormat" data-changename='indent' data-chanvevalue="+1">indent +1</button>
<button bindtap="setFormat" data-changename='indent' data-chanvevalue="-1">indent -1</button>
<button bindtap="setFormat" data-changename='list' data-chanvevalue="ordered">list ordered</button>
<button bindtap="setFormat" data-changename='list' data-chanvevalue="bullet">list bullet</button>
<button bindtap="setColor">设置颜色 red</button>
<button bindtap="removeFormat">removeFormat</button>
</scroll-view>
<!-- <button bindtap="complete">完成</button> -->
</view>

View File

@ -0,0 +1,382 @@
.wrapper {
padding: 5px;
}
.iconfont {
display: inline-block;
padding: 8px 8px;
width: 24px;
height: 24px;
cursor: pointer;
font-size: 20px;
}
.toolbar {
box-sizing: border-box;
/* border: 1px solid #ccc; */
border-bottom: 0;
font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
}
.ql-container {
box-sizing: border-box;
padding: 12px 15px;
width: 100%;
min-height: 30vh;
height: auto;
/* border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc; */
background: #fff;
margin-top: 20px;
font-size: 16px;
line-height: 1.5;
}
.ql-active {
color: #06c;
}
.index-hd {
padding: 80rpx;
text-align: center;
}
.index-bd {
padding: 0 30rpx 40rpx;
}
.index-ft {
padding-bottom: 20rpx;
text-align: center;
}
.index-logo {
width: 86rpx;
height: 86rpx;
}
.index-desc {
margin-top: 20rpx;
color: #888888;
font-size: 28rpx;
}
.navigator-box {
opacity: 0;
position: relative;
background-color: #FFFFFF;
line-height: 1.41176471;
font-size: 34rpx;
transform: translateY(-50%);
transition: .3s;
}
.navigator-box-show {
opacity: 1;
transform: translateY(0);
}
.navigator {
padding: 20rpx 30rpx;
position: relative;
display: flex;
align-items: center;
}
.navigator:before {
content: " ";
position: absolute;
left: 30rpx;
top: 0;
right: 30rpx;
height: 1px;
border-top: 1rpx solid #D8D8D8;
color: #D8D8D8;
}
.navigator:first-child:before {
display: none;
}
.navigator-text {
flex: 1;
}
.navigator-arrow {
padding-right: 26rpx;
position: relative;
}
.navigator-arrow:after {
content: " ";
display: inline-block;
height: 18rpx;
width: 18rpx;
border-width: 2rpx 2rpx 0 0;
border-color: #888888;
border-style: solid;
transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0);
position: absolute;
top: 50%;
margin-top: -8rpx;
right: 28rpx;
}
.kind-list-item {
margin: 20rpx 0;
background-color: #FFFFFF;
border-radius: 4rpx;
overflow: hidden;
}
.kind-list-item:first-child {
margin-top: 0;
}
.kind-list-text{
flex: 1;
}
.kind-list-img {
width: 60rpx;
height: 60rpx;
}
.kind-list-item-hd {
padding: 30rpx;
display: flex;
align-items: center;
transition: opacity .3s;
}
.kind-list-item-hd-show {
opacity: .2;
}
.kind-list-item-bd {
height: 0;
overflow: hidden;
}
.kind-list-item-bd-show {
height: auto;
}
/* reset */
page {
background-color: #F8F8F8;
height: 100%;
font-size: 32rpx;
line-height: 1.6;
}
checkbox, radio{
margin-right: 10rpx;
}
button{
margin-top: 20rpx;
margin-bottom: 20rpx;
}
form{
width: 100%;
}
input {
width: 100%;
}
/* lib */
.strong{
font-weight: bold;
}
.tc{
text-align: center;
}
/* page */
.container {
display: flex;
flex-direction: column;
min-height: 100%;
justify-content: space-between;
font-size: 32rpx;
font-family: -apple-system-font,Helvetica Neue,Helvetica,sans-serif;
}
.page-head{
padding: 60rpx 50rpx 80rpx;
text-align: center;
}
.page-head-title{
display: inline-block;
padding: 0 40rpx 20rpx 40rpx;
font-size: 32rpx;
color: #BEBEBE;
}
.page-head-line{
margin: 0 auto;
width: 150rpx;
height: 2rpx;
background-color: #D8D8D8;
}
.page-head-desc{
padding-top: 20rpx;
color: #9B9B9B;
font-size: 32rpx;
}
.page-body {
width: 100%;
flex-grow: 1;
overflow-x: hidden;
}
.page-body-wrapper {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.page-body-wording {
text-align: center;
padding: 200rpx 100rpx;
}
.page-body-info {
display: flex;
flex-direction: column;
align-items: center;
background-color: #fff;
width: 100%;
padding: 50rpx 0 150rpx 0;
}
.page-body-title {
margin-bottom: 100rpx;
font-size: 32rpx;
}
.page-body-text {
font-size: 30rpx;
line-height: 26px;
color: #ccc;
}
.page-body-text-small {
font-size: 24rpx;
color: #000;
margin-bottom: 100rpx;
}
.page-foot{
margin: 100rpx 0 30rpx 0;
text-align: center;
color: #1aad19;
font-size: 0;
}
.icon-foot{
width: 152rpx;
height: 23rpx;
}
.page-section{
width: 100%;
margin-bottom: 60rpx;
}
.page-section_center{
display: flex;
flex-direction: column;
align-items: center;
}
.page-section:last-child{
margin-bottom: 0;
}
.page-section-gap{
box-sizing: border-box;
padding: 0 30rpx;
}
.page-section-spacing{
box-sizing: border-box;
padding: 0 80rpx;
}
.page-section-title{
font-size: 28rpx;
color: #999999;
margin-bottom: 10rpx;
padding-left: 30rpx;
padding-right: 30rpx;
}
.page-section-gap .page-section-title{
padding-left: 0;
padding-right: 0;
}
.page-section-ctn{
}
/* widget */
.btn-area{
margin-top: 60rpx;
box-sizing: border-box;
width: 100%;
padding: 0 30rpx;
}
.image-plus {
width: 150rpx;
height: 150rpx;
border: 2rpx solid #D9D9D9;
position: relative;
}
.image-plus-nb{
border: 0;
}
.image-plus-text{
color: #888888;
font-size: 28rpx;
}
.image-plus-horizontal {
position: absolute;
top: 50%;
left: 50%;
background-color: #d9d9d9;
width: 4rpx;
height: 80rpx;
transform: translate(-50%, -50%);
}
.image-plus-vertical {
position: absolute;
top: 50%;
left: 50%;
background-color: #d9d9d9;
width: 80rpx;
height: 4rpx;
transform: translate(-50%, -50%);
}
.demo-text-1{
position: relative;
align-items: center;
justify-content: center;
background-color: #1AAD19;
color: #FFFFFF;
font-size: 36rpx;
}
.demo-text-1:before{
content: 'A';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.demo-text-2{
position: relative;
align-items: center;
justify-content: center;
background-color: #2782D7;
color: #FFFFFF;
font-size: 36rpx;
}
.demo-text-2:before{
content: 'B';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.demo-text-3{
position: relative;
align-items: center;
justify-content: center;
background-color: #F1F1F1;
color: #353535;
font-size: 36rpx;
}
.demo-text-3:before{
content: 'C';
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

View File

@ -22,7 +22,7 @@ Page({
id: 'form',
name: '表单组件',
open: false,
pages: ['button', 'checkbox', 'form', 'input', 'label', 'picker', 'picker-view', 'radio', 'slider', 'switch', 'textarea']
pages: ['button', 'checkbox', 'form', 'input', 'label', 'picker', 'picker-view', 'radio', 'slider', 'switch', 'textarea','editor']
}, {
id: 'nav',
name: '导航',