index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 class="" v-else-if="$fetchState.error">
  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. computed: {
  70. // currentPhoneSize() {
  71. // // return this.phoneSizeList.find(v=> v.width=== )
  72. // },
  73. },
  74. async fetch() {
  75. // await this.getDiskInfo();
  76. if (this.userCardId) {
  77. await this.getDiskInfo(this.userCardId);
  78. await this.getPhoneSizeList(this.userCardId);
  79. await this.connect(this.userCardId);
  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. return this.$axios
  122. .$post('/resources/user/cloud/connect', {
  123. userCardId,
  124. })
  125. .catch((error) => {
  126. if (error.response.data.status === 5200) {
  127. this.loadingLabel = '云手机挂载中...';
  128. }
  129. return error;
  130. });
  131. };
  132. const res = await getConnectData();
  133. if (!res.isAxiosError) {
  134. this.connectInfo = res.data;
  135. // this.connectInfo.sn = 'RK3931C13019';
  136. return res;
  137. }
  138. // 第一次连接失败,开启轮询
  139. const wres = await new Promise((resolve, reject) => {
  140. const startTime = Date.now();
  141. const maxTime = 1000 * 20;
  142. clearInterval(this._watchConnectInterval);
  143. this._watchConnectInterval = setInterval(async () => {
  144. try {
  145. if (Date.now() - startTime >= maxTime) {
  146. throw new Error('云手机挂载超时');
  147. }
  148. const res = await getConnectData();
  149. if (!res.isAxiosError) {
  150. clearInterval(this._watchConnectInterval);
  151. resolve(res);
  152. }
  153. } catch (error) {
  154. clearInterval(this._watchConnectInterval);
  155. reject(error);
  156. }
  157. }, 1000);
  158. });
  159. this.connectInfo = wres.data;
  160. // this.connectInfo.sn = 'RK3923C1201900139';
  161. return res;
  162. },
  163. },
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. // .disk {
  168. // position: relative;
  169. // display: flex;
  170. // flex-direction: column;
  171. // height: 100%;
  172. // }
  173. // .disk-header {
  174. // position: relative;
  175. // height: 0;
  176. // flex: none;
  177. // }
  178. // .disk-main {
  179. // position: relative;
  180. // flex: 1;
  181. // }
  182. // .disk-footer {
  183. // height: 50px;
  184. // flex: none;
  185. // }
  186. .disk-main {
  187. position: relative;
  188. overflow: hidden;
  189. }
  190. </style>