Commit 58f988a7184dd7bdec415627e16b56b80f36b661

Authored by vben
1 parent 28590676

feat: add tinymce embedded form example

package.json
@@ -81,7 +81,6 @@ @@ -81,7 +81,6 @@
81 "postcss-import": "^12.0.1", 81 "postcss-import": "^12.0.1",
82 "prettier": "^2.1.2", 82 "prettier": "^2.1.2",
83 "rimraf": "^3.0.2", 83 "rimraf": "^3.0.2",
84 - "rollup-plugin-analyzer": "^3.3.0",  
85 "rollup-plugin-visualizer": "^4.1.2", 84 "rollup-plugin-visualizer": "^4.1.2",
86 "stylelint": "^13.7.2", 85 "stylelint": "^13.7.2",
87 "stylelint-config-prettier": "^8.0.2", 86 "stylelint-config-prettier": "^8.0.2",
src/components/Tinymce/src/Editor.vue
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 watch, 15 watch,
16 onUnmounted, 16 onUnmounted,
17 onDeactivated, 17 onDeactivated,
  18 + watchEffect,
18 } from 'vue'; 19 } from 'vue';
19 import { basicProps } from './props'; 20 import { basicProps } from './props';
20 import toolbar from './toolbar'; 21 import toolbar from './toolbar';
@@ -57,6 +58,8 @@ @@ -57,6 +58,8 @@
57 const { height, options } = props; 58 const { height, options } = props;
58 return { 59 return {
59 selector: `#${unref(tinymceId)}`, 60 selector: `#${unref(tinymceId)}`,
  61 + base_url: CDN_URL,
  62 + suffix: '.min',
60 height: height, 63 height: height,
61 toolbar: toolbar, 64 toolbar: toolbar,
62 menubar: 'file edit insert view format table', 65 menubar: 'file edit insert view format table',
@@ -134,36 +137,48 @@ @@ -134,36 +137,48 @@
134 bindHandlers(e, attrs, unref(editorRef)); 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 function bindModelHandlers(editor: any) { 151 function bindModelHandlers(editor: any) {
138 const modelEvents = attrs.modelEvents ? attrs.modelEvents : null; 152 const modelEvents = attrs.modelEvents ? attrs.modelEvents : null;
139 const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents; 153 const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents;
140 watch( 154 watch(
141 () => props.modelValue, 155 () => props.modelValue,
142 (val: string, prevVal: string) => { 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 editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', () => { 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 return { 178 return {
163 containerWidth, 179 containerWidth,
164 initOptions, 180 initOptions,
165 tinymceContent, 181 tinymceContent,
166 - handleChange,  
167 tinymceScriptSrc, 182 tinymceScriptSrc,
168 elRef, 183 elRef,
169 tinymceId, 184 tinymceId,
src/router/menus/modules/demo/editor.ts
@@ -17,10 +17,10 @@ const menu: MenuModule = { @@ -17,10 +17,10 @@ const menu: MenuModule = {
17 path: 'index', 17 path: 'index',
18 name: '基础使用', 18 name: '基础使用',
19 }, 19 },
20 - // {  
21 - // path: 'editor',  
22 - // name: '嵌入form使用',  
23 - // }, 20 + {
  21 + path: 'editor',
  22 + name: '嵌入form使用',
  23 + },
24 ], 24 ],
25 }, 25 },
26 ], 26 ],
src/router/routes/modules/demo/editor.ts
@@ -40,14 +40,14 @@ export default { @@ -40,14 +40,14 @@ export default {
40 }, 40 },
41 }, 41 },
42 // TODO 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,8 +44,10 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
44 // 动态引入 44 // 动态引入
45 function asyncImportRoute(routes: AppRouteRecordRaw[]) { 45 function asyncImportRoute(routes: AppRouteRecordRaw[]) {
46 routes.forEach((item) => { 46 routes.forEach((item) => {
47 - const { component, children } = item; 47 + let { component } = item;
  48 + const { children } = item;
48 if (component) { 49 if (component) {
  50 + component = component.replace(/^\//, '');
49 item.component = () => import(`/@/views/${component}`); 51 item.component = () => import(`/@/views/${component}`);
50 } 52 }
51 children && asyncImportRoute(children); 53 children && asyncImportRoute(children);
yarn.lock
@@ -6757,11 +6757,6 @@ rimraf@^3.0.2: @@ -6757,11 +6757,6 @@ rimraf@^3.0.2:
6757 dependencies: 6757 dependencies:
6758 glob "^7.1.3" 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 rollup-plugin-babel@^4.3.3: 6760 rollup-plugin-babel@^4.3.3:
6766 version "4.4.0" 6761 version "4.4.0"
6767 resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb" 6762 resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb"