|
@@ -0,0 +1,450 @@
|
|
|
|
+import {
|
|
|
|
+ config
|
|
|
|
+} from './config.js'
|
|
|
|
+import {
|
|
|
|
+ tansParams
|
|
|
|
+} from "./util.js";
|
|
|
|
+
|
|
|
|
+export const apiResquest = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = config.base_url + prams.url;
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: '加载中',
|
|
|
|
+ mask: true
|
|
|
|
+ });
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: {
|
|
|
|
+ ...prams.data
|
|
|
|
+ },
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/json;charset=utf-8',
|
|
|
|
+ // 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ // 'Authorization': 'dbe91a38-a310-4c10-8d29-3e025e80bbb3'
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+export const apiResquestOutside = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = prams.url;
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: '加载中',
|
|
|
|
+ mask: true
|
|
|
|
+ });
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: {
|
|
|
|
+ ...prams.data
|
|
|
|
+ },
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/json;charset=utf-8',
|
|
|
|
+ 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+export const apiResquestForm = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = config.base_url + prams.url;
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: '加载中',
|
|
|
|
+ mask: true
|
|
|
|
+ });
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: {
|
|
|
|
+ ...prams.data
|
|
|
|
+ },
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded',
|
|
|
|
+ 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+export const apiResquestJsonList = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = config.base_url + prams.url;
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: '加载中',
|
|
|
|
+ mask: true
|
|
|
|
+ });
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: prams.data,
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/json',
|
|
|
|
+ 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+export const apiResquestFormVideo = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = uni.getStorageSync('cameraExtranetAgent') + prams.url;
|
|
|
|
+ uni.showLoading({
|
|
|
|
+ title: '加载中',
|
|
|
|
+ mask: true
|
|
|
|
+ });
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: {
|
|
|
|
+ ...prams.data
|
|
|
|
+ },
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded',
|
|
|
|
+ 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+export const apiResquestTimer = (prams) => {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let url = config.base_url + prams.url;
|
|
|
|
+ // get请求映射params参数
|
|
|
|
+ if (prams.method === 'GET' && prams.data) {
|
|
|
|
+ url = url + '?' + tansParams(prams.data);
|
|
|
|
+ url = url.slice(0, -1);
|
|
|
|
+ prams.data = {};
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return uni.request({
|
|
|
|
+ url: url,
|
|
|
|
+ data: {
|
|
|
|
+ ...prams.data
|
|
|
|
+ },
|
|
|
|
+ method: prams.method,
|
|
|
|
+ header: {
|
|
|
|
+ 'content-type': 'application/json;charset=utf-8',
|
|
|
|
+ 'Authorization': uni.getStorageSync('token')
|
|
|
|
+ },
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 成功
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ if (res.statusCode == 200) {
|
|
|
|
+ if (res.data.code == 200) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ } else if (res.data.code == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: res.data.message,
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ } else if (res.statusCode == 401) {
|
|
|
|
+ loginTimeout();
|
|
|
|
+ } else {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '连接异常,请联系管理员.',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ // 失败
|
|
|
|
+ uni.hideLoading()
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: '出错啦~请联系管理员!',
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ complete: () => {
|
|
|
|
+ // 完成
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+//登录超时-退出至登录页面
|
|
|
|
+export function loginTimeout(params) {
|
|
|
|
+ uni.showToast({
|
|
|
|
+ mask: true,
|
|
|
|
+ icon: "none",
|
|
|
|
+ position: "center",
|
|
|
|
+ title: "登录超时,请重新登录~",
|
|
|
|
+ duration: 2000
|
|
|
|
+ });
|
|
|
|
+ uni.removeStorageSync('token');
|
|
|
|
+ uni.removeStorageSync('userId');
|
|
|
|
+ uni.removeStorageSync('userType');
|
|
|
|
+ setTimeout(function() {
|
|
|
|
+ uni.redirectTo({
|
|
|
|
+ url: '/pages/views/login/login',
|
|
|
|
+ });
|
|
|
|
+ }, 2000);
|
|
|
|
+}
|