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

261 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. formItemStyle: { padding: 0 },
  61. }
  62. },
  63. methods: {
  64. onUpload() {
  65. uni.chooseImage({
  66. count: 1,
  67. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  68. success: res => {
  69. let image = res.tempFilePaths[0] // 将选择的图片赋值给我们定义的cover
  70. this.$Oss.ossUpload(image)
  71. .then(url => {
  72. this.form.image = url
  73. })
  74. }
  75. });
  76. },
  77. async onPublish() {
  78. try {
  79. await this.$refs.form.validate()
  80. const {
  81. } = this.form
  82. const params = {
  83. }
  84. // todo: fetch
  85. // await this.$fetch('updateAddress', params)
  86. uni.showToast({
  87. icon: 'success',
  88. title: '发布成功',
  89. });
  90. this.$emit('submitted')
  91. this.close()
  92. } catch (err) {
  93. console.log('onSave err', err)
  94. }
  95. },
  96. },
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .popup__view {
  101. width: 100vw;
  102. display: flex;
  103. flex-direction: column;
  104. box-sizing: border-box;
  105. background: #FFFFFF;
  106. border-top-left-radius: 32rpx;
  107. border-top-right-radius: 32rpx;
  108. }
  109. .header {
  110. position: relative;
  111. width: 100%;
  112. padding: 24rpx 0;
  113. box-sizing: border-box;
  114. border-bottom: 2rpx solid #EEEEEE;
  115. .title {
  116. font-family: PingFang SC;
  117. font-weight: 500;
  118. font-size: 34rpx;
  119. line-height: 1.4;
  120. color: #181818;
  121. }
  122. .btn {
  123. font-family: PingFang SC;
  124. font-weight: 500;
  125. font-size: 32rpx;
  126. line-height: 1.4;
  127. color: #8B8B8B;
  128. position: absolute;
  129. top: 26rpx;
  130. left: 40rpx;
  131. }
  132. }
  133. .form {
  134. max-height: 75vh;
  135. padding: 32rpx 40rpx;
  136. box-sizing: border-box;
  137. overflow-y: auto;
  138. &-item {
  139. padding: 8rpx 0 6rpx 0;
  140. & + & {
  141. padding-top: 24rpx;
  142. border-top: 2rpx solid #EEEEEE;
  143. }
  144. &-label {
  145. margin-bottom: 14rpx;
  146. display: flex;
  147. align-items: center;
  148. font-family: PingFang SC;
  149. font-weight: 400;
  150. font-size: 26rpx;
  151. line-height: 1.4;
  152. color: #181818;
  153. .icon {
  154. margin-right: 8rpx;
  155. width: 16rpx;
  156. height: auto;
  157. }
  158. }
  159. &-content {
  160. .text {
  161. padding: 2rpx 0;
  162. font-family: PingFang SC;
  163. font-weight: 400;
  164. font-size: 32rpx;
  165. line-height: 1.4;
  166. &.placeholder {
  167. color: #C6C6C6;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. .footer {
  174. width: 100%;
  175. padding: 32rpx 40rpx;
  176. box-sizing: border-box;
  177. border-top: 2rpx solid #F1F1F1;
  178. .btn {
  179. width: 100%;
  180. padding: 14rpx 0;
  181. box-sizing: border-box;
  182. font-family: PingFang SC;
  183. font-weight: 500;
  184. font-size: 36rpx;
  185. line-height: 1.4;
  186. color: #FFFFFF;
  187. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  188. border: 2rpx solid #00A9FF;
  189. border-radius: 41rpx;
  190. }
  191. }
  192. .btn-avatar {
  193. display: inline-block;
  194. width: auto;
  195. border: none;
  196. }
  197. .avatar {
  198. position: relative;
  199. width: 200rpx;
  200. height: 200rpx;
  201. border-radius: 24rpx;
  202. overflow: hidden;
  203. .img {
  204. width: 100%;
  205. height: 100%;
  206. }
  207. .mask {
  208. position: absolute;
  209. top: 0;
  210. left: 0;
  211. width: 100%;
  212. height: 100%;
  213. background: #00000080;
  214. border-radius: 24rpx;
  215. .icon {
  216. width: 64rpx;
  217. height: 64rpx;
  218. }
  219. }
  220. &.is-empty {
  221. background: #F3F2F7;
  222. .icon {
  223. width: 61rpx;
  224. height: auto;
  225. }
  226. }
  227. }
  228. </style>