hookehuyr

fix 富文本编辑器写入数据逻辑调整

1 <!-- 1 <!--
2 * @Date: 2022-09-26 21:52:25 2 * @Date: 2022-09-26 21:52:25
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2022-10-26 11:31:30 4 + * @LastEditTime: 2022-10-26 18:54:14
5 * @FilePath: /swx/src/components/activity-editor.vue 5 * @FilePath: /swx/src/components/activity-editor.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -56,28 +56,41 @@ import { ref } from 'vue' ...@@ -56,28 +56,41 @@ import { ref } from 'vue'
56 <script> 56 <script>
57 import Taro from '@tarojs/taro' 57 import Taro from '@tarojs/taro'
58 import BASE_URL from '@/utils/config'; 58 import BASE_URL from '@/utils/config';
59 +import { activityInfoAPI } from '@/api/Host/index';
60 +import { getCurrentPageParam } from "@/utils/weapp";
59 61
60 export default { 62 export default {
61 props: ['showTabBar', 'placeholder', 'name', 'htmlContent'], 63 props: ['showTabBar', 'placeholder', 'name', 'htmlContent'],
62 data() { 64 data() {
63 return { 65 return {
64 - editorCtx: '' 66 + editorCtx: '',
67 + html_content: ''
65 } 68 }
66 }, 69 },
67 watch: { 70 watch: {
68 - htmlContent (val) { 71 + async htmlContent (val) {
69 // 如果有传值,还原重新编辑 72 // 如果有传值,还原重新编辑
70 - this.editorCtx.setContents({ 73 + if (val) {
71 - html: val 74 + const { code, data } = await activityInfoAPI({ i: getCurrentPageParam().id });
72 - }) 75 + if (code) {
76 + // 更新活动信息
77 + this.html_content = data.activity.note
78 + this._onEditorReady()
79 + }
80 + }
73 } 81 }
74 }, 82 },
75 methods: { 83 methods: {
76 _onEditorReady: function () { 84 _onEditorReady: function () {
77 const that = this; 85 const that = this;
78 - Taro.createSelectorQuery().select('#editor').context(function (res) { 86 + setTimeout(() => {
79 - that.editorCtx = res.context 87 + wx.createSelectorQuery().select('#editor').context(function (res) {
88 + that.editorCtx = res.context;
89 + that.editorCtx.setContents({
90 + html: that.html_content //将数据写入编辑器内
91 + })
80 }).exec(); 92 }).exec();
93 + }, 500);
81 }, 94 },
82 //插入图片 95 //插入图片
83 _addImage: function (event) { 96 _addImage: function (event) {
...@@ -160,6 +173,12 @@ export default { ...@@ -160,6 +173,12 @@ export default {
160 // this.triggerEvent("input", { html: html, text: text }, {}); 173 // this.triggerEvent("input", { html: html, text: text }, {});
161 // console.warn(html); 174 // console.warn(html);
162 // console.warn(text); 175 // console.warn(text);
176 + },
177 + _rewrite (val) {
178 + // 如果有传值,还原重新编辑
179 + this.editorCtx.setContents({
180 + html: val
181 + })
163 } 182 }
164 } 183 }
165 } 184 }
......