|
@@ -3489,10 +3489,6 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
type: Object,
|
|
type: Object,
|
|
|
default: () => ({}),
|
|
default: () => ({}),
|
|
|
},
|
|
},
|
|
|
- customButtons: {
|
|
|
|
|
- type: Array,
|
|
|
|
|
- default: () => [],
|
|
|
|
|
- },
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
emits: ["update:modelValue", "ready", "change"],
|
|
emits: ["update:modelValue", "ready", "change"],
|
|
@@ -3725,34 +3721,32 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 如果 prop 为空,尝试从各种来源读取按钮配置
|
|
|
|
|
- let buttonsToUse = props.customButtons;
|
|
|
|
|
|
|
+ // 读取按钮配置 by xu 20250408(移除废弃的 props.customButtons)
|
|
|
|
|
+ let buttonsToUse = [];
|
|
|
|
|
+ // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
|
|
|
|
|
+ if (customButtonsFromParam && customButtonsFromParam.length > 0) {
|
|
|
|
|
+ buttonsToUse = customButtonsFromParam;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
|
|
|
if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
- // 1. 优先从 param.button 数组中筛选(新格式)by xu 20250331
|
|
|
|
|
- if (customButtonsFromParam && customButtonsFromParam.length > 0) {
|
|
|
|
|
- buttonsToUse = customButtonsFromParam;
|
|
|
|
|
- }
|
|
|
|
|
- // 2. 尝试从 param.customButtons 读取(旧格式,兼容)
|
|
|
|
|
- if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
|
|
- if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
|
|
|
|
|
- buttonsToUse = props.param.customButtons;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (props.param && props.param.customButtons && props.param.customButtons.length > 0) {
|
|
|
|
|
+ buttonsToUse = props.param.customButtons;
|
|
|
}
|
|
}
|
|
|
- // 3. 尝试通过桥接 API 读取
|
|
|
|
|
- if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
|
|
- const vm = window.SS.dom.getVueApp({ scope: "chain" });
|
|
|
|
|
- if (vm && vm.zwwjCustomButtons) {
|
|
|
|
|
- buttonsToUse = vm.zwwjCustomButtons;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // 3. 尝试通过桥接 API 读取
|
|
|
|
|
+ if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
|
|
+ const vm = window.SS.dom.getVueApp({ scope: "chain" });
|
|
|
|
|
+ if (vm && vm.zwwjCustomButtons) {
|
|
|
|
|
+ buttonsToUse = vm.zwwjCustomButtons;
|
|
|
}
|
|
}
|
|
|
- // 4. 从 formElemConfig 读取(兜底)
|
|
|
|
|
- if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
|
|
- const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
|
|
|
|
|
- if (zwwjConfig?.customButtons) {
|
|
|
|
|
- buttonsToUse = zwwjConfig.customButtons;
|
|
|
|
|
- } else {
|
|
|
|
|
- buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ // 4. 从 formElemConfig 读取(兜底)
|
|
|
|
|
+ if (!buttonsToUse || buttonsToUse.length === 0) {
|
|
|
|
|
+ const zwwjConfig = window.SS.dom.formElemConfig?.zwwj;
|
|
|
|
|
+ if (zwwjConfig?.customButtons) {
|
|
|
|
|
+ buttonsToUse = zwwjConfig.customButtons;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ buttonsToUse = window.SS.dom.formElemConfig?.zwwjCustomButtons;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -4109,46 +4103,6 @@ import { EVEN_VAR } from "./EventBus.js";
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- // 监听 customButtons 变化,支持运行时动态更新 by xu 20250331
|
|
|
|
|
- watch(
|
|
|
|
|
- () => props.customButtons,
|
|
|
|
|
- (newButtons) => {
|
|
|
|
|
- if (!editorRef.value) return;
|
|
|
|
|
- if (!newButtons || newButtons.length === 0) return;
|
|
|
|
|
-
|
|
|
|
|
- console.log("[SsEditor] customButtons 变化:", newButtons);
|
|
|
|
|
-
|
|
|
|
|
- const { controls, buttonNames } = buildCustomButtonRegistry(newButtons);
|
|
|
|
|
- if (buttonNames.length === 0) return;
|
|
|
|
|
-
|
|
|
|
|
- // 注册新控件到 Jodit
|
|
|
|
|
- buttonNames.forEach((btnKey) => {
|
|
|
|
|
- const control = controls[btnKey];
|
|
|
|
|
- if (control && control.exec) {
|
|
|
|
|
- // 使用 Jodit 的 register 方法注册新按钮
|
|
|
|
|
- editorRef.value.controls.register(btnKey, control);
|
|
|
|
|
- console.log("[SsEditor] 注册新按钮:", btnKey);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 更新工具栏(需要重新构建)
|
|
|
|
|
- const toolbar = editorRef.value.toolbar;
|
|
|
|
|
- if (toolbar && toolbar.build) {
|
|
|
|
|
- try {
|
|
|
|
|
- // 获取当前配置并重新构建工具栏
|
|
|
|
|
- const currentButtons = editorRef.value.options.buttons || [];
|
|
|
|
|
- const newToolbarButtons = [...currentButtons, ...buttonNames];
|
|
|
|
|
- editorRef.value.options.buttons = newToolbarButtons;
|
|
|
|
|
- toolbar.build(newToolbarButtons, toolbar.container);
|
|
|
|
|
- console.log("[SsEditor] 工具栏已更新,新按钮:", buttonNames);
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- console.warn("[SsEditor] 工具栏更新失败:", e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- { deep: true, immediate: false }
|
|
|
|
|
- );
|
|
|
|
|
-
|
|
|
|
|
onBeforeUnmount(() => {
|
|
onBeforeUnmount(() => {
|
|
|
if (editorRef.value) {
|
|
if (editorRef.value) {
|
|
|
editorRef.value.destruct();
|
|
editorRef.value.destruct();
|