util拆分
Former-commit-id: 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 822c86f85a1268c28513cf97b7107dd697eb6d43 [formerly 68c12439e9dd03521d919105efcbc06cb6da2126 [formerly 1d5c6a4b53da991761dd4a9399eefb27e70e96ca]]]]] Former-commit-id: fbe49d601541d01db7f4c36658c71a6e3b014733 Former-commit-id: e2e4e2958c7f63990339e1d06b4b3aaf463dab31 Former-commit-id: 20c693d8bcc308b276d15d7cbc7288c74c709dbf [formerly fc2f99d56d410c349d5bff5e42176a6fc97325da] Former-commit-id: 004230c8e00651d1793fd4ee68bb34299d4049f5 Former-commit-id: 94a29c7f87d6d3b6f200d9bdc9033fb25641cf3f Former-commit-id: b5d93d8b5c1b5e85b62c01ca815c87dc943a694f Former-commit-id: d787061bbfae4ea01a3aabf6f92cd1620377b572 Former-commit-id: 2fc8371e6d340382cca7539a5dc1aa09881fecb2
This commit is contained in:
@@ -10,9 +10,7 @@ db.defaults({
|
||||
// 新
|
||||
sys: {},
|
||||
// 旧
|
||||
themeActiveName: [],
|
||||
pageOpenedList: [],
|
||||
isMenuAsideCollapse: [],
|
||||
database: [],
|
||||
databasePublic: {}
|
||||
}).write()
|
||||
|
||||
43
src/libs/util.cookies.js
Normal file
43
src/libs/util.cookies.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import { version } from '../../package.json'
|
||||
|
||||
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 = '', setting = {}) {
|
||||
let cookieSetting = {
|
||||
expires: 1
|
||||
}
|
||||
Object.assign(cookieSetting, setting)
|
||||
Cookies.set(`d2admin-${version}-${name}`, value, cookieSetting)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 拿到 cookie 值
|
||||
* @param {String} name cookie name
|
||||
*/
|
||||
cookies.get = function (name = 'default') {
|
||||
return Cookies.get(`d2admin-${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-${version}-${name}`)
|
||||
}
|
||||
|
||||
export default cookies
|
||||
118
src/libs/util.js
118
src/libs/util.js
@@ -1,49 +1,13 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import axios from 'axios'
|
||||
import semver from 'semver'
|
||||
import UaParser from 'ua-parser-js'
|
||||
import { version } from '../../package.json'
|
||||
import log from './util.log.js'
|
||||
import cookies from './util.cookies.js'
|
||||
|
||||
let util = {
|
||||
cookies: {},
|
||||
log: {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 存储 cookie 值
|
||||
* @param {String} name cookie name
|
||||
* @param {String} value cookie value
|
||||
* @param {Object} setting cookie setting
|
||||
*/
|
||||
util.cookies.set = function (name = 'default', value = '', setting = {}) {
|
||||
let cookieSetting = {
|
||||
expires: 1
|
||||
}
|
||||
Object.assign(cookieSetting, setting)
|
||||
Cookies.set(`d2admin-${version}-${name}`, value, cookieSetting)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 拿到 cookie 值
|
||||
* @param {String} name cookie name
|
||||
*/
|
||||
util.cookies.get = function (name = 'default') {
|
||||
return Cookies.get(`d2admin-${version}-${name}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 拿到 cookie 全部的值
|
||||
*/
|
||||
util.cookies.getAll = function () {
|
||||
return Cookies.get()
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 删除 cookie
|
||||
* @param {String} name cookie name
|
||||
*/
|
||||
util.cookies.remove = function (name = 'default') {
|
||||
return Cookies.remove(`d2admin-${version}-${name}`)
|
||||
cookies,
|
||||
log
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,76 +38,6 @@ util.isOneOf = function (ele, targetArr) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 返回这个样式的颜色值
|
||||
* @param {String} type 样式名称 [ primary | success | warning | danger | text ]
|
||||
*/
|
||||
util.typeColor = function (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 打印一个 “胶囊” 样式的信息
|
||||
* @param {String} title title text
|
||||
* @param {String} info info text
|
||||
* @param {String} type style
|
||||
*/
|
||||
util.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:${util.typeColor(type)}; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;`,
|
||||
'background:transparent'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印彩色文字
|
||||
*/
|
||||
util.log.colorful = function (textArr) {
|
||||
console.log(
|
||||
`%c ${textArr.map(t => t.text).join(' %c ')}`,
|
||||
...textArr.map(t => `color: ${util.typeColor(t.type)};`)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 primary 样式的文字
|
||||
*/
|
||||
util.log.primary = function (text) {
|
||||
util.log.colorful([{ text, type: 'primary' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 success 样式的文字
|
||||
*/
|
||||
util.log.success = function (text) {
|
||||
util.log.colorful([{ text, type: 'success' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 warning 样式的文字
|
||||
*/
|
||||
util.log.warning = function (text) {
|
||||
util.log.colorful([{ text, type: 'warning' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印 danger 样式的文字
|
||||
*/
|
||||
util.log.danger = function (text) {
|
||||
util.log.colorful([{ text, type: 'danger' }])
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 检查版本更新
|
||||
* @param {Object} vm vue
|
||||
@@ -157,7 +51,7 @@ util.checkUpdate = function (vm) {
|
||||
let versionGet = res.tag_name
|
||||
const update = semver.lt(version, versionGet)
|
||||
if (update) {
|
||||
util.log.capsule('D2Admin', `New version ${res.name}`)
|
||||
log.capsule('D2Admin', `New version ${res.name}`)
|
||||
console.log(`版本号: ${res.tag_name} | 详情${res.html_url}`)
|
||||
vm.$store.commit('d2admin/releases/updateSet', true)
|
||||
}
|
||||
@@ -172,7 +66,7 @@ util.checkUpdate = function (vm) {
|
||||
* @description 显示版本信息
|
||||
*/
|
||||
util.showInfo = function showInfo () {
|
||||
util.log.capsule('D2Admin', `v${version}`)
|
||||
log.capsule('D2Admin', `v${version}`)
|
||||
console.log('Github https://github.com/d2-projects/d2-admin')
|
||||
console.log('Doc http://d2admin.fairyever.com/zh/')
|
||||
}
|
||||
|
||||
73
src/libs/util.log.js
Normal file
73
src/libs/util.log.js
Normal file
@@ -0,0 +1,73 @@
|
||||
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 打印 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