feat: 喂养计划

This commit is contained in:
ilhamtahir committed 2025-01-21 09:09:42 +08:00
1 parent dfadf3a8f0
commit b2d41fd537
22 files changed
+506 -17

No files matched your search

+5 -3
View File
@@ -10,11 +10,11 @@ const props = withDefaults(defineProps<{
<template>
<button
class="px-[60px] py-[5px] bg-primary border-none outline-none text-white rounded-3xl flex items-center justify-center text-lg disabled:bg-[red] after:border-none"
class="px-[60px] py-[5px] bg-primary border-none outline-none text-white rounded-3xl flex items-center justify-center text-lg disabled:bg-[red] after:border-none "
:disabled="disabled"
:class="{
'!bg-disabled !text-white': disabled,
'bg-primary': !disabled && type === 'primary',
'bg-primary button-shadow': !disabled && type === 'primary',
}"
>
<slot />
@@ -22,5 +22,7 @@ const props = withDefaults(defineProps<{
</template>
<style scoped>
.button-shadow {
box-shadow: 0 4px 12px 0 rgba(69, 69, 229, 0.30);
}
</style>
+102
View File
@@ -0,0 +1,102 @@
<script setup lang="ts">
const props = withDefaults(defineProps<{
modelValue: number
splitNumber?: number
step?: number
readonly?: boolean
}>(), {
splitNumber: 9,
step: 10,
readonly: false,
})
const emit = defineEmits<{
'update:modelValue': [number]
'change': [number]
}>()
// 将内部状态通过 update:modelValue 通知父组件
function updateValue(val: number) {
// 限制取值在 [0, 100] 之间
val = Math.max(0, Math.min(val, 100))
// 通知父组件 (v-model)
emit && emit('update:modelValue', val)
emit && emit('change', val)
}
const trackLeft = ref(0) // 轨道的X起点
const trackWidth = ref(0) // 轨道的宽度
onMounted(() => {
const instance = getCurrentInstance()
if (!instance)
return
uni.createSelectorQuery().in(instance.proxy).select('.slider-wrapper').boundingClientRect((data) => {
if (Array.isArray(data))
return
trackLeft.value = data.left || 0
trackWidth.value = data.width || 0
}).exec()
})
function onTouchStart(e: Event) {
e.preventDefault()
}
function onTouchMove(e: any) {
if (props.readonly)
return
// 1. 获取当前触点X坐标
const pageX = e.touches[0].pageX
// 2. 计算相对于轨道左侧的距离
const delta = pageX - trackLeft.value
// 3. 转化为 0~1 的进度,再*100变成百分比
let percent = (delta / trackWidth.value) * 100
// 4. 对 percent 进行 step 吸附(step默认为10,即0%、10%、20%等)
if (props.step > 0) {
const stepCount = Math.round(percent / props.step) // 离哪个step更近
percent = stepCount * props.step
}
// 5. 更新 currentValue 并emit通知父组件
updateValue(percent)
}
function onTouchEnd(e: Event) {
e.preventDefault()
}
</script>
<template>
<view
class="h-[8px] slider-wrapper rounded-full bg-[#E7E7E7] relative flex items-center" @touchstart="onTouchStart"
@touchmove="onTouchMove"
@touchend="onTouchEnd"
>
<view class="w-full h-full flex justify-around items-center absolute left-0 top-0 z-0">
<view v-for="i of splitNumber" :key="i" class="w-1 h-1.5 bg-disabled" />
</view>
<view
class="h-full absolute left-0 top-0 z-1 bg-primary rounded-full" :style="{
width: `${modelValue}%`,
}"
/>
<view
v-if="!readonly"
class="w-[14px] h-[14px] rounded-full slider-thumb bg-[white] absolute left-0 z-2" :style="{
left: `calc(${modelValue}% - 7px)`,
}"
/>
</view>
</template>
<style scoped>
.slider-thumb {
box-shadow: 0 0 6px 0 rgba(69, 69, 229, 0.53);
}
</style>
+40
View File
@@ -0,0 +1,40 @@
<script setup lang="ts">
import type { FeedingPlanProduct } from '@/model/feeding-plan'
defineProps<{
data: FeedingPlanProduct
}>()
</script>
<template>
<view class="pl-2.5 py-4 pr-5 rounded-xl bg-white shadow-cell-group flex items-center">
<image :src="data.product.photo" class="w-[120px] h-[120px]" />
<view class="flex-1 flex flex-col justify-between h-[80px] py-2">
<view class="font-semibold">
{{ data.product.name }}
</view>
<view class="flex gap-2">
<view v-for="tag in data.product.tags" :key="tag" class="px-2 py-0.5 bg-[#f3f3f3] rounded-0.75 text-xs">
{{ tag }}
</view>
</view>
</view>
<view class="text-right">
<view class="text-xs font-semibold">
每日
</view>
<view class="text-xl font-bold mb-4">
{{ data.dailyUsageWeight }}<text class="text-xs font-medium">
g
</text>
</view>
<view class="text-[9px] text-[#CDCDCD]">
{{ data.product.totalCalories }}Kcal
</view>
</view>
</view>
</template>
<style scoped>
</style>
+40
View File
@@ -0,0 +1,40 @@
<script setup lang="ts">
import type { FeedingPlanProduct } from '@/model/feeding-plan'
defineProps<{
data: FeedingPlanProduct
}>()
</script>
<template>
<view class="py-4 pl-2 pr-8 w-full flex gap-3 relative items-center border-b-[1px] border-[#E7E7E7] last-of-type:border-0">
<image :src="data.product.photo" class="w-[80px] h-[80px]" />
<view class="flex-1 flex flex-col justify-between h-[80px] py-2">
<view class="font-semibold">
{{ data.product.name }}
</view>
<view class="flex gap-2">
<view v-for="tag in data.product.tags" :key="tag" class="px-2 py-0.5 bg-[#f3f3f3] rounded-0.75 text-xs">
{{ tag }}
</view>
</view>
</view>
<view class="text-right">
<view class="text-xs font-semibold">
每日
</view>
<view class="text-xl font-bold mb-4">
{{ data.dailyUsageWeight }}<text class="text-xs font-medium">
g
</text>
</view>
<view class="text-[9px] text-[#CDCDCD]">
{{ data.product.totalCalories }}Kcal
</view>
</view>
</view>
</template>
<style scoped>
</style>
+38
View File
@@ -0,0 +1,38 @@
<script setup lang="ts">
const props = defineProps<{
title: string
subtitle?: string
onOperationClick?: () => void
operationTitle?: string
}>()
function handleTap() {
if (props.onOperationClick) {
props.onOperationClick()
}
}
</script>
<template>
<view class="w-full relative rounded-3 overflow-hidden shadow-cell-group bg-[#fff]">
<view v-if="operationTitle" class="w-[111px] h-[44px] bg-[#1a1a1a] absolute right-0 top-0" @tap="handleTap">
<view class="text-[#999] text-xs absolute right-4 leading-[34px]">
{{ operationTitle }}
</view>
</view>
<image class="w-[343px] h-[179px] absolute right-0 top-0 " src="@/static/image/shape-bg.png" />
<view class="pl-4 relative flex gap-1 h-[44px] items-center text-xs">
<view>{{ title }}</view>
<view v-if="subtitle" class="text-[#D9D9D9]">
{{ subtitle }}
</view>
</view>
<view class="relative">
<slot />
</view>
</view>
</template>
<style scoped>
</style>