Jamcuk
2017-12-27 3996156e8e022dce953986acd91c3045272a4adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// DOWX.js v1.0.6
// 2017-11-3
 
const com = require('common.js');
 
 
//================================================  自写隐藏 错误弹出框  ====================================================
// 写在do-body标签外: 
// <view wx:if='{{do_ycif==true}}' class='zdo_toast_wai'><view class='{{do_toastcolor==1?"zdo_toast1":"zdo_toast2"}}'>{{do_yccontent}}</view></view>
var zdo_errortimeout = null;
// 参数:  page()对象  提示文字内容
function Showred( thC, contentC )
{ if (zdo_errortimeout != null) { clearTimeout(zdo_errortimeout); } thC.setData({ do_ycif: false }); thC.setData({ do_ycif: true, do_yccontent: contentC, do_toastcolor: 1 });  zdo_errortimeout = setTimeout(function () { thC.setData({ do_ycif: false, do_yccontent: "" }); }, 3000); } 
module.exports.Showred = Showred;
 
//================================================  自写隐藏 正确弹出框  ====================================================
// 参数:  page()对象  提示文字内容
function Showgreen( thC, contentC )
{ if (zdo_errortimeout != null) { clearTimeout(zdo_errortimeout); } thC.setData({ do_ycif: false }); thC.setData({ do_ycif: true, do_yccontent: contentC, do_toastcolor: 2 }); zdo_errortimeout = setTimeout(function () { thC.setData({ do_ycif: false, do_yccontent: "" }); }, 3000); }
module.exports.Showgreen = Showgreen;
 
// ==================================================  自写刷新按钮  =======================================================
// 写在do-body外:  
// <view catchtap='refresh' style='right:20rpx;top:20rpx;' class='zdo_refresh'><image src='/img/zdo_ref1.png' class='{{zdotf_refresh==true?"zdoanimt_refresh":""}}'></image></view>
// js page中: 
// refresh: function() { dowx.Startrefresh(this); }
// 开启刷新动效,参数:  page()对象
var tf_refresh = false;
function Startrefresh (thC)
{if(tf_refresh==true){return false;}tf_refresh=true;thC.setData({ zdotf_refresh: true });}
module.exports.Startrefresh = Startrefresh;
// 关闭刷新动效,参数:  page()对象  完成请求的bool组(可不填)
var timeout_Stoprefresh = null;
function Stoprefresh (thC,zuC) 
{ if (zuC == null) { zuC = []; } var mo = zuC.indexOf(true); if (mo == -1) { if (timeout_Stoprefresh != null) { clearTimeout(timeout_Stoprefresh); } timeout_Stoprefresh = setTimeout(function(){ tf_refresh = false; thC.setData({ zdotf_refresh: false }); },800); } }
module.exports.Stoprefresh = Stoprefresh;
 
// ==============================================  语音播放的wifi图标动画  ==================================================
// 1.  js data: 
// zu_wificlass: ["wifiD", "wifiD", "wifiD"], //wifi播放图标的样式
// 2.  html写法: 
// <!--语音条  width最小140rpx--><view class='zwifi_wai' style='width:400rpx;'><view class='zwifi_jian'></view><view bindtap='Click_baitiao' class='flex1 zwifi_baitiao'><image class='{{zu_wificlass[0]}}' src='/img/yuyin1.png'></image><image class='{{zu_wificlass[1]}}' src='/img/yuyin2.png'></image><image class='{{zu_wificlass[2]}}' src='/img/yuyin3.png'></image></view><view class='zwifi_time font_min'><view class='font_gray'>{{time_luyin}}''</view><view catchtap='Click_chonglu' class='font_blue'>删除</view></view></view>
var zdo_interval=null;
// 开始wifi动画,参数:  当前page()对象   wifi的class样式
function Play_wifi (thatC, classC)  
{ var zu_0 = [classC, "displayNone", "displayNone"]; var zu_1 = [classC, classC, "displayNone"]; var zu_2 = [classC, classC, classC]; var zu_3 = ["displayNone", "displayNone", "displayNone"]; var nummo = 0; thatC.setData({ zu_wificlass: zu_3 }); if (zdo_interval != null) { clearInterval(zdo_interval); zdo_interval = null; } zdo_interval = setInterval(function(){ if (nummo == 0) { thatC.setData({ zu_wificlass: zu_0 });} else if (nummo == 1) { thatC.setData({ zu_wificlass: zu_1 }); } else if (nummo == 2) { thatC.setData({ zu_wificlass: zu_2 }); } if (nummo >= 3) { nummo = 0; thatC.setData({ zu_wificlass: zu_3 }); } else { nummo++; } },600);  }
module.exports.Play_wifi = Play_wifi;
// 结束wifi动画,参数:  当前page()对象   wifi的class样式
function Stop_wifi (thatC, classC) 
{ clearInterval(zdo_interval); zdo_interval = null; thatC.setData({ zu_wificlass: [classC, classC, classC] });}
module.exports.Stop_wifi = Stop_wifi;
 
// ====================================================  录音组件  ===========================================================
// 录音弹出框 do_ycly控制是否显示 do_yclytime控制一圈时长 
// 写在do-body外:  <view style='top: 400rpx;' class='zdo_luyin_wai {{do_ycly==true?"":"displayNone"}}' > <view class='zdo_luyin_yuan' > </view><view class='zdo_luyin_lt0'><view style='animation-duration:{{do_yclytime}}s;animation-delay:{{do_yclytime}}s;' class='zdo_luyin_lt {{do_ycly==true?"zanimt_luyin_lt":""}}'></view> </view><view style='animation-duration:{{do_yclytime}}s;' class='zdo_luyin_rt {{do_ycly==true?"zanimt_luyin_rt":""}}'></view> <image src='/img/zdo_ly.png' class='zdo_luyin_img' > </image></view>
var intval_record = null; //录音时长的计时器
var time_record = 0; //录音时长s
var time_oldrecord = 0; //旧的录音时间戳
var working_record = false; //录音是否正在工作
var tf_recordstop = false; //是否触发停止录音
// 开始录音,参数:  page()对象   录音长度最高限制s   生成的录音文件回调函数   每秒的动态回调函数(可不填)
function Record_start(thC, timemaxC, callback, callback2)
{ if (callback2 == null) { callback2 = function () {}; } var time_newrecord = new Date().getTime(); if ( (working_record != true) || (time_newrecord - time_oldrecord > 2000) ) { working_record = true; time_oldrecord = time_newrecord; tf_recordstop = false; time_record = 0; thC.setData({ do_ycly: true, do_yclytime: (timemaxC / 2) }); intval_record = setInterval(function () { time_record++; console.log("interval:录音计时" + time_record); if (tf_recordstop == true) { Record_stop(thC); } if (time_record >= timemaxC) { Record_stop(thC); } callback2(time_record); }, 1000); wx.startRecord({ success: function (res) { var back = { time: time_record, tempFilePath: res.tempFilePath }; callback(back); }, complete: function () { if (intval_record != null) { clearInterval(intval_record); intval_record = null; } time_record = 0; working_record = false; } }); } }
module.exports.Record_start = Record_start;
// 结束录音,参数:  page()对象
function Record_stop(thC)
{ tf_recordstop = true; thC.setData({ do_ycly: false }); if (time_record >= 1 && intval_record != null) { clearInterval(intval_record); intval_record = null; } wx.stopRecord(); }
module.exports.Record_stop = Record_stop;
 
// -=-=-=-=-=1
// -=-=-=-=-=
// -=-=-=-=-=
// -=-=-=-=-=2
 
// ==============================================  时间戳转换函数  =======================================================
// 参数:  1.时间戳
function FormatDate ( now ) 
{ now = parseFloat(now);var data = new Date(now);var year = data.getFullYear();var month = data.getMonth() + 1;var date = data.getDate();var hour = data.getHours();var minute = data.getMinutes();return year + "-" + month + "-" + date + " " + hour + ":" + minute; }
module.exports.FormatDate = FormatDate;
 
// =============================================  获取随机字符串函数  ======================================================
// 参数:  要开头的字符串
function Get_randomstring (strC) 
{ if(strC==null) { strC = ""; } var timestamp = new Date().getTime(); var sjs = Math.round(Math.random() * 899 + 100); var taskid = strC + timestamp + sjs; return taskid; }
module.exports.Get_randomstring = Get_randomstring;
 
// ================================================  获取文件MD5格式  =====================================================
// 资源上传,参数:  1.资源路径  2.成功回调函数
function GetFileMD5 ( pathC, callback )
{ if (callback == null) { callback = function () { }; } wx.getFileInfo({ filePath: pathC, digestAlgorithm: 'md5', success: function (infodata) { callback(infodata.digest); }, fail: function (error) { wx.showLoading({ title: '资源MD5→fail' }); console.log(error); } }); }
module.exports.GetFileMD5 = GetFileMD5;
 
// =================================================  获取设备信息  ======================================================
// 资源上传,参数:  1.成功回调函数
function GetSystemInfo ( callback )
{ if (callback == null) { callback = function () { }; } wx.getSystemInfo({ success: function (res) { var mydata = { brand: res.brand, model: res.model, screenWidth: res.screenWidth, screenHeight: res.screenHeight, windowWidth: res.windowWidth, windowHeight: res.windowHeight, version: res.version }; callback(mydata); }, fail: function () { wx.showLoading({ title: '设备info→fail' }); } }); }
module.exports.GetSystemInfo = GetSystemInfo;
 
// =================================================  获取节点信息  ======================================================
// 资源上传,参数:  1.节点的id字符串   2.成功回调函数
function GetQueryInfo ( idC, callback )
{ if (callback == null) { callback = function () { }; } wx.createSelectorQuery().select('#'+idC).boundingClientRect(function (rect) { var mydata = { left: rect.left, right: rect.right, top: rect.top, bottom: rect.bottom, width: rect.width, height: rect.height }; callback(mydata); }).exec(); }
module.exports.GetQueryInfo = GetQueryInfo;
 
// -=-=-=-=-=2
// -=-=-=-=-=
// -=-=-=-=-=
// -=-=-=-=-=3
 
// ====================================================  POST请求  ===========================================================
// 数据请求,参数:  1.地址url  2.发送的数据  3.接收数据的回调函数
function AjaxPost ( can_url, can_data, can_callback )
{ wx.showNavigationBarLoading(); wx.request({ method: "POST", url: can_url, data: can_data, success: function (res) { can_callback(res.data); }, fail: function (res) { wx.showLoading({ title: res.errMsg }); } }); }
module.exports.AjaxPost = AjaxPost;
 
// ====================================================  GET请求  ===========================================================
// 数据请求,参数:  1.地址url  2.发送的数据  3.接收数据的回调函数
function AjaxGet ( can_url, can_data, can_callback )
{ wx.showNavigationBarLoading(); wx.request({ method: "GET", url: can_url, data: can_data, success: function (res) { can_callback(res.data); }, fail: function (res) { wx.showLoading({ title: 'GET→fail', }); } }); }
module.exports.AjaxGet = AjaxGet;
 
// =====================================================  请求结束  =========================================================
// 关闭导航转圈动画, 参数:  完成请求的bool组(可不填)
function AjaxStop ( zuC )
{ if (zuC == null) { zuC = []; } var mo = zuC.indexOf(true); if (mo == -1) { wx.hideNavigationBarLoading(); } }
module.exports.AjaxStop = AjaxStop;
 
// -=-=-=-=-=3
// -=-=-=-=-=
// -=-=-=-=-=
// -=-=-=-=-=4
 
// ==================================================  获取用户信息  =======================================================
// 参数:   请求openid的url(可为空字符串"")   返回数据的回调函数
function Get_userInfo ( urlC, callback )
{ var calldata = {}; wx.login({ fail: function (res) { wx.showLoading({ title: 'login→fail' }); }, success: function (res) { wx.getUserInfo({ withCredentials: true, lang: "zh_CN", success: function (res2) { calldata.info1 = res2; if (urlC.length == 0) { callback(calldata); } else if (urlC.length > 0) { var mydata = { code: res.code }; var myurl = com.getWholeUrl(urlC, mydata); AjaxPost(myurl, {}, function (data) { if (data.code == 0) { calldata.info2 = data.data; callback(calldata); } else { console.log(data); wx.showLoading({ title: 'openid返回错误' }); } }); } } }); } }); }
module.exports.Get_userInfo = Get_userInfo;
 
// =================================================  获取用户信息权限  ======================================================
function Authorize_userInfo ( callback )
{ if (callback == null) { callback = function () {}; } wx.authorize({ scope: 'scope.userInfo', fail: function () { wx.showModal({ content: '请授权获取用户信息,仅含头像、昵称等基本信息,不涉及隐私信息', showCancel: false, confirmText: '去授权', complete: function (res) { if (res.confirm == true) { wx.openSetting(); } else { Authorize_userInfo(callback); } } }); }, success: function () { callback(); } }); }
module.exports.Authorize_userInfo = Authorize_userInfo;
 
// ==================================================  获取摄像头权限  =======================================================
function Authorize_camera ( callback ) 
{ if (callback == null) { callback = function () { }; } wx.authorize({ scope: 'scope.camera', fail: function () { wx.showModal({ content: '后面有录像操作,请授权获取摄像头', showCancel: false, confirmText: '去授权', complete: function (res) { if (res.confirm == true) { wx.openSetting(); } else { Authorize_camera(callback); } } }); }, success: function () { callback(); } }); }
module.exports.Authorize_camera = Authorize_camera;
 
// ===================================================  获取录音权限  =======================================================
function Authorize_record ( callback ) 
{ if (callback == null) { callback = function () { }; } wx.authorize({ scope: 'scope.record', fail: function () { wx.showModal({ content: '后面有录音操作,请授权获取录音功能', showCancel: false, confirmText: '去授权', complete: function (res) { if (res.confirm == true) { wx.openSetting(); } else { Authorize_record(callback); } } }); }, success: function () { callback(); } }); }
module.exports.Authorize_record = Authorize_record;
 
// =================================================  获取地理位置权限  ======================================================
function Authorize_userLocation ( callback ) 
{ if (callback == null) { callback = function () { }; } wx.authorize({ scope: 'scope.userLocation', fail: function () { wx.showModal({ content: '需要位置信息,请授权获取地理位置功能', showCancel: false, confirmText: '去授权', complete: function (res) { if (res.confirm == true) { wx.openSetting(); } else { Authorize_userLocation(callback); } } }); }, success: function () { callback(); } }); }
module.exports.Authorize_userLocation = Authorize_userLocation;