Upload.vue 4.63 KB
<template>
  <v-sheet>
    <v-layout justify-center>
      <v-overlay :value="loading">
        <v-progress-circular indeterminate size="80"></v-progress-circular>
      </v-overlay>
      <v-flex xs12 sm8 md6>
        <v-row justify="center" class="mx-0 my-12">
          <v-icon color="lightblue">mdi-power-on</v-icon>
          <div
            style="text-align: center; font-size: 22px; font-weight: 400; color: #343a40; "
          >Upload Video</div>
          <v-icon color="lightblue">mdi-power-on</v-icon>
        </v-row>
        <v-card elevation="0">
          <v-text-field
            class="mx-10 mt-12 mb-6"
            prepend-inner-icon="mdi-pen"
            v-model="form.title"
            :counter="40"
            label="Title"
            placeholder="Please input Title"
            type="text"
          ></v-text-field>
          <!-- file upload -->
          <div class="mx-10 mb-12 mt-6">
            <video-upload />
          </div>
          <v-dialog max-width="400" v-model="successDialog">
            <v-card max-width="400" class="pt-3">
              <div
                style="text-align: center; font-size: 20px;color: #5a5a5a; font-weight: 400"
              >Notice</div>
              <v-divider class="mt-2 mb-3"></v-divider>
              <div
                style="margin-left: 10px; margin-right: 10px; text-align: center; font-size: 18px; font-weight: 400"
              >Your Video's tags are successfully extracted</div>
              <v-btn class="mt-4" elevation="0" block color="primary">Close</v-btn>
            </v-card>
          </v-dialog>
          <v-card outlined class="pa-2 mx-10" elevation="0" min-height="67">
            <div
              style="margin-left: 5px; margin-top: -18px; background-color: #fff; width: 95px; text-align: center;font-size: 14px; color: #5a5a5a; font-weight: 500"
            >Selected Tags</div>
            <v-chip-group column>
              <v-chip
                color="secondary"
                v-for="(tag, index) in form.tag"
                :key="index"
                @click="deleteTags(index)"
              >
                {{ tag }}
                <v-icon small style="margin-left: 3px; margin-top: -2px">mdi-close-circle</v-icon>
              </v-chip>
            </v-chip-group>
          </v-card>
          <v-text-field
            class="mx-10 my-12"
            prepend-inner-icon="mdi-shape"
            v-model="tag"
            :counter="20"
            label="Tag"
            placeholder="Type to add Tag"
            append-icon="mdi-arrow-up-bold"
            @click:append="addTags(tag)"
            @keydown.enter="addTags(tag)"
            type="text"
          ></v-text-field>
        </v-card>
        <v-row justify="center" style="margin-top: 30px">
          <v-btn elevation="0" large color="primary" @click="submit()">
            <span style="font-size: 24px; font-weight: 300; letter-spacing: 2px">Upload</span>
          </v-btn>
        </v-row>
      </v-flex>
    </v-layout>
  </v-sheet>
</template>
<script>
import videoUpload from "../components/uploadFile";
export default {
  name: "Upload",
  components: {
    videoUpload
  },
  data() {
    return {
      myFiles: [],
      tag: "",
      form: {
        title: "",
        videoUrl: "",
        tag: [
          "Work",
          "Home Improvement",
          "Vacation",
          "Food",
          "Drawers",
          "Shopping",
          "Art",
          "Tech",
          "Creative Writing"
        ]
      },
      successDialog: false,
      errorDialog: false,
      loading: false
    };
  },
  created() {
    this.form.tag = [];
  },

  methods: {
    submit() {
      if (!(this.form.tag.length && this.form.title)) {
        this.errorDialog = true;
        return;
      } else {
        this.$axios
          .post("/home", this.form)
          .then(r => {
            window.location.reload();
            console.log(r);
            this.successDialog = true;
          })
          .catch(e => {
            console.log(e);
            this.errorDialog = true;
          });
      }
    },
    deleteTags(index) {
      for (let i = 0; i < this.form.tag.length; i++) {
        const element = this.form.tag[i];
        if (this.form.tag[index] === element) {
          this.form.tag[i] = this.form.tag[this.form.tag.length - 1];
          break;
        }
      }
      this.form.tag.pop();
    },
    addTags(tag) {
      let i;
      let check = true;
      for (i = 0; i < this.form.tag.length; i++) {
        const element = this.form.tag[i];
        if (tag === element) {
          check = false;
        }
      }
      if (tag && check) this.form.tag.push(tag);
      this.tag = "";
    }
  }
};
</script>