refactor pages/miauth.vue to composition API
This commit is contained in:
parent
751921e24f
commit
bcb07d819f
1 changed files with 35 additions and 41 deletions
|
@ -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,
|
let state: 'waiting' | 'denied' | 'accepted' | 'initial' = $ref('initial');
|
||||||
};
|
|
||||||
},
|
async function accept() {
|
||||||
methods: {
|
state = 'waiting';
|
||||||
async accept() {
|
|
||||||
this.state = 'waiting';
|
|
||||||
await os.api('miauth/gen-token', {
|
await os.api('miauth/gen-token', {
|
||||||
session: this.session,
|
session: props.session,
|
||||||
name: this.name,
|
name: props.name,
|
||||||
iconUrl: this.icon,
|
iconUrl: props.icon,
|
||||||
permission: this.permission,
|
permission: props.permission,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.state = 'accepted';
|
state = 'accepted';
|
||||||
if (this.callback) {
|
if (props.callback) {
|
||||||
location.href = appendQuery(this.callback, query({
|
location.href = appendQuery(props.callback, query({
|
||||||
session: this.session,
|
session: props.session,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
deny() {
|
|
||||||
this.state = 'denied';
|
function deny() {
|
||||||
},
|
state = 'denied';
|
||||||
onLogin(res) {
|
}
|
||||||
|
|
||||||
|
function onLogin(res) {
|
||||||
login(res.i);
|
login(res.i);
|
||||||
},
|
}
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
Loading…
Reference in a new issue