123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <template>
- <div
- :data-id="diskInfo && diskInfo.id"
- class="disk reverse flex flex-col h-full"
- >
- <header class="disk-header"></header>
- <main class="disk-main flex-auto">
- <disk-video :info="connectInfo"></disk-video>
- <disk-touch :info="connectInfo" @sizeChange="() => {}"></disk-touch>
- </main>
- <footer class="disk-footer h-50rpx"></footer>
- <v-overlay absolute :value="$fetchState.error || $fetchState.pending">
- <div
- v-if="$fetchState.pending"
- class="flex flex-col justify-center items-center"
- >
- <v-progress-circular
- indeterminate
- class="w-32rpx h-32rpx"
- ></v-progress-circular>
- <div v-if="loadingLabel" class="label mt-2">{{ loadingLabel }}</div>
- </div>
- <div v-else-if="$fetchState.error" class="">
- <v-icon>$error</v-icon>
- <div class="">{{ $fetchState.error.message }}</div>
- <div class="">
- <v-btn @click="$router.back()">退出</v-btn>
- </div>
- </div>
- </v-overlay>
- </div>
- </template>
- <script>
- export default {
- name: 'Disk',
- props: {
- userCardId: {
- type: Number,
- default: null,
- },
- },
- data() {
- return {
- diskInfo: null,
- connectInfo: null,
- // loading: false,
- loadingLabel: null,
- // 当前生效的分辨率
- currentWidth: 720,
- currentHeight: 1280,
- currentDpi: 1,
- // 当前选中的分辨率
- activeWidth: 720,
- activeHeight: 1280,
- activeDpi: 1,
- // 分辨率列表
- phoneSizeList: [
- {
- id: 1,
- width: 720,
- height: 1280,
- dpi: 1,
- },
- ],
- // currentPhoneSizeId: 0,
- // activePhoneSizeId: 0,
- };
- },
- async fetch() {
- // await this.getDiskInfo();
- if (this.userCardId) {
- await this.getDiskInfo(this.userCardId);
- await this.getPhoneSizeList(this.userCardId);
- await this.connect(this.userCardId);
- }
- },
- computed: {
- // currentPhoneSize() {
- // // return this.phoneSizeList.find(v=> v.width=== )
- // },
- },
- watch: {
- userCardId: '$fetch',
- },
- methods: {
- // 查询云机
- async getDiskInfo(userCardId) {
- // const res = await this.$axios.$get(
- // '/resources/v5/client/disk/info/userCard/single',
- // {
- // params: {
- // userCardId,
- // },
- // },
- // );
- const res = await this.$axios.$post('/resources/user/cloud/connect', { userCardId });
- this.diskInfo = res.data;
- },
- async getPhoneSizeList(userCardId) {
- try {
- const res = await this.$axios.$get(
- '/resources/v5/machine/resolution/getResolvingPower',
- {
- params: {
- userCardId,
- },
- },
- );
- this.phoneSizeList = res.data;
- } catch (error) {
- this.phoneSizeList = [];
- }
- },
- /**
- * 轮询连接云机,因为超分需要挂载
- * @param {number} userCardId
- * @param {number} 超时
- */
- async connect(userCardId) {
- // 连接云机
- const getConnectData = () =>
- this.$axios.$post('/resources/user/cloud/connect', {
- userCardId,
- });
- try {
- const res = await getConnectData();
- this.connectInfo = res.data;
- return res;
- } catch (error) {
- const res = await new Promise((resolve, reject) => {
- const startTime = Date.now();
- const maxTime = 1000 * 60;
- const interval = 1000 * 1;
- clearInterval(this._watchConnectInterval);
- this._watchConnectInterval = setInterval(async () => {
- try {
- if (Date.now() - startTime >= maxTime) {
- throw new Error('云手机挂载超时');
- }
- await getConnectData().then(resolve, (error) => {
- // console.log(
- // '🚀 ~ file: index.vue ~ line 149 ~ awaitgetConnectData ~ error',
- // error,
- // );
- if (error.response.data.status === 5220) {
- // console.log('一键修复');
- this.loadingLabel = error.response.data.msg;
- }
- });
- } catch (error) {
- clearInterval(this._watchConnectInterval);
- reject(error);
- }
- }, interval);
- });
- this.connectInfo = res.data;
- return res;
- }
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- // .disk {
- // position: relative;
- // display: flex;
- // flex-direction: column;
- // height: 100%;
- // }
- // .disk-header {
- // position: relative;
- // height: 0;
- // flex: none;
- // }
- // .disk-main {
- // position: relative;
- // flex: 1;
- // }
- // .disk-footer {
- // height: 50px;
- // flex: none;
- // }
- .disk-main {
- position: relative;
- overflow: hidden;
- }
- </style>
|