CloudGroupDropdown.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="group-dropdown pt-2 pb-2">
  3. <!-- 设备分组下拉 -->
  4. <Dropdown key="deviceList" v-model="activeGroup" :isActvie="true" @visible="(visible)=>($emit('dropdownVisibleChange', visible))" :list="groupList" :prop="{value: 'id'}" :dropdownMenuStyle="{ left: '0', top: '30px' }" :activeStyle="activeStyle">
  5. <!-- 触发下拉 -->
  6. <div class="menu-trigger"><div class="device-trigger-ex">{{ groupList.find(g => g.id === activeGroup).label }}</div><van-icon class="icon-arrow rotate-down" name="play" color="#fff" size="10" /></div>
  7. </Dropdown>
  8. <!-- 清晰度下拉 -->
  9. <Dropdown key="definition" ref="definitionDropdown" @visible="(visible)=>($emit('dropdownVisibleChange', visible))" :dropdownMenuStyle="{ left: '0', top: '30px' }">
  10. <!-- 触发下拉 -->
  11. <div class="menu-trigger">
  12. <div class="definition-trigger-ex">
  13. <span>{{ activeDefinition }}</span>
  14. <!-- 0-50ms绿色;51-200ms黄色;201-999ms红色;最多显示999ms;变色部分为延迟变色 -->
  15. <span class="definition-val" :class="{success: latency < 51, warning: latency > 50 && latency < 201, danger: latency > 200}">{{ latency }}ms</span>
  16. </div>
  17. <van-icon class="icon-arrow rotate-down" name="play" color="#fff" size="10" />
  18. </div>
  19. <!-- 清晰度下拉 -->
  20. <div slot="dropdown-menu">
  21. <DropdownMenu :activeValue="activeDefinition" :list="definitionList" :isActvie="true" :activeStyle="activeStyle" @change="selectFeatures" />
  22. </div>
  23. </Dropdown>
  24. </div>
  25. </template>
  26. <script>
  27. /**
  28. * 云机分组下拉框
  29. */
  30. // 引入自定义下拉项目组件
  31. import DropdownMenu from './DropdownMenu.vue'
  32. export default {
  33. name: 'CloudGroupDropdown',
  34. components: {
  35. DropdownMenu,
  36. },
  37. props: {
  38. // 拉流渲染引擎实例
  39. engine: {
  40. type: Object,
  41. default: () => ({})
  42. },
  43. // 网络延迟
  44. latency: {
  45. type: Number,
  46. default: 0,
  47. },
  48. // 选中的设备分组id 默认-1, 代表全部设备
  49. activeGroupId: {
  50. type: Number,
  51. default: -1,
  52. },
  53. // 设备分组下拉菜单数据
  54. groupList: {
  55. type: Array,
  56. default: () => []
  57. },
  58. // 清晰度默认值
  59. definitionValue: {
  60. type: String,
  61. default: ()=> localStorage.getItem('definitionValue') ?? '自动',
  62. },
  63. // 清晰度选项列表
  64. definitionList: {
  65. type: Array,
  66. default: () => [{
  67. label: '自动',
  68. value: '720P',
  69. bitrate: 2800, // 码率
  70. fps: 30, // 帧率
  71. width: 720, // 宽度
  72. height: 1280, // 高度
  73. }, {
  74. label: '高清',
  75. value: '720P',
  76. bitrate: 2800, // 码率
  77. fps: 30, // 帧率
  78. width: 720, // 宽度
  79. height: 1280, // 高度
  80. }, {
  81. label: '标清',
  82. value: '540P',
  83. bitrate: 1500, // 码率
  84. fps: 25, // 帧率
  85. width: 540, // 宽度
  86. height: 960, // 高度
  87. }, {
  88. label: '流畅',
  89. value: '360P',
  90. bitrate: 1000, // 码率
  91. fps: 20, // 帧率
  92. width: 360, // 宽度
  93. height: 640, // 高度
  94. }]
  95. },
  96. },
  97. data() {
  98. return {
  99. // 高亮项样式
  100. activeStyle: {
  101. color: '#FEAE4D',
  102. },
  103. activeDefinition: this.definitionValue, // 当前选中的清晰度
  104. }
  105. },
  106. computed: {
  107. // 选中的设备分组id
  108. activeGroup: {
  109. get() {
  110. return this.activeGroupId;
  111. },
  112. set(val) {
  113. this.$emit("update:activeGroupId", val);
  114. }
  115. },
  116. },
  117. methods: {
  118. // 选择清晰度
  119. selectFeatures(item) {
  120. // 更新清晰度值
  121. this.activeDefinition = item.label;
  122. localStorage.setItem('definitionValue', item.label);
  123. // 设置码率
  124. this.setBitrate(item);
  125. // 关闭清晰度下拉框
  126. this.$refs.definitionDropdown.visible = false;
  127. },
  128. // 设置码率
  129. setBitrate({width, height, fps, bitrate, label}) {
  130. // 设置码率和是否允许自动
  131. this.engine?.setCustomBitrate(bitrate, label === '自动');
  132. // 设置编码器分辨率和帧率
  133. this.engine?.setEncoderSize({
  134. width,
  135. height,
  136. fps,
  137. });
  138. },
  139. },
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .group-dropdown{
  144. display: flex;
  145. justify-content: space-around;
  146. }
  147. .menu-trigger{
  148. background-color: #5C5C5C;
  149. box-shadow: 0px 0px 30px 0px #1E2022;
  150. border-radius: 14px;
  151. padding: 6px 15px;
  152. display: inline-block;
  153. font-weight: 400;
  154. font-size: 12px;
  155. color: #F9F9F9;
  156. // 设备分组触发下拉
  157. .device-trigger-ex{
  158. display: inline-block;
  159. text-align: left;
  160. width: 88px;
  161. }
  162. // 清晰度触发下拉
  163. .definition-trigger-ex{
  164. display: inline-flex;
  165. justify-content: space-between;
  166. width: 94px;
  167. // 0-50ms绿色;51-200ms黄色;201-999ms红色;最多显示999ms;变色部分为延迟变色
  168. .definition-val{
  169. &.danger{
  170. color: #FF2627;
  171. }
  172. &.warning{
  173. color: #FF9800;
  174. }
  175. &.success{
  176. color: #44E2B1;
  177. }
  178. }
  179. }
  180. .icon-arrow{
  181. transition: transform 0.2s ease;
  182. &.rotate-down{
  183. transform: rotate(90deg);
  184. }
  185. &.rotate-up{
  186. transform: rotate(0270deg);
  187. }
  188. }
  189. }
  190. </style>