blob: 7e7902febebe4fbc142ea4b79189abe4a93c2478 [file] [log] [blame]
binquan.qiu7f2665f2020-03-27 17:19:57 +08001//app.js
2var server = 'https://yy.dlsmk.cn/payapi/mobileapi';
3
4wx.$doCountdown=function(that){
5 var inter = setInterval(function () {
6 that.setData({
7 smsFlag: false,
8 sendColor: '#cccccc',
9 sendTime: that.data.snsMsgWait + 's后重发',
10 snsMsgWait: that.data.snsMsgWait - 1
11 });
12 if (that.data.snsMsgWait < 0) {
13 clearInterval(inter)
14 that.setData({
15 smsFlag: true,
16 sendColor: 'rgb(124, 255, 112)',
17 sendTime: '获取验证码',
18 snsMsgWait: 30
19
20 });
21 }
22 }.bind(that), 1000);
23}
24
25
26wx.$checkBankcard=function() {
27 var userid = wx.getStorageSync("userid");
28 if (wx.$isEmpty(userid)) {
29 wx.showModal({
30 title: '提示',
31 content: '使用该功能前请先绑卡',
32 })
33 return false;
34 }
35 return true;
36}
37
38wx.$doPost = function(url, param, callback) {
39 var token = wx.getStorageSync("token") || '';
40 var tenantid = wx.getStorageSync("tenantid") || '';
41 var auth = 'Bearer ' + token;
42 var tenantid = tenantid;
43
44 wx.request({
45 url: server + url,
46 timeout: 10000,
47 method: 'POST',
48 header: {
49 'content-type': 'application/x-www-form-urlencoded',
50 'Authorization': auth,
51 'X-TENANT-ID': tenantid
52 },
53 data: param,
54 success: function(result) {
55 console.log(result);
56 if (callback) {
57 callback(true, result)
58 }
59 },
60 fail: function(result) {
61 console.log(result);
62 var status=result.status;
63
64 if (status && status == 401) {
65 wx.redirectTo({
66 url: '../wxlogin/wxlogin'
67 })
68 } else {
69 if (callback) {
70 callback(false, result)
71 }
72 }
73 }
74 })
75}
76
77wx.$isEmpty = function(str) {
78 if (!str || str == 'undefined' || str == null || str == '') {
79 return true;
80 }
81 return false;
82}
83
84wx.$getUUID = function(str) {
85 var d = new Date().getTime();
86 if (window.performance && typeof window.performance.now === "function") {
87 d += performance.now(); //use high-precision timer if available
88 }
89 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
90 var r = (d + Math.random() * 16) % 16 | 0;
91 d = Math.floor(d / 16);
92 return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
93 });
94 return uuid;
95}
96
97App({
98
99 onLaunch: function() {
100 // 展示本地存储能力
101 var logs = wx.getStorageSync('logs') || []
102 logs.unshift(Date.now())
103 wx.setStorageSync('logs', logs)
104
105 // 登录
106 wx.login({
107 success: res => {
108 // 发送 res.code 到后台换取 openId, sessionKey, unionId
109 }
110 })
111 // 获取用户信息
112 wx.getSetting({
113 success: res => {
114 if (res.authSetting['scope.userInfo']) {
115 // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
116 wx.getUserInfo({
117 success: res => {
118 // 可以将 res 发送给后台解码出 unionId
119 this.globalData.userInfo = res.userInfo
120
121 // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
122 // 所以此处加入 callback 以防止这种情况
123 if (this.userInfoReadyCallback) {
124 this.userInfoReadyCallback(res)
125 }
126 }
127 })
128 }
129 }
130 })
131 },
132 globalData: {
133 userInfo: null
134 }
135
136})