mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-22 19:13:28 +08:00
admin-import
This commit is contained in:
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
import axios from 'axios'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import router from '@/router/index'
|
||||
import { localGet } from './index'
|
||||
import config from '~/config'
|
||||
|
||||
|
||||
// 这边由于后端没有区分测试和正式,姑且都写成一个接口。
|
||||
axios.defaults.baseURL = config[import.meta.env.MODE].baseUrl
|
||||
// 携带 cookie,对目前的项目没有什么作用,因为我们是 token 鉴权
|
||||
axios.defaults.withCredentials = true
|
||||
// 请求头,headers 信息
|
||||
axios.defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
|
||||
axios.defaults.headers['token'] = localGet('token') || ''
|
||||
// 默认 post 请求,使用 application/json 形式
|
||||
axios.defaults.headers.post['Content-Type'] = 'application/json'
|
||||
|
||||
// 请求拦截器,内部根据返回值,重新组装,统一管理。
|
||||
axios.interceptors.response.use(res => {
|
||||
if (typeof res.data !== 'object') {
|
||||
ElMessage.error('服务端异常!')
|
||||
return Promise.reject(res)
|
||||
}
|
||||
if (res.data.resultCode != 200) {
|
||||
if (res.data.message) ElMessage.error(res.data.message)
|
||||
if (res.data.resultCode == 419) {
|
||||
router.push({ path: '/login' })
|
||||
}
|
||||
return Promise.reject(res.data)
|
||||
}
|
||||
|
||||
return res.data.data
|
||||
})
|
||||
|
||||
export default axios
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
export function localGet (key) {
|
||||
const value = window.localStorage.getItem(key)
|
||||
try {
|
||||
return JSON.parse(window.localStorage.getItem(key))
|
||||
} catch (error) {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
export function localSet (key, value) {
|
||||
window.localStorage.setItem(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
export function localRemove (key) {
|
||||
window.localStorage.removeItem(key)
|
||||
}
|
||||
|
||||
// 判断内容是否含有表情字符,现有数据库不支持。
|
||||
export function hasEmoji (str = '') {
|
||||
const reg = /[^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n]/g;
|
||||
return str.match(reg) && str.match(reg).length
|
||||
}
|
||||
|
||||
// 单张图片上传
|
||||
export const uploadImgServer = 'http://backend-api-02.newbee.ltd/manage-api/v1/upload/file'
|
||||
// 多张图片上传
|
||||
export const uploadImgsServer = 'http://backend-api-02.newbee.ltd/manage-api/v1/upload/files'
|
||||
|
||||
export const pathMap = {
|
||||
login: '登录',
|
||||
introduce: '系统介绍',
|
||||
dashboard: '大盘数据',
|
||||
add: '添加商品',
|
||||
swiper: '轮播图配置',
|
||||
hot: '热销商品配置',
|
||||
new: '新品上线配置',
|
||||
recommend: '为你推荐配置',
|
||||
category: '分类管理',
|
||||
level2: '分类二级管理',
|
||||
level3: '分类三级管理',
|
||||
good: '商品管理',
|
||||
guest: '会员管理',
|
||||
order: '订单管理',
|
||||
order_detail: '订单详情',
|
||||
account: '修改账户'
|
||||
}
|
||||
Reference in New Issue
Block a user