瀏覽代碼

钉钉模式-完善

shaogen1995 2 月之前
父節點
當前提交
eff432c4a2

+ 3 - 2
public/index.html

@@ -12,10 +12,11 @@
 
     <script>
       // 域名地址
-      const baseUrlTempOne = 'https://sit-yiwubwg.4dage.com'
+      // const baseUrlTempOne = 'https://sit-yiwubwg.4dage.com'
+      const baseUrlTempOne = 'http://192.168.20.61:8096'
 
       // 钉钉模式
-      const isDingTemp = false
+      const isDingTemp = true
 
       // const script = document.createElement('script')
       // script.src = `//${window.g_config.cdnHost}/gdt/dd-web-dev-center/3.12.0/assets/js/app_567f70b3-6512-4dca-8683-c2b5e2755fd0.js`

+ 13 - 13
src/components/AuthRoute/index.tsx

@@ -1,13 +1,13 @@
-import { hasToken } from "@//utils/storage";
-import { MessageFu } from "@/utils/message";
-import React from "react";
-import { Redirect, Route } from "react-router-dom";
+import { hasToken } from '@//utils/storage'
+// import { MessageFu } from "@/utils/message";
+import React from 'react'
+import { Redirect, Route } from 'react-router-dom'
 
 type AtahType = {
-  path: string;
-  component: React.FC;
-  [x: string]: any;
-};
+  path: string
+  component: React.FC
+  [x: string]: any
+}
 
 export default function AuthRoute({ path, component: Com, ...rest }: AtahType) {
   return (
@@ -15,18 +15,18 @@ export default function AuthRoute({ path, component: Com, ...rest }: AtahType) {
       path={path}
       {...rest}
       render={() => {
-        if (hasToken()) return <Com />;
+        if (hasToken()) return <Com />
         else {
-          MessageFu.warning("登录失效!");
+          // MessageFu.warning("登录失效!");
           return (
             <Redirect
               to={{
-                pathname: "/login",
+                pathname: '/login'
               }}
             />
-          );
+          )
         }
       }}
     />
-  );
+  )
 }

+ 20 - 0
src/components/DingLogin copy/index.module.scss

@@ -0,0 +1,20 @@
+.DingLogin {
+  width: 100%;
+  height: 100%;
+  background-image: url('../../assets/img/loginBac.jpg');
+  background-size: 100% 100%;
+  :global {
+    .DingLoginBox {
+      padding-top: 100px;
+      width: 100%;
+      height: 100%;
+      background-color: rgba(255, 255, 255, 0.4);
+      display: flex;
+      justify-content: center;
+      align-items: center;
+      & > h2 {
+        letter-spacing: 4px;
+      }
+    }
+  }
+}

+ 57 - 0
src/components/DingLogin copy/index.tsx

@@ -0,0 +1,57 @@
+import React, { useCallback, useEffect, useRef, useState } from 'react'
+import dd from 'gdt-jsapi'
+import styles from './index.module.scss'
+import { MessageFu } from '@/utils/message'
+import { domShowFu } from '@/utils/domShow'
+import { API_ddLogin } from '@/store/action/layout'
+import { setTokenInfo } from '@/utils/storage'
+import history from '@/utils/history'
+function DingLogin() {
+  const [txt, setTxt] = useState('正在授权登录中...')
+
+  let time = useRef(-1)
+  const succFu = useCallback((val: string, code?: string) => {
+    clearTimeout(time.current)
+    time.current = window.setTimeout(async () => {
+      domShowFu('#AsyncSpinLoding', false)
+      if (val === '成功') {
+        const res = await API_ddLogin(code!)
+        if (res.code === 0) {
+          MessageFu.success('登录成功')
+          // 用户信息存到本地
+          setTokenInfo(res.data)
+          history.push('/')
+        }
+      }
+    }, 500)
+  }, [])
+
+  useEffect(() => {
+    domShowFu('#AsyncSpinLoding', true)
+    dd.ready(function () {
+      dd.getAuthCode({
+        corpId: ''
+      })
+        .then(res => {
+          succFu('成功', res.auth_code)
+        })
+        .catch(err => {
+          succFu('失败')
+          setTxt(err)
+          MessageFu.error(err)
+        })
+    })
+  }, [succFu])
+
+  return (
+    <div className={styles.DingLogin}>
+      <div className='DingLoginBox'>
+        <h2>{txt}</h2>
+      </div>
+    </div>
+  )
+}
+
+const MemoDingLogin = React.memo(DingLogin)
+
+export default MemoDingLogin

+ 9 - 0
src/components/DingLogin/data.ts

@@ -0,0 +1,9 @@
+import history from '@/utils/history'
+
+export const loginOutFu = () => {
+  const urlAll = window.location.href
+  const urlArr = urlAll.split('/#/')
+  if (urlArr[1]) {
+    history.push(`/login?back=${urlArr[1]}`)
+  } else history.push('/login')
+}

+ 8 - 2
src/components/DingLogin/index.module.scss

@@ -5,15 +5,21 @@
   background-size: 100% 100%;
   :global {
     .DingLoginBox {
-      padding-top: 100px;
+      padding-top: 150px;
       width: 100%;
       height: 100%;
       background-color: rgba(255, 255, 255, 0.4);
       display: flex;
       justify-content: center;
       align-items: center;
-      & > h2 {
+      flex-direction: column;
+
+      & > h3 {
+        margin-top: 10px;
         letter-spacing: 4px;
+        span {
+          color: var(--themeColor);
+        }
       }
     }
   }

+ 49 - 24
src/components/DingLogin/index.tsx

@@ -2,44 +2,69 @@ import React, { useCallback, useEffect, useRef, useState } from 'react'
 import dd from 'gdt-jsapi'
 import styles from './index.module.scss'
 import { MessageFu } from '@/utils/message'
-import { domShowFu } from '@/utils/domShow'
+import { API_ddLogin } from '@/store/action/layout'
+import { Button } from 'antd'
+import { setTokenInfo } from '@/utils/storage'
+import history from '@/utils/history'
 function DingLogin() {
-  const [txt, setTxt] = useState('正在授权登录中...')
-
-  let time = useRef(-1)
-  const succFu = useCallback((val: string, code?: string) => {
-    clearTimeout(time.current)
-    time.current = window.setTimeout(() => {
-      domShowFu('#AsyncSpinLoding', false)
-
-      if (val === '成功') {
-        alert(code)
-        MessageFu.success('登录成功' + code)
-      }
-    }, 500)
-  }, [])
-
-  useEffect(() => {
-    domShowFu('#AsyncSpinLoding', true)
+  const DDloginFu = useCallback(() => {
     dd.ready(function () {
       dd.getAuthCode({
         corpId: ''
       })
-        .then(res => {
-          succFu('成功', res.auth_code)
+        .then(async res1 => {
+          const code = res1.auth_code
+          const res = await API_ddLogin(code!)
+          if (res.code === 0) {
+            MessageFu.success('登录成功')
+            // 用户信息存到本地
+            setTokenInfo(res.data)
+            const urlAll = window.location.href
+            if (urlAll.includes('?back=')) {
+              const url = urlAll.split('?back=')[1]
+              if (url) history.push(`/${url}`)
+              else history.push('/')
+            } else history.push('/')
+          }
         })
         .catch(err => {
-          succFu('失败')
-          setTxt(err)
           MessageFu.error(err)
         })
     })
-  }, [succFu])
+  }, [])
+
+  const [num, setNum] = useState(10)
+  const numRef = useRef(10)
+
+  useEffect(() => {
+    numRef.current = num
+    if (num <= 0) {
+      clearInterval(time.current)
+      DDloginFu()
+    }
+  }, [DDloginFu, num])
+
+  const time = useRef(-1)
+
+  useEffect(() => {
+    time.current = window.setInterval(() => {
+      setNum(numRef.current - 1)
+    }, 1000)
+
+    return () => {
+      clearInterval(time.current)
+    }
+  }, [])
 
   return (
     <div className={styles.DingLogin}>
       <div className='DingLoginBox'>
-        <h2>{txt}</h2>
+        <Button type='primary' size='large' onClick={() => setNum(0)}>
+          钉钉授权登录
+        </Button>
+        <h3 style={{ opacity: num <= 0 ? '0' : '1' }}>
+          <span>{num}</span>秒之后自动登录
+        </h3>
       </div>
     </div>
   )

+ 7 - 7
src/components/Z3upFiles/data.ts

@@ -8,13 +8,13 @@ export const authFilesLookFu = (name: string, url: string) => {
   const nameRes = name ? name : ''
 
   // pdf和txt 直接新窗口打开
-  const arr0: ('.pdf' | '.txt')[] = ['.pdf', '.txt']
-  arr0.forEach(v => {
-    if (nameRes.toLowerCase().endsWith(v)) {
-      if (url) window.open(baseURL + url)
-      flag = true
-    }
-  })
+  // const arr0: ('.pdf' | '.txt')[] = ['.pdf', '.txt']
+  // arr0.forEach(v => {
+  //   if (nameRes.toLowerCase().endsWith(v)) {
+  //     if (url) window.open(baseURL + url)
+  //     flag = true
+  //   }
+  // })
 
   // 图片使用 antd的图片预览组件
   const arr1 = ['.png', '.jpg', '.jpeg', '.gif']

+ 2 - 2
src/components/ZupFile/index.tsx

@@ -7,10 +7,10 @@ import { B1Xtype } from '@/pages/B_enterTibet/B1collect/data'
 import { baseURL } from '@/utils/http'
 import { fileTypeRes } from '@/store/action/layout'
 import { getTokenFu } from '@/utils/storage'
-import history from '@/utils/history'
 import { API_C2dels } from '@/store/action/C2files'
 import MyPopconfirm from '../MyPopconfirm'
 import { DeleteOutlined } from '@ant-design/icons'
+import { loginOutFu } from '../DingLogin/data'
 
 const { Dragger } = Upload
 
@@ -61,7 +61,7 @@ function ZupFile({ tableList, moduleId, isShow, closeFu, succFu }: Props) {
         }
         if (response.code === 5001 || response.code === 5002) {
           MessageFu.warning('登录失效!')
-          history.push('/login')
+          loginOutFu()
           return false
         }
 

+ 2 - 0
src/pages/A_workbench/A2business/A2editUser/index.tsx

@@ -6,6 +6,7 @@ import ZupOne from '@/components/ZupOne'
 import { UserTableListType } from '@/types'
 import { A2_APIeditUser } from '@/store/action/A2business'
 import { MessageFu } from '@/utils/message'
+import { isDing } from '@/utils/http'
 
 type Props = {
   closeFu: () => void
@@ -71,6 +72,7 @@ function A2editUser({ closeFu, userInfo, succFu }: Props) {
           </div>
           <div className='formRight'>
             <Input
+              disabled={isDing}
               style={{ width: 300 }}
               maxLength={10}
               showCount

+ 19 - 1
src/pages/Layout/index.tsx

@@ -10,7 +10,7 @@ import { Button, Form, Input, Modal } from 'antd'
 import { Base64 } from 'js-base64'
 import encodeStr from '@/utils/pass'
 import { API_getRoleArr, passWordEditAPI } from '@/store/action/layout'
-import { changSetFu, getTokenInfo, removeTokenInfo } from '@/utils/storage'
+import { changSetFu, getTokenInfo, removeTokenInfo, setTokenInfo } from '@/utils/storage'
 import { MessageFu } from '@/utils/message'
 import logoImg from '@/assets/img/logo2.png'
 import NotFound from '@/components/NotFound'
@@ -25,8 +25,26 @@ import store, { RootState } from '@/store'
 import { baseURL, isDing } from '@/utils/http'
 import baseTouXiangImg from '@/assets/img/user.png'
 import { Z5_APIgetInfo } from '@/store/action/Z5role'
+import { getUserInfoByIdAPI } from '@/store/action/Z6user'
 
 function Layout() {
+  // 获取最新用户信息 存到本地
+  const getUserInfoFu = useCallback(async () => {
+    const userInfoJting = getTokenInfo()
+    const res = await getUserInfoByIdAPI(userInfoJting.user.id)
+    if (res.code === 0) {
+      // alert(JSON.stringify(userInfoJting.token))
+      setTokenInfo({
+        ...userInfoJting,
+        user: res.data
+      })
+    }
+  }, [])
+
+  useEffect(() => {
+    getUserInfoFu()
+  }, [getUserInfoFu])
+
   // 获取角色下载权限
   const getDownRole = useCallback(async () => {
     const info = getTokenInfo().user

+ 2 - 1
src/pages/Z_system/Z6user/UserAdd/index.tsx

@@ -9,6 +9,7 @@ import { RootState } from '@/store'
 import { Z5_APIgetList } from '@/store/action/Z5role'
 import { treeLastIdFindFatherFu } from '../data'
 import { UserTableAPIType } from '@/types'
+import { isDing } from '@/utils/http'
 
 type Props = {
   id: any
@@ -142,7 +143,7 @@ function UserAdd({ id, closePage, upTableList, addTableList, formOld }: Props) {
             rules={[{ required: true, message: '请输入真实姓名!' }]}
             getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
           >
-            <Input maxLength={10} showCount placeholder='请输入内容' />
+            <Input disabled={isDing} maxLength={10} showCount placeholder='请输入内容' />
           </Form.Item>
 
           <Form.Item

+ 13 - 4
src/pages/Z_system/Z6user/index.tsx

@@ -12,6 +12,7 @@ import MyPopconfirm from '@/components/MyPopconfirm'
 import { getUserListAPI, userPassResetAPI, userRemoveAPI } from '@/store/action/Z6user'
 import { D4_APIgetTree } from '@/store/action/Z4organization'
 import { buMenRes } from '@/utils/history'
+import { isDing } from '@/utils/http'
 
 const baseFormData: UserTableAPIType = {
   pageNum: 1,
@@ -144,6 +145,10 @@ function Z6user() {
         render: (item: UserTableListType) => {
           return item.isAdmin === 1 ? (
             '-'
+          ) : isDing && item.source === 'DING' ? (
+            <Button size='small' type='text' onClick={() => openEditPageFu(item.id)}>
+              编辑
+            </Button>
           ) : (
             <>
               <MyPopconfirm
@@ -201,10 +206,14 @@ function Z6user() {
           </div>
 
           <div className='selectBoxRow'>
-            <Button type='primary' onClick={() => openEditPageFu(0)}>
-              新增
-            </Button>
-            &emsp;
+            {isDing ? null : (
+              <>
+                <Button type='primary' onClick={() => openEditPageFu(0)}>
+                  新增
+                </Button>
+                &emsp;
+              </>
+            )}
             <Button type='primary' onClick={clickSearch}>
               查询
             </Button>

+ 4 - 2
src/store/action/Z6user.ts

@@ -1,4 +1,4 @@
-import http from '@/utils/http'
+import http, { isDing } from '@/utils/http'
 import { AppDispatch } from '..'
 import { SaveUserType } from '@/types'
 /**
@@ -6,7 +6,9 @@ import { SaveUserType } from '@/types'
  */
 export const getUserListAPI = (data: any): any => {
   return async (dispatch: AppDispatch) => {
-    const res = await http.post('sys/user/list', data)
+    const url = 'sys/user/list?scope=' + (isDing ? 'DING' : 'SYS')
+
+    const res = await http.post(url, data)
     if (res.code === 0) {
       const obj = {
         list: res.data.records,

+ 7 - 0
src/store/action/layout.ts

@@ -82,3 +82,10 @@ export const API_upFile = (data: any, url: string) => {
 export const API_getRoleArr = (roleId: number) => {
   return http.get(`sys/resource/getTreeRolePermissions/${roleId}`)
 }
+
+/**
+ * 钉钉用户登录
+ */
+export const API_ddLogin = (code: string) => {
+  return http.get(`show/getSsoLogin?code=${code}`)
+}

+ 1 - 0
src/types/api/Z6user.d.ts

@@ -24,6 +24,7 @@ export type UserTableListType = {
   deptName: string
   deptNameRes: string
   deptId: number
+  source: string
 }
 
 export type SaveUserType = {

+ 5 - 3
src/utils/history.ts

@@ -13,10 +13,12 @@ export default history
 
 // -------------------所有藏品详情 全部新页面打开-------------------
 export const openGoodsInfoFu = (id: number, src?: string) => {
-  const urlArr = window.location
-  const urlQian = urlArr.origin + urlArr.pathname
+  // const urlArr = window.location
+  // const urlQian = urlArr.origin + urlArr.pathname
 
-  window.open(src ? urlQian + src + id : `${urlQian}#/goodsLook/${id}`, '_blank')
+  history.push(src ? (src + id).replace('#', '') : `/goodsLook/${id}`)
+
+  // window.open(src ? urlQian + src + id : `${urlQian}#/goodsLook/${id}`, '_blank')
 }
 
 // -------------------级联回显-------------------

+ 4 - 4
src/utils/http.ts

@@ -1,14 +1,14 @@
 import axios from 'axios'
-import history from './history'
 import { getTokenInfo, removeTokenInfo } from './storage'
 import store from '@/store'
 import { MessageFu } from './message'
 import { domShowFu } from './domShow'
+import { loginOutFu } from '@/components/DingLogin/data'
 
 // 是否是钉钉登录
 export const isDing = isDingTemp
 
-const envFlag = false
+const envFlag = process.env.NODE_ENV === 'development'
 
 const baseUrlTemp = baseUrlTempOne // 测试环境
 // export const baseUrlTemp = 'http://192.168.20.61:8096' // 线下环境
@@ -64,7 +64,7 @@ http.interceptors.response.use(
     }
     if (response.data.code === 5001 || response.data.code === 5002) {
       removeTokenInfo()
-      history.push('/login')
+      loginOutFu()
       clearTimeout(timeId)
       timeId = window.setTimeout(() => {
         MessageFu.warning('登录失效!')
@@ -95,7 +95,7 @@ http.interceptors.response.use(
           // 没有权限
           if (err.response.data.code === 5003) {
             removeTokenInfo()
-            history.push('/login')
+            loginOutFu()
           }
         } else MessageFu.error('响应错误,请联系管理员!')
       }