You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
4.4 KiB

8 months ago
8 months ago
  1. <template>
  2. <view class="content">
  3. <mNavbar title="相册" :leftClick="leftClick" />
  4. <view class="item-card">
  5. <view class="flex">
  6. <view class="head-line"/>
  7. <view class="tt">我的相册{{list.length}}/{{maxSize}}</view>
  8. </view>
  9. <view class="list">
  10. <view v-for="(item, i) in list"
  11. class="item" @click="index = i;show = true">
  12. <image :src="item" mode="aspectFill" class="ii-image"></image>
  13. </view>
  14. <view class="ii" v-if="list.length < maxSize"
  15. @click="selectImage"></view>
  16. </view>
  17. </view>
  18. <view class="b-fiexd">
  19. <view class="button-submit" @click="submit">保存</view>
  20. </view>
  21. <van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" />
  22. </view>
  23. </template>
  24. <script>
  25. import mNavbar from '@/components/base/m-navbar.vue'
  26. export default {
  27. components: {
  28. mNavbar,
  29. },
  30. data() {
  31. return {
  32. list : [],
  33. maxSize : 10,
  34. show : false,
  35. actions : [
  36. { name: '查看图片', index : 0 },
  37. { name: '删除图片', index : 1 },
  38. ],
  39. index : 0,
  40. userInfo : {},
  41. }
  42. },
  43. onShow() {
  44. this.getUserInfo()
  45. },
  46. methods: {
  47. selectImage(){
  48. uni.chooseImage({
  49. count: this.maxSize - this.list.length, // 默认9,设置为1表示单选
  50. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  51. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  52. success: (res) => {
  53. let resultPromise = [];
  54. res.tempFiles.forEach(file => {
  55. resultPromise.push(this.uploadFileToOSS(file));
  56. })
  57. Promise.all(resultPromise).then(imgPathArr => {
  58. this.list.push(...imgPathArr)
  59. })
  60. }
  61. });
  62. },
  63. submit(){
  64. this.$api('uploadTenImg', {
  65. file : this.list.join(',')
  66. }, res => {
  67. if(res.code == 200){
  68. uni.showToast({
  69. title : '保存成功',
  70. icon : 'none'
  71. })
  72. setTimeout(() => {
  73. uni.switchTab({
  74. url: '/pages/index/center'
  75. })
  76. }, 1000)
  77. }
  78. })
  79. },
  80. getUserInfo() {
  81. this.$api('giveTenInfo', {}, res => {
  82. if (res.code == 200) {
  83. this.userInfo = res.result.msgTen;
  84. this.list = this.userInfo.images ? this.userInfo.images.split(',') : []
  85. }
  86. }, '加载中...')
  87. },
  88. onSelect(e){
  89. console.log(e);
  90. this.show = false
  91. if(e.index == 0){
  92. uni.previewImage({
  93. current: this.index,
  94. urls: this.list,
  95. });
  96. }else if(e.index == 1){
  97. this.deleteImage(this.index)
  98. }
  99. },
  100. deleteImage(index){
  101. uni.showModal({
  102. title: '确认删除这张照片吗',
  103. confirmText : '确认',
  104. cancelText : '取消',
  105. success: function (res) {
  106. if (res.confirm) {
  107. this.list.splice(index, 1)
  108. } else if (res.cancel) {}
  109. }
  110. });
  111. },
  112. clickBanner(){ uni.navigateTo({ url: '/pages/login/login' }) },
  113. clickInfo(id){ uni.navigateTo({ url: `/pages/index/infod?id=${id}`}) },
  114. leftClick(){ uni.switchTab({
  115. url: '/pages/index/center'
  116. }) },
  117. }
  118. }
  119. </script>
  120. <style scoped lang="scss">
  121. .ii-image{
  122. width: 172rpx;
  123. height: 172rpx;
  124. }
  125. .list{
  126. display: flex;
  127. flex-wrap: wrap;
  128. .item{
  129. margin: 40rpx 20rpx 0 20rpx;
  130. }
  131. }
  132. body{
  133. background-color: #f3f3f3;
  134. }
  135. .head-line{
  136. width: 8rpx;
  137. height: 34rpx;
  138. background: #60bda2;
  139. border-radius: 4rpx;
  140. margin: 8rpx 0;
  141. }
  142. .item-card{
  143. padding: 40rpx 48rpx;
  144. background-color: #fff;
  145. margin-bottom: 20rpx;
  146. min-height: 252rpx;
  147. width: 100vw;
  148. }
  149. .button-submit{
  150. width: 596rpx;
  151. height: 90rpx;
  152. line-height: 90rpx;
  153. background: linear-gradient(180deg,#6fdfbe, #5ac796);
  154. border-radius: 46rpx;
  155. margin: 20rpx auto;
  156. font-size: 28rpx;
  157. font-family: PingFang SC, PingFang SC-Regular;
  158. font-weight: 400;
  159. text-align: center;
  160. color: #ffffff;
  161. }
  162. .tt{
  163. line-height: 48rpx;
  164. font-size: 28rpx;
  165. font-family: PingFang SC, PingFang SC-Bold;
  166. font-weight: 700;
  167. text-align: left;
  168. color: #333333;
  169. padding-left: 14rpx;
  170. }
  171. .ii{
  172. width: 172rpx;
  173. height: 172rpx;
  174. background-color: #f4f4f4;
  175. border-radius: 16rpx;
  176. margin-top: 40rpx;
  177. position: relative;
  178. }
  179. .ii::after{
  180. content: " ";
  181. width: 8rpx;
  182. height: 50rpx;
  183. background-color: #dfdfdf;
  184. position: absolute;
  185. top: calc(172rpx / 2 - 25rpx);
  186. left: calc(172rpx / 2 - 4rpx);
  187. }
  188. .ii::before{
  189. content: " ";
  190. width: 50rpx;
  191. height: 8rpx;
  192. background-color: #dfdfdf;
  193. position: absolute;
  194. top: calc(172rpx / 2 - 4rpx);
  195. left: calc(172rpx / 2 - 25rpx);
  196. }
  197. </style>