Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
async function logout () {
// 删除cookie
util.cookies.remove('token')
util.cookies.remove('uuid')
// 清空 vuex 用户信息
await dispatch('d2admin/user/set', {}, { root: true })
// 跳转路由
router.push({
name: 'login'
})
}
// 判断是否需要确认
if (confirm) {
commit('d2admin/gray/set', true, { root: true })
MessageBox.confirm('确定要注销当前用户吗', '注销用户', {
type: 'warning'
})
.then(() => {
commit('d2admin/gray/set', false, { root: true })
logout()
})
.catch(() => {
commit('d2admin/gray/set', false, { root: true })
Message({
message: '取消注销操作'
})
})
} else {
logout()
}
},
response => {
const res = response.data;
console.log("res=="+JSON.stringify(res));
// if the custom code is not 20000, it is judged as an error.
if (res.errno !== 0) {
Message({
message: res.errmsg || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 501) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.errmsg || 'Error'))
} else {
return res
}
},
error => {
response => {
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.code !== 200) {
Message({
message: res.message || 'Error',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014 || res.code === 401) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return Promise.reject(new Error(res.message || 'Error'))
} else {
return res
}
},
error => {
response => {
tryHideFullScreenLoading()
const res = response.data
// if the custom code is not 20000, it is judged as an error.
if (res.code !== 20000) {
Message({
message: res.message || '获取数据失败,请检查请求',
type: 'error',
duration: 5 * 1000
})
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
// to re-login
MessageBox.confirm('You have been logged out, you can cancel to stay on this page, or log in again', 'Confirm logout', {
confirmButtonText: 'Re-Login',
cancelButtonText: 'Cancel',
type: 'warning'
}).then(() => {
store.dispatch('user/resetToken').then(() => {
location.reload()
})
})
}
return res.message || '获取数据失败,请检查请求'
} else {
return res
}
},
error => {
checkOutSave (row) {
if (!this.$refs.elxEditable.checkValid().error) {
if (row.id === '-') {
this.isClearActiveFlag = false
MessageBox.confirm('该数据未保存,请确认操作?', '温馨提示', {
distinguishCancelAndClose: true,
confirmButtonText: '保存数据',
cancelButtonText: '移除数据',
type: 'warning'
}).then(action => {
this.$refs.elxEditable.clearActive()
this.saveRowEvent(row)
}).catch(action => {
if (action === 'cancel') {
this.$refs.elxEditable.remove(row)
// 由于 ElementUI 树表格不支持双向数据导致 remove 后界面无法响应,可以通过调用 refresh 刷新表格
this.$refs.elxEditable.refresh()
}
}).then(() => {
this.isClearActiveFlag = true
})
deleteSelectedEvent () {
let removeRecords = this.$refs.elxEditable.getSelecteds()
if (removeRecords.length) {
MessageBox.confirm('确定删除所选数据?', '温馨提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.loading = true
XEAjax.doPost('/api/file/save', { removeRecords }).then(({ data }) => {
Message({
type: 'success',
message: '删除成功!'
})
this.findList()
}).catch(e => {
this.loading = false
})
}).catch(e => e)
} else {
removeEvent (row) {
if (row.id) {
this.isClearActiveFlag = false
MessageBox.confirm('确定永久删除该数据?', '温馨提示', {
distinguishCancelAndClose: true,
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
XEAjax.doDelete(`/api/role/delete/${row.id}`).then(({ data }) => {
this.findList()
}).catch(e => {
this.loading = false
})
}).catch(action => action).then(() => {
this.isClearActiveFlag = true
})
} else {
this.$refs.elxEditable.remove(row)
}
cancelRowEvent (row) {
if (!row.id) {
MessageBox.confirm('该数据未保存,是否移除?', '温馨提示', {
distinguishCancelAndClose: true,
confirmButtonText: '移除数据',
cancelButtonText: '返回继续',
type: 'warning'
}).then(action => {
if (action === 'confirm') {
this.$refs.elxEditable.remove(row)
}
})
} else if (this.$refs.elxEditable.hasRowChange(row)) {
MessageBox.confirm('检测到未保存的内容,是否取消修改?', '温馨提示', {
distinguishCancelAndClose: true,
confirmButtonText: '取消修改',
cancelButtonText: '返回继续',
type: 'warning'
}).then(action => {
this.$refs.elxEditable.clearActive()
this.$refs.elxEditable.revert(row)
}).catch(action => {
if (action === 'cancel') {
this.$refs.elxEditable.setActiveRow(row)
}
})
} else {
this.$refs.elxEditable.clearActive()
}
},
checkOutSave (row) {
if (!row.id) {
this.isClearActiveFlag = false
MessageBox.confirm('该数据未保存,请确认操作?', '温馨提示', {
distinguishCancelAndClose: true,
confirmButtonText: '保存数据',
cancelButtonText: '移除数据',
type: 'warning'
}).then(action => {
this.$refs.elxEditable.clearActive()
this.saveRowEvent(row)
}).catch(action => {
if (action === 'cancel') {
this.$refs.elxEditable.remove(row)
}
}).then(() => {
this.isClearActiveFlag = true
})
} else if (this.$refs.elxEditable.hasRowChange(row)) {
this.isClearActiveFlag = false
deleteSelectedEvent () {
let removeRecords = this.$refs.elxEditable.getSelecteds()
if (removeRecords.length) {
MessageBox.confirm('确定删除所选数据?', '温馨提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.loading = true
XEAjax.doPost('/api/user/save', { removeRecords }).then(({ data }) => {
Message({
type: 'success',
message: '删除成功!'
})
this.findList()
}).catch(e => {
this.loading = false
})
}).catch(e => e)
} else {