Commit caee03a6 authored by Antoor's avatar Antoor Committed by GitHub

Merge pull request #62 from antoor/v2.0-beta-random-encoder

v2.0-beta::random encoder features
parents 9c156004 fda78468
......@@ -20,12 +20,35 @@ class Base {
opts['encode'] = opts['encode'] || 'utf8';
opts['encoder'] = opts['encoder'] || 'default';
this.__opts__ = opts;
// 默认编码器
this['__encoder__'] = {
/**
* 默认编码器
* @param {String} pwd 连接密码
* @param {Object} data 请求数据
* @return {Object} 生成数据
*/
default(pwd, data) {
data[pwd] = data['_'];
delete data['_'];
return data;
},
/**
* 随机编码器
* @param {String} pwd 连接密码
* @param {Object} data 请求数据
* @return {Object} 生成数据
*/
random(pwd, data) {
let _encoders = [];
for (let _ in this) {
if (_ === 'random') { continue }
_encoders.push(_);
}
let _index = parseInt(Math.random() * _encoders.length);
return this[
_encoders[_index]
](pwd, data);
}
}
}
......
......@@ -200,6 +200,11 @@ class Form {
{ type: 'label', label: LANG['list']['add']['form']['encoder'] },
{ type: 'radio', name: `encoder_${c}`, value: 'default', label: 'default', checked: true }
];
if (c !== 'custom') {
_.push({
type: 'radio', name: `encoder_${c}`, value: 'random', label: 'random'
});
}
encoders.map((e) => {
_.push({
type: 'radio', name: `encoder_${c}`,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment