开始做登录
This commit is contained in:
12
miniprogram_npm/@vant/weapp/wxs/add-unit.wxs
Normal file
12
miniprogram_npm/@vant/weapp/wxs/add-unit.wxs
Normal file
@@ -0,0 +1,12 @@
|
||||
/* eslint-disable */
|
||||
var REGEXP = getRegExp('^-?\d+(\.\d+)?$');
|
||||
|
||||
function addUnit(value) {
|
||||
if (value == null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return REGEXP.test('' + value) ? value + 'px' : value;
|
||||
}
|
||||
|
||||
module.exports = addUnit;
|
5
miniprogram_npm/@vant/weapp/wxs/array.wxs
Normal file
5
miniprogram_npm/@vant/weapp/wxs/array.wxs
Normal file
@@ -0,0 +1,5 @@
|
||||
function isArray(array) {
|
||||
return array && array.constructor === 'Array';
|
||||
}
|
||||
|
||||
module.exports.isArray = isArray;
|
39
miniprogram_npm/@vant/weapp/wxs/bem.wxs
Normal file
39
miniprogram_npm/@vant/weapp/wxs/bem.wxs
Normal file
@@ -0,0 +1,39 @@
|
||||
/* eslint-disable */
|
||||
var array = require('./array.wxs');
|
||||
var object = require('./object.wxs');
|
||||
var PREFIX = 'van-';
|
||||
|
||||
function join(name, mods) {
|
||||
name = PREFIX + name;
|
||||
mods = mods.map(function(mod) {
|
||||
return name + '--' + mod;
|
||||
});
|
||||
mods.unshift(name);
|
||||
return mods.join(' ');
|
||||
}
|
||||
|
||||
function traversing(mods, conf) {
|
||||
if (!conf) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof conf === 'string' || typeof conf === 'number') {
|
||||
mods.push(conf);
|
||||
} else if (array.isArray(conf)) {
|
||||
conf.forEach(function(item) {
|
||||
traversing(mods, item);
|
||||
});
|
||||
} else if (typeof conf === 'object') {
|
||||
object.keys(conf).forEach(function(key) {
|
||||
conf[key] && mods.push(key);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function bem(name, conf) {
|
||||
var mods = [];
|
||||
traversing(mods, conf);
|
||||
return join(name, mods);
|
||||
}
|
||||
|
||||
module.exports = bem;
|
55
miniprogram_npm/@vant/weapp/wxs/memoize.wxs
Normal file
55
miniprogram_npm/@vant/weapp/wxs/memoize.wxs
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Simple memoize
|
||||
* wxs doesn't support fn.apply, so this memoize only support up to 2 args
|
||||
*/
|
||||
/* eslint-disable */
|
||||
|
||||
function isPrimitive(value) {
|
||||
var type = typeof value;
|
||||
return (
|
||||
type === 'boolean' ||
|
||||
type === 'number' ||
|
||||
type === 'string' ||
|
||||
type === 'undefined' ||
|
||||
value === null
|
||||
);
|
||||
}
|
||||
|
||||
// mock simple fn.call in wxs
|
||||
function call(fn, args) {
|
||||
if (args.length === 2) {
|
||||
return fn(args[0], args[1]);
|
||||
}
|
||||
|
||||
if (args.length === 1) {
|
||||
return fn(args[0]);
|
||||
}
|
||||
|
||||
return fn();
|
||||
}
|
||||
|
||||
function serializer(args) {
|
||||
if (args.length === 1 && isPrimitive(args[0])) {
|
||||
return args[0];
|
||||
}
|
||||
var obj = {};
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
obj['key' + i] = args[i];
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
|
||||
function memoize(fn) {
|
||||
var cache = {};
|
||||
|
||||
return function() {
|
||||
var key = serializer(arguments);
|
||||
if (cache[key] === undefined) {
|
||||
cache[key] = call(fn, arguments);
|
||||
}
|
||||
|
||||
return cache[key];
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = memoize;
|
13
miniprogram_npm/@vant/weapp/wxs/object.wxs
Normal file
13
miniprogram_npm/@vant/weapp/wxs/object.wxs
Normal file
@@ -0,0 +1,13 @@
|
||||
/* eslint-disable */
|
||||
var REGEXP = getRegExp('{|}|"', 'g');
|
||||
|
||||
function keys(obj) {
|
||||
return JSON.stringify(obj)
|
||||
.replace(REGEXP, '')
|
||||
.split(',')
|
||||
.map(function(item) {
|
||||
return item.split(':')[0];
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.keys = keys;
|
42
miniprogram_npm/@vant/weapp/wxs/style.wxs
Normal file
42
miniprogram_npm/@vant/weapp/wxs/style.wxs
Normal file
@@ -0,0 +1,42 @@
|
||||
/* eslint-disable */
|
||||
var object = require('./object.wxs');
|
||||
var array = require('./array.wxs');
|
||||
|
||||
function kebabCase(word) {
|
||||
var newWord = word
|
||||
.replace(getRegExp("[A-Z]", 'g'), function (i) {
|
||||
return '-' + i;
|
||||
})
|
||||
.toLowerCase()
|
||||
|
||||
return newWord;
|
||||
}
|
||||
|
||||
function style(styles) {
|
||||
if (array.isArray(styles)) {
|
||||
return styles
|
||||
.filter(function (item) {
|
||||
return item != null && item !== '';
|
||||
})
|
||||
.map(function (item) {
|
||||
return style(item);
|
||||
})
|
||||
.join(';');
|
||||
}
|
||||
|
||||
if ('Object' === styles.constructor) {
|
||||
return object
|
||||
.keys(styles)
|
||||
.filter(function (key) {
|
||||
return styles[key] != null && styles[key] !== '';
|
||||
})
|
||||
.map(function (key) {
|
||||
return [kebabCase(key), [styles[key]]].join(':');
|
||||
})
|
||||
.join(';');
|
||||
}
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
module.exports = style;
|
10
miniprogram_npm/@vant/weapp/wxs/utils.wxs
Normal file
10
miniprogram_npm/@vant/weapp/wxs/utils.wxs
Normal file
@@ -0,0 +1,10 @@
|
||||
/* eslint-disable */
|
||||
var bem = require('./bem.wxs');
|
||||
var memoize = require('./memoize.wxs');
|
||||
var addUnit = require('./add-unit.wxs');
|
||||
|
||||
module.exports = {
|
||||
bem: memoize(bem),
|
||||
memoize: memoize,
|
||||
addUnit: addUnit
|
||||
};
|
Reference in New Issue
Block a user