refactor: welcome.setup.vue to composition api
This commit is contained in:
parent
a615a76cf1
commit
30d8bc9259
1 changed files with 22 additions and 35 deletions
|
@ -21,50 +21,37 @@
|
|||
</form>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
<script lang="ts" setup>
|
||||
import { } from 'vue';
|
||||
import MkButton from '@/components/ui/button.vue';
|
||||
import MkInput from '@/components/form/input.vue';
|
||||
import { host } from '@/config';
|
||||
import * as os from '@/os';
|
||||
import { login } from '@/account';
|
||||
import { i18n } from '@/i18n';
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
MkButton,
|
||||
MkInput,
|
||||
},
|
||||
let username = $ref('');
|
||||
let password = $ref('');
|
||||
let submitting = $ref(false);
|
||||
|
||||
data() {
|
||||
return {
|
||||
username: '',
|
||||
password: '',
|
||||
submitting: false,
|
||||
host,
|
||||
};
|
||||
},
|
||||
function submit(): void {
|
||||
if (submitting) return;
|
||||
submitting = true;
|
||||
|
||||
methods: {
|
||||
submit() {
|
||||
if (this.submitting) return;
|
||||
this.submitting = true;
|
||||
os.api('admin/accounts/create', {
|
||||
username,
|
||||
password,
|
||||
}).then(res => {
|
||||
return login(res.token);
|
||||
}).catch(() => {
|
||||
submitting = false;
|
||||
|
||||
os.api('admin/accounts/create', {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
}).then(res => {
|
||||
return login(res.token);
|
||||
}).catch(() => {
|
||||
this.submitting = false;
|
||||
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: this.$ts.somethingHappened
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
os.alert({
|
||||
type: 'error',
|
||||
text: i18n.ts.somethingHappened,
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
|
Loading…
Reference in a new issue