From aa27f53cfca6297014ed9169e38ef2215c0b6a1d Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Thu, 16 May 2024 15:53:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9D=83=E9=99=90=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/AuthStore.js | 31 +++++++++++++++++-- .../History/MergeConversationTo.jsx | 5 +-- src/views/Conversations/InputAssign.jsx | 5 +-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index c8bb625..8c00045 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -2,6 +2,9 @@ import { create } from 'zustand' import { fetchJSON, appendRequestHeader } from '@/utils/request' import { isEmpty, isNotEmpty } from '@/utils/commons' +export const PERM_MERGE_CONVERSATION = 'merge-conversation' +export const PERM_ASSIGN_NEW_CONVERSATION = 'assign-new-conversation' + const useAuthStore = create((set, get) => ({ loginUser: { @@ -18,6 +21,30 @@ const useAuthStore = create((set, get) => ({ loginStatus: 0, + isPermitted: (perm) => { + const { loginUser } = get() + + if (perm === PERM_MERGE_CONVERSATION) { + return ['404', '383', '227'].includes(loginUser.userId) + } + + if (perm === PERM_ASSIGN_NEW_CONVERSATION) { + return ['79', '383', '404', '227'].includes(loginUser.userId) + } + // 以上是 Hardcode 判断 + // 以下是权限列表从数据库读取后使用的方法 + // return this.permissionList.some((value, key, arry) => { + // if (value.indexOf(WILDCARD_TOKEN) > -1) { + // return true; + // } + // if (value === perm) { + // return true; + // } + // return false; + // }); + + }, + login: async (authCode) => { const { saveUserSession, setLoginStatus } = get() @@ -89,8 +116,8 @@ const useAuthStore = create((set, get) => ({ appendRequestHeader('X-User-Id', sesstionObj.userId) - window.__spytitle = sesstionObj.username; - window.initPageSpy(); + // window.__spytitle = sesstionObj.username; + // window.initPageSpy(); } }, diff --git a/src/views/Conversations/History/MergeConversationTo.jsx b/src/views/Conversations/History/MergeConversationTo.jsx index c28941a..79844ca 100644 --- a/src/views/Conversations/History/MergeConversationTo.jsx +++ b/src/views/Conversations/History/MergeConversationTo.jsx @@ -3,6 +3,7 @@ import { Button, Form, Input, Radio, Modal } from 'antd'; import { MergeCellsOutlined } from '@ant-design/icons'; import { fetchConversationMerge } from '@/actions/ConversationActions'; import useAuthStore from '@/stores/AuthStore'; +import {PERM_MERGE_CONVERSATION} from '@/stores/AuthStore'; export const MergeToForm = ({ currentWAID, initialValues, onFormInstanceReady }) => { const [form] = Form.useForm(); @@ -73,7 +74,7 @@ export const MergeToForm = ({ currentWAID, initialValues, onFormInstanceReady }) }; const MergeConversationTo = ({ currentWAID, opi_sn, ...props }) => { - const userId = useAuthStore((state) => state.loginUser.userId); + const isPermitted = useAuthStore((state) => state.isPermitted); const [open, setOpen] = useState(false); const [formInstance, setFormInstance] = useState(); const [loading, setLoading] = useState(false); @@ -86,7 +87,7 @@ const MergeConversationTo = ({ currentWAID, opi_sn, ...props }) => { }; return ( <> - {['404', '383', '227'].includes(userId) &&