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