Browse Source

api修改

master
王健 4 years ago
parent
commit
874e38e75c
  1. 54
      app.js
  2. 56
      utils/api.js
  3. 81
      utils/gisApi.js

54
app.js

@ -2,41 +2,6 @@
const $api = require('./utils/api').API;
App({
onLaunch() {
let that = this;
let token = wx.getStorageSync('access_token')
let userInfo = wx.getStorageSync('userInfo');
console.log(token)
// if(!token||token==""){
// wx.navigateTo({
// url:"/pages/auth/auth",
// })
// };
// wx.login({
// success (res) {
// if (res.code) {
// //发起网络请求
// $api.getUserAuth(res.code).then(data=>{
// if(data.access_token){
// wx.setStorage({
// key:"access_token",
// data:data.access_token
// })
// that.queryUsreInfo();
// }else if(data.code==2){
// that.registerBind(res.code)
// }else{
// }
// }).catch(err=>{
// console.log('err',err)
// })
// } else {
// console.log('登录失败!' + res.errMsg)
// }
// }
// })
// 监听更新版本
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
@ -70,25 +35,6 @@ App({
})
}
},
// registerBind(code){
// let that = this;
// let params = {
// state:'MINI',
// code,
// phone:'15198094357',
// phoneCode:'',
// nickName:'',
// avatar:'',
// legalName:''
// };
// $api.registerBind(params).then(data=>{
// wx.setStorage({
// key:"access_token",
// data:data.access_token
// })
// that.queryUsreInfo();
// })
// },
queryUsreInfo() {
$api.getUserInfo().then(res => {
if (res.code === 0) {

56
utils/api.js

@ -1,5 +1,6 @@
const baseURL = 'https://yoursairdata.com/api/'
// const baseURL = 'http://192.168.209.210:9002/'
const defaultCity = '重庆'
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
@ -8,14 +9,17 @@ const DELETE = 'DELETE';
function request(method, url, data, hasToke = true) {
let token = wx.getStorageSync('access_token')
let Authorization = token && hasToke ? `Bearer ${token}` : 'Basic YXBwOmFwcA==';
// console.log(Authorization)
// console.log(method,url, data,hasToke)
if (method === GET) {
let city = wx.getStorageSync('city')
city = city ? city : defaultCity
if (url.indexOf('?') !== -1) {
url += `&city=${city}`
} else {
url += `?city=${city}`
}
}
return new Promise(function (resolve, reject) {
let header = {
'content-type': 'application/json',
@ -27,7 +31,6 @@ function request(method, url, data, hasToke = true) {
data: method === POST ? JSON.stringify(data) : data,
header: header,
success(res) {
// console.log(res);
if (res.statusCode == 401) {
wx.showToast({
title: '登录过期,请重新登录',
@ -38,9 +41,6 @@ function request(method, url, data, hasToke = true) {
wx.navigateTo({
url: "/pages/auth/auth",
})
// setTimeout(() => {
// }, 1500)
} else {
resolve(res.data);
}
@ -54,14 +54,10 @@ function request(method, url, data, hasToke = true) {
}
// 登录方法
function requestLogin(method, url, data) {
let Authorization = 'Basic YXBwOmFwcA==';
return new Promise(function (resolve, reject) {
let header = {
// 'content-type': 'application/json',
'content-type': 'application/x-www-form-urlencoded',
'Authorization': Authorization,
};
@ -86,32 +82,34 @@ const API = {
getOpenid: (data) => request(GET, `oauth/token?grant_type=password&username=${data.admin}&password=${data.password}`),
getUserAuth: (data) => request(POST, `social/token?code=MINI@${data}`, '', false),
registerBind: (data) => request(POST, `social/register-bind`, data, false),
getUserInfo: () => request(GET, `user/info`), //获取用户信息
getUserInfo: () => request(GET, `user/info`), //获取用户信息
//字典
getDict: (data) => request(GET, `dict/type/${data}`),
//日历
getLandlistedList: (data) => request(GET, `applets/landlisted/list?annoDate=${data.annoDate}&canton=${data.canton}&size=9999`),//挂牌
getLandlistedList2: (data) => request(GET, `applets/landlisted/list?auctionDate=${data.auctionDate}&canton=${data.canton}&size=9999`),//拍卖
getLandDetail: (data) => request(GET, `applets/landlisted/${data}`),//通过ID获取详情
getPreSaleDetailList: (data) => request(GET, `applets/blocks/getPreSaleDetailList?landListedId=${data.landListedId}`),//查询预售明细列表
getPreSaleTotal: (data) => request(GET, `applets/blocks/getPreSaleTotal?landListedId=${data.landListedId}`),//销售情况统计
getLandlistedList: (data) => request(GET, `applets/landlisted/list?annoDate=${data.annoDate}&canton=${data.canton}&size=9999`), //挂牌
getLandlistedList2: (data) => request(GET, `applets/landlisted/list?auctionDate=${data.auctionDate}&canton=${data.canton}&size=9999`), //拍卖
getLandDetail: (data) => request(GET, `applets/landlisted/${data}`), //通过ID获取详情
getPreSaleDetailList: (data) => request(GET, `applets/blocks/getPreSaleDetailList?landListedId=${data.landListedId}`), //查询预售明细列表
getPreSaleTotal: (data) => request(GET, `applets/blocks/getPreSaleTotal?landListedId=${data.landListedId}`), //销售情况统计
//测算
getCalulaList: (data) => request(GET, `applets/measuredata/page?queryDate=${data.queryDate}&current=${data.current}&size=${data.size}&landListedId=${data.landListedId}`),//分页
getCalulaDeatail: (data) => request(GET, `applets/measuredata/getByLandListedId/${data}`),//通过地块ID获取测算详情
getCalulaList: (data) => request(GET, `applets/measuredata/page?queryDate=${data.queryDate}&current=${data.current}&size=${data.size}&landListedId=${data.landListedId}`), //分页
getCalulaDeatail: (data) => request(GET, `applets/measuredata/getByLandListedId/${data}`), //通过地块ID获取测算详情
//看地
getLandlistedPage: (data) => request(GET, `applets/landlisted/page?startDate=${data.startDate}&current=${data.current}&size=${data.size}&measureStatus=${data.measureStatus}&transactionStatus=${data.transactionStatus}&canton=${data.canton}&landCode=${data.landCode}&endDate=${data.endDate}`),//分页
getLandlistedPage: (data) => request(GET, `applets/landlisted/page?startDate=${data.startDate}&current=${data.current}&size=${data.size}&measureStatus=${data.measureStatus}&transactionStatus=${data.transactionStatus}&canton=${data.canton}&landCode=${data.landCode}&endDate=${data.endDate}`), //分页
//消息管理
getMessage: (data) => request(GET, `applets/message/page?current=${data.current}&size=${data.size}&messageType=${data.messageType}`),//分页
getMessage: (data) => request(GET, `applets/message/page?current=${data.current}&size=${data.size}&messageType=${data.messageType}`), //分页
//意见反馈
feedback: (data) => request(POST, `feedback`, data, true),//提交意见
uploadImg: (data) => request(POST, `file`, data, false),//图片上传
feedback: (data) => request(POST, `feedback`, data, true), //提交意见
uploadImg: (data) => request(POST, `file`, data, false), //图片上传
//保存测算数据
measureData: (data) => request(POST, `applets/measuredata`, data, true),//保存测算数据
measureData: (data) => request(POST, `applets/measuredata`, data, true), //保存测算数据
AJAX: (GET, url, data, is_toke) => request(GET, url, data, is_toke),
Login: (GET, url, data) => requestLogin(GET, url, data),
getCityList:()=>request(GET, '/cityArea/city'),
getAreaList:(city)=>request(GET,`/cityArea/getArea/${city}`)
};
module.exports = {
API: API,
baseURL:baseURL
baseURL: baseURL,
request: request
}

81
utils/gisApi.js

@ -1,4 +1,5 @@
const $host = require('./api').baseURL;
const request = require('./api').request;
const baseURL = `${$host}applets/map/`
const GET = 'GET';
@ -8,51 +9,51 @@ const FORM = 'FORM';
const DELETE = 'DELETE';
function request(method, url, data, hasToke = true) {
// function request(method, url, data, hasToke = true) {
let token = wx.getStorageSync('access_token')
let Authorization = token && hasToke ? `Bearer ${token}` : 'Basic YXBwOmFwcA==';
// let token = wx.getStorageSync('access_token')
// let Authorization = token && hasToke ? `Bearer ${token}` : 'Basic YXBwOmFwcA==';
// console.log(Authorization)
// console.log(method,url, data,hasToke)
// // console.log(Authorization)
// // console.log(method,url, data,hasToke)
return new Promise(function (resolve, reject) {
let header = {
'content-type': 'application/json',
'Authorization': Authorization,
};
wx.request({
url: baseURL + url,
method: method,
data: method === POST ? JSON.stringify(data) : data,
header: header,
success(res) {
// console.log(res);
if (res.statusCode == 401) {
wx.showToast({
title: '登录过期,请重新登录',
icon: "none",
mask: true,
})
wx.clearStorage();
wx.navigateTo({
url: "/pages/auth/auth",
})
// setTimeout(() => {
// return new Promise(function (resolve, reject) {
// let header = {
// 'content-type': 'application/json',
// 'Authorization': Authorization,
// };
// wx.request({
// url: baseURL + url,
// method: method,
// data: method === POST ? JSON.stringify(data) : data,
// header: header,
// success(res) {
// // console.log(res);
// if (res.statusCode == 401) {
// wx.showToast({
// title: '登录过期,请重新登录',
// icon: "none",
// mask: true,
// })
// wx.clearStorage();
// wx.navigateTo({
// url: "/pages/auth/auth",
// })
// // setTimeout(() => {
// }, 1500)
} else {
resolve(res.data);
}
},
fail(err) {
//请求失败
reject(err)
}
})
})
}
// // }, 1500)
// } else {
// resolve(res.data);
// }
// },
// fail(err) {
// //请求失败
// reject(err)
// }
// })
// })
// }
const API = {

Loading…
Cancel
Save