123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <script setup>
- import { ref, reactive } from "vue";
- import { useRoute, useRouter } from "vue-router";
- import { useMainStore } from "@/stores/store";
- import axios from "axios";
- import moment from "moment";
- import bookList from "@/utils/useBookList";
- import Navbar from "@/components/Navbar.vue";
- const route = useRoute();
- const router = useRouter();
- const store = useMainStore();
- // 網址參數
- const articleId = route.params.id;
- const articleCategory = route.params.category;
- console.log("articleId", articleId);
- console.log("articleCategory", articleCategory);
- let list = reactive({
- data: {},
- });
- if (articleCategory === "book") {
- list.data = bookList[articleId];
- } else if (articleCategory === "article") {
- getArticle();
- }
- let filePath = ref("");
- let file = reactive({
- list: [],
- });
- async function getArticle() {
- try {
- const response = await axios.get(
- `https://cmm.ai:8088/api/get_article?article_id=${articleId}`
- );
- console.log("response", response.data.articles[0]);
- list.data = response.data.articles[0];
- const fileData = response.data.articles[0].files;
- // 字符串轉物件
- const fileObject = JSON.parse(fileData.replace(/'/g, '"'));
- // 遍歷物件後將值存進陣列
- file.list = Object.keys(fileObject).map((key) => ({
- name: fileObject[key].split("/").pop(),
- url: fileObject[key],
- }));
- console.log("fileList", file.list);
- console.log("data", list.data);
- } catch (error) {
- console.error(error);
- }
- }
- </script>
- <template>
- <Navbar />
- <div class="position-relative mb-16">
- <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
- <v-container class="pa-0 pt-16 position-relative">
- <div class="content">
- <div class="article">
- <v-row>
- <v-col cols="12">
- <div class="d-flex align-center mb-5">
- <v-chip size="large" variant="elevated" class="px-8 me-3">
- {{
- articleCategory === "book"
- ? list.data.category
- : list.data.group_sort
- }}
- </v-chip>
- <!-- <p>
- {{ moment(`${list.data.create_time}`).format("YYYY.MM.DD") }}
- </p> -->
- </div>
- <h2 class="text-center">{{ list.data.title }}</h2>
- <v-img
- class="cover-img my-10"
- :lazy-src="
- articleCategory === 'book'
- ? list.data.img
- : `https://ntcri.org/${list.data.cover_img}`
- "
- :src="
- articleCategory === 'book'
- ? list.data.img
- : `https://ntcri.org/${list.data.cover_img}`
- "
- >
- <template v-slot:placeholder>
- <div class="d-flex align-center justify-center fill-height">
- <v-progress-circular
- color="grey-lighten-4"
- indeterminate
- ></v-progress-circular>
- </div>
- </template>
- </v-img>
- </v-col>
- <v-col cols="12">
- <section class="d-flex flex-column pa-0">
- <p v-html="list.data.content"></p>
- </section>
- </v-col>
- <v-col cols="12" class="mt-10" v-if="file.list.length">
- <p>附件下載:</p>
- <ul class="mt-7">
- <li
- v-for="(item, index) in file.list"
- :key="index"
- class="d-flex align-center mb-2"
- >
- <v-icon
- icon="mdi-file-download"
- color="brown"
- size="large"
- class="me-2"
- ></v-icon>
- <a :href="`https://ntcri.org/${item.url}`" download>{{
- item.name
- }}</a>
- </li>
- </ul>
- <!-- <a :href="`https://ntcri.org/${filePath}`" download class="download-link">附件下載</a> -->
- </v-col>
- </v-row>
- </div>
- </div>
- </v-container>
- <router-link
- v-if="articleCategory === 'book'"
- to="/crafts"
- class="mt-16 back-link"
- >< 返回知識文章</router-link
- >
- <a href="javascript:;" v-else @click="router.go(-1)" class="back-link"
- >< 回到上一頁</a
- >
- <img src="@/assets/img/news/news-01.png" alt="" class="material-img" />
- </div>
- </template>
- <style lang="scss" scoped>
- ul {
- a {
- line-height: 24px;
- letter-spacing: 1px;
- transition: all 0.3s;
- &:hover {
- opacity: 0.8;
- }
- }
- }
- .btn-block {
- display: flex;
- justify-content: end;
- }
- .content {
- padding: 20px;
- background-image: url("@/assets/img/news/news-02.png");
- background-position: center;
- background-size: cover;
- border-radius: 50px;
- @media (max-width: 960px) {
- width: 90%;
- margin: auto;
- }
- }
- .article {
- margin: auto;
- padding: 80px 50px;
- display: flex;
- justify-content: center;
- border: 1px solid #d4d6d8;
- border-radius: 50px;
- // @media (max-width: 960px) {
- // width: 80%;
- // }
- @media (max-width: 600px) {
- padding: 50px 0;
- border: none;
- }
- h2 {
- margin: 40px auto;
- font-size: 28px;
- font-weight: 500;
- line-height: 38px;
- letter-spacing: 2px;
- }
- section {
- height: 100%;
- padding: 30px;
- p {
- font-size: 18px;
- font-weight: 400;
- line-height: 32px;
- letter-spacing: 1px;
- white-space: pre-line;
- }
- }
- .cover-img {
- width: 100%;
- max-height: 500px;
- @media (max-width: 600px) {
- height: auto;
- }
- }
- }
- .bg-img {
- height: 1000px;
- position: relative;
- z-index: -1;
- @media (max-width: 600px) {
- height: 650px;
- }
- }
- .back-link {
- margin-top: 50px;
- display: block;
- text-align: center;
- transition: all 0.3s;
- letter-spacing: 1px;
- &:hover {
- opacity: 0.8;
- }
- }
- .material-img {
- position: absolute;
- &:first-child {
- top: -15vw;
- }
- &:last-child {
- bottom: -130px;
- z-index: -5;
- transform: scaleX(-1);
- @media (max-width: 600px) {
- bottom: -50px;
- }
- }
- }
- </style>
|