jiuyiUniapp/shop/utils/gio-minp/index.js

2 lines
44 KiB
JavaScript
Raw Normal View History

2024-12-18 15:46:27 +08:00
const Utils={devVer:1,guid:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){let e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},getScreenHeight:function(t){return t.pixelRatio?Math.round(t.screenHeight*t.pixelRatio):t.screenHeight},getScreenWidth:function(t){return t.pixelRatio?Math.round(t.screenWidth*t.pixelRatio):t.screenWidth},getOS:function(t){if(t){let e=t.toLowerCase();return-1!=e.indexOf("android")?`${gioGlobal.platformConfig.name}-Android`:-1!=e.indexOf("ios")?`${gioGlobal.platformConfig.name}-iOS`:t}},getOSV:t=>`${gioGlobal.platformConfig.name} ${t}`,isEmpty:t=>{for(let e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0},compareVersion(t,e){t=t.split("."),e=e.split(".");const i=Math.max(t.length,e.length);for(;i>t.length;)t.push("0");for(;i>e.length;)e.push("0");for(let n=0;i>n;n++){const i=parseInt(t[n]),o=parseInt(e[n]);if(i>o)return 1;if(o>i)return-1}return 0},queryParse(t){let e={};if(t){let i=t.split("&");for(let t of i){let i=t.split("="),n=i.length;2==n?e[i[0]]=i[1]:1==n&&i[0]&&(e[i[0]]="")}}return e},queryStringify:t=>Object.keys(t).map(e=>`${e}=${t[e]}`).join("&"),clearShareQuery(t){if(!t)return;let e=Utils.queryParse(t);return delete e.shareId,delete e.contentId,delete e.contentType,Utils.queryStringify(e)}},initGlobal=t=>{Object.defineProperty(Object.prototype,"gioGlobal",{get:()=>"quickApp"===t?global.__proto__:"my"===t?$global:global,configurable:!1,enumerable:!1})},getDataByPath=(t,e)=>{if(!t)return t;const i=e.split(".");let n=t[i.shift()];for(let t=0,e=i.length;e>t;t++){const t=i.shift();if(!n)return n;n=n[t]}return n},getManualImpInfo=t=>{let e={eventId:void 0,properties:{}};try{if(t.hasOwnProperty("gioTrack")&&"object"==typeof t.gioTrack)return e.eventId=t.gioTrack.name,e.properties=t.gioTrack.properties,e;if(!t.gioImpTrack)return e;e.eventId=t.gioImpTrack;const i=/^gioTrack(.+)/,n=/^\w+$/;for(let o in t){let r,s=o.match(i);if(s&&("track"===(r=s[1].toLowerCase())?e.eventId=t[o]:e.properties[r]=t[o]),!n.test(e.eventId)||10>parseInt(e.eventId[0]))throw e.eventId=null,Error()}}catch(t){console.warn("半打点IMP格式不正确, 事件名只能包含数字,字母和下划线,且不以数字开头, 请参考文档")}return e},isString=t=>t&&"string"==typeof t&&t.constructor===String,normalPath=t=>/^\//.test(t)?t:"/"+t;if(!Object.hasOwnProperty("getOwnPropertyDescriptors")){let t;t="object"==typeof Reflect&&"function"==typeof Reflect.ownKeys?Reflect.ownKeys:"function"==typeof Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,Object.defineProperty(Object,"getOwnPropertyDescriptors",{configurable:!0,writable:!0,value:function(e){return t(e).reduce((t,i)=>Object.defineProperty(t,i,{configurable:!0,enumerable:!0,writable:!0,value:Object.getOwnPropertyDescriptor(e,i)}),{})}})}const sdkVersion="3.5.8",platformConfig={wx:{name:"Weixin",path:"./weixin"},qq:{name:"QQ",path:"./qq"},my:{name:"Alipay",path:"./alipay"},swan:{name:"Baidu",path:"./baidu"},tt:{name:"Bytedance",path:"./bytedance"},quickApp:{name:"Quickapp",path:"./quickApp"},frame:{name:"Frame",path:"./multipleFrame"}},Config=Object.assign({},platformConfig.wx,{platform:"MinP",scnPrefix:"",appHandlers:["onShow","onHide","onError"],pageHandlers:["onLoad","onShow","onShareAppMessage","onShareTimeline","onTabItemTap","onHide","onUnload"],actionEventTypes:["onclick","tap","longpress","blur","change","submit","confirm","getuserinfo","getphonenumber","contact"],originalApp:App,originalPage:Page,originalComponent:Component,originalBehavior:Behavior,canHook:!0,hooks:{App:!0,Page:!0,Component:!0,Behavior:!0},lisiteners:{app:{appShow:"onShow",appClose:"onHide",appError:"onError"},page:{pageLoad:"onLoad",pageShow:"onShow",pageHide:"onHide",pageClose:"onUnload",tabTap:"onTabItemTap",shareApp:"onShareAppMessage",shareTime:"onShareTimeline"},actions:{click:["onclick","tap","longpress","getuserinfo","getphonenumber","contact"],change:["blur","change","confirm"],submit:["submit"]}}});var platformConfi