diff --git a/src/libs/db.js b/src/libs/db.js index 4d0afbce..e7951468 100644 --- a/src/libs/db.js +++ b/src/libs/db.js @@ -10,9 +10,7 @@ db.defaults({ // 新 sys: {}, // 旧 - themeActiveName: [], pageOpenedList: [], - isMenuAsideCollapse: [], database: [], databasePublic: {} }).write() diff --git a/src/libs/util.cookies.js b/src/libs/util.cookies.js new file mode 100644 index 00000000..6cf6431c --- /dev/null +++ b/src/libs/util.cookies.js @@ -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 diff --git a/src/libs/util.js b/src/libs/util.js index 95a4b80a..dfb043be 100644 --- a/src/libs/util.js +++ b/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/') } diff --git a/src/libs/util.log.js b/src/libs/util.log.js new file mode 100644 index 00000000..8f85641a --- /dev/null +++ b/src/libs/util.log.js @@ -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