createRandomString (type = 'STRING', dictValues = []) { // 随机生成符合类型的数据 let str = '' let long = Math.round(Math.random() * 6 + 2) // 6-8位 let words = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' let len = words.length let start = 0 let end = len if (type === 'INTEGER' || type === 'LONG' || type === 'DOUBLE' || type === 'Currency' || type === 'STRING') {
if (type !== 'STRING') { end = 9 len = 10 } for (let i = 0; i < long; i++) { let newWord = words.substring(start, end).charAt(Math.floor(Math.random() * len)) if (!newWord || (type === 'STRING' && str.indexOf(newWord) > -1) || (i === 0 && newWord * 1 === 0)) { i-- continue } str += newWord } } elseif (type === 'DATE' || type === 'TIMESTAMP') { let startTime = +newDate('1990-01-01T00:00:00') let nowTime = +newDate() let long = nowTime - startTime // str = moment(startTime + Math.round(Math.random() * long)).format('YYYY-MM-DD HH:mm:ss') str = startTime + Math.round(Math.random() * long) } elseif (type === 'Boolean') { str = ['true', 'false'][Math.round(Math.random() * 1)] } elseif (type === 'DICTIONARY' && dictValues.length > 0) { let index = Math.floor(Math.random() * dictValues.length) str = dictValues[index].dictValue || '' } return str }