import {commonIcon, ssIcon} from "./icon-config.js"; import * as IndexComponents from "./ss-index-components.js"; import * as EchartComponents from "./ss-echarts-compnents.js"; import {buildThumbUrl, isNum, toStyleStr,} from "./tools.js"; // 功能说明:组件内统一构建缩略图URL、打开服务弹窗,减少 JSP 层字段转换 by xu 20260122 import {EVEN_VAR} from "./EventBus.js"; // import * as elements from "../lib/element-plus.js"; (function () { const { createApp, ref, reactive, watch, onMounted, onBeforeUnmount, h, computed, resolveComponent, watchEffect, nextTick, onVnodeMounted, Teleport, inject, provide, } = Vue; // 弹窗默认遮罩z-index let currentZIndex = 100; // 目前已存在的弹窗 const topWindow = window.top; topWindow.dialogInstances = topWindow.dialogInstances || []; // 新建弹窗 function createSsDialogInstance(setting, callbackEvent) { currentZIndex += 10; // 动态提升 z-index const container = document.createElement("div"); document.body.appendChild(container); const app = Vue.createApp({ render() { return h(SsDialog, { ...setting, zIndex: currentZIndex, onClose() { document.body.removeChild(container); // 仅移除弹窗容器 const index = topWindow.dialogInstances.indexOf(app); if (index > -1) { topWindow.dialogInstances.splice(index, 1); // 移除实例 } // 关闭后的回调 if (callbackEvent && typeof callbackEvent === "function") { callbackEvent(); } app.unmount(); // 仅卸载弹窗实例 if (container.parentNode) { container.parentNode.removeChild(container); // 确保移除容器 } }, }); }, }); topWindow.dialogInstances.push({ app, callbackEvent, container }); app.component("ss-mark", SsMark); // 注册 ss-mark 组件 app.component("ss-icon", SsIcon); app.component("ss-full-style-header", SsFullStyleHeader); // 注册 ss-full-style-header 组件 app.mount(container); } // ss-breadcrumb 一级菜单页面面包屑 const SsBreadcrumb = { name: "SsBreadcrumb", props: { level: { type: Object, default: null, }, }, setup(props) { const currentMenu = ref(null); const folderPath = ref([]); const eventBus = window.parent.sharedEventBus; // 监听页面变化 onMounted(() => { // 获取初始页面 currentMenu.value = eventBus.getState(EVEN_VAR.currentPage); folderPath.value = eventBus.getState("folderPath") || []; // 订阅页面变化 eventBus.subscribe(EVEN_VAR.currentPage, (page) => { currentMenu.value = page; }); eventBus.subscribe("folderPath", (path) => { folderPath.value = path || []; }); }); // 修改点击处理函数 const handlePathClick = (index) => { if (props.level?.onBack) { // 截取到点击的位置,后面的路径会被销毁 const newPath = folderPath.value.slice(0, index + 1); eventBus.publish("folderPath", newPath); // 返回到对应层级 const targetFolder = newPath[newPath.length - 1]?.folder || null; props.level.onBack(targetFolder); } }; const SsCommonIcon = resolveComponent("SsCommonIcon"); return () => h("div", { class: "bread-crumb" }, [ currentMenu.value && h( "div", { onClick: () => { if (props.level?.onBack) { eventBus.publish("folderPath", []); props.level.onBack(null); // 返回到根目录 } else { eventBus.publish(EVEN_VAR.currentPage, currentMenu.value); } }, }, currentMenu.value.label || currentMenu.value.name ), ...(folderPath.value || []) .map((folder, index) => [ h(SsCommonIcon, { class: "common-icon-arrow-right" }), h( "div", { class: "bread-crumb-item", onClick: () => handlePathClick(index), style: { cursor: "pointer" }, }, folder.title ), ]) .flat(), ]); }, }; // ss-input form表单的输入 const SsInput = { name: "SsInp", //把SsInput改为SsInp Ben(20251225) inheritAttrs: false, // 不直接继承属性到组件根元素 props: { name: { type: String, required: true, default: "", }, // 接收 v-model 绑定的值 errTip: { type: String, }, required: { type: Boolean, default: false, }, placeholder: { type: String, default: "", // : "请输入",。再改,去掉 placeholder 默认值 "请输入" 。Lin }, defaultValue: [String, Number], modelValue: [String, Number], // 新增:附件配置 fj: { type: Object, default: null, }, // 新增:param 配置(用于附件功能) param: { type: Object, default: null, }, // 新增:高度配置 height: { type: String, default: "", }, // 功能说明:传 height 时允许回车换行(多行输入);未传 height 默认单行 by xu 20260204 // 功能说明:onChange 全局回调 prop,桥接 API 赋值时自动触发 by xu 20260416 onchange: { type: String, required: false, }, }, emits: ["update:modelValue", "input", "blur", "change"], // 允许更新 v-model 绑定的值 setup(props, { emit }) { const errMsg = ref(""); const inputRef = ref(null); const textareaRef = ref(null); const inputValue = ref(props.modelValue || props.defaultValue || ""); const contentFloatingDiv = ref(false); // 控制浮动 DIV 的显示 const floatingDivPosition = ref("bottom"); // 'bottom' 或 'top' const isFocused = ref(false); // 跟踪焦点状态 // 附件相关变量(仅在传入 param 时初始化) let fjid = ref(null); let fjName = null; let mode = null; if (props.param && props.param.button) { fjid = ref(props.param.button.val); fjName = props.param.button.desc; mode = props.param.mode; } // 功能说明:只有存在非空校验(notNull)且值为空时,才显示红线 by xu 20260402 const hasNotNullRule = () => { const validations = window.ssVm?.validations?.get(props.name); if (!validations || validations.length === 0) return false; return validations.some(v => v.ruleName && v.ruleName.includes('notNull')); }; const showRequired = computed(() => { const validations = window.ssVm?.validations?.get(props.name); if (!validations || validations.length === 0) return false; // 检查是否存在 notNull 规则 const hasNotNull = validations.some(v => v.ruleName && v.ruleName.includes('notNull')); // 有非空规则且值为空时显示红线 if (hasNotNull && !inputValue.value) { return true; } return false; }); // 计算floatdiv应该向上还是向下展开 const calculateFloatingDivPosition = () => { nextTick(() => { const textarea = inputRef.value; if (!textarea) return; const rect = textarea.getBoundingClientRect(); /* 改,改用
estimatedFloatDivHeight ) { floatingDivPosition.value = "top"; } else { floatingDivPosition.value = "bottom"; } */ if (spaceAbove >= estimatedFloatDivHeight) { // "上方空间足够,向上展开,不限制高度"。Lin floatingDivPosition.value = "top"; } else if (spaceBelow >= estimatedFloatDivHeight) { // "下方空间足够,向下展开,不限制高度"。Lin floatingDivPosition.value = "bottom"; } else { // "上下空间都不足,选择空间大的方向,并限制高度出滚动条"。Lin let growhDivHeight; // 增加,减少后的高度。Lin if (spaceBelow >= spaceAbove) { floatingDivPosition.value = "bottom"; growhDivHeight = spaceBelow; // popupMaxHeight.value = Math.max(spaceBelow, minPopupHeight) + "px"。Lin } else { floatingDivPosition.value = "top"; growhDivHeight = spaceAbove; // popupMaxHeight.value = Math.max(spaceAbove, minPopupHeight) + "px"。Lin } /// 增加,写 增加的全局变量 --growh-textarea-max-height(带px)。Lin document.documentElement.style.setProperty('--growh-textarea-max-height', growhDivHeight +"px"); /// } }); }; // 计算floatdiv的top偏移量 const getFloatingDivTop = computed(() => { if (props.height) { // 有height时,padding是5px return "5px"; } else { // 没有height时是单行居中,需要计算居中位置 // 假设input-container高度是32px(或者从CSS读取),单行20px // 居中偏移 = (容器高度 - 行高) / 2 = (32 - 20) / 2 = 6px return "6px"; } }); const validate = () => { if (window.ssVm) { const result = window.ssVm.validateField(props.name); errMsg.value = result.valid ? "" : result.message; } }; // 功能说明:调用全局 onChange 回调 by xu 20260416 const callGlobalOnchg = (value) => { if (props.onchange && typeof props.onchange === "string") { if ( typeof window !== "undefined" && window[props.onchange] && typeof window[props.onchange] === "function" ) { try { window[props.onchange](value); } catch (error) { console.error(`调用全局函数 ${props.onchange} 时出错:`, error); } } } }; // 使用 watch 监听 props.errTip 和 props.modelValue 的变化 watch( () => props.errTip, (newVal) => { errMsg.value = newVal; }, { immediate: true } ); watch( () => props.modelValue, (newVal) => { inputValue.value = newVal; // 桥接 API 赋值时触发全局 onChange by xu 20260416 callGlobalOnchg(newVal); } ); // 挂载时的逻辑 onMounted(() => { errMsg.value = props.errTip; inputValue.value = props.modelValue || props.defaultValue || ""; }); // 计算并调整textarea的高度 const adjustHeight = () => { nextTick(() => { const textarea = textareaRef.value; if (!textarea) return; // floatDiv的textarea始终自动计算高度,不受props.height影响 // 重置高度以获得正确的scrollHeight textarea.style.height = "auto"; // 计算新高度 - 统一限制为5行 const lineHeight = parseInt( getComputedStyle(textarea).lineHeight, 10 ); const maxHeight = lineHeight * 5; // 统一为5行 /* 改,支持 { const textarea = inputRef.value; if (!textarea) return false; // 首先检查是否有内容,没有内容时不显示floatdiv by xu 20251212 if (!inputValue.value || inputValue.value.toString().trim() === "") { console.log("[floatdiv] 内容为空,不显示floatdiv"); return false; } // 判断内容是否超出 by xu 20251212 // 同时检查横向和纵向溢出,任一方向溢出都应显示floatdiv // 纵向溢出需要加容差值,避免padding/border导致的误判 by xu 20251212 const verticalTolerance = 5; // 容差值5px const isHorizontalOverflow = textarea.scrollWidth > textarea.clientWidth; const isVerticalOverflow = textarea.scrollHeight > textarea.clientHeight + verticalTolerance; const isOverflow = isHorizontalOverflow || isVerticalOverflow; console.log( "[floatdiv] 溢出检测 - scrollWidth:", textarea.scrollWidth, "clientWidth:", textarea.clientWidth, "horizontalOverflow:", isHorizontalOverflow ); console.log( "[floatdiv] 溢出检测 - scrollHeight:", textarea.scrollHeight, "clientHeight:", textarea.clientHeight, "tolerance:", verticalTolerance, "verticalOverflow:", isVerticalOverflow ); const shouldShow = isFocused.value && isOverflow; console.log( "[floatdiv] 最终判断 - isFocused:", isFocused.value, "isOverflow:", isOverflow, "shouldShow:", shouldShow ); // 需要同时满足:有焦点 + 内容超出 return shouldShow; }; // 定义事件处理函数 const onInput = (event) => { const newValue = event.target.value; inputValue.value = newValue; emit("update:modelValue", newValue); validate(); // 输入时验证 nextTick(() => { // 检查是否需要显示浮动div contentFloatingDiv.value = checkShouldShowFloatingDiv(); // 如果需要显示floatdiv,计算其位置 if (contentFloatingDiv.value) { calculateFloatingDivPosition(); } }); adjustHeight(); }; const onFocus = (event) => { // 设置焦点状态为true isFocused.value = true; adjustHeight(); // 检查是否应该显示浮动窗口 nextTick(() => { contentFloatingDiv.value = checkShouldShowFloatingDiv(); if (contentFloatingDiv.value) { calculateFloatingDivPosition(); } }); }; // 失去焦点时进行验证 const onBlur = (event) => { emit("blur", event.target); validate(); // 失焦时验证 nextTick(() => { // 如果焦点不在 textarea 上,则隐藏浮动 div if (!document.activeElement.classList.contains("input-control")) { isFocused.value = false; contentFloatingDiv.value = false; } }); }; const onChange = (event) => { inputValue.value = event.target.value || ""; emit("change", inputValue.value); }; const onMouseover = (event) => { nextTick(() => { // setTimeout(contentFloatingDiv.value = true, 500) }); }; const onMouseleave = (event) => { // contentFloatingDiv.value = false }; // 功能说明:传了 height 视为多行允许回车;未传 height 拦截回车(单行表现) by xu 20260204 const onKeydown = (event) => { const allowMultiline = typeof props.height === "string" && props.height.trim() !== ""; if (!allowMultiline && event.key === "Enter") { event.preventDefault(); } }; // 增加
{ if (!event.target.id) // 点击的是