refactor: welcome.setup.vue to composition api

This commit is contained in:
Norm 2022-08-01 16:57:34 -04:00 committed by Gitea
parent a615a76cf1
commit 30d8bc9259

View file

@ -21,50 +21,37 @@
</form> </form>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import MkInput from '@/components/form/input.vue'; import MkInput from '@/components/form/input.vue';
import { host } from '@/config'; import { host } from '@/config';
import * as os from '@/os'; import * as os from '@/os';
import { login } from '@/account'; import { login } from '@/account';
import { i18n } from '@/i18n';
export default defineComponent({ let username = $ref('');
components: { let password = $ref('');
MkButton, let submitting = $ref(false);
MkInput,
},
data() { function submit(): void {
return { if (submitting) return;
username: '', submitting = true;
password: '',
submitting: false,
host,
};
},
methods: {
submit() {
if (this.submitting) return;
this.submitting = true;
os.api('admin/accounts/create', { os.api('admin/accounts/create', {
username: this.username, username,
password: this.password, password,
}).then(res => { }).then(res => {
return login(res.token); return login(res.token);
}).catch(() => { }).catch(() => {
this.submitting = false; submitting = false;
os.alert({ os.alert({
type: 'error', type: 'error',
text: this.$ts.somethingHappened text: i18n.ts.somethingHappened,
}); });
}); });
} }
}
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>