vue-filter.js 950 Bytes
let Vue = require('yoho-vue');


/**
 * 替换参数
 *
 * @example
 *   value = /{width}/{height}/{mode}
 *
 *   {value | resize 100 200 2}  ==> /100/200/2
 */
Vue.filter('resize', (value, width, height, mode)=> {
    return value ? value.replace(/(\{width}|\{height}|\{mode})/g, function($0) {
        const dict = {
            '{width}': width,
            '{height}': height,
            '{mode}': mode || 2
        };

        return dict[$0];
    }) : '';
});

/**
 * 性别款式
 *
 * @example
 *
 *  {value | gender}
 */
Vue.filter('clothingGenderIdentity', (value)=> {
    let ret = null;

    switch (value) {
        case 1:
            ret = '男款';
            break;
        case 2:
            ret = '女款';
            break;
        default:
            ret = '通用';
    }

    return ret;
});

/**
 * 品牌URL
 *
 * @param value brand domain
 */
Vue.filter('brandUrl', (value)=> {
    return `/brand?domain=${value}`;
});