PaintingDetailBox.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <script setup>
  2. import { ref, onMounted, computed } from 'vue'
  3. const props = defineProps({
  4. direction: {
  5. type: String,
  6. default: "横",
  7. },
  8. url: {
  9. type: String,
  10. default: "",
  11. },
  12. bigUrl: {
  13. type: String,
  14. default: "",
  15. }
  16. })
  17. const isRow = computed(() => {
  18. return props.direction
  19. })
  20. // 画作是否超过了屏幕(可以拖动)
  21. const isMove = ref(false)
  22. const imgWidth = ref(0)
  23. const imgHeight = ref(0)
  24. const pageHeight = ref(0)
  25. const zhouMove = ref(3)
  26. const tiemrr = ref(-1)
  27. // 画轴移动
  28. const isFlag = ref(false)
  29. const moveLoc = ref(0)
  30. // 横轴左侧大盒子的宽度
  31. const leftBoxWidth = ref(0)
  32. const mousemoveFu = (e, flag) => {
  33. let ev = e || event
  34. if (isFlag.value && isMove.value) {
  35. if (isRow.value === "竖") {
  36. // 最大能往下移动的距离
  37. const maxNum = imgHeight.value - window.innerHeight
  38. // 向上是负 向下是正
  39. let temp = moveLoc.value + ev.movementY * (flag ? -5 : 1)
  40. if (-temp < 0) temp = 0
  41. else if (-temp >= maxNum) temp = -maxNum
  42. moveLoc.value = temp
  43. } else {
  44. // 最大能往右移动的距离
  45. const maxNum = imgWidth.value - leftBoxWidth.value
  46. // 向左是负 向右是正
  47. let temp = moveLoc.value + ev.movementX * (flag ? -5 : 1)
  48. if (-temp < 0) temp = 0
  49. else if (-temp >= maxNum) temp = -maxNum
  50. moveLoc.value = temp
  51. }
  52. }
  53. }
  54. onMounted(() => {
  55. const element = document.querySelector('#myElement')
  56. const resizeObserver = new ResizeObserver(entries => {
  57. for (let entry of entries) {
  58. console.log(`Width changed to ${entry.contentRect.width}`)
  59. // 在这里执行你的逻辑
  60. // 判断画轴有没有超过屏幕
  61. const pageHeightWindow = window.innerHeight
  62. pageHeight.value = pageHeightWindow
  63. moveLoc.value = 0
  64. setTimeout(() => {
  65. if (isRow.value === "竖") {
  66. const dom = document.querySelector(".imgBox")
  67. if (dom && dom.offsetHeight > pageHeightWindow) {
  68. isMove.value = true
  69. imgWidth.value = dom.offsetWidth
  70. imgHeight.value = dom.offsetHeight
  71. }
  72. } else {
  73. const leftBoxWidthDom = document.querySelector(".leftBxo")
  74. const leftBoxWidthDomWidth = leftBoxWidthDom.offsetWidth
  75. leftBoxWidth.value = leftBoxWidthDomWidth
  76. const dom = document.querySelector(".imgBoxHH")
  77. if ( dom && dom.offsetWidth > leftBoxWidthDomWidth) {
  78. isMove.value = true
  79. imgWidth.value = dom.offsetWidth
  80. imgHeight.value = dom.offsetHeight
  81. }
  82. }
  83. }, 200)
  84. tiemrr.value = setInterval(() => {
  85. if (zhouMove.value >= 99) clearInterval(tiemrr.value)
  86. zhouMove.value = zhouMove.value + 1
  87. }, 30)
  88. }
  89. })
  90. resizeObserver.observe(element)
  91. })
  92. </script>
  93. <template>
  94. <div
  95. id="myElement"
  96. class="box"
  97. >
  98. <div
  99. :class="`leftBxo ${isMove ? '' : isRow === '横' ? '' : 'leftBxoCenter'}`"
  100. >
  101. <!-- 左侧加号 -->
  102. <div
  103. class="addIcon"
  104. @click="lookBigImg"
  105. >
  106. <el-image
  107. :src="require('@/assets/images/painting-box-img/big-view.png')"
  108. :max-scale="7"
  109. :min-scale="0.2"
  110. :preview-src-list="[props.bigUrl ? props.bigUrl : props.url]"
  111. fit="cover"
  112. />
  113. <!-- <img
  114. src="@/assets/images/painting-box-img/big-view.png"
  115. alt=""
  116. > -->
  117. </div>
  118. <!-- ---------竖------- 大盒子 -->
  119. <div
  120. v-if="isRow === '竖'"
  121. :class="`imgBox ${isMove ? '' : 'imgBoxMove'}`"
  122. :style="`clip-path: rect(0 100% ${zhouMove}% 0);
  123. transform: translateY(${moveLoc}px)
  124. `"
  125. @mousedown="isFlag = true"
  126. @mouseup="isFlag = false"
  127. @mouseleave="isFlag = false"
  128. @mousemove="mousemoveFu"
  129. >
  130. <!-- 画轴的移动 -->
  131. <img
  132. class="zhou"
  133. src="@/assets/images/painting-box-img/zhou.png"
  134. alt=""
  135. :style="`bottom:${100 - zhouMove}%`"
  136. >
  137. <img
  138. :src="`${props.url}`"
  139. alt=""
  140. >
  141. </div>
  142. <!-- ------------横----------大盒子 -->
  143. <div
  144. v-else
  145. :class="`imgBoxHH ${isMove ? '' : 'imgBoxHHMove'}`"
  146. :style="`clip-path: rect(0 ${zhouMove}% 100% 0);
  147. transform: translateX(${moveLoc}px) translateY(-50%)
  148. `"
  149. @mousedown="isFlag = true"
  150. @mouseup="isFlag = false"
  151. @mouseleave="isFlag = false"
  152. @mousemove="mousemoveFu"
  153. >
  154. <!-- 画轴的移动 -->
  155. <img
  156. class="zhou"
  157. src="@/assets/images/painting-box-img/zhouH.png"
  158. alt=""
  159. :style="`right:${100 - zhouMove}%`"
  160. >
  161. <img
  162. :src="`${props.url}`"
  163. alt=""
  164. >
  165. </div>
  166. <!-- 右侧小盒子 -->
  167. <div
  168. v-if="isMove"
  169. class="smImgBox"
  170. >
  171. <div
  172. class="smImgBoxMain"
  173. :style="`width:${imgWidth / 5}px; height:${imgHeight / 5}px`"
  174. >
  175. <div
  176. v-if="isRow === '竖'"
  177. class="smBoxBor"
  178. :style="`height:${pageHeight / 5}px;transform: translateY(${
  179. -moveLoc / 5
  180. }px)`"
  181. @mousedown="isFlag = true"
  182. @mouseup="isFlag = false"
  183. @mouseleave="isFlag = false"
  184. @mousemove="(e) => mousemoveFu(e, true)"
  185. />
  186. <div
  187. v-else
  188. class="smBoxBorHH"
  189. :style="`width:${leftBoxWidth / 5}px;transform: translateX(${
  190. -moveLoc / 5
  191. }px)`"
  192. @mousedown="isFlag = true"
  193. @mouseup="isFlag = false"
  194. @mouseleave="isFlag = false"
  195. @mousemove="(e) => mousemoveFu(e, true)"
  196. />
  197. <img
  198. :src="
  199. props.url
  200. "
  201. alt=""
  202. >
  203. </div>
  204. </div>
  205. </div>
  206. </div>
  207. </template>
  208. <style lang='less' scoped>
  209. ::v-deep(.el-image-viewer__actions__inner .el-icon:last-child),
  210. ::v-deep(.el-image-viewer__actions__inner .el-icon:nth-last-child(2)){
  211. display: none;
  212. }
  213. ::v-deep(.el-image-viewer__btn .el-icon){
  214. margin: auto 10px;
  215. }
  216. ::deep(.el-image-viewer__actions){
  217. width: 200px;
  218. }
  219. ::deep(.el-image-viewer__actions__inner){
  220. justify-content: center;
  221. }
  222. .box {
  223. width: 100%;
  224. height: 100%;
  225. overflow: hidden;
  226. .leftBxo {
  227. // background-color: aquamarine;
  228. width: 100%;
  229. height: 100%;
  230. position: relative;
  231. text-align: center;
  232. position: relative;
  233. overflow: hidden;
  234. .addIcon {
  235. position: absolute;
  236. bottom: 50px;
  237. left: 50px;
  238. cursor: pointer;
  239. font-size: 30px;
  240. }
  241. // 竖大盒子
  242. .imgBox {
  243. cursor: grab;
  244. height: auto;
  245. overflow: hidden;
  246. width: 46%;
  247. // padding: 5% 3%;
  248. padding:15% 3% 5% 3%;
  249. white-space: nowrap;
  250. display: inline-block;
  251. background-image: url("@/assets/images/painting-box-img/ba.png");
  252. background-size: 95% 100%;
  253. background-repeat: no-repeat;
  254. background-position: center;
  255. position: relative;
  256. .zhou {
  257. position: absolute;
  258. bottom: 100%;
  259. left: 0;
  260. width: 100%;
  261. }
  262. & > img {
  263. pointer-events: none;
  264. width: 100%;
  265. display: inline-block;
  266. }
  267. }
  268. .imgBoxMove {
  269. cursor: default;
  270. display: flex;
  271. align-items: center;
  272. margin: 0 auto;
  273. }
  274. // 横大盒子
  275. .imgBoxHH {
  276. cursor: grab;
  277. width: auto;
  278. overflow: hidden;
  279. height: 55%;
  280. padding: 3% 5%;
  281. white-space: nowrap;
  282. display: inline-block;
  283. background-image: url("@/assets/images/painting-box-img/baH.png");
  284. background-size: 100% 100%;
  285. position: relative;
  286. top: 50%;
  287. .zhou {
  288. position: absolute;
  289. right: 100%;
  290. top: 0;
  291. height: 100%;
  292. }
  293. & > img {
  294. pointer-events: none;
  295. height: 100%;
  296. display: inline-block;
  297. }
  298. }
  299. .imgBoxHHMove {
  300. cursor: default;
  301. }
  302. .smImgBox {
  303. position: absolute;
  304. bottom: 5px;
  305. right: 5px;
  306. background-color: rgba(0, 0, 0, 0.5);
  307. padding: 10px 20px;
  308. .smImgBoxMain {
  309. overflow: hidden;
  310. position: relative;
  311. .smBoxBor {
  312. cursor: grab;
  313. position: absolute;
  314. top: 0;
  315. left: 0;
  316. width: 100%;
  317. border: 1px solid #fff;
  318. }
  319. .smBoxBorHH {
  320. cursor: grab;
  321. position: absolute;
  322. top: 0;
  323. left: 0;
  324. height: 100%;
  325. border: 1px solid #fff;
  326. }
  327. & > img {
  328. height: 100%;
  329. width: 100%;
  330. }
  331. }
  332. }
  333. }
  334. .leftBxoCenter {
  335. display: flex;
  336. align-items: center;
  337. }
  338. }
  339. </style>