@ibiz-template/core 0.0.1-alpha.37 → 0.0.1-alpha.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/system/index.system.js +1 -1
- package/out/constant/index.d.ts +1 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +1 -0
- package/out/constant/util/util.d.ts +5 -0
- package/out/constant/util/util.d.ts.map +1 -0
- package/out/constant/util/util.js +5 -0
- package/out/interface/click-outside/click-outside.d.ts +70 -0
- package/out/interface/click-outside/click-outside.d.ts.map +1 -0
- package/out/interface/click-outside/click-outside.js +1 -0
- package/out/interface/index.d.ts +1 -0
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/index.js +1 -1
- package/out/utils/click-outside/click-outside.d.ts +14 -0
- package/out/utils/click-outside/click-outside.d.ts.map +1 -0
- package/out/utils/click-outside/click-outside.js +85 -0
- package/out/utils/event/event.d.ts +34 -0
- package/out/utils/event/event.d.ts.map +1 -0
- package/out/utils/event/event.js +60 -0
- package/out/utils/index.d.ts +2 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +0 -2
- package/package.json +2 -2
- package/src/constant/index.ts +1 -0
- package/src/constant/util/util.ts +5 -0
- package/src/interface/click-outside/click-outside.ts +71 -0
- package/src/interface/index.ts +1 -0
- package/src/utils/click-outside/click-outside.ts +110 -0
- package/src/utils/event/event.ts +77 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
System.register(["lodash-es","qx-util","axios","qs","pluralize"],(function(e){"use strict";var t,n,o,r,i,s,c;return{setters:[function(e){t=e.debounce,n=e.merge},function(e){o=e.getCookie,r=e.notNilEmpty},function(e){i=e.default},function(e){s=e.stringify},function(e){c=e.default}],execute:function(){function a(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}e({debounceAndMerge:function(e,n,o,r){var i,s=t((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i=void 0,e.apply(void 0,b([],w(t),!1))}),o,r);return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var o=e;return i&&(o=n(i,o)),i=o,s.apply(void 0,b([],w(o),!1))}},getToken:m,install:function(){if(window.ibiz)throw new Error("ibiz 已经存在, 无需重复安装");window.ibiz=new A,window.___fc=new S,ibiz.net.addInterceptor("CoreInterceptor",new O)},isOverlap:function(e,t){return Array.from(new Set(b(b([],w(e),!1),w(t),!1))).length!==e.length+t.length},plural:j,pluralLower:function(e){return j(e).toLowerCase()}});var u,l,p=e("CoreConst",function(){function e(){}return e.DEFAULT_MODEL_SERVICE_TAG="default",e.TOKEN="access_token",e}()),f=e("HttpStatusMessageConst",{200:"服务器成功返回请求的数据。",201:"新建或修改数据成功。",202:"一个请求已经进入后台排队(异步任务)。",204:"删除数据成功。",400:"发出的请求有错误,服务器没有进行新建或修改数据的操作。",401:"用户没有权限(令牌、用户名、密码错误)。",403:"用户得到授权,但是访问是被禁止的。",404:"发出的请求针对的是不存在的记录,服务器没有进行操作。",406:"请求的格式不可得。",410:"请求的资源被永久删除,且不会再得到的。",422:"当创建一个对象时,发生一个验证错误。",500:"服务器发生错误,请检查服务器。",502:"网关错误。",503:"服务不可用,服务器暂时过载或维护。",504:"网关超时。"});e("LoginMode",u),function(e){e.DEFAULT="DEFAULT",e.CUSTOM="CUSTOM",e.CAS="CAS"}(u||e("LoginMode",u={})),e("MenuPermissionMode",l),function(e){e.MIXIN="MIXIN",e.RESOURCE="RESOURCE",e.RT="RT"}(l||e("MenuPermissionMode",l={}));e("IBizContext",(function(e,t){if(void 0===e&&(e={}),t){var n=this;Object.defineProperty(this,"_context",{enumerable:!1,value:{}});var o={};Object.keys(t).forEach((function(e){o[e]={enumerable:!0,set:function(t){n._context[e]=null==t?null:t},get:function(){return void 0!==n._context[e]?n._context[e]:t[e]}}})),Object.defineProperties(this,o)}Object.assign(this,e)}));var h=e("Environment",{dev:!1,logLevel:"ERROR",jsCdn:"https://cdn.jsdelivr.net",baseUrl:"",pluginBaseUrl:"./plugins",remoteModelUrl:"/remotemodel",assetsUrl:"./assets",dcSystem:"",ExportFile:"/ibizutil/download",UploadFile:"/ibizutil/upload",casLoginUrl:"",loginMode:u.DEFAULT,menuPermissionMode:l.MIXIN,enablePermission:!0}),d=e("HttpError",(function(e){this.name="HttpError";var t=e.response;this.response=e.response,t?(t.data?this.message=t.data.message:this.message=t.statusText,this.message||(this.message=f[t.status]),this.message||(this.message="网络异常,请稍后重试!"),this.status=t.status):(this.message=e.message,this.status=500)})),y=(e("RuntimeError",(function(e){this.message=e,this.name="Runtime Error"})),function(e,t){return y=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},y(e,t)});function v(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((o=o.apply(e,t||[])).next())}))}function g(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function w(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s}function b(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function m(){return o(p.TOKEN)}var R,E,T,C=e("Interceptor",function(){function e(){}return e.prototype.onBeforeRequest=function(e){return v(this,void 0,void 0,(function(){return g(this,(function(t){return[2,e]}))}))},e.prototype.onRequestError=function(e){return console.log(e),Promise.reject(e)},e.prototype.onResponseSuccess=function(e){return v(this,void 0,void 0,(function(){return g(this,(function(t){return[2,e]}))}))},e.prototype.onResponseError=function(e){return console.log(e),Promise.reject(e)},e.prototype.use=function(e){this.requestTag=e.interceptors.request.use(this.onBeforeRequest,this.onRequestError),this.responseTag=e.interceptors.response.use(this.onResponseSuccess,this.onResponseError)},e.prototype.eject=function(e){this.requestTag&&e.interceptors.request.eject(this.requestTag),this.responseTag&&e.interceptors.response.eject(this.responseTag)},e}()),O=e("CoreInterceptor",function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}y(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.prototype.onBeforeRequest=function(t){return v(this,void 0,void 0,(function(){var n;return g(this,(function(o){switch(o.label){case 0:return[4,e.prototype.onBeforeRequest.call(this,t)];case 1:return o.sent(),t.headers||(t.headers={}),t.headers.Authorization="Bearer ".concat(m()),(n=ibiz.orgData)&&(n.systemid&&(t.headers.srfsystemid=n.systemid),n.orgid&&(t.headers.srforgid=n.orgid)),[2,t]}}))}))},t}(C)),L="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},P={exports:{}};E=L,T=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function r(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?i:void 0!==console[o]?r(console,o):void 0!==console.log?r(console,"log"):e)}function c(t,n){for(var r=0;r<o.length;r++){var i=o[r];this[i]=r<t?e:this.methodFactory(i,t,n)}this.log=this.debug}function a(e,n,o){return function(){typeof console!==t&&(c.call(this,n,o),this[e].apply(this,arguments))}}function u(e,t,n){return s(e)||a.apply(this,arguments)}function l(e,n,r){var i,s=this;n=null==n?"WARN":n;var a="loglevel";function l(){var e;if(typeof window!==t&&a){try{e=window.localStorage[a]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,o=n.indexOf(encodeURIComponent(a)+"=");-1!==o&&(e=/^([^;]+)/.exec(n.slice(o))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?a+=":"+e:"symbol"==typeof e&&(a=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=r||u,s.getLevel=function(){return i},s.setLevel=function(n,r){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(i=n,!1!==r&&function(e){var n=(o[e]||"silent").toUpperCase();if(typeof window!==t&&a){try{return void(window.localStorage[a]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"="+n+";"}catch(e){}}}(n),c.call(s,n,e),typeof console===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){n=e,l()||s.setLevel(e,!1)},s.resetLevel=function(){s.setLevel(n,!1),function(){if(typeof window!==t&&a){try{return void window.localStorage.removeItem(a)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var p=l();null==p&&(p=n),s.setLevel(p,!1)}var p=new l,f={};p.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=f[e];return t||(t=f[e]=new l(e,p.getLevel(),p.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return p.noConflict=function(){return typeof window!==t&&window.log===p&&(window.log=h),p},p.getLoggers=function(){return f},p.default=p,p},(R=P).exports?R.exports=T():E.log=T();var U=a({__proto__:null,default:P.exports},[P.exports]);e("Logger",U);function k(e,t,n,o,r){var i="".concat(e,"-").concat(t);return n&&(i+="-".concat(n)),o&&(i+="__".concat(o)),r&&(i+="--".concat(r)),i}e("Namespace",function(){function e(e,t){this.block=e,this.namespace=t||"ibiz"}return e.prototype.b=function(e){return void 0===e&&(e=""),k(this.namespace,this.block,e,"","")},e.prototype.e=function(e){return e?k(this.namespace,this.block,"",e,""):""},e.prototype.m=function(e){return e?k(this.namespace,this.block,"","",e):""},e.prototype.be=function(e,t){return e&&t?k(this.namespace,this.block,e,t,""):""},e.prototype.em=function(e,t){return e&&t?k(this.namespace,this.block,"",e,t):""},e.prototype.bm=function(e,t){return e&&t?k(this.namespace,this.block,e,"",t):""},e.prototype.bem=function(e,t,n){return e&&t&&n?k(this.namespace,this.block,e,t,n):""},e.prototype.is=function(e,t){return e&&t?"".concat("is-").concat(e):""},e.prototype.cssVar=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarName(n)]=e[n]);return t},e.prototype.cssVarBlock=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarBlockName(n)]=e[n]);return t},e.prototype.cssVarName=function(e){return"--".concat(this.namespace,"-").concat(e)},e.prototype.cssVarBlockName=function(e){return"--".concat(this.namespace,"-").concat(this.block,"-").concat(e)},e}()),e("HttpResponse",(function(e,t,n){this.local=!0,this.ok=!1,this.headers={},this.config={},this.data=e,this.status=t||200,this.statusText=n||"",this.status>=200&&this.status<300&&(this.ok=!0)}));var x=e("Net",function(){function e(e){this.interceptors=new Map,this.instance=i.create(e)}return e.prototype.addInterceptor=function(e,t){t.use(this.instance),this.interceptors.set(e,t)},e.prototype.removeInterceptor=function(e){var t=this.interceptors.get(e);t&&(t.eject(this.instance),this.interceptors.delete(e))},Object.defineProperty(e.prototype,"presetConfig",{get:function(){return{baseURL:this.instance.defaults.baseURL||ibiz.env.baseUrl,headers:{"Content-Type":"application/json;charset=UTF-8",Accept:"application/json"}}},enumerable:!1,configurable:!0}),e.prototype.mergeConfig=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 0===e.length?this.presetConfig:n.apply(void 0,b([this.presetConfig],w(e),!1))},e.prototype.post=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),v(this,void 0,void 0,(function(){var r,i;return g(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"post",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new d(i);case 4:return[2]}}))}))},e.prototype.get=function(e,t,o,r){return void 0===t&&(t={}),void 0===o&&(o={}),void 0===r&&(r={}),v(this,void 0,void 0,(function(){var i,s;return g(this,(function(c){switch(c.label){case 0:e=this.attachUrlParam(e,t),c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.request(e,n({method:"get",headers:o},r))];case 2:return i=c.sent(),[2,this.doResponseResult(i)];case 3:throw s=c.sent(),new d(s);case 4:return[2]}}))}))},e.prototype.delete=function(e,t,n){return void 0===n&&(n={}),v(this,void 0,void 0,(function(){var o,r;return g(this,(function(i){switch(i.label){case 0:e=this.handleAppPresetParam(e,t),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.request(e,{method:"delete",headers:n})];case 2:return o=i.sent(),[2,this.doResponseResult(o)];case 3:throw r=i.sent(),new d(r);case 4:return[2]}}))}))},e.prototype.put=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),v(this,void 0,void 0,(function(){var r,i;return g(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"put",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new d(i);case 4:return[2]}}))}))},e.prototype.getModel=function(e,t){return void 0===t&&(t={}),v(this,void 0,void 0,(function(){var n,o;return g(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.get(e,{headers:t})];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new d(o);case 3:return[2]}}))}))},e.prototype.request=function(e,t){return void 0===t&&(t={}),v(this,void 0,void 0,(function(){var n,o;return g(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.request(this.mergeConfig({url:e},t))];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new d(o);case 3:return[2]}}))}))},e.prototype.doResponseResult=function(e){var t=e;return t.status>=200&&t.status<=299&&(t.ok=!0),t},e.prototype.handleAppPresetParam=function(e,t){if(t){var n=Object.keys(t),o={};return n.forEach((function(e){e.startsWith("srf")&&r(t[e])&&(o[e]=t[e])})),this.attachUrlParam(e,t)}return e},e.prototype.attachUrlParam=function(e,t){var n=s(t);return r(n)&&(e=e.endsWith("?")||-1!==e.indexOf("?")&&e.endsWith("&")?"".concat(e).concat(n):-1===e.indexOf("?")||e.endsWith("&")?"".concat(e,"?").concat(n):"".concat(e,"&").concat(n)),e},e}());function j(e){return c(e)}e("UrlHelper",function(){function e(){}return Object.defineProperty(e,"routeBase",{get:function(){return"".concat(this.appBase,"/#")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"appBase",{get:function(){var e=window.location,t=e.origin,n=e.pathname;return"".concat(t).concat(n).replace(/\/$/,"")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"routePath",{get:function(){return window.location.hash.replace("#","")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"fullPath",{get:function(){return window.location.href},enumerable:!1,configurable:!0}),e}());var A=e("IBizSys",(function(){this.env=h,this.log=U,this.net=new x})),S=e("FactoryCenter",(function(){}))}}}));
|
|
1
|
+
System.register(["lodash-es","qx-util","axios","qs","pluralize"],(function(e){"use strict";var t,n,o,r,i,s,c;return{setters:[function(e){t=e.debounce,n=e.merge},function(e){o=e.getCookie,r=e.notNilEmpty},function(e){i=e.default},function(e){s=e.stringify},function(e){c=e.default}],execute:function(){function a(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var o=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,o.get?o:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}e({debounceAndMerge:function(e,n,o,r){var i,s=t((function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return i=void 0,e.apply(void 0,R([],b(t),!1))}),o,r);return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var o=e;return i&&(o=n(i,o)),i=o,s.apply(void 0,R([],b(o),!1))}},eventPath:I,getToken:E,install:function(){if(window.ibiz)throw new Error("ibiz 已经存在, 无需重复安装");window.ibiz=new q,window.___fc=new B,ibiz.net.addInterceptor("CoreInterceptor",new L)},isEventInside:N,isOverlap:function(e,t){return Array.from(new Set(R(R([],b(e),!1),b(t),!1))).length!==e.length+t.length},listenJSEvent:_,onClickOutside:function(e,t,n){void 0===n&&(n={});var o=n.window,r=void 0===o?M:o,i=n.ignore,s=void 0===i?[]:i,c=n.capture,a=void 0===c||c;if(!e)throw new y("target元素不存在");if(!r)throw new y("找不到window");var u,l=!0,p=function(t){return!R([e],b(s),!1).some((function(e){return N(t,e)}))},f=!1,h=function(e){f||(r.clearTimeout(u),l&&p(e)&&t(e))},d=[_(r,"click",h,{passive:!0,capture:a}),_(r,"pointerdown",(function(e){f||(l=p(e))}),{passive:!0}),_(r,"pointerup",(function(e){if(!f&&0===e.button){var t=I(e);e.composedPath=function(){return t},u=r.setTimeout((function(){return h(e)}),50)}}),{passive:!0})].filter(Boolean);return{stop:function(){return d.forEach((function(e){return e()}))},pause:function(){f=!0},proceed:function(){f=!1}}},plural:A,pluralLower:function(e){return A(e).toLowerCase()}});var u,l,p=e("CoreConst",function(){function e(){}return e.DEFAULT_MODEL_SERVICE_TAG="default",e.TOKEN="access_token",e}()),f=e("NOOP",(function(){})),h=e("HttpStatusMessageConst",{200:"服务器成功返回请求的数据。",201:"新建或修改数据成功。",202:"一个请求已经进入后台排队(异步任务)。",204:"删除数据成功。",400:"发出的请求有错误,服务器没有进行新建或修改数据的操作。",401:"用户没有权限(令牌、用户名、密码错误)。",403:"用户得到授权,但是访问是被禁止的。",404:"发出的请求针对的是不存在的记录,服务器没有进行操作。",406:"请求的格式不可得。",410:"请求的资源被永久删除,且不会再得到的。",422:"当创建一个对象时,发生一个验证错误。",500:"服务器发生错误,请检查服务器。",502:"网关错误。",503:"服务不可用,服务器暂时过载或维护。",504:"网关超时。"});e("LoginMode",u),function(e){e.DEFAULT="DEFAULT",e.CUSTOM="CUSTOM",e.CAS="CAS"}(u||e("LoginMode",u={})),e("MenuPermissionMode",l),function(e){e.MIXIN="MIXIN",e.RESOURCE="RESOURCE",e.RT="RT"}(l||e("MenuPermissionMode",l={}));e("IBizContext",(function(e,t){if(void 0===e&&(e={}),t){var n=this;Object.defineProperty(this,"_context",{enumerable:!1,value:{}});var o={};Object.keys(t).forEach((function(e){o[e]={enumerable:!0,set:function(t){n._context[e]=null==t?null:t},get:function(){return void 0!==n._context[e]?n._context[e]:t[e]}}})),Object.defineProperties(this,o)}Object.assign(this,e)}));var d=e("Environment",{dev:!1,logLevel:"ERROR",jsCdn:"https://cdn.jsdelivr.net",baseUrl:"",pluginBaseUrl:"./plugins",remoteModelUrl:"/remotemodel",assetsUrl:"./assets",dcSystem:"",ExportFile:"/ibizutil/download",UploadFile:"/ibizutil/upload",casLoginUrl:"",loginMode:u.DEFAULT,menuPermissionMode:l.MIXIN,enablePermission:!0}),v=e("HttpError",(function(e){this.name="HttpError";var t=e.response;this.response=e.response,t?(t.data?this.message=t.data.message:this.message=t.statusText,this.message||(this.message=h[t.status]),this.message||(this.message="网络异常,请稍后重试!"),this.status=t.status):(this.message=e.message,this.status=500)})),y=e("RuntimeError",(function(e){this.message=e,this.name="Runtime Error"})),g=function(e,t){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},g(e,t)};function w(e,t,n,o){return new(n||(n=Promise))((function(r,i){function s(e){try{a(o.next(e))}catch(e){i(e)}}function c(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((o=o.apply(e,t||[])).next())}))}function m(e,t){var n,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],o=0}finally{n=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function b(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var o,r,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)s.push(o.value)}catch(e){r={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return s}function R(e,t,n){if(n||2===arguments.length)for(var o,r=0,i=t.length;r<i;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}function E(){return o(p.TOKEN)}var T,O,P,C=e("Interceptor",function(){function e(){}return e.prototype.onBeforeRequest=function(e){return w(this,void 0,void 0,(function(){return m(this,(function(t){return[2,e]}))}))},e.prototype.onRequestError=function(e){return Promise.reject(e)},e.prototype.onResponseSuccess=function(e){return w(this,void 0,void 0,(function(){return m(this,(function(t){return[2,e]}))}))},e.prototype.onResponseError=function(e){return Promise.reject(e)},e.prototype.use=function(e){this.requestTag=e.interceptors.request.use(this.onBeforeRequest,this.onRequestError),this.responseTag=e.interceptors.response.use(this.onResponseSuccess,this.onResponseError)},e.prototype.eject=function(e){this.requestTag&&e.interceptors.request.eject(this.requestTag),this.responseTag&&e.interceptors.response.eject(this.responseTag)},e}()),L=e("CoreInterceptor",function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}g(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t.prototype.onBeforeRequest=function(t){return w(this,void 0,void 0,(function(){var n;return m(this,(function(o){switch(o.label){case 0:return[4,e.prototype.onBeforeRequest.call(this,t)];case 1:return o.sent(),t.headers||(t.headers={}),t.headers.Authorization="Bearer ".concat(E()),(n=ibiz.orgData)&&(n.systemid&&(t.headers.srfsystemid=n.systemid),n.orgid&&(t.headers.srforgid=n.orgid)),[2,t]}}))}))},t}(C)),k="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},U={exports:{}};O=k,P=function(){var e=function(){},t="undefined",n=typeof window!==t&&typeof window.navigator!==t&&/Trident\/|MSIE /.test(window.navigator.userAgent),o=["trace","debug","info","warn","error"];function r(e,t){var n=e[t];if("function"==typeof n.bind)return n.bind(e);try{return Function.prototype.bind.call(n,e)}catch(t){return function(){return Function.prototype.apply.apply(n,[e,arguments])}}}function i(){console.log&&(console.log.apply?console.log.apply(console,arguments):Function.prototype.apply.apply(console.log,[console,arguments])),console.trace&&console.trace()}function s(o){return"debug"===o&&(o="log"),typeof console!==t&&("trace"===o&&n?i:void 0!==console[o]?r(console,o):void 0!==console.log?r(console,"log"):e)}function c(t,n){for(var r=0;r<o.length;r++){var i=o[r];this[i]=r<t?e:this.methodFactory(i,t,n)}this.log=this.debug}function a(e,n,o){return function(){typeof console!==t&&(c.call(this,n,o),this[e].apply(this,arguments))}}function u(e,t,n){return s(e)||a.apply(this,arguments)}function l(e,n,r){var i,s=this;n=null==n?"WARN":n;var a="loglevel";function l(){var e;if(typeof window!==t&&a){try{e=window.localStorage[a]}catch(e){}if(typeof e===t)try{var n=window.document.cookie,o=n.indexOf(encodeURIComponent(a)+"=");-1!==o&&(e=/^([^;]+)/.exec(n.slice(o))[1])}catch(e){}return void 0===s.levels[e]&&(e=void 0),e}}"string"==typeof e?a+=":"+e:"symbol"==typeof e&&(a=void 0),s.name=e,s.levels={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,SILENT:5},s.methodFactory=r||u,s.getLevel=function(){return i},s.setLevel=function(n,r){if("string"==typeof n&&void 0!==s.levels[n.toUpperCase()]&&(n=s.levels[n.toUpperCase()]),!("number"==typeof n&&n>=0&&n<=s.levels.SILENT))throw"log.setLevel() called with invalid level: "+n;if(i=n,!1!==r&&function(e){var n=(o[e]||"silent").toUpperCase();if(typeof window!==t&&a){try{return void(window.localStorage[a]=n)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"="+n+";"}catch(e){}}}(n),c.call(s,n,e),typeof console===t&&n<s.levels.SILENT)return"No console available for logging"},s.setDefaultLevel=function(e){n=e,l()||s.setLevel(e,!1)},s.resetLevel=function(){s.setLevel(n,!1),function(){if(typeof window!==t&&a){try{return void window.localStorage.removeItem(a)}catch(e){}try{window.document.cookie=encodeURIComponent(a)+"=; expires=Thu, 01 Jan 1970 00:00:00 UTC"}catch(e){}}}()},s.enableAll=function(e){s.setLevel(s.levels.TRACE,e)},s.disableAll=function(e){s.setLevel(s.levels.SILENT,e)};var p=l();null==p&&(p=n),s.setLevel(p,!1)}var p=new l,f={};p.getLogger=function(e){if("symbol"!=typeof e&&"string"!=typeof e||""===e)throw new TypeError("You must supply a name when creating a logger.");var t=f[e];return t||(t=f[e]=new l(e,p.getLevel(),p.methodFactory)),t};var h=typeof window!==t?window.log:void 0;return p.noConflict=function(){return typeof window!==t&&window.log===p&&(window.log=h),p},p.getLoggers=function(){return f},p.default=p,p},(T=U).exports?T.exports=P():O.log=P();var x=a({__proto__:null,default:U.exports},[U.exports]);e("Logger",x);function S(e,t,n,o,r){var i="".concat(e,"-").concat(t);return n&&(i+="-".concat(n)),o&&(i+="__".concat(o)),r&&(i+="--".concat(r)),i}e("Namespace",function(){function e(e,t){this.block=e,this.namespace=t||"ibiz"}return e.prototype.b=function(e){return void 0===e&&(e=""),S(this.namespace,this.block,e,"","")},e.prototype.e=function(e){return e?S(this.namespace,this.block,"",e,""):""},e.prototype.m=function(e){return e?S(this.namespace,this.block,"","",e):""},e.prototype.be=function(e,t){return e&&t?S(this.namespace,this.block,e,t,""):""},e.prototype.em=function(e,t){return e&&t?S(this.namespace,this.block,"",e,t):""},e.prototype.bm=function(e,t){return e&&t?S(this.namespace,this.block,e,"",t):""},e.prototype.bem=function(e,t,n){return e&&t&&n?S(this.namespace,this.block,e,t,n):""},e.prototype.is=function(e,t){return e&&t?"".concat("is-").concat(e):""},e.prototype.cssVar=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarName(n)]=e[n]);return t},e.prototype.cssVarBlock=function(e){var t={};for(var n in e)e[n]&&(t[this.cssVarBlockName(n)]=e[n]);return t},e.prototype.cssVarName=function(e){return"--".concat(this.namespace,"-").concat(e)},e.prototype.cssVarBlockName=function(e){return"--".concat(this.namespace,"-").concat(this.block,"-").concat(e)},e}()),e("HttpResponse",(function(e,t,n){this.local=!0,this.ok=!1,this.headers={},this.config={},this.data=e,this.status=t||200,this.statusText=n||"",this.status>=200&&this.status<300&&(this.ok=!0)}));var j=e("Net",function(){function e(e){this.interceptors=new Map,this.instance=i.create(e)}return e.prototype.addInterceptor=function(e,t){t.use(this.instance),this.interceptors.set(e,t)},e.prototype.removeInterceptor=function(e){var t=this.interceptors.get(e);t&&(t.eject(this.instance),this.interceptors.delete(e))},Object.defineProperty(e.prototype,"presetConfig",{get:function(){return{baseURL:this.instance.defaults.baseURL||ibiz.env.baseUrl,headers:{"Content-Type":"application/json;charset=UTF-8",Accept:"application/json"}}},enumerable:!1,configurable:!0}),e.prototype.mergeConfig=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 0===e.length?this.presetConfig:n.apply(void 0,R([this.presetConfig],b(e),!1))},e.prototype.post=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),w(this,void 0,void 0,(function(){var r,i;return m(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"post",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new v(i);case 4:return[2]}}))}))},e.prototype.get=function(e,t,o,r){return void 0===t&&(t={}),void 0===o&&(o={}),void 0===r&&(r={}),w(this,void 0,void 0,(function(){var i,s;return m(this,(function(c){switch(c.label){case 0:e=this.attachUrlParam(e,t),c.label=1;case 1:return c.trys.push([1,3,,4]),[4,this.request(e,n({method:"get",headers:o},r))];case 2:return i=c.sent(),[2,this.doResponseResult(i)];case 3:throw s=c.sent(),new v(s);case 4:return[2]}}))}))},e.prototype.delete=function(e,t,n){return void 0===n&&(n={}),w(this,void 0,void 0,(function(){var o,r;return m(this,(function(i){switch(i.label){case 0:e=this.handleAppPresetParam(e,t),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,this.request(e,{method:"delete",headers:n})];case 2:return o=i.sent(),[2,this.doResponseResult(o)];case 3:throw r=i.sent(),new v(r);case 4:return[2]}}))}))},e.prototype.put=function(e,t,n,o){return void 0===n&&(n={}),void 0===o&&(o={}),w(this,void 0,void 0,(function(){var r,i;return m(this,(function(s){switch(s.label){case 0:e=this.handleAppPresetParam(e,n),s.label=1;case 1:return s.trys.push([1,3,,4]),[4,this.request(e,{method:"put",data:t,headers:o})];case 2:return r=s.sent(),[2,this.doResponseResult(r)];case 3:throw i=s.sent(),new v(i);case 4:return[2]}}))}))},e.prototype.getModel=function(e,t){return void 0===t&&(t={}),w(this,void 0,void 0,(function(){var n,o;return m(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.get(e,{headers:t})];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new v(o);case 3:return[2]}}))}))},e.prototype.request=function(e,t){return void 0===t&&(t={}),w(this,void 0,void 0,(function(){var n,o;return m(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.instance.request(this.mergeConfig({url:e},t))];case 1:return n=r.sent(),[2,this.doResponseResult(n)];case 2:throw o=r.sent(),new v(o);case 3:return[2]}}))}))},e.prototype.doResponseResult=function(e){var t=e;return t.status>=200&&t.status<=299&&(t.ok=!0),t},e.prototype.handleAppPresetParam=function(e,t){if(t){var n=Object.keys(t),o={};return n.forEach((function(e){e.startsWith("srf")&&r(t[e])&&(o[e]=t[e])})),this.attachUrlParam(e,t)}return e},e.prototype.attachUrlParam=function(e,t){var n=s(t);return r(n)&&(e=e.endsWith("?")||-1!==e.indexOf("?")&&e.endsWith("&")?"".concat(e).concat(n):-1===e.indexOf("?")||e.endsWith("&")?"".concat(e,"?").concat(n):"".concat(e,"&").concat(n)),e},e}());function A(e){return c(e)}e("UrlHelper",function(){function e(){}return Object.defineProperty(e,"routeBase",{get:function(){return"".concat(this.appBase,"/#")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"appBase",{get:function(){var e=window.location,t=e.origin,n=e.pathname;return"".concat(t).concat(n).replace(/\/$/,"")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"routePath",{get:function(){return window.location.hash.replace("#","")},enumerable:!1,configurable:!0}),Object.defineProperty(e,"fullPath",{get:function(){return window.location.href},enumerable:!1,configurable:!0}),e}());function I(e){var t=e.composedPath&&e.composedPath()||e.path;if(null!=t)return t;return[e.target].concat(function e(t,n){void 0===n&&(n=[]);var o=t.parentNode;return o?e(o,n.concat([o])):n}(e.target))}function _(e,t,n,o){void 0===o&&(o={}),e.addEventListener(t,n,o);var r=function(){e.removeEventListener(t,n,o),r=f};return function(){r()}}function N(e,t){return t&&(e.target===t||I(e).includes(t))}var M="undefined"!=typeof window?window:void 0;var q=e("IBizSys",(function(){this.env=d,this.log=x,this.net=new j})),B=e("FactoryCenter",(function(){}))}}}));
|
package/out/constant/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CoreConst } from './core/core';
|
|
2
|
+
export * from './util/util';
|
|
2
3
|
export { HttpStatusMessageConst } from './http-status-message/http-status-message';
|
|
3
4
|
export { LoginMode } from './login-mode/login-mode';
|
|
4
5
|
export { MenuPermissionMode } from './menu-permission-mode/menu-permission-mode';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constant/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC"}
|
package/out/constant/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CoreConst } from './core/core';
|
|
2
|
+
export * from './util/util';
|
|
2
3
|
export { HttpStatusMessageConst } from './http-status-message/http-status-message';
|
|
3
4
|
export { LoginMode } from './login-mode/login-mode';
|
|
4
5
|
export { MenuPermissionMode } from './menu-permission-mode/menu-permission-mode';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/constant/util/util.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,eAAO,MAAM,IAAI,YAAW,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可选配置参数
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-28 16:10:48
|
|
6
|
+
* @export
|
|
7
|
+
* @interface OnClickOutsideOptions
|
|
8
|
+
* @extends {ConfigurableWindow}
|
|
9
|
+
* @template E
|
|
10
|
+
*/
|
|
11
|
+
export interface OnClickOutsideOptions {
|
|
12
|
+
/**
|
|
13
|
+
* 指定使用的window,不给就用默认的window
|
|
14
|
+
* 一般是在iframe或测试环境中使用。
|
|
15
|
+
*
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-28 17:10:49
|
|
18
|
+
* @type {Window}
|
|
19
|
+
*/
|
|
20
|
+
window?: Window;
|
|
21
|
+
/**
|
|
22
|
+
* 指定需要忽略的元素,用于排除某些外部的元素
|
|
23
|
+
*
|
|
24
|
+
* @author lxm
|
|
25
|
+
* @date 2022-10-28 17:10:50
|
|
26
|
+
* @type {HTMLElement[]}
|
|
27
|
+
*/
|
|
28
|
+
ignore?: HTMLElement[];
|
|
29
|
+
/**
|
|
30
|
+
* 是否捕获内部元素。默认为是,内部元素不会触发回调。
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
capture?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 回调处理函数类型
|
|
37
|
+
*/
|
|
38
|
+
export declare type OnClickOutsideHandler = (_evt: PointerEvent | MouseEvent) => void;
|
|
39
|
+
/**
|
|
40
|
+
* OnClickOutside返回对象类型
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-10-31 11:10:59
|
|
44
|
+
* @export
|
|
45
|
+
* @interface OnClickOutsideResult
|
|
46
|
+
*/
|
|
47
|
+
export interface OnClickOutsideResult {
|
|
48
|
+
/**
|
|
49
|
+
* 停止监听,并移除相关监听事件
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-31 11:10:28
|
|
53
|
+
*/
|
|
54
|
+
stop: () => void;
|
|
55
|
+
/**
|
|
56
|
+
* 暂停监听
|
|
57
|
+
*
|
|
58
|
+
* @author lxm
|
|
59
|
+
* @date 2022-10-31 11:10:30
|
|
60
|
+
*/
|
|
61
|
+
pause: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* 继续监听
|
|
64
|
+
*
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2022-10-31 11:10:32
|
|
67
|
+
*/
|
|
68
|
+
proceed: () => void;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=click-outside.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"click-outside.d.ts","sourceRoot":"","sources":["../../../src/interface/click-outside/click-outside.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,oBAAY,qBAAqB,GAAG,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,KAAK,IAAI,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/out/interface/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,cAAc,+BAA+B,CAAC"}
|
package/out/interface/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './click-outside/click-outside';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OnClickOutsideHandler, OnClickOutsideOptions, OnClickOutsideResult } from '../../interface';
|
|
2
|
+
/**
|
|
3
|
+
* 监听目标元素之外的点击事件回调
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2022-10-28 18:10:25
|
|
7
|
+
* @export
|
|
8
|
+
* @param {HTMLElement} target 目标元素
|
|
9
|
+
* @param {OnClickOutsideHandler} handler 触发的时间回调
|
|
10
|
+
* @param {OnClickOutsideOptions} [options={}] 额外配置参数
|
|
11
|
+
* @returns {*} {OnClickOutsideResult}
|
|
12
|
+
*/
|
|
13
|
+
export declare function onClickOutside(target: HTMLElement, handler: OnClickOutsideHandler, options?: OnClickOutsideOptions): OnClickOutsideResult;
|
|
14
|
+
//# sourceMappingURL=click-outside.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"click-outside.d.ts","sourceRoot":"","sources":["../../../src/utils/click-outside/click-outside.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAKzB;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CAoFtB"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { RuntimeError } from '../../error';
|
|
2
|
+
import { eventPath, isEventInside, listenJSEvent } from '../event/event';
|
|
3
|
+
const defaultWindow = typeof window !== 'undefined' ? window : undefined;
|
|
4
|
+
/**
|
|
5
|
+
* 监听目标元素之外的点击事件回调
|
|
6
|
+
*
|
|
7
|
+
* @author lxm
|
|
8
|
+
* @date 2022-10-28 18:10:25
|
|
9
|
+
* @export
|
|
10
|
+
* @param {HTMLElement} target 目标元素
|
|
11
|
+
* @param {OnClickOutsideHandler} handler 触发的时间回调
|
|
12
|
+
* @param {OnClickOutsideOptions} [options={}] 额外配置参数
|
|
13
|
+
* @returns {*} {OnClickOutsideResult}
|
|
14
|
+
*/
|
|
15
|
+
export function onClickOutside(target, handler, options = {}) {
|
|
16
|
+
const { window = defaultWindow, ignore = [], capture = true } = options;
|
|
17
|
+
if (!target)
|
|
18
|
+
throw new RuntimeError('target元素不存在');
|
|
19
|
+
if (!window)
|
|
20
|
+
throw new RuntimeError('找不到window');
|
|
21
|
+
/** 是否需要监听,为false时handler不会执行 */
|
|
22
|
+
let shouldListen = true;
|
|
23
|
+
/**
|
|
24
|
+
* 判断event的触发是否是在元素的外部(排除了ignore元素)
|
|
25
|
+
* @param event 事件对象
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
const isOutside = (event) => {
|
|
29
|
+
// 有一个判断是在内部,则不算外部,返回false
|
|
30
|
+
return ![target, ...ignore].some(el => {
|
|
31
|
+
return isEventInside(event, el);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
/** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
|
|
35
|
+
let isPaused = false;
|
|
36
|
+
const pause = () => {
|
|
37
|
+
isPaused = true;
|
|
38
|
+
};
|
|
39
|
+
const proceed = () => {
|
|
40
|
+
isPaused = false;
|
|
41
|
+
};
|
|
42
|
+
/** pointerup延时触发标识 */
|
|
43
|
+
let fallback;
|
|
44
|
+
/**
|
|
45
|
+
* 事件监听处理回调
|
|
46
|
+
* @param event 事件对象
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
const listener = (event) => {
|
|
50
|
+
if (isPaused)
|
|
51
|
+
return;
|
|
52
|
+
window.clearTimeout(fallback);
|
|
53
|
+
// 当需要监听并且最终触发在外部时才需要执行回调
|
|
54
|
+
if (!(shouldListen && isOutside(event)))
|
|
55
|
+
return;
|
|
56
|
+
handler(event);
|
|
57
|
+
};
|
|
58
|
+
// 鼠标左键单击先后触发pointerdown,pointerup,click
|
|
59
|
+
// 鼠标右键单击先后触发pointerdown,pointerup
|
|
60
|
+
const cleanups = [
|
|
61
|
+
listenJSEvent(window, 'click', listener, { passive: true, capture }),
|
|
62
|
+
listenJSEvent(window, 'pointerdown', e => {
|
|
63
|
+
if (isPaused)
|
|
64
|
+
return;
|
|
65
|
+
// 当pointerdown是在内部触发则不需要后续监听
|
|
66
|
+
shouldListen = isOutside(e);
|
|
67
|
+
}, { passive: true }),
|
|
68
|
+
listenJSEvent(window, 'pointerup', e => {
|
|
69
|
+
if (isPaused)
|
|
70
|
+
return;
|
|
71
|
+
// 鼠标左键触发才执行
|
|
72
|
+
if (e.button === 0) {
|
|
73
|
+
// 锁死结果避免延时执行时变更
|
|
74
|
+
const path = eventPath(e);
|
|
75
|
+
e.composedPath = () => path;
|
|
76
|
+
fallback = window.setTimeout(() => listener(e), 50);
|
|
77
|
+
}
|
|
78
|
+
}, { passive: true }),
|
|
79
|
+
].filter(Boolean);
|
|
80
|
+
/**
|
|
81
|
+
* 停止事件监听,移除监听
|
|
82
|
+
*/
|
|
83
|
+
const stop = () => cleanups.forEach(fn => fn());
|
|
84
|
+
return { stop, pause, proceed };
|
|
85
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-28 17:10:14
|
|
6
|
+
* @param {MouseEvent} event
|
|
7
|
+
* @returns {*}
|
|
8
|
+
*/
|
|
9
|
+
export declare function eventPath(event: MouseEvent): (EventTarget | null)[];
|
|
10
|
+
/**
|
|
11
|
+
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
12
|
+
*
|
|
13
|
+
* @author lxm
|
|
14
|
+
* @date 2022-10-28 18:10:36
|
|
15
|
+
* @export
|
|
16
|
+
* @param {EventTarget} target 监听对象
|
|
17
|
+
* @param {string} eventName 监听事件名称
|
|
18
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
19
|
+
* @param {AddEventListenerOptions} options 额外参数
|
|
20
|
+
* @returns {*} {() => void}
|
|
21
|
+
*/
|
|
22
|
+
export declare function listenJSEvent(target: EventTarget, eventName: string, listener: (..._args: any[]) => any, options?: AddEventListenerOptions): () => void;
|
|
23
|
+
/**
|
|
24
|
+
* event是否是在目标元素内部触发的
|
|
25
|
+
*
|
|
26
|
+
* @author lxm
|
|
27
|
+
* @date 2022-10-31 11:10:49
|
|
28
|
+
* @export
|
|
29
|
+
* @param {MouseEvent} event 原生事件
|
|
30
|
+
* @param {HTMLElement} el 目标元素
|
|
31
|
+
* @returns {*} {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export declare function isEventInside(event: MouseEvent, el: HTMLElement): boolean;
|
|
34
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/utils/event/event.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAmBnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,OAAO,GAAE,uBAA4B,GACpC,MAAM,IAAI,CAYZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAEzE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { NOOP } from '../../constant';
|
|
3
|
+
/**
|
|
4
|
+
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-28 17:10:14
|
|
8
|
+
* @param {MouseEvent} event
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
export function eventPath(event) {
|
|
12
|
+
const path = ((event.composedPath && event.composedPath()) ||
|
|
13
|
+
event.path);
|
|
14
|
+
if (path != null)
|
|
15
|
+
return path;
|
|
16
|
+
// 浏览器没有提供的,自己递归计算
|
|
17
|
+
function getParents(node, memo = []) {
|
|
18
|
+
const parentNode = node.parentNode;
|
|
19
|
+
return parentNode
|
|
20
|
+
? getParents(parentNode, memo.concat([parentNode]))
|
|
21
|
+
: memo;
|
|
22
|
+
}
|
|
23
|
+
return [event.target].concat(getParents(event.target));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
27
|
+
*
|
|
28
|
+
* @author lxm
|
|
29
|
+
* @date 2022-10-28 18:10:36
|
|
30
|
+
* @export
|
|
31
|
+
* @param {EventTarget} target 监听对象
|
|
32
|
+
* @param {string} eventName 监听事件名称
|
|
33
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
34
|
+
* @param {AddEventListenerOptions} options 额外参数
|
|
35
|
+
* @returns {*} {() => void}
|
|
36
|
+
*/
|
|
37
|
+
export function listenJSEvent(target, eventName, listener, options = {}) {
|
|
38
|
+
target.addEventListener(eventName, listener, options);
|
|
39
|
+
let cleanup = () => {
|
|
40
|
+
target.removeEventListener(eventName, listener, options);
|
|
41
|
+
// cleanup方法只能调用一次
|
|
42
|
+
cleanup = NOOP;
|
|
43
|
+
};
|
|
44
|
+
return () => {
|
|
45
|
+
cleanup();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* event是否是在目标元素内部触发的
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-31 11:10:49
|
|
53
|
+
* @export
|
|
54
|
+
* @param {MouseEvent} event 原生事件
|
|
55
|
+
* @param {HTMLElement} el 目标元素
|
|
56
|
+
* @returns {*} {boolean}
|
|
57
|
+
*/
|
|
58
|
+
export function isEventInside(event, el) {
|
|
59
|
+
return el && (event.target === el || eventPath(event).includes(el));
|
|
60
|
+
}
|
package/out/utils/index.d.ts
CHANGED
|
@@ -6,4 +6,6 @@ export { Net } from './net/net';
|
|
|
6
6
|
export { plural, pluralLower } from './plural/plural';
|
|
7
7
|
export * from './util/util';
|
|
8
8
|
export * from './url-helper/url-helper';
|
|
9
|
+
export * from './event/event';
|
|
10
|
+
export * from './click-outside/click-outside';
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
package/out/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC"}
|
package/out/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;cACa,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAI9B;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;cACa,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAI9B;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG;IAKnC;;;;;;;;OAQG;cACa,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG;IAKpC;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAWlC;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,EAAE,aAAa;CAQ9B"}
|
|
@@ -29,7 +29,6 @@ export class Interceptor {
|
|
|
29
29
|
*/
|
|
30
30
|
onRequestError(error) {
|
|
31
31
|
// 处理请求错误
|
|
32
|
-
console.log(error);
|
|
33
32
|
return Promise.reject(error);
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
@@ -54,7 +53,6 @@ export class Interceptor {
|
|
|
54
53
|
*/
|
|
55
54
|
onResponseError(error) {
|
|
56
55
|
// 处理响应错误
|
|
57
|
-
console.log(error);
|
|
58
56
|
return Promise.reject(error);
|
|
59
57
|
}
|
|
60
58
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiz-template/core",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.39",
|
|
4
4
|
"description": "核心包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/index.js",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"lodash-es": "^4.17.21",
|
|
45
45
|
"qx-util": "^0.4.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "0c3339c9aa6fd4e59d180bb7b804dbbc8240e3ae"
|
|
48
48
|
}
|
package/src/constant/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { CoreConst } from './core/core';
|
|
2
|
+
export * from './util/util';
|
|
2
3
|
export { HttpStatusMessageConst } from './http-status-message/http-status-message';
|
|
3
4
|
export { LoginMode } from './login-mode/login-mode';
|
|
4
5
|
export { MenuPermissionMode } from './menu-permission-mode/menu-permission-mode';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可选配置参数
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-28 16:10:48
|
|
6
|
+
* @export
|
|
7
|
+
* @interface OnClickOutsideOptions
|
|
8
|
+
* @extends {ConfigurableWindow}
|
|
9
|
+
* @template E
|
|
10
|
+
*/
|
|
11
|
+
export interface OnClickOutsideOptions {
|
|
12
|
+
/**
|
|
13
|
+
* 指定使用的window,不给就用默认的window
|
|
14
|
+
* 一般是在iframe或测试环境中使用。
|
|
15
|
+
*
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-28 17:10:49
|
|
18
|
+
* @type {Window}
|
|
19
|
+
*/
|
|
20
|
+
window?: Window;
|
|
21
|
+
/**
|
|
22
|
+
* 指定需要忽略的元素,用于排除某些外部的元素
|
|
23
|
+
*
|
|
24
|
+
* @author lxm
|
|
25
|
+
* @date 2022-10-28 17:10:50
|
|
26
|
+
* @type {HTMLElement[]}
|
|
27
|
+
*/
|
|
28
|
+
ignore?: HTMLElement[];
|
|
29
|
+
/**
|
|
30
|
+
* 是否捕获内部元素。默认为是,内部元素不会触发回调。
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
capture?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 回调处理函数类型
|
|
38
|
+
*/
|
|
39
|
+
export type OnClickOutsideHandler = (_evt: PointerEvent | MouseEvent) => void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* OnClickOutside返回对象类型
|
|
43
|
+
*
|
|
44
|
+
* @author lxm
|
|
45
|
+
* @date 2022-10-31 11:10:59
|
|
46
|
+
* @export
|
|
47
|
+
* @interface OnClickOutsideResult
|
|
48
|
+
*/
|
|
49
|
+
export interface OnClickOutsideResult {
|
|
50
|
+
/**
|
|
51
|
+
* 停止监听,并移除相关监听事件
|
|
52
|
+
*
|
|
53
|
+
* @author lxm
|
|
54
|
+
* @date 2022-10-31 11:10:28
|
|
55
|
+
*/
|
|
56
|
+
stop: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* 暂停监听
|
|
59
|
+
*
|
|
60
|
+
* @author lxm
|
|
61
|
+
* @date 2022-10-31 11:10:30
|
|
62
|
+
*/
|
|
63
|
+
pause: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* 继续监听
|
|
66
|
+
*
|
|
67
|
+
* @author lxm
|
|
68
|
+
* @date 2022-10-31 11:10:32
|
|
69
|
+
*/
|
|
70
|
+
proceed: () => void;
|
|
71
|
+
}
|
package/src/interface/index.ts
CHANGED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { RuntimeError } from '../../error';
|
|
2
|
+
import {
|
|
3
|
+
OnClickOutsideHandler,
|
|
4
|
+
OnClickOutsideOptions,
|
|
5
|
+
OnClickOutsideResult,
|
|
6
|
+
} from '../../interface';
|
|
7
|
+
import { eventPath, isEventInside, listenJSEvent } from '../event/event';
|
|
8
|
+
|
|
9
|
+
const defaultWindow = typeof window !== 'undefined' ? window : undefined;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 监听目标元素之外的点击事件回调
|
|
13
|
+
*
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2022-10-28 18:10:25
|
|
16
|
+
* @export
|
|
17
|
+
* @param {HTMLElement} target 目标元素
|
|
18
|
+
* @param {OnClickOutsideHandler} handler 触发的时间回调
|
|
19
|
+
* @param {OnClickOutsideOptions} [options={}] 额外配置参数
|
|
20
|
+
* @returns {*} {OnClickOutsideResult}
|
|
21
|
+
*/
|
|
22
|
+
export function onClickOutside(
|
|
23
|
+
target: HTMLElement,
|
|
24
|
+
handler: OnClickOutsideHandler,
|
|
25
|
+
options: OnClickOutsideOptions = {},
|
|
26
|
+
): OnClickOutsideResult {
|
|
27
|
+
const { window = defaultWindow, ignore = [], capture = true } = options;
|
|
28
|
+
|
|
29
|
+
if (!target) throw new RuntimeError('target元素不存在');
|
|
30
|
+
if (!window) throw new RuntimeError('找不到window');
|
|
31
|
+
|
|
32
|
+
/** 是否需要监听,为false时handler不会执行 */
|
|
33
|
+
let shouldListen = true;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 判断event的触发是否是在元素的外部(排除了ignore元素)
|
|
37
|
+
* @param event 事件对象
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
const isOutside = (event: MouseEvent) => {
|
|
41
|
+
// 有一个判断是在内部,则不算外部,返回false
|
|
42
|
+
return ![target, ...ignore].some(el => {
|
|
43
|
+
return isEventInside(event, el);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
|
|
48
|
+
let isPaused = false;
|
|
49
|
+
const pause = () => {
|
|
50
|
+
isPaused = true;
|
|
51
|
+
};
|
|
52
|
+
const proceed = () => {
|
|
53
|
+
isPaused = false;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** pointerup延时触发标识 */
|
|
57
|
+
let fallback: number;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 事件监听处理回调
|
|
61
|
+
* @param event 事件对象
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
const listener = (event: MouseEvent) => {
|
|
65
|
+
if (isPaused) return;
|
|
66
|
+
window.clearTimeout(fallback);
|
|
67
|
+
|
|
68
|
+
// 当需要监听并且最终触发在外部时才需要执行回调
|
|
69
|
+
if (!(shouldListen && isOutside(event))) return;
|
|
70
|
+
|
|
71
|
+
handler(event);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// 鼠标左键单击先后触发pointerdown,pointerup,click
|
|
75
|
+
// 鼠标右键单击先后触发pointerdown,pointerup
|
|
76
|
+
const cleanups = [
|
|
77
|
+
listenJSEvent(window, 'click', listener, { passive: true, capture }),
|
|
78
|
+
listenJSEvent(
|
|
79
|
+
window,
|
|
80
|
+
'pointerdown',
|
|
81
|
+
e => {
|
|
82
|
+
if (isPaused) return;
|
|
83
|
+
// 当pointerdown是在内部触发则不需要后续监听
|
|
84
|
+
shouldListen = isOutside(e);
|
|
85
|
+
},
|
|
86
|
+
{ passive: true },
|
|
87
|
+
),
|
|
88
|
+
listenJSEvent(
|
|
89
|
+
window,
|
|
90
|
+
'pointerup',
|
|
91
|
+
e => {
|
|
92
|
+
if (isPaused) return;
|
|
93
|
+
// 鼠标左键触发才执行
|
|
94
|
+
if (e.button === 0) {
|
|
95
|
+
// 锁死结果避免延时执行时变更
|
|
96
|
+
const path = eventPath(e);
|
|
97
|
+
e.composedPath = () => path;
|
|
98
|
+
fallback = window.setTimeout(() => listener(e), 50);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{ passive: true },
|
|
102
|
+
),
|
|
103
|
+
].filter(Boolean);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 停止事件监听,移除监听
|
|
107
|
+
*/
|
|
108
|
+
const stop = () => cleanups.forEach(fn => fn());
|
|
109
|
+
return { stop, pause, proceed };
|
|
110
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import { NOOP } from '../../constant';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
7
|
+
*
|
|
8
|
+
* @author lxm
|
|
9
|
+
* @date 2022-10-28 17:10:14
|
|
10
|
+
* @param {MouseEvent} event
|
|
11
|
+
* @returns {*}
|
|
12
|
+
*/
|
|
13
|
+
export function eventPath(event: MouseEvent): (EventTarget | null)[] {
|
|
14
|
+
const path = ((event.composedPath && event.composedPath()) ||
|
|
15
|
+
(event as any).path) as HTMLElement[] | undefined;
|
|
16
|
+
|
|
17
|
+
if (path != null) return path;
|
|
18
|
+
|
|
19
|
+
// 浏览器没有提供的,自己递归计算
|
|
20
|
+
function getParents(
|
|
21
|
+
node: HTMLElement,
|
|
22
|
+
memo: HTMLElement[] = [],
|
|
23
|
+
): HTMLElement[] {
|
|
24
|
+
const parentNode = node.parentNode as HTMLElement | null;
|
|
25
|
+
|
|
26
|
+
return parentNode
|
|
27
|
+
? getParents(parentNode, memo.concat([parentNode]))
|
|
28
|
+
: memo;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return [event.target].concat(getParents(event.target as HTMLElement));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
36
|
+
*
|
|
37
|
+
* @author lxm
|
|
38
|
+
* @date 2022-10-28 18:10:36
|
|
39
|
+
* @export
|
|
40
|
+
* @param {EventTarget} target 监听对象
|
|
41
|
+
* @param {string} eventName 监听事件名称
|
|
42
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
43
|
+
* @param {AddEventListenerOptions} options 额外参数
|
|
44
|
+
* @returns {*} {() => void}
|
|
45
|
+
*/
|
|
46
|
+
export function listenJSEvent(
|
|
47
|
+
target: EventTarget,
|
|
48
|
+
eventName: string,
|
|
49
|
+
listener: (..._args: any[]) => any,
|
|
50
|
+
options: AddEventListenerOptions = {},
|
|
51
|
+
): () => void {
|
|
52
|
+
target.addEventListener(eventName, listener, options);
|
|
53
|
+
|
|
54
|
+
let cleanup = () => {
|
|
55
|
+
target.removeEventListener(eventName, listener, options);
|
|
56
|
+
// cleanup方法只能调用一次
|
|
57
|
+
cleanup = NOOP;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return () => {
|
|
61
|
+
cleanup();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* event是否是在目标元素内部触发的
|
|
67
|
+
*
|
|
68
|
+
* @author lxm
|
|
69
|
+
* @date 2022-10-31 11:10:49
|
|
70
|
+
* @export
|
|
71
|
+
* @param {MouseEvent} event 原生事件
|
|
72
|
+
* @param {HTMLElement} el 目标元素
|
|
73
|
+
* @returns {*} {boolean}
|
|
74
|
+
*/
|
|
75
|
+
export function isEventInside(event: MouseEvent, el: HTMLElement): boolean {
|
|
76
|
+
return el && (event.target === el || eventPath(event).includes(el));
|
|
77
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -55,7 +55,6 @@ export class Interceptor {
|
|
|
55
55
|
*/
|
|
56
56
|
protected onRequestError(error: any) {
|
|
57
57
|
// 处理请求错误
|
|
58
|
-
console.log(error);
|
|
59
58
|
return Promise.reject(error);
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -84,7 +83,6 @@ export class Interceptor {
|
|
|
84
83
|
*/
|
|
85
84
|
protected onResponseError(error: any) {
|
|
86
85
|
// 处理响应错误
|
|
87
|
-
console.log(error);
|
|
88
86
|
return Promise.reject(error);
|
|
89
87
|
}
|
|
90
88
|
|