123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import {
- appId
- } from "./api";
- import {
- encryption
- } from "./encryption";
- import {
- getItem,
- StorageKeys
- } from "../storage";
- /**
- * 配置信息,针对不同的平台进行配置
- */
- const envs = {
- //开发环境配置
- development: {
- baseUrl: "http://192.168.100.63:8087/ifzt/api/interfaceMidGroundIn",
- },
- //生产环境配置 https://testzeus.etcjz.cn/api/common/transmit/v1/send/zt
- production: {
- baseUrl: "https://testzeus.etcjz.cn/api/common/transmit/v1/send/zt",
- }
- }
- //222.85.144.89:19003
- //https://etcfile.etcjz.cn 文件服务器
- //公参
- export function request(code, options = {}) {
- //工参
- const Common = {
- agentId: "52010106004",
- channelId: "5201010200601130001",
- channelType: "1",
- staffId: "54623263cb4d4a289dccbc983b22a4af",
- terminalId: "999999999999"
- }
- //Url 地址
- //options.url = envs[process.env.NODE_ENV].baseUrl || '' + options.url
- options.url = 'http://192.168.100.63:8087/ifzt/api/interfaceMidGroundIn'
- // options.url = 'http://222.85.144.89:19002/ifzt/api/interfaceMidGroundIn'
- //判断baseUri是否为空
- if (options.baseUrl) {
- options.url = options.baseUrl
- }
- //默认json数据格式提交
- let contentType = 'application/x-www-form-urlencoded'
- //根据type判断数据传输格式
- if (options.type && options.type === 2) {
- contentType = 'application/json;charset=UTF-8'
- }
- options.header = {
- 'content-type': contentType,
- 'Access-Token': getItem(StorageKeys.Token)
- }
- //默认POST提交
- options.method = options.method ? options.method : 'POST'
- //设置请求超时时间
- options.timeout = 60000
-
- // if (!options.data.tel) {
- // options.data.tel = uni.getStorageSync('operatorId')
- // }
- // options.data.orderNo = uni.getStorageSync('orderNo')
- // options.data.operatorId = uni.getStorageSync('operatorId') //操作人编号
- // options.data.applySourceType = '6' //申请来源 6 H5
- //判断code不为空
- if (code) {
- options.data = encryption(code, Object.assign(Common, {
- ...options.data,
- 'appId': appId
- }), 2);
- }
-
- console.log('======请求参数======', options.data)
- //是否显示加载中
- if (options.showLoading) {
- wx.showLoading({
- title: '请稍后',
- mask: true
- });
- }
-
- //参数返回
- return new Promise((resolve, reject) => {
- options.success = (res) => {
- console.log('请求返回结果:======', res)
- // 请求返回后,隐藏loading(如果请求返回快的话,可能会没有loading)
- wx.hideLoading()
- if (res.data.statusCode !== 0 && res.data.statusCode !== 200) {
- if (res.data.statusCode == 600) {
- resolve(res.data)
- } else {
- wx.showModal({
- title: '提示',
- content: res.data.errorMsg,
- success: function(res) {
- if (res.confirm) {
- console.log('用户点击确定');
- } else if (res.cancel) {
- console.log('用户点击取消');
- }
- }
- });
- }
- // console.log("请求错误")
-
- reject(res.data.errorMsg)
- return
- }
- console.log("请求成功")
- //请求成功
- resolve(res.data)
- }
- options.fail = (err) => {
- wx.hideLoading()
- console.log('请求错误', err)
- //处理请求错误
- reject(err)
- }
- wx.request(options)
- });
- }
|