perf: 重构用户确认

This commit is contained in:
ibuler
2023-10-12 13:57:41 +08:00
parent 4eb61373e0
commit 50a9ce35ad
5 changed files with 25 additions and 2 deletions

View File

@@ -19,6 +19,7 @@ export const attrMatchOptions = [
{ label: i18n.t('common.Endswith'), value: 'endswith' },
{ label: i18n.t('common.Regex'), value: 'regex' },
{ label: i18n.t('common.BelongTo'), value: 'm2m' },
{ label: i18n.t('common.BelongToAll'), value: 'm2m_all' },
{ label: i18n.t('common.IPMatch'), value: 'ip_in' },
{ label: i18n.t('common.GreatEqualThan'), value: 'gte' },
{ label: i18n.t('common.LessEqualThan'), value: 'lte' }

View File

@@ -15,16 +15,19 @@
</el-alert>
<slot />
</PageContent>
<UserConfirmDialog v-if="showConfirmDialog" :handler="testIt" />
</div>
</template>
<script>
import PageHeading from './PageHeading'
import PageContent from './PageContent'
import UserConfirmDialog from '@/components/Apps/UserConfirmDialog/index.vue'
export default {
name: 'Page',
components: {
UserConfirmDialog,
PageHeading,
PageContent
},
@@ -53,11 +56,17 @@ export default {
return true
}
return window.history.length <= 2
},
showConfirmDialog() {
return this.$store.state.common.confirmDialogVisible
}
},
methods: {
handleGoBack() {
this.goBack.bind(this)()
},
testIt() {
return this.$axios.post('/api/v1/authentication/access-keys/')
}
}
}

View File

@@ -5,7 +5,8 @@ const getDefaultState = () => {
metaMap: {},
metaPromiseMap: {},
isRouterAlive: true,
sqlQueryCounter: []
sqlQueryCounter: [],
confirmDialogVisible: false
}
}
@@ -27,6 +28,9 @@ const mutations = {
if (state.sqlQueryCounter.length > 10) {
state.sqlQueryCounter.shift()
}
},
setConfirmDialogVisible: (state, show) => {
state.confirmDialogVisible = show
}
}
@@ -74,6 +78,9 @@ const actions = {
return
}
commit('addSQLQueryCounter', { url, count: sqlCount })
},
showConfirmDialog({ commit, state }, show) {
commit('setConfirmDialogVisible', show)
}
}

View File

@@ -76,6 +76,10 @@ function ifUnauthorized({ response, error }) {
}
}
function ifConfirmRequired({ response, error }) {
}
function ifBadRequest({ response, error }) {
if (response.status === 400) {
if (response.data?.detail) {
@@ -151,6 +155,7 @@ service.interceptors.response.use(
const response = error.response
ifUnauthorized({ response, error })
ifBadRequest({ response, error })
ifConfirmRequired({ response, error })
flashErrorMsg({ response, error })
return Promise.reject(error)
}

View File

@@ -105,7 +105,8 @@ export default {
type: 'primary',
can: () => this.$hasPerm('authentication.add_passkey'),
callback: function() {
this.dialogVisible = true
this.$store.dispatch('common/showConfirmDialog', true)
// this.dialogVisible = true
}.bind(this)
}
]