mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-17 08:03:49 +08:00
missing file
This commit is contained in:
82
rc-busness/config/common.js
Normal file
82
rc-busness/config/common.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* 存储localStorage
|
||||
*/
|
||||
export const setStore = (name, content) => {
|
||||
if (!name) return
|
||||
if (typeof content !== 'string') {
|
||||
content = JSON.stringify(content)
|
||||
}
|
||||
window.localStorage.setItem(name, content)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取localStorage
|
||||
*/
|
||||
export const getStore = (name) => {
|
||||
if (!name) return
|
||||
return window.localStorage.getItem(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除localStorage
|
||||
*/
|
||||
export const removeStore = name => {
|
||||
if (!name) return
|
||||
window.localStorage.removeItem(name)
|
||||
}
|
||||
|
||||
/**
|
||||
* 过滤周
|
||||
*/
|
||||
const getWeek = (arr) => {
|
||||
if (process.BROWSER_BUILD) {
|
||||
let weekArr = []
|
||||
arr.forEach(function (element) {
|
||||
switch (element) {
|
||||
case '1':
|
||||
weekArr.push('一')
|
||||
break
|
||||
case '2':
|
||||
weekArr.push('二')
|
||||
break
|
||||
case '3':
|
||||
weekArr.push('三')
|
||||
break
|
||||
case '4':
|
||||
weekArr.push('四')
|
||||
break
|
||||
case '5':
|
||||
weekArr.push('五')
|
||||
break
|
||||
case '6':
|
||||
weekArr.push('六')
|
||||
break
|
||||
case '7':
|
||||
weekArr.push('日')
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
})
|
||||
return '每周' + weekArr.join(',') + '上课'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出周几上课
|
||||
*/
|
||||
export const filterWeek = value => {
|
||||
if (process.BROWSER_BUILD) {
|
||||
let week = []
|
||||
if (value.indexOf('@') !== -1) {
|
||||
let arr = value.split('@')
|
||||
arr.forEach(function (element) {
|
||||
week.push(element.slice(2))
|
||||
}, this)
|
||||
return getWeek(week)
|
||||
} else {
|
||||
week.push(value.slice(2))
|
||||
return getWeek(week)
|
||||
}
|
||||
}
|
||||
}
|
||||
5
rc-busness/config/index.js
Normal file
5
rc-busness/config/index.js
Normal file
@@ -0,0 +1,5 @@
|
||||
|
||||
module.exports={
|
||||
//图片路径地址
|
||||
rbs:'http://47.96.75.242:10086/royalcanin/',
|
||||
}
|
||||
20
rc-busness/config/rem.js
Normal file
20
rc-busness/config/rem.js
Normal file
@@ -0,0 +1,20 @@
|
||||
// 隔离作用域,避免全局变量的污染
|
||||
!(function(){
|
||||
function setHtmlFontSize(){
|
||||
// 1.获取手机屏幕宽度
|
||||
var w = document.documentElement.getBoundingClientRect().width; //如果用window.innerwidth的话,改变窗口大小,不能够及时获取窗口大小
|
||||
// console.log(w);
|
||||
// 2.根据屏幕宽度计算html font-size大小, 7.5指的是设计稿的宽度为750,如果在公司中设计稿的尺寸为720,那么应该除以7.2
|
||||
var f = w/40;
|
||||
// 3.设置html 的font-szie
|
||||
document.documentElement.style.fontSize=f+"px";
|
||||
}
|
||||
setHtmlFontSize();
|
||||
window.addEventListener("resize",function(){
|
||||
// setTimeout 是为了解决在苹果手机上的闪屏情况
|
||||
setTimeout(function(){
|
||||
setHtmlFontSize();
|
||||
},300)
|
||||
|
||||
})
|
||||
})();
|
||||
271
rc-busness/config/request.js
Normal file
271
rc-busness/config/request.js
Normal file
@@ -0,0 +1,271 @@
|
||||
import axios from 'axios'
|
||||
|
||||
|
||||
// import Message from '@ele/component/Message'
|
||||
|
||||
|
||||
const instance = axios.create({
|
||||
// baseURL: apiPrefix,
|
||||
// baseURL: 'http://192.168.1.111:7005/',
|
||||
|
||||
// baseURL: 'http://kbptestservice.keyunzhihui.com/', //40
|
||||
|
||||
baseURL: 'http://47.96.75.242:10086/royalcanin/royalcanin/', //52
|
||||
|
||||
// baseURL: 'http://192.168.1.52:8080',
|
||||
// baseURL: 'http://192.168.1.60:8400',
|
||||
// baseURL: '',
|
||||
// baseURL: video,
|
||||
// baseURL: 'http://192.168.1.68:8848/',
|
||||
// baseURL: 'http://192.168.1.40:8080',
|
||||
|
||||
// baseURL: 'http://192.168.33.52:8080',
|
||||
|
||||
|
||||
// baseURL: 'http://192.168.1.68:8580/',
|
||||
// 媒体增删查改
|
||||
// videoURL: 'http://192.168.1.115:7005/',
|
||||
// baseURL: 'http://192.168.33.52:8080/',
|
||||
|
||||
// baseURL: 'http://192.168.1.83:8080',
|
||||
// baseURL:'http://172.19.0.9',
|
||||
|
||||
// withCredentials: true, // send cookies when cross-domain requests
|
||||
timeout: 60000 // request timeout
|
||||
})
|
||||
|
||||
instance.interceptors.request.use(
|
||||
config => {
|
||||
//登录状态下socket断连时,除登出外中断一切请求
|
||||
// if (store.state.user.id && !store.state.socket.online && config.url !== '/account/logout') {
|
||||
// Message.error('请等待与服务器重新连接')
|
||||
// return Promise.reject('')
|
||||
// }
|
||||
|
||||
// header添加token
|
||||
// if (store.state.user.token) {
|
||||
// config.headers['X-Token'] = store.state.user.token
|
||||
// }
|
||||
if (localStorage.getItem('Authorization')) {
|
||||
config.headers.Authorization = localStorage.getItem('Authorization');
|
||||
// config.headers.Authorization ='Bearer eyJhbGciOiJIUzUxMiJ9.eyJyb2xlQ29kZXMiOlsiUk9MRV9SOCIsIlJPTEVfUjE5IiwiUk9MRV9SMTgiLCJST0xFX1I0IiwiUk9MRV9SMTQiLCJST0xFX1IxMSIsIlJPTEVfWiszMiIsIlJPTEVfUjEwIiwiUk9MRV9SMTMiLCJST0xFX1IxMiJdLCJqdGkiOiIxIiwic3ViIjoiYWRtaW4iLCJleHAiOjE2MzI4MTQ1MDN9.M2VWwhih-T8AD1AwYYskH9y-SoOZtHk-qf4PV4Hdb7J6L4Nd7hxKw4JTibGNREjNsmTR1BwMPTDhVgioBSnDfQ'
|
||||
|
||||
}
|
||||
// config.headers.Authorization ='Bearer eyJhbGciOiJIUzUxMiJ9.eyJyb2xlQ29kZXMiOlsiUk9MRV9SOCIsIlJPTEVfUjE5IiwiUk9MRV9SMTgiLCJST0xFX1I0IiwiUk9MRV9SMTQiLCJST0xFX1IxMSIsIlJPTEVfWiszMiIsIlJPTEVfUjEwIiwiUk9MRV9SMTMiLCJST0xFX1IxMiJdLCJqdGkiOiIxIiwic3ViIjoiYWRtaW4iLCJleHAiOjE2MzI4MTQ1MDN9.M2VWwhih-T8AD1AwYYskH9y-SoOZtHk-qf4PV4Hdb7J6L4Nd7hxKw4JTibGNREjNsmTR1BwMPTDhVgioBSnDfQ'
|
||||
return config
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
)
|
||||
|
||||
instance.interceptors.response.use(
|
||||
response => {
|
||||
const res = response.data, { responseType = 'json' } = response.config
|
||||
console.log(res.errorCode);
|
||||
if (res.errorCode === 6001) {
|
||||
console.log('66666');
|
||||
localStorage.removeItem("Authorization");
|
||||
removeToken("Token")
|
||||
res && Notification.error({
|
||||
title: '错误',
|
||||
message: res.data.errorMessage || '请求错误,请稍后重试'
|
||||
})
|
||||
return Promise.reject(res)
|
||||
}
|
||||
if (res.errorCode === 6002) {
|
||||
console.log('6002');
|
||||
localStorage.removeItem("Authorization");
|
||||
removeToken("Token")
|
||||
|
||||
res && Notification.error({
|
||||
title: '错误',
|
||||
message: res.data.errorMessage || '账号或密码错误,请重试'
|
||||
})
|
||||
return Promise.reject(res)
|
||||
|
||||
}
|
||||
if (res.errorCode === 1001) {
|
||||
console.log('1001');
|
||||
localStorage.removeItem("Authorization");
|
||||
removeToken("Token")
|
||||
window.location.href='/#/login'
|
||||
res && Notification.error({
|
||||
title: '错误',
|
||||
message: res.data.errorMessage || '请求错误,请稍后重试'
|
||||
})
|
||||
return Promise.reject(res)
|
||||
|
||||
}
|
||||
if (res.errorCode === 1000) {
|
||||
localStorage.removeItem("Authorization");
|
||||
removeToken("Token")
|
||||
localStorage.removeItem("elecloud");
|
||||
console.log('---这是状态码')
|
||||
window.location.href='/#/login'
|
||||
// res && Notification.error({
|
||||
// title: '错误',
|
||||
// message: res.data.errorMessage || '请求错误,请稍后重试'
|
||||
// })
|
||||
return Promise.reject(res)
|
||||
|
||||
}
|
||||
if (res.errorCode === 1002) {
|
||||
localStorage.removeItem("Authorization");
|
||||
removeToken("Token")
|
||||
window.location.href='/#/login'
|
||||
res && Notification.error({
|
||||
title: '错误',
|
||||
message: res.data.errorMessage || '请求错误,请稍后重试'
|
||||
})
|
||||
return Promise.reject(res)
|
||||
|
||||
}
|
||||
//当返回类型非{status,data,msg}的接口请求时,不使用status来判断请求是否成功
|
||||
if ((!('status' in res)) || (res.status === 200)) {
|
||||
//当返回类型为json时,返回response.data
|
||||
return responseType === 'json' ? res : response
|
||||
}
|
||||
|
||||
//服务器异常
|
||||
if (res.status === 500) {
|
||||
// Message.error(res.msg || '操作失败')
|
||||
return Promise.reject(res.msg)
|
||||
}
|
||||
|
||||
//未登录
|
||||
// if (res.status === 6001) {
|
||||
// if (store.state.user.Authorization) return Promise.reject()
|
||||
// return MessageBox.alert('请登录后重试', {
|
||||
// type: 'warning',
|
||||
// beforeClose: (action, instance, done) => {
|
||||
// store.dispatch('user/logout').then(done)
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
//没有权限
|
||||
if (res.status === 403) {
|
||||
// Message.error(res.msg || '没有权限进行该操作')
|
||||
return Promise.reject(res.msg)
|
||||
}
|
||||
if (res.status === 400) {
|
||||
// Message.error(res.msg || '没有权限进行该操作')
|
||||
return Promise.reject(res)
|
||||
}
|
||||
// if(res.)
|
||||
|
||||
//其他错误
|
||||
// Message.error(res.msg || '接口有误')
|
||||
return Promise.reject(res)
|
||||
},
|
||||
error => {
|
||||
// console.log('error',error.response);
|
||||
if (axios.isCancel(error)) return
|
||||
error && Notification.error({
|
||||
title: '错误',
|
||||
// message: '请求错误,请稍后重试'
|
||||
message: error.response.data.message || '请求错误,请稍后重试'
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
class Api {
|
||||
/**
|
||||
* 数据接口定义
|
||||
* @param url 请求url,不带参数
|
||||
* @param arg 对传入参数的处理方法,返回值将作为axios[get,post]的第二个参数
|
||||
* @param chain 形参为请求返回的promise
|
||||
* @param method 请求方法,小写,get、post...
|
||||
*/
|
||||
constructor(url, arg, chain, method) {
|
||||
this.url = url
|
||||
this.arg = arg
|
||||
this.chain = chain
|
||||
this.method = method
|
||||
}
|
||||
|
||||
request(...args) {
|
||||
const params = this.arg ? this.arg(...args) : undefined
|
||||
const promise = instance[this.method](this.url, params).catch(e => console.error(e)
|
||||
|
||||
)
|
||||
return this.chain ? this.chain(promise) : promise
|
||||
}
|
||||
}
|
||||
|
||||
class ApiJson {
|
||||
/**
|
||||
* 数据接口定义
|
||||
* @param url 请求url,不带参数
|
||||
* @param arg 对传入参数的处理方法,返回值将作为axios[get,post]的第二个参数
|
||||
* @param chain 形参为请求返回的promise
|
||||
* @param method 请求方法,小写,get、post...
|
||||
* @param header 请求方法,头部信息Json
|
||||
*/
|
||||
constructor(url, arg, chain, method, header) {
|
||||
this.url = url
|
||||
this.arg = arg
|
||||
this.chain = chain
|
||||
this.method = method
|
||||
this.header = header
|
||||
}
|
||||
|
||||
request(...args) {
|
||||
const params = this.arg ? this.arg(...args) : undefined
|
||||
const promise = instance[this.method](this.url, params, { headers: { 'Content-Type': 'application/json' } }).catch(e => console.error(e))
|
||||
return this.chain ? this.chain(promise) : promise
|
||||
}
|
||||
}
|
||||
|
||||
export class PostApi extends Api {
|
||||
constructor(url, arg, chain) {
|
||||
if (!arg) arg = data => data
|
||||
super(url, arg, chain, 'post')
|
||||
}
|
||||
}
|
||||
|
||||
export class GetApi extends Api {
|
||||
constructor(url, arg, chain) {
|
||||
super(url, arg, chain, 'get')
|
||||
}
|
||||
}
|
||||
|
||||
export class DeleteApi extends Api {
|
||||
constructor(url, arg, chain) {
|
||||
super(url, arg, chain, 'delete')
|
||||
}
|
||||
}
|
||||
export class PatchApi extends Api {
|
||||
constructor(url, arg, chain) {
|
||||
if (!arg) arg = data => data
|
||||
super(url, arg, chain, 'patch')
|
||||
}
|
||||
}
|
||||
|
||||
export class PutApi extends Api {
|
||||
constructor(url, arg, chain) {
|
||||
if (!arg) arg = data => data
|
||||
|
||||
super(url, arg, chain, 'put')
|
||||
}
|
||||
}
|
||||
|
||||
export class PostJsonApi extends ApiJson {
|
||||
constructor(url, arg, chain) {
|
||||
if (!arg) arg = data => data
|
||||
let header = { headers: { 'Content-Type': 'application/json' } }
|
||||
super(url, arg, chain, 'post', header)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class DeleteJsonApi extends ApiJson {
|
||||
constructor(url, arg, chain) {
|
||||
super(url, arg, chain, 'delete')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
export default instance
|
||||
Reference in New Issue
Block a user