index.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. import { Transition, defineComponent, onMounted, ref } from 'vue';
  2. import LayoutSilder from './layoutSilder';
  3. import LayoutTop from './layoutTop';
  4. import styles from './index.module.less';
  5. import { NImage, NModal, NPopover } from 'naive-ui';
  6. import Moveable from 'moveable';
  7. import toolbox from './images/toolbox.png';
  8. import setTimeIcon from './images/setTimeIcon.png';
  9. import beatIcon from './images/beatIcon.png';
  10. import toneIcon from './images/toneIcon.png';
  11. import beatImage from './images/beatImage.png';
  12. import toneImage from './images/toneImage.png';
  13. import setTimeImage from './images/setTimeImage.png';
  14. import dragingBoxIcon from './images/dragingBoxIcon.png';
  15. export default defineComponent({
  16. name: 'layoutView',
  17. setup() {
  18. const directionType = ref('left');
  19. const showModalBeat = ref(false);
  20. const showModalTone = ref(false);
  21. const showModalTime = ref(false);
  22. const isDragIng = ref(false);
  23. const initMoveable = async () => {
  24. if (document.querySelector('.wrap')) {
  25. const moveable = new Moveable(document.querySelector('.wrap') as any, {
  26. target: document.querySelector('#moveNPopover') as any,
  27. // If the container is null, the position is fixed. (default: parentElement(document.body))
  28. container: document.querySelector('.wrap') as any,
  29. // snappable: true,
  30. // bounds: {"left":100,"top":100,"right":100,"bottom":100},
  31. draggable: true,
  32. resizable: false,
  33. scalable: false,
  34. rotatable: false,
  35. warpable: false,
  36. pinchable: false, // ["resizable", "scalable", "rotatable"]
  37. origin: false,
  38. keepRatio: false,
  39. // Resize, Scale Events at edges.
  40. edge: false,
  41. throttleDrag: 0,
  42. throttleResize: 0,
  43. throttleScale: 0,
  44. throttleRotate: 0
  45. });
  46. moveable
  47. // .on('dragStart', ({ target, clientX, clientY }) => {
  48. // console.log('dragStart');
  49. // })
  50. .on(
  51. 'drag',
  52. ({
  53. target,
  54. transform,
  55. left,
  56. top,
  57. right,
  58. bottom,
  59. beforeDelta,
  60. beforeDist,
  61. delta,
  62. dist,
  63. clientX,
  64. clientY
  65. }) => {
  66. isDragIng.value = true;
  67. const subdEl = document.getElementById(
  68. `moveNPopover`
  69. ) as HTMLDivElement;
  70. // console.log(subdEl, "subdEl", "drag");
  71. const subdElStyle = getComputedStyle(subdEl, null);
  72. const RectInfo = {
  73. left: Number(subdElStyle.left.replace('px', '')),
  74. top: Number(subdElStyle.top.replace('px', '')),
  75. width: Number(subdElStyle.width.replace('px', '')),
  76. height: Number(subdElStyle.height.replace('px', ''))
  77. };
  78. const mainWidth =
  79. parseInt(
  80. window.getComputedStyle(
  81. document.querySelector('.wrap') as Element
  82. ).width
  83. ) - RectInfo.width;
  84. const mainHeight =
  85. parseInt(
  86. window.getComputedStyle(
  87. document.querySelector('.wrap') as Element
  88. ).height
  89. ) - RectInfo.height;
  90. if (left < 0) {
  91. left = 2;
  92. }
  93. if (top < 0) {
  94. top = 2;
  95. }
  96. if (right < 0) {
  97. right = 2;
  98. }
  99. if (bottom < 0) {
  100. bottom = 2;
  101. }
  102. if (left > mainWidth - 2) {
  103. left = mainWidth - 2;
  104. }
  105. if (top > mainHeight - 2) {
  106. top = mainHeight - 2;
  107. }
  108. target!.style.left = `${left}px`;
  109. target!.style.top = `${top}px`;
  110. }
  111. )
  112. .on('dragEnd', async ({ target, isDrag, clientX, clientY }) => {
  113. if (document.body.clientWidth / 2 - clientX > 0) {
  114. // 往左出
  115. directionType.value = 'right';
  116. } else {
  117. // 往又出
  118. directionType.value = 'left';
  119. }
  120. isDragIng.value = false;
  121. });
  122. }
  123. };
  124. onMounted(() => {
  125. initMoveable();
  126. });
  127. const startShowModal = (val: 'setTimeIcon' | 'beatIcon' | 'toneIcon') => {
  128. if (val == 'setTimeIcon') {
  129. showModalTime.value = true;
  130. }
  131. if (val == 'beatIcon') {
  132. showModalBeat.value = true;
  133. }
  134. if (val == 'toneIcon') {
  135. showModalTone.value = true;
  136. }
  137. };
  138. return () => (
  139. <div class={[styles.wrap, 'wrap']}>
  140. <div>
  141. <LayoutSilder></LayoutSilder>
  142. </div>
  143. <div class={styles.Wrapcore}>
  144. <LayoutTop></LayoutTop>
  145. <div class={styles.WrapcoreView}>
  146. {/* <div class={styles.WrapcoreViewInfo}> */}
  147. <router-view>
  148. {(obj: any) => (
  149. <Transition name="fade-slide" mode="out-in">
  150. <obj.Component />
  151. </Transition>
  152. )}
  153. </router-view>
  154. {/* </div> */}
  155. </div>
  156. </div>
  157. <NPopover
  158. raw
  159. trigger="click"
  160. show-arrow={false}
  161. placement={directionType.value as 'left' | 'right'}
  162. v-slots={{
  163. trigger: () => (
  164. <img
  165. src={isDragIng.value ? dragingBoxIcon : toolbox}
  166. id="moveNPopover"
  167. class={[
  168. styles.toolboxImg,
  169. 'moveNPopover',
  170. isDragIng.value ? styles.isDragIng : ''
  171. ]}
  172. alt=""
  173. />
  174. )
  175. }}>
  176. <div class={styles.booxToolWrap}>
  177. <div
  178. class={styles.booxToolItem}
  179. onClick={() => startShowModal('beatIcon')}>
  180. <img src={beatIcon} alt="" />
  181. 节拍器
  182. </div>
  183. <div
  184. class={styles.booxToolItem}
  185. onClick={() => startShowModal('toneIcon')}>
  186. <img src={toneIcon} alt="" />
  187. 调音器
  188. </div>
  189. <div
  190. class={styles.booxToolItem}
  191. onClick={() => startShowModal('setTimeIcon')}>
  192. <img src={setTimeIcon} alt="" />
  193. 计时器
  194. </div>
  195. </div>
  196. </NPopover>
  197. <NModal v-model:show={showModalBeat.value}>
  198. <div
  199. onClick={() => {
  200. showModalBeat.value = false;
  201. }}>
  202. <NImage
  203. src={beatImage}
  204. previewDisabled
  205. class={styles.beatImage}></NImage>
  206. </div>
  207. </NModal>
  208. <NModal v-model:show={showModalTone.value}>
  209. <div
  210. onClick={() => {
  211. showModalTone.value = false;
  212. }}>
  213. <NImage
  214. src={toneImage}
  215. previewDisabled
  216. class={styles.beatImage}></NImage>
  217. </div>
  218. </NModal>
  219. <NModal v-model:show={showModalTime.value}>
  220. <div
  221. onClick={() => {
  222. showModalTime.value = false;
  223. }}>
  224. <NImage
  225. src={setTimeImage}
  226. previewDisabled
  227. class={styles.setTimeImage}></NImage>
  228. </div>
  229. </NModal>
  230. </div>
  231. );
  232. }
  233. });