45 changed files with 2118 additions and 1366 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,178 @@ |
|||||||
|
import store from "@/store/index.js"; |
||||||
|
import utils from '@/utils/utils.js' |
||||||
|
import functions from '@/utils/functions.js' |
||||||
|
import { |
||||||
|
host, |
||||||
|
APPKEY |
||||||
|
} from "@/config/host"; |
||||||
|
import base64 from '@/utils/base64.js'; |
||||||
|
import { |
||||||
|
hexMD5 |
||||||
|
} from '@/utils/md5.js' |
||||||
|
// import {
|
||||||
|
// useUserStore
|
||||||
|
// } from "@/store/uaeUserStore";
|
||||||
|
|
||||||
|
// import {
|
||||||
|
// storeToRefs
|
||||||
|
// } from 'pinia';
|
||||||
|
|
||||||
|
// const userStore = useUserStore()
|
||||||
|
|
||||||
|
// const {
|
||||||
|
// HANDLE_ACCTOKEN,
|
||||||
|
// HANDLE_ISLOGIN,
|
||||||
|
// HANDLE_REFTOKEN,
|
||||||
|
// HANDLE_USERINFO
|
||||||
|
// } = userStore
|
||||||
|
|
||||||
|
const service = (params) => { |
||||||
|
|
||||||
|
return new Promise(async (relove, reject) => { |
||||||
|
let refresh_token = uni.getStorageSync('refresh_token') |
||||||
|
let token = uni.getStorageSync('access_token') |
||||||
|
let user = uni.getStorageSync('userinfo') |
||||||
|
let header = {}; |
||||||
|
if (user && token && refresh_token) { |
||||||
|
store.commit('updateislog', true) |
||||||
|
store.commit('updaterftk', refresh_token) |
||||||
|
store.commit('updatetk', token) |
||||||
|
store.commit('updatauser', user) |
||||||
|
header['Blade-Auth'] = `bearer ${store.state.access_token}` |
||||||
|
} else { |
||||||
|
if (!token && params.url.indexOf('oauth/token') == -1) { |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
|
header.Authorization = `Basic ${base64.encode(APPKEY)}` |
||||||
|
|
||||||
|
// return
|
||||||
|
if (params.url.indexOf('blade-auth/oauth/token') != -1) { |
||||||
|
header['Content-Type'] = 'application/x-www-form-urlencoded' |
||||||
|
header['Tenant-Id'] = params.data.tenantId |
||||||
|
// 登录请求时, 加密密码
|
||||||
|
if (params.data.password) params.data.password = hexMD5(params.data.password) |
||||||
|
} |
||||||
|
// uni.showLoading({
|
||||||
|
// title:'请求中',
|
||||||
|
// mask:true
|
||||||
|
// })
|
||||||
|
let urlhd = '' |
||||||
|
if (uni.getStorageSync('setip')) { |
||||||
|
urlhd = uni.getStorageSync('setip') |
||||||
|
} else { |
||||||
|
urlhd = host |
||||||
|
} |
||||||
|
|
||||||
|
let version = '' |
||||||
|
if (!version) { |
||||||
|
// #ifdef APP
|
||||||
|
version = await utils.getversion() |
||||||
|
version = version.version |
||||||
|
// #endif
|
||||||
|
} |
||||||
|
|
||||||
|
function req() { |
||||||
|
let submitData = { |
||||||
|
url: urlhd + params.url, |
||||||
|
data: params.data, |
||||||
|
method: params.method, |
||||||
|
header |
||||||
|
} |
||||||
|
// 当程序在app上运行时, 带上版本号
|
||||||
|
// #ifdef APP
|
||||||
|
submitData = { |
||||||
|
url: urlhd + params.url, |
||||||
|
data: { |
||||||
|
...params.data, |
||||||
|
version |
||||||
|
}, |
||||||
|
method: params.method, |
||||||
|
// dataType: "json",
|
||||||
|
header |
||||||
|
} |
||||||
|
// #endif
|
||||||
|
|
||||||
|
const request = uni.request(submitData) |
||||||
|
|
||||||
|
console.log('request :>> ', request); |
||||||
|
|
||||||
|
request.then(res => { |
||||||
|
// console.log(res);
|
||||||
|
console.log('登录res :>> ', res); |
||||||
|
uni.hideLoading() |
||||||
|
if (res.statusCode == 200) { |
||||||
|
|
||||||
|
let data = res.data; |
||||||
|
// #ifdef APP
|
||||||
|
utils.ttsspke(data.audio || '') |
||||||
|
// #endif
|
||||||
|
if (data.code != 200 && data?.msg) { |
||||||
|
uni.showToast({ |
||||||
|
title: data?.msg || '', |
||||||
|
icon: 'none' |
||||||
|
}) |
||||||
|
} else if (data.audio) { |
||||||
|
uni.showToast({ |
||||||
|
title: data.msg, |
||||||
|
icon: 'none' |
||||||
|
}) |
||||||
|
} |
||||||
|
|
||||||
|
switch (data.code) { |
||||||
|
case 200: |
||||||
|
relove(data); |
||||||
|
break; |
||||||
|
case 203: |
||||||
|
relove(data); |
||||||
|
break; |
||||||
|
default: |
||||||
|
relove(data); |
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
} else { |
||||||
|
if (res.statusCode == 400) { |
||||||
|
relove({}); |
||||||
|
return |
||||||
|
} else if (res.statusCode == 500) { |
||||||
|
functions.error('接口出错,请联系后端开发人员') |
||||||
|
// #ifdef APP
|
||||||
|
utils.ttsspke('接口出错,请联系后端开发人员') |
||||||
|
// #endif
|
||||||
|
return |
||||||
|
} else if (res.statusCode == 401) { |
||||||
|
// 没有权限, 返回login页面
|
||||||
|
uni.reLaunch({ |
||||||
|
url: '/pages/login/login' |
||||||
|
}) |
||||||
|
uni.removeStorage({ |
||||||
|
key: 'access_token' |
||||||
|
}) |
||||||
|
functions.error('请登录') |
||||||
|
return |
||||||
|
} |
||||||
|
functions.error('连接服务器失败') |
||||||
|
// #ifdef APP
|
||||||
|
utils.ttsspke('连接服务器失败') |
||||||
|
// #endif
|
||||||
|
} |
||||||
|
}).catch(err => { |
||||||
|
console.log(err); |
||||||
|
// uni.reLaunch({
|
||||||
|
// url: '/pages/index/index'
|
||||||
|
// })
|
||||||
|
functions.error('请检查是否连接到无线网络') |
||||||
|
// #ifdef APP
|
||||||
|
utils.ttsspke('请检查是否连接到无线网络') |
||||||
|
// #endif
|
||||||
|
uni.hideLoading() |
||||||
|
}) |
||||||
|
} |
||||||
|
req() |
||||||
|
}) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
export default service; |
Loading…
Reference in new issue