123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- const APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
- const APPLICATION_JSON_UTF8_FORM = 'application/x-www-form-urlencoded;charset=UTF-8';
- const RESPONSE_OK = 20000;
- const TOKEN_BEOVERDUE = 40001;
- const TOKEN = wx.getStorageSync('accessToken') == null ? '' : wx.getStorageSync('accessToken');
- const HOST = 'https://wordpad-api-test.efunbox.cn';
- const httpData = {
- userId: 'test'
- }
- const interfaces = {
-
-
-
- getOrganizeAll: '/organize/all',
-
- getSchoolOrClass: '/school',
-
- phoneRegister: '/tch/user/register',
-
- getVerifyCode: '/tch/user/verifyCode',
-
- pwdPhoneLogin: '/tch/user/login',
-
- updatePassWord: '/tch/user/updatePassword',
-
- updateUserInfo: '/tch/user',
-
- getUserById: '/tch/user/getUserById',
-
- getDeviceById: '/tch/device/',
-
- getDevideIdByRSC: '/tch/device/site',
-
- postDeviceFault: '/tch/fault',
-
- uploadImageList: '/file/upload',
-
- getDeviceFault: '/tch/fault',
-
- getFaultInfoByDevId: '/tch/fault/',
-
- createLess: '/tch/lesson/',
-
- getDocumentFile: '/tch/document',
-
- }
- function fun(url: String, type: any, data: any, otherType: any) {
- if (!TOKEN) {
-
- console.log("Token:", TOKEN)
- }
- let promise = new Promise((resolve, reject) => {
- wx.request({
- url: HOST + url,
- method: type,
- data: type == 'GET' ? data : JSON.stringify(data),
- header: {
- 'content-type': otherType ? APPLICATION_JSON_UTF8_FORM : APPLICATION_JSON_UTF8_VALUE,
- 'access-token': wx.getStorageSync('accessToken') == null ? '' : wx.getStorageSync('accessToken'),
- 'userId': httpData.userId
- },
- success: function (res: any) {
- wx.stopPullDownRefresh();
- if (res) {
- resolve(res)
- } else {
- wx.showToast({
- title: res.data.subMsg ? res.data.subMsg : res.data.msg,
- icon: 'none',
- duration: 2000
- })
- }
- },
- fail: function (res: any) {
- wx.stopPullDownRefresh();
- reject(res)
- }
- })
- })
- return promise
- }
- function uploadFile(url: String, filePath: string, fileName: string, formData: any) {
- let promise = new Promise((resolve, reject) => {
- wx.uploadFile({
- url: HOST + url,
- filePath: filePath,
- name: fileName,
- formData: formData,
- success(res: any) {
- resolve(res)
-
-
- },
- fail(res: any) {
- reject(res)
- }
- })
- })
- return promise;
- }
- function downLoadFile(url: string, onProgress: any) {
- let promise = new Promise((resolve, reject) => {
- let download = wx.downloadFile({
- url: url,
- success(res: any) {
- resolve(res)
-
-
- },
- fail(res: any) {
- reject(res)
- }
- })
- download.onProgressUpdate((res) => {
- onProgress(res)
- })
- })
- return promise;
- }
- export const httpUtil = {
- httpData,
- interfaces,
- wxGet: function (url: String, data: any) {
- return fun(url, 'GET', data, null)
- },
- wxPost: function (url: String, data: any) {
- return fun(url, 'POST', data, null)
- },
- wxFormPost: function (url: String, data: any) {
- return fun(url, 'POST', data, 'formPost')
- },
- wxPut: function (url: String, data: any) {
- return fun(url, 'PUT', data, null)
- },
- wxDel: function (url: String, data: any) {
- return fun(url, 'DELETE', data, null)
- },
- wxUploadFile: function (url: String, filePath: string, fileName: string, formData: any) {
- return uploadFile(url, filePath, fileName, formData)
- },
- wxDownLoadFile: function (url: string, onProgress: any) {
- return downLoadFile(url, onProgress)
- }
- }
|