qrcode-app/utils/request.js
wyw 7217872c88 1、添加 信息查看导航 维码生成器 隐患查看 检查查看 风险查看 视频查看
2、按钮点击 添加形参
3、接口 添加   区域选择、检查库、隐患 搜索
4、修改 request  公共方法信息(原来的都写死了)
2025-02-25 16:46:59 +08:00

161 lines
3.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import config from '../config/common' // 配置文件
import handle401 from './handle401'
// import MD5 from 'md5'
export default {
send(params) {
const pages = getCurrentPages()
const currentPage = pages[pages.length - 1]
const Options = currentPage.options
let Company = Options.Company ? Options.Company : 'XLK'
let tenantId = ''
if (Company == 'DCJD') {
tenantId = 'A0000025'
} else if (Company == 'GXBB') {
tenantId = 'A0000028'
} else if (Company == 'LYYL') {
tenantId = 'A0000024'
} else if (Company == 'LYXT') {
tenantId = '0002'
} else {
tenantId = '0001'
}
let url = params.url;
let method = params.method || "get";
let data = params.data || {};
let isAll = false
if (params.isAll)
isAll = params.isAll
let header = {
// 'Blade-Auth': uni.getStorageSync('token') || '',
// 'Content-Type': type === 'post' ? 'application/json' : 'application/x-www-form-urlencoded',// 'Content-Type': 'application/json;charset=UTF-8',
// 'Content-Type': 'application/json;charset=UTF-8',
'Content-Type': params.method === 'post' ? 'application/json' : 'application/json;charset=UTF-8',
// 'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
'Tenant': tenantId, // avue配置相关
...params.header
}
return new Promise((resolve, reject) => {
uni.request({
url: config.serviceHost(url),
method: method,
header: header,
data: data,
// timeout
success(response) {
const res = response
// 根据返回的状态码做出对应的操作
//获取成功
// console.log(res.statusCode);
if (res.statusCode == 200) {
if (isAll)
resolve(res);
else
resolve(res.data);
} else {
uni.clearStorageSync()
switch (res.statusCode) {
case 401:
setTimeout(() => {
uni.showToast({
icon: 'error',
title: '请稍后重试...',
duration: 3000,
})
}, 10)
break;
case 404:
setTimeout(() => {
uni.showToast({
icon: 'error',
title: '请求地址不存在...',
duration: 3000,
})
}, 10)
break;
default:
setTimeout(() => {
uni.showToast({
icon: 'error',
title: '服务器内部错误...',
duration: 3000,
})
}, 10)
break;
}
}
},
fail(err) {
console.log(err)
if (err.errMsg.indexOf('request:fail') !== -1) {
setTimeout(() => {
uni.showToast({
title: '网络异常',
icon: "error",
duration: 2000
})
}, 10)
} else {
setTimeout(() => {
uni.showToast({
title: '未知异常',
duration: 2000
})
}, 10)
}
reject(err);
},
complete() {
// 不管成功还是失败都会执行
// uni.hideLoading();
uni.hideToast();
}
});
}).catch(() => {});
},
upload(url = '', filePath) {
const appInfoData = uni.getStorageSync('appInfo')
const tenant = uni.getStorageSync('Tenant') || ''
const userId = appInfoData?.User?.ID || ''
const orgId = appInfoData?.User?.ORG_ID || ''
return new Promise((resolve, reject) => {
uni.showLoading()
uni.uploadFile({
url: url,
filePath: filePath[0],
name: 'file',
formData: {
OrgId: orgId,
userID: userId
},
header: {
Tenant: tenant,
userid: userId
},
success: (res) => {
if (res.statusCode === 200) {
uni.hideLoading()
resolve(JSON.parse(res.data))
const uploadResult = JSON.parse(res.data)
if (uploadResult.IsSuccessful) {
resolve(uploadResult.Data)
} else {
reject(uploadResult.ErrorMessage)
}
}
},
fail: (err) => {
console.log(err)
}
})
})
},
}