赞
踩
- export const apiResquest = (prams) => { //prams 为我们需要调用的接口API的参数 下面会贴具体代码
- uni.showLoading({
- title: '加载中...',
- mask: true
- });
- // 判断请求类型
- let headerData = {
- 'content-type': 'application/json',
- 'system-type': 3,
- 'Authorization': uni.getStorageSync('token') ? "Bearer " + uni.getStorageSync('token') : ''
- }
- let dataObj = null
- dataObj = prams.query
- return new Promise((resolve, reject) => {
- let ip = process.env.VUE_APP_BASE_URL;
- const token = uni.getStorageSync("token");
- let whiteurl = ['file/add_file', 'user/login', 'get_dictionary_value_info', 'user/reset_password',
- 'user/info', 'file/get_file_info', 'user/edit', 'apiResquest', 'user/reset_pwd', 'region',
- 'auth/department/front','user/list/salesman'
- ]
- let url = ''
- const addip = '/linker/we_chat'
- if (whiteurl.indexOf(prams.url) != -1) {
- url = ip + '/' + prams.url; //请求的网络地址和局地的api地址组合
- } else {
- url = ip + addip + '/' + prams.url; //请求的网络地址和局地的api地址组合
- }
- console.log("请求的url地址");
- console.log(url);
- console.log("请求的参数->",dataObj);
- return uni.request({
- url: url,
- data: dataObj,
- method: prams.method || 'GET',
- header: headerData,
- success(res) {
- resolve(res.data);
- },
- fail(err) {
- reject(err);
- },
- complete(res) {
- console.log('res------------>', res);
- console.log("请求params->", dataObj);
- console.log("url->", url);
- uni.hideLoading({
- success: (response) => {
- // 成功
- },
- complete: response => {
- if (res.data.code != 200) {
- uni.showToast({
- title: res.data.msg,
- duration: 2000,
- icon: "none"
- })
- setTimeout(() => {
- if (res.data.code == 401) {
- uni.clearStorageSync("token")
- uni.clearStorageSync("userInfo")
- uni.clearStorageSync("routes")
- uni.showModal({
- title: '提示',
- content: `是否登录?`,
- cancelText: "取消", // 取消按钮的文字
- confirmText: "确认", // 确认按钮的文字
- showCancel: true, // 是否显示取消按钮,默认为 true
- confirmColor: '#f55850',
- cancelColor: '#39B54A',
- success: (res) => {
- if (res.confirm) {
- uni.switchTab({
- url: "/pages/login/login"
- })
- }
- }
- })
- }
- if (res.data.code == 400) {
- console.log("参数错误");
- }
- if (res.code == 500) {
- console.log("权限问题");
- }
- }, 1000)
- }
- }
- })
- }
- })
- })
- }
- // 公共图片上传网络请求封装
- export const uploadFile = (prams) => {
- return new Promise((resolve, reject) => {
- let ip = process.env.VUE_APP_BASE_URL;
- uni.uploadFile({
- url: ip + prams.url, //请求地址
- filePath: prams.data, //图片路径
- name: 'file',
- header: {
- 'system-type': 3,
- 'Authorization': uni.getStorageSync('token') ? "Bearer " + uni.getStorageSync(
- 'token') : ''
- },
- timeout: 2000,
- // formData: data,
- success: (res) => {
- if (JSON.parse(res.data).code == 200) {
- resolve(JSON.parse(res.data))
- }
- },
- fail: (error) => {
- console.log(error); //抛出异常
- if (error.errMsg == "uploadFile:fail timeout") {
- uni.showToast({
- title: '请求超时',
- mask: true,
- icon: 'error'
- })
- }
- },
- complete: () => {
- uni.hideLoading()
- }
- })
- })
- }
- import {
- data,
- methods
- } from 'uview-ui/libs/mixin/mixin'
- import {
- apiResquest
- } from './request.js'
- //修改日程 添加日程 删除日程
- export const calendar_app = (query, method) => {
- return apiResquest({
- url: 'calendar_app',
- method: method,
- query: {
- ...query
- }
- })
- }
.vue中使用
- import {
- calendar_app,
- userInfo,
- person_data,
- collect_data
- } from '../../api/index.js'
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。