no message
Former-commit-id: 487e22a0c9bf5da4474f9449ce95070e9a4ed727
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import Cookies from 'js-cookie'
|
||||
|
||||
const cookies = {}
|
||||
|
||||
/**
|
||||
* @description 存储 cookie 值
|
||||
* @param {String} name cookie name
|
||||
* @param {String} value cookie value
|
||||
* @param {Object} setting cookie setting
|
||||
*/
|
||||
cookies.set = function (name = 'default', value = '', cookieSetting = {}) {
|
||||
let currentCookieSetting = {
|
||||
expires: 1
|
||||
}
|
||||
Object.assign(currentCookieSetting, cookieSetting)
|
||||
Cookies.set(`d2admin-${process.env.VUE_APP_VERSION}-${name}`, value, currentCookieSetting)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 拿到 cookie 值
|
||||
* @param {String} name cookie name
|
||||
*/
|
||||
cookies.get = function (name = 'default') {
|
||||
return Cookies.get(`d2admin-${process.env.VUE_APP_VERSION}-${name}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 拿到 cookie 全部的值
|
||||
*/
|
||||
cookies.getAll = function () {
|
||||
return Cookies.get()
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 删除 cookie
|
||||
* @param {String} name cookie name
|
||||
*/
|
||||
cookies.remove = function (name = 'default') {
|
||||
return Cookies.remove(`d2admin-${process.env.VUE_APP_VERSION}-${name}`)
|
||||
}
|
||||
|
||||
export default cookies
|
||||
@@ -0,0 +1,14 @@
|
||||
import low from 'lowdb'
|
||||
import LocalStorage from 'lowdb/adapters/LocalStorage'
|
||||
|
||||
const adapter = new LocalStorage(`d2admin-${process.env.VUE_APP_VERSION}`)
|
||||
const db = low(adapter)
|
||||
|
||||
db
|
||||
.defaults({
|
||||
sys: {},
|
||||
database: {}
|
||||
})
|
||||
.write()
|
||||
|
||||
export default db
|
||||
@@ -0,0 +1,34 @@
|
||||
import cookies from './util.cookies'
|
||||
import db from './util.db'
|
||||
import log from './util.log'
|
||||
|
||||
const util = {
|
||||
cookies,
|
||||
db,
|
||||
log
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 更新标题
|
||||
* @param {String} title 标题
|
||||
*/
|
||||
util.title = function (titleText) {
|
||||
const processTitle = process.env.VUE_APP_TITLE || 'D2Admin'
|
||||
window.document.title = `${processTitle}${titleText ? ` | ${titleText}` : ''}`
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打开新页面
|
||||
* @param {String} url 地址
|
||||
*/
|
||||
util.open = function (url) {
|
||||
var a = document.createElement('a')
|
||||
a.setAttribute('href', url)
|
||||
a.setAttribute('target', '_blank')
|
||||
a.setAttribute('id', 'd2admin-link-temp')
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(document.getElementById('d2admin-link-temp'))
|
||||
}
|
||||
|
||||
export default util
|
||||
@@ -0,0 +1,80 @@
|
||||
const log = {}
|
||||
|
||||
/**
|
||||
* @description 返回这个样式的颜色值
|
||||
* @param {String} type 样式名称 [ primary | success | warning | danger | text ]
|
||||
*/
|
||||
function typeColor (type = 'default') {
|
||||
let color = ''
|
||||
switch (type) {
|
||||
case 'default': color = '#35495E'; break
|
||||
case 'primary': color = '#3488ff'; break
|
||||
case 'success': color = '#43B883'; break
|
||||
case 'warning': color = '#e6a23c'; break
|
||||
case 'danger': color = '#f56c6c'; break
|
||||
default:; break
|
||||
}
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印一个 [ title | text ] 样式的信息
|
||||
* @param {String} title title text
|
||||
* @param {String} info info text
|
||||
* @param {String} type style
|
||||
*/
|
||||
log.capsule = function (title, info, type = 'primary') {
|
||||
console.log(
|
||||
`%c ${title} %c ${info} %c`,
|
||||
'background:#35495E; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;',
|
||||
`background:${typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
|
||||
'background:transparent'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印彩色文字
|
||||
*/
|
||||
log.colorful = function (textArr) {
|
||||
console.log(
|
||||
`%c${textArr.map(t => t.text || '').join('%c')}`,
|
||||
...textArr.map(t => `color: ${typeColor(t.type)};`)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 default 样式的文字
|
||||
*/
|
||||
log.default = function (text) {
|
||||
log.colorful([{ text }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 primary 样式的文字
|
||||
*/
|
||||
log.primary = function (text) {
|
||||
log.colorful([{ text, type: 'primary' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 success 样式的文字
|
||||
*/
|
||||
log.success = function (text) {
|
||||
log.colorful([{ text, type: 'success' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 warning 样式的文字
|
||||
*/
|
||||
log.warning = function (text) {
|
||||
log.colorful([{ text, type: 'warning' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 danger 样式的文字
|
||||
*/
|
||||
log.danger = function (text) {
|
||||
log.colorful([{ text, type: 'danger' }])
|
||||
}
|
||||
|
||||
export default log
|
||||
Reference in New Issue
Block a user