選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

tools.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. import md5 from '../sys/md5.js';
  2. import sha1 from '../sys/sha1.js';
  3. import datas from './datas.js';
  4. import ksort from '../sys/ksort.js';
  5. import theme from '../../config/theme.js';
  6. import config from '../../config/config.js';
  7. import urlConfig from '../../config/urlConfig.js';
  8. import http from './http.js'; //身份类型
  9. const identityData = [{
  10. id: 101,
  11. name: '身份证(含临时身份证)'
  12. },
  13. {
  14. id: 102,
  15. name: '护照(限外籍人士)'
  16. },
  17. {
  18. id: 103,
  19. name: '港澳居民来往内地通行证'
  20. },
  21. {
  22. id: 104,
  23. name: '台湾居民来往大陆通行证'
  24. },
  25. {
  26. id: 105,
  27. name: '军官证'
  28. },
  29. {
  30. id: 106,
  31. name: '武警警察身份证'
  32. },
  33. {
  34. id: 201,
  35. name: '统一社会信用代码证书'
  36. },
  37. {
  38. id: 202,
  39. name: '组织机构代码证'
  40. },
  41. {
  42. id: 203,
  43. name: '营业执照'
  44. },
  45. {
  46. id: 204,
  47. name: '事业单位法人证书'
  48. },
  49. {
  50. id: 205,
  51. name: '社会团体法人登记证书'
  52. },
  53. {
  54. id: 206,
  55. name: '律师事务所执业许可证'
  56. },
  57. {
  58. id: 217,
  59. name: '公司商业登记副本(3个月内)'
  60. },
  61. {
  62. id: 218,
  63. name: '公司营业税单M8副本'
  64. },
  65. {
  66. id: 219,
  67. name: '公司营业税开业/更改M1副本'
  68. }
  69. ];
  70. const deviceModel = [{
  71. name: '万集',
  72. value: 'WJ'
  73. },
  74. {
  75. name: '聚利',
  76. value: 'JL'
  77. },
  78. {
  79. name: '金溢',
  80. value: 'JY'
  81. },
  82. {
  83. name: '埃特斯',
  84. value: 'AT'
  85. },
  86. {
  87. name: '建投',
  88. value: 'JT'
  89. },
  90. {
  91. name: '握奇',
  92. value: 'WQ'
  93. },
  94. {
  95. name: '成谷',
  96. value: 'CG'
  97. },
  98. {
  99. name: '天地融',
  100. value: 'TD'
  101. },
  102. {
  103. name: '智载',
  104. value: 'ZZ'
  105. }
  106. ];
  107. /********************** 路由跳转 **********************/
  108. //保留当前页面,跳转到应用内的某个页面
  109. function toUrl(url) {
  110. uni.showToast({
  111. //显示消息提示框 此处是提升用户体验的作用
  112. title: '加载中',
  113. icon: 'loading'
  114. }); // if (url.indexOf("?")==-1){
  115. // url += '?rand=' + datas.randomNum(1000,9999)
  116. // }else{
  117. // url += '&rand=' + datas.randomNum(1000,9999)
  118. // }
  119. console.log('url:*****' + url);
  120. uni.navigateTo({
  121. url: url,
  122. complete: function(response) {
  123. uni.hideToast();
  124. }
  125. });
  126. } //关闭当前页面,返回上一页面或多级页面。
  127. function navigateBack(delta, successFunc = null, failFunc = null) {
  128. uni.navigateBack({
  129. delta: delta,
  130. success: function(res) {
  131. //接口调用成功的回调函数
  132. if (successFunc != null) {
  133. successFunc(res);
  134. }
  135. },
  136. fail: function(res) {
  137. //接口调用失败的回调函数
  138. if (failFunc != null) {
  139. failFunc(res);
  140. }
  141. },
  142. complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  143. });
  144. }
  145. /********************** showModalAlert ************************/
  146. function showModalAlert(content, successFunc = null, failFunc = null, title = '温馨提示', showCancel = false) {
  147. uni.showModal({
  148. title: title,
  149. content: content,
  150. showCancel: showCancel,
  151. //是否显示取消按钮
  152. cancelText: '取消',
  153. //默认是“取消”
  154. cancelColor: theme.cancelModalColor,
  155. //取消文字的颜色
  156. confirmText: '确定',
  157. //默认是“确定”
  158. confirmColor: theme.modalColor,
  159. //确定文字的颜色
  160. success: function(res) {
  161. //接口调用成功的回调函数
  162. if (successFunc != null) {
  163. successFunc(res);
  164. }
  165. },
  166. fail: function(res) {
  167. //接口调用失败的回调函数
  168. if (failFunc != null) {
  169. failFunc(res);
  170. }
  171. },
  172. complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  173. });
  174. }
  175. /*******************showToastAlert********************/
  176. function showToastAlert(title = '成功', icon = 'none', image = '', duration = 2000, mask = true, successFunc = null,
  177. failFunc = null, completeFun = null) {
  178. uni.showToast({
  179. title: title,
  180. icon: icon,
  181. //success显示成功图标,loading显示加载图标,none不显示图标
  182. image: image,
  183. duration: duration,
  184. mask: mask,
  185. ////是否显示透明蒙层,防止触摸穿透
  186. success: function(res) {
  187. //接口调用成功的回调函数
  188. if (successFunc != null) {
  189. successFunc(res);
  190. }
  191. },
  192. fail: function(res) {
  193. //接口调用失败的回调函数
  194. if (failFunc != null) {
  195. failFunc(res);
  196. }
  197. },
  198. complete: function(res) {
  199. //接口调用结束的回调函数(调用成功、失败都会执行)
  200. if (completeFun != null) {
  201. completeFun(res);
  202. }
  203. }
  204. });
  205. }
  206. /******************showLoadingAlert************************/
  207. function showLoadingAlert(title = '加载中...', mask = true, successFunc = null, failFunc = null, completeFun = null) {
  208. uni.showLoading({
  209. title: title,
  210. mask: mask,
  211. //是否显示透明蒙层,防止触摸穿透
  212. success: function(res) {
  213. //接口调用成功的回调函数
  214. if (successFunc != null) {
  215. successFunc(res);
  216. }
  217. },
  218. fail: function(res) {
  219. //接口调用失败的回调函数
  220. if (failFunc != null) {
  221. failFunc(res);
  222. }
  223. },
  224. complete: function(res) {
  225. //接口调用结束的回调函数(调用成功、失败都会执行)
  226. if (completeFun != null) {
  227. completeFun(res);
  228. }
  229. }
  230. });
  231. }
  232. function hideLoadingAlert(successFunc = null, failFunc = null, completeFun = null) {
  233. uni.hideLoading({
  234. success: function(res) {
  235. //接口调用成功的回调函数
  236. if (successFunc != null) {
  237. successFunc(res);
  238. }
  239. },
  240. fail: function(res) {
  241. //接口调用失败的回调函数
  242. if (failFunc != null) {
  243. failFunc(res);
  244. }
  245. },
  246. complete: function(res) {
  247. //接口调用结束的回调函数(调用成功、失败都会执行)
  248. if (completeFun != null) {
  249. completeFun(res);
  250. }
  251. }
  252. });
  253. } //签名
  254. function sign(data, signCode) {
  255. data = ksort.ksort(data);
  256. var signStr = '';
  257. var requestId = false;
  258. for (let k in data) {
  259. if (k != 'sign') {
  260. if (k == 'requestId') {
  261. requestId = data[k];
  262. }
  263. signStr += k + '=' + data[k] + '&';
  264. }
  265. }
  266. signStr += 'signCode=' + signCode; // console.log("signStr*************"+signStr);
  267. if (!requestId) {
  268. return false;
  269. }
  270. signStr = md5.i(signStr);
  271. signStr = signStr.toUpperCase(); // console.log('MD5**************' + signStr);
  272. signStr += requestId; // console.log('requestId**************' + signStr);
  273. signStr = sha1.i(signStr);
  274. signStr = signStr.toUpperCase(); // console.log('SHA1**************' + signStr);
  275. return signStr;
  276. } //字符串加密
  277. function md5Str(str) {
  278. var _str = md5.i(str);
  279. return _str;
  280. }
  281. function sha1Str(str) {
  282. var _str = sha1.i(str);
  283. return _str;
  284. } //加载
  285. // function loading(msg = "加载中") {
  286. // uni.showToast({ //显示消息提示框 此处是提升用户体验的作用
  287. // title: msg,
  288. // icon: 'loading',
  289. // duration: 60000, //提示的延迟时间
  290. // mask: true, //是否显示透明蒙层,防止触摸穿透
  291. // });
  292. // }
  293. //对话
  294. // function showAlertv2(content, func = nu l l, titl e = "温馨提示") {
  295. // uni.hideLoading();
  296. // uni.showModal({
  297. // title: title,
  298. // content: content,
  299. // showCancel : false,//是否显示取消按钮
  300. // cancelTex "否",//默认是“取消”
  301. // cancelColor: theme.modalColo//取消文字的颜色
  302. // confirmText: "确定",//默认是“确定”
  303. // confirmColor: theme.modalColor,//确定文字的颜色
  304. // success: function (res) {
  305. // if (func != null) {
  306. // func(res);
  307. // }
  308. // },
  309. // fail: function (res) { },//接口调用失败的回调函数
  310. // complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  311. // })
  312. // }
  313. //公用的获取车牌颜色
  314. function getVehicleColor(callback) {
  315. http.sendPostv2(config.serviceMiniURL + urlConfig.vehiclePlateColor, {}, function(res) {
  316. if (res.rc != '00') {
  317. return;
  318. }
  319. if (callback != null) {
  320. callback(res);
  321. }
  322. });
  323. }
  324. function getVehicleColorBYcode(code, callback) {
  325. getVehicleColor(function(res) {
  326. callback(
  327. res.rd.filter((item) => {
  328. return item.code == code;
  329. })[0].name
  330. );
  331. });
  332. } //获取开户行
  333. function getEtcBankList(callback) {
  334. http.sendPostv2(config.aftersaleURL + urlConfig.etcBankList, {}, function(res) {
  335. if (res.rc != '00') {
  336. alertF(res.rm);
  337. return;
  338. }
  339. if (callback != null) {
  340. callback(res.rd);
  341. }
  342. });
  343. }
  344. /**
  345. * 判断用户是否关注公众号
  346. */
  347. function isFollow(callback) {
  348. var requestData = new Array();
  349. requestData['openId'] = datas.getData('wxOpenId');
  350. var requestData = datas.arrayToJson(requestData);
  351. http.sendPostv2(config.etcNewUrl + urlConfig.isFollow, requestData, function(res) {
  352. if (res.rc != '00') {
  353. alertF(res.rm);
  354. return;
  355. }
  356. if (callback != null) {
  357. callback(res.rd.subscribe);
  358. }
  359. });
  360. }
  361. function alertF(msg) {
  362. //隐藏加载框
  363. hideLoadingAlert(); //提示对话框
  364. showModalAlert(msg);
  365. }
  366. function alertFback(msg, backcall) {
  367. //隐藏加载框
  368. hideLoadingAlert(); //提示对话框
  369. showModalAlert(msg, backcall);
  370. }
  371. /*
  372. 调用核心接口,外层接口共用(暂用于发票模块)
  373. */
  374. function coreInter(url, param, successFun, failFun) {
  375. var initSignUrl = config.zeusURL + urlConfig.htlUrl;
  376. var requestData = new Array();
  377. requestData['requestId'] = datas.getDate() + datas.generateMixed(10);
  378. requestData['accessCode'] = 'etc';
  379. requestData['distinction'] = url;
  380. requestData['data'] = JSON.stringify(param);
  381. requestData['sign'] = sign(requestData, config._signCode);
  382. var requestData = datas.arrayToJson(requestData);
  383. showLoadingAlert('加载中');
  384. http.sendPostv2(initSignUrl, requestData, function(res) {
  385. hideLoadingAlert();
  386. if (res.rc != '00') {
  387. alertF(res.rm);
  388. return;
  389. }
  390. if (!res.rd.success) {
  391. failFun ? failFun() : alertF(res.rd.msg);
  392. return;
  393. }
  394. successFun(res);
  395. });
  396. }
  397. /**
  398. * 车牌数字转车牌中文
  399. */
  400. function vehiclePlateStr(num, successFun) {
  401. var vehicleColorStr;
  402. switch (num) {
  403. case 0:
  404. vehicleColorStr = '蓝色';
  405. successFun(vehicleColorStr);
  406. break;
  407. case 1:
  408. vehicleColorStr = '黄色';
  409. successFun(vehicleColorStr);
  410. break;
  411. case 2:
  412. vehicleColorStr = '黑色';
  413. successFun(vehicleColorStr);
  414. break;
  415. case 3:
  416. vehicleColorStr = '白色';
  417. successFun(vehicleColorStr);
  418. break;
  419. case 4:
  420. vehicleColorStr = '渐变绿色';
  421. successFun(vehicleColorStr);
  422. break;
  423. case 5:
  424. vehicleColorStr = '黄绿双拼色';
  425. successFun(vehicleColorStr);
  426. break;
  427. case 6:
  428. vehicleColorStr = '蓝白渐变色';
  429. successFun(vehicleColorStr);
  430. break;
  431. case 7:
  432. vehicleColorStr = '临时牌照';
  433. successFun(vehicleColorStr);
  434. break;
  435. case 9:
  436. vehicleColorStr = '未确定';
  437. successFun(vehicleColorStr);
  438. break;
  439. case 11:
  440. vehicleColorStr = '绿色';
  441. successFun(vehicleColorStr);
  442. break;
  443. case 12:
  444. vehicleColorStr = '红色';
  445. successFun(vehicleColorStr);
  446. break;
  447. default:
  448. vehicleColorStr = '未知';
  449. successFun(vehicleColorStr);
  450. break;
  451. }
  452. }
  453. module.exports = {
  454. coreInter,
  455. toUrl,
  456. navigateBack,
  457. showModalAlert,
  458. showToastAlert,
  459. showLoadingAlert,
  460. hideLoadingAlert,
  461. sign,
  462. getVehicleColor,
  463. getVehicleColorBYcode,
  464. getEtcBankList,
  465. // showAlertv2,
  466. // loading,
  467. md5Str,
  468. sha1Str,
  469. alertF,
  470. alertFback,
  471. identityData,
  472. deviceModel,
  473. isFollow,
  474. vehiclePlateStr
  475. };