@tmsfe/tms-core 0.0.1 → 0.0.5

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.
@@ -0,0 +1,149 @@
1
+ /**
2
+ * Tencent Inc. All Rights Reserved.
3
+ * @author:
4
+ * Created:
5
+ * Description: format time.
6
+ * History:
7
+ * 2017-07-26 @davislu modify.
8
+ */
9
+
10
+ /**
11
+ * @function
12
+ * @description 格式化时间
13
+ * @param {Number} seconds 秒数
14
+ * @returns {String} 格式化的时间 -> 2小时47分钟或者12天
15
+ */
16
+ const formatTime = (seconds) => {
17
+ if (typeof seconds !== 'number') return seconds;
18
+
19
+ const PER_MINUTE = 60 * 1;
20
+ const PER_HOUR = 60 * PER_MINUTE;
21
+ const PRE_DAY = 24 * PER_HOUR;
22
+ let cost = '';
23
+ // >24小时的显示 【x天】
24
+ if (seconds >= PRE_DAY) {
25
+ cost = `${Math.floor(seconds / PRE_DAY)}天`;
26
+ // <1小时的显示 【x分钟】 ,x取整数上限,最低为1分钟。
27
+ } else if (seconds < PER_HOUR) {
28
+ cost = `${Math.ceil(seconds / PER_MINUTE)}分钟`;
29
+ // <24小时&>1小时的显示 【x小时y分钟】 ,分钟取整数上限
30
+ } else {
31
+ cost = `${Math.floor(seconds / PER_HOUR)}小时`;
32
+ const s = seconds % PER_HOUR;
33
+ if (s > 0) {
34
+ cost += `${Math.ceil(s / PER_MINUTE)}分钟`;
35
+ }
36
+ }
37
+
38
+ return cost;
39
+ };
40
+
41
+ /**
42
+ * @function
43
+ * @description 将秒数格式化为x天y小时z分钟
44
+ * @param {Number} oriSeconds 秒数
45
+ * @returns {String} 格式化后的文案
46
+ */
47
+ const formatTimeWithDetails = (oriSeconds) => {
48
+ let seconds = oriSeconds;
49
+ // 非Number类型,直接返回,不进行处理
50
+ if (typeof seconds !== 'number') return seconds;
51
+ // 参数为NaN类型,直接抛出异常
52
+ if (isNaN(seconds)) throw new Error(`formatTimeWithDetails方法的参数seconds必须时一个非NaN数字,现在的值为${seconds}`);
53
+
54
+ // 定义一些常量
55
+ // 1分钟包含的秒数
56
+ const PER_MINUTE = 60 * 1;
57
+ // 1小时包含的秒数
58
+ const PER_HOUR = 60 * PER_MINUTE;
59
+ // 1天包含的秒数
60
+ const PRE_DAY = 24 * PER_HOUR;
61
+ let cost = '';
62
+
63
+ // 秒数多于1天
64
+ if (seconds >= PRE_DAY) {
65
+ cost = `${Math.floor(seconds / PRE_DAY)}天`;
66
+ seconds %= PRE_DAY;
67
+ }
68
+
69
+ // 秒数小于1小时
70
+ if (seconds < PER_HOUR) {
71
+ if (cost) {
72
+ cost += '0小时';
73
+ }
74
+ cost += `${Math.ceil(seconds / PER_MINUTE)}分钟`;
75
+ } else {
76
+ // 秒数介于1天和1分钟之间
77
+ cost += `${Math.floor(seconds / PER_HOUR)}小时`;
78
+ const s = seconds % PER_HOUR;
79
+ if (s > 0) {
80
+ cost += `${Math.ceil(s / PER_MINUTE)}分钟`;
81
+ }
82
+ }
83
+
84
+ return cost;
85
+ };
86
+
87
+
88
+ /**
89
+ * @function
90
+ * @description 对原有时间字符串进行格式化
91
+ * @param {String} str - 原字符串
92
+ * @param {String} dateSeprator - 日期分隔符
93
+ * @param {Boolean} keepSeconds - 是否保留秒数
94
+ * @returns {String} 格式化后的文案
95
+ */
96
+ const formatTimeStr = (str = '', dateSeprator = '.', keepSeconds = false) => {
97
+ if (typeof str !== 'string' || str === '') {
98
+ return '';
99
+ }
100
+ let s = str.replace(/-/g, dateSeprator).replace(/:/g, ':');
101
+
102
+ // 不保留秒的时候,如果有两个冒号,截取第二个冒号之前的部分
103
+ if (!keepSeconds && /[^:]*:[^:]*:/.test(s)) {
104
+ const firstIndex = s.indexOf(':');
105
+ const secondIndex = s.indexOf(':', firstIndex + 1);
106
+ if (secondIndex > -1) {
107
+ s = s.substring(0, secondIndex);
108
+ }
109
+ }
110
+ return s;
111
+ };
112
+
113
+
114
+ /**
115
+ * @description 格式化时间戳为 yyyy-mm-dd, yyyy-mm-dd HH:MM, yyyy-mm-dd HH:MM:SS
116
+ * @param {Date} date 日期
117
+ * @param {Boolean} withTime 是否带时间
118
+ * @param {Boolean} withSeconds 是否带秒数
119
+ * @param {String} join 连字符
120
+ * @returns {String} 格式化后的字符串,如 2021-03-18 或者 2021-03-18 10:11
121
+ */
122
+ const dateToString = (date, withTime = false, withSeconds = false, join = '-') => {
123
+ const DATE = date ? new Date(date) : new Date();
124
+ // 为兼容ios,android平台的差异,故而不使用toLocaleDateString方法
125
+ const year = DATE.getFullYear();
126
+ const month = DATE.getMonth() + 1;
127
+ const day = DATE.getDate();
128
+ const time = DATE.toTimeString().slice(0, 8);
129
+ let dateStr = year + join + month + join + day;
130
+
131
+ if (!withTime) {
132
+ return dateStr.replace(/\b\d\b/g, '0$&');
133
+ }
134
+
135
+ dateStr = `${dateStr} ${time}`.replace(/\b\d\b/g, '0$&');
136
+
137
+ if (!withSeconds) {
138
+ dateStr = dateStr.slice(0, -3);
139
+ }
140
+
141
+ return dateStr;
142
+ };
143
+
144
+ export {
145
+ formatTime,
146
+ formatTimeStr,
147
+ formatTimeWithDetails,
148
+ dateToString,
149
+ };
@@ -0,0 +1,12 @@
1
+ export interface ObjectType {
2
+ [props: string]: ObjectType | string | number | boolean;
3
+ }
4
+ export interface WxPostionType {
5
+ latitude: number
6
+ longitude: number
7
+ speed: number
8
+ accuracy: number
9
+ altitude: number
10
+ verticalAccuracy: number
11
+ horizontalAccuracy: number
12
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "sourceMap": false,
4
+ "target": "esnext",
5
+ "module": "esnext",
6
+ "moduleResolution": "node",
7
+ "allowJs": true,
8
+ "strict": true,
9
+ "declarationMap": false,
10
+ "noUnusedLocals": true,
11
+ "experimentalDecorators": true,
12
+ "resolveJsonModule": true,
13
+ "esModuleInterop": true,
14
+ "removeComments": false,
15
+ "jsx": "preserve",
16
+ "lib": ["esnext", "dom"],
17
+ "rootDir": ".",
18
+ "types": ["wechat-miniprogram"],
19
+ "paths": {
20
+ }
21
+ },
22
+ "include": [
23
+ "src"
24
+ ]
25
+ }
26
+
@@ -1 +0,0 @@
1
- import{a,g as e}from"./env-b76a9d75.js";const n=async(n="",s={},t=!0)=>{const{cloudEnvId:o,appVersion:r}=e(),i=Date.now(),c={...s,timestamp:i,seqId:`${i}7${Math.random().toString().slice(2,7)}`,appVersion:r};if(t){const{userId:e,token:n}=await a();Object.assign(c,{userId:e,token:n})}return await new Promise((a,e)=>{wx.cloud.callFunction({name:n,data:c,config:{env:o},success:a,fail:a=>{e({err:a,name:n,mergedData:c})}})})};export{n as callCloudFunc};
@@ -1 +0,0 @@
1
- const p={wxAppId:"",appVersion:"",appEnv:"",client:""};let e=void 0;const s=[],n=(p,n)=>{for(e=p;s.length;){const p=s.shift();n?p.reject(n):p.resolve(e)}},o=async()=>void 0!==e?e:new Promise((p,e)=>s.push({resolve:p,reject:e})),t=()=>p,a=e=>{const{wxAppId:s,appVersion:n,appEnv:o,client:t}=e;p.wxAppId=s,p.appVersion=n,p.appEnv=o,p.client=t};export{o as a,a as b,t as g,n as s};
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- import{R as t,m as e}from"./request-f9eddadc.js";import{g as n,a as o,s as r,b as c}from"./env-b76a9d75.js";let a;class s{static report(e,o=!0,r=40,c=!0,a=!0){var i;if(null==e||!e[27])return Promise.reject("invalid report param");const l=new Array(41),u=n();if(Object.keys(e).forEach(t=>{const n=typeof e[t];l[t]="string"===n?e[t]:"object"===n?JSON.stringify(e[t]):String(e[t])}),l[9]="2",a&&!l[10]&&(l[10]=u.appVersion),l[26]||(l[26]=null===(i=l[27])||void 0===i?void 0:i[0]),l[28]=u.client,c&&!l[29]){const t=wx.getStorageSync("appShowScene");t&&(l[29]=String(t))}return o&&!l[r]&&(l[r]=s.getSimulatedUserId()),(new t).post("basic/event/upload",{batch:[l]}).catch(()=>null)}static getSimulatedUserId(){if(a)return a;const t="SimulatedUserKey";if(a=wx.getStorageSync(t),a)return a;const e=Math.random().toString(36).substr(2,10);return a=`${Date.now()}_${e}`,wx.setStorage({key:t,data:a}),a}}let i=null,l=null,u=null;const d=()=>{if(i)return i;try{return i=wx.getSystemInfoSync(),i}catch(t){return{}}},g=()=>{if(l)return l;try{return l=wx.getLaunchOptionsSync(),l}catch(t){return{}}};var h={getPlatform:()=>{try{const t=d(),{platform:e}=t;return e||"unknown"}catch(t){return"unknown"}},getSystemInfoSync:d,getLaunchOptionsSync:g,getLaunchParamOfString:()=>{try{const t=g()||{};return JSON.stringify(t)}catch(t){return""}},resetSystemInfoSync:()=>{i=null},getAccountInfoSync:()=>{if(u)return u;try{return u=wx.getAccountInfoSync(),u}catch(t){return{}}}};const f={debug:()=>{},info:()=>{},log:()=>{},warn:()=>{},error:()=>{},addFilterMsg:()=>{},setFilterMsg:()=>{}},p=wx.getLogManager?wx.getLogManager():f,y=wx.getRealtimeLogManager?wx.getRealtimeLogManager():f,m=t=>t.map(t=>"string"==typeof t?t:JSON.stringify(t)),w={debug(...t){p.debug(...m(t))},info(...t){p.info(...m(t))},log(...t){p.log(...m(t))},warn(...t){p.warn(...m(t))},error(...t){w.warn(...t)}},S={info(...t){y.info(...m(t))},warn(...t){y.warn(...m(t))},error(...t){y.error(...m(t))},addFilterMsg(t){y.addFilterMsg(t)},setFilterMsg(t){y.setFilterMsg(t)}};class v{constructor(){this.handlers=[]}bind(t,e){void 0===this.handlers[t]&&(this.handlers[t]=[]),this.handlers[t].push(e)}bindOnce(t,e){void 0===this.handlers[t]&&(this.handlers[t]=[]);0===this.handlers[t].length&&this.handlers[t].push(e)}remove(t){this.handlers[t]=[]}unbind(t,e){if(this.handlers[t]instanceof Array){const n=this.handlers[t];let o=0;const r=n.length;for(;o<r&&n[o]!==e;o+=1);n.splice(o,1)}}dispatch(t){if(this.handlers[t.type]instanceof Array){this.handlers[t.type].forEach(e=>e(t))}}}const x=new t,L=new v,I={};let b=null,P=null,A=!0,M=null,j="",N=null;const _=(t="scope.userLocation")=>N||(N=new Promise((e,n)=>{wx.getSetting({success:({authSetting:n={}})=>{e(n[t]),N=null},fail:(t={})=>{N=null;const{errMsg:o=""}=t||{};o.indexOf("getSetting:fail data no response")>-1?e(!0):n(t)}})}),N),C=(t,e)=>{let n=t;return t.startsWith(e)&&(n=t.substr(e.length)),n},E=async t=>{if(t&&!A){let e=!1;try{e=await _(),A=!0}catch(t){}if(!1!==e)return void L.dispatch({type:"loc_status_changed"});const n=setTimeout(()=>{E(t),clearTimeout(n)},200)}else A=t};class O{static locForNoAuth={province:"广东省",cityCode:"440300",cityName:"深圳市",latitude:22.54286,longitude:114.05956};static async getMergedLocation(t=!0){const e=O.getUserLocation();return e||await O.getLocationDetail(t)}static getUserLocation(){return M}static setUserLocation(t){if(!t||"object"!=typeof t)return;const{cityName:e}=t;e&&j!==e&&(j=e,M=t,L.dispatch({type:"loc_city_changed"}))}static async getLocationSilent(t="gcj02"){let e,n=null;try{if(e=await _(),e)return O.getLocation(!1,t)}catch(t){n=t}return E(!1),Promise.reject({err:n,unAuthed:!0,locationScopeStatus:e})}static getLocationDetailSilent(t=0,e="gcj02"){return O.getLocationSilent(e).then(e=>O.getPoiInfo(e.latitude,e.longitude,t)).catch(t=>Promise.reject(t))}static getLocation(t=!1,e="gcj02",n="",o=!0){return b||(b=new Promise((r,c)=>{((t="gcj02")=>new Promise((e,n)=>{wx.getLocation({type:t||"gcj02",success:e,fail:n})}))(e).then(t=>{b=null,E(!0),r(t)}).catch((e={})=>{b=null,E(!1);const a=e.errMsg||"",{locationEnabled:s,locationAuthorized:i}=(()=>{try{const t=wx.getSystemInfoSync()||{};return"devtools"===t.platform&&(t.locationEnabled=!0,t.locationAuthorized=!0),t}catch(t){return{}}})();if(s&&i&&a.search(/auth [deny|denied]|authorize/)<0)return void c(e);if(!t){const t={...e,unAuthed:!0};return void c(t)}const l=s&&i,{authLevelName:u,confirmText:d}=((t,e)=>({authLevelName:t?"微信":"系统",confirmText:e?"去开启":"好的"}))(s,l);wx.showModal({confirmText:d,title:`未开启${u}位置信息权限`,content:n||`开启${u}位置信息权限\n体验更顺畅的出行服务`,showCancel:o&&l,confirmColor:"#4875fd",success:t=>{if(!t.confirm||!s||!i){const t={...e,unAuthed:!0};return c(t)}((t="scope.userLocation")=>new Promise((e,n)=>{wx.openSetting({success:o=>{const{authSetting:r}=o;r[t]?e():n(o)},fail:n})}))().then(()=>{r(O.getLocation())}).catch(t=>{const e={...t,unAuthed:!0};c(e)})}})})}),b)}static getPoiInfo(t,e,n=0){const o=`${t}-${e}-${n}`;return I[o]?Promise.resolve(I[o]):P||(P=x.post("basic/lbs/decode",{lat:t,lng:e,getPoi:n}).then(r=>{const{errCode:c,resData:a={}}=r;if(0===c){const{result:r={}}=a,{ad_info:c={}}=r,s={province:c.province,cityName:c.city,adCode:c.adcode,cityCode:C(c.city_code,c.nation_code),latitude:t,longitude:e};return P=null,0===n?(I[o]=s,s):(s.adCode=c.adcode,s.poi=((t={})=>{const{pois:e=[],address_reference:n}=t;return e.length?e[0]:n&&n.landmark_l2?n.landmark_l2:{}})(r),I[o]=s,s)}return P=null,Promise.reject(r)}).catch(t=>(P=null,Promise.reject(t))),P)}static getLocationDetail(t=!1,e="gcj02",n="",o=0){return O.getLocation(t,e,n).then(t=>O.getPoiInfo(t.latitude,t.longitude,o)).catch(t=>Promise.reject(t))}static onLocStatusChange(t){t&&"function"==typeof t&&L.bind("loc_status_changed",t)}static onCityChange(t){t&&"function"==typeof t&&L.bind("loc_city_changed",t)}static async getRoute(t,e,n="driving"){let o=e;const r=new RegExp(/(\d+\.\d{6,}),(\d+\.\d{6,})/);if(!r.test(t))throw Error("目的地参数格式错误");if(!r.test(o)){const{latitude:t,longitude:e}=await O.getMergedLocation();o=`${t},${e}`}return x.post("basic/lbs/direction",{from:o,to:t,mode:n})}}const R=new t,{miniProgram:{version:D}={}}=wx.getAccountInfoSync()||{},$=getApp({allowDefault:!0}),k=[];let U=-1,F={};try{F=wx.getLaunchOptionsSync()}catch(t){F={}}const T=new Promise(t=>{wx.getSystemInfo({success:e=>{const{model:n,version:o,platform:r,SDKVersion:c,host:a}=e;t({model:n,wxVersion:o,platform:r,SDKVersion:c,host:a})},fail:()=>{t({})}})});let V=null;const J=async()=>{if(V)return V;try{const t=await O.getLocationDetailSilent();return V={city:t.cityName,province:t.province},V}catch(t){return{city:"",province:""}}},q=async()=>{if(t)return Promise.resolve(t);const{userId:t}=await o();return t};let z="";const H=async(t,e)=>{const[n,o,r]=e,c=Array.isArray(t.param)?t.param:((t={})=>{const e=[];return e.length=40,Object.keys(t).forEach(n=>{const o=Number(n);e[o]=t[n]}),e})(t),{client:a}=await $.tms.getEnvInfo();return c[5]=await q(),c[10]=D,c[19]=null==n?void 0:n.host,c[16]=(()=>{if(z)return z;try{const t=wx.getLaunchOptionsSync()||{},{query:e={}}=t;return z=e.from||"",z}catch(t){return""}})(),c[17]=c[17]||(null==r?void 0:r.province),c[18]=c[18]||(null==r?void 0:r.city),c[28]=a,c[9]||(c[9]="2"),c[12]||(c[12]=o),c[13]||(c[13]="2"),c[29]||(c[29]=F.scene),c[33]||(c[33]=JSON.stringify(n)),c[36]||(c[36]=F),c.forEach((t,e)=>{if(t&&"string"!=typeof t)c[e]=""+JSON.stringify(t);else{const t=c[e];c[e]=t||0===t?""+t:""}}),c.map(t=>null!==t?encodeURIComponent(t):t)},K=(t=[])=>{try{t.forEach(t=>{const{eventName:e,analyticsData:n}=(async t=>{const e={},{10:n,29:o}=t;e[10]=n,e[29]=o,e[17]=decodeURIComponent(t[17]),e[18]=decodeURIComponent(t[18]);for(let n=30;n<41;n+=1)e[n]=decodeURIComponent(t[n]||""),t[33]&&t[33].indexOf("model")>-1&&(e[33]="");const{client:r}=await $.tms.getEnvInfo();return{analyticsData:e,eventName:`${r}_${t[27]}`}})(t);wx.reportAnalytics(e,n)})}catch(t){}},W=(t,e)=>{if([1030,1129].includes(F.scene))return Promise.resolve();const n=[T,new Promise(t=>{wx.getNetworkType({success:e=>{t(e.networkType)},fail:()=>{t("unknown")}})}),J()];return Promise.all(n).then(async e=>{const n=await H(t,e);k.push(n)}).then(()=>e?B():{cache:!0})},B=async()=>{if(0===k.length)return Promise.resolve();const t=[...k];return R.post("basic/event/upload",{userId:await q(),batch:t}).then((e={})=>{const{errCode:n}=e||{};0===n&&(k.splice(0,t.length),K(t))})},G=t=>{U=setInterval(async()=>{B(),t&&clearInterval(U)},3e3)},Q=(t=!1,e=!1)=>{t?(k.length>0&&B(),e?clearInterval(U):G(e)):G(e)};wx.onAppShow(t=>{(t=>{F=t})(t),Q(!0)}),wx.onAppHide(()=>{Q(!0,!0)});const X={init:(e={})=>{const{appVersion:n,wxAppId:o,client:r,defaultHost:a,cloudEnvId:s,appEnv:i,appPagePaths:l}=e;c({wxAppId:o,appVersion:n,appEnv:i,client:r}),t.defaultHost=a,wx.cloud.init({env:s})},createRequest:(e={})=>new t(e),setAuthInfo:r,getLogManager:()=>w,getRealtimeLogManager:()=>S,md5:e,getReporter:()=>({report:W}),getFastReporter:()=>s,getLocationManager:()=>O,getEventDispatcher:()=>new v,getAccountInfoSync:h.getAccountInfoSync};export default X;
@@ -1 +0,0 @@
1
- import{a as t,g as e}from"./env-b76a9d75.js";const s=function(t){const e=(t,e)=>{const s=2147483648&t,a=2147483648&e,r=1073741824&t,n=1073741824&e,o=(1073741823&t)+(1073741823&e);return r&n?2147483648^o^s^a:r|n?1073741824&o?3221225472^o^s^a:1073741824^o^s^a:o^s^a},s=t=>{const{FN:s,a:a,b:r,c:n,d:o,x:i,s:h,ac:c}=t,u=e(a,e(e(s(r,n,o),i),c));return e((l=u)<<(d=h)|l>>>32-d,r);var l,d},a=t=>{let e="";for(let s=0;s<=3;s+=1){const a="0"+(t>>>8*s&255).toString(16);e+=a.substr(a.length-2,2)}return e};let[r,n,o,i]=[1732584193,4023233417,2562383102,271733878];const h=[[7,12,17,22],[5,9,14,20],[4,11,16,23],[6,10,15,21]],c="16b05af49e38d27c58be147ad0369cf207e5c3a18f6d4b29".split("").map(t=>parseInt(t,16)),u=[3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745],l=(t,e=0)=>(t+e)%4,d=(t,e,s)=>t&e|~t&s,p=(t,e,s)=>t&s|e&~s,m=(t,e,s)=>t^e^s,f=(t,e,s)=>e^(t|~s),w=(t=>{const e=t.length,s=16*((e+8-(e+8)%64)/64+1),a=Array(s-1);let r=0;for(;r<=e;){const s=(r-r%4)/4,n=r%4*8,o=r===e?128:t.charCodeAt(r);a[s]|=o<<n,r+=1}return a[s-2]=e<<3,a[s-1]=e>>>29,a})((t=>{const e=t.replace(/\r\n/g,"\n"),s=t=>String.fromCharCode(t),a=[];for(let t=0;t<e.length;t+=1){let r=e.charCodeAt(t);r<128?a.push(s(r)):r<2048?a.push(s(r>>6|192),s(63&r|128)):r<55296||r>=57344?a.push(s(r>>12|224),s(r>>6&63|128),s(63&r|128)):(r=65536+((1023&r)<<10|1023&e.charCodeAt(t+=1)),a.push(s(r>>18|240),s(r>>12&63|128),s(r>>6&63|128),s(63&r|128)))}return a.join("")})(t));for(let t=0;t<w.length;t+=16){const a=r,b=n,g=o,A=i,y=[r,i,o,n];u.forEach((e,a)=>{const r=a%16,n=a/16<<0,o=a<16?a:c[a-16],i=[d,p,m,f][n];y[l(r)]=s({FN:i,a:y[l(r)],b:y[l(r,3)],c:y[l(r,2)],d:y[l(r,1)],x:w[t+o],s:h[n][r%4],ac:e})}),r=e(y[0],a),n=e(y[3],b),o=e(y[2],g),i=e(y[1],A)}return(a(r)+a(n)+a(o)+a(i)).toLowerCase()},a=(t={})=>{const e=s((t=>Object.keys(t).filter(e=>void 0!==t[e]).sort().map(e=>{const s=t[e];return`${e}${"object"==typeof s?JSON.stringify(s):s}`}).join(""))(t)+"");return{...t,sign:e}},r=async(t={},s=!0,a={})=>{const{appVersion:r,wxAppId:o,client:i}=e(),h=Math.random().toString(36).substr(2,10),c=Date.now(),u=Math.random().toString().slice(2,7),l=`${c}${["","sinan","mycar"].indexOf(i)+7}${u}`,d=await n(t,s);return Object.assign({version:"1.0",appVersion:r,nonce:h,timestamp:c,seqId:l,wxAppId:o},{...a},{...d})},n=async(e,s)=>{const a={...e};if(s){const{userId:e,token:s}=await t();return a.userId=e,a.token=s,a}return delete a.userId,delete a.userid,delete a.token,a};class o{static defaultHost="";host="";withAuth=!0;baseParam={};constructor(t={withAuth:!0}){t.host&&(this.host=t.host),void 0!==t.withAuth&&(this.withAuth=!!t.withAuth),this.baseParam=t.baseParam||{}}makeUrl(t){if(/^http/i.test(t))return t;const e=this.host||o.defaultHost;return`${/^http/i.test(e)?e:"https://"+e}/${t}`}get(t,e,s){return this.doRequest(t,e,"GET",s)}post(t,e,s){return this.doRequest(t,e,"POST",s)}async upload(t,e,s,n){const o=await r(s,this.withAuth,this.baseParam),i=await new Promise((s,r)=>{wx.uploadFile({name:"content",url:this.makeUrl(t),filePath:e,formData:a(o),header:n,success:s,fail:r})});return"string"==typeof(null==i?void 0:i.data)?JSON.parse(null==i?void 0:i.data):null==i?void 0:i.data}async doRequest(t,e={},s="POST",n={}){const o=await r(e,this.withAuth,this.baseParam),i=await new Promise((e,r)=>{wx.request({url:this.makeUrl(t),header:n,method:s,data:a(o),success:e,fail:r})});return"string"==typeof(null==i?void 0:i.data)?JSON.parse(null==i?void 0:i.data):null==i?void 0:i.data}async serialize(t,e={}){let s=this.makeUrl(t);const n=await r(e,this.withAuth,this.baseParam),o=a(n),i=[];return Object.keys(o).forEach(t=>{const e=encodeURIComponent(o[t]);i.push(`${t}=${e}`)}),i.length&&(s+=(/\?/.test(s)?"&":"?")+i.join("&")),Promise.resolve({url:s})}}export{o as R,s as m};
package/dist/request.js DELETED
@@ -1 +0,0 @@
1
- export{R as default}from"./request-f9eddadc.js";import"./env-b76a9d75.js";
@@ -1,25 +0,0 @@
1
- {
2
- "private": {
3
- "name": "@tencent/tms-core",
4
- "version": "0.3.5",
5
- "description": "tms运行时框架",
6
- "repository": {
7
- "type": "git",
8
- "url": "http://git.code.oa.com/lbsweb/tms/tms-arch.git"
9
- }
10
- },
11
- "public": {
12
- "name": "@tmsfe/tms-core",
13
- "version": "0.0.1",
14
- "description": "tms-core",
15
- "repository": {
16
- "type": "git"
17
- }
18
- },
19
- "main": "dist/index",
20
- "miniprogram": "dist",
21
- "scripts": {},
22
- "author": "tms·web",
23
- "gitHead": "67425bc1ca159701c3373a6aa9cdd801ffb82d8a",
24
- "devDependencies": {}
25
- }