filter.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import Vue from 'vue'
  2. //保留两位小数
  3. Vue.filter('keepTwoNum',function(val){
  4. let value = Number(val)
  5. return value.toFixed(2)
  6. });
  7. //格式化数字三位加一逗号
  8. Vue.filter('NumFormat', function(value) {
  9. if(!value) return '';
  10. /*原来用的是Number(value).toFixed(0),这样取整时有问题,例如0.51取整之后为1 */
  11. /*后来改成了 Number(value)|0,但是输入超过十一位就为负数了 */
  12. var intPart = Number(value) - Number(value)%1; //获取整数部分
  13. var intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
  14. return intPartFormat;
  15. });
  16. //链接加时间戳
  17. Vue.filter("timestamp", function(link) {
  18. return link + '?t=' + new Date().getTime();
  19. });
  20. //截取第一张照片且判断是否有图片,没有图片输入默认图片
  21. Vue.filter("firstImg",function(arr,sizeType,imgType){
  22. //图片类型判断
  23. if(arr){
  24. if(arr instanceof Array){
  25. img = arr[0]
  26. }else{
  27. img = arr.split(',')[0]
  28. }
  29. }else if(!arr){
  30. //如果没有图片则随机输出一张
  31. // if(imgType === 'farmer'){
  32. // const farmerList = ['carbon2/farmer/1.png','carbon2/farmer/2.png']
  33. // img = farmerList[Math.floor(Math.random() * farmerList.length)];
  34. // }
  35. // img = '/static/img/inbuild.png'
  36. }
  37. // return config.imgUrl + img;
  38. return img;
  39. });
  40. //七牛云压缩图片
  41. Vue.filter("miniImg",function(img,quality){
  42. return img+'?imageMogr2/quality/'+quality
  43. });
  44. //单位米m转换为单位千米km,提醒:传递参数不要带引号,如kmUnit('100')会返回0m。
  45. Vue.filter("kmUnit",function(m){
  46. var v;
  47. if(typeof m === 'number' && !isNaN(m)){
  48. if (m >= 1000) {
  49. v = (m / 1000).toFixed(2) + 'km'
  50. } else {
  51. v = m + 'm'
  52. }
  53. }else{
  54. v = '0m'
  55. }
  56. return v;
  57. });
  58. // 订单状态
  59. Vue.filter("filterOrderStatus",function(status){
  60. status = Number(status);
  61. switch (status){
  62. case 1:
  63. return '停放中'
  64. break;
  65. case 2:
  66. return '出场'
  67. break;
  68. case 3:
  69. return '欠费'
  70. break;
  71. case 4:
  72. return '已完成'
  73. break;
  74. default:
  75. return '未知'
  76. break;
  77. }
  78. });
  79. // 支付状态
  80. Vue.filter("filterPayStatus",function(status){
  81. status = Number(status);
  82. switch (status){
  83. case 0:
  84. return '未支付'
  85. break;
  86. case 1:
  87. return '已支付'
  88. break;
  89. case 2:
  90. return '支付中'
  91. break;
  92. case 3:
  93. return '支付失败'
  94. break;
  95. default:
  96. return '未知'
  97. break;
  98. }
  99. });
  100. // 汽车类型
  101. Vue.filter("energyTpye",function(value){
  102. let status = Number(value);
  103. switch (status){
  104. case 1:
  105. return '汽油车'
  106. break;
  107. case 2:
  108. return '新能源'
  109. break;
  110. default:
  111. return '汽油车'
  112. break;
  113. }
  114. });
  115. // 设配类型
  116. Vue.filter("deviceType",function(value){
  117. let status = Number(value);
  118. switch (status){
  119. case 1:
  120. return '地磁'
  121. break;
  122. case 2:
  123. return '车位锁'
  124. break;
  125. case 3:
  126. return '栏杆道闸'
  127. break;
  128. default:
  129. return '未知'
  130. break;
  131. }
  132. });
  133. // 设配状态
  134. Vue.filter("deviceStatus",function(value){
  135. let status = Number(value);
  136. switch (status){
  137. case 0:
  138. return '异常'
  139. break;
  140. case 1:
  141. return '正常'
  142. break;
  143. default:
  144. return '未知'
  145. break;
  146. }
  147. });
  148. // 车位锁设配状态
  149. Vue.filter("device2Status",function(value){
  150. let status = Number(value);
  151. switch (status){
  152. case 0:
  153. return '降板'
  154. break;
  155. case 1:
  156. return '升板'
  157. break;
  158. case 2:
  159. return '心跳'
  160. break;
  161. case 5:
  162. return '车辆入位'
  163. break;
  164. case 6:
  165. return '车辆出位'
  166. break;
  167. case 7:
  168. return '复位'
  169. break;
  170. case 8:
  171. return '逃费'
  172. break;
  173. case 10:
  174. return '状态上报'
  175. break;
  176. default:
  177. return '未知'
  178. break;
  179. }
  180. });
  181. // 查看设备事件信息事件类型
  182. Vue.filter("deviceLogMsgType",function(value){
  183. let status = Number(value);
  184. switch (status){
  185. case 0:
  186. return '事件帧'
  187. break;
  188. case 1:
  189. return '心跳帧'
  190. break;
  191. default:
  192. return '未知'
  193. break;
  194. }
  195. });
  196. // 消息类型
  197. Vue.filter("filterMsgType",function(value){
  198. let status = Number(value);
  199. switch (status){
  200. case 0:
  201. return '欠费车入场通知'
  202. break;
  203. case 1:
  204. return '异常上报评价通知'
  205. break;
  206. default:
  207. return '未知'
  208. break;
  209. }
  210. });
  211. // 处理状态
  212. Vue.filter("filterIsProcess",function(value){
  213. let status = Number(value);
  214. switch (status){
  215. case 0:
  216. return '未处理'
  217. break;
  218. case 1:
  219. return '已处理'
  220. break;
  221. case 2:
  222. return '部分处理'
  223. break;
  224. default:
  225. return '请选择'
  226. break;
  227. }
  228. });