Commit 1a102063 by xinla

优化store写法

1 parent e11a2bea
......@@ -2,13 +2,13 @@
* 操作权限处理
*/
import store from '@/stores'
import stores from '@/stores'
export default {
inserted(el, binding, vnode) {
mounted(el, binding, vnode) {
const { value } = binding
const all_permission = '*:*:*'
const permissions = store && store.permissions
const permissions = stores() && stores().permissions
if (value && value instanceof Array && value.length > 0) {
const permissionFlag = value
......
......@@ -2,13 +2,13 @@
* 角色权限处理
*/
import store from '@/stores'
import stores from '@/stores'
export default {
inserted(el, binding, vnode) {
mounted(el, binding, vnode) {
const { value } = binding
const super_admin = 'admin'
const roles = store && store.roles
const roles = stores() && stores().roles
if (value && value instanceof Array && value.length > 0) {
const roleFlag = value
......
......@@ -3,7 +3,7 @@
* 使用 <div @click="search" v-preventReClick="1000">搜索</div>
*/
export default {
inserted(el, binding) {
mounted(el, binding) {
el.addEventListener('click', () => {
el.style.pointerEvents = 'none'
setTimeout(() => {
......
......@@ -70,7 +70,7 @@
<script>
import { mapState } from 'pinia'
import { appStore } from '@/stores'
import stores from '@/stores'
import SidebarItem from './SidebarItem'
......@@ -78,7 +78,7 @@ export default {
components: { SidebarItem },
computed: {
// ...mapState(['settings']),
...mapState(appStore, ['permission_routes', 'sidebarRouters', 'sidebar']),
...mapState(stores, ['permission_routes', 'sidebarRouters', 'sidebar']),
activeMenu() {
const route = this.$route
const { meta, path } = route
......
......@@ -115,7 +115,7 @@
import Settings from './Settings'
import { isExternal } from '@/utils/validate'
import { mapState } from 'pinia'
import { appStore } from '@/stores'
import stores from '@/stores'
import Logo from './Logo'
// import { getCustomerServiceQrUrl } from "@/api/login";
......@@ -138,7 +138,7 @@ export default {
Settings,
},
computed: {
...mapState(appStore, ['avatar', 'name', 'permission_routes']),
...mapState(stores, ['avatar', 'name', 'permission_routes']),
},
mounted() {
// console.log(this.permission_routes)
......
......@@ -28,7 +28,7 @@ import CustomerService from './components/CustomerService'
import ResizeMixin from './mixin/ResizeHandler'
import { mapState } from 'pinia'
import { appStore } from '@/stores'
import stores from '@/stores'
export default {
name: 'Layout',
......@@ -43,7 +43,7 @@ export default {
mixins: [ResizeMixin],
computed: {
// ...mapGetters(['sidebar', 'avatar', 'device']),
...mapState(appStore, {
...mapState(stores, {
sidebar: (state) => state.app.sidebar,
device: (state) => state.app.device,
showSettings: (state) => state.settings.showSettings,
......
......@@ -133,11 +133,10 @@ initAMapApiLoader({
import directive from './directive'
app.use(directive)
// import { createPinia, defineStore } from 'pinia'
import store, { stores } from '@/stores'
import stores, { store } from '@/stores'
app.use(stores)
app.use(store)
app.use(router)
app.config.globalProperties.$store = store()
app.config.globalProperties.$store = stores()
app.mount('#app')
......@@ -6,9 +6,9 @@ import permission from './modules/permission'
import settings from './modules/settings'
import getters from './getters'
export const stores = createPinia()
export const store = createPinia()
export const appStore = defineStore('app', {
export default defineStore('app', {
state: () => ({
app: { ...app.state },
user: { ...user.state },
......@@ -25,5 +25,3 @@ export const appStore = defineStore('app', {
},
getters,
})
export default appStore
import store from '@/stores'
import stores from '@/stores'
/**
* 字符权限校验
......@@ -7,7 +7,7 @@ import store from '@/stores'
*/
export function checkPermi(value) {
if (value && value instanceof Array && value.length > 0) {
const permissions = store && store.permissions
const permissions = stores() && stores().permissions
const permissionDatas = value
const hasPermission = permissions.some((permission) => {
......
import axios from 'axios'
import { ElNotification as Notification, ElMessageBox as MessageBox, ElMessage as Message } from 'element-plus'
import _store from '@/stores'
import stores from '@/stores'
import { getToken, setToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode'
......@@ -34,7 +34,7 @@ service.interceptors.request.use(
// 响应拦截器
service.interceptors.response.use(
(res) => {
let store = _store()
let store = stores()
// 未设置状态码则默认成功状态
const code = res.data.code || 200
// 获取错误信息
......
......@@ -53,7 +53,7 @@
</template>
<script>
import store from '@/stores'
import stores from '@/stores'
import 'vue-cropper/dist/index.css'
import { VueCropper } from 'vue-cropper'
import { uploadAvatar } from '@/api/system/user'
......@@ -75,7 +75,7 @@ export default {
title: '修改头像',
options: {
outputType: 'png', // 裁剪生成图片的格式 jpeg, png, webp
img: store().avatar, //裁剪图片的地址
img: stores().avatar, //裁剪图片的地址
autoCrop: true, // 是否默认生成截图框
autoCropWidth: 200, // 默认生成截图框宽度
autoCropHeight: 200, // 默认生成截图框高度
......@@ -129,7 +129,7 @@ export default {
if (response.code === 200) {
this.open = false
this.options.img = response.imgUrl
store.avatar = this.options.img
stores.avatar = this.options.img
this.msgSuccess('修改成功')
}
this.visible = false
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!