diff --git a/src/mock/constant.js b/src/mock/constant.js index 3a83fa55..599a7c1c 100644 --- a/src/mock/constant.js +++ b/src/mock/constant.js @@ -24,10 +24,10 @@ */ module.exports = { GUID: 1, - RE_KEY: /(.+)\|(?:\+(\d+)|([\+\-]?\d+-?[\+\-]?\d*)?(?:\.(\d+-?\d*))?)/, + RE_KEY: /(.+)\|(?:\+([\d\.]+)|([\+\-]?\d+-?[\+\-]?\d*)?(?:\.(\d+-?\d*))?)/, RE_RANGE: /([\+\-]?\d+)-?([\+\-]?\d+)?/, RE_PLACEHOLDER: /\\*@([^@#%&()\?\s]+)(?:\((.*?)\))?/g // /\\*@([^@#%&()\?\s\/\.]+)(?:\((.*?)\))?/g // RE_INDEX: /^index$/, // RE_KEY: /^key$/ -} \ No newline at end of file +} diff --git a/src/mock/handler.js b/src/mock/handler.js index 1c3c4d32..410bb2af 100644 --- a/src/mock/handler.js +++ b/src/mock/handler.js @@ -262,7 +262,11 @@ Handler.extend({ // 'id|+1': 1 inc = key.match(Constant.RE_KEY) if (inc && inc[2] && Util.type(options.template[key]) === 'number') { - options.template[key] += parseInt(inc[2], 10) + // 支持浮点数自增 'id|+0.1': 0.2 + options.template[key] = (function(f,d){var c,b,a;try{c=f.toString().split(".")[1].length}catch(g){c=0} + try{b=d.toString().split(".")[1].length}catch(g){b=0} + a=Math.pow(10,Math.max(c,b));return(f*a+d*a)/a}) + (options.template[key],parseFloat(inc[2])); } } } @@ -537,4 +541,4 @@ Handler.extend({ } }) -module.exports = Handler \ No newline at end of file +module.exports = Handler