-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 代码分离,功能优化 1. 代码迁移到 ts. 2. 分离 axios 部分代码. 3. 增加 pinia 支持,全局状态代码迁移到相对应的 store. 4. 代码格式优化, 用 === 代替 ==. 5. 代码声明更改,用 const 代替 var 声明. 6. Header 使用 Router 导航. 7. v-for 增加 key. * fix[fe]: 移除过时的 prop 引用 * fix[fe]: 移除过时的 prop 引用 * fix[fe]: 修复 logo 上面有横线的问题 * fix[fe]: 修复 logo 上面有横线的问题 --------- Co-authored-by: zhe28 <huangze28@foxmail.com>
- Loading branch information
Showing
20 changed files
with
1,676 additions
and
1,674 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,123 @@ | ||
<template> | ||
<div id="main"> | ||
<el-tree :expand-on-click-node="false" :data="data" :props="defaultProps" :defaultExpandAll="true" :class="node"> | ||
<template #default="{ node, data }"> | ||
<div> | ||
<span v-if="data.id != -1"> {{ data.label }}</span> | ||
<el-input v-if="data.id == -1" v-model="data.label" @blur="onInputBlur(data)"></el-input> | ||
<el-button v-if="data.id != 0" @click="del(node, data)" size="small" type="danger" circle> - | ||
</el-button> | ||
<el-button v-if="data.id != 0" @click="add(data)" size="small" type="primary" circle> + </el-button> | ||
</div> | ||
</template> | ||
</el-tree> | ||
<div id="main"> | ||
<el-tree | ||
:expand-on-click-node="false" | ||
:data="data" | ||
:defaultExpandAll="true" | ||
> | ||
<template #default="{ node, data }"> | ||
<div> | ||
<span v-if="data.id !== -1"> {{ data.label }}</span> | ||
<el-input | ||
v-if="data.id === -1" | ||
v-model="data.label" | ||
@blur="onInputBlur(data)" | ||
></el-input> | ||
<el-button | ||
v-if="data.id !== 0" | ||
@click="del(node, data)" | ||
size="small" | ||
type="danger" | ||
circle | ||
> | ||
- | ||
</el-button> | ||
<el-button | ||
v-if="data.id !== 0" | ||
@click="add(data)" | ||
size="small" | ||
type="primary" | ||
circle | ||
> | ||
+ | ||
</el-button> | ||
</div> | ||
</template> | ||
</el-tree> | ||
|
||
<el-button @click="addRoot">{{ lang.add_group }}</el-button> | ||
</div> | ||
<el-button @click="addRoot">{{ lang.add_group }}</el-button> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { reactive, ref, getCurrentInstance } from 'vue' | ||
import lang from '../i18n/i18n'; | ||
import { reactive } from "vue"; | ||
import lang from "../i18n/i18n"; | ||
import { http } from "@/utils/axios"; | ||
import { ElMessage } from "element-plus"; | ||
const data = reactive([]) | ||
const app = getCurrentInstance() | ||
const $http = app.appContext.config.globalProperties.$http | ||
const data = reactive([]); | ||
$http.get('/api/group').then(res => { | ||
data.push(...res.data) | ||
}) | ||
http.get("/api/group").then((res) => { | ||
data.push(...res.data); | ||
}); | ||
const del = function (node, data) { | ||
if (data.id != -1) { | ||
this.$axios.post("/api/group/del", { "id": data.id }).then(res => { | ||
if (res.errorNo != 0) { | ||
ElMessage({ | ||
message: res.errorMsg, | ||
type: 'error', | ||
}) | ||
} else { | ||
const pc = node.parent.childNodes | ||
for (let i = 0; i < pc.length; i++) { | ||
if (pc[i].id == node.id) { | ||
pc.splice(i, 1) | ||
return | ||
} | ||
} | ||
} | ||
}) | ||
} else { | ||
const pc = node.parent.childNodes | ||
if (data.id !== -1) { | ||
this.$axios.post("/api/group/del", { id: data.id }).then((res) => { | ||
if (res.errorNo !== 0) { | ||
ElMessage({ | ||
message: res.errorMsg, | ||
type: "error", | ||
}); | ||
} else { | ||
const pc = node.parent.childNodes; | ||
for (let i = 0; i < pc.length; i++) { | ||
if (pc[i].id == node.id) { | ||
pc.splice(i, 1) | ||
return | ||
} | ||
if (pc[i].id === node.id) { | ||
pc.splice(i, 1); | ||
return; | ||
} | ||
} | ||
} | ||
}); | ||
} else { | ||
const pc = node.parent.childNodes; | ||
for (let i = 0; i < pc.length; i++) { | ||
if (pc[i].id === node.id) { | ||
pc.splice(i, 1); | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
const add = function (item) { | ||
if (item.children == null) { | ||
item.children = [] | ||
} | ||
item.children.push({ | ||
"children": [], | ||
"label": "", | ||
"id": "-1", | ||
"parent_id": item.id | ||
}) | ||
} | ||
if (item.children == null) { | ||
item.children = []; | ||
} | ||
item.children.push({ | ||
children: [], | ||
label: "", | ||
id: "-1", | ||
parent_id: item.id, | ||
}); | ||
}; | ||
const addRoot = function () { | ||
data.push({ | ||
"children": [], | ||
"label": "", | ||
"id": "-1", | ||
"parent_id": 0 | ||
}) | ||
} | ||
data.push({ | ||
children: [], | ||
label: "", | ||
id: "-1", | ||
parent_id: 0, | ||
}); | ||
}; | ||
const onInputBlur = function (item) { | ||
if (item.label != "") { | ||
this.$axios.post("/api/group/add", { "name": item.label, "parent_id": item.parent_id }).then(res => { | ||
if (res.errorNo != 0) { | ||
ElMessage({ | ||
message: res.errorMsg, | ||
type: 'error', | ||
}) | ||
} else { | ||
this.$axios.get('/api/group').then(res => { | ||
data.splice(0, data.length) | ||
data.push(...res.data) | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
</script> | ||
if (item.label !== "") { | ||
http | ||
.post("/api/group/add", { name: item.label, parent_id: item.parent_id }) | ||
.then((res) => { | ||
if (res.errorNo !== 0) { | ||
ElMessage({ | ||
message: res.errorMsg, | ||
type: "error", | ||
}); | ||
} else { | ||
this.$axios.get("/api/group").then((res) => { | ||
data.splice(0, data.length); | ||
data.push(...res.data); | ||
}); | ||
} | ||
}); | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.