LeftMenuPopup.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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" @funcHandle="funcHandle"/>
  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. // url中获取的参数, 父组件传递
  88. parametersData: {
  89. type: Object,
  90. default: () => ({})
  91. },
  92. },
  93. components: {
  94. CloudMainPanel,
  95. FunctionMenu,
  96. CloudList,
  97. CapsuleSelect,
  98. CloudGroupDropdown,
  99. },
  100. data() {
  101. return {
  102. // 当前清晰度
  103. actDefinition: this.definitionValue,
  104. // 云机列表高度
  105. cloudListScrollHeight: 0,
  106. /**
  107. * popup遮罩的overflow-y属性是否启用
  108. * @type {Boolean}
  109. * @description 解决下拉框的遮罩会裁剪的问题, 当下拉框弹出时,需设置此属性,否则下拉框的遮罩会裁剪
  110. * 下拉框弹出时,点击任意地方可以关闭下拉框, 但是遮罩的overflow-y属性会被设置为hidden, 导致下拉框的遮罩会裁剪
  111. * 解决方法: 在下拉框弹出时,设置popupMaskOverflowY为true, 关闭下拉框时,设置popupMaskOverflowY为false
  112. * */
  113. popupMaskOverflowY: true,
  114. // 当前选择的云机分组id 默认-1, 代表全部设备
  115. activeGroupId: -1,
  116. }
  117. },
  118. watch: {
  119. levitatedSphereVisible(val) {
  120. // 弹窗显示时,获取云机列表的高度
  121. if (val) {
  122. this.$nextTick(() => {
  123. this.scrollHeight();
  124. });
  125. }
  126. },
  127. },
  128. methods: {
  129. // 获取并设置云机列表的滚动高度
  130. // 1. 显示弹窗时,获取云机列表的高度
  131. // 2. 功能展开及收起时,获取云机列表的高度
  132. scrollHeight() {
  133. try {
  134. // 获取popup总高度
  135. let popupHheight = document.getElementsByClassName('levitated-sphere-drawer')[0]?.offsetHeight ?? 0;
  136. // 获取顶部云机id等信息高度
  137. let headerHeight = document.getElementById('pupop-header')?.offsetHeight ?? 0;
  138. // 获取功能区域高度
  139. let functionMenuHeight = document.getElementById('function-menu').offsetHeight ?? 0;
  140. // 获取下拉选项区高度
  141. let selectWrapHeight = document.getElementById('select-wrap').offsetHeight ?? 0;
  142. // 获取退出按钮高度
  143. let exitWrapHeight = document.getElementById('exit-wrap').offsetHeight ?? 0;
  144. // 计算出云机列表的高度
  145. let scrollHeight = popupHheight - headerHeight - functionMenuHeight - selectWrapHeight - exitWrapHeight;
  146. // 如果计算出的云机列表的高度小于100,那么就设置为100, 防止云机列表高度为0
  147. scrollHeight < 100 ? this.cloudListScrollHeight = 100 : this.cloudListScrollHeight = scrollHeight;
  148. } catch (error) {
  149. console.error('Error calculating scroll height:', error);
  150. // 如果计算失败,则设置为0
  151. this.cloudListScrollHeight = 100;
  152. }
  153. },
  154. // 处理功能菜单的事件
  155. funcHandle(val){
  156. // 关闭popup
  157. this.$emit('update:levitatedSphereVisible', false);
  158. // 触发父组件事件
  159. this.$emit('funcHandle', val);
  160. },
  161. /**
  162. * 根据卡套餐获取对应图标
  163. * @method imgFun
  164. * @param {String} type--1 套餐类型 VIP|SVIP|STARRYSKY
  165. * @param {String} androidVersion--2 安卓系统版本
  166. * @param {String} key='previewUrl'--3 ['previewUrl' | 'phonePreviewUrl'] 判断是预览图还是套餐图标用的
  167. * @returns {String} 图片路径
  168. *
  169. */
  170. imgFun(type, androidVersion = '', key = 'previewUrl') {
  171. let obj = this.mealTypeObj[type + androidVersion]
  172. // obj[key]的值是default或defaultPhonePreviewUrl时候,就是后端没有返回图标还有预览图过来,显示默认的
  173. return obj[key] === 'default' ? '/static/img/userMealUpgradeVO_icon.png' : (obj[key] === 'defaultPhonePreviewUrl' ?
  174. this.remoteImgUrl + 'defalut-preview.png' : obj[key])
  175. },
  176. showChange(val){
  177. this.$emit('update:levitatedSphereVisible', val);
  178. },
  179. async exit(){
  180. try {
  181. const activeCloud = this.cloudList.find(item => item.userCardId === +this.userCardId);
  182. // 判断当前云机
  183. // 1、2、3:年卡、普通计时、自动续费普通计时卡
  184. if ([1, 2, 3].includes(activeCloud.userCardType)) {
  185. this.$dialog.alert({
  186. title: '提示',
  187. message: '确定退出云手机并下机',
  188. confirmButtonText: '确定',
  189. confirmButtonColor: '#3cc51f',
  190. showCancelButton: true,
  191. beforeClose: (action, done) => {
  192. if (action === 'cancel') done()
  193. if (action === 'confirm') {
  194. this.$axios.get('/resources/yearMember/downline?userCardId=${this.userCardId}`')
  195. .then((res) => {
  196. if(!res.status){
  197. done(true);
  198. // 判断是否是顶级窗口(不是嵌套在 iframe 中)目前只有ios的浏览器中才会是顶级窗口
  199. const isTopWindow = window.parent === window.self;
  200. if(isTopWindow){
  201. // 通信给h5项目告知是退出并下机
  202. parent.postMessage({ type: 'exit' }, '*');
  203. uni.postMessage({ data: { type: 'exit' }});
  204. }
  205. // 关闭popup
  206. this.$emit('update:levitatedSphereVisible', false);
  207. this.$emit('exit');
  208. } else {
  209. done(false);
  210. this.$toast(res.msg);
  211. }
  212. });
  213. }
  214. }
  215. })
  216. } else {
  217. // 关闭popup
  218. this.$emit('update:levitatedSphereVisible', false);
  219. this.$emit('exit');
  220. }
  221. } catch (error) {
  222. }
  223. }
  224. }
  225. }
  226. </script>
  227. <style lang="scss" scoped>
  228. // 文字高亮颜色
  229. $active-color: #FEAE4D;
  230. .left-menu-popup {
  231. // 当胶囊下拉框(下拉选项区)弹出时,需设置此属性,否则下拉框的遮罩会裁剪
  232. .levitated-sphere-drawer.overflow-y-initial{
  233. overflow-y: initial !important;
  234. }
  235. .menu-wrap{
  236. width: 300px;
  237. display: flex;
  238. flex-direction: column;
  239. #exit-wrap{
  240. padding: 9px 0;
  241. background-color: #1F1F1F;
  242. .exit-btn{
  243. width: 200px;
  244. }
  245. }
  246. }
  247. }
  248. </style>