refactor(frontend): use composition api
This commit is contained in:
parent
3d4a90b08a
commit
0717afc312
8 changed files with 495 additions and 621 deletions
|
@ -54,8 +54,8 @@
|
|||
</MkModalWindow>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { reactive, shallowRef } from 'vue';
|
||||
import MkInput from './MkInput.vue';
|
||||
import MkTextarea from './MkTextarea.vue';
|
||||
import MkSwitch from './MkSwitch.vue';
|
||||
|
@ -66,58 +66,36 @@ import MkRadios from './MkRadios.vue';
|
|||
import MkModalWindow from '@/components/MkModalWindow.vue';
|
||||
import { i18n } from '@/i18n';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkModalWindow,
|
||||
MkInput,
|
||||
MkTextarea,
|
||||
MkSwitch,
|
||||
MkSelect,
|
||||
MkRange,
|
||||
MkButton,
|
||||
MkRadios,
|
||||
},
|
||||
const props = defineProps<{
|
||||
title: string;
|
||||
form: any;
|
||||
}>();
|
||||
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
form: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
const emit = defineEmits<{
|
||||
(ev: 'done', v: {
|
||||
canceled?: boolean;
|
||||
result?: any;
|
||||
}): void;
|
||||
}>();
|
||||
|
||||
emits: ['done'],
|
||||
const dialog = shallowRef<InstanceType<typeof MkModalWindow>>();
|
||||
const values = reactive({});
|
||||
|
||||
data() {
|
||||
return {
|
||||
values: {},
|
||||
i18n,
|
||||
};
|
||||
},
|
||||
for (const item in props.form) {
|
||||
values[item] = props.form[item].default ?? null;
|
||||
}
|
||||
|
||||
created() {
|
||||
for (const item in this.form) {
|
||||
this.values[item] = this.form[item].default ?? null;
|
||||
}
|
||||
},
|
||||
function ok() {
|
||||
emit('done', {
|
||||
result: values,
|
||||
});
|
||||
dialog.value.close();
|
||||
}
|
||||
|
||||
methods: {
|
||||
ok() {
|
||||
this.$emit('done', {
|
||||
result: this.values,
|
||||
});
|
||||
this.$refs.dialog.close();
|
||||
},
|
||||
|
||||
cancel() {
|
||||
this.$emit('done', {
|
||||
canceled: true,
|
||||
});
|
||||
this.$refs.dialog.close();
|
||||
},
|
||||
},
|
||||
});
|
||||
function cancel() {
|
||||
emit('done', {
|
||||
canceled: true,
|
||||
});
|
||||
dialog.value.close();
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue