WXtrialInterface.js 30 KB

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