index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. Page({
  3. behaviors:[sceneReadyBehavior],
  4. data: {
  5. menu:[],
  6. radius: 80
  7. },
  8. touchEnd: function (e) {
  9. moveIdx = -1;
  10. //当位移触摸点松开时,保证旋转触摸点取的为第一接触点
  11. if (rotateIdx == 1)
  12. rotateIdx = 0;
  13. this.setData({
  14. hLeft: centerX - hWidth / 2,
  15. hTop: centerY - hHeight / 2,
  16. transferData:{
  17. biasX: 0,
  18. biasY: 0,
  19. }
  20. });
  21. },
  22. animateChoose: function(e) {
  23. console.log("choose:", e.currentTarget.dataset.index)
  24. this.setData({
  25. itemIndex: e.currentTarget.dataset.index
  26. })
  27. },
  28. processMenu: function(){
  29. var positionX = (this.data.touchPos.x + 1) / 2 * this.data.width;
  30. var positionY = (1 - (this.data.touchPos.y + 1) / 2) * this.data.height;
  31. var radius = this.data.radius * this.data.len;
  32. var item = [];
  33. var animLength = this.data.clipName.length
  34. var offsetAngle
  35. if(animLength > 6 ){
  36. offsetAngle = 2 * Math.PI / animLength
  37. }else{
  38. offsetAngle = Math.PI / animLength
  39. }
  40. var originAngle = - Math.PI / 2;
  41. for(var i = 0; i < animLength; i++){
  42. var x = radius * Math.cos( originAngle + i * offsetAngle);
  43. var y = radius * Math.sin( originAngle + i * offsetAngle);
  44. var text;
  45. switch(i){
  46. case 0:
  47. text = "暂停"
  48. break
  49. case 1:
  50. text = "继续"
  51. break
  52. default:
  53. text = this.data.clipName[i-2]
  54. break
  55. }
  56. item.push({"index": i, "x":positionX, "y":positionY, "biasX": x, "biasY":y,"text":text});
  57. }
  58. this.setData({
  59. menu:item
  60. });
  61. },
  62. handleInfoListener(cur) {
  63. const detail = cur.detail;
  64. // console.log("receive:", detail)
  65. if(detail.clipName){
  66. this.setData({
  67. clipName: detail.clipName
  68. })
  69. }
  70. if(detail.position){
  71. this.setData({
  72. touchPos: detail.position,
  73. len: detail.len
  74. })
  75. this.processMenu()
  76. }
  77. }
  78. });