Commit 8ea9de60 by Sendya

fixed: storage util

add: vue-ls lib
parent 5ea79910
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
"viser-vue": "^2.3.0", "viser-vue": "^2.3.0",
"vue": "^2.5.17", "vue": "^2.5.17",
"vue-cropper": "^0.4.0", "vue-cropper": "^0.4.0",
"vue-ls": "^3.2.0",
"vue-router": "^3.0.1", "vue-router": "^3.0.1",
"vuex": "^3.0.1" "vuex": "^3.0.1"
}, },
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
:menus="menus" :menus="menus"
:theme="theme" :theme="theme"
:mode="menuMode" :mode="menuMode"
:collapsed="!siderOpen || collapsed" :collapsed="collapsed"
:collapsible="true"></sider-menu> :collapsible="true"></sider-menu>
<a-layout> <a-layout>
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
import SiderMenu from '@/components/menu/SiderMenu' import SiderMenu from '@/components/menu/SiderMenu'
import LayoutHeader from './LayoutHeader' import LayoutHeader from './LayoutHeader'
import LayoutFooter from './LayoutFooter' import LayoutFooter from './LayoutFooter'
import {mapState} from 'vuex' import { mapState, mapActions } from 'vuex'
export default { export default {
name: "LayoutView", name: "LayoutView",
...@@ -70,19 +70,22 @@ ...@@ -70,19 +70,22 @@
computed: { computed: {
...mapState({ ...mapState({
mainMenu: state => state.permission.addRouters, mainMenu: state => state.permission.addRouters,
siderOpen: state => state.app.sidebar.opened, sidebarOpened: state => state.app.sidebar.opened,
theme: state => state.app.theme, theme: state => state.app.theme,
device: state => state.app.device, device: state => state.app.device,
}) })
}, },
mounted() {
this.collapsed = this.sidebarOpened
},
methods: { methods: {
...mapActions(['setSidebar']),
toggle() { toggle() {
this.collapsed = !this.collapsed; this.collapsed = !this.collapsed;
this.setSidebar(this.collapsed)
}, },
menuSelect() { menuSelect() {
if (this.device !== 'desktop') { if (this.device !== 'desktop') {
console.log('selected')
this.collapsed = false this.collapsed = false
} }
} }
......
...@@ -57,11 +57,13 @@ export default { ...@@ -57,11 +57,13 @@ export default {
}); });
}, },
pageSize(val) { pageSize(val) {
console.log('pageSize:', val)
Object.assign(this.localPagination, { Object.assign(this.localPagination, {
pageSize: val pageSize: val
}); });
}, },
showSizeChanger(val) { showSizeChanger(val) {
console.log('showSizeChanger', val)
Object.assign(this.localPagination, { Object.assign(this.localPagination, {
showSizeChanger: val showSizeChanger: val
}); });
...@@ -111,7 +113,6 @@ export default { ...@@ -111,7 +113,6 @@ export default {
}); });
!r.totalCount && ['auto', false].includes(this.showPagination) && (this.localPagination = false) !r.totalCount && ['auto', false].includes(this.showPagination) && (this.localPagination = false)
console.log(this.localPagination);
this.localDataSource = r.data; // 返回结果中的数组数据 this.localDataSource = r.data; // 返回结果中的数组数据
this.localLoading = false this.localLoading = false
}); });
...@@ -216,6 +217,7 @@ export default { ...@@ -216,6 +217,7 @@ export default {
return props[k] = _vm[k]; return props[k] = _vm[k];
}) })
// 显示信息提示 // 显示信息提示
if (this.showAlertInfo) { if (this.showAlertInfo) {
...@@ -248,7 +250,7 @@ export default { ...@@ -248,7 +250,7 @@ export default {
]); ]);
} }
/*
return h("a-table", { return h("a-table", {
tag: "component", tag: "component",
attrs: props, attrs: props,
...@@ -257,5 +259,7 @@ export default { ...@@ -257,5 +259,7 @@ export default {
}, },
scopedSlots: this.$scopedSlots scopedSlots: this.$scopedSlots
}, this.$slots.default); }, this.$slots.default);
*/
} }
}; };
\ No newline at end of file
import Vue from 'vue' import Vue from 'vue'
import App from './App.vue' import App from './App.vue'
import Storage from 'vue-ls'
import router from './router/' import router from './router/'
import store from './store/' import store from './store/'
...@@ -13,18 +14,33 @@ import * as dayjs from 'dayjs' // 日期时间支持库 ...@@ -13,18 +14,33 @@ import * as dayjs from 'dayjs' // 日期时间支持库
import '@/permission' // permission control import '@/permission' // permission control
import { ACCESS_TOKEN, DEFAULT_THEME, SIDEBAR_TYPE } from "@/store/mutation-types"
Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') { Vue.filter('dayjs', function(dataStr, pattern = 'YYYY-MM-DD HH:mm:ss') {
return dayjs(dataStr).format(pattern) return dayjs(dataStr).format(pattern)
}) })
const options = {
namespace: 'ant__', // key prefix
name: 'ls', // name variable Vue.[ls] or this.[$ls],
storage: 'local', // storage name session, local, memory
}
Vue.config.productionTip = false
Vue.use(Storage, options)
Vue.use(Antd) Vue.use(Antd)
Vue.use(VueAxios, router) Vue.use(VueAxios, router)
Vue.use(Viser) Vue.use(Viser)
Vue.config.productionTip = false
new Vue({ new Vue({
router, router,
store, store,
mounted () {
store.commit('SET_SIDEBAR_TYPE', Vue.ls.get(SIDEBAR_TYPE, true))
store.commit('TOGGLE_THEME', Vue.ls.get(DEFAULT_THEME, 'dark'))
store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
},
render: h => h(App) render: h => h(App)
}).$mount('#app') }).$mount('#app')
import Vue from 'vue'
import router from './router' import router from './router'
import store from './store' import store from './store'
import NProgress from 'nprogress' // progress bar import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style import 'nprogress/nprogress.css' // progress bar style
import { ACCESS_TOKEN } from "@/store/mutation-types"
import { getToken } from "./utils/auth"
NProgress.configure({ showSpinner: false })// NProgress Configuration NProgress.configure({ showSpinner: false })// NProgress Configuration
...@@ -13,7 +13,7 @@ const whiteList = ['/login']// no redirect whitelist ...@@ -13,7 +13,7 @@ const whiteList = ['/login']// no redirect whitelist
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar NProgress.start() // start progress bar
if (getToken()) { if (Vue.ls.get(ACCESS_TOKEN)) {
/* has token */ /* has token */
if (to.path === '/login') { if (to.path === '/login') {
next({ path: '/dashboard/workplace' }) next({ path: '/dashboard/workplace' })
......
import { getStore, setStore } from "@/utils/storage" import Vue from 'vue'
import { SIDEBAR_TYPE, DEFAULT_THEME } from "@/store/mutation-types"
let theme = getStore('_DEFAULT_THEME')
const app = { const app = {
state: { state: {
sidebar: { sidebar: {
opened: !+getStore('sidebarStatus'), opened: true,
withoutAnimation: false withoutAnimation: false
}, },
device: 'desktop', device: 'desktop',
theme: !theme ? 'dark' : theme theme: ''
}, },
mutations: { mutations: {
TOGGLE_SIDEBAR: state => { SET_SIDEBAR_TYPE: (state, type) => {
if (state.sidebar.opened) { state.sidebar.opened = type
setStore('sidebarStatus', 1) Vue.ls.set(SIDEBAR_TYPE, type)
} else {
setStore('sidebarStatus', 0)
}
state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false
}, },
CLOSE_SIDEBAR: (state, withoutAnimation) => { CLOSE_SIDEBAR: (state, withoutAnimation) => {
setStore('sidebarStatus', 1) Vue.ls.set(SIDEBAR_TYPE, true)
state.sidebar.opened = false state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation state.sidebar.withoutAnimation = withoutAnimation
}, },
...@@ -30,15 +24,16 @@ const app = { ...@@ -30,15 +24,16 @@ const app = {
state.device = device state.device = device
}, },
TOGGLE_THEME: (state, theme) => { TOGGLE_THEME: (state, theme) => {
setStore('_DEFAULT_THEME', theme) // setStore('_DEFAULT_THEME', theme)
Vue.ls.set(DEFAULT_THEME, theme)
state.theme = theme state.theme = theme
} }
}, },
actions: { actions: {
ToggleSideBar: ({ commit }) => { setSidebar: ({ commit }, type) => {
commit('TOGGLE_SIDEBAR') commit('SET_SIDEBAR_TYPE', type)
}, },
CloseSideBar({ commit }, { withoutAnimation }) { CloseSidebar({ commit }, { withoutAnimation }) {
commit('CLOSE_SIDEBAR', withoutAnimation) commit('CLOSE_SIDEBAR', withoutAnimation)
}, },
ToggleDevice({ commit }, device) { ToggleDevice({ commit }, device) {
......
import Vue from 'vue'
import { login, getInfo, logout } from "@/api/login" import { login, getInfo, logout } from "@/api/login"
import { setToken, getToken, removeToken } from '@/utils/auth' import { ACCESS_TOKEN } from "@/store/mutation-types"
import { welcome } from "@/utils/util" import { welcome } from "@/utils/util"
const user = { const user = {
state: { state: {
token: getToken(), token: '',
name: '', name: '',
welcome: '', welcome: '',
avatar: '', avatar: '',
...@@ -37,7 +38,7 @@ const user = { ...@@ -37,7 +38,7 @@ const user = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(userInfo).then(response => { login(userInfo).then(response => {
const result = response.result const result = response.result
setToken(result.token) Vue.ls.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
commit('SET_TOKEN', result.token) commit('SET_TOKEN', result.token)
resolve() resolve()
}).catch(error => { }).catch(error => {
...@@ -83,7 +84,7 @@ const user = { ...@@ -83,7 +84,7 @@ const user = {
return new Promise((resolve) => { return new Promise((resolve) => {
commit('SET_TOKEN', '') commit('SET_TOKEN', '')
commit('SET_ROLES', []) commit('SET_ROLES', [])
removeToken() Vue.ls.remove(ACCESS_TOKEN)
logout(state.token).then(() => { logout(state.token).then(() => {
resolve() resolve()
......
export const ACCESS_TOKEN = 'Access-Token'
export const SIDEBAR_TYPE = 'SIDEBAR_TYPE'
export const DEFAULT_THEME = 'DEFAULT_THEME'
\ No newline at end of file
import { setStore, getStore, clearStore } from "@/utils/storage"; /**
* 弃用
*/
import { setStore, getStore, clearStore } from "@/utils/storage"
export const TokenKey = 'Access-Token' export const TokenKey = 'Access-Token'
......
import Vue from 'vue'
import axios from 'axios' import axios from 'axios'
import store from '../store' import store from '../store'
import { VueAxios } from './axios' import { VueAxios } from './axios'
import notification from 'ant-design-vue/es/notification' import notification from 'ant-design-vue/es/notification'
import { getToken } from "@/utils/auth" import { ACCESS_TOKEN } from "@/store/mutation-types"
// 创建 axios 实例 // 创建 axios 实例
const service = axios.create({ const service = axios.create({
...@@ -28,7 +28,7 @@ const err = (error) => { ...@@ -28,7 +28,7 @@ const err = (error) => {
// request 拦截器 // request 拦截器
service.interceptors.request.use(config => { service.interceptors.request.use(config => {
const token = getToken() const token = Vue.ls.get(ACCESS_TOKEN)
if (token) { if (token) {
config.headers[ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改 config.headers[ 'Access-Token' ] = token // 让每个请求携带自定义 token 请根据实际情况自行修改
} }
......
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
</div> </div>
<s-table <s-table
ref="table"
size="default" size="default"
:columns="columns" :columns="columns"
:data="loadData" :data="loadData"
...@@ -266,6 +267,8 @@ ...@@ -266,6 +267,8 @@
onChange (row) { onChange (row) {
this.selectedRowKeys = row.selectedRowKeys this.selectedRowKeys = row.selectedRowKeys
this.selectedRows = row.selectedRows this.selectedRows = row.selectedRows
console.log(this.$refs.table)
}, },
toggleAdvanced () { toggleAdvanced () {
this.advanced = !this.advanced this.advanced = !this.advanced
......
...@@ -7585,6 +7585,10 @@ vue-loader@^15.4.2: ...@@ -7585,6 +7585,10 @@ vue-loader@^15.4.2:
vue-hot-reload-api "^2.3.0" vue-hot-reload-api "^2.3.0"
vue-style-loader "^4.1.0" vue-style-loader "^4.1.0"
vue-ls@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/vue-ls/-/vue-ls-3.2.0.tgz#33356ad3ec9c30dac203757cf4036abe4ff767b3"
vue-router@^3.0.1: vue-router@^3.0.1:
version "3.0.1" version "3.0.1"
resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9" resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-3.0.1.tgz#d9b05ad9c7420ba0f626d6500d693e60092cc1e9"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment