各个部分的代码测试
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import request from '@/utils/request'
|
import request from '@/utils/request'
|
||||||
|
|
||||||
// 查询参数列表
|
// 查询参数列表
|
||||||
export function listConfig(query) {
|
export function listConfig(query, requestOptions = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/config/list',
|
url: '/system/config/list',
|
||||||
method: 'get',
|
method: 'get',
|
||||||
params: query
|
params: query,
|
||||||
|
...requestOptions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,28 +19,31 @@ export function getConfig(configId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 根据参数键名查询参数值
|
// 根据参数键名查询参数值
|
||||||
export function getConfigKey(configKey) {
|
export function getConfigKey(configKey, requestOptions = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/config/configKey/' + configKey,
|
url: '/system/config/configKey/' + configKey,
|
||||||
method: 'get'
|
method: 'get',
|
||||||
|
...requestOptions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增参数配置
|
// 新增参数配置
|
||||||
export function addConfig(data) {
|
export function addConfig(data, requestOptions = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/config',
|
url: '/system/config',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: data
|
data: data,
|
||||||
|
...requestOptions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修改参数配置
|
// 修改参数配置
|
||||||
export function updateConfig(data) {
|
export function updateConfig(data, requestOptions = {}) {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/config',
|
url: '/system/config',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
data: data
|
data: data,
|
||||||
|
...requestOptions
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -802,6 +802,8 @@ export default {
|
|||||||
pageNum: 1,
|
pageNum: 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
configKey,
|
configKey,
|
||||||
|
}, {
|
||||||
|
silentError: true,
|
||||||
})
|
})
|
||||||
const rows = (res && res.rows) || []
|
const rows = (res && res.rows) || []
|
||||||
const hit = rows.find(item => item && item.configKey === configKey)
|
const hit = rows.find(item => item && item.configKey === configKey)
|
||||||
@@ -839,7 +841,6 @@ export default {
|
|||||||
this.debugLog('saveConfig-payload-too-long', { payloadLength: payload.length, persistPayload })
|
this.debugLog('saveConfig-payload-too-long', { payloadLength: payload.length, persistPayload })
|
||||||
if (this.$cache) this.$cache.local.setJSON(storageKey, persistPayload)
|
if (this.$cache) this.$cache.local.setJSON(storageKey, persistPayload)
|
||||||
this.configVisible = false
|
this.configVisible = false
|
||||||
if (this.$modal) this.$modal.msgWarning(`配置内容过多,后端参数长度上限为500,当前为${payload.length},已使用本地保存`)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -848,6 +849,8 @@ export default {
|
|||||||
const updateRes = await updateConfig({
|
const updateRes = await updateConfig({
|
||||||
...existsConfig,
|
...existsConfig,
|
||||||
configValue: payload,
|
configValue: payload,
|
||||||
|
}, {
|
||||||
|
silentError: true,
|
||||||
})
|
})
|
||||||
this.debugLog('saveConfig-updateConfig-success', { storageKey, updateRes, existsConfig })
|
this.debugLog('saveConfig-updateConfig-success', { storageKey, updateRes, existsConfig })
|
||||||
} else {
|
} else {
|
||||||
@@ -859,6 +862,8 @@ export default {
|
|||||||
configValue: payload,
|
configValue: payload,
|
||||||
configType: 'Y',
|
configType: 'Y',
|
||||||
remark: `工作台快捷入口配置(${label})`,
|
remark: `工作台快捷入口配置(${label})`,
|
||||||
|
}, {
|
||||||
|
silentError: true,
|
||||||
})
|
})
|
||||||
this.debugLog('saveConfig-addConfig-success', { storageKey, addRes })
|
this.debugLog('saveConfig-addConfig-success', { storageKey, addRes })
|
||||||
}
|
}
|
||||||
@@ -869,7 +874,6 @@ export default {
|
|||||||
this.debugLog('saveConfig-upsert-error', e)
|
this.debugLog('saveConfig-upsert-error', e)
|
||||||
if (this.$cache) this.$cache.local.setJSON(storageKey, persistPayload)
|
if (this.$cache) this.$cache.local.setJSON(storageKey, persistPayload)
|
||||||
this.configVisible = false
|
this.configVisible = false
|
||||||
if (this.$modal) this.$modal.msgWarning('保存失败,已使用本地保存')
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ service.interceptors.response.use(res => {
|
|||||||
const code = res.data.code || 200;
|
const code = res.data.code || 200;
|
||||||
// 获取错误信息
|
// 获取错误信息
|
||||||
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
const msg = errorCode[code] || res.data.msg || errorCode['default']
|
||||||
|
const silentError = !!(res.config && res.config.silentError)
|
||||||
// 二进制数据则直接返回
|
// 二进制数据则直接返回
|
||||||
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
|
||||||
return res.data
|
return res.data
|
||||||
@@ -120,13 +121,19 @@ service.interceptors.response.use(res => {
|
|||||||
}
|
}
|
||||||
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
|
||||||
} else if (code === 500) {
|
} else if (code === 500) {
|
||||||
|
if (!silentError) {
|
||||||
Message({ message: msg, type: 'error' })
|
Message({ message: msg, type: 'error' })
|
||||||
|
}
|
||||||
return Promise.reject(new Error(msg))
|
return Promise.reject(new Error(msg))
|
||||||
} else if (code === 601) {
|
} else if (code === 601) {
|
||||||
|
if (!silentError) {
|
||||||
Message({ message: msg, type: 'warning' })
|
Message({ message: msg, type: 'warning' })
|
||||||
|
}
|
||||||
return Promise.reject('error')
|
return Promise.reject('error')
|
||||||
} else if (code !== 200) {
|
} else if (code !== 200) {
|
||||||
|
if (!silentError) {
|
||||||
Notification.error({ title: msg })
|
Notification.error({ title: msg })
|
||||||
|
}
|
||||||
return Promise.reject('error')
|
return Promise.reject('error')
|
||||||
} else {
|
} else {
|
||||||
return res.data
|
return res.data
|
||||||
@@ -142,7 +149,9 @@ service.interceptors.response.use(res => {
|
|||||||
} else if (message.includes("Request failed with status code")) {
|
} else if (message.includes("Request failed with status code")) {
|
||||||
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
message = "系统接口" + message.substr(message.length - 3) + "异常";
|
||||||
}
|
}
|
||||||
|
if (!(error.config && error.config.silentError)) {
|
||||||
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
Message({ message: message, type: 'error', duration: 5 * 1000 })
|
||||||
|
}
|
||||||
return Promise.reject(error)
|
return Promise.reject(error)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user