feat: 文章详情完成
This commit is contained in:
1 parent
b730f7966b
commit
1dfddbf1da
11 files changed
+88
-17
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import carousalApi from '@/api/carousal'
|
import carousalApi from '@/api/carousal'
|
||||||
import CardList from '@/pages/pet-manual/components/CardList.vue'
|
import CardList from '../src/components/CardList.vue'
|
||||||
// const searchValue = ref('')
|
// const searchValue = ref('')
|
||||||
import bg from '@/static/image/feed-plan/bg.png'
|
import bg from '@/static/image/feed-plan/bg.png'
|
||||||
import circle from '@/static/image/feed-plan/circle.png'
|
import circle from '@/static/image/feed-plan/circle.png'
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import type { Article } from '@/model/pet-manual'
|
||||||
|
import httpClient from '@/api/httpClient'
|
||||||
|
|
||||||
|
export async function getArticle(id: string) {
|
||||||
|
return httpClient.get<Article>(`/articles/${id}`)
|
||||||
|
}
|
||||||
@@ -8,3 +8,7 @@ export async function createFeedingPlan(createFeedingPlanRequest: CreateFeedingP
|
|||||||
export async function getFeedingPlan(id: string) {
|
export async function getFeedingPlan(id: string) {
|
||||||
return httpClient.get<FeedingPlan>(`/feeding-plans/${id}`)
|
return httpClient.get<FeedingPlan>(`/feeding-plans/${id}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function updateFeedingPlan(id: string, createFeedingPlanRequest: CreateFeedingPlanRequest) {
|
||||||
|
return httpClient.put<FeedingPlan>(`/feeding-plans/${id}`, createFeedingPlanRequest)
|
||||||
|
}
|
||||||
Vendored
+1
@@ -10,6 +10,7 @@ declare module 'vue' {
|
|||||||
AddFeedingPlan: typeof import('./components/AddFeedingPlan.vue')['default']
|
AddFeedingPlan: typeof import('./components/AddFeedingPlan.vue')['default']
|
||||||
BButton: typeof import('./components/BButton.vue')['default']
|
BButton: typeof import('./components/BButton.vue')['default']
|
||||||
BSlider: typeof import('./components/BSlider.vue')['default']
|
BSlider: typeof import('./components/BSlider.vue')['default']
|
||||||
|
CardList: typeof import('./components/CardList.vue')['default']
|
||||||
Cell: typeof import('./components/Cell.vue')['default']
|
Cell: typeof import('./components/Cell.vue')['default']
|
||||||
CellGroup: typeof import('./components/CellGroup.vue')['default']
|
CellGroup: typeof import('./components/CellGroup.vue')['default']
|
||||||
FeedForm: typeof import('./components/FeedForm.vue')['default']
|
FeedForm: typeof import('./components/FeedForm.vue')['default']
|
||||||
|
|||||||
@@ -34,12 +34,19 @@ function handleLoadMore() {
|
|||||||
}
|
}
|
||||||
emit('loadMore')
|
emit('loadMore')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function goToArticle(id: string) {
|
||||||
|
uni.navigateTo({
|
||||||
|
url: `/pages/article/detail?id=${id}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<view class="flex flex-col gap-4 px-4">
|
<view class="flex flex-col gap-4 px-4">
|
||||||
<view
|
<view
|
||||||
v-for="(item, index) in props.cardList" :key="index" class="bg-[white] rounded-md shadow-lg flex w-full h-[120px] overflow-hidden"
|
v-for="(item, index) in props.cardList" :key="index" class="bg-[white] rounded-md shadow-lg flex w-full h-[120px] overflow-hidden"
|
||||||
|
@tap="() => goToArticle(item.id)"
|
||||||
>
|
>
|
||||||
<image class="w-[120px] h-[120px] rounded-l-md shrink-0" :src="item?.imageUrl || titleBg" />
|
<image class="w-[120px] h-[120px] rounded-l-md shrink-0" :src="item?.imageUrl || titleBg" />
|
||||||
<view class="p-4 flex flex-col">
|
<view class="p-4 flex flex-col">
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { Paging } from '@/model/base'
|
import type { BaseModel, Paging } from '@/model/base'
|
||||||
import type { CreatePetRequest } from '@/model/pet'
|
import type { CreatePetRequest } from '@/model/pet'
|
||||||
|
|
||||||
export interface CreateCarousalsRequest {
|
export interface CreateCarousalsRequest {
|
||||||
@@ -20,14 +20,13 @@ export interface ArticleParams extends Paging {
|
|||||||
categoryId: string
|
categoryId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Article {
|
export interface Article extends BaseModel {
|
||||||
id: string
|
|
||||||
content: string
|
content: string
|
||||||
status: string
|
status: string
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
updatedTime?: string
|
|
||||||
imageUrl?: string
|
imageUrl?: string
|
||||||
|
category: Category
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Recommends {
|
export interface Recommends {
|
||||||
|
|||||||
+5
-5
@@ -7,6 +7,11 @@
|
|||||||
},
|
},
|
||||||
"entryPagePath": "pages/home/index",
|
"entryPagePath": "pages/home/index",
|
||||||
"pages": [
|
"pages": [
|
||||||
|
{
|
||||||
|
"path": "pages/article/detail",
|
||||||
|
"type": "page",
|
||||||
|
"style": {}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/feed-plan/index",
|
"path": "pages/feed-plan/index",
|
||||||
"type": "page",
|
"type": "page",
|
||||||
@@ -86,11 +91,6 @@
|
|||||||
"path": "pages/userInfo/index",
|
"path": "pages/userInfo/index",
|
||||||
"type": "page",
|
"type": "page",
|
||||||
"style": {}
|
"style": {}
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "pages/pet-manual/components/CardList",
|
|
||||||
"type": "page",
|
|
||||||
"style": {}
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"globalStyle": {
|
"globalStyle": {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { Article } from '@/model/pet-manual'
|
||||||
|
import { getArticle } from '@/api/article'
|
||||||
|
|
||||||
|
const article = ref<Article | null>()
|
||||||
|
|
||||||
|
const id = ref('')
|
||||||
|
|
||||||
|
onLoad((options) => {
|
||||||
|
id.value = options!.id as string
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
fetchData()
|
||||||
|
})
|
||||||
|
|
||||||
|
async function fetchData() {
|
||||||
|
article.value = await getArticle(id.value)
|
||||||
|
await uni.setNavigationBarTitle({
|
||||||
|
title: article.value.category.name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const fixedContent = computed(() => {
|
||||||
|
if (!article.value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
return article.value.content.replace(/<img/g, '<img class="w-full"')
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<view v-if="article" class="w-full h-screen p-4 bg-[#F5F6F7]">
|
||||||
|
<view class="mb-2 text-xl font-semibold">
|
||||||
|
{{ article.title }}
|
||||||
|
</view>
|
||||||
|
<view class="flex text-xs text-[#999] mb-6">
|
||||||
|
<view>{{ article.createdTime }}</view>
|
||||||
|
</view>
|
||||||
|
<rich-text :nodes="fixedContent" />
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
|
||||||
|
</style>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
import type { Paging } from '@/model/base'
|
import type { Paging } from '@/model/base'
|
||||||
import type { Article, ArticleParams, Category, CreateCarousalsRequest, Recommends } from '@/model/pet-manual'
|
import type { Article, ArticleParams, Category, CreateCarousalsRequest, Recommends } from '@/model/pet-manual'
|
||||||
import carousalApi from '@/api/carousal'
|
import carousalApi from '@/api/carousal'
|
||||||
import CardList from '@/pages/pet-manual/components/CardList.vue'
|
import CardList from '@/components/CardList.vue'
|
||||||
import circle from '@/static/image/feed-plan/circle.png'
|
import circle from '@/static/image/feed-plan/circle.png'
|
||||||
import message from '@/static/image/feed-plan/message.png'
|
import message from '@/static/image/feed-plan/message.png'
|
||||||
import ToolApi from '@/utils'
|
import ToolApi from '@/utils'
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { FeedingPlanProduct } from '@/model/feeding-plan'
|
import type { FeedingPlanProduct } from '@/model/feeding-plan'
|
||||||
import type { Product } from '@/model/product'
|
import type { Product } from '@/model/product'
|
||||||
import { createFeedingPlan } from '@/api/feeding-plan'
|
import { createFeedingPlan, updateFeedingPlan } from '@/api/feeding-plan'
|
||||||
import { createPet } from '@/api/pet'
|
import { createPet } from '@/api/pet'
|
||||||
import {
|
import {
|
||||||
type CreateFeedingPlanRequest,
|
type CreateFeedingPlanRequest,
|
||||||
@@ -221,6 +221,8 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEdit = ref(false)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改指定 productId 的 percentage
|
* 修改指定 productId 的 percentage
|
||||||
* @param productId 产品的id
|
* @param productId 产品的id
|
||||||
@@ -246,6 +248,7 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
arrangeDailyConsumeWeight()
|
arrangeDailyConsumeWeight()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const savedFeedingPlan = ref<FeedingPlan | null>(null)
|
||||||
|
|
||||||
const confirm = async () => {
|
const confirm = async () => {
|
||||||
if (savedPet.value === null) {
|
if (savedPet.value === null) {
|
||||||
@@ -260,7 +263,13 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
percentage: item.percentage,
|
percentage: item.percentage,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await createFeedingPlan(feedingPlan.value)
|
|
||||||
|
if ((isEdit.value && savedFeedingPlan.value)) {
|
||||||
|
await updateFeedingPlan(savedFeedingPlan.value.id, feedingPlan.value)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
await createFeedingPlan(feedingPlan.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const initPet = (payload: Pet) => {
|
const initPet = (payload: Pet) => {
|
||||||
@@ -282,7 +291,6 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
|
|||||||
feedingPlan.value.targetWeight = calculateIdealWeight()
|
feedingPlan.value.targetWeight = calculateIdealWeight()
|
||||||
rer.value = calculateRER(pet.value.weight)
|
rer.value = calculateRER(pet.value.weight)
|
||||||
}
|
}
|
||||||
const savedFeedingPlan = ref<FeedingPlan | null>(null)
|
|
||||||
|
|
||||||
const initFeedingPlan = (payload: FeedingPlan) => {
|
const initFeedingPlan = (payload: FeedingPlan) => {
|
||||||
// @ts-expect-error @ts-ignore
|
// @ts-expect-error @ts-ignore
|
||||||
|
|||||||
Vendored
+3
-3
@@ -4,7 +4,8 @@
|
|||||||
// Generated by vite-plugin-uni-pages
|
// Generated by vite-plugin-uni-pages
|
||||||
|
|
||||||
interface NavigateToOptions {
|
interface NavigateToOptions {
|
||||||
url: "/pages/feed-plan/index" |
|
url: "/pages/article/detail" |
|
||||||
|
"/pages/feed-plan/index" |
|
||||||
"/pages/feed-plan-calculator/choose-product" |
|
"/pages/feed-plan-calculator/choose-product" |
|
||||||
"/pages/feed-plan-calculator/confirm" |
|
"/pages/feed-plan-calculator/confirm" |
|
||||||
"/pages/feed-plan-calculator/index" |
|
"/pages/feed-plan-calculator/index" |
|
||||||
@@ -14,8 +15,7 @@ interface NavigateToOptions {
|
|||||||
"/pages/pet-manual/index" |
|
"/pages/pet-manual/index" |
|
||||||
"/pages/setting/index" |
|
"/pages/setting/index" |
|
||||||
"/pages/start-filing/index" |
|
"/pages/start-filing/index" |
|
||||||
"/pages/userInfo/index" |
|
"/pages/userInfo/index";
|
||||||
"/pages/pet-manual/components/CardList";
|
|
||||||
}
|
}
|
||||||
interface RedirectToOptions extends NavigateToOptions {}
|
interface RedirectToOptions extends NavigateToOptions {}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user