Sanakey
2021-04-30 8724a444c8a1d09dc8f9efd005e8443aad8df1ab
提交 | 用户 | age
aa6d80 1 const formatTime = (dateString: Date) => {
b6cc28 2   let date = new Date(dateString);
67dc7b 3   const year = date.getFullYear()
S 4   const month = date.getMonth() + 1
5   const day = date.getDate()
6   const hour = date.getHours()
7   const minute = date.getMinutes()
8   const second = date.getSeconds()
9
10   return (
c09e73 11     [year, month, day].map(formatNumber).join('-') +
67dc7b 12     ' ' +
S 13     [hour, minute, second].map(formatNumber).join(':')
14   )
15 }
16
17 const formatNumber = (n: number) => {
18   const s = n.toString()
19   return s[1] ? s : '0' + s
20 }
aa6d80 21
S 22 const to = (promise:Promise<any>)=>{
23   return promise.then((res:any)=>{
24     return [null,res]
25   }).catch((error:any)=>{
26     return [error]
27   })
28 }
29
3dd7c0 30 const getUrl = (url:string,params:string)=>{
S 31   // AppId: app.globalData.AppId
32   url = wx.globalData.reqBase + url;
33   if(params != null){
34     url = url + (url.indexOf('?') >= 0 ? "&" : "?") + params;
35   }
36   if (wx.globalData.AppId != null && url.indexOf('AppId=') < 0) {
37     url = url + (url.indexOf('?') >= 0 ? "&" : "?") + "AppId=" + wx.globalData.AppId;
38   }
39   if (url.indexOf('wx=3') < 0) {
40     url = url + (url.indexOf('?') >= 0 ? "&" : "?")  +'wx=3';
41   }
282d69 42   // if (url.indexOf('FromUserId=') < 0) {
S 43   //   url = url + (url.indexOf('?') >= 0 ? "&" : "?")  +'FromUserId=' + wx.globalData.FromUserId;
44   // }
3dd7c0 45
S 46   return url ;
47 }
48
a38dad 49 const makePhoneCall = (mobile:string)=>{
S 50   wx.pro.showModal({
51     title: '提示',
52     content: `即将拨打电话 ${mobile}`,
53   }).then((res:any) => {
54     // on close
55     console.log(res);
56     if (res.confirm){
57       console.log('确认');
58       wx.makePhoneCall({
59         phoneNumber: mobile,
60       })
61     }
62   });
63 }
64
f9ad6c 65 const debounce = (fn:()=>{},delay:number)=>{
S 66   let timer:any = null;
67   return function () {
68     if (timer) clearTimeout(timer);
69     timer = setTimeout(() => {
70       // console.log(this);
71       if (typeof fn === "function") {
72         // @ts-ignore
73         fn.apply(this,arguments)
74       }
75       timer = null;
76     }, delay);
77   }
78 }
79
8724a4 80 const  setGlobalData = (_this:any)=>{
S 81   let loginData = wx.globalData.loginData;
82   console.log('<<<<<<<<<获取loginData',loginData);
83   _this.setData({
84     loginData,
85   })
86 }
aa6d80 87 export default{
S 88   formatTime,
3dd7c0 89   to,
S 90   getUrl,
f9ad6c 91   makePhoneCall,
8724a4 92   debounce,
S 93   setGlobalData
aa6d80 94 }