index.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. const res = await this.$axios.$post('/resources/user/cloud/connect', { userCardId });
  97. this.diskInfo = res.data;
  98. },
  99. async getPhoneSizeList(userCardId) {
  100. try {
  101. const res = await this.$axios.$get(
  102. '/resources/v5/machine/resolution/getResolvingPower',
  103. {
  104. params: {
  105. userCardId,
  106. },
  107. },
  108. );
  109. this.phoneSizeList = res.data;
  110. } catch (error) {
  111. this.phoneSizeList = [];
  112. }
  113. },
  114. /**
  115. * 轮询连接云机,因为超分需要挂载
  116. * @param {number} userCardId
  117. * @param {number} 超时
  118. */
  119. async connect(userCardId) {
  120. // 连接云机
  121. const getConnectData = () =>
  122. this.$axios.$post('/resources/user/cloud/connect', {
  123. userCardId,
  124. });
  125. try {
  126. const res = await getConnectData();
  127. this.connectInfo = res.data;
  128. return res;
  129. } catch (error) {
  130. const res = await new Promise((resolve, reject) => {
  131. const startTime = Date.now();
  132. const maxTime = 1000 * 60;
  133. const interval = 1000 * 1;
  134. clearInterval(this._watchConnectInterval);
  135. this._watchConnectInterval = setInterval(async () => {
  136. try {
  137. if (Date.now() - startTime >= maxTime) {
  138. throw new Error('云手机挂载超时');
  139. }
  140. await getConnectData().then(resolve, (error) => {
  141. // console.log(
  142. // '🚀 ~ file: index.vue ~ line 149 ~ awaitgetConnectData ~ error',
  143. // error,
  144. // );
  145. if (error.response.data.status === 5220) {
  146. // console.log('一键修复');
  147. this.loadingLabel = error.response.data.msg;
  148. }
  149. });
  150. } catch (error) {
  151. clearInterval(this._watchConnectInterval);
  152. reject(error);
  153. }
  154. }, interval);
  155. });
  156. this.connectInfo = res.data;
  157. return res;
  158. }
  159. },
  160. },
  161. };
  162. </script>
  163. <style lang="scss" scoped>
  164. // .disk {
  165. // position: relative;
  166. // display: flex;
  167. // flex-direction: column;
  168. // height: 100%;
  169. // }
  170. // .disk-header {
  171. // position: relative;
  172. // height: 0;
  173. // flex: none;
  174. // }
  175. // .disk-main {
  176. // position: relative;
  177. // flex: 1;
  178. // }
  179. // .disk-footer {
  180. // height: 50px;
  181. // flex: none;
  182. // }
  183. .disk-main {
  184. position: relative;
  185. overflow: hidden;
  186. }
  187. </style>