mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 08:53:09 +02:00
refactor(client): use setup syntax
This commit is contained in:
parent
f337459c6e
commit
4c3d094a45
1 changed files with 56 additions and 83 deletions
|
@ -1,11 +1,12 @@
|
|||
<template>
|
||||
<XModalWindow ref="dialog"
|
||||
<XModalWindow
|
||||
ref="dialog"
|
||||
:width="400"
|
||||
:height="450"
|
||||
:with-ok-button="true"
|
||||
:ok-button-disabled="false"
|
||||
:can-close="false"
|
||||
@close="$refs.dialog.close()"
|
||||
@close="dialog.close()"
|
||||
@closed="$emit('closed')"
|
||||
@ok="ok()"
|
||||
>
|
||||
|
@ -27,91 +28,63 @@
|
|||
</XModalWindow>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { permissions } from 'misskey-js';
|
||||
import XModalWindow from '@/components/ui/modal-window.vue';
|
||||
<script lang="ts" setup>
|
||||
import { } from 'vue';
|
||||
import { permissions as kinds } from 'misskey-js';
|
||||
import MkInput from './form/input.vue';
|
||||
import MkTextarea from './form/textarea.vue';
|
||||
import MkSwitch from './form/switch.vue';
|
||||
import MkButton from './ui/button.vue';
|
||||
import MkInfo from './ui/info.vue';
|
||||
import XModalWindow from '@/components/ui/modal-window.vue';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
XModalWindow,
|
||||
MkInput,
|
||||
MkTextarea,
|
||||
MkSwitch,
|
||||
MkButton,
|
||||
MkInfo,
|
||||
},
|
||||
const props = withDefaults(defineProps<{
|
||||
title?: string | null;
|
||||
information?: string | null;
|
||||
initialName?: string | null;
|
||||
initialPermissions?: string[] | null;
|
||||
}>(), {
|
||||
title: null,
|
||||
information: null,
|
||||
initialName: null,
|
||||
initialPermissions: null,
|
||||
});
|
||||
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
information: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
initialName: {
|
||||
type: String,
|
||||
required: false,
|
||||
default: null
|
||||
},
|
||||
initialPermissions: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
const emit = defineEmits<{
|
||||
(ev: 'closed'): void;
|
||||
(ev: 'done', result: { name: string | null, permissions: string[] }): void;
|
||||
}>();
|
||||
|
||||
emits: ['done', 'closed'],
|
||||
const dialog = $ref<InstanceType<typeof XModalWindow>>();
|
||||
let name = $ref(props.initialName);
|
||||
let permissions = $ref({});
|
||||
|
||||
data() {
|
||||
return {
|
||||
name: this.initialName,
|
||||
permissions: {},
|
||||
kinds: permissions
|
||||
};
|
||||
},
|
||||
|
||||
created() {
|
||||
if (this.initialPermissions) {
|
||||
for (const kind of this.initialPermissions) {
|
||||
this.permissions[kind] = true;
|
||||
if (props.initialPermissions) {
|
||||
for (const kind of props.initialPermissions) {
|
||||
permissions[kind] = true;
|
||||
}
|
||||
} else {
|
||||
for (const kind of this.kinds) {
|
||||
this.permissions[kind] = false;
|
||||
for (const kind of kinds) {
|
||||
permissions[kind] = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
ok() {
|
||||
this.$emit('done', {
|
||||
name: this.name,
|
||||
permissions: Object.keys(this.permissions).filter(p => this.permissions[p])
|
||||
function ok(): void {
|
||||
emit('done', {
|
||||
name: name,
|
||||
permissions: Object.keys(permissions).filter(p => permissions[p]),
|
||||
});
|
||||
this.$refs.dialog.close();
|
||||
},
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
disableAll() {
|
||||
for (const p in this.permissions) {
|
||||
this.permissions[p] = false;
|
||||
function disableAll(): void {
|
||||
for (const p in permissions) {
|
||||
permissions[p] = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
enableAll() {
|
||||
for (const p in this.permissions) {
|
||||
this.permissions[p] = true;
|
||||
function enableAll(): void {
|
||||
for (const p in permissions) {
|
||||
permissions[p] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue