LeftMenuPopup.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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" />
  9. <!-- 功能区域 -->
  10. <FunctionMenu id="function-menu" @functionMenuVisible="scrollHeight" @funcHandle="funcHandle"/>
  11. <!-- 包一层是为了获取区域的height计算云机列表滚动高度 -->
  12. <div id="select-wrap">
  13. <!-- 下拉选项区 -->
  14. <CloudGroupDropdown v-bind="$attrs" v-on="$listeners" :engine="engine" @dropdownVisibleChange="(val)=>(popupMaskOverflowY = val)"/>
  15. </div>
  16. <!-- 云机列表 -->
  17. <CloudList id="cloud-list" :height="`${cloudListScrollHeight}px`"/>
  18. <!-- 退出 -->
  19. <div id="exit-wrap">
  20. <van-button class="exit-btn" type="primary" size="small" color="#3370FF">退出并下机</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,
  43. default: ''
  44. },
  45. // popup是否显示
  46. levitatedSphereVisible: {
  47. type: Boolean,
  48. default: false,
  49. },
  50. // 清晰度默认值
  51. definitionValue: {
  52. type: String,
  53. default: ()=> localStorage.getItem('definitionValue') ?? '自动',
  54. },
  55. // 清晰度列表
  56. definitionList: {
  57. type: Array,
  58. default: () => [{
  59. name: '自动',
  60. value: 2800
  61. }, {
  62. name: '高清',
  63. value: 2800
  64. }, {
  65. name: '标清',
  66. value: 1500,
  67. }, {
  68. name: '流畅',
  69. value: 1000,
  70. }]
  71. },
  72. // 清晰度对应分辨率和帧率列表
  73. resolutionRatioList: {
  74. type: Object,
  75. default: () => ({
  76. '自动': { width: 720, height: 1280, fps: 30 },
  77. '高清': { width: 720, height: 1280, fps: 30 },
  78. '标清': { width: 540, height: 960, fps: 25 },
  79. '流畅': { width: 360, height: 640, fps: 20 },
  80. })
  81. },
  82. // url中获取的参数, 父组件传递
  83. parametersData: {
  84. type: Object,
  85. default: () => ({})
  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. }
  110. },
  111. computed: {
  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. funcHandle(val){
  151. // 关闭popup
  152. this.$emit('update:levitatedSphereVisible', false);
  153. // 触发父组件事件
  154. this.$emit('funcHandle', val);
  155. },
  156. /**
  157. * 根据卡套餐获取对应图标
  158. * @method imgFun
  159. * @param {String} type--1 套餐类型 VIP|SVIP|STARRYSKY
  160. * @param {String} androidVersion--2 安卓系统版本
  161. * @param {String} key='previewUrl'--3 ['previewUrl' | 'phonePreviewUrl'] 判断是预览图还是套餐图标用的
  162. * @returns {String} 图片路径
  163. *
  164. */
  165. imgFun(type, androidVersion = '', key = 'previewUrl') {
  166. let obj = this.mealTypeObj[type + androidVersion]
  167. // obj[key]的值是default或defaultPhonePreviewUrl时候,就是后端没有返回图标还有预览图过来,显示默认的
  168. return obj[key] === 'default' ? '/static/img/userMealUpgradeVO_icon.png' : (obj[key] === 'defaultPhonePreviewUrl' ?
  169. this.remoteImgUrl + 'defalut-preview.png' : obj[key])
  170. },
  171. showChange(val){
  172. this.$emit('update:levitatedSphereVisible', val);
  173. },
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. // 文字高亮颜色
  179. $active-color: #FEAE4D;
  180. .left-menu-popup {
  181. // 当胶囊下拉框(下拉选项区)弹出时,需设置此属性,否则下拉框的遮罩会裁剪
  182. .levitated-sphere-drawer.overflow-y-initial{
  183. overflow-y: initial !important;
  184. }
  185. .menu-wrap{
  186. width: 300px;
  187. display: flex;
  188. flex-direction: column;
  189. #exit-wrap{
  190. padding: 9px 0;
  191. background-color: #1F1F1F;
  192. .exit-btn{
  193. width: 200px;
  194. }
  195. }
  196. }
  197. }
  198. </style>