import loading from ‘./loading’
import message from ‘./message’
import api from ‘…/config/api’
export function request(url: string, data = {}, method?: method,showLoding:boolean=true):any{
if(showLoding){
loading.show()
}
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(url=====>${url}
, data=====>
, data)
wx.request({
url,
data,
method: method === ‘GET’ ? ‘GET’ : ‘POST’,
success: (res: any) => {
// console.log(success response=====>${JSON.stringify(res.data)}
)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:’/pages/register/detail/detail’
})
break;
default:
message.error(response.result)
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error(‘网络异常’)
console.log(fail response=====>${JSON.stringify(e)}
)
},
complete() {
if(showLoding)
loading.hide()
}
})
})
}
// showmodal报错后点击确认回退两个步长
export const erroBackTwoRequest = function (url: string, data = {}, method?: method) {
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(url=====>${url}
, data=====>
, data)
wx.request({
url,
data,
method: method === ‘GET’ ? ‘GET’ : ‘POST’,
success: (res: any) => {
// console.log(success response=====>${JSON.stringify(res.data)}
)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:’/pages/register/detail/detail’
})
break;
default:
console.log(res.data);
console.log(res.data.result);
wx.showModal({
content:''+res.data.result,
confirmText:"确认",
showCancel:false,
success(a){
if(a.confirm){
wx.navigateBack(2)
}
}
})
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error('网络异常')
console.log(`fail response=====>${JSON.stringify(e)}`)
},
complete() {
// loading.hide()
}
})
})
}
export const sliceRequest = function (url: string, data = {}, method?: method) {
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(url=====>${url}
, data=====>
, data)
wx.request({
url,
data,
method: method === ‘GET’ ? ‘GET’ : ‘POST’,
success: (res: any) => {
// console.log(success response=====>${JSON.stringify(res.data)}
)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:’/pages/register/detail/detail’
})
break;
default:
message.error(response.result)
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error(‘网络异常’)
console.log(fail response=====>${JSON.stringify(e)}
)
},
complete() {
// loading.hide()
}
})
})
}
export const getNavigationHeight = () => {
const { model, windowHeight, windowWidth, statusBarHeight } = wx.getSystemInfoSync()
let titleBarHeight = 0;
if (model.indexOf(‘iPhone’) !== -1) {
titleBarHeight = 44;
} else {
titleBarHeight = 48;
}
let rpxStatus = Math.round((statusBarHeight * 750 / windowWidth))
let rpxTitle = Math.round((titleBarHeight * 750 / windowWidth))
return {
windowHeight: windowHeight,
windowWidth: windowWidth,
rpxStatus,
rpxTitle,
navigationHeight: rpxStatus + rpxTitle
}
// return wx.getMenuButtonBoundingClientRect()
}
function requestSlice(url: string, data = {}):any{
data = Object.assign( data, { sessionId: getApp().globalData.sessionId })
wx.request({
url,
data,
method: ‘POST’,
fail(e: any) {
message.error(‘网络异常’)
console.log(fail response=====>${JSON.stringify(e)}
)
}
})
}
wx.enterIn= function (){
//@ts-ignore
requestSlice(api.addMiniprogramData,{page:this.route,type:‘1’})
}
wx.getOut=function (){
//@ts-ignore
requestSlice(api.addMiniprogramData,{page:this.route,type:‘2’})
}
import loading from './loading'
import message from './message'
import api from '../config/api'
export function request(url: string, data = {}, method?: method,showLoding:boolean=true):any{
if(showLoding){
loading.show()
}
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(`url=====>${url}`, `data=====>`, data)
wx.request({
url,
data,
method: method === 'GET' ? 'GET' : 'POST',
success: (res: any) => {
// console.log(`success response=====>${JSON.stringify(res.data)}`)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:'/pages/register/detail/detail'
})
break;
default:
message.error(response.result)
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error('网络异常')
console.log(`fail response=====>${JSON.stringify(e)}`)
},
complete() {
if(showLoding)
loading.hide()
}
})
})
}
// showmodal报错后点击确认回退两个步长
export const erroBackTwoRequest = function (url: string, data = {}, method?: method) {
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(`url=====>${url}`, `data=====>`, data)
wx.request({
url,
data,
method: method === 'GET' ? 'GET' : 'POST',
success: (res: any) => {
// console.log(`success response=====>${JSON.stringify(res.data)}`)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:'/pages/register/detail/detail'
})
break;
default:
console.log(res.data);
console.log(res.data.result);
wx.showModal({
content:''+res.data.result,
confirmText:"确认",
showCancel:false,
success(a){
if(a.confirm){
wx.navigateBack(2)
}
}
})
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error('网络异常')
console.log(`fail response=====>${JSON.stringify(e)}`)
},
complete() {
// loading.hide()
}
})
})
}
export const sliceRequest = function (url: string, data = {}, method?: method) {
return new Promise((resolve, reject) => {
data = Object.assign({}, data, { sessionId: getApp().globalData.sessionId })
console.log(`url=====>${url}`, `data=====>`, data)
wx.request({
url,
data,
method: method === 'GET' ? 'GET' : 'POST',
success: (res: any) => {
// console.log(`success response=====>${JSON.stringify(res.data)}`)
if (res.statusCode == 200) {
// 请求成功
const response = res.data
switch (parseInt(response.code)) {
case 1000:
resolve(response.result)
break;
case 7003:
wx.navigateTo({
url:'/pages/register/detail/detail'
})
break;
default:
message.error(response.result)
reject(response)
}
} else {
message.error(res.data.result)
}
},
fail(e: any) {
message.error('网络异常')
console.log(`fail response=====>${JSON.stringify(e)}`)
},
complete() {
// loading.hide()
}
})
})
}
export const getNavigationHeight = () => {
const { model, windowHeight, windowWidth, statusBarHeight } = wx.getSystemInfoSync()
let titleBarHeight = 0;
if (model.indexOf('iPhone') !== -1) {
titleBarHeight = 44;
} else {
titleBarHeight = 48;
}
let rpxStatus = Math.round((statusBarHeight * 750 / windowWidth))
let rpxTitle = Math.round((titleBarHeight * 750 / windowWidth))
return {
windowHeight: windowHeight,
windowWidth: windowWidth,
rpxStatus,
rpxTitle,
navigationHeight: rpxStatus + rpxTitle
}
// return wx.getMenuButtonBoundingClientRect()
}
function requestSlice(url: string, data = {}):any{
data = Object.assign( data, { sessionId: getApp().globalData.sessionId })
wx.request({
url,
data,
method: 'POST',
fail(e: any) {
message.error('网络异常')
console.log(`fail response=====>${JSON.stringify(e)}`)
}
})
}
wx.enterIn= function (){
//@ts-ignore
requestSlice(api.addMiniprogramData,{page:this.route,type:'1'})
}
wx.getOut=function (){
//@ts-ignore
requestSlice(api.addMiniprogramData,{page:this.route,type:'2'})
}