WXtrialInterface.js 30 KB

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