对接动物后端

This commit is contained in:
bicey 2024-06-09 16:21:01 +08:00
parent fca50296df
commit f3e9ba083b
14 changed files with 167 additions and 134 deletions

View File

@ -48,7 +48,7 @@ export default {
<template> <template>
<el-form label-width="auto"> <el-form label-width="auto">
<el-form-item label="动物ID"> <el-form-item label="动物ID">
<el-input v-model.number="form.id" placeholder="请设置动物ID" type="number" :disabled="edit || detail"/> <el-input v-model.number="form.id" placeholder="系统自动生成ID" type="number" :disabled="edit || detail || true"/>
</el-form-item> </el-form-item>
<el-form-item label="动物名称"> <el-form-item label="动物名称">
<el-input v-model="form.name" placeholder="动物名称" :disabled="detail"/> <el-input v-model="form.name" placeholder="动物名称" :disabled="detail"/>

View File

@ -47,7 +47,7 @@ export default {
<template> <template>
<el-form label-width="auto"> <el-form label-width="auto">
<el-form-item label="记录号"> <el-form-item label="记录号">
<el-input v-model.number="form.id" type="number" placeholder="记录号" :disabled="edit || detail"/> <el-input v-model.number="form.id" type="number" placeholder="系统自动生成记录号" :disabled="edit || detail || true"/>
</el-form-item> </el-form-item>
<el-form-item label="动物ID"> <el-form-item label="动物ID">
<el-input v-model.number="form.animalId" type="number" placeholder="动物ID" :disabled="detail"/> <el-input v-model.number="form.animalId" type="number" placeholder="动物ID" :disabled="detail"/>

View File

@ -19,7 +19,7 @@ export default {
} }
}, },
mounted() { mounted() {
console.log('auth', this.loginUser) // console.log('auth', this.loginUser)
} }
} }

View File

@ -45,7 +45,7 @@ export default {
<template> <template>
<el-form label-width="auto"> <el-form label-width="auto">
<el-form-item label="计划ID"> <el-form-item label="计划ID">
<el-input v-model.number="form.id" type="number" placeholder="饲养计划ID" :disabled="edit || detail"/> <el-input v-model.number="form.id" type="number" placeholder="系统自动生成ID" :disabled="edit || detail || true"/>
</el-form-item> </el-form-item>
<el-form-item label="计划名称"> <el-form-item label="计划名称">
<el-input v-model="form.name" placeholder="计划名称" :disabled="detail"/> <el-input v-model="form.name" placeholder="计划名称" :disabled="detail"/>

View File

@ -48,7 +48,7 @@ export default {
<template> <template>
<el-form label-width="auto"> <el-form label-width="auto">
<el-form-item label="监测号"> <el-form-item label="监测号">
<el-input v-model.number="form.id" type="number" placeholder="监测号" :disabled="edit || detail"/> <el-input v-model.number="form.id" type="number" placeholder="系统自动生成监测号" :disabled="edit || detail || true"/>
</el-form-item> </el-form-item>
<el-form-item label="动物ID"> <el-form-item label="动物ID">
<el-input v-model.number="form.animalId" type="number" placeholder="动物ID" :disabled="detail"/> <el-input v-model.number="form.animalId" type="number" placeholder="动物ID" :disabled="detail"/>

View File

@ -42,8 +42,8 @@ export default {
<template> <template>
<el-form label-width="auto"> <el-form label-width="auto">
<el-form-item label="用户ID"> <el-form-item label="用户ID">
<el-input v-model.number="form.id" placeholder="请设置用户ID" type="number" <el-input v-model.number="form.id" placeholder="系统自动生成ID" type="number"
:disabled="edit || detail"/> :disabled="edit || detail|| true"/>
</el-form-item> </el-form-item>
<el-form-item label="用户名"> <el-form-item label="用户名">
<el-input v-model="form.username" placeholder="请设置用户名" :disabled="detail"/> <el-input v-model="form.username" placeholder="请设置用户名" :disabled="detail"/>

View File

@ -2,9 +2,9 @@
import {copy, fuzzyMatching, splitKeyWords} from "@/utils/common.js"; import {copy, fuzzyMatching, splitKeyWords} from "@/utils/common.js";
import {Delete, Document, DocumentAdd, Edit, Search, Tickets} from "@element-plus/icons-vue"; import {Delete, Document, DocumentAdd, Edit, Search, Tickets} from "@element-plus/icons-vue";
import ZooAnimalFormDialog from "@/components/ZooAnimalFormDialog.vue"; import ZooAnimalFormDialog from "@/components/ZooAnimalFormDialog.vue";
import {mapActions, mapMutations, mapState} from "vuex"; import {mapMutations, mapState} from "vuex";
import ZooArchiveTimeline from "@/components/ZooArchiveTimeline.vue"; import ZooArchiveTimeline from "@/components/ZooArchiveTimeline.vue";
import request, {frontendAnimals} from "@/utils/request.js"; import request, {frontendAnimal, frontendAnimals} from "@/utils/request.js";
export default { export default {
name: "ZooAnimal", name: "ZooAnimal",
@ -67,7 +67,6 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(["getAnimals"]),
...mapMutations(['updateAnimals','updateAnimalsTableData']), ...mapMutations(['updateAnimals','updateAnimalsTableData']),
// //
@ -76,20 +75,18 @@ export default {
// //
request.queryAnimalRequest(data.id).then(response => { request.queryAnimalRequest(data.id).then(response => {
console.log(response.data)
if (response.data.data===null){ if (response.data.data===null){
this.refresh(); this.refresh();
return ElMessage({ return ElMessage({
message: '该动物不存在,请刷新', message: '该动物不存在,请刷新',
type: 'warning', type: 'warning',
}) })
} } else {
}) this.dialog.dialogData = frontendAnimal(response.data.data)
//
this.dialog.dialogData = this.animals.find(e => e.id === data.id)
// //
this.dialog.detailDialogVisible = true this.dialog.detailDialogVisible = true
}
})
}, },
// //
@ -97,45 +94,49 @@ export default {
console.log('显示编辑', data) console.log('显示编辑', data)
// //
// request.queryAnimalRequest(data.id).then(response => {
this.dialog.dialogData = this.animals.find(e => e.id === data.id) if (response.data.data===null){
this.refresh();
return ElMessage({
message: '该动物不存在,请刷新',
type: 'warning',
})
} else {
this.dialog.dialogData = frontendAnimal(response.data.data)
// //
this.dialog.editDialogVisible = true this.dialog.editDialogVisible = true
}
})
}, },
edit(data) { edit(data) {
console.log('编辑', data) console.log('编辑', data)
// //
return this.isEmpty(data); if (this.isEmpty(data)) {
return;
}
// //
// request.updateAnimalRequest(data).then(response => {
if (false) { if (response.data.code===1){
//
//
this.refresh()
this.dialog.editDialogVisible = false//
return ElMessage({
message: '编辑成功',
type: 'success',
})
}else {
return ElMessage({ return ElMessage({
message: '编辑失败', message: '编辑失败',
type: 'warning', type: 'warning',
}) })
} }
//
if (false) {
return ElMessage({
message: '编辑成功',
type: 'success',
}) })
}
// //
// this.getAnimals()
// this.search()
//
this.refresh()
//
this.dialog.editDialogVisible = false
}, },
delete_(data) { delete_(data) {
@ -150,12 +151,18 @@ export default {
type: 'warning', type: 'warning',
} }
).then(() => { ).then(() => {
//
request.queryAnimalRequest(data.id).then(response => {
if (response.data.data===null){
this.refresh();
return ElMessage({
message: '该动物不存在,请刷新',
type: 'warning',
})
} else {
// //
request.deleteAnimalRequest(data.id).then(response => {
// // if (response.data.code===1){
// this.getAnimals()
// this.search()
// //
this.refresh() this.refresh()
@ -164,6 +171,15 @@ export default {
type: 'success', type: 'success',
message: '删除成功', message: '删除成功',
}) })
} else {
ElMessage({
type: 'success',
message: '删除失败',
})
}
})
}
})
}).catch(() => { }).catch(() => {
ElMessage({ ElMessage({
type: 'info', type: 'info',
@ -177,26 +193,12 @@ export default {
// //
if (this.isEmpty(data)) { if (this.isEmpty(data)) {
return ElMessage({ return;
message: '请输入动物名称',
type: 'warning',
})
} }
//
request.queryAnimalRequest(data.id).then(response => {
if (response.data.data!==null){
return ElMessage({
message: '该动物已存在',
type: 'warning',
})
}
})
request.addAnimalRequest(data).then(response => { request.addAnimalRequest(data).then(response => {
if (response.data.code===1){ if (response.data.code===1){
// //
// //
this.refresh() this.refresh()
@ -206,6 +208,11 @@ export default {
message: '添加成功', message: '添加成功',
type: 'success', type: 'success',
}) })
}else {
return ElMessage({
message: '添加失败',
type: 'warning',
})
} }
}) })
}, },
@ -234,7 +241,10 @@ export default {
// //
isEmpty(form) { isEmpty(form) {
if (!form.name) { if (!form.name) {
return true return ElMessage({
message: '请输入动物名称',
type: 'warning',
})
} }
}, },
@ -306,9 +316,6 @@ export default {
mounted() { mounted() {
// //
this.refresh() this.refresh()
// request.queryAnimalRequest(0).then(response => {
// console.log(response.data,"11111111111111111111111111111")
// })
} }
} }
</script> </script>

View File

@ -26,7 +26,7 @@ export default {
...mapMutations(['updateLoginUser']), ...mapMutations(['updateLoginUser']),
// //
login() { login() {
console.log('登录', this.form) console.log('点击登录', this.form)
// //
if (!this.form.username || !this.form.password) { if (!this.form.username || !this.form.password) {
// //
@ -40,8 +40,8 @@ export default {
request.login(this.form).then(response => { request.login(this.form).then(response => {
if (response.data.code === 1) { if (response.data.code === 1) {
// //
this.updateLoginUser(frontendLoginUser(response.data.data, this.form.username)) this.updateLoginUser(frontendLoginUser(response.data.data))
localStorage.setItem('username', this.form.username);// localStorage.setItem('username', response.data.data.username);//
// //
this.$router.push('/panel/home') this.$router.push('/panel/home')
return ElMessage({ return ElMessage({
@ -68,7 +68,6 @@ export default {
// //
this.form.username = localStorage.getItem('username'); this.form.username = localStorage.getItem('username');
} }
} }
</script> </script>

View File

@ -24,7 +24,13 @@ export default {
ZooFooter ZooFooter
}, },
mounted() { mounted() {
console.log("登录用户",this.$store.state.loginUser)
//
this.getUsers();
this.getAnimals(); this.getAnimals();
this.getBreedingPlans();
this.getArchives();
this.getHealths();
} }
} }
</script> </script>

View File

@ -3,6 +3,7 @@ import {Delete, Edit, Search, User, Document} from "@element-plus/icons-vue";
import {mapState, mapActions, mapMutations} from "vuex"; import {mapState, mapActions, mapMutations} from "vuex";
import ZooUserFormDialog from "@/components/ZooUserFormDialog.vue"; import ZooUserFormDialog from "@/components/ZooUserFormDialog.vue";
import {copy, fuzzyMatching, splitKeyWords, showPassword, hidePassword} from "@/utils/common.js"; import {copy, fuzzyMatching, splitKeyWords, showPassword, hidePassword} from "@/utils/common.js";
import request, {frontendUsers} from "@/utils/request.js";
export default { export default {
@ -65,7 +66,7 @@ export default {
hidePassword, hidePassword,
showPassword, showPassword,
...mapActions(['getUsers']), ...mapActions(['getUsers']),
...mapMutations(['updateUsersTableData']), ...mapMutations(['updateUsers','updateUsersTableData']),
// //
showDetail(data) { showDetail(data) {
@ -163,33 +164,35 @@ export default {
console.log('添加', data) console.log('添加', data)
// //
return this.isEmpty(data); if (this.isEmpty(data)) {
return;
}
// //
request.queryUserRequest(data.id).then(response => {
// console.log(response.data.data,"aaaaaaaaaaaaaaaaaa")
if (false) { if (response.data.data!=null){
return ElMessage({ return ElMessage({
message: '该用户已存在', message: '该用户ID已存在',
type: 'warning', type: 'warning',
}) })
} }
})
// //
if (false) { request.addUserRequest(data).then(response => {
if (response.data.code===1){
//
this.refresh()
this.dialog.addDialogVisible = false//
return ElMessage({ return ElMessage({
message: '添加成功', message: '添加成功',
type: 'success', type: 'success',
}) })
} }
})
// //
// this.getUsers()
// this.search()
//
this.refresh()
this.dialog.addDialogVisible = false//
}, },
// //
@ -257,22 +260,19 @@ export default {
console.log('刷新数据') console.log('刷新数据')
// //
this.getUsers() request.queryUserRequest().then(response => {
if (response.data.code === 1) {
this.updateUsers(frontendUsers(response.data.data))
}
// //
this.search() this.search()
// //
this.getPagesData() this.getPagesData()
})
} }
}, },
mounted() { mounted() {
// //
// this.getUsers()
//
// //
// this.getPagesData()
this.refresh() this.refresh()
}, },
} }

View File

@ -76,7 +76,7 @@ router.beforeEach((to, from, next) => {
//不是登录界面都需要权限。。。 //不是登录界面都需要权限。。。
// console.log(to, from, next); // console.log(to, from, next);
if (to.path !== '/login') { if (to.path !== '/login') {
if (!store.state.loginUser) { if (!store.state.loginUser.username) {
router.replace({ router.replace({
path: '/login', path: '/login',
}) })

View File

@ -1,6 +1,6 @@
import {createStore} from "vuex"; import {createStore} from "vuex";
import {copy, generateAnimals, generateArchives, generateBreedingPlans, generateUsers} from "@/utils/common.js"; import {copy, generateAnimals, generateArchives, generateBreedingPlans, generateUsers} from "@/utils/common.js";
import request, {frontendAnimals, frontendLoginUser} from "@/utils/request.js"; import request, {frontendAnimals, frontendUsers} from "@/utils/request.js";
import router from "@/router/index.js"; import router from "@/router/index.js";
const actions = { const actions = {
@ -8,14 +8,13 @@ const actions = {
getUsers(context) { getUsers(context) {
console.log('getUsers') console.log('getUsers')
//通过后端获取数据 //通过后端获取数据
// request.queryUserRequest().then(response => { request.queryUserRequest().then(response => {
// if (response.data.code === 1) { if (response.data.code === 1) {
// context.commit('updateUsers', response.data.data); context.commit('updateUsers', frontendUsers(response.data.data));
// console.log(response.data.data); }
// } })
// }) // // context.commit('updateUsers', generateUsers())
// context.commit('updateUsers', generateUsers()) // context.commit('updateUsers', context.state.users);
context.commit('updateUsers', context.state.users);
}, },
//获取动物数据 //获取动物数据
getAnimals(context) { getAnimals(context) {

View File

@ -290,7 +290,7 @@ export function hidePassword(event) {
export function splitKeyWords(keyword) { export function splitKeyWords(keyword) {
let keyset = keyword.split(' ')//提取关键字 let keyset = keyword.split(' ')//提取关键字
keyset = Array.from(new Set(keyset))//关键字去重 keyset = Array.from(new Set(keyset))//关键字去重
console.log('切割去重好的关键字', keyset) // console.log('切割去重好的关键字', keyset)
return keyset; return keyset;
} }
@ -307,7 +307,7 @@ export function fuzzyMatching(object, keyset) {
function keywordMatching(object, keyword) { function keywordMatching(object, keyword) {
//该关键字为空,肯定能匹配上 //该关键字为空,肯定能匹配上
if (keyword === '') { if (keyword === '') {
console.log('keywordMatching关键字为空', object, keyword, true) // console.log('keywordMatching关键字为空', object, keyword, true)
return true return true
} }
//只要对象的任意属性能匹配一次关键字就返回truesome():遇到true就返回true所有false就返回false //只要对象的任意属性能匹配一次关键字就返回truesome():遇到true就返回true所有false就返回false

View File

@ -15,7 +15,7 @@ export default {
//用户请求 //用户请求
addUserRequest(user) { addUserRequest(user) {
return instance.post("/zoo/account/add", backendUser(user)); return instance.post("/zoo/account/save", backendUser(user));
}, },
deleteUserRequest(id) { deleteUserRequest(id) {
return instance.get("/zoo/account/delete", {params: {id}}); return instance.get("/zoo/account/delete", {params: {id}});
@ -91,14 +91,31 @@ export default {
// } // }
// 将后端对象转化为符合前端需求的对象 // 将后端对象转化为符合前端需求的对象
export function frontendLoginUser(data, username) { export function frontendLoginUser(data) {
return { return {
id: data.roleid, id: data.id,
username: username, username: data.username,
auth: data.permissions auth: data.permissions
}; };
} }
export function frontendUsers(users){
const newUsers = []
users.forEach(user => {
newUsers.push(frontendUser(user));
})
return newUsers
}
export function frontendUser(user){
return {
id: user.id,
username: user.username,
password: user.password,
auth: user.permissions
}
}
export function frontendAnimals(animals) { export function frontendAnimals(animals) {
const newAnimals = [] const newAnimals = []
animals.forEach((element) => { animals.forEach((element) => {
@ -111,7 +128,7 @@ export function frontendAnimal(animal) {
return { return {
id: animal.aId, id: animal.aId,
name: animal.name, name: animal.name,
sex: animal.sex === 0 ? '雄性' : '雌性', sex: animal.sex,
species: animal.species,//种类 species: animal.species,//种类
weight: animal.weight, weight: animal.weight,
height: animal.height, height: animal.height,
@ -125,7 +142,12 @@ export function frontendAnimal(animal) {
// 将前端对象的属性转为能和后端对应上属性的对象 // 将前端对象的属性转为能和后端对应上属性的对象
export function backendUser(user) { export function backendUser(user) {
return {} return {
id: user.id,
username: user.username,
password: user.password,
permissions: user.auth
}
} }
export function backendAnimal(animal) { export function backendAnimal(animal) {