浏览代码

feat: 首页入库增加权限控制显示

xyh 2 年之前
父节点
当前提交
40dec2308f

文件差异内容过多而无法显示
+ 1 - 0
src/assets/anomaly.svg


文件差异内容过多而无法显示
+ 1 - 0
src/assets/customer.svg


+ 66 - 0
src/pages/index/hooks.js

@@ -0,0 +1,66 @@
+import sendIcon from '@assets/sending.svg';
+import complateIcon from '@assets/complate.svg';
+import orderIcon from '@assets/order.svg';
+import anomalyIcon from '@assets/anomaly.svg';
+import customerIcon from '@assets/customer.svg';
+import {DELIVER_GOODS_PATH, ORDER_PATH, RECEIVE_GOODS_PATH} from '@routes';
+import {useStore} from 'zustand';
+import {userStore} from '@stores';
+import {useEffect, useState} from 'react';
+
+export function useBtnList() {
+  const {power, token} = useStore(userStore);
+
+  const [btnList, setBtnList] = useState([
+    {
+      title: '收发货',
+      children: [
+        {title: '发货', icon: sendIcon, url: DELIVER_GOODS_PATH},
+        {title: '收货', icon: complateIcon, url: RECEIVE_GOODS_PATH},
+      ],
+    },
+    {
+      title: '查询',
+      children: [],
+    },
+  ]);
+
+  useEffect(
+    function () {
+      const powerContext = Number(power),
+        sendContext = /**    */ 0x000001,
+        anomalyContext = /**    */ 0x000010,
+        customerContext = /**   */ 0x000100;
+
+      setBtnList(function (prev) {
+        const next = [...prev];
+
+        powerContext & sendContext &&
+          next[1].children.push({
+            title: '发货单',
+            icon: orderIcon,
+            url: ORDER_PATH,
+          });
+
+        powerContext & anomalyContext &&
+          next[1].children.push({
+            title: '异常订单',
+            icon: anomalyIcon,
+            url: '',
+          });
+
+        powerContext & customerContext &&
+          next[1].children.push({
+            title: '客户管理',
+            icon: customerIcon,
+            url: '',
+          });
+
+        return next;
+      });
+    },
+    [power],
+  );
+
+  return btnList;
+}

+ 8 - 21
src/pages/index/index.jsx

@@ -1,33 +1,18 @@
 import {View, Image, Text} from '@tarojs/components';
-import classNames from 'classnames';
-import sendIcon from '@assets/sending.svg';
-import complateIcon from '@assets/complate.svg';
-import orderIcon from '@assets/order.svg';
 import face from '@assets/face.svg';
+import classNames from 'classnames';
+import {useStore} from 'zustand';
 import Login from './login';
 import {useBoolean} from 'ahooks';
-import {DELIVER_GOODS_PATH, ORDER_PATH, RECEIVE_GOODS_PATH} from '@routes';
+import {ORDER_PATH} from '@routes';
 import {useNavigate} from '@hooks';
-import {useStore} from 'zustand';
+import {useBtnList} from './hooks';
 import {userStore} from '@stores';
 
-const btnList = [
-  {
-    title: '收发货',
-    children: [
-      {title: '发货', icon: sendIcon, url: DELIVER_GOODS_PATH},
-      {title: '收货', icon: complateIcon, url: RECEIVE_GOODS_PATH},
-    ],
-  },
-  {
-    title: '历史记录',
-    children: [{title: '发货单', icon: orderIcon, url: ORDER_PATH}],
-  },
-];
-
 export default function App() {
   const [visible, {toggle, setFalse}] = useBoolean();
   const {navigateWithLogin, navigate} = useNavigate();
+  const {userName} = useStore(userStore);
 
   function navigateTo(name, needLogin) {
     return function () {
@@ -35,7 +20,7 @@ export default function App() {
     };
   }
 
-  const userName = useStore(userStore, state => state.userName);
+  const btnList = useBtnList();
 
   return (
     <>
@@ -63,6 +48,8 @@ export default function App() {
         </View>
 
         {btnList.map(function (el, index) {
+          if (!el.children.length) return null;
+
           return (
             <View
               key={el.title}

+ 1 - 0
src/pages/index/login/hooks.js

@@ -34,6 +34,7 @@ export function useLogin(userName, password, {onClose}) {
         const userData = {
           token: data.data.token,
           userName: data.data.userName,
+          power: data.data.power,
         };
 
         onClose();

+ 4 - 2
src/stores/user.js

@@ -5,15 +5,17 @@ import {createStore} from 'zustand';
 export const userStore = createStore(function (set) {
   const storage = getStorageSync(USER_TOKEN_STORAGE);
   let token = '',
-    userName = '';
+    userName = '',
+    power = '000000';
 
   if (storage) {
-    ({token, userName} = storage);
+    ({token, userName, power} = storage);
   }
 
   return {
     token,
     userName,
+    power,
     init(data) {
       set(data, true);
     },

+ 4 - 1
src/utils/constants.js

@@ -1,5 +1,8 @@
 /** 请求地址 */
-export const NETWORK_URL = 'https://tms.tuyatrip.com';
+export const NETWORK_URL =
+  process.env.NODE_ENV === 'development'
+    ? 'http://192.168.0.147:8090'
+    : 'https://tms.tuyatrip.com';
 /** token存储 */
 export const USER_TOKEN_STORAGE = 'userToken';
 /** 按钮loading大小 */