| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 | 
							- //随机获取7种颜色中的一种颜色,常亮显示
 
- const getRandomRGB = () => {
 
- 	let index = Math.floor(Math.random() * 7);
 
- 	// console.log("index:" + index);
 
- 	let head = '5B0E02';
 
- 	let tail = '5D';
 
- 	for (let i = 0; i < 7; i++) {
 
- 		if (i == index) {
 
- 			head = head.concat('FF')
 
- 		} else {
 
- 			head = head.concat('00')
 
- 		}
 
- 		//时间设置为0,常亮
 
- 		head = head.concat('00');
 
- 	}
 
- 	head = head.concat(tail);
 
- 	// console.log(head);
 
- 	return head;
 
- }
 
- //随机获取7种颜色中的三种颜色,随机显示
 
- const getRandomThreeRGB = () => {
 
- 	//原数组
 
- 	var arr = [0, 1, 2, 3, 4, 5, 6];
 
- 	//输出数组    
 
- 	var out = [];
 
- 	//输出个数    
 
- 	var num = 3;
 
- 	while (out.length < num) {
 
- 		var temp = (Math.random() * arr.length) >> 0;
 
- 		out.push(arr.splice(temp, 1));
 
- 	}
 
- 	// console.log("out:" + out);
 
- 	let head = '5B0E02';
 
- 	let tail = '5D';
 
- 	for (let i = 0; i < 7; i++) {
 
- 		let bHas = false;
 
- 		for (let j = 0; j < out.length; j++) {
 
- 			// console.log(i + '==' + out[j])
 
- 			if (i == out[j]) {
 
- 				bHas = true;
 
- 			}
 
- 			if (j == out.length - 1) {
 
- 				//需要灭灯的时间
 
- 				let addStr = bHas ? '08' : '00';
 
- 				head = head.concat(addStr);
 
- 				// console.log(addStr)
 
- 			}
 
- 		}
 
- 		//时间设置为0,常亮, 对应灭灯时间 20ms
 
- 		let timeStr = bHas ? '02' : '00';
 
- 		head = head.concat(timeStr);
 
- 	}
 
- 	head = head.concat(tail);
 
- 	// console.log(head);
 
- 	return head;
 
- }
 
- export default {
 
- 	getRandomRGB,
 
- 	getRandomThreeRGB
 
- }
 
 
  |