鸿宇研学生前端代码
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.

260 lines
5.4 KiB

  1. <template>
  2. <view>
  3. <uv-popup ref="popup" mode="bottom" bgColor="none" >
  4. <view class="popup__view">
  5. <view class="flex header">
  6. <view class="title">新增回顾</view>
  7. <button class="btn" @click="close">关闭</button>
  8. </view>
  9. <view class="form">
  10. <uv-form
  11. ref="form"
  12. :model="form"
  13. :rules="rules"
  14. errorType="toast"
  15. >
  16. <view class="form-item">
  17. <uv-form-item prop="image" :customStyle="formItemStyle">
  18. <view class="form-item-label">
  19. <image class="icon" src="@/static/image/icon-require.png" mode="widthFix"></image>
  20. 上传图片
  21. </view>
  22. <view class="form-item-content">
  23. <button class="flex btn">
  24. <view v-if="form.image" class="avatar">
  25. <image class="img" :src="form.image" mode="aspectFill"></image>
  26. <view class="flex mask">
  27. <image class="icon" src="@/static/image/icon-change.png" mode="widthFix" />
  28. </view>
  29. </view>
  30. <view v-else class="flex avatar is-empty">
  31. <image class="icon" src="@/static/image/icon-plus.png" mode="widthFix" />
  32. </view>
  33. </button>
  34. </view>
  35. </uv-form-item>
  36. </view>
  37. </uv-form>
  38. </view>
  39. <view class="footer">
  40. <button class="flex btn" @click="onPublish">发布</button>
  41. </view>
  42. </view>
  43. </uv-popup>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. form: {
  51. image: null,
  52. },
  53. rules: {
  54. 'image': {
  55. type: 'string',
  56. required: true,
  57. message: '请上传图片',
  58. },
  59. },
  60. }
  61. },
  62. methods: {
  63. onUpload() {
  64. uni.chooseImage({
  65. count: 1,
  66. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  67. success: res => {
  68. let image = res.tempFilePaths[0] // 将选择的图片赋值给我们定义的cover
  69. this.$Oss.ossUpload(image)
  70. .then(url => {
  71. this.form.image = url
  72. })
  73. }
  74. });
  75. },
  76. async onPublish() {
  77. try {
  78. await this.$refs.form.validate()
  79. const {
  80. } = this.form
  81. const params = {
  82. }
  83. // todo: fetch
  84. // await this.$fetch('updateAddress', params)
  85. uni.showToast({
  86. icon: 'success',
  87. title: '发布成功',
  88. });
  89. this.$emit('submitted')
  90. this.close()
  91. } catch (err) {
  92. console.log('onSave err', err)
  93. }
  94. },
  95. },
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. .popup__view {
  100. width: 100vw;
  101. display: flex;
  102. flex-direction: column;
  103. box-sizing: border-box;
  104. background: #FFFFFF;
  105. border-top-left-radius: 32rpx;
  106. border-top-right-radius: 32rpx;
  107. }
  108. .header {
  109. position: relative;
  110. width: 100%;
  111. padding: 24rpx 0;
  112. box-sizing: border-box;
  113. border-bottom: 2rpx solid #EEEEEE;
  114. .title {
  115. font-family: PingFang SC;
  116. font-weight: 500;
  117. font-size: 34rpx;
  118. line-height: 1.4;
  119. color: #181818;
  120. }
  121. .btn {
  122. font-family: PingFang SC;
  123. font-weight: 500;
  124. font-size: 32rpx;
  125. line-height: 1.4;
  126. color: #8B8B8B;
  127. position: absolute;
  128. top: 26rpx;
  129. left: 40rpx;
  130. }
  131. }
  132. .form {
  133. max-height: 75vh;
  134. padding: 32rpx 40rpx;
  135. box-sizing: border-box;
  136. overflow-y: auto;
  137. &-item {
  138. padding: 8rpx 0 6rpx 0;
  139. & + & {
  140. padding-top: 24rpx;
  141. border-top: 2rpx solid #EEEEEE;
  142. }
  143. &-label {
  144. margin-bottom: 14rpx;
  145. display: flex;
  146. align-items: center;
  147. font-family: PingFang SC;
  148. font-weight: 400;
  149. font-size: 26rpx;
  150. line-height: 1.4;
  151. color: #181818;
  152. .icon {
  153. margin-right: 8rpx;
  154. width: 16rpx;
  155. height: auto;
  156. }
  157. }
  158. &-content {
  159. .text {
  160. padding: 2rpx 0;
  161. font-family: PingFang SC;
  162. font-weight: 400;
  163. font-size: 32rpx;
  164. line-height: 1.4;
  165. &.placeholder {
  166. color: #C6C6C6;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. .footer {
  173. width: 100%;
  174. padding: 32rpx 40rpx;
  175. box-sizing: border-box;
  176. border-top: 2rpx solid #F1F1F1;
  177. .btn {
  178. width: 100%;
  179. padding: 14rpx 0;
  180. box-sizing: border-box;
  181. font-family: PingFang SC;
  182. font-weight: 500;
  183. font-size: 36rpx;
  184. line-height: 1.4;
  185. color: #FFFFFF;
  186. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  187. border: 2rpx solid #00A9FF;
  188. border-radius: 41rpx;
  189. }
  190. }
  191. .btn-avatar {
  192. display: inline-block;
  193. width: auto;
  194. border: none;
  195. }
  196. .avatar {
  197. position: relative;
  198. width: 200rpx;
  199. height: 200rpx;
  200. border-radius: 24rpx;
  201. overflow: hidden;
  202. .img {
  203. width: 100%;
  204. height: 100%;
  205. }
  206. .mask {
  207. position: absolute;
  208. top: 0;
  209. left: 0;
  210. width: 100%;
  211. height: 100%;
  212. background: #00000080;
  213. border-radius: 24rpx;
  214. .icon {
  215. width: 64rpx;
  216. height: 64rpx;
  217. }
  218. }
  219. &.is-empty {
  220. background: #F3F2F7;
  221. .icon {
  222. width: 61rpx;
  223. height: auto;
  224. }
  225. }
  226. }
  227. </style>