123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import config from "@/config";
- function request(options) {
- return new Promise((resolve, reject) => {
- let header = options.header || {
- 'Content-Type': 'application/json'
- }
- if (uni.getStorageSync('token')) header['token'] = uni.getStorageSync('token');
- uni.request({
- url: config.imBaseUrl + options.url, // 服务器url
- method: options.method || 'GET', // 请求方法,默认为GET
- data: options.data || {}, // 请求参数
- header: header, // 设置请求的 header
- success: (res) => {
- // 请求成功
- if (res.statusCode === 200) {
- resolve(res.data);
- if (res.data.code != 200) uni.showToast({
- title: res.data.message,
- icon: 'none'
- })
- } else {
- // 可以根据项目要求修改错误处理
- reject(res.data);
- uni.hideLoading();
- }
- },
- fail: (err) => {
- // 请求失败处理
- uni.showToast({
- title: '出错了,请联系管理员~',
- icon: 'none'
- })
- reject(err);
- uni.hideLoading();
- },
- });
- });
- }
- /*
- * 获取公海
- *
- *
- */
- export function login(data) {
- return request({
- url: `/user/token/get`,
- method: 'post',
- data: data
- })
- }
|