没那没复杂吧,也没必要使用云函数
getTimeAndId: function () {
let ranNum = (len) => {
var m = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], res = []
while (len) {
var b = parseInt(Math.random() * len) - 1,
res.push(m.splice(b, 1).shift())
len -= 1
}
return res
}, date = new Date(new Date().getTime() + 8 * 3600 * 1000), data = {}
data.time = date.toJSON().replace(/T/g, ’ ').replace(/\.\d+Z$/g, ‘’).trim()
data.orderId = data.time.replace(/[-: ]/g, ‘’).trim() + ranNum(5).join(’’)
console.log(data)
}
//===============================
上面的 ranNum 方法
随机5个数字 ranNum(5) => 如:[2,4,5,8,7]