1.3
This commit is contained in:
15
src/utils/auth.js
Normal file
15
src/utils/auth.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const TokenKey = 'Admin-Token'
|
||||
|
||||
export function getToken() {
|
||||
return Cookies.get(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
return Cookies.set(TokenKey, token)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return Cookies.remove(TokenKey)
|
||||
}
|
||||
64
src/utils/chartMixins/resize.js
Normal file
64
src/utils/chartMixins/resize.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import { debounce } from '@/utils/debounce'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
$_sidebarElm: null,
|
||||
$_resizeHandler: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$_resizeHandler = debounce(() => {
|
||||
if (this.chart) {
|
||||
this.chart.resize()
|
||||
}
|
||||
}, 100)
|
||||
this.$_initResizeEvent()
|
||||
this.$_initSidebarResizeEvent()
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.$_destroyResizeEvent()
|
||||
this.$_destroySidebarResizeEvent()
|
||||
},
|
||||
// to fixed bug when cached by keep-alive
|
||||
// https://github.com/PanJiaChen/vue-element-admin/issues/2116
|
||||
activated() {
|
||||
this.$_initResizeEvent()
|
||||
this.$_initSidebarResizeEvent()
|
||||
},
|
||||
deactivated() {
|
||||
this.$_destroyResizeEvent()
|
||||
this.$_destroySidebarResizeEvent()
|
||||
},
|
||||
methods: {
|
||||
// use $_ for mixins properties
|
||||
// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential
|
||||
$_initResizeEvent() {
|
||||
window.addEventListener('resize', this.$_resizeHandler)
|
||||
},
|
||||
$_destroyResizeEvent() {
|
||||
window.removeEventListener('resize', this.$_resizeHandler)
|
||||
},
|
||||
$_sidebarResizeHandler(e) {
|
||||
if (e.propertyName === 'width') {
|
||||
this.$_resizeHandler()
|
||||
}
|
||||
},
|
||||
$_initSidebarResizeEvent() {
|
||||
this.$_sidebarElm =
|
||||
document.getElementsByClassName('sidebar-container')[0]
|
||||
this.$_sidebarElm &&
|
||||
this.$_sidebarElm.addEventListener(
|
||||
'transitionend',
|
||||
this.$_sidebarResizeHandler
|
||||
)
|
||||
},
|
||||
$_destroySidebarResizeEvent() {
|
||||
this.$_sidebarElm &&
|
||||
this.$_sidebarElm.removeEventListener(
|
||||
'transitionend',
|
||||
this.$_sidebarResizeHandler
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
40
src/utils/debounce.js
Normal file
40
src/utils/debounce.js
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @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
|
||||
}
|
||||
}
|
||||
8
src/utils/dict.js
Normal file
8
src/utils/dict.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// 前端写死的list
|
||||
export default {
|
||||
packageState: [
|
||||
{ dataCode: 0, dataName: '包装中' },
|
||||
{ dataCode: 1, dataName: '复投中' },
|
||||
{ dataCode: 2, dataName: '已下架' }
|
||||
]
|
||||
}
|
||||
53
src/utils/index.js
Normal file
53
src/utils/index.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import moment from 'moment'
|
||||
import dictionaryList from './dict'
|
||||
// tableHeight
|
||||
export function tableHeight(n) {
|
||||
return window.innerHeight - n
|
||||
}
|
||||
|
||||
// table中用来过滤时间
|
||||
export function timeFormatter(timeObj) {
|
||||
if (timeObj) {
|
||||
return moment(timeObj).format('YYYY-MM-DD HH:mm:ss')
|
||||
} else {
|
||||
return '-'
|
||||
}
|
||||
}
|
||||
|
||||
// table中用来过滤字典
|
||||
const publicList = JSON.parse(localStorage.getItem('publicList'))
|
||||
export function publicFormatter(dictTable) {
|
||||
return function (val) {
|
||||
const arr = {}
|
||||
const dicList = publicList?.[dictTable]
|
||||
dicList.map((item) => {
|
||||
arr[item.dataCode] = item.dataName
|
||||
})
|
||||
return arr?.[val]
|
||||
}
|
||||
}
|
||||
|
||||
export function dictionaryFormatter(dictTable) {
|
||||
return function (val) {
|
||||
const arr = {}
|
||||
const dictList = dictionaryList?.[dictTable]
|
||||
dictList.map((item) => {
|
||||
arr[item.dataCode] = item.dataName
|
||||
})
|
||||
return arr?.[val]
|
||||
}
|
||||
}
|
||||
|
||||
// table中用来过滤金额
|
||||
export function amountFormatter(param) {
|
||||
if (param) {
|
||||
return parseFloat(param).toFixed(2)
|
||||
} else {
|
||||
return '0.00'
|
||||
}
|
||||
}
|
||||
|
||||
// svgicon
|
||||
export function isExternal(path) {
|
||||
return /^(https?:|mailto:|tel:)/.test(path)
|
||||
}
|
||||
Reference in New Issue
Block a user