123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- import Vue from 'vue'
- //保留两位小数
- Vue.filter('keepTwoNum',function(val){
- let value = Number(val)
- return value.toFixed(2)
- });
- //格式化数字三位加一逗号
- Vue.filter('NumFormat', function(value) {
- if(!value) return '';
- /*原来用的是Number(value).toFixed(0),这样取整时有问题,例如0.51取整之后为1 */
- /*后来改成了 Number(value)|0,但是输入超过十一位就为负数了 */
- var intPart = Number(value) - Number(value)%1; //获取整数部分
- var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
- return intPartFormat;
- });
- //链接加时间戳
- Vue.filter("timestamp", function(link) {
- return link + '?t=' + new Date().getTime();
- });
- //截取第一张照片且判断是否有图片,没有图片输入默认图片
- Vue.filter("firstImg",function(arr,sizeType,imgType){
- //图片类型判断
- if(arr){
- if(arr instanceof Array){
- img = arr[0]
- }else{
- img = arr.split(',')[0]
- }
- }else if(!arr){
- //如果没有图片则随机输出一张
- // if(imgType === 'farmer'){
- // const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png']
- // img = farmerList[Math.floor(Math.random() * farmerList.length)];
- // }
- // img = '/static/img/inbuild.png'
- }
- // return config.imgUrl + img;
- return img;
- });
- //七牛云压缩图片
- Vue.filter("miniImg",function(img,quality){
- return img+'?imageMogr2/quality/'+quality
- });
- //单位米m转换为单位千米km,提醒:传递参数不要带引号,如kmUnit('100')会返回0m。
- Vue.filter("kmUnit",function(m){
- var v;
- if(typeof m === 'number' && !isNaN(m)){
- if (m >= 1000) {
- v = (m / 1000).toFixed(2) + 'km'
- } else {
- v = m + 'm'
- }
- }else{
- v = '0m'
- }
- return v;
- });
- // 订单状态
- Vue.filter("filterOrderStatus",function(status){
- status = Number(status);
- switch (status){
- case 1:
- return '停放中'
- break;
- case 2:
- return '出场'
- break;
- case 3:
- return '欠费'
- break;
- case 4:
- return '已完成'
- break;
- default:
- return '未知'
- break;
- }
-
- });
- // 支付状态
- Vue.filter("filterPayStatus",function(status){
- status = Number(status);
- switch (status){
- case 0:
- return '未支付'
- break;
- case 1:
- return '已支付'
- break;
- case 2:
- return '支付中'
- break;
- case 3:
- return '支付失败'
- break;
- default:
- return '未知'
- break;
- }
-
- });
- // 汽车类型
- Vue.filter("energyTpye",function(value){
- let status = Number(value);
- switch (status){
- case 1:
- return '汽油车'
- break;
- case 2:
- return '新能源'
- break;
- default:
- return '汽油车'
- break;
- }
-
- });
- // 设配类型
- Vue.filter("deviceType",function(value){
- let status = Number(value);
- switch (status){
- case 1:
- return '地磁'
- break;
- case 2:
- return '车位锁'
- break;
- case 3:
- return '栏杆道闸'
- break;
- default:
- return '未知'
- break;
- }
- });
- // 设配状态
- Vue.filter("deviceStatus",function(value){
- let status = Number(value);
- switch (status){
- case 0:
- return '异常'
- break;
- case 1:
- return '正常'
- break;
- default:
- return '未知'
- break;
- }
- });
- // 车位锁设配状态
- Vue.filter("device2Status",function(value){
- let status = Number(value);
- switch (status){
- case 0:
- return '降板'
- break;
- case 1:
- return '升板'
- break;
- case 2:
- return '心跳'
- break;
- case 5:
- return '车辆入位'
- break;
- case 6:
- return '车辆出位'
- break;
- case 7:
- return '复位'
- break;
- case 8:
- return '逃费'
- break;
- case 10:
- return '状态上报'
- break;
- default:
- return '未知'
- break;
- }
- });
- // 查看设备事件信息事件类型
- Vue.filter("deviceLogMsgType",function(value){
- let status = Number(value);
- switch (status){
- case 0:
- return '事件帧'
- break;
- case 1:
- return '心跳帧'
- break;
- default:
- return '未知'
- break;
- }
- });
- // 消息类型
- Vue.filter("filterMsgType",function(value){
- let status = Number(value);
- switch (status){
- case 0:
- return '欠费车入场通知'
- break;
- case 1:
- return '异常上报评价通知'
- break;
- default:
- return '未知'
- break;
- }
- });
- // 处理状态
- Vue.filter("filterIsProcess",function(value){
- let status = Number(value);
- switch (status){
- case 0:
- return '未处理'
- break;
- case 1:
- return '已处理'
- break;
- case 2:
- return '部分处理'
- break;
- default:
- return '请选择'
- break;
- }
- });
|