WXtrialInterface.js 29 KB

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