MyPhoto.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class='myphoto'>
  3. <div class="top">
  4. <img src="@/assets/img/MyPhoto/back.png" alt="" @click="goBack()">
  5. <img src="@/assets/img/MyPhoto/mypic.png" alt="">
  6. </div>
  7. <div class="tips">
  8. 最多存20张,长按图片保存<br />
  9. </div>
  10. <div v-if="myPhoto.length == 0" class="noImg">
  11. 暂无相片
  12. </div>
  13. <div v-else class="imgList">
  14. <div class="imgItem" v-for="(item, index) in myPhoto" :key="index">
  15. <img :src="item.msg" alt="">
  16. <img @click="deletePic(index)" class="close" src="@/assets/img/MyPhoto/close-icon.png" alt="">
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. components: {},
  24. data() {
  25. return {
  26. myPhoto: []
  27. };
  28. },
  29. computed: {},
  30. watch: {},
  31. methods: {
  32. goBack() {
  33. this.$emit('sonBack')
  34. },
  35. deletePic(data) {
  36. this.$dialog
  37. .confirm({
  38. title: '四维艺术',
  39. message: '删除后无法恢复,是否删除?',
  40. })
  41. .then(() => {
  42. // on confirm
  43. console.log(data.msg)
  44. console.log(this.myPhoto)
  45. // this.myPhoto = this.myPhoto.filter((item) => {
  46. // return item.msg === data.msg
  47. // })
  48. this.myPhoto.splice(data, 1)
  49. localStorage.setItem('myPhoto', JSON.stringify(this.myPhoto))
  50. })
  51. .catch(() => {
  52. // on cancel
  53. });
  54. }
  55. },
  56. created() {
  57. },
  58. mounted() {
  59. //从store中获取我的相片列表
  60. this.myPhoto = localStorage.getItem('myPhoto') ? JSON.parse(localStorage.getItem('myPhoto')) : []
  61. },
  62. beforeCreate() { }, //生命周期 - 创建之前
  63. beforeMount() { }, //生命周期 - 挂载之前
  64. beforeUpdate() { }, //生命周期 - 更新之前
  65. updated() { }, //生命周期 - 更新之后
  66. beforeDestroy() { }, //生命周期 - 销毁之前
  67. destroyed() { }, //生命周期 - 销毁完成
  68. activated() { }, //如果页面有keep-alive缓存功能,这个函数会触发
  69. }
  70. </script>
  71. <style lang='less' scoped>
  72. .myphoto {
  73. width: 100%;
  74. height: 100%;
  75. .top {
  76. width: 100%;
  77. display: flex;
  78. justify-content: space-between;
  79. padding: 10px;
  80. img {
  81. height: 2.2rem;
  82. }
  83. }
  84. .tips {
  85. color: #00b3ec;
  86. font-size: 10px;
  87. text-align: right;
  88. padding-right: 10px;
  89. margin-top: -10px;
  90. }
  91. .noImg {
  92. width: 100%;
  93. height: 30vh;
  94. display: flex;
  95. justify-content: center;
  96. align-items: center;
  97. color: #999;
  98. }
  99. .imgList {
  100. width: 100%;
  101. // max-height: 80vh;
  102. overflow: auto;
  103. padding: 10px;
  104. box-sizing: border-box;
  105. display: grid;
  106. grid-template-columns: repeat(2, minmax(0, 1fr));
  107. gap: 10px;
  108. overflow: auto;
  109. .imgItem {
  110. display: flex;
  111. flex-direction: column;
  112. justify-content: center;
  113. align-items: center;
  114. .close {
  115. width: 35px;
  116. height: 35px;
  117. // margin-top: 3px;
  118. }
  119. }
  120. img {
  121. width: 100%;
  122. // height: 20vh;
  123. object-fit: cover;
  124. }
  125. }
  126. ::-webkit-scrollbar {
  127. display: none;
  128. /* 隐藏滚动条 */
  129. }
  130. }
  131. </style>