This commit is contained in:
1 parent
81fcc6a0a9
commit
c9b95079a0
6 files changed
+62
-16
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { reactive } from "vue";
|
||||
import useGroupStore from '../../../stores/group';
|
||||
|
||||
import lang from "../../../i18n/i18n";
|
||||
|
||||
@@ -10,6 +11,8 @@ import { Folder, Delete, Plus } from "@element-plus/icons-vue";
|
||||
|
||||
export function usePage() {
|
||||
const data = reactive([]);
|
||||
const groupStore = useGroupStore();
|
||||
const saving = new WeakSet();
|
||||
|
||||
http.get("/api/v1/group").then((res) => {
|
||||
data.push(...res.data);
|
||||
@@ -21,6 +24,7 @@ export function usePage() {
|
||||
if (res.errorNo !== 0) {
|
||||
ElMessage({ message: res.errorMsg, type: "error" });
|
||||
} else {
|
||||
groupStore.invalidate();
|
||||
const pc = node.parent.childNodes;
|
||||
for (let i = 0; i < pc.length; i++) {
|
||||
if (pc[i].id === node.id) {
|
||||
@@ -63,18 +67,22 @@ export function usePage() {
|
||||
};
|
||||
|
||||
const onInputBlur = function (item) {
|
||||
if (item.label !== "") {
|
||||
if (item.id !== -1 || saving.has(item)) return;
|
||||
if (item.label.trim() !== "") {
|
||||
saving.add(item);
|
||||
http.post("/api/v1/group/add", { name: item.label, parent_id: item.parent_id })
|
||||
.then((res) => {
|
||||
if (res.errorNo !== 0) {
|
||||
ElMessage({ message: res.errorMsg, type: "error" });
|
||||
} else {
|
||||
http.get("/api/v1/group").then((res) => {
|
||||
groupStore.invalidate();
|
||||
return http.get("/api/v1/group").then((res) => {
|
||||
data.splice(0, data.length);
|
||||
data.push(...res.data);
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch(error => ElMessage.error(error.message))
|
||||
.finally(() => saving.delete(item));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -47,7 +47,11 @@ export function usePage() {
|
||||
|
||||
const data = ref([]);
|
||||
|
||||
const searchQuery = ref("");
|
||||
const searchQuery = ref(groupStore.keyword);
|
||||
const submitSearch = () => {
|
||||
groupStore.keyword = searchQuery.value.trim();
|
||||
router.push({ name: "list" });
|
||||
};
|
||||
|
||||
const activeGroup = ref(groupStore.tag);
|
||||
|
||||
@@ -55,7 +59,7 @@ export function usePage() {
|
||||
activeGroup.value = newVal;
|
||||
});
|
||||
|
||||
http.get("/api/v1/group").then((res) => {
|
||||
const loadGroups = () => http.get("/api/v1/group").then((res) => {
|
||||
if (res.data) {
|
||||
// Attempting to flatten the tree for a simpler premium menu or keep it, el-tree is less beautiful.
|
||||
// For now we assume res.data is an array of items. If it's a tree, we flatten it.
|
||||
@@ -68,8 +72,11 @@ export function usePage() {
|
||||
}
|
||||
traverse(res.data);
|
||||
data.value = list;
|
||||
|
||||
}
|
||||
});
|
||||
}).catch(error => ElMessage.error(error.message));
|
||||
watch(() => groupStore.revision, loadGroups);
|
||||
loadGroups();
|
||||
|
||||
const handleMenuSelect = function (index) {
|
||||
const selected = data.value.find(d => d.tag === index);
|
||||
@@ -111,6 +118,7 @@ export function usePage() {
|
||||
router,
|
||||
data,
|
||||
searchQuery,
|
||||
submitSearch,
|
||||
activeGroup,
|
||||
handleMenuSelect,
|
||||
openSettings
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
<div class="search-box">
|
||||
<el-input
|
||||
v-model="searchQuery"
|
||||
@keyup.enter="submitSearch"
|
||||
@clear="submitSearch"
|
||||
:placeholder="lang.search"
|
||||
prefix-icon="Search"
|
||||
clearable
|
||||
@@ -63,6 +65,7 @@ import { usePage, BrandLogo, Setting, SwitchButton } from './HomeAside.js'
|
||||
|
||||
const {
|
||||
searchQuery,
|
||||
submitSearch,
|
||||
lang,
|
||||
activeGroup,
|
||||
handleMenuSelect,
|
||||
|
||||
Reference in new issue
Block a user