fix: select2添加axios参数无权限时不弹出提示

This commit is contained in:
“huailei000” 2022-03-09 21:21:09 +08:00 committed by 老广
parent 2b984cb456
commit 1bf3371a00
3 changed files with 41 additions and 9 deletions

View File

@ -88,6 +88,7 @@ export default {
} }
}, },
data() { data() {
const vm = this
const defaultPageSize = 10 const defaultPageSize = 10
const defaultParams = { const defaultParams = {
search: '', search: '',
@ -95,7 +96,18 @@ export default {
hasMore: true, hasMore: true,
pageSize: defaultPageSize pageSize: defaultPageSize
} }
// axios
const validateStatus = (status) => {
if (status === 403) {
setTimeout(() => {
vm.initialized = true
}, 300)
return 200
}
return status
}
return { return {
validateStatus,
loading: false, loading: false,
initialized: false, initialized: false,
defaultParams: _.cloneDeep(defaultParams), defaultParams: _.cloneDeep(defaultParams),
@ -150,7 +162,7 @@ export default {
results = data results = data
total = data.length total = data.length
} else if (typeof data === 'object') { } else if (typeof data === 'object') {
results = data.results results = data?.results || []
more = !!data.next more = !!data.next
total = data.count total = data.count
} }
@ -163,7 +175,8 @@ export default {
pageSize: defaultPageSize, pageSize: defaultPageSize,
makeParams: defaultMakeParams, makeParams: defaultMakeParams,
transformOption: defaultTransformOption, transformOption: defaultTransformOption,
processResults: defaultProcessResults processResults: defaultProcessResults,
validateStatus: this.validateStatus
} }
return Object.assign(defaultAjax, this.ajax, this.url ? { url: this.url } : {}) return Object.assign(defaultAjax, this.ajax, this.url ? { url: this.url } : {})
} }
@ -231,9 +244,13 @@ export default {
this.getOptions() this.getOptions()
}, },
async getInitialOptions() { async getInitialOptions() {
const { url, processResults, validateStatus } = this.iAjax
const params = this.safeMakeParams(this.params) const params = this.safeMakeParams(this.params)
let data = await this.$axios.get(this.iAjax.url, { params: params }) let data = await this.$axios.get(url, {
data = this.iAjax.processResults.bind(this)(data) params,
validateStatus
})
data = processResults.bind(this)(data)
data.results.forEach((v) => { data.results.forEach((v) => {
this.initialOptions.push(v) this.initialOptions.push(v)
if (this.optionsValues.indexOf(v.value) === -1) { if (this.optionsValues.indexOf(v.value) === -1) {
@ -251,9 +268,13 @@ export default {
} }
}, },
async getOptions() { async getOptions() {
const { url, processResults, validateStatus } = this.iAjax
const params = this.safeMakeParams(this.params) const params = this.safeMakeParams(this.params)
const resp = await this.$axios.get(this.iAjax.url, { params: params }) const resp = await this.$axios.get(url, {
const data = this.iAjax.processResults.bind(this)(resp) params,
validateStatus
})
const data = processResults.bind(this)(resp)
if (!data.pagination) { if (!data.pagination) {
this.params.hasMore = false this.params.hasMore = false
} }

View File

@ -217,9 +217,17 @@ export default {
async loadHasObjects() { async loadHasObjects() {
this.$log.debug('Start loadHasObject: ', this.params) this.$log.debug('Start loadHasObject: ', this.params)
const params = this.safeMakeParams(this.params) const params = this.safeMakeParams(this.params)
let data = await this.$axios.get(this.iAjax.url, { params: params }) let data = await this.$axios.get(this.iAjax.url, {
params: params,
validateStatus: (status) => {
if (status === 403) {
return 200
}
return status
}
})
data = this.iAjax.processResults.bind(this)(data) data = this.iAjax.processResults.bind(this)(data)
data.results.forEach((v) => { data.results && data.results.forEach((v) => {
if (!this.hasObjects.find((item) => item.value === v.value)) { if (!this.hasObjects.find((item) => item.value === v.value)) {
this.iHasObjects.push(v) this.iHasObjects.push(v)
} }

View File

@ -81,7 +81,10 @@ export default {
hasRefresh: true, hasRefresh: true,
hasSearch: true, hasSearch: true,
hasMoreActions: false, hasMoreActions: false,
createRoute: 'CommandFilterCreate' createRoute: 'CommandFilterCreate',
canCreate: () => {
return this.$hasPerm('assets.add_commandfilter')
}
} }
} }
}, },