mirror of
https://example.com
synced 2024-11-24 06:56:41 +09: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,
|
||||
},
|
||||
|
||||
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
|
||||
}
|
||||
},
|
||||
|
||||
emits: ['done', 'closed'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
name: this.initialName,
|
||||
permissions: {},
|
||||
kinds: permissions
|
||||
};
|
||||
},
|
||||
|
||||
created() {
|
||||
if (this.initialPermissions) {
|
||||
for (const kind of this.initialPermissions) {
|
||||
this.permissions[kind] = true;
|
||||
}
|
||||
} else {
|
||||
for (const kind of this.kinds) {
|
||||
this.permissions[kind] = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
ok() {
|
||||
this.$emit('done', {
|
||||
name: this.name,
|
||||
permissions: Object.keys(this.permissions).filter(p => this.permissions[p])
|
||||
});
|
||||
this.$refs.dialog.close();
|
||||
},
|
||||
|
||||
disableAll() {
|
||||
for (const p in this.permissions) {
|
||||
this.permissions[p] = false;
|
||||
}
|
||||
},
|
||||
|
||||
enableAll() {
|
||||
for (const p in this.permissions) {
|
||||
this.permissions[p] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
const props = withDefaults(defineProps<{
|
||||
title?: string | null;
|
||||
information?: string | null;
|
||||
initialName?: string | null;
|
||||
initialPermissions?: string[] | null;
|
||||
}>(), {
|
||||
title: null,
|
||||
information: null,
|
||||
initialName: null,
|
||||
initialPermissions: null,
|
||||
});
|
||||
|
||||
const emit = defineEmits<{
|
||||
(ev: 'closed'): void;
|
||||
(ev: 'done', result: { name: string | null, permissions: string[] }): void;
|
||||
}>();
|
||||
|
||||
const dialog = $ref<InstanceType<typeof XModalWindow>>();
|
||||
let name = $ref(props.initialName);
|
||||
let permissions = $ref({});
|
||||
|
||||
if (props.initialPermissions) {
|
||||
for (const kind of props.initialPermissions) {
|
||||
permissions[kind] = true;
|
||||
}
|
||||
} else {
|
||||
for (const kind of kinds) {
|
||||
permissions[kind] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function ok(): void {
|
||||
emit('done', {
|
||||
name: name,
|
||||
permissions: Object.keys(permissions).filter(p => permissions[p]),
|
||||
});
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
function disableAll(): void {
|
||||
for (const p in permissions) {
|
||||
permissions[p] = false;
|
||||
}
|
||||
}
|
||||
|
||||
function enableAll(): void {
|
||||
for (const p in permissions) {
|
||||
permissions[p] = true;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue