refs #3301 Rewrite Authorize with composition API
This commit is contained in:
parent
875d7dbde2
commit
b1d507a1e1
|
@ -5,7 +5,7 @@
|
||||||
<el-row>
|
<el-row>
|
||||||
<el-col :span="24" class="close">
|
<el-col :span="24" class="close">
|
||||||
<el-button type="text" @click="close" class="close-button">
|
<el-button type="text" @click="close" class="close-button">
|
||||||
<font-awesome-icon icon="x-mark"></font-awesome-icon>
|
<font-awesome-icon icon="xmark"></font-awesome-icon>
|
||||||
</el-button>
|
</el-button>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
@ -43,16 +43,15 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts">
|
||||||
export default {
|
import { defineComponent, ref, reactive, toRefs, onMounted } from 'vue'
|
||||||
data() {
|
import { useRouter } from 'vue-router'
|
||||||
return {
|
import { useI18next } from 'vue3-i18next'
|
||||||
authorizeForm: {
|
import { ElMessage } from 'element-plus'
|
||||||
code: null
|
import { useStore } from '@/store'
|
||||||
},
|
import { ACTION_TYPES } from '@/store/Authorize'
|
||||||
submitting: false
|
|
||||||
}
|
export default defineComponent({
|
||||||
},
|
|
||||||
name: 'authorize',
|
name: 'authorize',
|
||||||
props: {
|
props: {
|
||||||
url: {
|
url: {
|
||||||
|
@ -64,42 +63,63 @@ export default {
|
||||||
default: 'mastodon'
|
default: 'mastodon'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
setup(props) {
|
||||||
console.log(this.url)
|
const space = 'Authorize'
|
||||||
},
|
const store = useStore()
|
||||||
methods: {
|
const router = useRouter()
|
||||||
authorizeSubmit() {
|
const i18n = useI18next()
|
||||||
this.submitting = true
|
|
||||||
this.$store
|
const { url, sns } = toRefs(props)
|
||||||
.dispatch('Authorize/submit', {
|
|
||||||
code: this.authorizeForm.code,
|
const authorizeForm = reactive({
|
||||||
sns: this.sns
|
code: null
|
||||||
|
})
|
||||||
|
const submitting = ref<boolean>(false)
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
console.log(url.value)
|
||||||
|
})
|
||||||
|
|
||||||
|
const authorizeSubmit = () => {
|
||||||
|
submitting.value = true
|
||||||
|
store
|
||||||
|
.dispatch(`${space}/${ACTION_TYPES.SUBMIT}`, {
|
||||||
|
code: authorizeForm.code,
|
||||||
|
sns: sns.value
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.submitting = false
|
submitting.value = false
|
||||||
})
|
})
|
||||||
.then(id => {
|
.then(id => {
|
||||||
this.$router.push({ path: `/${id}/home` })
|
router.push({ path: `/${id}/home` })
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
if (err.name === 'DuplicateRecordError') {
|
if (err.name === 'DuplicateRecordError') {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.authorize_duplicate_error'),
|
message: i18n.t('message.authorize_duplicate_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
this.$message({
|
ElMessage({
|
||||||
message: this.$t('message.authorize_error'),
|
message: i18n.t('message.authorize_error'),
|
||||||
type: 'error'
|
type: 'error'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
}
|
||||||
close() {
|
|
||||||
return this.$router.push({ path: '/', query: { redirect: 'home' } })
|
const close = () => {
|
||||||
|
router.push({ path: '/', query: { redirect: 'home' } })
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
authorizeForm,
|
||||||
|
submitting,
|
||||||
|
authorizeSubmit,
|
||||||
|
close
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|
|
@ -2,14 +2,18 @@ import { Module, ActionTree } from 'vuex'
|
||||||
import { RootState } from '@/store'
|
import { RootState } from '@/store'
|
||||||
import { MyWindow } from '~/src/types/global'
|
import { MyWindow } from '~/src/types/global'
|
||||||
|
|
||||||
const win = (window as any) as MyWindow
|
const win = window as any as MyWindow
|
||||||
|
|
||||||
export type AuthorizeState = {}
|
export type AuthorizeState = {}
|
||||||
|
|
||||||
const state = (): AuthorizeState => ({})
|
const state = (): AuthorizeState => ({})
|
||||||
|
|
||||||
|
export const ACTION_TYPES = {
|
||||||
|
SUBMIT: 'submit'
|
||||||
|
}
|
||||||
|
|
||||||
const actions: ActionTree<AuthorizeState, RootState> = {
|
const actions: ActionTree<AuthorizeState, RootState> = {
|
||||||
submit: async (_, request: { code: string | null; sns: 'mastodon' | 'pleroma' | 'misskey' }): Promise<string> => {
|
[ACTION_TYPES.SUBMIT]: async (_, request: { code: string | null; sns: 'mastodon' | 'pleroma' | 'misskey' }): Promise<string> => {
|
||||||
let req = {
|
let req = {
|
||||||
sns: request.sns
|
sns: request.sns
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue