预对接后端

This commit is contained in:
bicey 2024-06-09 00:50:12 +08:00
parent a5de0b4987
commit ff62e543ef
10 changed files with 370 additions and 76 deletions

91
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "0.0.0", "version": "0.0.0",
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"axios": "^1.7.2",
"element-plus": "^2.7.3", "element-plus": "^2.7.3",
"unplugin-icons": "^0.19.0", "unplugin-icons": "^0.19.0",
"vite-plugin-inspect": "^0.8.4", "vite-plugin-inspect": "^0.8.4",
@ -991,6 +992,21 @@
"resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz", "resolved": "https://registry.npmjs.org/async-validator/-/async-validator-4.2.5.tgz",
"integrity": "sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==" "integrity": "sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg=="
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz",
"integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -1070,6 +1086,17 @@
"fsevents": "~2.3.2" "fsevents": "~2.3.2"
} }
}, },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/confbox": { "node_modules/confbox": {
"version": "0.1.7", "version": "0.1.7",
"resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.7.tgz", "resolved": "https://registry.npmjs.org/confbox/-/confbox-0.1.7.tgz",
@ -1151,6 +1178,14 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/element-plus": { "node_modules/element-plus": {
"version": "2.7.3", "version": "2.7.3",
"resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.7.3.tgz", "resolved": "https://registry.npmjs.org/element-plus/-/element-plus-2.7.3.tgz",
@ -1327,6 +1362,38 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/follow-redirects": {
"version": "1.15.6",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/fs-extra": { "node_modules/fs-extra": {
"version": "11.2.0", "version": "11.2.0",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz",
@ -1625,6 +1692,25 @@
"node": ">=8.6" "node": ">=8.6"
} }
}, },
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mimic-fn": { "node_modules/mimic-fn": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz",
@ -1857,6 +1943,11 @@
"node": "^10 || ^12 || >=14" "node": "^10 || ^12 || >=14"
} }
}, },
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
"node_modules/queue-microtask": { "node_modules/queue-microtask": {
"version": "1.2.3", "version": "1.2.3",
"resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz",

View File

@ -10,6 +10,7 @@
}, },
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.3.1", "@element-plus/icons-vue": "^2.3.1",
"axios": "^1.7.2",
"element-plus": "^2.7.3", "element-plus": "^2.7.3",
"unplugin-icons": "^0.19.0", "unplugin-icons": "^0.19.0",
"vite-plugin-inspect": "^0.8.4", "vite-plugin-inspect": "^0.8.4",

View File

@ -4,6 +4,7 @@ import {Delete, Document, DocumentAdd, Edit, Search, Tickets} from "@element-plu
import ZooAnimalFormDialog from "@/components/ZooAnimalFormDialog.vue"; import ZooAnimalFormDialog from "@/components/ZooAnimalFormDialog.vue";
import {mapActions, mapMutations, mapState} from "vuex"; import {mapActions, mapMutations, mapState} from "vuex";
import ZooArchiveTimeline from "@/components/ZooArchiveTimeline.vue"; import ZooArchiveTimeline from "@/components/ZooArchiveTimeline.vue";
import request, {frontendAnimals} from "@/utils/request.js";
export default { export default {
name: "ZooAnimal", name: "ZooAnimal",
@ -67,13 +68,23 @@ export default {
}, },
methods: { methods: {
...mapActions(["getAnimals"]), ...mapActions(["getAnimals"]),
...mapMutations(['updateAnimalsTableData']), ...mapMutations(['updateAnimals','updateAnimalsTableData']),
// //
showDetail(data) { showDetail(data) {
console.log('显示详情', data) console.log('显示详情', data)
// //
request.queryAnimalRequest(data.id).then(response => {
console.log(response.data)
if (response.data.data===null){
this.refresh();
return ElMessage({
message: '该动物不存在,请刷新',
type: 'warning',
})
}
})
// //
this.dialog.dialogData = this.animals.find(e => e.id === data.id) this.dialog.dialogData = this.animals.find(e => e.id === data.id)
@ -165,32 +176,38 @@ export default {
console.log('添加', data) console.log('添加', data)
// //
return this.isEmpty(data); if (this.isEmpty(data)) {
return ElMessage({
message: '请输入动物名称',
type: 'warning',
})
}
// //
request.queryAnimalRequest(data.id).then(response => {
// if (response.data.data!==null){
if (false) {
return ElMessage({ return ElMessage({
message: '该动物已存在', message: '该动物已存在',
type: 'warning', type: 'warning',
}) })
} }
//
if (false) {
return ElMessage({
message: '添加成功',
type: 'success',
}) })
}
// // request.addAnimalRequest(data).then(response => {
// this.getAnimals() if (response.data.code===1){
// this.search() //
// //
this.refresh() this.refresh()
this.dialog.addDialogVisible = false// this.dialog.addDialogVisible = false//
return ElMessage({
message: '添加成功',
type: 'success',
})
}
})
}, },
//线 //线
@ -217,11 +234,7 @@ export default {
// //
isEmpty(form) { isEmpty(form) {
if (!form.name) { if (!form.name) {
// return true
return ElMessage({
message: '动物名不能为空',
type: 'warning',
})
} }
}, },
@ -278,18 +291,24 @@ export default {
console.log('刷新数据') console.log('刷新数据')
// //
this.getAnimals() request.queryAnimalRequest().then(response => {
if (response.data.code === 1) {
this.updateAnimals(frontendAnimals(response.data.data))
}
// //
this.search() this.search()
// //
this.getPagesData() this.getPagesData()
})
}, },
}, },
mounted() { mounted() {
// //
this.refresh() this.refresh()
// request.queryAnimalRequest(0).then(response => {
// console.log(response.data,"11111111111111111111111111111")
// })
} }
} }
</script> </script>
@ -375,7 +394,7 @@ export default {
</div> </div>
<!-- 添加动物对话框--> <!-- 添加动物对话框-->
<el-dialog v-model="dialog.addDialogVisible" title="添加动物" width="500" align-center draggable overflow> <el-dialog v-model="dialog.addDialogVisible" title="添加动物" width="500" align-center draggable overflow destroy-on-close>
<ZooAnimalFormDialog> <ZooAnimalFormDialog>
<template #default="scope"> <template #default="scope">
<el-button @click="dialog.addDialogVisible = false"> <el-button @click="dialog.addDialogVisible = false">

View File

@ -1,6 +1,6 @@
<script> <script>
import {mapMutations, mapState} from "vuex";
import {mapMutations, mapState, mapActions} from "vuex"; import request, {frontendLoginUser} from "@/utils/request.js";
export default { export default {
name: "ZooContainer", name: "ZooContainer",
@ -8,8 +8,8 @@ export default {
return { return {
// //
form: { form: {
username: '', username: 'admin',
password: '123456', password: '123',
}, },
picture: [ picture: [
'https://www4.bing.com//th?id=OHR.BambooPanda_ZH-CN8455481760_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp', 'https://www4.bing.com//th?id=OHR.BambooPanda_ZH-CN8455481760_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp',
@ -23,7 +23,6 @@ export default {
...mapState(['loginUser']) ...mapState(['loginUser'])
}, },
methods: { methods: {
...mapActions(['getLoginUser']),
...mapMutations(['updateLoginUser']), ...mapMutations(['updateLoginUser']),
// //
login() { login() {
@ -37,16 +36,25 @@ export default {
}) })
} }
// //
this.getLoginUser(this.form)// request.login(this.form).then(response => {
if (response.data.code === 1) {
// //
if (this.loginUser) { this.updateLoginUser(frontendLoginUser(response.data.data, this.form.username))
localStorage.setItem('username', this.loginUser.username);// localStorage.setItem('username', this.form.username);//
// //
this.$router.push('/panel/home') this.$router.push('/panel/home')
return ElMessage({
message: '登录成功',
type: 'success',
})
} else {
return ElMessage({
message: '用户名不存在或密码错误',
type: 'error',
})
} }
})
}, },
// //
reset() { reset() {
@ -67,7 +75,6 @@ export default {
<template> <template>
<div id="login-root"> <div id="login-root">
<!-- 背景图片--> <!-- 背景图片-->
<!-- <img src="https://www4.bing.com//th?id=OHR.BambooPanda_ZH-CN8455481760_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp" width="90%" height="auto" class="center"/>-->
<div> <div>
<el-carousel motion-blur height="700px" style="width: auto;"> <el-carousel motion-blur height="700px" style="width: auto;">
<el-carousel-item v-for="(item,index) in picture" :key="index" style="text-align: center"> <el-carousel-item v-for="(item,index) in picture" :key="index" style="text-align: center">

View File

@ -3,6 +3,7 @@ import ZooHeader from "@/components/ZooHeader.vue";
import ZooAside from "@/components/ZooAside.vue"; import ZooAside from "@/components/ZooAside.vue";
import ZooMain from "@/components/ZooMain.vue"; import ZooMain from "@/components/ZooMain.vue";
import ZooFooter from "@/components/ZooFooter.vue"; import ZooFooter from "@/components/ZooFooter.vue";
import {mapActions} from "vuex";
export default { export default {
name: "ZooPanel", name: "ZooPanel",
@ -14,15 +15,17 @@ export default {
} }
}, },
methods: { methods: {
...mapActions(['getUsers','getAnimals','getArchives','getBreedingPlans','getHealths'])
}, },
components: { components: {
ZooHeader, ZooHeader,
ZooAside, ZooAside,
ZooMain, ZooMain,
ZooFooter ZooFooter
},
mounted() {
this.getAnimals();
} }
} }
</script> </script>

View File

@ -27,7 +27,7 @@ export default {
addDialogVisible: false,// addDialogVisible: false,//
editDialogVisible: false,// editDialogVisible: false,//
detailDialogVisible: false,// detailDialogVisible: false,//
} },
} }
}, },
computed: { computed: {
@ -57,7 +57,6 @@ export default {
searchInput: { searchInput: {
deep: true, deep: true,
handler(val) { handler(val) {
// this.search()
this.refresh(); this.refresh();
} }
} }

View File

@ -46,7 +46,7 @@ export default {
message: '成功', message: '成功',
type: 'success', type: 'success',
}) })
} },
} }
} }
</script> </script>

View File

@ -1,26 +1,19 @@
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 router from "@/router/index.js";
const actions = { const actions = {
//获取登录用户
getLoginUser(context, value) {
//此处接入后端登录接口验证登录用户名和密码,验证通过方可通行
//密码错误
if (false) {
return ElMessage({
message: '用户名不存在或密码错误',
type: 'error',
})
}
const user = context.state.users.find(user => user.username === value.username)
user.auth = 0
//登录成功
context.commit('updateLoginUser', user);//存储登录用户,这里拉取远程登录的用户作为参数
},
//获取用户数据 //获取用户数据
getUsers(context) { getUsers(context) {
console.log('getUsers') console.log('getUsers')
//通过后端获取数据 //通过后端获取数据
// request.queryUserRequest().then(response => {
// if (response.data.code === 1) {
// context.commit('updateUsers', 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);
}, },
@ -28,8 +21,13 @@ const actions = {
getAnimals(context) { getAnimals(context) {
console.log('getAnimals') console.log('getAnimals')
// 通过后端获取数据 // 通过后端获取数据
request.queryAnimalRequest().then(response => {
if (response.data.code === 1) {
context.commit('updateAnimals', frontendAnimals(response.data.data));
}
})
// context.commit('updateAnimals', generateAnimals()) // context.commit('updateAnimals', generateAnimals())
context.commit('updateAnimals', context.state.animals); // context.commit('updateAnimals', context.state.animals);
}, },
//获取饲养计划 //获取饲养计划
getBreedingPlans(context) { getBreedingPlans(context) {
@ -120,7 +118,7 @@ const state = {
//登录用户数据 //登录用户数据
loginUser: { loginUser: {
id:0, id:0,
username: 'user1', username: '',
auth: 0 auth: 0
}, },
// //用户数据 // //用户数据

View File

@ -1,7 +1,180 @@
import store from "@/store/index.js"; import axios from "axios";
import {id} from "element-plus/es/locale/index";
export function getUserById(id) { const instance = axios.create({
const data = store.state.users.find(e => e.id === id); baseURL: 'http://localhost:8888',
})
return data; export default {
login(form) {
const formData = new FormData();
formData.append('username', form.username);
formData.append('password', form.password);
return instance.post("/zoo/login/login", formData);
},
// queryUserRequest(id) {
// return instance.get("/zoo/admin/info", id)
// },
// addUserRequest(user) {
// return instance.post("/zoo/admin/add", user);
// },
//动物请求
addAnimalRequest(animal) {
return instance.post("/zoo/animal/add", backendAnimal(animal));
},
deleteAnimalRequest(aid) {
return instance.get("/zoo/animal/delete", {params: {aid}});
},
updateAnimalRequest(animal) {
return instance.post("/zoo/animal/update", backendAnimal(animal));
},
queryAnimalRequest(aid) {
return instance.get("/zoo/animal/info", {params: {aid}})
},
//饲养计划请求
addBreedingPlanRequest(breedingPlan) {
return instance.post("/zoo/plan/add", backendBreeding(breedingPlan));
},
deleteBreedingPlanRequest(id) {
return instance.get("/zoo/plan/delete", {params: {id}})
},
updateBreedingPlanRequest(breedingPlan) {
return instance.post("/zoo/plan/update", backendBreeding(breedingPlan));
},
queryBreedingPlanRequest(id) {
return instance.get("/zoo/plan/info", {params: {id}})
},
//档案请求
addArchiveRequest(archive) {
return instance.post("/com/zoo/archive/add", backendArchive(archive));
},
deleteArchiveRequest(id) {
return instance.get("/com/zoo/archive/delete", {params: {id}})
},
updateArchiveRequest(archive) {
return instance.post("/com/zoo/archive/update", backendArchive(archive));
},
queryArchiveRequest(id) {
return instance.get("/com/zoo/archive/info", {params: {id}})
},
//健康记录请求
addHealthRequest(health) {
return instance.post("/com/zoo/health/add", backendHealth(health));
},
deleteHealthRequest(id) {
return instance.get("/com/zoo/health/delete", {params: {id}})
},
updateHealthRequest(health) {
return instance.post("/com/zoo/health/update", backendHealth(health));
},
queryHealthRequest(id) {
return instance.get("/com/zoo/health/info", {params: {id}})
}
}
// export function getUserById(id) {
// const data = store.state.users.find(e => e.id === id);
//
// return data;
// }
// 将后端对象转化为符合前端需求的对象
export function frontendLoginUser(data, username) {
return {
id: data.roleid,
username: username,
auth: data.permissions
};
}
export function frontendAnimals(animals) {
const newAnimals = []
animals.forEach((element) => {
newAnimals.push(frontendAnimal(element))
})
return newAnimals
}
export function frontendAnimal(animal) {
return {
id: animal.aId,
name: animal.name,
sex: animal.sex === 0 ? '雄性' : '雌性',
species: animal.species,//种类
weight: animal.weight,
height: animal.height,
state: animal.state,//状态0正常 1异常
roleId: animal.roleid,//饲养员id
color: animal.color,//颜色
features: animal.features,//特征
phase: animal.phase//生长阶段
}
}
// 将前端对象的属性转为能和后端对应上属性的对象
export function backendUser(user) {
return {}
}
export function backendAnimal(animal) {
return {
aId: animal.id,
name: animal.name,
sex: animal.sex,
species: animal.species,
weight: animal.weight,
height: animal.height,
state: animal.state,
roleid: animal.roleId,
color: animal.color,
features: animal.features,
phase: animal.phase
}
}
export function backendBreeding(breeding) {
return {
id: breeding.id,
name: breeding.name,
species: breeding.species,
sex: breeding.sex,
phase: breeding.phase,
state: breeding.state,
roleid: breeding.roleId,
description: breeding.description,
}
}
export function backendArchive(archive) {
return {
id: archive.id,
animallId: archive.animalId,
animalName: archive.animalName,
phase: archive.phase,
state: archive.state,
type: archive.type,
date: archive.date,
time: archive.time,
roleId: archive.roleId,
description: archive.description,
}
}
export function backendHealth(health) {
return {
id: health.id,
animalId: health.animalId,
animalName: health.animalName,
state: health.state,
temperature: health.temperature,
breathRate: health.breathRate,
heartRate: health.heartRate,
bloodPressure: health.bloodPressure,
date: health.date,
time: health.time,
description: health.description
}
} }

View File

@ -22,5 +22,8 @@ export default defineConfig({
alias: { alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)) '@': fileURLToPath(new URL('./src', import.meta.url))
} }
},
server:{
port:5000
} }
}) })