第一次提交
This commit is contained in:
15
web/src/utils/auth.js
Normal file
15
web/src/utils/auth.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const TokenKey = 'vue_admin_template_token'
|
||||
|
||||
export function getToken() {
|
||||
return Cookies.get(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
return Cookies.set(TokenKey, token)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return Cookies.remove(TokenKey)
|
||||
}
|
20
web/src/utils/confirm.js
Normal file
20
web/src/utils/confirm.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { MessageBox, Message } from 'element-ui'
|
||||
|
||||
const confirm = (text) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
MessageBox.confirm(text?text:'确定要执行此操作吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
resolve(true)
|
||||
}).catch(() => {
|
||||
Message.info('已取消')
|
||||
reject(false)
|
||||
})
|
||||
}).catch(() => {
|
||||
// 可对错误进行处理
|
||||
})
|
||||
}
|
||||
|
||||
export default confirm
|
15
web/src/utils/directive.js
Normal file
15
web/src/utils/directive.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import Vue from 'vue'
|
||||
import store from '../store'
|
||||
/**
|
||||
* @export 自定义指令 https://juejin.cn/post/6844903824704929799
|
||||
*/
|
||||
export function directive() {
|
||||
Vue.directive('hasPerms', {
|
||||
//inserted dom渲染后再执行删除节点
|
||||
inserted(el, binding) {
|
||||
// 一行三目运算符就可
|
||||
!store.getters.perms.includes(binding.value) ? el.parentNode.removeChild(el) : {}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
17
web/src/utils/formValidate.js
Normal file
17
web/src/utils/formValidate.js
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
const formValid = (vue) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
vue.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
resolve(true)
|
||||
} else {
|
||||
reject(false)
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}).catch(reason => {
|
||||
// 可对错误进行处理
|
||||
})
|
||||
}
|
||||
|
||||
export default formValid
|
10
web/src/utils/get-page-title.js
Normal file
10
web/src/utils/get-page-title.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import defaultSettings from '@/settings'
|
||||
|
||||
const title = defaultSettings.title || 'Vue Admin Template'
|
||||
|
||||
export default function getPageTitle(pageTitle) {
|
||||
if (pageTitle) {
|
||||
return `${pageTitle} - ${title}`
|
||||
}
|
||||
return `${title}`
|
||||
}
|
432
web/src/utils/index.js
Normal file
432
web/src/utils/index.js
Normal file
@@ -0,0 +1,432 @@
|
||||
/**
|
||||
* Created by PanJiaChen on 16/11/18.
|
||||
*/
|
||||
import { Message } from 'element-ui'
|
||||
import store from '@/store/index';
|
||||
/**
|
||||
* Parse the time to string
|
||||
* @param {(Object|string|number)} time
|
||||
* @param {string} cFormat
|
||||
* @returns {string | null}
|
||||
*/
|
||||
export function parseTime(time, cFormat) {
|
||||
if (arguments.length === 0 || !time) {
|
||||
return null
|
||||
}
|
||||
const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
|
||||
let date
|
||||
if (typeof time === 'object') {
|
||||
date = time
|
||||
} else {
|
||||
if ((typeof time === 'string')) {
|
||||
if ((/^[0-9]+$/.test(time))) {
|
||||
// support "1548221490638"
|
||||
time = parseInt(time)
|
||||
} else {
|
||||
// support safari
|
||||
// https://stackoverflow.com/questions/4310953/invalid-date-in-safari
|
||||
time = time.replace(new RegExp(/-/gm), '/')
|
||||
}
|
||||
}
|
||||
|
||||
if ((typeof time === 'number') && (time.toString().length === 10)) {
|
||||
time = time * 1000
|
||||
}
|
||||
date = new Date(time)
|
||||
}
|
||||
const formatObj = {
|
||||
y: date.getFullYear(),
|
||||
m: date.getMonth() + 1,
|
||||
d: date.getDate(),
|
||||
h: date.getHours(),
|
||||
i: date.getMinutes(),
|
||||
s: date.getSeconds(),
|
||||
a: date.getDay()
|
||||
}
|
||||
const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
||||
const value = formatObj[key]
|
||||
// Note: getDay() returns 0 on Sunday
|
||||
if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
|
||||
return value.toString().padStart(2, '0')
|
||||
})
|
||||
return time_str
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} time
|
||||
* @param {string} option
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatTime(time, option) {
|
||||
if (('' + time).length === 10) {
|
||||
time = parseInt(time) * 1000
|
||||
} else {
|
||||
time = +time
|
||||
}
|
||||
const d = new Date(time)
|
||||
const now = Date.now()
|
||||
|
||||
const diff = (now - d) / 1000
|
||||
|
||||
if (diff < 30) {
|
||||
return '刚刚'
|
||||
} else if (diff < 3600) {
|
||||
// less 1 hour
|
||||
return Math.ceil(diff / 60) + '分钟前'
|
||||
} else if (diff < 3600 * 24) {
|
||||
return Math.ceil(diff / 3600) + '小时前'
|
||||
} else if (diff < 3600 * 24 * 2) {
|
||||
return '1天前'
|
||||
}
|
||||
if (option) {
|
||||
return parseTime(time, option)
|
||||
} else {
|
||||
return (
|
||||
d.getMonth() +
|
||||
1 +
|
||||
'月' +
|
||||
d.getDate() +
|
||||
'日' +
|
||||
d.getHours() +
|
||||
'时' +
|
||||
d.getMinutes() +
|
||||
'分'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function param2Obj(url) {
|
||||
const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
|
||||
if (!search) {
|
||||
return {}
|
||||
}
|
||||
const obj = {}
|
||||
const searchArr = search.split('&')
|
||||
searchArr.forEach(v => {
|
||||
const index = v.indexOf('=')
|
||||
if (index !== -1) {
|
||||
const name = v.substring(0, index)
|
||||
const val = v.substring(index + 1, v.length)
|
||||
obj[name] = val
|
||||
}
|
||||
})
|
||||
return obj
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Function} func
|
||||
* @param {number} wait
|
||||
* @param {boolean} immediate
|
||||
* @return {*}
|
||||
*/
|
||||
export function debounce(func, wait, immediate) {
|
||||
let timeout, args, context, timestamp, result
|
||||
|
||||
const later = function() {
|
||||
// 据上一次触发时间间隔
|
||||
const last = +new Date() - timestamp
|
||||
|
||||
// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait
|
||||
if (last < wait && last > 0) {
|
||||
timeout = setTimeout(later, wait - last)
|
||||
} else {
|
||||
timeout = null
|
||||
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
|
||||
if (!immediate) {
|
||||
result = func.apply(context, args)
|
||||
if (!timeout) context = args = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return function(...args) {
|
||||
context = this
|
||||
timestamp = +new Date()
|
||||
const callNow = immediate && !timeout
|
||||
// 如果延时不存在,重新设定延时
|
||||
if (!timeout) timeout = setTimeout(later, wait)
|
||||
if (callNow) {
|
||||
result = func.apply(context, args)
|
||||
context = args = null
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just a simple version of deep copy
|
||||
* Has a lot of edge cases bug
|
||||
* If you want to use a perfect deep copy, use lodash's _.cloneDeep
|
||||
* @param {Object} source
|
||||
* @returns {Object}
|
||||
*/
|
||||
export function deepClone(source) {
|
||||
if (!source && typeof source !== 'object') {
|
||||
throw new Error('error arguments', 'deepClone')
|
||||
}
|
||||
const targetObj = source.constructor === Array ? [] : {}
|
||||
Object.keys(source).forEach(keys => {
|
||||
if (source[keys] && typeof source[keys] === 'object') {
|
||||
targetObj[keys] = deepClone(source[keys])
|
||||
} else {
|
||||
targetObj[keys] = source[keys]
|
||||
}
|
||||
})
|
||||
return targetObj
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否为空
|
||||
* @param obj
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isEmpty(obj) {
|
||||
if (typeof obj == "undefined" || obj == null || obj == "" || obj == undefined || obj == " " || obj == "undefined") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断值是否不为空
|
||||
* @param obj
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isNotEmpty(obj) {
|
||||
if (typeof obj == "undefined" || obj == null || obj == "" || obj == undefined || obj == " " ||obj == "undefined") {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//成功提示
|
||||
export function success(msg,sec){
|
||||
return Message({
|
||||
message: msg,
|
||||
type: 'success',
|
||||
duration: (sec?sec:3) * 1000
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误提示
|
||||
* @param obj
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function error(msg,sec) {
|
||||
return Message({
|
||||
message: msg,
|
||||
type: 'error',
|
||||
duration: (sec?sec:3) * 1000
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//设置表单字段
|
||||
export function setRequiredFields(requiredFields){
|
||||
let rules = {};
|
||||
requiredFields.forEach(filed=>{
|
||||
rules[filed] = [
|
||||
{required: true, message: '请输入必填项', trigger: 'blur'}
|
||||
]
|
||||
})
|
||||
return rules;
|
||||
}
|
||||
|
||||
//获取 下拉选择的选择
|
||||
export function getSelectObj(val, opt,key) {
|
||||
return opt.find(item => {
|
||||
return item[key] === val
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function regroupCascaderData(
|
||||
id, //要寻找的唯一值
|
||||
data, // 列表总数据
|
||||
key = 'label', //列表总数据 的key
|
||||
val = 'value', //列表总数据 的value
|
||||
list = 'children' //列表总数据 下属关系的key
|
||||
) {
|
||||
let _allObj = {}
|
||||
const _allArr = []
|
||||
const setData = function(data) {
|
||||
let Obj
|
||||
for (const item of data) {
|
||||
Obj = {
|
||||
[key]: item[key],
|
||||
[val]: item[val]
|
||||
}
|
||||
if (item[val] == id) {
|
||||
Obj['isOk'] = true //如果条件符合,接下来就不会再判断
|
||||
return Obj
|
||||
} else if (item[list] && item[list].length) {
|
||||
Obj[list] = setData(item[list])
|
||||
if (Obj[list] && Obj[list]['isOk']) {
|
||||
Obj['isOk'] = true
|
||||
return Obj
|
||||
}
|
||||
} else {
|
||||
Obj = null
|
||||
}
|
||||
}
|
||||
return Obj
|
||||
}
|
||||
const getObjData = function(data) {
|
||||
// 递归向数组中填充数据
|
||||
_allArr.push(data[val])
|
||||
if (data[list]) {
|
||||
getObjData(data[list])
|
||||
}
|
||||
}
|
||||
_allObj = setData(data)
|
||||
getObjData(_allObj)
|
||||
return {
|
||||
obj: _allObj,
|
||||
arr: _allArr
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//数组转字符串
|
||||
export function arrayToString(array) {
|
||||
let str = '';
|
||||
for(let item of array){
|
||||
str += (item+",")
|
||||
}
|
||||
if(str.length>0){
|
||||
str = str.slice(0,str.length-1)
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
//获取级联obj
|
||||
export function getCascaderObj(val, opt){
|
||||
return val.map(function (value, index, array) {
|
||||
for (var itm of opt) {
|
||||
if (itm.value == value) {
|
||||
opt = itm.children;
|
||||
return itm;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
//input只能输入非中文
|
||||
export function clearChinese(obj) {
|
||||
obj.target.value = obj.target.value.replace(/[\u4E00-\u9FA5]/g, "")
|
||||
}
|
||||
|
||||
|
||||
|
||||
//加法
|
||||
export function accAdd(arg1,arg2){
|
||||
var r1=0,r2=0,m,s1=arg1.toString(),s2=arg2.toString();
|
||||
try{
|
||||
if(s1.split(".")[1] != undefined )
|
||||
r1=s1.split(".")[1].length;
|
||||
}catch(e){}
|
||||
try{
|
||||
if(s2.split(".")[1] != undefined )
|
||||
r2=s2.split(".")[1].length;
|
||||
}catch(e){}
|
||||
m=Math.pow(10,Math.max(r1,r2));
|
||||
return (accMul(arg1,m)+accMul(arg2,m))/m;
|
||||
}
|
||||
//减法
|
||||
export function Subtr(arg1,arg2){
|
||||
var r1=0,r2=0,m,n,s1=arg1.toString(),s2=arg2.toString();
|
||||
try{
|
||||
if(s1.split(".")[1] != undefined )
|
||||
r1=s1.split(".")[1].length;
|
||||
}catch(e){}
|
||||
try{
|
||||
if(s2.split(".")[1] != undefined )
|
||||
r2=s2.split(".")[1].length;
|
||||
}catch(e){}
|
||||
m=Math.pow(10,Math.max(r1,r2));
|
||||
//last modify by deeka
|
||||
//动态控制精度长度
|
||||
n=(r1>=r2)?r1:r2;
|
||||
return (accMul(arg1,m)-accMul(arg2,m))/m;
|
||||
}
|
||||
//乘法函数,用来得到精确的乘法结果
|
||||
export function accMul (arg1, arg2) {
|
||||
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
|
||||
try {
|
||||
if (s1.split(".")[1] != undefined)
|
||||
m += s1.split(".")[1].length
|
||||
} catch (e) {
|
||||
}
|
||||
try {
|
||||
if (s2.split(".")[1] != undefined)
|
||||
m += s2.split(".")[1].length
|
||||
} catch (e) {
|
||||
}
|
||||
return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
|
||||
}
|
||||
//除法
|
||||
export function accDiv(arg1,arg2){
|
||||
var r1=0,r2=0,m,s1=arg1.toString(),s2=arg2.toString();
|
||||
try{
|
||||
if(s1.split(".")[1] != undefined )
|
||||
r1=s1.split(".")[1].length;
|
||||
}catch(e){}
|
||||
try{
|
||||
if(s2.split(".")[1] != undefined )
|
||||
r2=s2.split(".")[1].length;
|
||||
}catch(e){}
|
||||
m=Math.pow(10,Math.max(r1,r2));
|
||||
return (accMul(arg1,m))/(accMul(arg2,m));
|
||||
}
|
||||
//获取 带小数点的数字
|
||||
export function getFloatStr(num){
|
||||
num += '';
|
||||
num = num.replace(/[^0-9|\.]/g, '');
|
||||
|
||||
if(/^0+/)
|
||||
num = num.replace(/^0+/, '');
|
||||
if(!/\./.test(num))
|
||||
num += '.00';
|
||||
if(/^\./.test(num))
|
||||
num = '0' + num;
|
||||
num += '00';
|
||||
num = num.match(/\d+\.\d{2}/)[0];
|
||||
return num;
|
||||
}
|
||||
|
||||
export function getFormattedTimeAsSerialNumber() {
|
||||
const date = new Date();
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
|
||||
|
||||
return `${year}${month}${day}${hours}${minutes}${seconds}${milliseconds}`;
|
||||
}
|
||||
|
||||
//input只能输入金额
|
||||
export function clearNoNum(obj) {
|
||||
obj.target.value = obj.target.value.replace(/[^\d.]/g, "")
|
||||
.replace(/^0\d+|^\./g, "")
|
||||
.replace(/\.{2,}/g, ".")
|
||||
.replace(".", "$#$")
|
||||
.replace(/\./g, "")
|
||||
.replace("$#$", ".")
|
||||
.replace(/^(\d+)\.(\d\d).*$/, "$1.$2"); //清除"数字"和"."以外的字符
|
||||
}
|
||||
|
||||
export function getLoginUser(){
|
||||
//获取当前登录人
|
||||
return store.getters.user
|
||||
}
|
37
web/src/utils/loading.js
Normal file
37
web/src/utils/loading.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Loading } from 'element-ui';
|
||||
|
||||
let loadingCount = 0;
|
||||
let loading;
|
||||
|
||||
const startLoading = () => {
|
||||
loading = Loading.service({
|
||||
lock: true,
|
||||
text: '请求中……',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
});
|
||||
};
|
||||
|
||||
const endLoading = () => {
|
||||
setTimeout(()=>{
|
||||
loading.close();
|
||||
},500)
|
||||
|
||||
};
|
||||
|
||||
export const showLoading = () => {
|
||||
if (loadingCount === 0) {
|
||||
startLoading();
|
||||
}
|
||||
loadingCount += 1;
|
||||
|
||||
};
|
||||
|
||||
export const hideLoading = () => {
|
||||
if (loadingCount <= 0) {
|
||||
return;
|
||||
}
|
||||
loadingCount -= 1;
|
||||
if (loadingCount === 0) {
|
||||
endLoading();
|
||||
}
|
||||
};
|
25
web/src/utils/prompt.js
Normal file
25
web/src/utils/prompt.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { MessageBox } from 'element-ui';
|
||||
|
||||
// 封装prompt函数,用于获取用户输入且校验非空
|
||||
const prompt = (text, defaultValue = '') => {
|
||||
return new Promise((resolve, reject) => {
|
||||
MessageBox.prompt(text? text : '请输入内容', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
inputValue: defaultValue,
|
||||
inputPlaceholder: '在此输入内容'
|
||||
}).then(({ value }) => {
|
||||
if (value.trim() === '') {
|
||||
MessageBox.alert('输入内容不能为空,请重新输入', '提示');
|
||||
return prompt(text, defaultValue); // 递归调用自身,让用户重新输入
|
||||
}
|
||||
resolve(value);
|
||||
}).catch(() => {
|
||||
reject(null);
|
||||
});
|
||||
}).catch(() => {
|
||||
// 可对错误进行处理
|
||||
});
|
||||
};
|
||||
|
||||
export default prompt;
|
113
web/src/utils/request.js
Normal file
113
web/src/utils/request.js
Normal file
@@ -0,0 +1,113 @@
|
||||
import axios from 'axios'
|
||||
import { MessageBox, Message } from 'element-ui'
|
||||
import store from '@/store'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import {hideLoading, showLoading} from "@/utils/loading";
|
||||
import { success } from '@/utils/index'
|
||||
|
||||
// create an axios instance
|
||||
const service = axios.create({
|
||||
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
|
||||
// withCredentials: true, // send cookies when cross-domain requests
|
||||
timeout: 5000 // request timeout
|
||||
})
|
||||
|
||||
// request interceptor
|
||||
service.interceptors.request.use(
|
||||
config => {
|
||||
// do something before request is sent
|
||||
|
||||
if(config.method == 'post'){
|
||||
showLoading()
|
||||
}
|
||||
|
||||
if (store.getters.token) {
|
||||
// let each request carry token
|
||||
// ['X-Token'] is a custom headers key
|
||||
// please modify it according to the actual situation
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken()
|
||||
}
|
||||
return config
|
||||
},
|
||||
error => {
|
||||
// do something with request error
|
||||
console.log(error) // for debug
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
// response interceptor
|
||||
service.interceptors.response.use(
|
||||
/**
|
||||
* If you want to get http information such as headers or status
|
||||
* Please return response => response
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determine the request status by custom code
|
||||
* Here is just an example
|
||||
* You can also judge the status by HTTP Status Code
|
||||
*/
|
||||
response => {
|
||||
if(response.config.method == 'post'){
|
||||
hideLoading()
|
||||
}
|
||||
const res = response.data
|
||||
|
||||
// if the custom code is not 20000, it is judged as an error.
|
||||
if (res.code !== 200) {
|
||||
Message({
|
||||
message: res.message || 'Error',
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
|
||||
// 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
|
||||
if (res.code === 50008 || res.code === 50012 || res.code === 50014 || res.code === 403 || res.code === 700) {
|
||||
// to re-login
|
||||
MessageBox.confirm('您已注销登录,您可以取消以留在当前页面,或者再次登录。', '确认注销', {
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
store.dispatch('user/resetToken').then(() => {
|
||||
location.reload()
|
||||
})
|
||||
})
|
||||
}
|
||||
return Promise.reject(new Error(res.message || 'Error'))
|
||||
} else {
|
||||
if(response.config.method == 'post'){
|
||||
success('提交成功')
|
||||
}
|
||||
return res
|
||||
}
|
||||
},
|
||||
error => {
|
||||
if(error.config.method == 'post'){
|
||||
hideLoading()
|
||||
}
|
||||
if(error.response.status == '403'){
|
||||
// to re-login
|
||||
MessageBox.confirm('您已注销登录,您可以取消以留在当前页面,或者再次登录。', '确认注销', {
|
||||
confirmButtonText: '重新登录',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
store.dispatch('user/resetToken').then(() => {
|
||||
location.reload()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
console.log('err' + error) // for debug
|
||||
Message({
|
||||
message: error.message,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
return Promise.reject(error)
|
||||
}
|
||||
)
|
||||
|
||||
export default service
|
58
web/src/utils/scroll-to.js
Normal file
58
web/src/utils/scroll-to.js
Normal file
@@ -0,0 +1,58 @@
|
||||
Math.easeInOutQuad = function(t, b, c, d) {
|
||||
t /= d / 2
|
||||
if (t < 1) {
|
||||
return c / 2 * t * t + b
|
||||
}
|
||||
t--
|
||||
return -c / 2 * (t * (t - 2) - 1) + b
|
||||
}
|
||||
|
||||
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
|
||||
var requestAnimFrame = (function() {
|
||||
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60) }
|
||||
})()
|
||||
|
||||
/**
|
||||
* Because it's so fucking difficult to detect the scrolling element, just move them all
|
||||
* @param {number} amount
|
||||
*/
|
||||
function move(amount) {
|
||||
document.documentElement.scrollTop = amount
|
||||
document.body.parentNode.scrollTop = amount
|
||||
document.body.scrollTop = amount
|
||||
}
|
||||
|
||||
function position() {
|
||||
return document.documentElement.scrollTop || document.body.parentNode.scrollTop || document.body.scrollTop
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} to
|
||||
* @param {number} duration
|
||||
* @param {Function} callback
|
||||
*/
|
||||
export function scrollTo(to, duration, callback) {
|
||||
const start = position()
|
||||
const change = to - start
|
||||
const increment = 20
|
||||
let currentTime = 0
|
||||
duration = (typeof (duration) === 'undefined') ? 500 : duration
|
||||
var animateScroll = function() {
|
||||
// increment the time
|
||||
currentTime += increment
|
||||
// find the value with the quadratic in-out easing function
|
||||
var val = Math.easeInOutQuad(currentTime, start, change, duration)
|
||||
// move the document.body
|
||||
move(val)
|
||||
// do the animation unless its over
|
||||
if (currentTime < duration) {
|
||||
requestAnimFrame(animateScroll)
|
||||
} else {
|
||||
if (callback && typeof (callback) === 'function') {
|
||||
// the animation is done so lets callback
|
||||
callback()
|
||||
}
|
||||
}
|
||||
}
|
||||
animateScroll()
|
||||
}
|
20
web/src/utils/validate.js
Normal file
20
web/src/utils/validate.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Created by PanJiaChen on 16/11/18.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} path
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function isExternal(path) {
|
||||
return /^(https?:|mailto:|tel:)/.test(path)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} str
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
export function validUsername(str) {
|
||||
const valid_map = ['admin', 'editor']
|
||||
return valid_map.indexOf(str.trim()) >= 0
|
||||
}
|
Reference in New Issue
Block a user