feat: 增加后端API接口
This commit is contained in:
@@ -13,52 +13,51 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<wd-card title="1号菜地">
|
||||
<image src="https://wot-ui.cn/assets/panda.jpg" mode="aspectFill" />
|
||||
<wd-card v-for="(item, index) in patchStore.patchList" :key="item.id">
|
||||
<template #title>
|
||||
<view class="wd-card__title-text flex items-center justify-between">
|
||||
<text>{{ item.name }}</text>
|
||||
<text v-if="item.location" class="text-sm text-[#999]">{{ item.location }}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<wd-img width="100%" height="40vh" :src="`${patchStore.baseUrl}/${item.crop?.images[0]}`"
|
||||
lazy-load mode="aspectFill" @click="handlePreview(item.crop)">
|
||||
<template #error>
|
||||
<view class="error-wrap">暂无记录</view>
|
||||
</template>
|
||||
</wd-img>
|
||||
|
||||
<template #footer>
|
||||
<view class="flex-1 flex justify-between items-center">
|
||||
<view class="flex flex-col gap-1">
|
||||
<view v-if="item.crop" class="flex flex-col gap-1">
|
||||
<view class="text-base font-medium">
|
||||
西红柿
|
||||
<text class="text-sm text-gray-400 font-normal ml-1">粉果番茄</text>
|
||||
{{ item.crop.name }}
|
||||
<text class="text-sm text-gray-400 font-normal ml-1">{{ item.crop.variety }}</text>
|
||||
</view>
|
||||
<view class="flex gap-1 align-center">
|
||||
<wd-text text="🌱 生长期"/>
|
||||
<wd-text text="📅 2025-04-10"/>
|
||||
<wd-text v-if="item.crop.stage" :text="item.crop.stage"/>
|
||||
<wd-text :text="`📅 ${item.crop.date}`"/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<wd-text v-else text="暂无作物 请先添加"/>
|
||||
|
||||
<view class="flex gap-1">
|
||||
<wd-button icon="edit" round></wd-button>
|
||||
<wd-button icon="list" round></wd-button>
|
||||
<wd-button icon="edit" round @click="editPatchClick(item)"></wd-button>
|
||||
<wd-button icon="list" round @click="viewDetailClick(item)"></wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</wd-card>
|
||||
|
||||
<wd-card title="2号菜地">
|
||||
<image src="https://wot-ui.cn/assets/redpanda.jpg" mode="aspectFill" />
|
||||
<wd-empty v-if="patchStore.patchList.length === 0" tip="暂无数据"/>
|
||||
|
||||
<template #footer>
|
||||
<view class="flex-1 flex justify-between items-center">
|
||||
<view class="flex flex-col gap-1">
|
||||
<view class="text-base font-medium">
|
||||
黄瓜
|
||||
<text class="text-sm text-gray-400 font-normal ml-1">旱黄瓜</text>
|
||||
</view>
|
||||
<view class="flex gap-1 align-center">
|
||||
<wd-text text="🌱 开花期"/>
|
||||
<wd-text text="📅 2025-04-10"/>
|
||||
</view>
|
||||
</view>
|
||||
<view class="flex gap-1">
|
||||
<wd-button icon="edit" round></wd-button>
|
||||
<wd-button icon="list" round></wd-button>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
</wd-card>
|
||||
<liu-drag-button v-if="patchStore.showPatchFab" background="#22c55e" @clickBtn="addPatchClick">
|
||||
<wd-icon name="plus" size="24px"></wd-icon>
|
||||
</liu-drag-button>
|
||||
|
||||
<patch-popup />
|
||||
<view class="h-[10px]"></view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -67,9 +66,13 @@
|
||||
import { computed } from 'vue'
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import appLogo from '@/static/logo.png'
|
||||
import { usePatchStore } from "@/stores/patch";
|
||||
import type {ICrop, IPatch} from "@/types";
|
||||
import PatchPopup from "@/components/PatchPopup.vue";
|
||||
|
||||
defineOptions({ name: 'Home' })
|
||||
|
||||
const patchStore = usePatchStore()
|
||||
const imgURL = appLogo
|
||||
|
||||
// ===== 时间 =====
|
||||
@@ -90,10 +93,48 @@ const today = computed(() => {
|
||||
return `${m}月${d}日 周${w}`
|
||||
})
|
||||
|
||||
onShow(async () => {
|
||||
await loadData()
|
||||
})
|
||||
|
||||
onShow(() => loadData())
|
||||
async function loadData() {
|
||||
await patchStore.queryPatchList()
|
||||
}
|
||||
|
||||
function loadData() {
|
||||
function addPatchClick() {
|
||||
patchStore.patchForm = {
|
||||
id: 0,
|
||||
name: '',
|
||||
location: '',
|
||||
status: ''
|
||||
}
|
||||
patchStore.patchApiType = 'ADD'
|
||||
patchStore.showPatchPopup = true
|
||||
patchStore.showPatchFab = false
|
||||
}
|
||||
|
||||
function editPatchClick(patch: IPatch) {
|
||||
patchStore.patchForm = JSON.parse(JSON.stringify(patch))
|
||||
patchStore.patchApiType = 'UPDATE'
|
||||
patchStore.showPatchPopup = true
|
||||
patchStore.showPatchFab = false
|
||||
}
|
||||
|
||||
async function viewDetailClick(patch: IPatch) {
|
||||
patchStore.currentPatch = patch
|
||||
|
||||
if (patch.crop) {
|
||||
await patchStore.queryRecordList(patch.crop.id)
|
||||
} else {
|
||||
patchStore.recordList = []
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/record/index'
|
||||
})
|
||||
}
|
||||
|
||||
function handlePreview(crop: ICrop) {
|
||||
const fullUrls = crop.images?.map(url => `${patchStore.baseUrl}/${url}`) as string[]
|
||||
uni.previewImage({ urls: fullUrls, current: fullUrls[0] })
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user