Commit 58f988a7184dd7bdec415627e16b56b80f36b661
1 parent
28590676
feat: add tinymce embedded form example
Showing
6 changed files
with
43 additions
and
32 deletions
package.json
src/components/Tinymce/src/Editor.vue
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | watch, |
16 | 16 | onUnmounted, |
17 | 17 | onDeactivated, |
18 | + watchEffect, | |
18 | 19 | } from 'vue'; |
19 | 20 | import { basicProps } from './props'; |
20 | 21 | import toolbar from './toolbar'; |
... | ... | @@ -57,6 +58,8 @@ |
57 | 58 | const { height, options } = props; |
58 | 59 | return { |
59 | 60 | selector: `#${unref(tinymceId)}`, |
61 | + base_url: CDN_URL, | |
62 | + suffix: '.min', | |
60 | 63 | height: height, |
61 | 64 | toolbar: toolbar, |
62 | 65 | menubar: 'file edit insert view format table', |
... | ... | @@ -134,36 +137,48 @@ |
134 | 137 | bindHandlers(e, attrs, unref(editorRef)); |
135 | 138 | } |
136 | 139 | |
140 | + function setValue(editor: any, val: string, prevVal: string) { | |
141 | + if ( | |
142 | + editor && | |
143 | + typeof val === 'string' && | |
144 | + val !== prevVal && | |
145 | + val !== editor.getContent({ format: attrs.outputFormat }) | |
146 | + ) { | |
147 | + editor.setContent(val); | |
148 | + } | |
149 | + } | |
150 | + | |
137 | 151 | function bindModelHandlers(editor: any) { |
138 | 152 | const modelEvents = attrs.modelEvents ? attrs.modelEvents : null; |
139 | 153 | const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents; |
140 | 154 | watch( |
141 | 155 | () => props.modelValue, |
142 | 156 | (val: string, prevVal: string) => { |
143 | - if ( | |
144 | - editor && | |
145 | - typeof val === 'string' && | |
146 | - val !== prevVal && | |
147 | - val !== editor.getContent({ format: attrs.outputFormat }) | |
148 | - ) { | |
149 | - editor.setContent(val); | |
150 | - } | |
157 | + setValue(editor, val, prevVal); | |
158 | + } | |
159 | + ); | |
160 | + | |
161 | + watch( | |
162 | + () => props.value, | |
163 | + (val: string, prevVal: string) => { | |
164 | + setValue(editor, val, prevVal); | |
165 | + }, | |
166 | + { | |
167 | + immediate: true, | |
151 | 168 | } |
152 | 169 | ); |
153 | 170 | |
154 | 171 | editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', () => { |
155 | - emit('update:modelValue', editor.getContent({ format: attrs.outputFormat })); | |
172 | + const content = editor.getContent({ format: attrs.outputFormat }); | |
173 | + emit('update:modelValue', content); | |
174 | + emit('change', content); | |
156 | 175 | }); |
157 | 176 | } |
158 | 177 | |
159 | - function handleChange(value: string) { | |
160 | - emit('change', value); | |
161 | - } | |
162 | 178 | return { |
163 | 179 | containerWidth, |
164 | 180 | initOptions, |
165 | 181 | tinymceContent, |
166 | - handleChange, | |
167 | 182 | tinymceScriptSrc, |
168 | 183 | elRef, |
169 | 184 | tinymceId, | ... | ... |
src/router/menus/modules/demo/editor.ts
src/router/routes/modules/demo/editor.ts
... | ... | @@ -40,14 +40,14 @@ export default { |
40 | 40 | }, |
41 | 41 | }, |
42 | 42 | // TODO |
43 | - // { | |
44 | - // path: 'editor', | |
45 | - // name: 'TinymceFormDemo', | |
46 | - // component: () => import('/@/views/demo/comp/tinymce/Editor.vue'), | |
47 | - // meta: { | |
48 | - // title: '嵌入form使用', | |
49 | - // }, | |
50 | - // }, | |
43 | + { | |
44 | + path: 'editor', | |
45 | + name: 'TinymceFormDemo', | |
46 | + component: () => import('/@/views/demo/editor/tinymce/Editor.vue'), | |
47 | + meta: { | |
48 | + title: '嵌入form使用', | |
49 | + }, | |
50 | + }, | |
51 | 51 | ], |
52 | 52 | }, |
53 | 53 | ], | ... | ... |
src/utils/helper/routeHelper.ts
... | ... | @@ -44,8 +44,10 @@ export function genRouteModule(moduleList: AppRouteModule[]) { |
44 | 44 | // 动态引入 |
45 | 45 | function asyncImportRoute(routes: AppRouteRecordRaw[]) { |
46 | 46 | routes.forEach((item) => { |
47 | - const { component, children } = item; | |
47 | + let { component } = item; | |
48 | + const { children } = item; | |
48 | 49 | if (component) { |
50 | + component = component.replace(/^\//, ''); | |
49 | 51 | item.component = () => import(`/@/views/${component}`); |
50 | 52 | } |
51 | 53 | children && asyncImportRoute(children); | ... | ... |
yarn.lock
... | ... | @@ -6757,11 +6757,6 @@ rimraf@^3.0.2: |
6757 | 6757 | dependencies: |
6758 | 6758 | glob "^7.1.3" |
6759 | 6759 | |
6760 | -rollup-plugin-analyzer@^3.3.0: | |
6761 | - version "3.3.0" | |
6762 | - resolved "https://registry.npmjs.org/rollup-plugin-analyzer/-/rollup-plugin-analyzer-3.3.0.tgz#52fb30465ae927d9c078b6ec90c578cfb9164fc2" | |
6763 | - integrity sha512-zUPGitW4usmZcVa0nKecRvw3odtXgnxdCben9Hx1kxVoR3demek8RU9tmRG/R35hnRPQTb7wEsYEe3GUcjxIMA== | |
6764 | - | |
6765 | 6760 | rollup-plugin-babel@^4.3.3: |
6766 | 6761 | version "4.4.0" |
6767 | 6762 | resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb" | ... | ... |