refactor pages/miauth.vue to composition API

This commit is contained in:
Johann150 2022-08-01 21:18:46 +02:00
parent 751921e24f
commit bcb07d819f
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -36,52 +36,46 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent } from 'vue'; import { } from 'vue';
import MkSignin from '@/components/signin.vue'; import MkSignin from '@/components/signin.vue';
import MkButton from '@/components/ui/button.vue'; import MkButton from '@/components/ui/button.vue';
import * as os from '@/os'; import * as os from '@/os';
import { login } from '@/account'; import { login } from '@/account';
import { appendQuery, query } from '@/scripts/url'; import { appendQuery, query } from '@/scripts/url';
export default defineComponent({ const props = defineProps<{
components: { session: string;
MkSignin, callback: string;
MkButton, name: string;
}, icon: string;
props: ['session', 'callback', 'name', 'icon', 'permission'], permission: string;
data() { }>();
return {
state: null,
};
},
methods: {
async accept() {
this.state = 'waiting';
await os.api('miauth/gen-token', {
session: this.session,
name: this.name,
iconUrl: this.icon,
permission: this.permission,
});
this.state = 'accepted'; let state: 'waiting' | 'denied' | 'accepted' | 'initial' = $ref('initial');
if (this.callback) {
location.href = appendQuery(this.callback, query({ async function accept() {
session: this.session, state = 'waiting';
})); await os.api('miauth/gen-token', {
} session: props.session,
}, name: props.name,
deny() { iconUrl: props.icon,
this.state = 'denied'; permission: props.permission,
}, });
onLogin(res) {
login(res.i); state = 'accepted';
}, if (props.callback) {
}, location.href = appendQuery(props.callback, query({
}); session: props.session,
}));
}
}
function deny() {
state = 'denied';
}
function onLogin(res) {
login(res.i);
}
</script> </script>
<style lang="scss" scoped>
</style>