diff --git a/src/libs/util.js b/src/libs/util.js index dfb043be..4fc81800 100644 --- a/src/libs/util.js +++ b/src/libs/util.js @@ -1,6 +1,5 @@ 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' @@ -18,13 +17,6 @@ util.title = function (titleText) { window.document.title = `${process.env.VUE_APP_TITLE}${titleText ? ` | ${titleText}` : ''}` } -/** - * @description 获取所有的 UA 信息 - */ -util.ua = function () { - return new UaParser().getResult() -} - /** * @description 判断是否在其内 * @param {*} ele element diff --git a/src/main.js b/src/main.js index a2214d24..8ef9c4fe 100644 --- a/src/main.js +++ b/src/main.js @@ -58,7 +58,7 @@ new Vue({ // D2Admin 开发环境检查更新 util.checkUpdate(this) // 获取并记录用户 UA - this.$store.commit('d2admin/uaGet') + this.$store.commit('d2admin/ua/get') // 展示系统信息 util.showInfo() // 用户登陆后从数据库加载一系列的设置 diff --git a/src/pages/demo/playground/store/sys/index.vue b/src/pages/demo/playground/store/sys/index.vue index b69befb2..d51a9cf0 100644 --- a/src/pages/demo/playground/store/sys/index.vue +++ b/src/pages/demo/playground/store/sys/index.vue @@ -153,8 +153,7 @@ export default { 'isGrayMode', 'pagePool', 'pageOpenedList', - 'pageCurrent', - 'ua' + 'pageCurrent' ]), ...mapGetters('d2admin', { keepAliveInclude: 'keepAliveInclude', diff --git a/src/pages/demo/playground/store/ua/index.vue b/src/pages/demo/playground/store/ua/index.vue index 957f5d2a..700f15f4 100644 --- a/src/pages/demo/playground/store/ua/index.vue +++ b/src/pages/demo/playground/store/ua/index.vue @@ -1,8 +1,8 @@ @@ -11,11 +11,11 @@ import { mapState } from 'vuex' export default { computed: { - ...mapState('d2admin', [ - 'ua' - ]), + ...mapState('d2admin/ua', { + uaData: 'data' + }), uaStr () { - const { browser, engine, os, device, cpu } = this.ua + const { browser, engine, os, device, cpu } = this.uaData return JSON.stringify({ browser, engine, os, device, cpu }, null, 2) } } diff --git a/src/store/modules/d2admin/index.js.REMOVED.git-id b/src/store/modules/d2admin/index.js.REMOVED.git-id index 91f75821..df881c23 100644 --- a/src/store/modules/d2admin/index.js.REMOVED.git-id +++ b/src/store/modules/d2admin/index.js.REMOVED.git-id @@ -1 +1 @@ -4d21835fa9e3352a4c11053634775c7e45774fae \ No newline at end of file +33558b2365f6936e850cfc9012fbe3de139d35db \ No newline at end of file diff --git a/src/store/modules/d2admin/modules/ua.js b/src/store/modules/d2admin/modules/ua.js new file mode 100644 index 00000000..05c50d7a --- /dev/null +++ b/src/store/modules/d2admin/modules/ua.js @@ -0,0 +1,18 @@ +import UaParser from 'ua-parser-js' + +export default { + namespaced: true, + state: { + // 用户 UA + data: {} + }, + mutations: { + /** + * @description 记录 UA + * @param {Object} state vuex state + */ + get (state) { + state.data = new UaParser().getResult() + } + } +}