@z-utils/react
Version:
zzy 工具库/react
2 lines (1 loc) • 2.4 kB
JavaScript
;var e=require("@babel/runtime/helpers/classCallCheck"),r=require("@babel/runtime/helpers/createClass"),t=require("@babel/runtime/helpers/inherits"),n=require("@babel/runtime/helpers/possibleConstructorReturn"),o=require("@babel/runtime/helpers/getPrototypeOf"),i=require("react/jsx-runtime"),l=require("react");function c(e){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var t,i=o(e);if(r){var l=o(this).constructor;t=Reflect.construct(i,arguments,l)}else t=i.apply(this,arguments);return n(this,t)}}var s={"font-size":"2.5rem",color:"red",margin:"1rem","word-break":"break-word"},u=function(n){t(l,n);var o=c(l);function l(r){var t;return e(this,l),(t=o.call(this,r)).state={hasError:!1},t}return r(l,[{key:"componentDidCatch",value:function(e,r){console.log(e,r,"将报错上传至服务器"),console.log("JSON化错误日志:error--------",JSON.stringify(e),"errorInfo---------",JSON.stringify(e))}},{key:"render",value:function(){return this.state.hasError?i.jsxs("div",{style:s,className:"errorBoundary-component_zzyDevtools",children:["Something was wrong, please open the console to check the printing, or contact the Developer.",i.jsx("br",{}),"development"===this.props.mode&&i.jsxs("div",{onClick:function(){return a(window.location.href||"none")},children:[i.jsx("br",{}),i.jsxs("span",{children:["link: ",window.location.href||"none"]}),i.jsx("br",{}),i.jsx("br",{}),"点击链接进行复制."]})]}):this.props.children}}],[{key:"getDerivedStateFromError",value:function(e){return console.error(e,"更新state 使下一次的UI是降级后的UI"),{hasError:!0}}}]),l}(l.Component),a=function(e){var r,t,n=document.createElement("textarea");n.value=e,n.setAttribute("readonly",""),n.style.position="absolute",n.style.left="-9999px",document.body.appendChild(n);var o,i,l=(null===(r=document.getSelection())||void 0===r?void 0:r.rangeCount)>0&&(null===(t=document.getSelection())||void 0===t?void 0:t.getRangeAt(0));(n.select(),document.execCommand("copy"),document.body.removeChild(n),l)&&(null===(o=document.getSelection())||void 0===o||o.removeAllRanges(),null===(i=document.getSelection())||void 0===i||i.addRange(l))};module.exports=u;