index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. var sceneReadyBehavior = require('../../behavior-scene/scene-ready');
  2. Page({
  3. behaviors:[sceneReadyBehavior],
  4. data: {
  5. showBackBtn: true,
  6. resourceData: {
  7. },
  8. onFlags: [
  9. false, false, // gltf
  10. false, false, // image
  11. false, false, false // video
  12. ],
  13. gltfList: [],
  14. imageList: [],
  15. videoList: [],
  16. },
  17. onLoad() {
  18. // 准备加载数据
  19. },
  20. tapResBtn(event) {
  21. const dataSet = event.target.dataset;
  22. // console.log(event);
  23. const onFlags = this.data.onFlags;
  24. const src = dataSet.src;
  25. const index = parseInt(dataSet.index);
  26. onFlags[index] = !onFlags[index];
  27. switch (dataSet.type) {
  28. case 'gltf':
  29. let gltfListNew;
  30. if (onFlags[index]) {
  31. gltfListNew = this.data.gltfList;
  32. gltfListNew.push({
  33. id: index,
  34. src: src
  35. });
  36. } else {
  37. let matchIndex = -1;
  38. for (let i = 0; i < this.data.gltfList.length; i++) {
  39. if (this.data.gltfList[i] && src === this.data.gltfList[i].src) {
  40. matchIndex = i;
  41. break;
  42. }
  43. }
  44. this.data.gltfList.splice(matchIndex, 1);
  45. gltfListNew = this.data.gltfList;
  46. }
  47. this.setData({
  48. gltfList: gltfListNew,
  49. onFlags: onFlags
  50. });
  51. break;
  52. case 'image':
  53. let imageListNew;
  54. if (onFlags[index]) {
  55. imageListNew = this.data.imageList;
  56. imageListNew.push({
  57. id: index,
  58. src: src
  59. });
  60. } else {
  61. let matchIndex = -1;
  62. for (let i = 0; i < this.data.imageList.length; i++) {
  63. if (this.data.imageList[i] && src === this.data.imageList[i].src) {
  64. matchIndex = i;
  65. break;
  66. }
  67. }
  68. this.data.imageList.splice(matchIndex, 1);
  69. imageListNew = this.data.imageList;
  70. }
  71. this.setData({
  72. imageList: imageListNew,
  73. onFlags: onFlags
  74. });
  75. break
  76. case 'video':
  77. let videoListNew;
  78. if (onFlags[index]) {
  79. videoListNew = this.data.videoList;
  80. videoListNew.push({
  81. id: index,
  82. src: src
  83. });
  84. } else {
  85. let matchIndex = -1;
  86. for (let i = 0; i < this.data.videoList.length; i++) {
  87. if (this.data.videoList[i] && src === this.data.videoList[i].src) {
  88. matchIndex = i;
  89. break;
  90. }
  91. }
  92. this.data.videoList.splice(matchIndex, 1);
  93. videoListNew = this.data.videoList;
  94. }
  95. this.setData({
  96. videoList: videoListNew,
  97. onFlags: onFlags
  98. });
  99. break
  100. default:
  101. break;
  102. }
  103. },
  104. handleInfoListener(cur) {
  105. const detail = cur.detail;
  106. this.setData({
  107. });
  108. }
  109. });