-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. 代码迁移到 ts. 2. 分离 axios 部分代码. 3. 增加 pinia 支持,全局状态代码迁移到相对应的 store. 4. 代码格式优化, 用 === 代替 ==. 5. 代码声明更改,用 const 代替 var 声明. 6. Header 使用 Router 导航. 7. v-for 增加 key.
- Loading branch information
zhe28
committed
Sep 20, 2024
1 parent
dbb671d
commit f2180ce
Showing
20 changed files
with
1,624 additions
and
1,647 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,99 @@ | ||
<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" :props="defaultProps" :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 {reactive} from 'vue' | ||
import lang from '../i18n/i18n'; | ||
import {http} from "@/utils/axios"; | ||
import {ElMessage} from "element-plus"; | ||
import {defaultProps} from "element-plus/es/components/select-v2/src/useProps"; | ||
const data = reactive([]) | ||
const app = getCurrentInstance() | ||
const $http = app.appContext.config.globalProperties.$http | ||
$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 | ||
} | ||
} | ||
} | ||
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 { | ||
} 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) | ||
}) | ||
} | ||
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.