WXtrialInterface.js 29 KB

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