import md5 from './md5.js'; // import sha1 from '../sys/sha1.js'; import datas from './datas.js'; import theme from './theme.js'; const common_vendor = require("../../common/vendor.js"); var uni = common_vendor.index /********************** 路由跳转 **********************/ //保留当前页面,跳转到应用内的某个页面 function toUrl(url) { uni.showToast({ //显示消息提示框 此处是提升用户体验的作用 title: '加载中', icon: 'loading' }); console.log('url:*****' + url); uni.navigateTo({ url: url, complete: function(response) { uni.hideToast(); } }); } //关闭当前页面,返回上一页面或多级页面。 function navigateBack(delta, successFunc = null, failFunc = null) { uni.navigateBack({ delta: delta, success: function(res) { //接口调用成功的回调函数 if (successFunc != null) { successFunc(res); } }, fail: function(res) { //接口调用失败的回调函数 if (failFunc != null) { failFunc(res); } }, complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行) }); } /********************** showModalAlert ************************/ function showModalAlert(content, successFunc = null, failFunc = null, title = '温馨提示', showCancel = false) { console.log("温馨提示", title, content != "") if (content != "") { if (content == 'timeout' || content == 'creatConnectionFailure') { content = "请重新打开OBU设备蓝牙后在手机上重新搜索蓝牙设备" } // if (content.indexOf("发送数据失败")) { // content = "OBU设备蓝牙已关闭,请返回到【选择蓝牙设备】界面重新连接蓝牙设备" // } uni.showModal({ title: title, content: content, showCancel: showCancel, //是否显示取消按钮 cancelText: '取消', //默认是“取消” cancelColor: theme.cancelModalColor, //取消文字的颜色 confirmText: '确定', //默认是“确定” confirmColor: theme.modalColor, //确定文字的颜色 success: function(res) { //接口调用成功的回调函数 if (successFunc != null) { successFunc(res); } }, fail: function(res) { //接口调用失败的回调函数 if (failFunc != null) { failFunc(res); } }, complete: function(res) {} //接口调用结束的回调函数(调用成功、失败都会执行) }); } } /*******************showToastAlert********************/ function showToastAlert(title = '成功', icon = 'none', image = '', duration = 2000, mask = true, successFunc = null, failFunc = null, completeFun = null) { uni.showToast({ title: title, icon: icon, //success显示成功图标,loading显示加载图标,none不显示图标 image: image, duration: duration, mask: mask, ////是否显示透明蒙层,防止触摸穿透 success: function(res) { //接口调用成功的回调函数 if (successFunc != null) { successFunc(res); } }, fail: function(res) { //接口调用失败的回调函数 if (failFunc != null) { failFunc(res); } }, complete: function(res) { //接口调用结束的回调函数(调用成功、失败都会执行) if (completeFun != null) { completeFun(res); } } }); } /******************showLoadingAlert************************/ function showLoadingAlert(title = '加载中...', mask = true, successFunc = null, failFunc = null, completeFun = null) { uni.showLoading({ title: title, mask: mask, //是否显示透明蒙层,防止触摸穿透 success: function(res) { //接口调用成功的回调函数 if (successFunc != null) { successFunc(res); } }, fail: function(res) { //接口调用失败的回调函数 if (failFunc != null) { failFunc(res); } }, complete: function(res) { //接口调用结束的回调函数(调用成功、失败都会执行) if (completeFun != null) { completeFun(res); } //添加安全锁,防止Loading不会关闭 // setTimeout(() => { // hideLoadingAlert() // }, 5000) } }); } function hideLoadingAlert(successFunc = null, failFunc = null, completeFun = null) { uni.hideLoading({ success: function(res) { //接口调用成功的回调函数 if (successFunc != null) { successFunc(res); } }, fail: function(res) { //接口调用失败的回调函数 if (failFunc != null) { failFunc(res); } }, complete: function(res) { //接口调用结束的回调函数(调用成功、失败都会执行) if (completeFun != null) { completeFun(res); } } }); } //签名 function alertF(msg) { //隐藏加载框 hideLoadingAlert(); //提示对话框 showModalAlert(msg); } function alertFback(msg, backcall) { //隐藏加载框 hideLoadingAlert(); //提示对话框 showModalAlert(msg, backcall); } /** * 车牌数字转车牌中文 */ function vehiclePlateStr(num, successFun) { var vehicleColorStr; switch (num) { case 0: vehicleColorStr = '蓝色'; successFun(vehicleColorStr); break; case 1: vehicleColorStr = '黄色'; successFun(vehicleColorStr); break; case 2: vehicleColorStr = '黑色'; successFun(vehicleColorStr); break; case 3: vehicleColorStr = '白色'; successFun(vehicleColorStr); break; case 4: vehicleColorStr = '渐变绿色'; successFun(vehicleColorStr); break; case 5: vehicleColorStr = '黄绿双拼色'; successFun(vehicleColorStr); break; case 6: vehicleColorStr = '蓝白渐变色'; successFun(vehicleColorStr); break; case 7: vehicleColorStr = '临时牌照'; successFun(vehicleColorStr); break; case 9: vehicleColorStr = '未确定'; successFun(vehicleColorStr); break; case 11: vehicleColorStr = '绿色'; successFun(vehicleColorStr); break; case 12: vehicleColorStr = '红色'; successFun(vehicleColorStr); break; default: vehicleColorStr = '未知'; successFun(vehicleColorStr); break; } } //字符串加密 function md5Str(str) { var _str = md5.i(str); return _str; } module.exports = { toUrl, navigateBack, showModalAlert, showToastAlert, showLoadingAlert, hideLoadingAlert, md5Str, alertF, alertFback, vehiclePlateStr };