[盘债计算器]
This commit is contained in:
159
apis/index.js
Normal file
159
apis/index.js
Normal file
@@ -0,0 +1,159 @@
|
||||
|
||||
/**
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
import store from '@/store'
|
||||
|
||||
// 基础配置
|
||||
const config = {
|
||||
apiUrl : 'http://debt.douhuofalv.com/api/', // 正式环境
|
||||
timeout : 60000
|
||||
}
|
||||
|
||||
let loginHintState = false
|
||||
|
||||
// 网络请求
|
||||
const request = (parameter, hideLoding) => {
|
||||
// 检查url配置
|
||||
if(parameter.url === 'undefined' || parameter.url === ''){
|
||||
uni.showToast({
|
||||
title: '请求地址不能为空',
|
||||
icon : 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// 注入header
|
||||
config.header = {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': store.getters.getToken || ''
|
||||
}
|
||||
|
||||
// 加载提示
|
||||
if(!hideLoding) uni.showLoading({
|
||||
title: '加载中',
|
||||
mask : true
|
||||
});
|
||||
|
||||
// 请求实例
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url : config.apiUrl + parameter.url,
|
||||
timeout : config.timeout,
|
||||
header : config.header || {},
|
||||
data : parameter.data || {},
|
||||
method : parameter.method || 'GET',
|
||||
success : res => {
|
||||
if (res.header.Authorization){
|
||||
updateToken('token', res.header.Authorization)
|
||||
}
|
||||
if(res.statusCode === 200){
|
||||
uni.hideLoading()
|
||||
const resolveData = res.data
|
||||
if(resolveData.status_code === 200) {
|
||||
resolve(resolveData.data)
|
||||
return
|
||||
}
|
||||
if(resolveData.status_code === 401) {
|
||||
loginHint()
|
||||
return
|
||||
}
|
||||
reject(resolveData)
|
||||
return
|
||||
}
|
||||
errToast(res.statusCode)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 文件上传
|
||||
const uploading = (paths, driver) => {
|
||||
|
||||
uni.showLoading({
|
||||
title: '上传中',
|
||||
mask : true
|
||||
});
|
||||
// 注入header
|
||||
config.header = {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': store.getters.getToken || ''
|
||||
}
|
||||
// 上传图片
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url : config.apiUrl + 'storage/uploads',
|
||||
files : paths,
|
||||
header : config.header || {},
|
||||
formData: driver || {},
|
||||
success : res=>{
|
||||
if(res.statusCode === 200){
|
||||
uni.hideLoading()
|
||||
let updData = JSON.parse(res.data)
|
||||
if(updData.status_code === 200){
|
||||
resolve(updData.data)
|
||||
return
|
||||
}
|
||||
reject(updData)
|
||||
return
|
||||
}
|
||||
errToast(res.statusCode)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 处理一些http请求错误提示
|
||||
const errToast = (code) => {
|
||||
switch (code){
|
||||
case 404:
|
||||
uni.showToast({
|
||||
title: code + '接口不存在,请联系系统管理员',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case 405:
|
||||
uni.showToast({
|
||||
title: code + '请检查接口请求方式错误',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
case 500:
|
||||
uni.showToast({
|
||||
title: code + '服务端错误,请检查服务器信息',
|
||||
icon : 'none'
|
||||
})
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新token
|
||||
const updateToken = (token) => {
|
||||
store.commit('setToken', token)
|
||||
}
|
||||
|
||||
// 处理登录提示
|
||||
const loginHint = () => {
|
||||
if( loginHintState ) return
|
||||
if(!loginHintState) loginHintState = true
|
||||
updateToken('')
|
||||
uni.showModal({
|
||||
title: '登录提示',
|
||||
content: '您的登录信息已过期,请重新登录',
|
||||
confirmColor: '#8b64fd',
|
||||
showCancel:false,
|
||||
success: res=> {
|
||||
loginHintState = false
|
||||
if (res.confirm) uni.reLaunch({
|
||||
url:'/pages/index/index'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export {
|
||||
request,
|
||||
uploading,
|
||||
config
|
||||
}
|
||||
29
apis/interfaces/authUrl.js
Normal file
29
apis/interfaces/authUrl.js
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
import { request } from '../index'
|
||||
|
||||
// 微信授权登录(获取跳转地址)
|
||||
const authFollow = (data) => {
|
||||
return request({
|
||||
url : 'user/auth/official/url',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 微信登录(传入code)
|
||||
const wechatCode = (data) => {
|
||||
return request({
|
||||
url : 'user/auth/official/openid',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
authFollow,
|
||||
wechatCode
|
||||
}
|
||||
67
apis/interfaces/index.js
Normal file
67
apis/interfaces/index.js
Normal file
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 手太欠
|
||||
* 愿这世界都如故事里一样 美好而动人~
|
||||
*/
|
||||
|
||||
import { request } from '../index'
|
||||
|
||||
// 计算前置接口
|
||||
const Init = (data) => {
|
||||
return request({
|
||||
url : 'init',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// 开始计算
|
||||
const Debt = (data) => {
|
||||
return request({
|
||||
url : 'debt',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 完善用户信息
|
||||
const Info = (data) => {
|
||||
return request({
|
||||
url : 'userinfo',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 查看结果
|
||||
const Lists = (data) => {
|
||||
return request({
|
||||
url : 'lists',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 客户管理
|
||||
const Clients = (data) => {
|
||||
return request({
|
||||
url : 'clients',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
|
||||
// 删除结果
|
||||
const logDel = (log_id) => {
|
||||
return request({
|
||||
url : 'debt/' + log_id,
|
||||
method: 'DELETE'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export {
|
||||
Init,
|
||||
Debt,
|
||||
Info,
|
||||
Lists,
|
||||
Clients,
|
||||
logDel
|
||||
}
|
||||
Reference in New Issue
Block a user