123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- /**
- * 公共方法的封装
- */
- import Vue from 'vue'
- // 性别
- Vue.filter("filterSex", function(val) {
- if(val == 1){
- return '男';
- }else if(val == 2){
- return '女';
- }else {
- return '未知';
- }
- });
- // 链接加时间戳
- Vue.filter("timestamp", function(link) {
- return link + '?t=' + new Date().getTime();
- });
- // 保留两位小数,自动补充零
- Vue.filter("filterToFixed", function(val) {
- var value=Math.round(parseFloat(val)*100)/100;
- if(!value){return '0'}
- var xsd=value.toString().split(".");
- if(xsd.length==1){
- value=value.toString()+".00";
- return value;
- }
- if(xsd.length>1){
- if(xsd[1].length<2){
- value=value.toString()+"0";
- }
- return value;
- }
- })
- // 订单状态
- Vue.filter("filterOrderState", function(val) {
- let orderList = ['待支付', '','超时取消', '待使用', '退款中', '己退款', '退款失败', '己使用', '己超期','己关闭']
- return orderList[val]
- });
- // 个人二维码状态
- Vue.filter("filterSingleState", function(val) {
- let list = ['未使用', '已使用','作废']
- return list[val]
- });
- // 退款状态
- Vue.filter("filterRefundState", function(val) {
- console.log('filterRefundState',val);
- if(!val){
- return false
- }
- let list = ['申请中', '退款成功','退款失败', '退款中']
- return list[val]
- });
- // 支付状态
- Vue.filter("filterPayState", function(val) {
- let orderList = ['未支付', '已支付','支付中', '支付失败', '支付退款']
- return orderList[val]
- });
- // 结账方式
- Vue.filter("filterPayType", function(val) {
- let payTypeList = ['', '微信', '余额', '积分','农商行支付'];
- return payTypeList[val]
- });
- // 物流状态
- Vue.filter("filterDilevery", function(val) {
- let dileveryList = ['下单', '揽件', '运输中', '派件中', '签收', '退回', '拒签']
- return dileveryList[val]
- });
- // 退款状态
- Vue.filter("filterRefundState", function(val) {
- let rundStateList = ['申请中', '退款成功', '退款失败', '退款中']
- return rundStateList[val]
- });
- // 评分文字
- Vue.filter("rateText", function(val) {
- let rateList = ['很差', '差', '一般', '很好', '非常好']
- return rateList[val-1]
- });
- // 支持的物流方式
- Vue.filter("filterLogisticsType", function(val) {
- let logisticsType = ['邮寄', '自提', '同城配送']
- return logisticsType[val]
- });
- // js手机号码中间4位变星星
- Vue.filter("hidePhoneNumber", function(val) {
- return val?val.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2"):'';
- });
- // 保质期转换
- Vue.filter("filterPeriod", function(day) {
- if (!day) return;
- const unitObj = {
- 年: 365,
- 月: 30,
- 日: 1
- };
- for (const key in unitObj) {
- if (day % unitObj[key] === 0) {
- return `${day / unitObj[key]}${key}`;
- }
- }
- });
- // 身份证加密显示
- Vue.filter('maskID', function(value) {
- if (value.length != 18) {
- // 如果身份证号码不是18位,直接返回原始值
- return value;
- }
- const front = value.slice(0, 6); // 取身份证号码前6位
- const tail = value.slice(-4); // 取身份证号码后4位
- const masked = '*'.repeat(value.length - 10); // 中间部分用星号替代
- return front + masked + tail;
- });
- // 判断如果是今天就返回今天,如果是明天就返回明天如果都不是就返回星期几
- Vue.filter('checkDate', function(date) {
- let today = new Date(); // 获取今天的日期
- date = new Date(date);
-
- if (date.getFullYear() === today.getFullYear() &&
- date.getMonth() === today.getMonth() &&
- date.getDate() === today.getDate()) {
- return "今天";
- } else if (date.getFullYear() === today.getFullYear() &&
- date.getMonth() === today.getMonth() &&
- date.getDate() === today.getDate() + 1) {
- return "明天";
- } else {
- let days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
- let diffDays = Math.floor((date.getTime() - today.getTime()) / (1000 * 3600 * 24));
- if (diffDays > 7) {
- // return date.toLocaleDateString("zh-CN");
- return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
- } else {
- return days[date.getDay()];
- }
- }
- });
- // 判断如果是今天就返回今天,如果是明天就返回明天如果都不是就返回星期几
- Vue.filter('checkWeekDate', function(date) {
- let today = new Date(); // 获取今天的日期
- date = new Date(date);
-
- if (date.getFullYear() === today.getFullYear() &&
- date.getMonth() === today.getMonth() &&
- date.getDate() === today.getDate()) {
- return "今天";
- } else if (date.getFullYear() === today.getFullYear() &&
- date.getMonth() === today.getMonth() &&
- date.getDate() === today.getDate() + 1) {
- return "明天";
- } else {
- let days = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
- let diffDays = Math.floor((date.getTime() - today.getTime()) / (1000 * 3600 * 24));
- return days[date.getDay()];
- }
- });
|