index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <div
  3. :data-id="diskInfo && diskInfo.id"
  4. class="disk reverse flex flex-col h-full"
  5. >
  6. <header class="disk-header"></header>
  7. <main class="disk-main flex-auto">
  8. <disk-video :info="connectInfo"></disk-video>
  9. <disk-touch :info="connectInfo" @sizeChange="() => {}"></disk-touch>
  10. </main>
  11. <footer class="disk-footer h-50rpx"></footer>
  12. <v-overlay absolute :value="$fetchState.error || $fetchState.pending">
  13. <div
  14. v-if="$fetchState.pending"
  15. class="flex flex-col justify-center items-center"
  16. >
  17. <v-progress-circular
  18. indeterminate
  19. class="w-32rpx h-32rpx"
  20. ></v-progress-circular>
  21. <div v-if="loadingLabel" class="label mt-2">{{ loadingLabel }}</div>
  22. </div>
  23. <div v-else-if="$fetchState.error" class="">
  24. <v-icon>$error</v-icon>
  25. <div class="">{{ $fetchState.error.message }}</div>
  26. <div class="">
  27. <v-btn @click="$router.back()">退出</v-btn>
  28. </div>
  29. </div>
  30. </v-overlay>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'Disk',
  36. props: {
  37. userCardId: {
  38. type: Number,
  39. default: null,
  40. },
  41. },
  42. data() {
  43. return {
  44. diskInfo: null,
  45. connectInfo: null,
  46. // loading: false,
  47. loadingLabel: null,
  48. // 当前生效的分辨率
  49. currentWidth: 720,
  50. currentHeight: 1280,
  51. currentDpi: 1,
  52. // 当前选中的分辨率
  53. activeWidth: 720,
  54. activeHeight: 1280,
  55. activeDpi: 1,
  56. // 分辨率列表
  57. phoneSizeList: [
  58. {
  59. id: 1,
  60. width: 720,
  61. height: 1280,
  62. dpi: 1,
  63. },
  64. ],
  65. // currentPhoneSizeId: 0,
  66. // activePhoneSizeId: 0,
  67. };
  68. },
  69. async fetch() {
  70. // await this.getDiskInfo();
  71. if (this.userCardId) {
  72. await this.getDiskInfo(this.userCardId);
  73. await this.getPhoneSizeList(this.userCardId);
  74. await this.connect(this.userCardId);
  75. }
  76. },
  77. computed: {
  78. // currentPhoneSize() {
  79. // // return this.phoneSizeList.find(v=> v.width=== )
  80. // },
  81. },
  82. watch: {
  83. userCardId: '$fetch',
  84. },
  85. methods: {
  86. // 查询云机
  87. async getDiskInfo(userCardId) {
  88. const res = await this.$axios.$get(
  89. '/resources/v5/client/disk/info/userCard/single',
  90. {
  91. params: {
  92. userCardId,
  93. },
  94. },
  95. );
  96. this.diskInfo = res.data;
  97. },
  98. async getPhoneSizeList(userCardId) {
  99. try {
  100. const res = await this.$axios.$get(
  101. '/resources/v5/machine/resolution/getResolvingPower',
  102. {
  103. params: {
  104. userCardId,
  105. },
  106. },
  107. );
  108. this.phoneSizeList = res.data;
  109. } catch (error) {
  110. this.phoneSizeList = [];
  111. }
  112. },
  113. /**
  114. * 轮询连接云机,因为超分需要挂载
  115. * @param {number} userCardId
  116. * @param {number} 超时
  117. */
  118. async connect(userCardId) {
  119. // 连接云机
  120. const getConnectData = () =>
  121. this.$axios.$post('/resources/user/cloud/connect', {
  122. userCardId,
  123. });
  124. try {
  125. const res = await getConnectData();
  126. this.connectInfo = res.data;
  127. return res;
  128. } catch (error) {
  129. const res = await new Promise((resolve, reject) => {
  130. const startTime = Date.now();
  131. const maxTime = 1000 * 60;
  132. const interval = 1000 * 1;
  133. clearInterval(this._watchConnectInterval);
  134. this._watchConnectInterval = setInterval(async () => {
  135. try {
  136. if (Date.now() - startTime >= maxTime) {
  137. throw new Error('云手机挂载超时');
  138. }
  139. await getConnectData().then(resolve, (error) => {
  140. // console.log(
  141. // '🚀 ~ file: index.vue ~ line 149 ~ awaitgetConnectData ~ error',
  142. // error,
  143. // );
  144. if (error.response.data.status === 5220) {
  145. // console.log('一键修复');
  146. this.loadingLabel = error.response.data.msg;
  147. }
  148. });
  149. } catch (error) {
  150. clearInterval(this._watchConnectInterval);
  151. reject(error);
  152. }
  153. }, interval);
  154. });
  155. this.connectInfo = res.data;
  156. return res;
  157. }
  158. },
  159. },
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. // .disk {
  164. // position: relative;
  165. // display: flex;
  166. // flex-direction: column;
  167. // height: 100%;
  168. // }
  169. // .disk-header {
  170. // position: relative;
  171. // height: 0;
  172. // flex: none;
  173. // }
  174. // .disk-main {
  175. // position: relative;
  176. // flex: 1;
  177. // }
  178. // .disk-footer {
  179. // height: 50px;
  180. // flex: none;
  181. // }
  182. .disk-main {
  183. position: relative;
  184. overflow: hidden;
  185. }
  186. </style>