index.html 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0" />
  6. <title>检测性能</title>
  7. <link rel="stylesheet" href="style.css">
  8. </head>
  9. <body>
  10. <div id="app" class="hc-app-animation-body">
  11. <div v-for="item in 190" :key='item' class="animation-mode item"
  12. :style="`background-color: ${getColor()}; animation-name: animation-${getIndex()};`"
  13. :id="`item-${item}`" @animationend="onAnimationend(item)"></div>
  14. </div>
  15. <script type="text/javascript" src="../js/uni.webview.1.5.5.js"></script>
  16. <script type="text/javascript" src="../js/vue-2.7.14.js"></script>
  17. <script>
  18. document.addEventListener('UniAppJSBridgeReady', () => {
  19. window.addEventListener('message', (event) => {
  20. if (event.data.source === 'animation-web') {
  21. uni.postMessage({
  22. data: event.data
  23. });
  24. }
  25. });
  26. });
  27. //创建vue实例
  28. var app = new Vue({
  29. el: '#app',
  30. data: {
  31. startTime: new Date(),
  32. indexs: [],
  33. colors: ['red', 'green', 'black', 'pink', 'orange', 'aqua', 'yellowgreen', 'blue']
  34. },
  35. mounted() {
  36. let newArr = [];
  37. for (let i = 0; i < 14; i++) {
  38. newArr.push(i + 1)
  39. }
  40. this.indexs = newArr;
  41. },
  42. methods: {
  43. getIndex() {
  44. let arr = this.indexs
  45. return arr[Math.floor((Math.random() * arr.length))];
  46. },
  47. getColor() {
  48. let arr = this.colors;
  49. return arr[Math.floor((Math.random() * arr.length))];
  50. },
  51. onAnimationend(i) {
  52. if (i === 100) {
  53. const duration = new Date() - this.startTime
  54. window.postMessage({
  55. type: 'on-animation',
  56. source: 'animation-web',
  57. data: duration
  58. }, '*')
  59. }
  60. },
  61. }
  62. })
  63. </script>
  64. </body>
  65. </html>