addCollection.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <div class="message-add" :style="{height:height,width:width}" >
  3. <!-- <el-page-header @back="goBack" content="创建消息"></el-page-header> -->
  4. <div class="message-add-box">
  5. <el-form :model="message" :rules="rules" ref="form" label-width="100px">
  6. <el-form-item label="藏品名称:" prop="collectionName">
  7. <el-input v-model="message.collectionName" style="width: 550px" placeholder="请输入藏品名称"></el-input>
  8. </el-form-item>
  9. <el-form-item label="藏品头图:" prop="imageUrl">
  10. <el-upload
  11. class="avatar-uploader"
  12. action="https://jsonplaceholder.typicode.com/posts/"
  13. :show-file-list="false"
  14. :on-success="handleAvatarSuccess"
  15. :before-upload="beforeAvatarUpload"
  16. >
  17. <img v-if="imageUrl" :src="imageUrl" class="avatar" />
  18. <i
  19. v-else
  20. class="el-icon-plus avatar-uploader-icon"
  21. ></i> </el-upload>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" @click="addCollection('form')">提交</el-button>
  25. <el-button @click="resetForm('form')">重置</el-button>
  26. <el-button @click="importForm('form')">导入</el-button>
  27. </el-form-item>
  28. </el-form>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import {addCollection} from '../../api/collection/collection.js'
  34. export default {
  35. data() {
  36. return {
  37. message: {
  38. collectionName:'',
  39. imageUrl: ''
  40. },
  41. rules:{
  42. collectionName: [
  43. { required: true, message: '请输入藏品名称', trigger: 'blur' }
  44. ],
  45. }
  46. }
  47. },
  48. mounted() {
  49. console.log( "-****" , this.message.collectionName);
  50. console.log( "-****" , this.message.imageUrl);
  51. },
  52. methods: {
  53. handleAvatarSuccess(res, file) {
  54. this.imageUrl = URL.createObjectURL(file.raw);
  55. },
  56. beforeAvatarUpload(file) {
  57. const isJPG = file.type === 'image/jpeg';
  58. const isLt2M = file.size / 1024 / 1024 < 2;
  59. if (!isJPG) {
  60. this.$message.error('上传头像图片只能是 JPG 格式!');
  61. }
  62. if (!isLt2M) {
  63. this.$message.error('上传头像图片大小不能超过 2MB!');
  64. }
  65. return isJPG && isLt2M;
  66. },
  67. addCollection() {
  68. console.log( "-****" , this.message.collectionName);
  69. console.log( "-****" , this.message.imageUrl);
  70. addCollection(this.collectionName) .then((res)=>{
  71. console.log(res);
  72. })
  73. },
  74. resetForm(formName) {
  75. this.$refs[formName].resetFields();
  76. },
  77. // importForm(formName) {
  78. // }
  79. }
  80. }
  81. </script>
  82. <style>
  83. .avatar-uploader .el-upload {
  84. border: 1px dashed #d9d9d9;
  85. border-radius: 6px;
  86. cursor: pointer;
  87. position: relative;
  88. overflow: hidden;
  89. }
  90. .avatar-uploader .el-upload:hover {
  91. border-color: #409EFF;
  92. }
  93. .avatar-uploader-icon {
  94. font-size: 28px;
  95. color: #8c939d;
  96. width: 178px;
  97. height: 178px;
  98. line-height: 178px;
  99. text-align: center;
  100. }
  101. .avatar {
  102. width: 178px;
  103. height: 178px;
  104. display: block;
  105. }
  106. .message-add-box{
  107. width: 60%;
  108. height: 100%;
  109. margin: 50px auto;
  110. border: 1px solid #ccc;
  111. padding-top: 40px;
  112. padding-left: 100px;
  113. padding-right: 30px;
  114. }
  115. /* .users-input-box{
  116. color:aqua;
  117. } */
  118. .quill-editor /deep/ .ql-container {
  119. min-height: 220px;
  120. }
  121. .ql-container {
  122. min-height: 230px;
  123. }
  124. .ql-toolbar.ql-snow {
  125. border: 1px solid #ccc;
  126. -webkit-box-sizing: border-box;
  127. box-sizing: border-box;
  128. font-family: 'Helvetica Neue', 'Helvetica', 'Arial', sans-serif;
  129. padding: 8px;
  130. width: 450px;
  131. }
  132. .ql-toolbar.ql-snow + .ql-container.ql-snow {
  133. border-top: 0px;
  134. width: 450px;
  135. }
  136. </style>