ebu_ecology_dev1/javascript/youhong.ai/yihong/index.js

75 lines
2.8 KiB
JavaScript
Raw Permalink Normal View History

2023-04-14 10:16:48 +08:00
/* ******************* 按钮变灰 ******************* */
$(() => {
const disabledRightButton = function (...indexIds) {
indexIds.forEach(index => {
let buttons = $(".ant-menu-item.text-elli[ecid='_Route@9uoqid_Com@knmejd_WeaRightMenu@spqptt_Item@eu37n0_li@zyccqn']")
let nodeArr = []
for (let i = 0; i < buttons.length; i++) {
let item = buttons[i]
nodeArr.push(findReact(item))
}
let disableArr = []
for (let i = 0; i < nodeArr.length; i++) {
let node = nodeArr[i]
if (index === i) {
node.props.disabled = true
node.setState({})
disableArr.push(node)
}
}
for (let i = 0; i < nodeArr.length; i++) {
let node = nodeArr[i]
let onMouseOver = node.onMouseOver
let onMouseLeave = node.onMouseLeave
node.onMouseOver = (...args) => {
disableArr.forEach(item => {
item.props.disabled = true
item.setState({})
})
onMouseOver(...args)
}
node.onMouseLeave = (...args) => {
disableArr.forEach(item => {
item.props.disabled = true
item.setState({})
})
onMouseLeave(...args)
}
}
})
}
const findReact = function (dom, traverseUp = 0) {
const key = Object.keys(dom).find(key => {
return key.startsWith("__reactFiber$") // react 17+
|| key.startsWith("__reactInternalInstance$")
|| key.startsWith("__reactEventHandlers$"); // react <17
});
const domFiber = dom[key];
if (domFiber == null) return null;
// react <16
if (domFiber._currentElement) {
let compFiber = domFiber._currentElement._owner;
for (let i = 0; i < traverseUp; i++) {
compFiber = compFiber._currentElement._owner;
}
return compFiber._instance;
}
// react 16+
const GetCompFiber = fiber => {
let parentFiber = fiber.return;
while (typeof parentFiber.type == "string") {
parentFiber = parentFiber.return;
}
return parentFiber;
};
let compFiber = GetCompFiber(domFiber);
for (let i = 0; i < traverseUp; i++) {
compFiber = GetCompFiber(compFiber);
}
return compFiber.stateNode;
}
window.disabledRightButton = disabledRightButton
})
/* ******************* 按钮变灰 ******************* */