PaintingDetailBox.vue 9.1 KB

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