提交 58f988a7 作者: vben

feat: add tinymce embedded form example

上级 28590676
...@@ -81,7 +81,6 @@ ...@@ -81,7 +81,6 @@
"postcss-import": "^12.0.1", "postcss-import": "^12.0.1",
"prettier": "^2.1.2", "prettier": "^2.1.2",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"rollup-plugin-analyzer": "^3.3.0",
"rollup-plugin-visualizer": "^4.1.2", "rollup-plugin-visualizer": "^4.1.2",
"stylelint": "^13.7.2", "stylelint": "^13.7.2",
"stylelint-config-prettier": "^8.0.2", "stylelint-config-prettier": "^8.0.2",
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
watch, watch,
onUnmounted, onUnmounted,
onDeactivated, onDeactivated,
watchEffect,
} from 'vue'; } from 'vue';
import { basicProps } from './props'; import { basicProps } from './props';
import toolbar from './toolbar'; import toolbar from './toolbar';
...@@ -57,6 +58,8 @@ ...@@ -57,6 +58,8 @@
const { height, options } = props; const { height, options } = props;
return { return {
selector: `#${unref(tinymceId)}`, selector: `#${unref(tinymceId)}`,
base_url: CDN_URL,
suffix: '.min',
height: height, height: height,
toolbar: toolbar, toolbar: toolbar,
menubar: 'file edit insert view format table', menubar: 'file edit insert view format table',
...@@ -134,36 +137,48 @@ ...@@ -134,36 +137,48 @@
bindHandlers(e, attrs, unref(editorRef)); bindHandlers(e, attrs, unref(editorRef));
} }
function setValue(editor: any, val: string, prevVal: string) {
if (
editor &&
typeof val === 'string' &&
val !== prevVal &&
val !== editor.getContent({ format: attrs.outputFormat })
) {
editor.setContent(val);
}
}
function bindModelHandlers(editor: any) { function bindModelHandlers(editor: any) {
const modelEvents = attrs.modelEvents ? attrs.modelEvents : null; const modelEvents = attrs.modelEvents ? attrs.modelEvents : null;
const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents; const normalizedEvents = Array.isArray(modelEvents) ? modelEvents.join(' ') : modelEvents;
watch( watch(
() => props.modelValue, () => props.modelValue,
(val: string, prevVal: string) => { (val: string, prevVal: string) => {
if ( setValue(editor, val, prevVal);
editor && }
typeof val === 'string' && );
val !== prevVal &&
val !== editor.getContent({ format: attrs.outputFormat }) watch(
) { () => props.value,
editor.setContent(val); (val: string, prevVal: string) => {
} setValue(editor, val, prevVal);
},
{
immediate: true,
} }
); );
editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', () => { editor.on(normalizedEvents ? normalizedEvents : 'change keyup undo redo', () => {
emit('update:modelValue', editor.getContent({ format: attrs.outputFormat })); const content = editor.getContent({ format: attrs.outputFormat });
emit('update:modelValue', content);
emit('change', content);
}); });
} }
function handleChange(value: string) {
emit('change', value);
}
return { return {
containerWidth, containerWidth,
initOptions, initOptions,
tinymceContent, tinymceContent,
handleChange,
tinymceScriptSrc, tinymceScriptSrc,
elRef, elRef,
tinymceId, tinymceId,
......
...@@ -17,10 +17,10 @@ const menu: MenuModule = { ...@@ -17,10 +17,10 @@ const menu: MenuModule = {
path: 'index', path: 'index',
name: '基础使用', name: '基础使用',
}, },
// { {
// path: 'editor', path: 'editor',
// name: '嵌入form使用', name: '嵌入form使用',
// }, },
], ],
}, },
], ],
......
...@@ -40,14 +40,14 @@ export default { ...@@ -40,14 +40,14 @@ export default {
}, },
}, },
// TODO // TODO
// { {
// path: 'editor', path: 'editor',
// name: 'TinymceFormDemo', name: 'TinymceFormDemo',
// component: () => import('/@/views/demo/comp/tinymce/Editor.vue'), component: () => import('/@/views/demo/editor/tinymce/Editor.vue'),
// meta: { meta: {
// title: '嵌入form使用', title: '嵌入form使用',
// }, },
// }, },
], ],
}, },
], ],
......
...@@ -44,8 +44,10 @@ export function genRouteModule(moduleList: AppRouteModule[]) { ...@@ -44,8 +44,10 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
// 动态引入 // 动态引入
function asyncImportRoute(routes: AppRouteRecordRaw[]) { function asyncImportRoute(routes: AppRouteRecordRaw[]) {
routes.forEach((item) => { routes.forEach((item) => {
const { component, children } = item; let { component } = item;
const { children } = item;
if (component) { if (component) {
component = component.replace(/^\//, '');
item.component = () => import(`/@/views/${component}`); item.component = () => import(`/@/views/${component}`);
} }
children && asyncImportRoute(children); children && asyncImportRoute(children);
......
...@@ -6757,11 +6757,6 @@ rimraf@^3.0.2: ...@@ -6757,11 +6757,6 @@ rimraf@^3.0.2:
dependencies: dependencies:
glob "^7.1.3" glob "^7.1.3"
rollup-plugin-analyzer@^3.3.0:
version "3.3.0"
resolved "https://registry.npmjs.org/rollup-plugin-analyzer/-/rollup-plugin-analyzer-3.3.0.tgz#52fb30465ae927d9c078b6ec90c578cfb9164fc2"
integrity sha512-zUPGitW4usmZcVa0nKecRvw3odtXgnxdCben9Hx1kxVoR3demek8RU9tmRG/R35hnRPQTb7wEsYEe3GUcjxIMA==
rollup-plugin-babel@^4.3.3: rollup-plugin-babel@^4.3.3:
version "4.4.0" version "4.4.0"
resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb" resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.4.0.tgz#d15bd259466a9d1accbdb2fe2fff17c52d030acb"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论