From 56071bdbf40fc24cebaa66172d301814b5538069 Mon Sep 17 00:00:00 2001
From: helloworld180 <1678854362@qq.com>
Date: Wed, 18 Dec 2024 23:11:13 +0800
Subject: [PATCH] =?UTF-8?q?=E6=97=8F=E8=B0=B1=E6=A0=91=E5=AF=B9=E6=8E=A5?=
=?UTF-8?q?=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/axiosConfig.js | 2 +-
src/views/space/familyTree.vue | 115 ++++++---
src/views/space/familyTree1.vue | 407 ++++++++++----------------------
vue.config.js | 6 +-
4 files changed, 209 insertions(+), 321 deletions(-)
diff --git a/src/utils/axiosConfig.js b/src/utils/axiosConfig.js
index df07b0c2..0677c327 100644
--- a/src/utils/axiosConfig.js
+++ b/src/utils/axiosConfig.js
@@ -5,7 +5,7 @@ import {getToken} from '@/token/auth' // 注意这里使用了解构赋值来导
// 创建axios实例
const service = axios.create({
// 去vue.config.js文件改baseurl!!
- baseURL: '/api', // 注意!! 这里全局统一加上了 '/api' 前缀,但是vue.config.js文件在发送请求时去掉了/api,所以页面的请求接口若有/api还是要携带/api
+ baseURL: 'http://10.133.25.59:8083/loveforest/api', // 注意!! 这里全局统一加上了 '/api' 前缀,但是vue.config.js文件在发送请求时去掉了/api,所以页面的请求接口若有/api还是要携带/api
timeout: 5000, // 请求超时时间
});
diff --git a/src/views/space/familyTree.vue b/src/views/space/familyTree.vue
index fa2dd958..2fe17dc0 100644
--- a/src/views/space/familyTree.vue
+++ b/src/views/space/familyTree.vue
@@ -5,7 +5,7 @@
添加祖辈信息
编辑祖辈信息
- 保存族谱
+
@@ -15,9 +15,9 @@
:collapse-enabled="true"
node-text="name"
>
-
+
-
+
{{ node.name }}
{{ node.relation }}
@@ -35,8 +35,8 @@
v-model="dialogVisible"
width="500px"
>
-
-
+
+
@@ -56,7 +56,7 @@
-
+
-
+
-
+
-
-
+
+
@@ -143,10 +143,22 @@ export default {
},
data() {
return {
+ userId: 3,
+ rules: {
+ name: [
+ { required: true, message: '请输入姓名', trigger: 'blur' }
+ ],
+ parentId: [
+ { required: true, message: '请选择所属分支', trigger: 'change' }
+ ],
+ relation: [
+ { required: true, message: '请选择关系', trigger: 'change' }
+ ]
+ },
treeData :{
id: '1',
name: '爷爷',
- avatar: '/avatar/1.jpg',
+ avatar: 'https://via.placeholder.com/150',
relation: 'grandfather',
birthDate: '1940-01-01',
phone: '13800138000',
@@ -154,7 +166,7 @@ export default {
{
id: '2',
name: '父亲',
- avatar: '/avatar/2.jpg',
+ avatar: '../../assets/pictures/space/post1.png',
relation: 'father',
birthDate: '1965-01-01',
phone: '13800138001',
@@ -207,7 +219,7 @@ export default {
phone: '',
isCurrentUser: false
},
- uploadUrl: '/api/upload',
+ uploadUrl: '/upload',
flattenedTreeData: [
{
id: 1,
@@ -281,15 +293,28 @@ export default {
// 获取族谱数据
async fetchTreeData() {
try {
- const { data } = await request.get('/api/family-tree')
- this.treeData = data
- this.flattenedTreeData = flattenTree(data)
+ const response = await request.get(`/family-tree/${this.userId}`)
+ this.processTreeData(response)
+ this.treeData = response
+ this.flattenedTreeData = flattenTree(response)
this.availableParents = this.flattenedTreeData
+ // console.log('获取族谱树数据成功:', response)
} catch (error) {
ElMessage.error('获取族谱数据失败')
}
},
-
+ processTreeData(node) {
+ // 设置默认值
+ node.avatar = node.avatar || '/default-avatar.png'
+ node.relation = node.relation || '未知'
+ node.birthDate = node.birthDate || '未知'
+ node.phone = node.phone || '未知'
+
+ // 递归处理子节点
+ if (node.children && node.children.length) {
+ node.children.forEach(child => this.processTreeData(child))
+ }
+ },
// 显示添加对话框
showAddDialog() {
this.dialogTitle = '添加成员'
@@ -354,23 +379,31 @@ export default {
// 保存成员信息
async saveMember() {
+ const isValid = await new Promise((resolve) => {
+ this.$refs.memberForm.validate((valid) => {
+ resolve(valid);
+ });
+ });
+ if (!isValid) {
+ ElMessage.error('请填写完整的表单信息!');
+ return;
+ }
+
try {
const url = this.currentMember.id ?
- `/api/family-tree/${this.currentMember.id}` :
- '/api/family-tree'
-
- const { data } = await request({
+ `/family-tree/${this.currentMember.id}` :
+ '/family-tree'
+ await request({
url,
method: this.currentMember.id ? 'put' : 'post',
data: this.currentMember
})
-
- if (data.code === 0) {
+ // console.log('保存成功:',response) 没有response么嘎
ElMessage.success('保存成功')
this.dialogVisible = false
this.fetchTreeData()
- }
} catch (error) {
+ console.log('新增成员失败', this.currentMember)
ElMessage.error('保存失败')
}
},
@@ -378,12 +411,28 @@ export default {
// 删除成员
async deleteMember() {
try {
- const { data } = await request.delete(`/api/family-tree/${this.currentMember.id}`)
- if (data.code === 0) {
- ElMessage.success('删除成功')
- this.dialogVisible = false
- this.fetchTreeData()
+ const confirmResult = await this.$confirm(
+ '此操作将永久删除该成员, 是否继续?',
+ '提示',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }
+ ).catch(err => err);
+
+ // 如果用户确认删除,则 confirmResult 为 'confirm'
+ // 如果用户取消删除,则 confirmResult 为 'cancel'
+ if (confirmResult !== 'confirm') {
+ return; // 用户取消操作,直接返回
}
+
+ // 执行删除操作
+ await request.delete(`/family-tree/${this.currentMember.id}`);
+ ElMessage.success('删除成功');
+ this.dialogVisible = false;
+ this.fetchTreeData();
+
} catch (error) {
ElMessage.error('删除失败')
}
@@ -392,10 +441,8 @@ export default {
// 保存整个族谱
async saveTreeData() {
try {
- const { data } = await request.put('/api/family-tree', this.treeData)
- if (data.code === 0) {
- ElMessage.success('保存成功')
- }
+ await request.put('/family-tree', this.treeData)
+ ElMessage.success('保存成功')
} catch (error) {
ElMessage.error('保存失败')
}
diff --git a/src/views/space/familyTree1.vue b/src/views/space/familyTree1.vue
index d2fc7a30..27a491ba 100644
--- a/src/views/space/familyTree1.vue
+++ b/src/views/space/familyTree1.vue
@@ -1,337 +1,178 @@
-
-
-
-
- 添加祖辈节点
- 保存族谱
-
-
-
-
-
-
-
![image]()
-
+
+
+
+ 放大
+ 缩小
+ 重置
+
+
+
+
+
+
+
+
+
+ true"
+ />
+
+
+
+
{{ node.name }}
-
+
{{ node.relation }}
+
{{ node.birthDate }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 取消
- 确定
- 删除
-
-
+
\ No newline at end of file
diff --git a/vue.config.js b/vue.config.js
index 79f65298..dbbdade4 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -1,12 +1,12 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
devServer:{
- host: 'localhost',
- port: 8080,
+ // host: 'localhost',
+ // port: 8080,
https: false,
proxy:{
'/api': { //设置拦截器 拦截器格式 斜杠+拦截器名字,名字可以自己定
- target: 'https://911fb0525ms3.vicp.fun/loveforest/api/', //代理的目标地址
+ target: 'http://10.133.25.59:8083/loveforest', //代理的目标地址
changeOrigin: true, //是否设置同源,输入是的
pathRewrite: { //路径重写
'^/api': '' //选择忽略拦截器里面的内容