cli3改版基本完成
Former-commit-id: 637e58a7d3aef389a4ea51c179aaee17f421f34c [formerly 637e58a7d3aef389a4ea51c179aaee17f421f34c [formerly 637e58a7d3aef389a4ea51c179aaee17f421f34c [formerly 637e58a7d3aef389a4ea51c179aaee17f421f34c [formerly fc66dcb2e437ff46b2c36ec1e3bcce71a6461250 [formerly b6451dc60d4c1e6006a9fcd380656d2023436e64]]]]] Former-commit-id: c791410cda91e2df1b9808bfb032f0d3d68106ef Former-commit-id: 0c5197800cfae6f27f7ab792c887fb25a73a23e0 Former-commit-id: 208a8e77c0fada6e9d191a7d495615ec2ef9704d [formerly af8c1367ed65b626196ac156c8521257cc804d60] Former-commit-id: 1fdb571cea6ed9dba9ea02f4ba6ebfb5d89e1b2f Former-commit-id: 774a145ae0694612edf988d9992ef797ddf4f21d Former-commit-id: 03fc24d70365836d60360aa24e24dc7cb4520b91 Former-commit-id: bba4fd5552fa42da029fd6b310f5ee48558d5508 Former-commit-id: 2de81d34fb07248965677e8a3866c13089fa95e7
This commit is contained in:
84
src/libs/util.js
Normal file
84
src/libs/util.js
Normal file
@@ -0,0 +1,84 @@
|
||||
// 插件
|
||||
import Cookies from 'js-cookie'
|
||||
import axios from 'axios'
|
||||
import semver from 'semver'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
// 获取项目信息
|
||||
import packJson from '../../package.json'
|
||||
|
||||
let util = {}
|
||||
|
||||
/**
|
||||
* @description 得到现在的用户
|
||||
*/
|
||||
util.uuid = function () {
|
||||
return Cookies.get('uuid')
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 更新标题
|
||||
* @param {string} title 标题
|
||||
*/
|
||||
util.title = function title (titleText) {
|
||||
window.document.title = `${process.env.VUE_APP_TITLE}${titleText ? ` | ${titleText}` : ''}`
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 判断是否在其内
|
||||
* @param {*} ele element
|
||||
* @param {array} targetArr array
|
||||
*/
|
||||
util.isOneOf = function (ele, targetArr) {
|
||||
if (targetArr.indexOf(ele) >= 0) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 打印一个 “胶囊” 样式的信息
|
||||
* @param {string} title title text
|
||||
* @param {string} info info text
|
||||
*/
|
||||
util.logCapsule = function (title, info) {
|
||||
console.log(
|
||||
`%c ${title} %c ${info} %c`,
|
||||
'background:#29384b; padding: 1px; border-radius: 3px 0 0 3px; color: #fff',
|
||||
'background:#3488ff; padding: 1px; border-radius: 0 3px 3px 0; color: #fff',
|
||||
'background:transparent'
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 检查版本更新
|
||||
* @param {object} vm vue
|
||||
*/
|
||||
util.checkUpdate = function (vm) {
|
||||
axios.get('https://api.github.com/repos/FairyEver/d2-admin/releases/latest')
|
||||
.then(res => {
|
||||
let version = res.tag_name
|
||||
const update = semver.lt(packJson.version, version)
|
||||
if (update) {
|
||||
util.logCapsule('D2Admin', `New version ${res.name}`)
|
||||
console.log(`${dayjs(res.created_at).format('YYYY年M月D日')}更新 版本号: ${res.tag_name} | 详情${res.html_url}`)
|
||||
}
|
||||
vm.$store.commit('d2adminUpdateSet', update)
|
||||
vm.$store.commit('d2adminReleasesSet', res)
|
||||
})
|
||||
.catch(err => {
|
||||
console.log('checkUpdate error', err)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 显示版本信息
|
||||
*/
|
||||
util.showInfo = function showInfo () {
|
||||
util.logCapsule('D2Admin', `v${packJson.version}`)
|
||||
console.log('Github https://github.com/d2-projects/d2-admin')
|
||||
console.log('Doc http://d2admin.fairyever.com/zh/')
|
||||
}
|
||||
|
||||
export default util
|
||||
Reference in New Issue
Block a user