您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
10 个月前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
1年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. import md5 from './md5.js';
  2. // import sha1 from '../sys/sha1.js';
  3. import datas from './datas.js';
  4. import theme from './theme.js';
  5. const common_vendor = require("../../common/vendor.js");
  6. var uni = common_vendor.index
  7. /********************** 路由跳转 **********************/
  8. //保留当前页面,跳转到应用内的某个页面
  9. function toUrl(url) {
  10. uni.showToast({
  11. //显示消息提示框 此处是提升用户体验的作用
  12. title: '加载中',
  13. icon: 'loading'
  14. });
  15. console.log('url:*****' + url);
  16. uni.navigateTo({
  17. url: url,
  18. complete: function(response) {
  19. uni.hideToast();
  20. }
  21. });
  22. } //关闭当前页面,返回上一页面或多级页面。
  23. function navigateBack(delta, successFunc = null, failFunc = null) {
  24. uni.navigateBack({
  25. delta: delta,
  26. success: function(res) {
  27. //接口调用成功的回调函数
  28. if (successFunc != null) {
  29. successFunc(res);
  30. }
  31. },
  32. fail: function(res) {
  33. //接口调用失败的回调函数
  34. if (failFunc != null) {
  35. failFunc(res);
  36. }
  37. },
  38. complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  39. });
  40. }
  41. /********************** showModalAlert ************************/
  42. function showModalAlert(content, successFunc = null, failFunc = null, title = '温馨提示', showCancel = false) {
  43. console.log("温馨提示", title, content != "")
  44. if (content != "") {
  45. if (content == 'timeout' || content == 'creatConnectionFailure') {
  46. content = "请重新打开OBU设备蓝牙后在手机上重新搜索蓝牙设备"
  47. }
  48. // if (content.indexOf("发送数据失败")) {
  49. // content = "OBU设备蓝牙已关闭,请返回到【选择蓝牙设备】界面重新连接蓝牙设备"
  50. // }
  51. uni.showModal({
  52. title: title,
  53. content: content,
  54. showCancel: showCancel,
  55. //是否显示取消按钮
  56. cancelText: '取消',
  57. //默认是“取消”
  58. cancelColor: theme.cancelModalColor,
  59. //取消文字的颜色
  60. confirmText: '确定',
  61. //默认是“确定”
  62. confirmColor: theme.modalColor,
  63. //确定文字的颜色
  64. success: function(res) {
  65. //接口调用成功的回调函数
  66. if (successFunc != null) {
  67. successFunc(res);
  68. }
  69. },
  70. fail: function(res) {
  71. //接口调用失败的回调函数
  72. if (failFunc != null) {
  73. failFunc(res);
  74. }
  75. },
  76. complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  77. });
  78. }
  79. }
  80. /*******************showToastAlert********************/
  81. function showToastAlert(title = '成功', icon = 'none', image = '', duration = 2000, mask = true, successFunc = null,
  82. failFunc = null, completeFun = null) {
  83. uni.showToast({
  84. title: title,
  85. icon: icon,
  86. //success显示成功图标,loading显示加载图标,none不显示图标
  87. image: image,
  88. duration: duration,
  89. mask: mask,
  90. ////是否显示透明蒙层,防止触摸穿透
  91. success: function(res) {
  92. //接口调用成功的回调函数
  93. if (successFunc != null) {
  94. successFunc(res);
  95. }
  96. },
  97. fail: function(res) {
  98. //接口调用失败的回调函数
  99. if (failFunc != null) {
  100. failFunc(res);
  101. }
  102. },
  103. complete: function(res) {
  104. //接口调用结束的回调函数(调用成功、失败都会执行)
  105. if (completeFun != null) {
  106. completeFun(res);
  107. }
  108. }
  109. });
  110. }
  111. /******************showLoadingAlert************************/
  112. function showLoadingAlert(title = '加载中...', mask = true, successFunc = null, failFunc = null, completeFun = null) {
  113. uni.showLoading({
  114. title: title,
  115. mask: mask,
  116. //是否显示透明蒙层,防止触摸穿透
  117. success: function(res) {
  118. //接口调用成功的回调函数
  119. if (successFunc != null) {
  120. successFunc(res);
  121. }
  122. },
  123. fail: function(res) {
  124. //接口调用失败的回调函数
  125. if (failFunc != null) {
  126. failFunc(res);
  127. }
  128. },
  129. complete: function(res) {
  130. //接口调用结束的回调函数(调用成功、失败都会执行)
  131. if (completeFun != null) {
  132. completeFun(res);
  133. }
  134. //添加安全锁,防止Loading不会关闭
  135. // setTimeout(() => {
  136. // hideLoadingAlert()
  137. // }, 5000)
  138. }
  139. });
  140. }
  141. function hideLoadingAlert(successFunc = null, failFunc = null, completeFun = null) {
  142. uni.hideLoading({
  143. success: function(res) {
  144. //接口调用成功的回调函数
  145. if (successFunc != null) {
  146. successFunc(res);
  147. }
  148. },
  149. fail: function(res) {
  150. //接口调用失败的回调函数
  151. if (failFunc != null) {
  152. failFunc(res);
  153. }
  154. },
  155. complete: function(res) {
  156. //接口调用结束的回调函数(调用成功、失败都会执行)
  157. if (completeFun != null) {
  158. completeFun(res);
  159. }
  160. }
  161. });
  162. } //签名
  163. function alertF(msg) {
  164. //隐藏加载框
  165. hideLoadingAlert(); //提示对话框
  166. showModalAlert(msg);
  167. }
  168. function alertFback(msg, backcall) {
  169. //隐藏加载框
  170. hideLoadingAlert(); //提示对话框
  171. showModalAlert(msg, backcall);
  172. }
  173. /**
  174. * 车牌数字转车牌中文
  175. */
  176. function vehiclePlateStr(num, successFun) {
  177. var vehicleColorStr;
  178. switch (num) {
  179. case 0:
  180. vehicleColorStr = '蓝色';
  181. successFun(vehicleColorStr);
  182. break;
  183. case 1:
  184. vehicleColorStr = '黄色';
  185. successFun(vehicleColorStr);
  186. break;
  187. case 2:
  188. vehicleColorStr = '黑色';
  189. successFun(vehicleColorStr);
  190. break;
  191. case 3:
  192. vehicleColorStr = '白色';
  193. successFun(vehicleColorStr);
  194. break;
  195. case 4:
  196. vehicleColorStr = '渐变绿色';
  197. successFun(vehicleColorStr);
  198. break;
  199. case 5:
  200. vehicleColorStr = '黄绿双拼色';
  201. successFun(vehicleColorStr);
  202. break;
  203. case 6:
  204. vehicleColorStr = '蓝白渐变色';
  205. successFun(vehicleColorStr);
  206. break;
  207. case 7:
  208. vehicleColorStr = '临时牌照';
  209. successFun(vehicleColorStr);
  210. break;
  211. case 9:
  212. vehicleColorStr = '未确定';
  213. successFun(vehicleColorStr);
  214. break;
  215. case 11:
  216. vehicleColorStr = '绿色';
  217. successFun(vehicleColorStr);
  218. break;
  219. case 12:
  220. vehicleColorStr = '红色';
  221. successFun(vehicleColorStr);
  222. break;
  223. default:
  224. vehicleColorStr = '未知';
  225. successFun(vehicleColorStr);
  226. break;
  227. }
  228. }
  229. //字符串加密
  230. function md5Str(str) {
  231. var _str = md5.i(str);
  232. return _str;
  233. }
  234. module.exports = {
  235. toUrl,
  236. navigateBack,
  237. showModalAlert,
  238. showToastAlert,
  239. showLoadingAlert,
  240. hideLoadingAlert,
  241. md5Str,
  242. alertF,
  243. alertFback,
  244. vehiclePlateStr
  245. };