created
This commit is contained in:
@@ -0,0 +1,331 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view>
|
||||
<uni-nav-bar
|
||||
title="添加小标题"
|
||||
leftText="取消"
|
||||
left-icon="left"
|
||||
right-text="完成"
|
||||
backgroundColor="#ffffff"
|
||||
color="#000000"
|
||||
@clickRight="toSuccess()"
|
||||
@clickLeft="back()">
|
||||
</uni-nav-bar>
|
||||
</view>
|
||||
<view class="page-body">
|
||||
<view class='wrapper'>
|
||||
|
||||
|
||||
<view class="editor-wrapper">
|
||||
<editor id="editor" class="ql-container" placeholder="开始输入..." show-img-size show-img-toolbar
|
||||
show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady">
|
||||
</editor>
|
||||
</view>
|
||||
<view class='toolbar' @tap="format">
|
||||
<view class="item-wrap">
|
||||
<zb-popover
|
||||
placement="top"
|
||||
:options="actions"
|
||||
ref="Popover1"
|
||||
actions-direction="horizontal">
|
||||
<view class="iconfont icon-fontsize"
|
||||
></view>
|
||||
<template #content>
|
||||
<view
|
||||
:class="formats.fontSize === '36rpx' ? 'ql-active' : ''"
|
||||
class="iconfont icon-fontsize"
|
||||
data-name="fontSize"
|
||||
data-value="36rpx">
|
||||
</view>
|
||||
</template>
|
||||
</zb-popover>
|
||||
|
||||
<zb-popover
|
||||
placement="bottom-end"
|
||||
:options="actions"
|
||||
ref="Popover1"
|
||||
actions-direction="horizontal">
|
||||
<view class="iconfont icon-juzhongduiqi"></view>
|
||||
<template #content>
|
||||
<view
|
||||
:class="formats.align === 'left' ? 'ql-active' : ''"
|
||||
class="iconfont icon-zuoduiqi"
|
||||
data-name="align"
|
||||
data-value="left">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="formats.align === 'center' ? 'ql-active' : ''"
|
||||
class="iconfont icon-juzhongduiqi"
|
||||
data-name="align"
|
||||
data-value="center">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="formats.align === 'right' ? 'ql-active' : ''"
|
||||
class="iconfont icon-youduiqi"
|
||||
data-name="align"
|
||||
data-value="right">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="formats.align === 'justify' ? 'ql-active' : ''"
|
||||
class="iconfont icon-zuoyouduiqi"
|
||||
data-name="align"
|
||||
data-value="justify">
|
||||
</view>
|
||||
</template>
|
||||
</zb-popover>
|
||||
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#000000'),
|
||||
'not-color': !isColor('#000000')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-000000-item color-item"
|
||||
data-value="#000000">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#7a7e83'),
|
||||
'not-color': !isColor('#7a7e83')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-7a7e83-item color-item"
|
||||
data-value="#7a7e83">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#ff0000'),
|
||||
'not-color': !isColor('#ff0000')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-ff0000-item color-item"
|
||||
data-value="#ff0000">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#ff9900'),
|
||||
'not-color': !isColor('#ff9900')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-ff9900-item color-item"
|
||||
data-value="#ff9900">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#1aad19'),
|
||||
'not-color': !isColor('#1aad19')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-1aad19-item color-item"
|
||||
data-value="#1aad19">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#1a73e8'),
|
||||
'not-color': !isColor('#1a73e8')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-1a73e8-item color-item"
|
||||
data-value="#1a73e8">
|
||||
</view>
|
||||
|
||||
<view
|
||||
:class="{
|
||||
'is-color': isColor('#cc00cc'),
|
||||
'not-color': !isColor('#cc00cc')
|
||||
}"
|
||||
data-name="color"
|
||||
class="color-cc00cc-item color-item"
|
||||
data-value="#cc00cc">
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
readOnly: false,
|
||||
formats: {
|
||||
|
||||
color: "#000000",
|
||||
// fontSize 36 48 64
|
||||
fontSize: "36rpx",
|
||||
|
||||
},
|
||||
actions: [
|
||||
{ text: '选项一' },
|
||||
{ text: '选项二' },
|
||||
{ text: '选项三' },
|
||||
],
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
// #ifndef MP-BAIDU
|
||||
// uni.loadFontFace({
|
||||
// family: 'Pacifico',
|
||||
// source: 'url("https://sungd.github.io/Pacifico.ttf")'
|
||||
// })
|
||||
// #endif
|
||||
|
||||
// uniCloud.downloadFile({
|
||||
// fileID: 'cloud://example.123/theme/blue-theme.css',
|
||||
// success: (res) => {
|
||||
// this.setDynamicStyle(res.tempFilePath);
|
||||
// }
|
||||
// });
|
||||
},
|
||||
methods: {
|
||||
isColor(color) {
|
||||
console.log(color, this.formats.color)
|
||||
if (color === this.formats.color) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
async toSuccess() {
|
||||
// let that = this;
|
||||
// let index = uni.getStorageSync("selectIndex");
|
||||
// let cms = uni.getStorageSync("cms");
|
||||
// console.log(cms)
|
||||
// if (cms && cms.cmsLst && cms.cmsLst[index]) {
|
||||
// this.editorCtx.getContents({
|
||||
// success: async (res) => {
|
||||
// console.log(res);
|
||||
// let {
|
||||
// html,
|
||||
// text,
|
||||
// delta
|
||||
// } = res;
|
||||
// console.log(cms)
|
||||
// cms.cmsLst[index] = {
|
||||
// image: cms.cmsLst[index].image,
|
||||
// type: cms.cmsLst[index].type,
|
||||
// text: text,
|
||||
// html: html,
|
||||
// delta:delta,
|
||||
// }
|
||||
// await uni.setStorageSync("cms", cms);
|
||||
// await that.back();
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// console.log(err)
|
||||
// },
|
||||
// complete: () => {
|
||||
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
},
|
||||
async back() {
|
||||
try {
|
||||
uni.navigateBack({delta: 1});
|
||||
} catch(e) {
|
||||
uni.navigateTo({
|
||||
url: "/pages2/editCms/editCms"
|
||||
})
|
||||
}
|
||||
},
|
||||
readOnlyChange() {
|
||||
this.readOnly = !this.readOnly
|
||||
},
|
||||
onEditorReady() {
|
||||
// #ifdef MP-BAIDU
|
||||
this.editorCtx = requireDynamicLib('editorLib').createEditorContext('editor');
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS || MP-WEIXIN || H5
|
||||
uni.createSelectorQuery().select('#editor').context((res) => {
|
||||
this.editorCtx = res.context
|
||||
}).exec()
|
||||
// #endif
|
||||
},
|
||||
undo() {
|
||||
this.editorCtx.undo()
|
||||
},
|
||||
redo() {
|
||||
this.editorCtx.redo()
|
||||
},
|
||||
format(e) {
|
||||
let {
|
||||
name,
|
||||
value
|
||||
} = e.target.dataset
|
||||
if (!name) return
|
||||
// console.log('format', name, value)
|
||||
this.editorCtx.format(name, value)
|
||||
},
|
||||
onStatusChange(e) {
|
||||
const formats = e.detail
|
||||
this.formats = formats
|
||||
},
|
||||
insertDivider() {
|
||||
this.editorCtx.insertDivider({
|
||||
success: function() {
|
||||
console.log('insert divider success')
|
||||
}
|
||||
})
|
||||
},
|
||||
clear() {
|
||||
uni.showModal({
|
||||
title: '清空编辑器',
|
||||
content: '确定清空编辑器全部内容?',
|
||||
success: res => {
|
||||
if (res.confirm) {
|
||||
this.editorCtx.clear({
|
||||
success: function(res) {
|
||||
console.log("clear success")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
removeFormat() {
|
||||
this.editorCtx.removeFormat()
|
||||
},
|
||||
insertDate() {
|
||||
const date = new Date()
|
||||
const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
|
||||
this.editorCtx.insertText({
|
||||
text: formatDate
|
||||
})
|
||||
},
|
||||
insertImage() {
|
||||
uni.chooseImage({
|
||||
count: 1,
|
||||
success: (res) => {
|
||||
this.editorCtx.insertImage({
|
||||
src: res.tempFilePaths[0],
|
||||
alt: '图像',
|
||||
success: function() {
|
||||
console.log('insert image success')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@import url("./css/edit.css");
|
||||
</style>
|
||||
Reference in New Issue
Block a user