WXtrialInterface.js 30 KB

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