fwblz.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view class="container">
  3. <view class="page-body">
  4. <view class='wrapper'>
  5. <view class='toolbar' @tap="format" style="height: 150px;overflow-y: auto;">
  6. <view :class="formats.bold ? 'ql-active' : ''" class="iconfont icon-zitijiacu" data-name="bold">
  7. </view>
  8. <view :class="formats.italic ? 'ql-active' : ''" class="iconfont icon-zitixieti" data-name="italic">
  9. </view>
  10. <view :class="formats.underline ? 'ql-active' : ''" class="iconfont icon-zitixiahuaxian"
  11. data-name="underline"></view>
  12. <view :class="formats.strike ? 'ql-active' : ''" class="iconfont icon-zitishanchuxian"
  13. data-name="strike"></view>
  14. <!-- #ifndef MP-BAIDU -->
  15. <view :class="formats.align === 'left' ? 'ql-active' : ''" class="iconfont icon-zuoduiqi"
  16. data-name="align" data-value="left"></view>
  17. <!-- #endif -->
  18. <view :class="formats.align === 'center' ? 'ql-active' : ''" class="iconfont icon-juzhongduiqi"
  19. data-name="align" data-value="center"></view>
  20. <view :class="formats.align === 'right' ? 'ql-active' : ''" class="iconfont icon-youduiqi"
  21. data-name="align" data-value="right"></view>
  22. <view :class="formats.align === 'justify' ? 'ql-active' : ''" class="iconfont icon-zuoyouduiqi"
  23. data-name="align" data-value="justify"></view>
  24. <!-- #ifndef MP-BAIDU -->
  25. <view :class="formats.lineHeight ? 'ql-active' : ''" class="iconfont icon-line-height"
  26. data-name="lineHeight" data-value="2"></view>
  27. <view :class="formats.letterSpacing ? 'ql-active' : ''" class="iconfont icon-Character-Spacing"
  28. data-name="letterSpacing" data-value="2em"></view>
  29. <view :class="formats.marginTop ? 'ql-active' : ''" class="iconfont icon-722bianjiqi_duanqianju"
  30. data-name="marginTop" data-value="20px"></view>
  31. <view :class="formats.marginBottom ? 'ql-active' : ''" class="iconfont icon-723bianjiqi_duanhouju"
  32. data-name="marginBottom" data-value="20px"></view>
  33. <!-- #endif -->
  34. <view class="iconfont icon-clearedformat" @tap="removeFormat"></view>
  35. <!-- #ifndef MP-BAIDU -->
  36. <view :class="formats.fontSize === '24px' ? 'ql-active' : ''" class="iconfont icon-fontsize"
  37. data-name="fontSize" data-value="24px"></view>
  38. <!-- #endif -->
  39. <view :class="formats.color === '#0000ff' ? 'ql-active' : ''" class="iconfont icon-text_color"
  40. data-name="color" data-value="#0000ff"></view>
  41. <view :class="formats.backgroundColor === '#00ff00' ? 'ql-active' : ''"
  42. class="iconfont icon-fontbgcolor" data-name="backgroundColor" data-value="#00ff00"></view>
  43. <view class="iconfont icon-date" @tap="insertDate"></view>
  44. <view class="iconfont icon--checklist" data-name="list" data-value="check"></view>
  45. <view :class="formats.list === 'ordered' ? 'ql-active' : ''" class="iconfont icon-youxupailie"
  46. data-name="list" data-value="ordered"></view>
  47. <view :class="formats.list === 'bullet' ? 'ql-active' : ''" class="iconfont icon-wuxupailie"
  48. data-name="list" data-value="bullet"></view>
  49. <view class="iconfont icon-undo" @tap="undo"></view>
  50. <view class="iconfont icon-redo" @tap="redo"></view>
  51. <view class="iconfont icon-outdent" data-name="indent" data-value="-1"></view>
  52. <view class="iconfont icon-indent" data-name="indent" data-value="+1"></view>
  53. <view class="iconfont icon-fengexian" @tap="insertDivider"></view>
  54. <view class="iconfont icon-charutupian" @tap="insertImage"></view>
  55. <view :class="formats.header === 1 ? 'ql-active' : ''" class="iconfont icon-format-header-1"
  56. data-name="header" :data-value="1"></view>
  57. <view :class="formats.script === 'sub' ? 'ql-active' : ''" class="iconfont icon-zitixiabiao"
  58. data-name="script" data-value="sub"></view>
  59. <view :class="formats.script === 'super' ? 'ql-active' : ''" class="iconfont icon-zitishangbiao"
  60. data-name="script" data-value="super"></view>
  61. <view class="iconfont icon-shanchu" @tap="clear"></view>
  62. <view :class="formats.direction === 'rtl' ? 'ql-active' : ''" class="iconfont icon-direction-rtl"
  63. data-name="direction" data-value="rtl"></view>
  64. </view>
  65. <view class="editor-wrapper">
  66. <editor id="editor" class="ql-container" placeholder="开始输入..." show-img-size show-img-toolbar
  67. show-img-resize @statuschange="onStatusChange" :read-only="readOnly" @ready="onEditorReady" @blur="blur">
  68. </editor>
  69. <view class="" style="text-align: center;margin-bottom: 30rpx;">
  70. <button style="" type="primary" size="medium" @click="submitInfo()">发布</button>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. // import quill from "quill";
  79. export default {
  80. data() {
  81. return {
  82. title: 'Hello',
  83. readOnly: false,
  84. formats: {},
  85. info:''
  86. }
  87. },
  88. onLoad() {
  89. },
  90. methods: {
  91. blur(e){
  92. this.info=e.detail.html
  93. console.log(this.info,e,'失去焦点')
  94. },
  95. readOnlyChange() {
  96. this.readOnly = !this.readOnly
  97. },
  98. onEditorReady() {
  99. // #ifdef MP-BAIDU
  100. this.editorCtx = requireDynamicLib('editorLib').createEditorContext('editor');
  101. // #endif
  102. // #ifdef APP-PLUS || MP-WEIXIN || H5
  103. uni.createSelectorQuery().select('#editor').context((res) => {
  104. this.editorCtx = res.context
  105. }).exec()
  106. // #endif
  107. },
  108. undo() {
  109. this.editorCtx.undo()
  110. },
  111. redo() {
  112. this.editorCtx.redo()
  113. },
  114. format(e) {
  115. let {
  116. name,
  117. value
  118. } = e.target.dataset
  119. if (!name) return
  120. // console.log('format', name, value)
  121. this.editorCtx.format(name, value)
  122. },
  123. onStatusChange(e) {
  124. const formats = e.detail
  125. this.formats = formats
  126. },
  127. insertDivider() {
  128. this.editorCtx.insertDivider({
  129. success: function() {
  130. console.log('insert divider success')
  131. }
  132. })
  133. },
  134. clear() {
  135. uni.showModal({
  136. title: '清空编辑器',
  137. content: '确定清空编辑器全部内容?',
  138. success: res => {
  139. if (res.confirm) {
  140. this.editorCtx.clear({
  141. success: function(res) {
  142. console.log("clear success")
  143. }
  144. })
  145. }
  146. }
  147. })
  148. },
  149. removeFormat() {
  150. this.editorCtx.removeFormat()
  151. },
  152. insertDate() {
  153. const date = new Date()
  154. const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
  155. this.editorCtx.insertText({
  156. text: formatDate
  157. })
  158. },
  159. insertImage() {
  160. uni.chooseImage({
  161. count: 1,
  162. success: (res) => {
  163. this.editorCtx.insertImage({
  164. src: res.tempFilePaths[0],
  165. alt: '图像',
  166. success: function() {
  167. console.log('insert image success')
  168. }
  169. })
  170. }
  171. })
  172. },
  173. submitInfo(){
  174. this.info = "我已获取到内容,内容如下:"+this.info
  175. }
  176. }
  177. }
  178. </script>
  179. <style>
  180. @import "../../static/editor/editor-icon.css";
  181. .page-body {
  182. height: calc(100vh - var(--window-top) - var(--status-bar-height));
  183. }
  184. .wrapper {
  185. height: 100%;
  186. display: flex;
  187. flex-direction: column;
  188. justify-content: space-between;
  189. }
  190. .editor-wrapper {
  191. height: calc(100vh - var(--window-top) - var(--status-bar-height) - 140px);
  192. background: #fff;
  193. display: flex;
  194. flex-direction: column;
  195. justify-content: space-between;
  196. }
  197. .iconfont {
  198. display: inline-block;
  199. padding: 26rpx 26rpx;
  200. width: 80rpx;
  201. height:80rpx;
  202. cursor: pointer;
  203. font-size: 20px;
  204. }
  205. .toolbar {
  206. box-sizing: border-box;
  207. border-bottom: 0;
  208. font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  209. }
  210. .ql-container {
  211. flex:1;
  212. box-sizing: border-box;
  213. padding: 12px 15px;
  214. width: 100%;
  215. min-height: 30vh;
  216. /* height: auto; */
  217. /* height: 80%; */
  218. margin-top: 20px;
  219. font-size: 16px;
  220. line-height: 1.5;
  221. }
  222. .ql-active {
  223. color: #06c;
  224. }
  225. </style>