Merge pull request #1007 from dataease/pr@dev@feat_basic_setting

feat: 增加超时时间配置
This commit is contained in:
fit2cloud-chenyw
2021-10-22 15:08:41 +08:00
committed by GitHub
16 changed files with 356 additions and 43 deletions

View File

@@ -5,11 +5,12 @@
</template>
<script>
export default {
name: 'App',
beforeCreate() {
// document.body.className = 'blackTheme'
}
}
</script>

View File

@@ -0,0 +1,19 @@
import request from '@/utils/request'
export function basicInfo() {
return request({
url: '/system/basic/info',
method: 'get',
loading: true
})
}
export function updateInfo(data) {
return request({
url: '/system/edit/basic',
method: 'post',
loading: true,
data
})
}

View File

@@ -606,6 +606,11 @@ export default {
mailbox_service_settings: 'Mail Settings',
test_connection: 'Test connection',
SMTP_host: 'SMTP Host',
basic_setting: 'Basic setting',
front_time_out: 'Request timeOut(unit: second, Attention: Refresh browser takes effect after saving)',
msg_time_out: 'Message retention time(unit: day)',
empty_front: 'If empty then default value is 10s',
empty_msg: 'If empty then default value is 30 days',
SMTP_port: 'SMTP Port',
SMTP_account: 'SMTP Account',
SMTP_password: 'SMTP Password',

View File

@@ -608,6 +608,11 @@ export default {
mailbox_service_settings: '郵件設置',
test_connection: '測試連接',
SMTP_host: 'SMTP主機',
basic_setting: '基礎設置',
front_time_out: '請求超時時間(單位:秒, 注意:保存後刷新瀏覽器生效)',
msg_time_out: '消息保留時間(單位:天)',
empty_front: '為空則默認取值10秒',
empty_msg: '為空則默認取值30天',
SMTP_port: 'SMTP端口',
SMTP_account: 'SMTP賬戶',
SMTP_password: 'SMTP密碼',

View File

@@ -608,6 +608,13 @@ export default {
mailbox_service_settings: '邮件设置',
test_connection: '测试连接',
SMTP_host: 'SMTP主机',
basic_setting: '基础设置',
front_time_out: '请求超时时间(单位:秒, 注意:保存后刷新浏览器生效)',
msg_time_out: '消息保留时间(单位:天)',
empty_front: '为空则默认取10秒',
empty_msg: '为空则默认取30天',
front_error: '请填写0-100正整数',
msg_error: '请填写正整数',
SMTP_port: 'SMTP端口',
SMTP_account: 'SMTP账户',
SMTP_password: 'SMTP密码',
@@ -1500,7 +1507,8 @@ export default {
i18n_msg_type_dataset_sync_faild: '数据集同步失败',
i18n_msg_type_ds_invalid: '数据源失效',
i18n_msg_type_all: '全部类型',
channel_inner_msg: '站内消息'
channel_inner_msg: '站内消息',
channel_email_msg: '邮件'
},
denumberrange: {
label: '数值区间',

View File

@@ -48,3 +48,8 @@ export function getSysUI() {
return json ? JSON.parse(json) : null
}
export function getTimeOut() {
const val = Cookies.get('request-time-out')
return val
}

View File

@@ -12,11 +12,42 @@ import { getLinkToken, setLinkToken } from '@/utils/auth'
const TokenKey = Config.TokenKey
const RefreshTokenKey = Config.RefreshTokenKey
const LinkTokenKey = Config.LinkTokenKey
import Cookies from 'js-cookie'
// create an axios instance
const service = axios.create({
const getTimeOut = () => {
let time = 10
const url = '/system/requestTimeOut'
const xhr = new XMLHttpRequest()
xhr.onreadystatechange = () => {
if (xhr.readyState === 4 && xhr.status === 200) {
if (xhr.responseText) {
try {
const response = JSON.parse(xhr.responseText)
if (response.success) {
Cookies.set('request-time-out', response.data)
time = response.data
} else {
$error('系统异常,请联系管理员')
}
} catch (e) {
$error('系统异常,请联系管理员')
}
} else {
$error('网络异常,请联系网管')
}
}
}
xhr.open('get', url, false)
xhr.send()
return time
}
const time = getTimeOut()
let service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
// withCredentials: true, // send cookies when cross-domain requests
timeout: 10000 // request timeout
timeout: time ? time * 1000 : 10000
})
// request interceptor
@@ -60,13 +91,36 @@ service.interceptors.request.use(
}
)
// const defaultOptions = {
// confirmButtonText: i18n.t('login.re_login')
// }
service.setTimeOut = time => {
service = axios.create({
baseURL: process.env.VUE_APP_BASE_API,
timeout: time
})
}
// 请根据实际需求修改
service.interceptors.response.use(response => {
response.config.loading && tryHideLoading(store.getters.currentPath)
checkAuth(response)
return response.data
}, error => {
const config = error.response && error.response.config || error.config
const headers = error.response && error.response.headers || error.response || config.headers
config.loading && tryHideLoading(store.getters.currentPath)
let msg
if (error.response) {
checkAuth(error.response)
// checkPermission(error.response)
msg = error.response.data.message || error.response.data
} else {
msg = error.message
}
!config.hideMsg && (!headers['authentication-status']) && $error(msg)
return Promise.reject(error)
})
const checkAuth = response => {
// 请根据实际需求修改
if (response.headers['authentication-status'] === 'login_expire') {
const message = i18n.t('login.expires')
// store.dispatch('user/setLoginMsg', message)
@@ -103,31 +157,5 @@ const checkAuth = response => {
setLinkToken(linkToken)
store.dispatch('user/setLinkToken', linkToken)
}
// 许可状态改变 刷新页面
// if (response.headers['lic-status']) {
// location.reload()
// }
}
// 请根据实际需求修改
service.interceptors.response.use(response => {
response.config.loading && tryHideLoading(store.getters.currentPath)
checkAuth(response)
return response.data
}, error => {
const config = error.response && error.response.config || error.config
const headers = error.response && error.response.headers || error.response || config.headers
config.loading && tryHideLoading(store.getters.currentPath)
let msg
if (error.response) {
checkAuth(error.response)
// checkPermission(error.response)
msg = error.response.data.message || error.response.data
} else {
msg = error.message
}
!config.hideMsg && (!headers['authentication-status']) && $error(msg)
return Promise.reject(error)
})
export default service

View File

@@ -0,0 +1,144 @@
<template>
<div>
<!--基础配置表单-->
<el-form
ref="formInline"
v-loading="loading"
:model="formInline"
:rules="rules"
class="demo-form-inline"
:disabled="show"
size="small"
>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.front_time_out')" prop="frontTimeOut">
<el-input
v-model="formInline.frontTimeOut"
:placeholder="$t('system_parameter_setting.empty_front')"
/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item :label="$t('system_parameter_setting.msg_time_out')" prop="msgTimeOut">
<el-input
v-model="formInline.msgTimeOut"
:placeholder="$t('system_parameter_setting.empty_msg')"
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div>
<el-button v-if="showEdit" size="small" @click="edit">{{ $t('commons.edit') }}</el-button>
<el-button v-if="showSave" type="success" :disabled="disabledSave" size="small" @click="save('formInline')">
{{ $t('commons.save') }}
</el-button>
<el-button v-if="showCancel" type="info" size="small" @click="cancel">{{ $t('commons.cancel') }}</el-button>
</div>
</div>
</template>
<script>
import { basicInfo, updateInfo } from '@/api/system/basic'
export default {
name: 'EmailSetting',
data() {
return {
formInline: {},
input: '',
visible: true,
showEdit: true,
showSave: false,
showCancel: false,
show: true,
disabledSave: false,
loading: false,
rules: {
frontTimeOut: [
{
pattern: '^([0-9]{1,2}|100)$',
message: this.$t('system_parameter_setting.front_error'),
trigger: 'blur'
}
],
msgTimeOut: [
{
pattern: '^[0-9]*$',
message: this.$t('system_parameter_setting.msg_error'),
trigger: 'blur'
}
]
}
}
},
created() {
this.query()
},
methods: {
query() {
basicInfo().then(response => {
this.formInline = response.data
this.$nextTick(() => {
this.$refs.formInline.clearValidate()
})
})
},
edit() {
this.showEdit = false
this.showSave = true
this.showCancel = true
this.show = false
},
save(formInline) {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
const param = [
{ paramKey: 'basic.frontTimeOut', paramValue: this.formInline.frontTimeOut, type: 'text', sort: 1 },
{ paramKey: 'basic.msgTimeOut', paramValue: this.formInline.msgTimeOut, type: 'text', sort: 2 }
]
this.$refs[formInline].validate(valid => {
if (valid) {
updateInfo(param).then(response => {
const flag = response.success
if (flag) {
this.$success(this.$t('commons.save_success'))
window.location.reload()
} else {
this.$message.error(this.$t('commons.save_failed'))
}
})
} else {
// this.result = false
}
})
},
cancel() {
this.showEdit = true
this.showCancel = false
this.showSave = false
this.show = true
this.query()
}
}
}
</script>
<style scoped>
</style>

View File

@@ -2,6 +2,10 @@
<layout-content v-loading="$store.getters.loadingMap[$store.getters.currentPath]">
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.basic_setting')" name="zero">
<basic-setting />
</el-tab-pane>
<el-tab-pane :lazy="true" :label="$t('system_parameter_setting.mailbox_service_settings')" name="first">
<email-setting />
</el-tab-pane>
@@ -22,17 +26,17 @@
</layout-content>
</template>
<script>
import BasicSetting from './BasicSetting'
import EmailSetting from './EmailSetting'
import LayoutContent from '@/components/business/LayoutContent'
import PluginCom from '@/views/system/plugin/PluginCom'
import { pluginLoaded } from '@/api/user'
export default {
components: { EmailSetting, LayoutContent, PluginCom },
components: { BasicSetting, EmailSetting, LayoutContent, PluginCom },
data() {
return {
activeName: 'first',
activeName: 'zero',
isPluginLoaded: false
}
},