converted views/settings/Users.vue to composition api

This commit is contained in:
Joep 2023-09-10 16:21:57 +02:00
parent d1b21c8089
commit a14adb7cfd
2 changed files with 55 additions and 36 deletions

View File

@ -1,7 +1,34 @@
interface user { type UserKey = keyof IUser;
interface IUser {
id: number; id: number;
username: string;
password: string;
scope: string;
locale: string; locale: string;
perm: any; lockPassword: boolean;
viewMode: string;
singleClick: boolean;
perm: UserPerm;
commands: any[];
sorting: UserSorting;
rules: any[];
hideDotfiles: boolean;
dateFormat: boolean;
} }
type userKey = keyof user; interface UserPerm {
admin: boolean;
execute: boolean;
create: boolean;
rename: boolean;
modify: boolean;
delete: boolean;
share: boolean;
download: boolean;
}
interface UserSorting {
by: string;
asc: boolean;
}

View File

@ -1,13 +1,13 @@
<template> <template>
<errors v-if="error" :errorCode="error.status" /> <errors v-if="error" :errorCode="error.status" />
<div class="row" v-else-if="!loading"> <div class="row" v-else-if="!layoutStore.loading">
<div class="column"> <div class="column">
<div class="card"> <div class="card">
<div class="card-title"> <div class="card-title">
<h2>{{ $t("settings.users") }}</h2> <h2>{{ t("settings.users") }}</h2>
<router-link to="/settings/users/new" <router-link to="/settings/users/new"
><button class="button"> ><button class="button">
{{ $t("buttons.new") }} {{ t("buttons.new") }}
</button></router-link </button></router-link
> >
</div> </div>
@ -15,9 +15,9 @@
<div class="card-content full"> <div class="card-content full">
<table> <table>
<tr> <tr>
<th>{{ $t("settings.username") }}</th> <th>{{ t("settings.username") }}</th>
<th>{{ $t("settings.admin") }}</th> <th>{{ t("settings.admin") }}</th>
<th>{{ $t("settings.scope") }}</th> <th>{{ t("settings.scope") }}</th>
<th></th> <th></th>
</tr> </tr>
@ -41,36 +41,28 @@
</div> </div>
</template> </template>
<script> <script setup lang="ts">
import { mapWritableState } from "pinia";
import { useLayoutStore } from "@/stores/layout"; import { useLayoutStore } from "@/stores/layout";
import { users as api } from "@/api"; import { users as api } from "@/api";
import Errors from "@/views/Errors.vue"; import Errors from "@/views/Errors.vue";
import { onMounted, ref } from "vue";
import { useI18n } from "vue-i18n";
export default { const error = ref<any>(null);
name: "users", const users = ref<IUser[]>([]);
components: {
Errors,
},
data: function () {
return {
error: null,
users: [],
};
},
async created() {
this.loading = true;
try { const layoutStore = useLayoutStore();
this.users = await api.getAll(); const { t } = useI18n();
} catch (e) {
this.error = e; onMounted(async () => {
} finally { layoutStore.loading = true;
this.loading = false;
} try {
}, users.value = await api.getAll();
computed: { } catch (e: any) {
...mapWritableState(useLayoutStore, ["loading"]), error.value = e;
}, } finally {
}; layoutStore.loading = false;
}
});
</script> </script>