Article.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script setup lang="ts">
  2. import { ref, reactive } from "vue";
  3. import { useMainStore } from "@/stores/main";
  4. import { required } from "@/utils";
  5. import { useI18n } from "vue-i18n";
  6. import type { ArticleCreate } from "@/interfaces";
  7. // import Dialog from "@/components/Dialog.vue";
  8. const mainStore = useMainStore();
  9. const { t } = useI18n();
  10. const valid = ref(true);
  11. const Form = ref();
  12. let title = ref("");
  13. let link = ref("");
  14. let content = ref("");
  15. // props
  16. // let dialog = reactive({
  17. // msg: "上傳成功!",
  18. // state: "success",
  19. // show: false,
  20. // });
  21. async function Submit() {
  22. // setTimeout(() => {
  23. // dialog.show = true;
  24. // }, 2000);
  25. await (Form as any).value.validate();
  26. if (valid.value) {
  27. valid.value = false;
  28. const article_data: ArticleCreate = {
  29. title: title.value,
  30. link: link.value,
  31. content: content.value,
  32. };
  33. await mainStore.uploadArticle(article_data);
  34. // (Form as any).value.reset();
  35. }
  36. }
  37. </script>
  38. <template>
  39. <v-container fluid>
  40. <v-card class="ma-3 pa-3">
  41. <v-card-title primary-title>
  42. <h3 class="card-title mb-3">{{ t("makeArticle") }}</h3>
  43. </v-card-title>
  44. <v-card-text>
  45. <v-form v-model="valid" ref="Form">
  46. <v-text-field
  47. :label="$t('articleTitle')"
  48. v-model="title"
  49. :rules="required"
  50. prepend-icon="title"
  51. >
  52. </v-text-field>
  53. <v-text-field
  54. v-model="link"
  55. :label="$t('articleLink')"
  56. prepend-icon="link"
  57. >
  58. </v-text-field>
  59. <v-textarea
  60. v-model="content"
  61. :label="$t('articleContent')"
  62. prepend-icon="edit_document"
  63. ></v-textarea>
  64. </v-form>
  65. </v-card-text>
  66. <v-card-actions>
  67. <v-spacer></v-spacer>
  68. <v-btn @click="Submit" :disabled="!valid">
  69. {{ t("send") }}
  70. </v-btn>
  71. </v-card-actions>
  72. </v-card>
  73. <!-- <template>
  74. <div class="text-center">
  75. <Dialog
  76. :msg="dialog.msg"
  77. :state="dialog.state"
  78. :dialog="dialog.show"
  79. @close="dialog.show = false"
  80. ></Dialog>
  81. </div>
  82. </template> -->
  83. </v-container>
  84. </template>
  85. <style lang="scss"></style>