123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- const baseUrl = "https://www.cqna.gov.cn/mnazw"
- const imgUrl = "https://www.cqna.gov.cn/mnazw/applet/"
- import {
- cacheGet
- } from "../../utils/cacheUtil"
- const request = (options) => {
- islogin(options.url)
- // let token = wx.getStorageSync('token')
- let token = cacheGet('token')
- return new Promise((resolve, reject) => {
- options.url = baseUrl + options.url
- let contentType;
- if (options.contentType) {
- contentType = options.contentType;
- } else if (options.method && options.method === 'POST') {
- contentType = 'application/x-www-form-urlencoded';
- } else if (options.method === 'GET') {
- contentType = 'application/json;charset=UTF-8';
- }
- wx.request({
- // 配置 "wx.request" 请求参数
- ...options,
- header: {
- 'content-type': contentType,
- 'mini-token': `${token}`
- },
- success: function (res) {
- console.log("network-res=>", res);
- if (res.data.msg == '请重新登录' && !res.data.result && token != null && token != '') {
- wx.showModal({
- title: '未授权',
- content: '您登录授权已过期,请重新登录授权',
- showCancel: false,
- confirmText: '登录',
- success: function (res) {
- wx.navigateTo({
- url: '/pages/login/login',
- });
- },
- });
- }
- // 返回成功信息
- resolve(res.data)
- },
- fail: function (error) {
- console.log("network-err=>", error);
- // 返回错误信息
- reject(error)
- }
- })
- })
- }
- const request2 = (options) => {
- return new Promise((resolve, reject) => {
- options.url = "https://www.cqna.gov.cn/data" + options.url
- wx.request({
- // 配置 "wx.request" 请求参数
- ...options,
- header: {
- 'content-type': 'application/json;charset=UTF-8'
- },
- success: function (res) {
- console.log("network-res=>", res);
- // 返回成功信息
- resolve(res.data)
- },
- fail: function (error) {
- console.log("network-err=>", error);
- // 返回错误信息
- reject(error)
- }
- })
- })
- }
- function islogin(data) {
- let urls = data.split("\/")
- if (!noNeedLogin(urls)) {
- // let token = wx.getStorageSync('token')
- let token = cacheGet('token')
- if (token == null || token == '') {
- wx.showModal({
- title: '未授权',
- content: '您登录授权已过期,请重新登录授权',
- showCancel: false,
- confirmText: '登录',
- success: function (res) {
- wx.navigateTo({
- url: '/pages/login/login',
- });
- },
- });
- }
- }
- }
- var noNeedLoginList = ["login", "getGoodOrBadByYearAndArea", "getOfficeNumberByAreaInfo"]
- function noNeedLogin(data) {
- for (const element of noNeedLoginList) {
- let a = data[data.length - 1].split("?")[0]
- if (a === element) {
- return true;
- }
- }
- }
- export {
- request,
- imgUrl,
- baseUrl,
- request2
- }
|