编写饲养计划前端基本界面、功能

This commit is contained in:
bicey 2024-05-20 15:25:19 +08:00
parent 4ec4b70918
commit fd7c0fabf0
6 changed files with 223 additions and 184 deletions

View File

@ -110,7 +110,7 @@ breedingPlan: {
name: '',//字符 饲养计划名称
species: '',//字符 种类
sex: '雄性',//字符 饲养动物性别
phase: '',//字符 饲养动物阶段:幼年期、成长期、成年期、老年期
phase: '',//字符 饲养动物生长阶段:幼年期、成长期、成年期、老年期
state: 0,//int 状态0正常 1异常
describe: ''//字符 饲养计划的描述
}
@ -193,7 +193,7 @@ breedingPlan: {
### 饲养员
- [ ] 数据展示
- [x] 数据展示
- [ ] 基本功能
- [ ] 基本方法
- [ ] 接入后端

View File

@ -52,7 +52,7 @@ export default {
showEditDialog(animal) {
//使animalid
this.dialog.editData = this.animals.find(e => e.id === animal.id)
console.log('点击了编辑', this.dialog.editData)
console.log('点击了动物编辑', this.dialog.editData)
this.dialog.editDialogVisible = true
},
//
@ -86,7 +86,7 @@ export default {
//
this.dialog.editDialogVisible = false//
},
deleteUser(animal) {
deleteAnimal(animal) {
console.log('删除动物', animal)
return ElMessageBox.confirm(
'该操作不可撤销,是否继续?',
@ -180,7 +180,7 @@ export default {
<div class="right">
<el-input
v-model="searchInput.keyword"
style="max-width: 300px"
style="width: 400px"
placeholder="搜索动物 空格隔开关键字"
>
<template #prepend>
@ -200,9 +200,9 @@ export default {
<!-- <hr/>-->
<div class="table">
<el-table :data="tableData" style="width: 100%;height: 100%" empty-text="暂无数据" border>
<el-table-column fixed prop="id" label="动物ID"/>
<el-table-column fixed prop="id" label="动物ID" width="70"/>
<el-table-column fixed prop="name" label="动物名称" width="100"/>
<el-table-column prop="sex" label="性别"/>
<el-table-column prop="sex" label="性别" width="60"/>
<el-table-column prop="species" label="动物种类" width="90"/>
<el-table-column prop="weight" label="动物体重KG" width="130"/>
<el-table-column prop="height" label="动物身高M" width="130"/>
@ -220,14 +220,14 @@ export default {
<el-color-picker v-model="scope.row.color" disabled/>
</template>
</el-table-column>
<el-table-column prop="features" label="动物特征" width="100"/>
<el-table-column prop="habit" label="生活习性" width="100"/>
<el-table-column prop="features" label="动物特征" width="200"/>
<el-table-column prop="habit" label="生活习性" width="200"/>
<el-table-column fixed="right" label="操作" width="130">
<template #default="scope">
<el-button link type="primary" size="small" :icon="Edit" @click="showEditDialog(scope.row)">
编辑
</el-button>
<el-button link type="danger" size="small" :icon="Delete" @click="deleteUser(scope.row)">
<el-button link type="danger" size="small" :icon="Delete" @click="deleteAnimal(scope.row)">
删除
</el-button>
</template>

View File

@ -2,7 +2,7 @@
import ZooBreedingPlanFormDialog from "@/components/ZooBreedingPlanFormDialog.vue";
import {mapState,mapActions} from "vuex";
import {Delete, DocumentAdd, Edit, Search} from "@element-plus/icons-vue";
import {copy} from "@/utils/common.js";
import {copy, splitKeyWords,fuzzyMatching} from "@/utils/common.js";
export default {
name: "ZooBreeding",
@ -11,8 +11,8 @@ export default {
return {
tableData: [],
searchInput: {
// state: '',//0 1
// keyword: ''
state: '',//0 1
keyword: ''
},
dialog: {
addDialogVisible: false,//
@ -40,76 +40,77 @@ export default {
...mapState(["breedingPlans"])
},
watch: {
// searchInput: {
// deep: true,
// handler(val) {
// this.searchAnimal();
// }
// }
searchInput: {
deep: true,
handler(val) {
this.searchBreedingPlan();
}
}
},
methods: {
...mapActions(["getBreedingPlans"]),
// showEditDialog(animal) {
// //使animalid
// this.dialog.editData = this.animals.find(e => e.id === animal.id)
// console.log('', this.dialog.editData)
// this.dialog.editDialogVisible = true
// },
// //
// isEmpty(form) {
// if (!form.name) {
// //
// return ElMessage({
// message: '',
// type: 'warning',
// })
// }
// },
// editAnimal(form) {
// console.log('', form)
// //
// return this.isEmpty(form);
// //
// if (false) {
// return ElMessage({
// message: '',
// type: 'warning',
// })
// }
// //
// if (false) {
// return ElMessage({
// message: '',
// type: 'success',
// })
// }
// //
// this.dialog.editDialogVisible = false//
// },
// deleteUser(animal) {
// console.log('', animal)
// return ElMessageBox.confirm(
// '',
// '' + animal.name,
// {
// confirmButtonText: '',
// cancelButtonText: '',
// type: 'warning',
// }
// ).then(() => {
// //
// //
// ElMessage({
// type: 'success',
// message: '',
// })
// }).catch(() => {
// ElMessage({
// type: 'info',
// message: '',
// })
// })
// },
showEditDialog(breedingPlan) {
//使animalid
this.dialog.editData = this.breedingPlans.find(e => e.id === breedingPlan.id)
console.log('点击了编辑', this.dialog.editData)
this.dialog.editDialogVisible = true
},
//
isEmpty(form) {
if (!form.name) {
//
return ElMessage({
message: '计划名不能为空',
type: 'warning',
})
}
},
editBreedingPlan(form) {
console.log('确认编辑饲养计划', form)
//
return this.isEmpty(form);
//
if (false) {
return ElMessage({
message: '编辑失败',
type: 'warning',
})
}
//
if (false) {
return ElMessage({
message: '编辑成功',
type: 'success',
})
}
//
this.getBreedingPlans()
this.dialog.editDialogVisible = false//
},
deleteBreedingPlan(breedingPlan) {
console.log('删除动物', breedingPlan)
return ElMessageBox.confirm(
'该操作不可撤销,是否继续?',
'删除饲养计划:' + breedingPlan.name,
{
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}
).then(() => {
//
//
ElMessage({
type: 'success',
message: '删除成功',
})
}).catch(() => {
ElMessage({
type: 'info',
message: '取消删除',
})
})
},
addBreedingPlan(form) {
console.log('添加饲养计划', form)
//
@ -131,37 +132,37 @@ export default {
//
this.dialog.addDialogVisible = false//
},
// searchAnimal() {
// console.log('', this.searchInput)
// let searchResult = []//
// //
// if (typeof this.searchInput.state === 'number') {
// this.animals.forEach(e => {
// if (e.state === this.searchInput.state) {
// searchResult.push(copy(e))//
// }
// })
// } else { //
// searchResult = copy(this.animals)
// }
//
// let searchResult2 = []
// let keyset = splitKeyWords(this.searchInput.keyword)//
//
// //
// searchResult.forEach(e => {
// //
// // console.log(',',e,keyset)
// let is = fuzzyMatching(e, keyset);
// if (is) {
// searchResult2.push(e)
// }
// // console.log('',e,keyset,is)
// })
// searchResult = searchResult2
//
// this.tableData = searchResult
// },
searchBreedingPlan() {
console.log('饲养计划搜索', this.searchInput)
let searchResult = []//
//
if (typeof this.searchInput.state === 'number') {
this.breedingPlans.forEach(e => {
if (e.state === this.searchInput.state) {
searchResult.push(copy(e))//
}
})
} else { //
searchResult = copy(this.breedingPlans)
}
let searchResult2 = []
let keyset = splitKeyWords(this.searchInput.keyword)//
//
searchResult.forEach(e => {
//
// console.log(',',e,keyset)
let is = fuzzyMatching(e, keyset);
if (is) {
searchResult2.push(e)
}
// console.log('',e,keyset,is)
})
searchResult = searchResult2
this.tableData = searchResult
},
},
mounted() {
this.getBreedingPlans()
@ -176,63 +177,61 @@ export default {
<div class="left">
<el-button type="primary" :icon="DocumentAdd" @click="dialog.addDialogVisible = true">添加饲养计划</el-button>
</div>
<!-- <div class="right">-->
<!-- <el-input-->
<!-- v-model="searchInput.keyword"-->
<!-- style="max-width: 300px"-->
<!-- placeholder="搜索动物 空格隔开关键字"-->
<!-- >-->
<!-- <template #prepend>-->
<!-- <el-select v-model="searchInput.state" placeholder="状态" style="width: 80px">-->
<!-- <el-option label="不选择" value=""/>-->
<!-- <el-option label="正常" :value="0"/>-->
<!-- <el-option label="异常" :value="1"/>-->
<!-- </el-select>-->
<!-- </template>-->
<!-- <template #append>-->
<!-- <el-button :icon="Search" @click="searchAnimal()"/>-->
<!-- </template>-->
<!-- </el-input>-->
<!-- </div>-->
<div class="right">
<el-input
v-model="searchInput.keyword"
style="max-width: 400px"
placeholder="搜索饲养计划 空格隔开关键字"
>
<template #prepend>
<el-select v-model="searchInput.state" placeholder="状态" style="width: 80px">
<el-option label="不选择" value=""/>
<el-option label="正常" :value="0"/>
<el-option label="异常" :value="1"/>
</el-select>
</template>
<template #append>
<el-button :icon="Search" @click="searchBreedingPlan()"/>
</template>
</el-input>
</div>
</div>
<!-- <hr/>-->
<!-- <div class="table">-->
<!-- <el-table :data="tableData" style="width: 100%;height: 100%" empty-text="暂无数据" border>-->
<!-- <el-table-column fixed prop="id" label="动物ID"/>-->
<!-- <el-table-column fixed prop="name" label="动物名称" width="100"/>-->
<!-- <el-table-column prop="sex" label="性别"/>-->
<!-- <el-table-column prop="species" label="动物种类" width="90"/>-->
<!-- <el-table-column prop="weight" label="动物体重KG" width="130"/>-->
<!-- <el-table-column prop="height" label="动物身高M" width="130"/>-->
<!-- <el-table-column prop="state" label="动物状态" width="90">-->
<!-- <template #default="scope">-->
<!-- <span v-if="scope.row.state===0" style="color: green">正常</span>-->
<!-- <span v-else-if="scope.row.state===1" style="color: red">异常</span>-->
<!-- <span v-else>未知</span>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column prop="roleId" label="饲养员ID" width="120"/>-->
<!-- <el-table-column prop="color" label="动物颜色" width="150">-->
<!-- <template #default="scope">-->
<!-- {{ scope.row.color }}-->
<!-- <el-color-picker v-model="scope.row.color" disabled/>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- <el-table-column prop="features" label="动物特征" width="100"/>-->
<!-- <el-table-column prop="habit" label="生活习性" width="100"/>-->
<!-- <el-table-column fixed="right" label="操作" width="130">-->
<!-- <template #default="scope">-->
<!-- <el-button link type="primary" size="small" :icon="Edit" @click="showEditDialog(scope.row)">-->
<!-- 编辑-->
<!-- </el-button>-->
<!-- <el-button link type="danger" size="small" :icon="Delete" @click="deleteUser(scope.row)">-->
<!-- 删除-->
<!-- </el-button>-->
<!-- </template>-->
<!-- </el-table-column>-->
<!-- </el-table>-->
<!-- </div>-->
<!-- id: '',//int id-->
<!-- name: '',// -->
<!-- species: '',// -->
<!-- sex: '雄性',// -->
<!-- phase: '',// -->
<!-- state: 0,//int 0 1-->
<!-- describe: ''// -->
<div class="table">
<el-table :data="tableData" style="width: 100%;height: 100%" empty-text="暂无数据" border>
<el-table-column fixed prop="id" label="饲养计划ID" width="100"/>
<el-table-column fixed prop="name" label="饲养计划名称" width="200"/>
<el-table-column prop="species" label="动物种类" width="90"/>
<el-table-column prop="sex" label="性别" width="60"/>
<el-table-column prop="phase" label="生长阶段" width="90"/>
<el-table-column prop="state" label="动物状态" width="90">
<template #default="scope">
<span v-if="scope.row.state===0" style="color: green">正常</span>
<span v-else-if="scope.row.state===1" style="color: red">异常</span>
<span v-else>未知</span>
</template>
</el-table-column>
<el-table-column prop="describe" label="计划描述" width="300"/>
<el-table-column fixed="right" label="操作" width="130">
<template #default="scope">
<el-button link type="primary" size="small" :icon="Edit" @click="showEditDialog(scope.row)">
编辑
</el-button>
<el-button link type="danger" size="small" :icon="Delete" @click="deleteBreedingPlan(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
<!-- 添加动物对话框-->
@ -249,20 +248,20 @@ export default {
</ZooBreedingPlanFormDialog>
</el-dialog>
<!-- &lt;!&ndash; 编辑动物对话框&ndash;&gt;-->
<!-- <el-dialog v-model="dialog.editDialogVisible" title="编辑动物" width="500" align-center draggable overflow-->
<!-- destroy-on-close>-->
<!-- <ZooAnimalFormDialog :animal="dialog.editData">-->
<!-- <template #default="scope">-->
<!-- <el-button @click="dialog.editDialogVisible = false">-->
<!-- 取消-->
<!-- </el-button>-->
<!-- <el-button type="primary" @click="editAnimal(scope.form)">-->
<!-- 修改-->
<!-- </el-button>-->
<!-- </template>-->
<!-- </ZooAnimalFormDialog>-->
<!-- </el-dialog>-->
<!-- 编辑动物对话框-->
<el-dialog v-model="dialog.editDialogVisible" title="编辑饲养计划" width="500" align-center draggable overflow
destroy-on-close>
<ZooBreedingPlanFormDialog :breedingPlan="dialog.editData">
<template #default="scope">
<el-button @click="dialog.editDialogVisible = false">
取消
</el-button>
<el-button type="primary" @click="editBreedingPlan(scope.form)">
修改
</el-button>
</template>
</ZooBreedingPlanFormDialog>
</el-dialog>
</template>
<style scoped>

View File

@ -2,7 +2,7 @@
import {Delete, Edit, Search, User} from "@element-plus/icons-vue";
import {mapState,mapActions} from "vuex";
import ZooUserFormDialog from "@/components/ZooUserFormDialog.vue";
import {copy, fuzzyMatching, generateUsers, splitKeyWords} from "@/utils/common.js";
import {copy, fuzzyMatching, splitKeyWords} from "@/utils/common.js";
export default {
@ -88,6 +88,7 @@ export default {
})
}
//
this.getUsers()
this.dialog.editDialogVisible = false//
},
deleteUser(user) {
@ -105,6 +106,7 @@ export default {
).then(() => {
//
//
this.getUsers()
ElMessage({
type: 'success',
message: '删除成功',
@ -135,6 +137,7 @@ export default {
})
}
//
this.getUsers()
this.dialog.addDialogVisible = false//
},
@ -197,8 +200,8 @@ export default {
<div class="right">
<el-input
v-model="searchInput.keyword"
style="max-width: 300px"
placeholder="搜索用户"
style="width: 400px"
placeholder="搜索用户 空格隔开关键字"
>
<template #prepend>
<el-select v-model="searchInput.auth" placeholder="身份" style="width: 90px">

View File

@ -1,5 +1,5 @@
import {createStore} from "vuex";
import {generateAnimals, generateUsers} from "@/utils/common.js";
import {generateAnimals, generateBreedingPlans, generateUsers} from "@/utils/common.js";
const actions = {
//更新登录用户
@ -25,7 +25,7 @@ const actions = {
},
//获取饲养计划
getBreedingPlans(context) {
context.commit('updateBreedingPlans','')
context.commit('updateBreedingPlans',generateBreedingPlans())
}
}

View File

@ -35,6 +35,43 @@ export function generateAnimals() {
return animals
}
// id: '',//int 饲养计划id
// name: '',//字符 饲养计划名称
// species: '',//字符 种类
// sex: '雄性',//字符 饲养动物性别
// phase: '',//字符 饲养动物阶段:幼年期、成长期、成年期、老年期
// state: 0,//int 状态0正常 1异常
// describe: ''//字符 饲养计划的描述
export function generateBreedingPlans() {
const breedingPlans = []
for (let i = 0; i < 100; i++) {
let breedingPlan = {
id: i,
name: 'breeding' + (i + 3),
species: Math.floor(Math.random() * 10).toString(),
sex: Math.floor(Math.random() * 2) === 0 ? '雌性' : '雄性',
phase:generatePhase(),
state: Math.floor(Math.random() * 2),
description: Math.floor(Math.random() * 500).toString(),
}
breedingPlans.push(breedingPlan)
}
return breedingPlans
}
function generatePhase() {
const phase = Math.floor(Math.random() * 4)
if (phase===0)
return '幼年期'
if (phase===1)
return '成长期'
if (phase===2)
return '成年期'
if (phase===3)
return '老年期'
}
//深拷贝任何值
export function copy(value) {
let result = JSON.stringify(value)