Advertisement
KoctrX

Untitled

Jul 22nd, 2022
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.65 KB | None | 0 0
  1. <template>
  2. <div class="sidbar__wrpr flex flex-col">
  3.  
  4. <div class="flex items-center justify-between w-full left_sidebar_head">
  5. <h3 class="sidbar__title uppercase">RECORD</h3>
  6. <button class="sidbar__close ml-2.5" v-html="icons['close-my-files-arrow.svg']"></button>
  7. </div>
  8. <div class="sidbar__body rercord">
  9. <ul class="rercord-list">
  10. <li class="record-list__item mb-3"
  11. v-for="(item, index) in recordingTypes"
  12. :key="index" :class="{ 'active': item.title === (currentRecord && currentRecord.typeName)}"
  13. @click="addRecord(item)"
  14. >
  15. <div class="record-list__item-img">
  16. <img :src="item.img" alt="">
  17. </div>
  18. <div class="record-list__item-title">
  19. {{ item.title }}
  20. </div>
  21. </li>
  22. </ul>
  23.  
  24. <div class="current-records__item" v-if="currentRecord" :ref="'record-' + currentRecord.id"
  25. :style="'top:' + currentRecord.top + 'px'">
  26. <div class="current-records__item-move" :ref="'record-'+currentRecord.id+'-caret'">
  27. <inline-svg :src="require(`@/assets/img/move.svg`)"/>
  28. </div>
  29.  
  30. <div class="flex items-center cursor-pointer" @click="toggleRecord(currentRecord)">
  31. <inline-svg v-if="currentRecord.isActive" :src="require(`@/assets/img/record-play.svg`)"/>
  32. <inline-svg v-if="!currentRecord.isActive" :src="require(`@/assets/img/record-stop.svg`)"/>
  33. </div>
  34.  
  35. <div class="current-records__item-micro p-2"
  36. :class="{'active': currentRecord.isActive, 'context': contextMenu.open}"
  37. @click="currentRecord.isMicroActive = !currentRecord.isMicroActive"
  38. @contextmenu.prevent="openContextMenu($event, currentRecord)">
  39. <inline-svg v-if="!currentRecord.isMicroActive" :src="require(`@/assets/img/micro-disabled.svg`)"/>
  40. <inline-svg v-if="currentRecord.isMicroActive" :src="require(`@/assets/img/micro-enabled.svg`)"/>
  41. </div>
  42.  
  43. <div class="flex items-center current-records__item-timer" :class="{'active': currentRecord.isActive}">
  44. <span>
  45. <span>{{ currentRecord.time | time }}</span>
  46. <!-- / <span style="color: #a8a6a6;">{{ currentRecord.max | time }}</span> -->
  47. </span>
  48. </div>
  49.  
  50. <div class="current-records__item-close p-2" @click="closeRecord">
  51. <inline-svg :src="require(`@/assets/img/record-close.svg`)"/>
  52. </div>
  53. </div>
  54.  
  55. <ul class="custom-select__dropdown context-menu record active"
  56. v-if="contextMenu.open"
  57. style="position: fixed;"
  58. :style="{
  59. top: contextMenu.top + 'px',
  60. left: contextMenu.left + 'px'
  61. }" v-click-outside="closeMenu">
  62. <li class="custom-select__item flex items-center cursor-pointer pl-3"
  63. v-for="(device, index) in contextMenu.currentRecord.devices"
  64. :key="index" :class="{'active': device.title === contextMenu.currentRecord.selectedDevice}"
  65. @click="$set(contextMenu.item, 'selectedDevice', device.title)">
  66. <div class="flex items-center cursor-pointer">
  67. <span class="ml-2">{{ device.title }}</span>
  68. </div>
  69. </li>
  70. </ul>
  71. </div>
  72. </div>
  73. </template>
  74.  
  75. <script>
  76. import { svgIcons } from "@/helpers/index.js";
  77.  
  78. export default {
  79. filters: {
  80. time: function(ms) {
  81. let secNum = ms / 1000;
  82. let minutes = parseInt(secNum / 60);
  83. let seconds = secNum % 60 || 0;
  84.  
  85. if (minutes < 10) {minutes = "0"+minutes;}
  86. if (seconds < 10) {seconds = "0"+seconds;}
  87.  
  88. return `${minutes}:${seconds}`;
  89. }
  90. },
  91.  
  92. data() {
  93. return {
  94. icons: svgIcons,
  95. recordHeight: 42,
  96. contextMenu: {
  97. open: false,
  98. left: 0,
  99. top: 0,
  100. item: null,
  101. },
  102. }
  103. },
  104.  
  105. computed: {
  106. recordingTypes() {
  107. return this.$store.state.recorderState.recordingTypes;
  108. },
  109.  
  110. currentRecord: {
  111. get() { return this.$store.state.recorderState.recordingType; },
  112. set(val) { this.$store.state.recorderState.recordingType = val; }
  113. }
  114. },
  115.  
  116. methods: {
  117. async addRecord(recordType) {
  118. const record = {
  119. type: recordType.type,
  120. typeName: recordType.title,
  121. isActive: false,
  122. isMicroActive: false,
  123. time: 0,
  124. interval: null,
  125. id: Math.floor(Math.random() * 10000),
  126. // index: this.currentRecords.length,
  127. top: window.innerHeight - this.recordHeight - 10,//window.innerHeight - (this.recordHeight * (this.currentRecords.length + 1 )) - 10 * this.currentRecords.length,
  128. selectedDevice: 'None',
  129. devices: [
  130. {
  131. title: 'Default - Microphone #1 (High Definition Audio Device)'
  132. },
  133. {
  134. title: 'Microphone #2 (High Definition Audio Device) '
  135. },
  136. {
  137. title: 'Microphone #3 (High Definition Audio Device) '
  138. },
  139. {
  140. title: 'None'
  141. }
  142. ]
  143. }
  144.  
  145. // this.currentRecords.push(record);
  146.  
  147. if (this.currentRecord) {
  148. await this.closeRecord();
  149. }
  150.  
  151. this.currentRecord = record;
  152. setTimeout(() => {
  153. this.dragElement(this.$refs[`record-${record.id}`], this.$refs[`record-${record.id}-caret`])
  154. }, 30)
  155. },
  156.  
  157. toggleRecord(record) {
  158. if (!record.isActive) {
  159. record.interval = setInterval(() => {
  160. // if (record.time == record.max) {
  161. // return clearInterval(this.interval);
  162. // }
  163.  
  164. record.time += 1000;
  165. }, 1000);
  166.  
  167. } else {
  168. clearInterval(record.interval)
  169. }
  170.  
  171. this.$set(record, 'isActive', !record.isActive);
  172. },
  173.  
  174. dragElement(elmnt, caret) {
  175. if (!elmnt) return;
  176.  
  177. let pos1 = 0,
  178. pos2 = 0,
  179. pos3 = 0,
  180. pos4 = 0;
  181.  
  182. const dragMouseDown = (e) => {
  183. console.log(e)
  184. e = e || window.event;
  185. e.preventDefault();
  186.  
  187. // get the mouse cursor position at startup:
  188. pos3 = e.clientX;
  189. pos4 = e.clientY;
  190. document.onmouseup = closeDragElement;
  191.  
  192. // call a function whenever the cursor moves:
  193. document.onmousemove = elementDrag;
  194. }
  195.  
  196. const elementDrag = (e) => {
  197. e = e || window.event;
  198. e.preventDefault();
  199.  
  200. // calculate the new cursor position:
  201. pos1 = pos3 - e.clientX;
  202. pos2 = pos4 - e.clientY;
  203. pos3 = e.clientX;
  204. pos4 = e.clientY;
  205.  
  206. // set the element's new position:
  207. elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
  208. elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  209. }
  210.  
  211. const closeDragElement = () => {
  212. /* stop moving when mouse button is released:*/
  213. document.onmouseup = null;
  214. document.onmousemove = null;
  215. }
  216.  
  217. if (caret) {
  218. /* if present, the header is where you move the DIV from:*/
  219. caret.addEventListener('mousedown', dragMouseDown);
  220. } else {
  221. /* otherwise, move the DIV from anywhere inside the DIV:*/
  222. elmnt.addEventListener('mousedown', dragMouseDown);
  223. }
  224. },
  225.  
  226. openContextMenu(event, item) {
  227. const contextHeight = 144;
  228.  
  229. this.contextMenu.left = event.clientX;
  230. this.contextMenu.top = event.clientY + contextHeight > window.innerHeight ? window.innerHeight - contextHeight : event.clientY ;
  231. this.contextMenu.open = true;
  232. this.contextMenu.item = item;
  233. },
  234.  
  235. closeMenu(){
  236. this.contextMenu = {
  237. open: false,
  238. left: 0,
  239. top: 0,
  240. item: null,
  241. }
  242. },
  243.  
  244. async closeRecord() {
  245. if (!this.currentRecord.time) return this.currentRecord = null;
  246.  
  247. if (this.currentRecord.type === 'video') {
  248. this.openPopup('RecordVideo');
  249. } else {
  250. this.openPopup('RecordAudio');
  251. }
  252.  
  253. return new Promise((res, rej) => {
  254. setTimeout(() => {
  255. Array.from(document.querySelectorAll('.record-btn')).forEach(node => {
  256. node.addEventListener('click', () => {
  257. this.currentRecord = null;
  258. res();
  259. })
  260. })
  261. }, 50)
  262. })
  263.  
  264. // this.currentRecords.splice(index, 1)
  265. },
  266.  
  267. openPopup(value) {
  268. this.$store.commit('openPopup', value);
  269. },
  270. },
  271. }
  272. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement