WXtrialInterface.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. playOnBtn.bind(this)()
  242. this.pushflowPopup()
  243. this.getResidueTime()
  244. return
  245. }
  246. if (event.val === "connecting") return
  247. this.exit()
  248. break;
  249. case "StreamStates":
  250. // “currentRoundTripTime”:延迟 “lostRate”:丢包率 “seconds_KBytes”:带宽 “framesPerSecond”:帧率
  251. // ballPosition.value = event.val
  252. break;
  253. case 'videoResolution': // 云机系统分辨率
  254. break
  255. }
  256. },
  257. // 悬浮球移动
  258. touchmoveLevitatedSphere(e) {
  259. let { pageX, pageY } = e.targetTouches[0]
  260. let min = 20
  261. let MaxPageX = this.width - 20
  262. let MaxPageY = this.height - 20
  263. pageX = pageX <= min ? min : (pageX >= MaxPageX ? MaxPageX : pageX)
  264. pageY = pageY <= min ? min : (pageY >= MaxPageY ? MaxPageY : pageY)
  265. this.levitatedSpherePositionData = {
  266. left: `${pageX}px`,
  267. top: `${pageY}px`,
  268. transform: 'translate(-50%, -50%)'
  269. }
  270. },
  271. touchendLevitatedSphere(e) {
  272. localStorage.setItem('levitatedSpherePositionData', JSON.stringify(this.levitatedSpherePositionData))
  273. },
  274. // 清晰度
  275. definitionFun(value) {
  276. this.definitionValue = value
  277. this.engine.makeBitrate(value)
  278. localStorage.setItem('definitionValue', value)
  279. this.levitatedSphereVisible = false
  280. },
  281. // 修改分辨率
  282. resolutionRatio() {
  283. request.get('/api/resources/v5/machine/resolution/getResolvingPower', { params: { userCardId: this.parametersData.userCardId } }).then(res => {
  284. if (res.success) {
  285. this.resolutionRatioList = res.data.map(item => {
  286. item.height = item.high
  287. return item
  288. })
  289. this.levitatedSphereVisible = false
  290. // this.resolutionRatioVisible = true
  291. }
  292. })
  293. },
  294. // 确定修改分辨率
  295. // confirmResolution() {
  296. // let { width, height, dpi } = this.phoneSize
  297. // this.doConnectDirectivesWs.send(JSON.stringify({
  298. // type: "setPhoneSize",
  299. // data: {
  300. // width,
  301. // height,
  302. // dpi
  303. // }
  304. // }))
  305. // // this.resolutionRatioVisible = false
  306. // },
  307. // 退出相关按钮操作
  308. exitFun(key) {
  309. switch (key) {
  310. case 'dormant':
  311. Dialog.alert({
  312. title: '提示',
  313. message: '确定退出云手机并下机',
  314. confirmButtonText: '确定',
  315. confirmButtonColor: '#3cc51f',
  316. showCancelButton: true,
  317. beforeClose: (action, done) => {
  318. if (action === 'cancel') done()
  319. if (action === 'confirm') {
  320. this.downline(done)
  321. }
  322. }
  323. })
  324. break;
  325. case 'shearplate':
  326. this.copyTextValue = ''
  327. pasteText().then(content => {
  328. typeof content !== 'boolean' ? this.openPasteboard(content) : this.copyTextVisible = true
  329. }, err => {
  330. this.copyTextVisible = true
  331. })
  332. break;
  333. case 'signout':
  334. this.exit()
  335. break;
  336. }
  337. },
  338. // 业务指令
  339. doConnectDirectives() {
  340. let { internetHttps, localIp, cardToken } = this.userCardInfoData
  341. let cUrl = `wss://${internetHttps}/businessChannel?cardIp=${localIp}&token=${cardToken}&type=directives`
  342. this.doConnectDirectivesWs = new WebSocket(cUrl);
  343. this.doConnectDirectivesWs.binaryType = 'arraybuffer'
  344. clearInterval(doConnectDirectivesIntervalerPing)
  345. // 链接成功
  346. this.doConnectDirectivesWs.onopen = (e) => {
  347. doConnectDirectivesIntervalerPing = setInterval(() => {
  348. if (this.doConnectDirectivesWs.readyState === 1) {
  349. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'ping' }));
  350. } else {
  351. clearInterval(doConnectDirectivesIntervalerPing);
  352. }
  353. }, 3000)
  354. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'getVsStatus' }))
  355. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'bitRate', data: { bitRate: 1243000 } }))
  356. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'InputMethod', data: { type: 2 } }))
  357. this.doConnectDirectivesWs.send(JSON.stringify({ type: 'getPhoneSize' }))
  358. }
  359. // 接受到的消息
  360. this.doConnectDirectivesWs.onmessage = res => {
  361. const result = typeof res.data === 'string' ? JSON.parse(res.data) : res.data;
  362. switch (result.type) {
  363. // 分辨率
  364. case 'getPhoneSize':
  365. case 'setPhoneSize':
  366. this.phoneSize = result.data
  367. break
  368. // 云机复制过来的文本
  369. case 'reProduceText':
  370. if (navigator.clipboard) {
  371. navigator.clipboard.writeText(result.data.text);
  372. }
  373. break
  374. case 'downAdnInstallRep':
  375. Toast(result.data.msg)
  376. break
  377. }
  378. }
  379. // 链接报错的回调
  380. this.doConnectDirectivesWs.onerror = res => {
  381. clearInterval(doConnectDirectivesTimerInterval)
  382. if (doConnectDirectivesRequestNum > 6) {
  383. this.exit()
  384. return
  385. }
  386. doConnectDirectivesRequestNum++
  387. this.doConnectDirectives()
  388. }
  389. },
  390. // 粘贴版相关接口
  391. shearContent({ type, params, queryStr }) {
  392. let url = '/api/public/v5/shear/content'
  393. if (queryStr) url += queryStr
  394. return request[type](url, params)
  395. },
  396. // 清空全部、清除某条
  397. deletePasteVersion(ids) {
  398. if (!ids) {
  399. Dialog.alert({
  400. title: '提示',
  401. message: '确定清空剪贴板?',
  402. confirmButtonText: '确定',
  403. confirmButtonColor: '#3cc51f',
  404. showCancelButton: true,
  405. beforeClose: (action, done) => {
  406. if (action === 'cancel') done()
  407. if (action === 'confirm') {
  408. fun.bind(this)(done)
  409. }
  410. }
  411. })
  412. return
  413. }
  414. fun.bind(this)()
  415. function fun(callBack = () => { }) {
  416. this.shearContent({
  417. type: 'delete', queryStr: Qs.stringify(
  418. {
  419. ids: ids ? [ids] : this.pasteVersionList.map((v) => v.id),
  420. },
  421. { arrayFormat: 'repeat', addQueryPrefix: true },
  422. )
  423. }).then(res => {
  424. if (res.status === 0) {
  425. this.getPasteVersion()
  426. callBack(true)
  427. } else {
  428. callBack(false)
  429. Toast(res.msg)
  430. }
  431. }).catch(() => {
  432. callBack(false)
  433. })
  434. }
  435. },
  436. // 获取粘贴版数据
  437. getPasteVersion(callBack = () => { }) {
  438. this.shearContent({ type: 'get' }).then(res => {
  439. this.pasteVersionList = res.data
  440. callBack(true)
  441. }).catch(() => {
  442. callBack(false)
  443. }).finally(() => { })
  444. },
  445. // 复制弹窗是否关闭
  446. beforeCloseCopy(action, done) {
  447. if (action !== 'confirm') {
  448. // 获取剪切板
  449. this.getPasteVersion(() => {
  450. this.pasteVersionVisible = true
  451. this.levitatedSphereVisible = false
  452. done()
  453. })
  454. return
  455. }
  456. if (!this.copyTextValue) {
  457. Toast('请输入复制到剪切板的内容')
  458. done(false)
  459. return
  460. }
  461. this.openPasteboard(this.copyTextValue, done)
  462. },
  463. // 打开粘贴板
  464. async openPasteboard(content, callBack = () => { }) {
  465. this.shearContent({ type: 'post', params: { content } }).then().finally(() => {
  466. callBack()
  467. // 获取剪切板
  468. this.getPasteVersion(() => {
  469. this.pasteVersionVisible = true
  470. this.levitatedSphereVisible = false
  471. })
  472. })
  473. },
  474. // 复制粘贴某条数据
  475. copyPasteVersiontext(e) {
  476. clickCopyText(e, (event) => {
  477. this.doConnectDirectivesWs.send(JSON.stringify({
  478. type: 'cutting',
  479. data: {
  480. str: event.text,
  481. },
  482. }))
  483. Toast('复制成功')
  484. }, () => {
  485. Toast('复制失败')
  486. })
  487. },
  488. // 获取卡信息
  489. getUserCardInfo() {
  490. Toast.loading({
  491. duration: 0, // 持续展示 toast
  492. message: '数据加载中...',
  493. });
  494. let { userCardId } = this.parametersData
  495. userCardId = +userCardId
  496. const statusTips = {
  497. 5200: '网络异常,请稍后重试',
  498. 5220: '云手机正在一键修复中',
  499. 5203: '正在排队中,请稍等',
  500. 5204: '云机异常,正在为你重新分配云机'
  501. }
  502. request.post('/api/resources/user/cloud/connect', { userCardId }).then(async res => {
  503. const { isWeixin } = this.parametersData;
  504. switch (res.status) {
  505. case 0:
  506. getUserCardInfoRequestNum = 1
  507. // 不支持webRTC跳转到指定的页面
  508. if (!res.data.isWebrtc) {
  509. location.replace(`${location.origin}/h5/webRtcYJ/WXtrialInterface.html${location.search}`)
  510. return
  511. }
  512. if (!this.isSupportRtc) {
  513. Dialog.alert({
  514. title: '提示',
  515. message: `${+isWeixin ? '微信小程序' : ''}当前版本暂不支持使用,可下载谷歌浏览器或双子星客户端进行使用`,
  516. confirmButtonText: '确定',
  517. confirmButtonColor: '#3cc51f',
  518. beforeClose: (action, done) => {
  519. this.exit()
  520. done()
  521. }
  522. })
  523. return
  524. }
  525. this.userCardInfoData = res.data
  526. this.doConnectDirectives()
  527. setTimeout(() => {
  528. this.connectWebRtc()
  529. }, 1000)
  530. return
  531. case 5200:
  532. case 5220:
  533. case 5203:
  534. case 5204:
  535. if (res.status === 5200) {
  536. reconnect.bind(this)()
  537. return
  538. }
  539. Toast(statusTips[res.status])
  540. break
  541. default:
  542. Toast('画面异常,请重新进入')
  543. break
  544. }
  545. setTimeout(() => {
  546. this.exit()
  547. }, 3000)
  548. })
  549. function reconnect() {
  550. if (getUserCardInfoRequestNum > 6) {
  551. Toast('网络异常,请稍后重试')
  552. clearTimeout(getUserCardInfoTimerInterval)
  553. setTimeout(() => {
  554. this.exit()
  555. }, 3000)
  556. return
  557. }
  558. getUserCardInfoTimerInterval = setTimeout(() => {
  559. this.getUserCardInfo()
  560. getUserCardInfoRequestNum++
  561. }, 3000)
  562. }
  563. },
  564. // 超过指定触碰时间是否提示关闭链接
  565. pushflowPopup() {
  566. request.get('/api/public/v5/pushflow/popup').then(res => {
  567. if (res.success) {
  568. this.isFiringNoOperationSetTimeout = res.data
  569. if (this.isFiringNoOperationSetTimeout) {
  570. this.noOperationSetTimeout()
  571. }
  572. }
  573. })
  574. },
  575. // // 获取网络运营商
  576. // district() {
  577. // request.get('https://qifu-api.baidubce.com/ip/local/geo/v1/district').then(res => {
  578. // if (res.data) {
  579. // this.districtValue = res.data.isp || res.data.owner || ''
  580. // }
  581. // if (!this.districtValue) getOperatorNetworkByIp()
  582. // }).catch(err => {
  583. // getOperatorNetworkByIp.bind(this)()
  584. // })
  585. // function getOperatorNetworkByIp() {
  586. // request.get('/api/resources/user/cloud/getOperatorNetworkByIp').then(res => {
  587. // if (res.success) {
  588. // this.districtValue = res.data.operatorNetwork
  589. // }
  590. // })
  591. // }
  592. // },
  593. // 退出功能
  594. exit() {
  595. this.engine.disconnect && this.engine.disconnect();
  596. this.doConnectDirectivesWs && this.doConnectDirectivesWs.close()
  597. uni.reLaunch({
  598. url: '/pages/index/index'
  599. });
  600. },
  601. // 不触碰屏幕显示退出链接弹窗
  602. noOperationSetTimeout(key) {
  603. if (this.isFiringNoOperationSetTimeout) return
  604. clearTimeout(noOperationSetTimeoutTimeInterval)
  605. if (key === 'cancel') {
  606. clearInterval(noOperationSetIntervalTimeInterval)
  607. this.noOperationSetTimeoutTimeVisible = false
  608. this.noOperationSetTimeout()
  609. return
  610. }
  611. noOperationSetTimeoutTimeInterval = setTimeout(() => {
  612. let index = 9
  613. this.confirmButtonText = '退出(10秒)'
  614. this.noOperationSetTimeoutTimeVisible = true
  615. noOperationSetIntervalTimeInterval = setInterval(() => {
  616. this.confirmButtonText = `退出${index ? `(${index}秒)` : ''}`
  617. index--
  618. if (index < 0) {
  619. this.noOperationSetTimeout('cancel')
  620. this.exit()
  621. }
  622. }, 1000)
  623. }, 300000)
  624. },
  625. // 获取云机剩余时长
  626. async getResidueTime() {
  627. clearInterval(countdownTimeInterval)
  628. const { userCardType, isShowCountdown, isShowRule } = this.parametersData
  629. const { userCardId } = this.userCardInfoData
  630. if (![1, 2, 3].includes(+userCardType)) return
  631. const res = await request.get(`/api/resources/yearMember/getResidueTime?userCardId=${userCardId}`)
  632. let time = res.data;
  633. if (!res.status) {
  634. this.countdownTime = residueTimeStamp(time)
  635. await request.get(`/api/resources/yearMember/startTime?userCardId=${userCardId}`)
  636. if (+isShowCountdown) this.timingVisible = true
  637. if (+isShowRule) this.billingRulesVisible = true
  638. countdownTimeInterval = setInterval(() => {
  639. if (time <= 0) {
  640. clearInterval(countdownTimeInterval)
  641. this.downline()
  642. return
  643. }
  644. time--
  645. this.countdownTime = residueTimeStamp(time)
  646. }, 1000)
  647. }
  648. },
  649. // 关闭倒计时弹窗
  650. handlecountdownTimeClose() {
  651. const { userCardId } = this.userCardInfoData
  652. request.get(`/api/resources/yearMember/closeRemind?userCardId=${userCardId}`).then(res => {
  653. if (!res.status) {
  654. clearInterval(countdownTimeInterval)
  655. this.timingVisible = false
  656. return
  657. }
  658. Toast(res.msg);
  659. })
  660. },
  661. // 退出并下机
  662. downline(fun = () => { }) {
  663. const { userCardId } = this.userCardInfoData
  664. request.get(`/api/resources/yearMember/downline?userCardId=${userCardId}`).then(res => {
  665. if (!res.status) {
  666. fun(true)
  667. // 通信给h5项目告知是退出并下机
  668. parent.postMessage(
  669. {
  670. type: 'exit',
  671. },
  672. '*',
  673. );
  674. uni.postMessage({
  675. data: {
  676. type: 'exit'
  677. }
  678. });
  679. this.exit()
  680. return
  681. }
  682. fun(false)
  683. Toast(res.msg);
  684. })
  685. },
  686. // 获取推荐列表
  687. getRecommend() {
  688. const { userCardId } = this.userCardInfoData
  689. request.get(`/api/public/v1/market/get/recommend?userCardId=${userCardId}`).then(res => {
  690. if (!res.status) {
  691. this.billingRulesVisible = false
  692. this.recommendList = res.data
  693. this.recommendList.length && (this.applyRecommendVisible = true)
  694. }
  695. })
  696. },
  697. // 下载apk
  698. downAndInstallApk({ downloadUrl: apkUrl, id: taskUid }) {
  699. this.doConnectDirectivesWs.send(JSON.stringify({
  700. type: 'downAndInstallApk',
  701. data: {
  702. apkUrl,
  703. taskUid
  704. },
  705. }))
  706. },
  707. // 移开手指时会发生的回调
  708. touchendRtcMediaPlayer(event) {
  709. this.engine.touchClick(event, 1, true)
  710. if (this.isFiringNoOperationSetTimeout) {
  711. this.noOperationSetTimeout()
  712. }
  713. }
  714. }
  715. })
  716. function playOnBtn() {
  717. const { isTips } = this.parametersData;
  718. Dialog.alert({
  719. title: '提示',
  720. message: `${+isTips ? '开始' : '继续'}使用云手机`,
  721. confirmButtonText: '确定',
  722. confirmButtonColor: '#3cc51f',
  723. beforeClose: (action, done) => {
  724. if (action === 'confirm') {
  725. this.$refs.rtcMediaPlayer.play()
  726. setTimeout(() => {
  727. this.definitionFun(this.definitionValue)
  728. })
  729. done()
  730. }
  731. }
  732. });
  733. }
  734. // 获取URL参数
  735. function getParameters() {
  736. let arr = location.search.split('?')
  737. let obj = {}
  738. if (arr[1]) {
  739. arr = arr[1].split('&')
  740. arr.forEach(item => {
  741. let [key, value = ''] = item.split('=')
  742. obj[key] = value
  743. })
  744. }
  745. return obj
  746. }
  747. // 倒计时处理的时间
  748. function residueTimeStamp(value) {
  749. let theTime = value;//秒
  750. let middle = 0;//分
  751. let hour = 0;//小时
  752. if (theTime > 59) {
  753. middle = parseInt(theTime / 60);
  754. theTime = parseInt(theTime % 60);
  755. }
  756. if (middle > 59) {
  757. hour = parseInt(middle / 60);
  758. middle = parseInt(middle % 60);
  759. }
  760. theTime < 10 ? theTime = '0' + theTime : theTime = theTime
  761. middle < 10 ? middle = '0' + middle : middle = middle
  762. hour < 10 ? hour = '0' + hour : hour = hour
  763. return hour + ':' + middle + ':' + theTime
  764. }