12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import {
- encryption
- } from "./encryption"
-
- /**
- * 配置信息,针对不同的平台进行配置
- */
- export const envs = {
- //开发环境配置
- development: {
- // baseUrl: "222.85.144.89:19002",
- baseUrl: "192.168.100.63:8087",
- },
- //生产环境配置
- production: {
- baseUrl: "192.168.100.63:8087",
- }
- }
-
- export function request(code, options = {}) {
- console.log('接口请求参数:', options)
- //公参
- const Common = {
- }
- //Url 地址
- options.url = 'http://' + envs['development'].baseUrl + '/ifzt/api/interfaceMidGroundIn'
- // options.url = 'https://' + 'skx.mynatapp.cc' + '/ifzt/api/interfaceMidGroundIn'
- //判断baseUri是否为空
- if (options.baseUrl) {
- options.url = options.baseUrl
- }
- //默认json数据格式提交`
- let contentType = 'application/json;charset=UTF-8'
- //根据type判断数据传输格式
- if (options.type && options.type === 2) {
- contentType = 'application/x-www-form-urlencoded '
- }
- options.header = {
- 'content-type': contentType
- }
- //默认POST提交
- options.method = options.method ? options.method : 'POST'
- //设置请求超时时间
- options.timeout = 60000
- //判断code不为空
- if (code) {
- options.data = encryption(code, Object.assign(Common, {
- ...options.data,
- 'appId': '52030131'
- }), 2);
- }
- //是否显示加载中
- if (!options.showLoading) {
- uni.showLoading({
- title: options.showTitle ? options.showTitle : '加载中',
- mask: true
- });
- }
- //参数返回
- return new Promise((resolve, reject) => {
- options.success = (res) => {
- // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
- uni.hideLoading()
- if (res.data.statusCode !== 0) {
- uni.showModal({
- title: '提示',
- content: res.data.errorMsg,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
- //请求成功
- resolve(res.data)
- }
- options.fail = (err) => {
- uni.hideLoading()
- console.log('请求错误', err)
- //处理请求错误
- reject(err)
- }
- uni.request(options)
- });
- }
|