publish.vue 1.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<template>
  <div class="publish">
    <van-cell-group class="content">
      <van-field
        v-model="message"
        autosize
        type="textarea"
        maxlength="200"
        placeholder="这一刻的想法..."
        show-word-limit
      />
      <van-uploader
        class="add"
        multiple
        v-model="fileList"
        :after-read="afterRead"
      >
        <img
          class="add-img"
          src="@/assets/images/editAdd.png"
          alt="添加图片和视频"
        />
      </van-uploader>
    </van-cell-group>
    <div class="btn">
26 27 28
      <van-button type="primary" size="large" @click="onPublish"
        >发布</van-button
      >
29 30 31 32 33
    </div>
  </div>
</template>

<script>
34 35
import { uploadImage } from "@/api/infomation";

36 37 38 39 40 41 42 43 44 45
export default {
  name: "publish",
  data() {
    return {
      message: "",
      fileShow: false,
      fileList: []
    };
  },
  methods: {
46 47 48 49 50
    onPublish() {
      console.log("发布===文字", this.message);
      console.log("发布===文件", this.fileList);
      const fd = new FormData();
      this.fileList.forEach(file => {
leiqingsong's avatar
leiqingsong committed
51
        fd.append("files", file.file);
52
      });
leiqingsong's avatar
leiqingsong committed
53
      fd.append("zxField", this.message);
leiqingsong's avatar
leiqingsong committed
54
      fd.append("userId", JSON.parse(localStorage.getItem("user")).userId);
leiqingsong's avatar
leiqingsong committed
55
      uploadImage(fd).then();
56
    },
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    openPopup() {
      this.fileShow = true;
    },
    afterRead(file) {
      console.log(file);
    }
  }
};
</script>

<style lang="scss" scoped>
.content {
  position: relative;
  height: 350px;
  margin-top: 10px;
  background-color: #fff;

  .van-field {
    height: 230px;
  }

  ::v-deep .van-field__word-limit {
    position: absolute;
    right: 0;
    bottom: 0;
  }

  .add {
    position: absolute;
    left: 10px;
    bottom: 20px;
    .add-img {
      width: 88px;
      height: 88px;
    }
  }
}
.btn {
  padding: 10px 16px;
}
</style>