createInteract.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="create-interact">
  3. <nav-bar :title="title" @click-left="$router.go(-1)">
  4. <div slot="right" class="nav-bar-right">提交</div>
  5. </nav-bar>
  6. <div class="title">
  7. <input placeholder="输入标题内容,30字以内" maxlength="30" v-model="form.title" />
  8. </div>
  9. <div class="content">
  10. <textarea placeholder="详细描述您的问题" v-model="form.content"></textarea>
  11. </div>
  12. <div class="upload">
  13. <van-uploader v-model="fileList" accept="image/*" multiple :after-read="afterRead" max-count="6" />
  14. </div>
  15. <div class="switch-wrapper" v-if="type === 'official'">
  16. <div class="label">是否公开</div>
  17. <van-switch v-model="pub" active-color="#BF1616" />
  18. </div>
  19. </div>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. type: '',
  26. form: { title: '', content: '' },
  27. fileList: [],
  28. pub: false
  29. };
  30. },
  31. created() {
  32. this.type = this.$route.query.type;
  33. },
  34. computed: {
  35. title() {
  36. switch (this.type) {
  37. case 'official':
  38. return '我要咨询';
  39. case 'forum':
  40. return '发布话题';
  41. case 'qa':
  42. return '发布问题';
  43. default:
  44. return '';
  45. }
  46. }
  47. },
  48. methods: {
  49. afterRead(file) {
  50. console.log(file);
  51. file.status = 'uploading';
  52. file.message = '上传中...';
  53. let form = new FormData();
  54. form.append('file', file.file);
  55. this.$http
  56. .post('/upload/file', form)
  57. .then(res => {
  58. console.log(res);
  59. file.status = 'success';
  60. file.url = res;
  61. })
  62. .catch(e => {
  63. console.log(e);
  64. file.status = 'failed';
  65. file.message = '上传失败';
  66. });
  67. }
  68. }
  69. };
  70. </script>
  71. <style lang="less" scoped>
  72. .create-interact {
  73. height: 100%;
  74. .flex-col();
  75. }
  76. .nav-bar-right {
  77. color: @prim;
  78. font-size: 16px;
  79. word-break: keep-all;
  80. user-select: none;
  81. &:active {
  82. color: fade(@prim, 60%);
  83. }
  84. }
  85. .title {
  86. position: relative;
  87. padding: 16px 16px 18px 16px;
  88. &::after {
  89. .setBottomLine();
  90. left: 16px;
  91. right: 16px;
  92. }
  93. input {
  94. width: 100%;
  95. padding: 0;
  96. margin: 0;
  97. font-size: 20px;
  98. line-height: 30px;
  99. &::-webkit-input-placeholder {
  100. color: @text4;
  101. }
  102. }
  103. }
  104. .content {
  105. flex-grow: 1;
  106. padding: 16px;
  107. position: relative;
  108. textarea {
  109. width: 100%;
  110. height: 100%;
  111. border: none;
  112. font-size: 16px;
  113. line-height: 26px;
  114. resize: none;
  115. &::-webkit-input-placeholder {
  116. color: @text4;
  117. }
  118. }
  119. &::after {
  120. .setBottomLine();
  121. left: 16px;
  122. right: 16px;
  123. }
  124. }
  125. .upload {
  126. padding: 16px;
  127. }
  128. /deep/ .van-uploader__preview-image {
  129. width: 70px;
  130. height: 70px;
  131. }
  132. /deep/ .van-uploader__upload {
  133. width: 70px;
  134. height: 70px;
  135. &::after {
  136. content: '添加图片';
  137. font-size: 12px;
  138. color: @text4;
  139. margin-top: 4px;
  140. }
  141. }
  142. .switch-wrapper {
  143. padding: 0 16px 14px 16px;
  144. .flex();
  145. .label {
  146. flex-grow: 1;
  147. color: @text1;
  148. font-size: 13px;
  149. }
  150. }
  151. /deep/ .van-switch--on {
  152. .van-switch__node {
  153. .flex();
  154. justify-content: center;
  155. &::after {
  156. content: '是';
  157. font-size: 12px;
  158. color: @prim;
  159. }
  160. }
  161. }
  162. </style>