版本2.0更新

This commit is contained in:
yunian
2022-06-20 13:38:00 +08:00
parent 34d4905010
commit 738574807a
164 changed files with 0 additions and 35631 deletions

View File

@@ -1,54 +0,0 @@
export const GetdeepObj = (obj,length=true) =>{
if (typeof obj == 'object' && !Array.isArray(obj)) {
let arr = []
for (let key in obj) {
if (obj.hasOwnProperty(key)) {
if (Array.isArray(obj[key])) {
let obj = {
value: key,
label: key,
}
if(length){
obj.children=[{
value: 'length()',
label: '长度',
valueType: 1,
}]
}else{
obj.children=[]
}
arr.push(obj)
} else if (typeof obj[key] == 'object' && obj[key] != null) {
arr.push({
value: key,
label: key,
children:GetdeepObj(obj[key],length)
})
} else {
arr.push({
value: key,
label: key,
valueType: typeof obj[key] == 'string' ? 2 : 1,
})
}
}
}
return arr
} else if (Array.isArray(obj)) {
let obj
if(length){
obj=[{
value: 'length()',
label: '长度',
valueType: 1,
}]
}else{
obj=[]
}
return obj
}
}

View File

@@ -1,20 +0,0 @@
import bus from '@/components/common/bus.js';
export default {
created(){
bus.$emit('collapseHeader',true)
},
data(){
return {
smallHeader:false
}
},
methods:{
openHeader(){
this.smallHeader = !this.smallHeader
},
mixinClose(){
this.$emit('close')
bus.$emit('collapseHeader',false)
}
}
}

View File

@@ -1,363 +0,0 @@
export default {
data() {
return {
}
},
created() {
},
computed: {
showRight() {
if (this.currid) {
return true
} else {
return false
}
},
listunfold() {
let arr = []
this.deepGetListunfold(this.list, arr)
console.log(arr)
return arr
}
},
mounted() {},
methods: {
deepGetListunfold(list, arr) {
list.forEach(value => {
arr.push(value)
if (value.children.length > 0) {
this.deepGetListunfold(value.children, arr)
}
})
},
mixnewFileSure(params) {
let is = false
let parentId = params.parentId
let tempId = this.currid
if (this.tempNewF.trim() == "") {
this.$message.error('文件夹名不能为空');
this.leftloading = false
return
}
this.tempNewF = this.tempNewF.trim()
this.deepGetCurr(parentId, this.list, (value) => {
value.children.forEach(item => {
if (item.name == params.name || item.name == params.fieldType) {
is = true
}
})
})
// 验证重名
if (is) {
this.$message.error('同一文件夹下不允许同名');
this.leftloading = false
return
}
if (params.parentId == "99999999") {
params.parentId = "0"
}
this.getData.addlist(params).then((res) => {
if (res.status === "1") {
this.$message({
message: '添加成功',
type: 'success'
});
this.leftloading = false
this.deepGetCurr(parentId, this.list, (value) => {
value.children.push({
ZIndex: value.ZIndex + 1,
name: this.tempNewF,
id: res.data.fieldTypeId || res.data.node.id,
open: false,
show: value.open,
Rename: false,
parentId: parentId,
children: []
})
})
}
this.newf = false
this.tempNewF = ""
}).catch(() => {
this.$message.error("请求失败了" + '-_-');
this.leftloading = false
})
},
using(id) {
let arr = this.selection.map((value) => {
return value.id
})
if (arr.length < 1) {
this.$message.error('未选择任何文件');
return
}
let params = {
status: id,
ids: arr.join(','),
nameId: this.currid
}
this.getData.fieldusing(params).then(res => {
if (res.status == "1") {
this.$message({
message: '操作成功',
type: 'success'
});
if (this.getData.type == 1 || this.getData.type == 2) {
this.$store.dispatch('reGetRuleList')
}
this.getlist()
this.selection = []
}
})
},
clickCurrid(id) {
this.currid = id
this.currPage = 1
this.listRedact = false;
this.tempRedactId = 0
this.selection = []
let tempIs = false
this.list.forEach(value => {
if (value.id === id && value.Rename) {
tempIs = true
}
})
if (!tempIs) {
this.RenameFun()
}
this.getlist()
this.deepGetCurr(id, this.list, deepSetCurr)
// 递归寻找文件夹
// 打开关闭文件夹
function deepSetCurr(obj) {
if (obj.open) {
// 关闭文件夹
obj.open = false
deepCloseFile(obj)
} else {
// 打开文件夹
obj.open = true
obj.children.forEach(value => {
value.show = true
})
}
}
function deepCloseFile(obj) {
if (obj.children.length > 0) {
obj.children.forEach(value => {
value.show = false
deepCloseFile(value)
})
}
}
},
deepGetCurr(id, item, fn, fn2) {
item.forEach((value, index) => {
if (value.id == id) {
fn(value, item, index)
} else {
if (fn2) {
fn2(value, item, index)
}
if (value.children.length > 0) {
this.deepGetCurr(id, value.children, fn, fn2)
}
}
})
},
listTreeDeep(item, num) {
let arr = item.map((value) => {
return {
id: value.id,
parentId: value.parentId,
name: value.name || value.fieldType,
ZIndex: num,
open: false,
show: num === 1 ? true : false,
Rename: false,
children: this.listTreeDeep(value.children, num + 1)
}
})
return arr
},
RenameFun(id) {
this.deepGetCurr(id, this.list, (value) => {
value.Rename = true
}, (value) => {
value.Rename = false
})
},
newFile() {
if (!this.currid) {
this.$message({
message: '请先选择左侧文件夹',
type: 'warning'
});
} else {
this.newf = true
}
},
RenameClose() {
this.deepGetCurr(0, this.list, () => {}, (value) => {
value.Rename = false
})
},
updatafilelist(params) {
this.leftloading = true
let tempNum = null
this.deepGetCurr(params.id, this.list, (value) => {
tempNum = value.parentId
})
params.parentId = tempNum == 99999999 ? 0 : tempNum
tempNum = null
this.getData.updatalist(params).then(res => {
if (res.status === "1") {
this.$message({
message: '修改成功',
type: 'success'
});
this.deepGetCurr(params.id, this.list, (value) => {
value.name = params.name
value.Rename = false
})
this.leftloading = false
} else {
this.leftloading = false
}
}).catch(() => {
this.$message.error("请求失败了" + '-_-');
this.leftloading = false
})
},
delectFun(id) {
let name
let parentId
this.deepGetCurr(id, this.list, (value) => {
name = value.name
parentId = value.parentId
})
let params = {
status: "-1",
id: id,
name: name,
"type": "1",
"engineId": "",
"parentId": parentId == 99999999 ? 0 : parentId
}
this.getData.updatalist(params).then(res => {
if (res.status === "1") {
this.$message({
type: 'success',
message: '删除成功!'
});
this.deepGetCurr(id, this.list, (value, item, index) => {
item.splice(index, 1)
})
}
this.leftloading = false
this.currid = 99999999
this.getlist()
}).catch(() => {
this.$message.error("请求失败了" + '-_-');
this.leftloading = false
})
},
dialogShow(id) {
this.tempRedactId = id
this.listRedact = true
},
select(selection) {
this.selection = selection
},
selectAll(selection) {
this.selection = selection
},
fileRight(e, item) {
this.tempHintLeft = e.x
this.tempHintTop = e.y
this.tempId = item.id
},
beforeUpload(file) {
console.log(file, '文件');
this.files = file;
const extension = file.name.split('.')[1] === 'xls'
const extension2 = file.name.split('.')[1] === 'xlsx'
const isLt2M = file.size / 1024 / 1024 < 5
if (!extension && !extension2) {
this.$message.warning('上传模板只能是 xls、xlsx格式!')
return
}
if (!isLt2M) {
this.$message.warning('上传模板大小不能超过 5MB!')
return
}
this.fileName = file.name;
return false // 返回false不会自动上传
},
submitUpload() {
this.Uploadloading = true
console.log('上传' + this.files.name)
if (this.fileName == "") {
this.$message.warning('请选择要上传的文件!')
this.Uploadloading = false
return false
}
let fileFormData = new FormData();
fileFormData.append('file', this.files); //filename是键file是值就是要传的文件test.zip是要传的文件名
this.getData.fieldsubmit(fileFormData).then(res => {
if (res.status === "1") {
this.callbackresult = res.data
this.upCallbackShow = true
this.upShowClose()
this.getlist()
this.$store.dispatch('reGetRuleList')
this.$store.dispatch('reGetfielduser')
}
this.Uploadloading = false
})
},
upShowClose() {
this.upShow = false
}
}
}

View File

@@ -1,55 +0,0 @@
import ElementUI from 'element-ui';
export function endRuleVerification(obj){
let is= {
is:false,
msg:''
}
if(!obj.selectedRule.length){
return false
}
if(obj.output.fieldId===''){
is.is = true
is.msg = '请选择终止结果变量'
}
if(obj.output.fieldValue===''){
is.is = true
is.msg = '请填写终止结果的输出值'
}
obj.conditions.forEach((value,index)=>{
if(value.fieldCode===''){
is.is = true
is.msg ='请查看是否有终止选项未选'
}
if(value.operator===''){
is.is = true
is.msg ='请查看是否有运算符未选'
}
if(value.value===''){
is.is = true
is.msg ='请查看是否有终止值未填写'
}
if(value.relativeOperator===''&&index!=obj.conditions.length-1){
is.is = true
is.msg ='请查看是否连接符未选'
}
})
if(is.is){
ElementUI.Message.error(is.msg)
}
return is.is
}

View File

@@ -1 +0,0 @@
export const iframeurl = window.location.protocol+'//'+window.location.host;

View File

@@ -1,252 +0,0 @@
export default {
install(Vue) {
Vue.mixin({
data() {
return {
mixinlogical: [{
value: '&&',
label: 'AND'
},{
value: '||',
label: 'OR'
}]
}
},
created() {
},
computed: {
FieldUserObj() {
return this.$store.state.FieldUserObj ? this.$store.state.FieldUserObj.data.fieldList : []
},
FieldUser() {
return this.$store.state.FieldUser ? this.$store.state.FieldUser.data.fieldList : []
},
Sourcelist() {
return this.$store.state.Sourcelist ? this.$store.state.Sourcelist:[]
}
},
mounted() {},
methods: {
randomAdd(item,is) {
if(is||!item){
return
}
if (item.random) {
setTimeout(() => {
item.random++
}, 200)
} else {
// item.random=1
setTimeout(() => {
this.$set(item, 'random', 1)
}, 200)
}
},
verificationNameCode(str){
if(str.indexOf('@')!=-1){
this.$message.error('名称和Code均不允许出现 @% ')
return true
}else if(str.indexOf('%')!=-1){
this.$message.error('名称和Code均不允许出现 @% ')
return true
}
return false
},
mixinSaveJSON(data, filename){
if(!data) {
this.$message.error('保存的数据为空');
return;
}
if(!filename)
filename = 'json.json'
if(typeof data === 'object'){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
},
mixinGetValueTypeByJSONEn(e){
if(!e||e.length==0) return
if(!Array.isArray(e)) e=e.split('.')
let obj =this.FieldUserObj
e.forEach((value,index)=>{
if(index) obj = obj['children']
obj = obj.find(x=>x.value==value)
})
return obj.valueType
},
mixinGetValueByCn(e) {
let num = this.FieldUser.find(x=>x.fieldCn===e)
// this.FieldUser.forEach(value => {
// if (value.fieldCn === e) {
// num = value
// }
// })
return num
},
mixinReGetStorage(){
this.$store.dispatch('reGetfielduser')
this.$store.dispatch('reGetRuleList')
Object.keys(this.$store.state.cacheList).forEach(value=>{
this.$store.dispatch('regetcache', value)
})
},
mixinGetLogical(str){
let num = this.mixinlogical.find(x=>x.value===str)
// this.mixinlogical.forEach(value=>{
// if(str==value.value){
// num = value.label
// }
// })
return num&&num.label
},
mixinGetValueById(e) {
let num =this.FieldUser.find(x=>x.id===e)
// this.FieldUser.forEach(value => {
// if (value.id === e) {
// num = value
// }
// })
return num
},
mixinGetCnByEn(e) {
let num =this.FieldUser.find(x=>x.fieldEn===e)
// this.FieldUser.forEach(value => {
// if (value.fieldEn === e) {
// num = value.fieldCn
// }
// })
return num&&num.fieldCn
},
mixinGetIdByEn(e) {
let num =this.FieldUser.find(x=>x.fieldEn===e)
// this.FieldUser.forEach(value => {
// if (value.fieldEn === e) {
// num = value.id
// }
// })
return num&&num.id
},
mixinGetValueTypeByEn(e) {
let num =this.FieldUser.find(x=>x.fieldEn===e)
// this.FieldUser.forEach(value => {
// if (value.fieldEn === e) {
// num = value.valueType
// }
// })
return num&&num.valueType
},
mixinGetFieldByEn(e) {
let num =this.FieldUser.find(x=>x.fieldEn=== e)
// this.FieldUser.forEach(value => {
// if (value.fieldEn === e) {
// num = value
// }
// })
return num
},
mixinMoveChange(e) {
let arr = this.selection.map((value) => {
return value.id
})
if (arr.length < 1) {
this.$message.error('未选择任何文件');
return
}
let params = {
ids: arr,
folderId: e
}
this.getData.updateParent(params).then(res => {
if (res.status == "1") {
this.clickCurrid(this.currid)
this.$message({
message: '移动成功',
type: 'success'
});
this.selection = []
}
})
this.tempMove = ""
},
mixinDeepCopy() {
let result;
if (typeof target === 'object') {
if (Array.isArray(target)) {
result = [];
for (let i in target) {
result.push(this.mixinDeepCopy(target[i]))
}
} else if (target === null) {
result = null;
} else if (target.constructor === RegExp) {
result = target;
} else {
result = {};
for (let i in target) {
result[i] = this.mixinDeepCopy(target[i]);
}
}
} else {
result = target;
}
return result;
},
mixinGetvalueType(cont) {
let num = this.FieldUser.find(x=>x.id===parseInt(cont))
// this.FieldUser.forEach(value => {
// if (value.id === parseInt(cont)) {
// num = value.valueType
// }
// })
return num&&num.valueType
},
mixinGetvalueEn(cont) {
let num = this.FieldUser.find(x=>x.id===parseInt(cont))
// this.FieldUser.forEach(value => {
// if (value.id === parseInt(cont)) {
// num = value.fieldEn
// }
// })
return num&&num.fieldEn
},
mixinGetvalueCn(cont) {
let num = this.FieldUser.find(x=>x.id===parseInt(cont))
// this.FieldUser.forEach(value => {
// if (value.id === parseInt(cont)) {
// num = value.fieldCn
// }
// })
if(!num&&cont!==""&&cont!==null){
console.log(num,cont)
num="(此字段丢失)"
}
return num&&num.fieldCn
},
mixinGetvalueCode(cont) {
let num = this.FieldUser.find(x=>x.id===parseInt(cont))
return num &&num.fieldCode
}
}
})
}
}

View File

@@ -1,270 +0,0 @@
var Mock = require('mockjs')
// Mock.mock("/Riskmanage/datasource/save", {
// "status": "1",
// data: {
// }
// })
Mock.mock("/Riskmanage/v3/qvshi2", {
"status": "1",
data: {
dycs: [{
dycslabel: '0609',
'dycsvalue|10-100': 1
},{
dycslabel: '0608',
'dycsvalue|10-100': 1
},{
dycslabel: '0607',
'dycsvalue|10-100': 1
},{
dycslabel: '0606',
'dycsvalue|10-100': 1
},{
dycslabel: '0605',
'dycsvalue|10-100': 1
}],
'jcjg':[{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
},{
'jcjglabel':Mock.mock('@cname()'),
'jcjgvalue|20-39':1
}],
gzmz:{
gzmztime:['0603','0604','0605','0606','0607','0608','0609'],
gzmzdata:[
{
gzmzlabel:'规则1',
gzmzvalue:[parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70)]
},
{
gzmzlabel:Mock.mock('@cname()'),
gzmzvalue:[parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70)]
},
{
gzmzlabel:Mock.mock('@cname()'),
gzmzvalue:[parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70)]
},
{
gzmzlabel:Mock.mock('@cname()'),
gzmzvalue:[parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70)]
},
{
gzmzlabel:Mock.mock('@cname()'),
gzmzvalue:[parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70),parseInt(Math.random()*70)]
}
]
}
}
})
Mock.mock("/Riskmanage/v3/qvshi1", {
"status": "1",
data: {
klist: [{ // 每一个模板
engindId: 1, //引擎ID
engName: 'XX引擎', //引擎name
time: { //时间
startTime: '', // 开始时间
endTime: '' // 结束时间
},
dimensions: [ // 统计维度们
{
dimension: 'call', // 调用次数维度
field: [] // 此维度下的指标
},
{
dimension: 'rule',
field: []
},
],
chart: [{
Time: '4.15',
value: {
call: 20,
rule: 80,
}
}, {
Time: '4.15',
value: {
call: 30,
rule: 90,
}
}, {
Time: '4.15',
value: {
call: 40,
rule: 100,
}
}, {
Time: '4.15',
value: {
call: 50,
rule: 200,
}
}, {
Time: '4.15',
value: {
call: 60,
rule: 400,
}
}, {
Time: '4.15',
value: {
call: 70,
rule: 800,
}
}, {
Time: '4.15',
value: {
call: 80,
rule: 1000,
}
}]
}]
}
})
Mock.mock("/Riskmanage/v3/1", {
"status": "1",
data: {
klist: [{
name: '1引擎', //引擎名
id: 1, //id
top: false, // 是否置顶
call: { // 调用次数
'yesterday': 1, // 昨天
'today': 456, // 今天
'todayPredict': 789, // 今天预计
},
result: { // 决策结果
yesterday: 123,
today: 456,
todayPredict: 789,
},
hit: { // 命中规则
yesterday: 123,
today: 456,
todayPredict: 789,
}
}, {
name: '2引擎',
id: 2,
top: false,
call: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
result: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
hit: {
yesterday: 123,
today: 456,
todayPredict: 789,
}
}, {
name: '3引擎',
id: 3,
top: false,
call: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
result: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
hit: {
yesterday: 123,
today: 456,
todayPredict: 789,
}
}, {
name: '4引擎',
id: 4,
top: false,
call: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
result: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
hit: {
yesterday: 123,
today: 456,
todayPredict: 789,
}
}, {
name: '5引擎',
id: 5,
top: false,
call: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
result: {
yesterday: 123,
today: 456,
todayPredict: 789,
},
hit: {
yesterday: 123,
today: 456,
todayPredict: 789,
}
}]
}
})

View File

@@ -1,123 +0,0 @@
export const nodes = [{
node: {
dataId: "0",
text: "开始",
type: 1,
url: "/start.png"
}
},
// {
// node: {
// dataId: "0",
// text: "名单库",
// type: 5,
// url: "/createBlackName.png",
// url2: '/heimingdan.png'
// }
// },
{
node: {
dataId: "2",
text: "分流",
type: 7,
url: "/createRiverRate.png",
haveChildren: true
}
}, {
node: {
dataId: "3",
text: "分组",
type: 3,
url: "/createUserGroup.png",
haveChildren: true
}
}, {
node: {
dataId: "19",
text: "并行",
type: 19,
url: "/parallelNode.png",
haveChildren: true
}
}, {
node: {
dataId: "20",
text: "聚合",
type: 20,
url: "/gettogether.png"
}
}, {
node: {
dataId: "21",
text: "冠军挑战",
type: 21,
url: "/champion.png",
haveChildren: true
}
}, {
node: {
dataId: "4",
text: "规则集",
type: 2,
url: "/ruleGroup.png",
url2: '/guizeji.png'
}
},
// {
// node: {
// dataId: "5",
// text: "评分卡",
// type: 4,
// url: "/createScoreLevel.png",
// url2: '/pingfenka.png'
// }
// },
// {
// node: {
// dataId: "16",
// text: "决策表",
// type: 16,
// url: "/juecebiaonode.png",
// url2: '/juecebiao.png'
// }
// }, {
// node: {
// dataId: "17",
// text: "决策树",
// type: 17,
// url: "/jueceshuNode.png",
// url2: '/jueceshu.png'
// }
// }, {
// node: {
// dataId: "12",
// text: "模型",
// type: 15,
// url: "/models.png",
// url2: '/moxing.png'
// }
// },
{
node: {
dataId: "18",
text: "远程调用",
type: 18,
url: "/rpc.png",
url2: '/rpcnode.png'
}
}, {
node: {
dataId: "7",
text: "决策选项",
type: 9,
url: "/createDcisionOption.png"
}
}, {
node: {
dataId: "11",
text: "子引擎",
type: 14,
url: "/childEngine.png",
url2: '/ziyinqing.png'
}
}]

View File

@@ -1,110 +0,0 @@
import axios from 'axios'
import router from '../router';
import ElementUI from 'element-ui';
var url = window.location.origin || window.location.protocol + '//' + window.location.hostname + (window.location.port ?
':' + window.location.port : '')
const instance = axios.create({
baseURL: process.env.NODE_ENV === 'produce' || process.env.NODE_ENV === 'release' || process.env.NODE_ENV === 'test' ||
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'jia'|| process.env.NODE_ENV === 'niu' ? '/' : url,
timeout: 500000,
})
instance.interceptors.request.use((config) => {
// config.headers['AAA'] = 'AAA';
// console.log(config)
deepTirm(config)
if (config.data) {
if (config.data.getexcel) {
config.headers['responseType'] = 'blob'
}
}
if (localStorage.getItem('token')) {
config.headers['token'] = localStorage.getItem('token');
}
return config
})
instance.interceptors.response.use((response) => {
const {
data,
config
} = response
// console.log(response)
let result = data
if (response.data.status === "0") {
if (response.data.error === "01000103") {
if (document.getElementsByClassName('el-message').length === 0) {
ElementUI.Message.error(response.data.msg);
router.push({
path: '/login',
})
}
} else {
ElementUI.Message.error(response.data.msg);
}
}
return result
}, (error) => {
// console.log('error', error)
if (error.message.match(/timeout/)) {
ElementUI.Message.error('请求超时,请稍后再试!');
} else if (error.response.status === 500) {
ElementUI.Message.error('连接失败,请稍后再试!');
} else if (error.response.status === 502) {
ElementUI.Message.error('网关超时,请稍后再试!');
} else {
ElementUI.Message.error('连接失败,请稍后再试!');
}
return Promise.reject(error)
});
function deepTirm(e) {
Object.keys(e).forEach(value => {
if (typeof e[value] == 'string' && (e[value][0] === " " || e[value][e[value].length - 1] === " ")) {
e[value] = e[value].trim()
}
if (isJSON(e[value])) {
e[value] = JSON.stringify(deepTirm(JSON.parse(e[value])))
}
if (typeof e[value] === "object" && e[value] !== null) {
if (Array.isArray(e[value])) {
e[value].forEach(item => {
if (typeof item === 'string' && (item[0] === " " || item[item.length - 1] === " ")) {
item = item.trim()
}
if (typeof item === 'object') {
item = deepTirm(item)
}
})
} else {
deepTirm(e[value])
}
}
})
return e
}
function isJSON(str) {
if (typeof str == 'string') {
try {
var obj = JSON.parse(str);
if (typeof obj == 'object' && obj) {
return true;
} else {
return false;
}
} catch (e) {
return false;
}
}
}
export default instance