15 changed files with 736 additions and 238 deletions
@ -0,0 +1,130 @@ |
|||
/** |
|||
* 这里是uni-app内置的常用样式变量 |
|||
* |
|||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量 |
|||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App |
|||
* |
|||
*/ |
|||
|
|||
/** |
|||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能 |
|||
* |
|||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件 |
|||
*/ |
|||
|
|||
/* 颜色变量 */ |
|||
|
|||
/* 行为相关颜色 */ |
|||
$uni-color-primary: #007aff; |
|||
$uni-color-success: #4cd964; |
|||
$uni-color-warning: #f0ad4e; |
|||
$uni-color-error: #dd524d; |
|||
|
|||
/* 文字基本颜色 */ |
|||
$uni-text-color: #333; //基本色 |
|||
$uni-text-color-inverse: #fff; //反色 |
|||
$uni-text-color-grey: #999; //辅助灰色,如加载更多的提示信息 |
|||
$uni-text-color-placeholder: #808080; |
|||
$uni-text-color-disable: #c0c0c0; |
|||
|
|||
/* 背景颜色 */ |
|||
$uni-bg-color: #ffffff; |
|||
$uni-bg-color-grey: #f8f8f8; |
|||
$uni-bg-color-hover: #f1f1f1; //点击状态颜色 |
|||
$uni-bg-color-mask: rgba(0, 0, 0, 0.4); //遮罩颜色 |
|||
|
|||
/* 边框颜色 */ |
|||
$uni-border-color: #c8c7cc; |
|||
|
|||
/* 尺寸变量 */ |
|||
|
|||
/* 文字尺寸 */ |
|||
$uni-font-size-sm: 12px; |
|||
$uni-font-size-base: 14px; |
|||
$uni-font-size-lg: 16; |
|||
|
|||
/* 图片尺寸 */ |
|||
$uni-img-size-sm: 20px; |
|||
$uni-img-size-base: 26px; |
|||
$uni-img-size-lg: 40px; |
|||
|
|||
/* Border Radius */ |
|||
$uni-border-radius-sm: 2px; |
|||
$uni-border-radius-base: 3px; |
|||
$uni-border-radius-lg: 6px; |
|||
$uni-border-radius-circle: 50%; |
|||
|
|||
/* 水平间距 */ |
|||
$uni-spacing-row-sm: 5px; |
|||
$uni-spacing-row-base: 10px; |
|||
$uni-spacing-row-lg: 15px; |
|||
|
|||
/* 垂直间距 */ |
|||
$uni-spacing-col-sm: 4px; |
|||
$uni-spacing-col-base: 8px; |
|||
$uni-spacing-col-lg: 12px; |
|||
|
|||
/* 透明度 */ |
|||
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度 |
|||
|
|||
/* 文章场景相关 */ |
|||
$uni-color-title: #2c405a; // 文章标题颜色 |
|||
$uni-font-size-title: 20px; |
|||
$uni-color-subtitle: #555555; // 二级标题颜色 |
|||
$uni-font-size-subtitle: 26px; |
|||
$uni-color-paragraph: #3f536e; // 文章段落颜色 |
|||
$uni-font-size-paragraph: 15px; |
|||
|
|||
/** |
|||
* 下面为当前APP自己定义的公共样式 |
|||
*/ |
|||
.app-container { |
|||
padding: 20px; |
|||
font-size: 14px; |
|||
line-height: 24px; |
|||
} |
|||
|
|||
.u-block { |
|||
padding: 14px; |
|||
&__section { |
|||
margin-bottom: 10px; |
|||
} |
|||
&__title { |
|||
margin-top: 10px; |
|||
font-size: 15px; |
|||
color: $u-content-color; |
|||
margin-bottom: 10px; |
|||
} |
|||
&__flex { |
|||
/* #ifndef APP-NVUE */ |
|||
display: flex; |
|||
/* #endif */ |
|||
} |
|||
} |
|||
|
|||
// 使用了cell组件的icon图片样式 |
|||
.u-cell-icon { |
|||
width: 36rpx; |
|||
height: 36rpx; |
|||
margin-right: 8rpx; |
|||
} |
|||
|
|||
.u-page { |
|||
padding: 15px 15px 40px 15px; |
|||
} |
|||
|
|||
.u-demo-block { |
|||
flex: 1; |
|||
margin-bottom: 23px; |
|||
|
|||
&__content { |
|||
@include flex(column); |
|||
} |
|||
|
|||
&__title { |
|||
font-size: 14px; |
|||
color: rgb(143, 156, 162); |
|||
margin-bottom: 8px; |
|||
@include flex; |
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
/** |
|||
* config 配置项说明 |
|||
* baseUrl = "", // 接口的根地址
|
|||
* tokenName = "Authorization", // 请求头中token的名字,与服务器端对应
|
|||
* loginTimeoutCode : "5000", // 登录超时或失效的情况下,服务器端返回的错误码
|
|||
* loginTimeoutPage = "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面
|
|||
*/ |
|||
module.exports = { |
|||
baseUrl: 'http://192.168.1.105:8001', |
|||
// baseUrl: 'http://jianguan.yyundong.com/api',
|
|||
tokenName: "Authorization", // 请求头中token的名字,与服务器端对应
|
|||
loginTimeoutCode: "5001", // 登录超时或失效的情况下,服务器端返回的错误码
|
|||
loginTimeoutPage: "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面
|
|||
} |
@ -0,0 +1,7 @@ |
|||
export default { |
|||
data() { |
|||
return { |
|||
|
|||
} |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
uni.$u.props.gap.bgColor = '#f3f4f6' |
|||
uni.$u.props.gap.height = '10' |
@ -0,0 +1,16 @@ |
|||
const { |
|||
http |
|||
} = uni.$u |
|||
|
|||
export default { |
|||
login: (params, config = {}) => http.post('/login', params, { |
|||
custom: { |
|||
catchError: true, |
|||
showFailMessage: true |
|||
} |
|||
}), |
|||
sayhello: (params = {}) => http.get("/sayb", params), |
|||
|
|||
// 查看预警信息
|
|||
selectBusinessRiskInfo: (params = {}) => http.post("/v1/businessData/selectBusinessRiskInfo", params) |
|||
} |
@ -0,0 +1,12 @@ |
|||
import request from '@/utils/requester.js' |
|||
|
|||
export default { |
|||
login: (params = {}) => request.post("/portal/v1/sysuser/login", params), |
|||
sayhello: (params = {}) => request.get("/sayb", params), |
|||
getSalesReport: (params = {}) => request.get("/system/reportCenter/getSalesReport", params), |
|||
getGoodsOnWay: (params = {}) => request.get("/system/reportCenter/getGoodsOnWay", params), |
|||
getThresholdAnalysis: (params = {}) => request.get("/system/risk/getThresholdAnalysis", params), |
|||
|
|||
// 查看预警信息
|
|||
selectBusinessRiskInfo: (params = {}) => request.post("/v1/businessData/selectBusinessRiskInfo", params) |
|||
} |
After Width: | Height: | Size: 2.0 KiB |
@ -0,0 +1,13 @@ |
|||
const TokenKey = 'Global-Auth-Token' |
|||
|
|||
const token = { |
|||
|
|||
getToken: function() { |
|||
return uni.getStorageSync(TokenKey) |
|||
}, |
|||
setToken: function(token) { |
|||
return uni.setStorageSync(TokenKey, token) |
|||
} |
|||
} |
|||
|
|||
export default token |
@ -0,0 +1,13 @@ |
|||
// 引入配置
|
|||
import config from '@/common/config' |
|||
// 初始化请求配置
|
|||
uni.$u.http.setConfig((defaultConfig) => { |
|||
/* defaultConfig 为默认全局配置 */ |
|||
defaultConfig.baseURL = config.baseUrl /* 根域名 */ |
|||
return defaultConfig |
|||
}) |
|||
|
|||
module.exports = (vm) => { |
|||
require('./requestInterceptors')(vm) |
|||
require('./responseInterceptors')(vm) |
|||
} |
@ -0,0 +1,35 @@ |
|||
import conf from "@/common/config.js" |
|||
import token from '@/utils/auth.token.js' |
|||
/** |
|||
* 请求拦截 |
|||
* @param {Object} http |
|||
*/ |
|||
module.exports = (vm) => { |
|||
uni.$u.http.interceptors.request.use((config) => { // 可使用async await 做异步操作
|
|||
// 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
|
|||
config.data = config.data || {} |
|||
// 可以在此通过vm引用vuex中的变量,具体值在vm.$store.state中
|
|||
// console.log(vm.$store.state);
|
|||
|
|||
// 设置请求头中token的名字,以及token的值
|
|||
let _token = token.getToken() |
|||
let _tokenName = 'Authorization' |
|||
if (conf.tokenName) { |
|||
_tokenName = conf.tokenName |
|||
} |
|||
config.header[_tokenName] = _token |
|||
|
|||
// 设置针对响应结果的处理方式
|
|||
let _cus = { |
|||
showLoading: true, // 是否显示加载等待框
|
|||
loadingTitle: '加载中', // 加载等待框的提示文字
|
|||
showFailMessage: true, // 返回失败信息是否显示
|
|||
catchError: true, // 是否集中管理Catch,
|
|||
} |
|||
Object.assign(_cus, config.custom) |
|||
config.custom = _cus |
|||
|
|||
return config |
|||
}, (config) => // 可使用async await 做异步操作
|
|||
Promise.reject(config)) |
|||
} |
@ -0,0 +1,130 @@ |
|||
import conf from "@/common/config.js" |
|||
/** |
|||
* 响应拦截 |
|||
* @param {Object} http |
|||
*/ |
|||
module.exports = (vm) => { |
|||
uni.$u.http.interceptors.response.use((response) => { |
|||
/* 对响应成功做点什么 可使用async await 做异步操作*/ |
|||
|
|||
// 自定义参数
|
|||
let _cus = { |
|||
showLoading: true, // 是否显示加载等待框
|
|||
loadingTitle: '加载中', // 加载等待框的提示文字
|
|||
showFailMessage: true, // 返回失败信息是否显示
|
|||
catchError: true, // 是否集中管理Catch,
|
|||
} |
|||
if (response.config && response.config.custom) |
|||
Object.assign(_cus, response.config.custom) |
|||
|
|||
if (200 == response.statusCode) { |
|||
let data = response.data |
|||
if (_cus.catchError) { |
|||
if (data.success) { |
|||
return data.data |
|||
} else { |
|||
let loginTimeoutCode = "5000" |
|||
let loginTimeoutPage = "/pages/login/index" |
|||
if (conf.loginTimeoutCode) { |
|||
loginTimeoutCode = "" + conf.loginTimeoutCode |
|||
} |
|||
if (conf.loginTimeoutPage) { |
|||
loginTimeoutPage = conf.loginTimeoutPage |
|||
} |
|||
if (loginTimeoutCode === data.code) { |
|||
uni.showModal({ |
|||
title: '提示', |
|||
content: '登录过期或失效,请重新登录!', |
|||
showCancel: false, |
|||
success: function(res) { |
|||
uni.reLaunch({ |
|||
url: loginTimeoutPage |
|||
}) |
|||
} |
|||
}); |
|||
} else { |
|||
if (_cus.showFailMessage) { |
|||
uni.showToast({ |
|||
title: data.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
} |
|||
return Promise.reject(data) |
|||
} |
|||
} else { |
|||
return data |
|||
} |
|||
} else { |
|||
console.log('response.statusCode--', response) |
|||
let em = { |
|||
"code": "" + response.statusCode, |
|||
"data": "", |
|||
"msg": "网络请求失败~", |
|||
"success": false, |
|||
"timestamp": new Date().getTime() |
|||
} |
|||
if (res.data) { |
|||
em.msg = res.data |
|||
} |
|||
if (_cus.showFailMessage) { |
|||
uni.showToast({ |
|||
title: em.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
return Promise.reject(em) |
|||
} |
|||
|
|||
// const data = response.data
|
|||
// if (data.code !== 200) { // 服务端返回的状态码不等于200,则reject()
|
|||
// // 如果没有显式定义custom的toast参数为false的话,默认对报错进行toast弹出提示
|
|||
// if (custom.toast !== false) {
|
|||
// uni.$u.toast(data.message)
|
|||
// }
|
|||
// // 如果需要catch返回,则进行reject
|
|||
// if (custom?.catch) {
|
|||
// return Promise.reject(data)
|
|||
// } else {
|
|||
// // 否则返回一个pending中的promise
|
|||
// return new Promise(() => {})
|
|||
// }
|
|||
// }
|
|||
// return data.data || {}
|
|||
}, (error) => { |
|||
console.log('request-fail', error) |
|||
let _opts = { |
|||
showLoading: true, // 是否显示加载等待框
|
|||
loadingTitle: '加载中', // 加载等待框的提示文字
|
|||
showFailMessage: true, // 返回失败信息是否显示
|
|||
catchError: true, // 是否集中管理Catch,
|
|||
} |
|||
if (error.config && error.config.custom) |
|||
Object.assign(_opts, response.config.custom) |
|||
let em = { |
|||
"code": "600", |
|||
"data": "", |
|||
"msg": "网络请求失败~", |
|||
"success": false, |
|||
"timestamp": new Date().getTime() |
|||
} |
|||
if (404 == error.statusCode) { |
|||
em.code = "404" |
|||
em.msg = "404,请求地址错误" |
|||
} |
|||
if (500 == error.statusCode) { |
|||
em.code = "500" |
|||
em.msg = "500,内部服务错误" |
|||
} |
|||
if (_opts.showFailMessage) { |
|||
uni.showToast({ |
|||
title: em.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
return Promise.reject(em) |
|||
}) |
|||
} |
@ -0,0 +1,196 @@ |
|||
/** |
|||
* config 配置项说明 |
|||
* baseUrl = "", // 接口的根地址
|
|||
* tokenName = "Authorization", // 请求头中token的名字,与服务器端对应
|
|||
* loginTimeoutCode : "5000", // 登录超时或失效的情况下,服务器端返回的错误码
|
|||
* loginTimeoutPage = "/pages/login/index", // 登录超时或失效的情况下,跳转到的登录页面
|
|||
*/ |
|||
import config from '@/common/config.js' |
|||
import token from '@/utils/auth.token.js' |
|||
|
|||
/** |
|||
* request options配置项说明 |
|||
* url: '', // url String 是 开发者服务器接口地址
|
|||
* data: {}, // data Object/String/ArrayBuffer 否 请求的参数 App 3.3.7 以下不支持 ArrayBuffer 类型
|
|||
* header: {}, // header Object 否 设置请求的 header,header 中不能设置 Referer。 App、H5端会自动带上cookie,且H5端不可手动修改
|
|||
* method: 'GET', // method String 否 GET 有效值详见下方说明
|
|||
* timeout: 6000, // timeout Number 否 60000 超时时间,单位 ms H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
|||
* showLoading: true, // 是否显示加载等待框
|
|||
* loadingTitle: '加载中', // 加载等待框的提示文字
|
|||
* showFailMessage: true, // 返回失败信息是否显示
|
|||
* catchError: true, // 是否集中管理返回的success为false的情况,如果为false,在请求处判断code值做业务处理
|
|||
*/ |
|||
const request = (options) => { |
|||
let _opts = { |
|||
url: '', // url String 是 开发者服务器接口地址
|
|||
data: {}, // data Object/String/ArrayBuffer 否 请求的参数 App 3.3.7 以下不支持 ArrayBuffer 类型
|
|||
header: {}, // header Object 否 设置请求的 header,header 中不能设置 Referer。 App、H5端会自动带上cookie,且H5端不可手动修改 {"content-type": "application/json"}
|
|||
method: 'GET', // method String 否 GET 有效值详见下方说明
|
|||
timeout: 60000, // timeout Number 否 60000 超时时间,单位 ms H5(HBuilderX 2.9.9+)、APP(HBuilderX 2.9.9+)、微信小程序(2.10.0)、支付宝小程序
|
|||
// dataType String 否 json 如果设为 json,会尝试对返回的数据做一次 JSON.parse
|
|||
// responseType String 否 text 设置响应的数据类型。合法值:text、arraybuffer 支付宝小程序不支持
|
|||
// sslVerify Boolean 否 true 验证 ssl 证书 仅App安卓端支持(HBuilderX 2.3.3+),不支持离线打包
|
|||
// withCredentials Boolean 否 false 跨域请求时是否携带凭证(cookies) 仅H5支持(HBuilderX 2.6.15+)
|
|||
// firstIpv4 Boolean 否 false DNS解析时优先使用ipv4 仅 App-Android 支持 (HBuilderX 2.8.0+)
|
|||
// success Function 否 收到开发者服务器成功返回的回调函数
|
|||
// fail Function 否 接口调用失败的回调函数
|
|||
// complete Function 否 接口调用结束的回调函数(调用成功、失败都会执行)
|
|||
showLoading: true, // 是否显示加载等待框
|
|||
loadingTitle: '加载中', // 加载等待框的提示文字
|
|||
showFailMessage: true, // 返回失败信息是否显示
|
|||
catchError: true, // 是否集中管理Catch,
|
|||
} |
|||
Object.assign(_opts, options) |
|||
let _token = token.getToken() |
|||
let _baseUrl = config.baseUrl |
|||
let _tokenName = config.tokenName |
|||
if (_tokenName) { |
|||
_opts.header[_tokenName] = _token |
|||
} else { |
|||
_opts.header['Authorization'] = _token |
|||
} |
|||
|
|||
return new Promise((resolve, reject) => { |
|||
if (_opts.showLoading) { |
|||
uni.showLoading({ |
|||
title: _opts.loadingTitle || '加载中', |
|||
mask: true |
|||
}) |
|||
} |
|||
return uni.request({ |
|||
url: (_baseUrl || '') + (_opts.url || ''), |
|||
method: _opts.method, |
|||
data: _opts.data || null, |
|||
header: _opts.header, |
|||
timeout: _opts.timeout || 60000, |
|||
success: res => { |
|||
if (200 === res.statusCode) { |
|||
let data = res.data |
|||
if (_opts.catchError) { |
|||
if (data.success) { |
|||
resolve(data.data) |
|||
} else { |
|||
let loginTimeoutCode = "5000" |
|||
let loginTimeoutPage = "/pages/login/index" |
|||
if (config.loginTimeoutCode) { |
|||
loginTimeoutCode = "" + config.loginTimeoutCode |
|||
} |
|||
if (config.loginTimeoutPage) { |
|||
loginTimeoutPage = config.loginTimeoutPage |
|||
} |
|||
if (loginTimeoutCode === data.code) { |
|||
uni.showModal({ |
|||
title: '提示', |
|||
content: '登录过期或失效,请重新登录!', |
|||
showCancel: false, |
|||
success: function(res) { |
|||
uni.reLaunch({ |
|||
url: loginTimeoutPage |
|||
}) |
|||
} |
|||
}); |
|||
} else { |
|||
if (_opts.showFailMessage) { |
|||
uni.showToast({ |
|||
title: data.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
} |
|||
reject(data) |
|||
} |
|||
} else { |
|||
resolve(data) |
|||
} |
|||
} else { |
|||
let em = { |
|||
"code": "404", |
|||
"data": "", |
|||
"msg": "网络请求失败~", |
|||
"success": false, |
|||
"timestamp": new Date().getTime() |
|||
} |
|||
if (res.data) { |
|||
if (res.data.error) { |
|||
if (res.data.path) { |
|||
em.msg = res.data.path + res.data.error |
|||
} else { |
|||
em.msg = res.data.error |
|||
} |
|||
} |
|||
if (res.data.status) { |
|||
em.code = "" + res.data.status |
|||
} |
|||
} |
|||
if (_opts.showFailMessage) { |
|||
uni.showToast({ |
|||
title: em.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
reject(em) |
|||
} |
|||
}, |
|||
fail: error => { |
|||
console.log('request-fail: ', error) |
|||
let em = { |
|||
"code": "600", |
|||
"data": "", |
|||
"msg": "网络请求失败~", |
|||
"success": false, |
|||
"timestamp": new Date().getTime() |
|||
} |
|||
if (error.errMsg) { |
|||
// em.msg = error.errMsg
|
|||
} |
|||
if (_opts.showFailMessage) { |
|||
uni.showToast({ |
|||
title: em.msg, |
|||
icon: 'none', |
|||
duration: 2000, |
|||
}) |
|||
} |
|||
reject(em) |
|||
}, |
|||
complete() { |
|||
if (_opts.showLoading) { |
|||
uni.hideLoading() |
|||
} |
|||
} |
|||
}) |
|||
}) |
|||
|
|||
} |
|||
|
|||
const req = function(url, method = "GET", data = {}, header = {}, options = {}) { |
|||
let _opts = { |
|||
url: url, |
|||
method: method, |
|||
data: data, |
|||
header: header |
|||
} |
|||
Object.assign(options, _opts) |
|||
return request(options) |
|||
} |
|||
|
|||
const get = function(url, data = {}, header = {}, options = {}) { |
|||
return req(url, "GET", data, header, options) |
|||
} |
|||
const post = function(url, data = {}, header = {}, options = {}) { |
|||
return req(url, "POST", data, header, options) |
|||
} |
|||
const formpost = function(url, data = {}, header = {}, options = {}) { |
|||
let _head = { |
|||
"content-type": "application/x-www-form-urlencoded" |
|||
} |
|||
Object.assign(header, _head) |
|||
return req(url, "POST", data, header, options) |
|||
} |
|||
request.get = get |
|||
request.post = post |
|||
request.formpost = formpost |
|||
request.req = req |
|||
|
|||
export default request |
Loading…
Reference in new issue