WXtrialInterface.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. import request from './request.js'
  2. import { clickCopyText, pasteText } from './common.js'
  3. // 禁止双击缩放
  4. document.addEventListener('dblclick', function (e) {
  5. e.preventDefault();
  6. });
  7. const { Dialog, Toast } = vant
  8. Toast.setDefaultOptions({ duration: 2000 });
  9. // 从 CLOUD_GAME_SDK 结构中解构必要的函数和常量
  10. const RtcEngineSDK = window.rtc_sdk.CloudGameSdk
  11. // 业务通道定时标识
  12. let doConnectDirectivesIntervalerPing = null
  13. // 获取云机数据定时标识
  14. let getUserCardInfoTimerInterval = null
  15. let getUserCardInfoRequestNum = 1
  16. let doConnectDirectivesRequestNum = 1
  17. let doConnectDirectivesTimerInterval = null
  18. // 触碰间隔定时标识
  19. let noOperationSetTimeoutTimeInterval = null
  20. let noOperationSetIntervalTimeInterval = null
  21. // 倒计时定时标识
  22. let countdownTimeInterval = null
  23. // let vc = new VConsole()
  24. const app = new Vue({
  25. el: '#app',
  26. data: {
  27. // 底部按钮
  28. footerBtn: [{
  29. key: 'task',
  30. img: '../static/img/wx/gengduo_icon.png'
  31. }, {
  32. key: 'home',
  33. img: '../static/img/wx/home_icon.png'
  34. }, {
  35. key: 'onBack',
  36. img: '../static/img/wx/fanhui_icon.png'
  37. }],
  38. // 宽高
  39. width: 0,
  40. height: 0,
  41. // webRtc实例
  42. engine: {},
  43. // 横竖屏幕 false是竖
  44. isLandscape: false,
  45. // 悬浮球位置
  46. levitatedSpherePositionData: {},
  47. // 右侧弹窗
  48. levitatedSphereVisible: false,
  49. // 清晰度数据
  50. definitionList: [{
  51. name: '高清',
  52. value: 2800
  53. }, {
  54. name: '标清',
  55. value: 2200,
  56. }, {
  57. name: '极速',
  58. value: 1800,
  59. }],
  60. // 选中的清晰度
  61. definitionValue: '',
  62. // 分辨率
  63. resolutionRatioVisible: false,
  64. resolutionRatioList: [],
  65. // 需要用到的参数
  66. parametersData: {},
  67. // 屏幕分辨率
  68. phoneSize: {},
  69. // 业务指令通道实例
  70. doConnectDirectivesWs: null,
  71. // 粘贴版
  72. pasteVersionVisible: false,
  73. pasteVersionList: [],
  74. // 复制内容
  75. copyTextValue: '',
  76. copyTextVisible: false,
  77. // 卡数据
  78. userCardInfoData: {},
  79. // 是否显示计时
  80. timingVisible: false,
  81. // 计费规则
  82. billingRulesVisible: false,
  83. applyRecommendVisible: false,
  84. // 是否是启动不操作自动退出云机功能
  85. isFiringNoOperationSetTimeout: false,
  86. // 超过指定触碰时间的弹窗
  87. noOperationSetTimeoutTimeVisible: false,
  88. // 超过指定触碰时间的弹窗文案
  89. confirmButtonText: '',
  90. // 云机剩余时长
  91. countdownTime: 0,
  92. // 是否支持webRTC
  93. isSupportRtc: !!(
  94. typeof RTCPeerConnection !== 'undefined' &&
  95. typeof RTCIceCandidate !== 'undefined' &&
  96. typeof RTCSessionDescription !== 'undefined'
  97. ),
  98. // 推荐列表
  99. recommendList: [],
  100. layoutViewWidth: null,
  101. layoutViewHeight: null,
  102. // 是否显示video
  103. isShowVideo: false,
  104. plugFlowStartDate: null,
  105. obtainCardInfoStartDate: null
  106. },
  107. created() {
  108. this.initConfig()
  109. },
  110. mounted() {
  111. this.obtainCardInfoStartDate = + new Date()
  112. this.getUserCardInfo()
  113. },
  114. computed: {
  115. // 右侧弹框退出相关按钮
  116. exitList() {
  117. let arr = [{
  118. name: '剪贴版',
  119. key: "shearplate",
  120. img: '../static/img/wx/jianqieban_icon.png'
  121. }, {
  122. name: '退出',
  123. key: 'signout',
  124. img: '../static/img/wx/tuichu_icon.png'
  125. }]
  126. if ([1, 2, 3].includes(+this.parametersData.userCardType)) {
  127. arr.push({
  128. name: '退出并下机',
  129. key: 'dormant',
  130. img: '../static/img/wx/tuichu_icon.png'
  131. })
  132. }
  133. return arr
  134. },
  135. rtcMediaPlayerStyle() {
  136. let obj = {
  137. objectFit: "fill"
  138. }
  139. if (this.isLandscape) {
  140. obj = {
  141. width: `${this.layoutViewHeight}px`,
  142. height: `${this.layoutViewWidth}px`,
  143. left: '50%',
  144. top: '50%',
  145. transform: 'translate(-50%, -50%) rotate(90deg)'
  146. }
  147. }
  148. return obj
  149. }
  150. },
  151. methods: {
  152. // 初始化
  153. initConfig() {
  154. // 获取窗口尺寸
  155. this.getInitSize()
  156. let levitatedSpherePositionData = localStorage.getItem('levitatedSpherePositionData')
  157. let definitionValue = localStorage.getItem('definitionValue')
  158. // 悬浮球位置
  159. this.levitatedSpherePositionData = levitatedSpherePositionData ? JSON.parse(levitatedSpherePositionData) : { right: '15px', top: '15px' }
  160. // 清晰度
  161. this.definitionValue = definitionValue ? +definitionValue : 2200
  162. // 获取参数
  163. this.parametersData = getParameters()
  164. let { token, validTime } = this.parametersData
  165. // 给api增加需要的参数
  166. request.defaults.headers.Authorization = token
  167. request.defaults.headers.versionname = '5.8.7'
  168. window.onresize = () => {
  169. this.getInitSize()
  170. }
  171. },
  172. // 连接webRTC
  173. connectWebRtc() {
  174. this.plugFlowStartDate = +new Date()
  175. const { sn: topic, cardToken: authToken, internetHttps, internetHttp, webrtcTransferCmnet, webrtcTransferTelecom, webrtcTransferUnicom } = this.userCardInfoData;
  176. const isWss = location.protocol === 'https:'
  177. const url = `${isWss ? 'wss://' : 'ws://'}${isWss ? internetHttps : internetHttp}/nats`;
  178. const ICEServerUrl = [
  179. { "CMNET": webrtcTransferCmnet || '' }, // 移动
  180. { 'CHINANET-GD': webrtcTransferTelecom || '' }, // 电信
  181. { 'UNICOM-GD': webrtcTransferUnicom || '' }, // 联通
  182. ];
  183. const connection = {
  184. name: "猪猪令是猪",
  185. topic, // 云机ID 必填
  186. url, //信令服务地址 必填
  187. ICEServerUrl,
  188. width: 720, // 推流视频宽度 必填
  189. height: 1280, // 推流视频高度 必填
  190. // cardWidth: this.phoneSize.width || 1080, // 云机系统分辨率 宽 必填
  191. // cardHeight: this.phoneSize.height || 1920, // 云机系统分辨率 高 必填
  192. // cardDensity: this.phoneSize.dpi || 480, // 云机系统显示 密度 必填
  193. cardWidth: 0, // 云机系统分辨率 宽 必填
  194. cardHeight: 0, // 云机系统分辨率 高 必填
  195. cardDensity: 0, // 云机系统显示 密度 必填
  196. authToken, //拉流鉴权 token 必填
  197. bitrate: 6000, //码率 必填
  198. fps: 30, //必填
  199. callback: this.statusCallBack,//回调函数 必填
  200. };
  201. // 初始化 SDK
  202. this.engine = new RtcEngineSDK(connection);
  203. this.engine.RtcEngine()
  204. },
  205. // webRTC状态回调
  206. statusCallBack(event) {
  207. if (event.type !== 'StreamStates') {
  208. // console.log("链接的状态", event, event.val);
  209. }
  210. switch (event.type) {
  211. case "screenChange":
  212. // 0:横屏 1:竖屏
  213. console.log("屏幕方向变化事件:" + event.val);
  214. this.isLandscape = event.val === 0;
  215. break;
  216. case "wsState":
  217. // “TIMEOUT”:nats链接超时
  218. // success 链接成功
  219. const status = ["TIMEOUT", "failed"]
  220. if (status.includes(event.val)) {
  221. Dialog.alert({
  222. title: '提示',
  223. message: '链接超时',
  224. confirmButtonText: '确定',
  225. confirmButtonColor: '#3cc51f',
  226. beforeClose: (action, done) => {
  227. this.exit()
  228. done()
  229. }
  230. })
  231. }
  232. break;
  233. case "rtcState":
  234. // “connected”:rtc链接成功 “failed”:rtc链接失败 “closed”:rtc链接关闭 “disconnected”:rtc链接超时
  235. if (event.val === "connected") {
  236. Toast.clear();
  237. this.doConnectDirectives()
  238. this.isShowVideo = true
  239. this.$refs.rtcMediaPlayer.volume = 0
  240. console.log('推流消耗时间:' + ((+ new Date() - this.plugFlowStartDate) / 1000) + '秒')
  241. this.$refs.rtcMediaPlayer.play().then(() => {
  242. this.$refs.rtcMediaPlayer.volume = 1
  243. }).catch(error => {
  244. Dialog.alert({
  245. title: '提示',
  246. message: '加载失败,请手动刷新',
  247. confirmButtonText: '刷新',
  248. confirmButtonColor: '#3cc51f',
  249. beforeClose: (action, done) => {
  250. this.$refs.rtcMediaPlayer.play()
  251. this.$refs.rtcMediaPlayer.volume = 1
  252. done()
  253. }
  254. })
  255. // Toast('如需声音,可调高音量使用')
  256. console.error('自动播放失败', error);
  257. });
  258. this.definitionFun(this.definitionValue)
  259. this.pushflowPopup()
  260. this.getResidueTime()
  261. return
  262. }
  263. if (event.val === "connecting") return
  264. this.exit()
  265. break;
  266. case "AuthenticationStatus":
  267. console.log(`鉴权${event.val === "success" ? '成功' : '失败'}`);
  268. break;
  269. case "StreamStates":
  270. // “currentRoundTripTime”:延迟 “lostRate”:丢包率 “seconds_KBytes”:带宽 “framesPerSecond”:帧率
  271. // ballPosition.value = event.val
  272. // console.log(event.val)
  273. break;
  274. case 'videoResolution': // 云机视频分辨率
  275. // console.log(event.val, '分辨率')
  276. break
  277. case 'networkService': // 获取三网信息
  278. console.log("三网信息:", event.val);
  279. break
  280. case 'networkServiceURL': // 获取三网信息
  281. console.log("三网IP地址:", event.val);
  282. break
  283. }
  284. },
  285. // 悬浮球移动
  286. touchmoveLevitatedSphere(e) {
  287. let { pageX, pageY } = e.targetTouches[0]
  288. let min = 20
  289. let MaxPageX = this.width - 20
  290. let MaxPageY = this.height - 20
  291. pageX = pageX <= min ? min : (pageX >= MaxPageX ? MaxPageX : pageX)
  292. pageY = pageY <= min ? min : (pageY >= MaxPageY ? MaxPageY : pageY)
  293. this.levitatedSpherePositionData = {
  294. left: `${pageX}px`,
  295. top: `${pageY}px`,
  296. transform: 'translate(-50%, -50%)'
  297. }
  298. },
  299. touchendLevitatedSphere(e) {
  300. localStorage.setItem('levitatedSpherePositionData', JSON.stringify(this.levitatedSpherePositionData))
  301. },
  302. // 清晰度
  303. definitionFun(value) {
  304. this.definitionValue = value
  305. this.engine.makeBitrate(value)
  306. localStorage.setItem('definitionValue', value)
  307. this.levitatedSphereVisible = false
  308. },
  309. // 修改分辨率
  310. resolutionRatio() {
  311. request.get('/api/resources/v5/machine/resolution/getResolvingPower', { params: { userCardId: this.parametersData.userCardId } }).then(res => {
  312. if (res.success) {
  313. this.resolutionRatioList = res.data.map(item => {
  314. item.height = item.high
  315. return item
  316. })
  317. this.levitatedSphereVisible = false
  318. this.resolutionRatioVisible = true
  319. }
  320. })
  321. },
  322. // 确定修改分辨率
  323. confirmResolution() {
  324. let { width, height, dpi: density } = this.phoneSize
  325. this.engine.makeResolution({ width, height, density })
  326. this.resolutionRatioVisible = false
  327. },
  328. // 退出相关按钮操作
  329. exitFun(key) {
  330. switch (key) {
  331. case 'dormant':
  332. Dialog.alert({
  333. title: '提示',
  334. message: '确定退出云手机并下机',
  335. confirmButtonText: '确定',
  336. confirmButtonColor: '#3cc51f',
  337. showCancelButton: true,
  338. beforeClose: (action, done) => {
  339. if (action === 'cancel') done()
  340. if (action === 'confirm') {
  341. this.downline(done)
  342. }
  343. }
  344. })
  345. break;
  346. case 'shearplate':
  347. this.copyTextValue = ''
  348. pasteText().then(content => {
  349. typeof content !== 'boolean' ? this.openPasteboard(content) : this.copyTextVisible = true
  350. }, err => {
  351. this.copyTextVisible = true
  352. })
  353. break;
  354. case 'signout':
  355. this.exit()
  356. break;
  357. }
  358. },
  359. // 业务指令
  360. doConnectDirectives() {
  361. let { internetHttps, localIp, cardToken } = this.userCardInfoData
  362. let cUrl = `wss://${internetHttps}/businessChannel?cardIp=${localIp}&token=${cardToken}&type=directives`
  363. this.doConnectDirectivesWs = new WebSocket(cUrl);
  364. this.doConnectDirectivesWs.binaryType = 'arraybuffer'
  365. clearInterval(doConnectDirectivesIntervalerPing)
  366. // 链接成功
  367. this.doConnectDirectivesWs.onopen = (e) => {
  368. doConnectDirectivesIntervalerPing = setInterval(() => {
  369. if (this.doConnectDirectivesWs.readyState === 1) {
  370. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'ping' }));
  371. } else {
  372. clearInterval(doConnectDirectivesIntervalerPing);
  373. }
  374. }, 3000)
  375. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'getVsStatus' }))
  376. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'bitRate', data: { bitRate: 1243000 } }))
  377. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'InputMethod', data: { type: 2 } }))
  378. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'getPhoneSize' }))
  379. }
  380. // 接受到的消息
  381. this.doConnectDirectivesWs.onmessage = res => {
  382. const result = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
  383. switch (result.type) {
  384. // 分辨率
  385. case 'getPhoneSize':
  386. case 'setPhoneSize':
  387. let data = JSON.parse(JSON.stringify(result.data))
  388. let { width, height } = data
  389. if (width > height) {
  390. data.width = height
  391. data.height = width
  392. }
  393. this.phoneSize = data
  394. break
  395. // 云机复制过来的文本
  396. case 'reProduceText':
  397. if (navigator.clipboard) {
  398. navigator.clipboard.writeText(result.data.text);
  399. }
  400. break
  401. case 'downAdnInstallRep':
  402. Toast(result.data.msg)
  403. break
  404. }
  405. }
  406. // 链接报错的回调
  407. this.doConnectDirectivesWs.onerror = res => {
  408. clearInterval(doConnectDirectivesTimerInterval)
  409. if (doConnectDirectivesRequestNum > 6) {
  410. this.exit()
  411. return
  412. }
  413. doConnectDirectivesRequestNum++
  414. this.doConnectDirectives()
  415. }
  416. },
  417. // 粘贴版相关接口
  418. shearContent({ type, params, queryStr }) {
  419. let url = '/api/public/v5/shear/content'
  420. if (queryStr) url += queryStr
  421. return request[type](url, params)
  422. },
  423. // 清空全部、清除某条
  424. deletePasteVersion(ids) {
  425. if (!ids) {
  426. Dialog.alert({
  427. title: '提示',
  428. message: '确定清空剪贴板?',
  429. confirmButtonText: '确定',
  430. confirmButtonColor: '#3cc51f',
  431. showCancelButton: true,
  432. beforeClose: (action, done) => {
  433. if (action === 'cancel') done()
  434. if (action === 'confirm') {
  435. fun.bind(this)(done)
  436. }
  437. }
  438. })
  439. return
  440. }
  441. fun.bind(this)()
  442. function fun(callBack = () => { }) {
  443. this.shearContent({
  444. type: 'delete', queryStr: Qs.stringify(
  445. {
  446. ids: ids ? [ids] : this.pasteVersionList.map((v) => v.id),
  447. },
  448. { arrayFormat: 'repeat', addQueryPrefix: true },
  449. )
  450. }).then(res => {
  451. if (res.status === 0) {
  452. this.getPasteVersion()
  453. callBack(true)
  454. } else {
  455. callBack(false)
  456. Toast(res.msg)
  457. }
  458. }).catch(() => {
  459. callBack(false)
  460. })
  461. }
  462. },
  463. // 获取粘贴版数据
  464. getPasteVersion(callBack = () => { }) {
  465. this.shearContent({ type: 'get' }).then(res => {
  466. this.pasteVersionList = res.data
  467. callBack(true)
  468. }).catch(() => {
  469. callBack(false)
  470. }).finally(() => { })
  471. },
  472. // 复制弹窗是否关闭
  473. beforeCloseCopy(action, done) {
  474. if (action !== 'confirm') {
  475. // 获取剪切板
  476. this.getPasteVersion(() => {
  477. this.pasteVersionVisible = true
  478. this.levitatedSphereVisible = false
  479. done()
  480. })
  481. return
  482. }
  483. if (!this.copyTextValue) {
  484. Toast('请输入复制到剪切板的内容')
  485. done(false)
  486. return
  487. }
  488. this.openPasteboard(this.copyTextValue, done)
  489. },
  490. // 打开粘贴板
  491. async openPasteboard(content, callBack = () => { }) {
  492. this.shearContent({ type: 'post', params: { content } }).then().finally(() => {
  493. callBack()
  494. // 获取剪切板
  495. this.getPasteVersion(() => {
  496. this.pasteVersionVisible = true
  497. this.levitatedSphereVisible = false
  498. })
  499. })
  500. },
  501. // 复制粘贴某条数据
  502. copyPasteVersiontext(e) {
  503. clickCopyText(e, (event) => {
  504. this.doConnectDirectivesWs.send(JSON.stringify({
  505. type: 'cutting',
  506. data: {
  507. str: event.text,
  508. },
  509. }))
  510. Toast('复制成功')
  511. }, () => {
  512. Toast('复制失败')
  513. })
  514. },
  515. // 获取卡信息
  516. getUserCardInfo() {
  517. Toast.loading({
  518. duration: 0, // 持续展示 toast
  519. message: '数据加载中...',
  520. });
  521. let { userCardId } = this.parametersData
  522. userCardId = +userCardId
  523. const statusTips = {
  524. 5200: '网络异常,请稍后重试',
  525. 5220: '云手机正在一键修复中',
  526. 5203: '正在排队中,请稍等',
  527. 5204: '云机异常,正在为你重新分配云机'
  528. }
  529. request.post('/api/resources/user/cloud/connect', { userCardId }).then(async res => {
  530. const { isWeixin } = this.parametersData;
  531. switch (res.status) {
  532. case 0:
  533. getUserCardInfoRequestNum = 1
  534. // 不支持webRTC跳转到指定的页面
  535. if (!res.data.isWebrtc) {
  536. location.replace(`${location.origin}/h5/webRtcYJ/WXtrialInterface.html${location.search}`)
  537. return
  538. }
  539. if (!this.isSupportRtc) {
  540. Dialog.alert({
  541. title: '提示',
  542. message: `${+isWeixin ? '微信小程序' : ''}当前版本暂不支持使用,可下载谷歌浏览器或双子星客户端进行使用`,
  543. confirmButtonText: '确定',
  544. confirmButtonColor: '#3cc51f',
  545. beforeClose: (action, done) => {
  546. this.exit()
  547. done()
  548. }
  549. })
  550. return
  551. }
  552. this.userCardInfoData = res.data
  553. console.log('获取卡信息消耗时间:' + ((+ new Date() - this.obtainCardInfoStartDate) / 1000) + '秒')
  554. this.connectWebRtc()
  555. return
  556. case 5200:
  557. case 5220:
  558. case 5203:
  559. case 5204:
  560. if (res.status === 5200) {
  561. reconnect.bind(this)()
  562. return
  563. }
  564. Toast(statusTips[res.status])
  565. break
  566. default:
  567. Toast('画面异常,请重新进入')
  568. break
  569. }
  570. setTimeout(() => {
  571. this.exit()
  572. }, 3000)
  573. })
  574. function reconnect() {
  575. if (getUserCardInfoRequestNum > 6) {
  576. Toast('网络异常,请稍后重试')
  577. clearTimeout(getUserCardInfoTimerInterval)
  578. setTimeout(() => {
  579. this.exit()
  580. }, 3000)
  581. return
  582. }
  583. getUserCardInfoTimerInterval = setTimeout(() => {
  584. this.getUserCardInfo()
  585. getUserCardInfoRequestNum++
  586. }, 3000)
  587. }
  588. },
  589. // 超过指定触碰时间是否提示关闭链接
  590. pushflowPopup() {
  591. request.get('/api/public/v5/pushflow/popup').then(res => {
  592. if (res.success) {
  593. this.isFiringNoOperationSetTimeout = res.data
  594. this.noOperationSetTimeout()
  595. }
  596. })
  597. },
  598. // 退出功能
  599. exit() {
  600. this.engine.disconnect && this.engine.disconnect();
  601. this.doConnectDirectivesWs && this.doConnectDirectivesWs.close()
  602. uni.reLaunch({
  603. url: '/pages/index/index'
  604. });
  605. },
  606. // 不触碰屏幕显示退出链接弹窗
  607. noOperationSetTimeout(key) {
  608. if (!this.isFiringNoOperationSetTimeout) return
  609. clearTimeout(noOperationSetTimeoutTimeInterval)
  610. if (key === 'cancel') {
  611. clearInterval(noOperationSetIntervalTimeInterval)
  612. this.noOperationSetTimeoutTimeVisible = false
  613. this.noOperationSetTimeout()
  614. return
  615. }
  616. noOperationSetTimeoutTimeInterval = setTimeout(() => {
  617. let index = 9
  618. this.confirmButtonText = '退出(10秒)'
  619. this.noOperationSetTimeoutTimeVisible = true
  620. noOperationSetIntervalTimeInterval = setInterval(() => {
  621. this.confirmButtonText = `退出${index ? `(${index}秒)` : ''}`
  622. index--
  623. if (index < 0) {
  624. this.noOperationSetTimeout('cancel')
  625. this.exit()
  626. }
  627. }, 1000)
  628. }, 300000)
  629. },
  630. // 获取云机剩余时长
  631. async getResidueTime() {
  632. clearInterval(countdownTimeInterval)
  633. const { userCardType, isShowCountdown, isShowRule } = this.parametersData
  634. const { userCardId } = this.userCardInfoData
  635. if (![1, 2, 3].includes(+userCardType)) return
  636. const res = await request.get(`/api/resources/yearMember/getResidueTime?userCardId=${userCardId}`)
  637. let time = res.data;
  638. if (!res.status) {
  639. this.countdownTime = residueTimeStamp(time)
  640. await request.get(`/api/resources/yearMember/startTime?userCardId=${userCardId}`)
  641. if (+isShowCountdown) this.timingVisible = true
  642. if (+isShowRule) this.billingRulesVisible = true
  643. countdownTimeInterval = setInterval(() => {
  644. if (time <= 0) {
  645. clearInterval(countdownTimeInterval)
  646. this.downline()
  647. return
  648. }
  649. time--
  650. this.countdownTime = residueTimeStamp(time)
  651. }, 1000)
  652. }
  653. },
  654. // 关闭倒计时弹窗
  655. handlecountdownTimeClose() {
  656. const { userCardId } = this.userCardInfoData
  657. request.get(`/api/resources/yearMember/closeRemind?userCardId=${userCardId}`).then(res => {
  658. if (!res.status) {
  659. clearInterval(countdownTimeInterval)
  660. this.timingVisible = false
  661. return
  662. }
  663. Toast(res.msg);
  664. })
  665. },
  666. // 退出并下机
  667. downline(fun = () => { }) {
  668. const { userCardId } = this.userCardInfoData
  669. request.get(`/api/resources/yearMember/downline?userCardId=${userCardId}`).then(res => {
  670. if (!res.status) {
  671. fun(true)
  672. // 通信给h5项目告知是退出并下机
  673. parent.postMessage(
  674. {
  675. type: 'exit',
  676. },
  677. '*',
  678. );
  679. uni.postMessage({
  680. data: {
  681. type: 'exit'
  682. }
  683. });
  684. this.exit()
  685. return
  686. }
  687. fun(false)
  688. Toast(res.msg);
  689. })
  690. },
  691. // 获取推荐列表
  692. getRecommend() {
  693. const { userCardId } = this.userCardInfoData
  694. request.get(`/api/public/v1/market/get/recommend?userCardId=${userCardId}`).then(res => {
  695. if (!res.status) {
  696. this.billingRulesVisible = false
  697. this.recommendList = res.data
  698. this.recommendList.length && (this.applyRecommendVisible = true)
  699. }
  700. })
  701. },
  702. // 下载apk
  703. downAndInstallApk({ downloadUrl: apkUrl, id: taskUid }) {
  704. this.doConnectDirectivesWs.send(JSON.stringify({
  705. type: 'downAndInstallApk',
  706. data: {
  707. apkUrl,
  708. taskUid
  709. },
  710. }))
  711. },
  712. // 移开手指时会发生的回调
  713. touchendRtcMediaPlayer(event) {
  714. this.engine.touchClick(event, 1, true)
  715. this.noOperationSetTimeout()
  716. },
  717. // 返回、主页、任务器
  718. footerBtnFun(key) {
  719. this.engine[key]()
  720. this.noOperationSetTimeout()
  721. },
  722. // 获取初始化尺寸
  723. getInitSize() {
  724. // 高度、悬浮球相关配置
  725. this.height = window.innerHeight
  726. this.width = window.innerWidth
  727. this.$nextTick(() => {
  728. // 云机画面宽高
  729. let layoutView = document.querySelector('.layout-view')
  730. this.layoutViewWidth = layoutView.offsetWidth
  731. this.layoutViewHeight = layoutView.offsetHeight
  732. })
  733. }
  734. }
  735. })
  736. function playOnBtn() {
  737. const { isTips } = this.parametersData;
  738. Dialog.alert({
  739. title: '提示',
  740. message: `${+isTips ? '开始' : '继续'}使用云手机`,
  741. confirmButtonText: '确定',
  742. confirmButtonColor: '#3cc51f',
  743. beforeClose: (action, done) => {
  744. if (action === 'confirm') {
  745. done()
  746. }
  747. }
  748. });
  749. }
  750. // 获取URL参数
  751. function getParameters() {
  752. let arr = location.search.split('?')
  753. let obj = {}
  754. if (arr[1]) {
  755. arr = arr[1].split('&')
  756. arr.forEach(item => {
  757. let [key, value = ''] = item.split('=')
  758. obj[key] = value
  759. })
  760. }
  761. return obj
  762. }
  763. // 倒计时处理的时间
  764. function residueTimeStamp(value) {
  765. let theTime = value;//秒
  766. let middle = 0;//分
  767. let hour = 0;//小时
  768. if (theTime > 59) {
  769. middle = parseInt(theTime / 60);
  770. theTime = parseInt(theTime % 60);
  771. }
  772. if (middle > 59) {
  773. hour = parseInt(middle / 60);
  774. middle = parseInt(middle % 60);
  775. }
  776. theTime < 10 ? theTime = '0' + theTime : theTime = theTime
  777. middle < 10 ? middle = '0' + middle : middle = middle
  778. hour < 10 ? hour = '0' + hour : hour = hour
  779. return hour + ':' + middle + ':' + theTime
  780. }