初始化
This commit is contained in:
85
request/api.js
Normal file
85
request/api.js
Normal file
@@ -0,0 +1,85 @@
|
||||
// 存放接口处
|
||||
import http from './request.js';
|
||||
|
||||
/**
|
||||
* 账号密码登录
|
||||
* @param{account:string ,password: string} params
|
||||
*/
|
||||
export const userLogin = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/login',
|
||||
data
|
||||
});
|
||||
|
||||
/**
|
||||
* 微信code登录
|
||||
* @param{platform:string ,code: 微信code} data
|
||||
*/
|
||||
export const thirdLogin = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/third',
|
||||
data
|
||||
})
|
||||
|
||||
/**
|
||||
* 手机验证码登录
|
||||
* @param{mobile:string ,captcha: 验证码} data
|
||||
*/
|
||||
export const phonenumberLogin = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/mobilelogin',
|
||||
data
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
* @param{mobile:string ,captcha: 验证码,newpassword:string} data
|
||||
*/
|
||||
export const retrievePassword = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/resetpwd',
|
||||
data
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 发送验证码
|
||||
* @param{mobile:手机号码 ,event: [register:'注册',login:'登录',bind:'绑定手机号',修改:'savepwd']} data
|
||||
*/
|
||||
export const sendVerifyCode = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/sms/send',
|
||||
data
|
||||
})
|
||||
|
||||
|
||||
// /**
|
||||
// * 上传文件
|
||||
// * @param{file} file
|
||||
// */
|
||||
// export const uploadFile = (files) => {
|
||||
// uni.uploadFile({
|
||||
// url: 'https://jx.xiaolinghou.com/api/common/upload', //仅为示例,非真实的接口地址
|
||||
// header: {
|
||||
// token: uni.getStorageSync('token'),
|
||||
// },
|
||||
// files,
|
||||
// name: 'file',
|
||||
// success: (res) => {
|
||||
// console.log(res);
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// console.log(err);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 上传
|
||||
*/
|
||||
export const uploadFile = (filePath) => http.upload('/common/upload', {
|
||||
filePath,
|
||||
name: 'file'
|
||||
})
|
||||
1
request/baseUrl.js
Normal file
1
request/baseUrl.js
Normal file
@@ -0,0 +1 @@
|
||||
export const baseUrl = 'https://jx.xiaolinghou.com/api';
|
||||
52
request/request.js
Normal file
52
request/request.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import Request from 'luch-request' // https://www.quanzhan.co/luch-request/guide/3.x/#npm
|
||||
import {
|
||||
baseUrl
|
||||
} from './baseUrl.js';
|
||||
const http = new Request();
|
||||
|
||||
http.setConfig((config) => {
|
||||
console.log(12313123123);
|
||||
/* config 为默认全局配置*/
|
||||
config.baseURL = baseUrl; /* 根域名 */
|
||||
config.timeout = 100000;
|
||||
// config.header['Access-Control-Allow-Origin'] = "*"
|
||||
// config.header['Origin']='*'
|
||||
return config
|
||||
})
|
||||
|
||||
// 在请求之前拦截
|
||||
http.interceptors.request.use((config) => {
|
||||
console.log(config);
|
||||
config.header = {
|
||||
token:uni.getStorageSync('token'),
|
||||
...config.header,
|
||||
}
|
||||
|
||||
return config
|
||||
}, config => { // 可使用async await 做异步操作
|
||||
console.log(config);
|
||||
return Promise.reject(config)
|
||||
})
|
||||
|
||||
// 在请求之后拦截
|
||||
http.interceptors.response.use((response) => {
|
||||
/* 对响应成功做点什么 可使用async await 做异步操作*/
|
||||
|
||||
return response
|
||||
}, (response) => {
|
||||
console.log(response,'1111111111');
|
||||
if(response.data?.code===401){
|
||||
uni.navigateTo({
|
||||
url:'pages/login/login'
|
||||
})
|
||||
}
|
||||
uni.showToast({
|
||||
title:'请求错误',
|
||||
icon:'error'
|
||||
})
|
||||
// uni.showToast({title:response.data?.message||response.errMsg})
|
||||
/* 对响应错误做点什么*/
|
||||
// console.log(response)
|
||||
return Promise.reject(response)
|
||||
})
|
||||
export default http;
|
||||
200
request/wm.js
Normal file
200
request/wm.js
Normal file
@@ -0,0 +1,200 @@
|
||||
// 存放接口处
|
||||
import http from './request.js';
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
import {
|
||||
TextDecoder
|
||||
} from '@/utils/text-encoding-0.6.3/index.js'
|
||||
// #endif
|
||||
|
||||
|
||||
// 获取聊天记录
|
||||
export const getMessageList = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/chat/history'
|
||||
});
|
||||
|
||||
/**
|
||||
* 微信code登录
|
||||
* @param{platform:string ,code: 微信code} data
|
||||
*/
|
||||
export const thirdLogin = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/third',
|
||||
data
|
||||
})
|
||||
|
||||
// 发送消息
|
||||
// export const sendMessageApi = (data) => http.request({
|
||||
// method: "POST",
|
||||
// url: '/chat/random',
|
||||
// data
|
||||
// })
|
||||
|
||||
|
||||
// 发送消息
|
||||
// export const sendMessageApi = (data) => {
|
||||
// const requestTask = uni.request({
|
||||
// url: "https://jx.xiaolinghou.com/api/chat/random",
|
||||
// timeout: 150000,
|
||||
// responseType: "text",
|
||||
// method: "POST",
|
||||
// header: {
|
||||
// token: 'ccef1fb8-c85c-4144-9e69-00a4f279f9ab'
|
||||
// },
|
||||
// enableChunked: true, //配置这里
|
||||
// data,
|
||||
// success: response => {
|
||||
// console.log(response)
|
||||
// },
|
||||
// fail: error => {}
|
||||
// })
|
||||
// requestTask.onChunkReceived(function(res) {
|
||||
// const uint8Array = new Uint8Array(res.data);
|
||||
// // 尝试使用多个字符编码进行解码
|
||||
// const encodings = ['utf-8', 'gbk', 'big5']; // 按照你的需求添加更多的编码方式
|
||||
// let text = '';
|
||||
// for (const encoding of encodings) {
|
||||
// try {
|
||||
// const textDecoder = new TextDecoder(encoding);
|
||||
// text = textDecoder.decode(uint8Array);
|
||||
// break;
|
||||
// } catch (error) {
|
||||
// console.log(`Decoding failed with ${encoding}: ${error}`);
|
||||
// }
|
||||
// }
|
||||
|
||||
// console.log(text);
|
||||
// })
|
||||
// }
|
||||
|
||||
// 发送消息
|
||||
export const sendMessageApi = async (data, that) => {
|
||||
let token = uni.getStorageSync('token')
|
||||
if (!token) {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/login'
|
||||
})
|
||||
return
|
||||
}
|
||||
// #ifdef H5
|
||||
const response = await fetch('https://jx.xiaolinghou.com/api/chat/random', {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
token,
|
||||
},
|
||||
body: JSON.stringify(data)
|
||||
}, );
|
||||
const reader = response.body.getReader();
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
|
||||
let read = () => {
|
||||
return reader.read().then(({
|
||||
done,
|
||||
value
|
||||
}) => {
|
||||
if (done) {
|
||||
that.isSnedMsg = false
|
||||
return;
|
||||
}
|
||||
// 将已下载部分的内容展示出来
|
||||
let text = decoder.decode(value, {
|
||||
stream: true
|
||||
});
|
||||
const match = text.match(/"(.*?)"/);
|
||||
if (match) {
|
||||
text = match[1];
|
||||
}
|
||||
console.log(text);
|
||||
that.messageList[that.messageList.length - 1].message += text
|
||||
// 继续读取下一部分
|
||||
return read();
|
||||
});
|
||||
}
|
||||
|
||||
read()
|
||||
// #endif
|
||||
|
||||
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const requestTask = uni.request({
|
||||
url: "https://jx.xiaolinghou.com/api/chat/random",
|
||||
timeout: 150000,
|
||||
responseType: "text",
|
||||
method: "POST",
|
||||
header: {
|
||||
token
|
||||
},
|
||||
enableChunked: true, //配置这里
|
||||
data,
|
||||
success: response => {
|
||||
console.log(response)
|
||||
},
|
||||
fail: error => {}
|
||||
})
|
||||
const decoder = new TextDecoder("utf8");
|
||||
requestTask.onChunkReceived(function(response) {
|
||||
const uint8Array = new Uint8Array(response.data);
|
||||
let text = String.fromCharCode.apply(null, uint8Array);
|
||||
text = decodeURIComponent(escape(text));
|
||||
const match = text.match(/"(.*?)"/);
|
||||
if (match) {
|
||||
text = match[1]
|
||||
}
|
||||
console.log(text);
|
||||
that.messageList[that.messageList.length - 1].message += text
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// 获取问题列表
|
||||
export const getQuestionApi = () => http.request({
|
||||
method: "GET",
|
||||
url: '/index/article'
|
||||
})
|
||||
|
||||
// 获取价格区间
|
||||
export const getPhotoPriceApi = () => http.request({
|
||||
method: "GET",
|
||||
url: '/index/photo'
|
||||
})
|
||||
|
||||
// 支付
|
||||
export const toPay = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/order/pay',
|
||||
data
|
||||
})
|
||||
// 快递方式列表
|
||||
export const getPostList = () => http.request({
|
||||
method: "GET",
|
||||
url: '/order/express'
|
||||
})
|
||||
|
||||
|
||||
// 代收信件信息
|
||||
export const getAgentBusinessInfoApi = () => http.request({
|
||||
method: "GET",
|
||||
url: '/user/write_back'
|
||||
})
|
||||
|
||||
|
||||
// 保存代收信息
|
||||
export const setAgentBusinessInfoApi = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/set_back',
|
||||
data
|
||||
})
|
||||
|
||||
// 查询订单详情
|
||||
|
||||
export const getOrderInfo = (params) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/info',
|
||||
params
|
||||
})
|
||||
121
request/yyf.js
Normal file
121
request/yyf.js
Normal file
@@ -0,0 +1,121 @@
|
||||
// 存放接口处
|
||||
import http from './request.js';
|
||||
|
||||
// 获取用户信息
|
||||
export const getUserInfo = () => http.request({
|
||||
method: "GET",
|
||||
url: '/user/get_info',
|
||||
});
|
||||
|
||||
// 删除地址
|
||||
export const delAddress = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/address_del',
|
||||
data
|
||||
});
|
||||
|
||||
// 修改地址
|
||||
export const editAddress = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/address_edit',
|
||||
data
|
||||
});
|
||||
|
||||
// 添加地址
|
||||
export const addAddress = (data) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/address_add',
|
||||
data
|
||||
});
|
||||
|
||||
// 收货地址列表
|
||||
export const getAddressList = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/user/address_list',
|
||||
data
|
||||
});
|
||||
|
||||
|
||||
// 下单记录
|
||||
export const getOrderList = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/list',
|
||||
data
|
||||
})
|
||||
|
||||
// 订单详情
|
||||
export const getOrderDetails = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/info',
|
||||
data
|
||||
})
|
||||
|
||||
// 订单数量
|
||||
export const getOrderNum = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/count',
|
||||
data
|
||||
})
|
||||
|
||||
// 查询优惠券
|
||||
export const getCouponList = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/coupon/list',
|
||||
data
|
||||
})
|
||||
|
||||
// 重新支付
|
||||
export const cancelPayment = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/close',
|
||||
data
|
||||
})
|
||||
|
||||
// 重新支付
|
||||
export const rePayment = (data) => http.request({
|
||||
method: "GET",
|
||||
url: '/order/pays',
|
||||
data
|
||||
})
|
||||
|
||||
// 看守所列表
|
||||
export const getJailListApi = (params) => http.request({
|
||||
method: "GET",
|
||||
url: '/index/city',
|
||||
params,
|
||||
})
|
||||
|
||||
// 看守所详情
|
||||
export const getAddrDetails = (params) => http.request({
|
||||
method: "GET",
|
||||
url: '/index/city_info',
|
||||
params,
|
||||
})
|
||||
|
||||
// 看守所详情
|
||||
export const onLogout = (params) => http.request({
|
||||
method: "POST",
|
||||
url: '/user/logout',
|
||||
params,
|
||||
})
|
||||
|
||||
// 充值列表
|
||||
export const getPayList = (params) => http.request({
|
||||
method: "POST",
|
||||
url: '/pay/list',
|
||||
params,
|
||||
})
|
||||
|
||||
// 检查是否支付成功
|
||||
export const checkPayStatus = (params) => http.request({
|
||||
method: "GET",
|
||||
url: '/pay/check',
|
||||
params,
|
||||
})
|
||||
|
||||
// 下单
|
||||
export const onPayment = (params) => http.request({
|
||||
method: "POST",
|
||||
url: '/pay/pay',
|
||||
params,
|
||||
})
|
||||
Reference in New Issue
Block a user