LeftMenuPopup.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <!-- 左侧弹窗 -->
  3. <div class="left-menu-popup">
  4. <van-popup :value="levitatedSphereVisible" class="levitated-sphere-drawer" :class="{'overflow-y-initial': popupMaskOverflowY}" @input="showChange" position="left"
  5. overlay-class="levitated-sphere-overlay" :overlay-style="{'background-color': 'transparent !important'}" :style="{ height: '100%', 'background-color': '#2C2C2D' }">
  6. <div class="menu-wrap">
  7. <!-- 头部云机id等信息 -->
  8. <CloudMainPanel id="pupop-header" v-bind="$attrs" v-on="$listeners" :userCardId="userCardId" :cloudList="cloudList" />
  9. <!-- 功能区域 -->
  10. <FunctionMenu id="function-menu" @functionMenuVisible="scrollHeight" v-bind="$attrs" v-on="$listeners" />
  11. <!-- 包一层是为了获取区域的height计算云机列表滚动高度 -->
  12. <div id="select-wrap">
  13. <!-- 下拉选项区 -->
  14. <CloudGroupDropdown v-bind="$attrs" v-on="$listeners" :engine="engine" :activeGroupId.sync="activeGroupId" @dropdownVisibleChange="(val)=>(popupMaskOverflowY = val)"/>
  15. </div>
  16. <!-- 云机列表 -->
  17. <CloudList id="cloud-list" v-bind="$attrs" v-on="$listeners" :activeGroupId="activeGroupId" :userCardId="userCardId" :cloudList="cloudList" :height="`${cloudListScrollHeight}px`"/>
  18. <!-- 退出 -->
  19. <div id="exit-wrap">
  20. <van-button class="exit-btn" type="primary" size="small" color="#3370FF" @click="exit">退出并下机</van-button>
  21. </div>
  22. </div>
  23. </van-popup>
  24. </div>
  25. </template>
  26. <script>
  27. import * as uni from '../../../static/static/js/uni.webview.1.5.2.js';
  28. import CloudMainPanel from './CloudMainPanel.vue';
  29. import FunctionMenu from './FunctionMenu.vue';
  30. import CloudList from './CloudList.vue';
  31. import CapsuleSelect from './CapsuleSelect.vue';
  32. import CloudGroupDropdown from './CloudGroupDropdown.vue';
  33. export default {
  34. name: 'LeftMenuPopup',
  35. props: {
  36. // 拉流渲染引擎实例
  37. engine: {
  38. type: Object,
  39. default: () => ({})
  40. },
  41. userCardId: {
  42. type: [String, Number],
  43. default: ''
  44. },
  45. // 云机列表
  46. cloudList: {
  47. type: Array,
  48. default: () => []
  49. },
  50. // popup是否显示
  51. levitatedSphereVisible: {
  52. type: Boolean,
  53. default: false,
  54. },
  55. // 清晰度默认值
  56. definitionValue: {
  57. type: String,
  58. default: ()=> localStorage.getItem('definitionValue') ?? '自动',
  59. },
  60. // 清晰度列表
  61. definitionList: {
  62. type: Array,
  63. default: () => [{
  64. name: '自动',
  65. value: 2800
  66. }, {
  67. name: '高清',
  68. value: 2800
  69. }, {
  70. name: '标清',
  71. value: 1500,
  72. }, {
  73. name: '流畅',
  74. value: 1000,
  75. }]
  76. },
  77. // 清晰度对应分辨率和帧率列表
  78. resolutionRatioList: {
  79. type: Object,
  80. default: () => ({
  81. '自动': { width: 720, height: 1280, fps: 30 },
  82. '高清': { width: 720, height: 1280, fps: 30 },
  83. '标清': { width: 540, height: 960, fps: 25 },
  84. '流畅': { width: 360, height: 640, fps: 20 },
  85. })
  86. },
  87. },
  88. components: {
  89. CloudMainPanel,
  90. FunctionMenu,
  91. CloudList,
  92. CapsuleSelect,
  93. CloudGroupDropdown,
  94. },
  95. data() {
  96. return {
  97. // 当前清晰度
  98. actDefinition: this.definitionValue,
  99. // 云机列表高度
  100. cloudListScrollHeight: 0,
  101. /**
  102. * popup遮罩的overflow-y属性是否启用
  103. * @type {Boolean}
  104. * @description 解决下拉框的遮罩会裁剪的问题, 当下拉框弹出时,需设置此属性,否则下拉框的遮罩会裁剪
  105. * 下拉框弹出时,点击任意地方可以关闭下拉框, 但是遮罩的overflow-y属性会被设置为hidden, 导致下拉框的遮罩会裁剪
  106. * 解决方法: 在下拉框弹出时,设置popupMaskOverflowY为true, 关闭下拉框时,设置popupMaskOverflowY为false
  107. * */
  108. popupMaskOverflowY: true,
  109. // 当前选择的云机分组id 默认-1, 代表全部设备
  110. activeGroupId: -1,
  111. }
  112. },
  113. watch: {
  114. levitatedSphereVisible(val) {
  115. // 弹窗显示时,获取云机列表的高度
  116. if (val) {
  117. this.$nextTick(() => {
  118. this.scrollHeight();
  119. });
  120. }
  121. },
  122. },
  123. methods: {
  124. // 获取并设置云机列表的滚动高度
  125. // 1. 显示弹窗时,获取云机列表的高度
  126. // 2. 功能展开及收起时,获取云机列表的高度
  127. scrollHeight() {
  128. try {
  129. // 获取popup总高度
  130. let popupHheight = document.getElementsByClassName('levitated-sphere-drawer')[0]?.offsetHeight ?? 0;
  131. // 获取顶部云机id等信息高度
  132. let headerHeight = document.getElementById('pupop-header')?.offsetHeight ?? 0;
  133. // 获取功能区域高度
  134. let functionMenuHeight = document.getElementById('function-menu').offsetHeight ?? 0;
  135. // 获取下拉选项区高度
  136. let selectWrapHeight = document.getElementById('select-wrap').offsetHeight ?? 0;
  137. // 获取退出按钮高度
  138. let exitWrapHeight = document.getElementById('exit-wrap').offsetHeight ?? 0;
  139. // 计算出云机列表的高度
  140. let scrollHeight = popupHheight - headerHeight - functionMenuHeight - selectWrapHeight - exitWrapHeight;
  141. // 如果计算出的云机列表的高度小于100,那么就设置为100, 防止云机列表高度为0
  142. scrollHeight < 100 ? this.cloudListScrollHeight = 100 : this.cloudListScrollHeight = scrollHeight;
  143. } catch (error) {
  144. console.error('Error calculating scroll height:', error);
  145. // 如果计算失败,则设置为0
  146. this.cloudListScrollHeight = 100;
  147. }
  148. },
  149. /**
  150. * 根据卡套餐获取对应图标
  151. * @method imgFun
  152. * @param {String} type--1 套餐类型 VIP|SVIP|STARRYSKY
  153. * @param {String} androidVersion--2 安卓系统版本
  154. * @param {String} key='previewUrl'--3 ['previewUrl' | 'phonePreviewUrl'] 判断是预览图还是套餐图标用的
  155. * @returns {String} 图片路径
  156. *
  157. */
  158. imgFun(type, androidVersion = '', key = 'previewUrl') {
  159. let obj = this.mealTypeObj[type + androidVersion]
  160. // obj[key]的值是default或defaultPhonePreviewUrl时候,就是后端没有返回图标还有预览图过来,显示默认的
  161. return obj[key] === 'default' ? '/static/img/userMealUpgradeVO_icon.png' : (obj[key] === 'defaultPhonePreviewUrl' ?
  162. this.remoteImgUrl + 'defalut-preview.png' : obj[key])
  163. },
  164. showChange(val){
  165. this.$emit('update:levitatedSphereVisible', val);
  166. },
  167. async exit(){
  168. try {
  169. const activeCloud = this.cloudList.find(item => item.userCardId === +this.userCardId);
  170. // 判断当前云机
  171. // 1、2、3:年卡、普通计时、自动续费普通计时卡
  172. if ([1, 2, 3].includes(activeCloud.userCardType)) {
  173. this.$dialog.alert({
  174. title: '提示',
  175. message: '确定退出云手机并下机',
  176. confirmButtonText: '确定',
  177. confirmButtonColor: '#3cc51f',
  178. showCancelButton: true,
  179. beforeClose: (action, done) => {
  180. if (action === 'cancel') done()
  181. if (action === 'confirm') {
  182. this.$axios.get('/resources/yearMember/downline?userCardId=${this.userCardId}`')
  183. .then((res) => {
  184. if(!res.status){
  185. done(true);
  186. // 判断是否是顶级窗口(不是嵌套在 iframe 中)目前只有ios的浏览器中才会是顶级窗口
  187. const isTopWindow = window.parent === window.self;
  188. if(isTopWindow){
  189. // 通信给h5项目告知是退出并下机
  190. parent.postMessage({ type: 'exit' }, '*');
  191. uni.postMessage({ data: { type: 'exit' }});
  192. }
  193. // 关闭popup
  194. this.$emit('update:levitatedSphereVisible', false);
  195. this.$emit('exit');
  196. } else {
  197. done(false);
  198. this.$toast(res.msg);
  199. }
  200. });
  201. }
  202. }
  203. })
  204. } else {
  205. // 关闭popup
  206. this.$emit('update:levitatedSphereVisible', false);
  207. this.$emit('exit');
  208. }
  209. } catch (error) {
  210. }
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. // 文字高亮颜色
  217. $active-color: #FEAE4D;
  218. .left-menu-popup {
  219. // 当胶囊下拉框(下拉选项区)弹出时,需设置此属性,否则下拉框的遮罩会裁剪
  220. .levitated-sphere-drawer.overflow-y-initial{
  221. overflow-y: initial !important;
  222. }
  223. .menu-wrap{
  224. width: 300px;
  225. display: flex;
  226. flex-direction: column;
  227. #exit-wrap{
  228. padding: 9px 0;
  229. background-color: #1F1F1F;
  230. .exit-btn{
  231. width: 200px;
  232. }
  233. }
  234. }
  235. }
  236. </style>