shenwu 6 months ago
parent
commit
09db5821ad
2 changed files with 28 additions and 7 deletions
  1. 11 0
      src/pages/MiniApp/EmsCnpl/Auth/index.tsx
  2. 17 7
      src/utils/index.ts

+ 11 - 0
src/pages/MiniApp/EmsCnpl/Auth/index.tsx

@@ -7,6 +7,7 @@ import { PlusCircleOutlined } from "@ant-design/icons"
 import { listOfPage } from "@/services/miniApp/extend"
 import { listOfPage } from "@/services/miniApp/extend"
 import { authSuccess, getMpAccount, preAuth } from "@/services/miniApp/emsCnpl"
 import { authSuccess, getMpAccount, preAuth } from "@/services/miniApp/emsCnpl"
 import { useEffect } from "react"
 import { useEffect } from "react"
+import { searchToObj } from "@/utils"
 
 
 const Page: React.FC = () => {
 const Page: React.FC = () => {
     let { initialState } = useModel("@@initialState")
     let { initialState } = useModel("@@initialState")
@@ -14,6 +15,16 @@ const Page: React.FC = () => {
     let PreAuth = useAjax((params) => preAuth(params)) //授权地址
     let PreAuth = useAjax((params) => preAuth(params)) //授权地址
     let AuthSuccess = useAjax((params) => authSuccess(params)) //授权
     let AuthSuccess = useAjax((params) => authSuccess(params)) //授权
     useEffect(()=>{
     useEffect(()=>{
+        if(history.location.search){
+            let obj = searchToObj(history.location.search)
+            if(obj?.auth_code){
+                console.log(obj,initialState?.selectApp)
+                // AuthSuccess.run({
+                //     appType: initialState?.selectApp?.appType,
+                //     appId: initialState?.selectApp?.id,
+                // })
+            }
+        }
         console.log("history.location.search", history.location.search)
         console.log("history.location.search", history.location.search)
     },[])
     },[])
     // 授权
     // 授权

+ 17 - 7
src/utils/index.ts

@@ -19,7 +19,7 @@ export function getDescriptions(enumArr: any[], arr: any[]) {
  * @param {Array} customParams 要插入数据的目标可以不传  { 0: { disabled: true } } 第0个数据内插入disabled: true
  * @param {Array} customParams 要插入数据的目标可以不传  { 0: { disabled: true } } 第0个数据内插入disabled: true
  * */
  * */
 export function convertEnumArr(enumArr: any, customParams: any = {}, config?: { key: string, value: string }) {
 export function convertEnumArr(enumArr: any, customParams: any = {}, config?: { key: string, value: string }) {
-    let result: { [key: string|number]: { text: string, disabled?: boolean } } = {};
+    let result: { [key: string | number]: { text: string, disabled?: boolean } } = {};
     for (let item of enumArr) {
     for (let item of enumArr) {
         let newItem = { text: config ? item[config.value] : item.description };
         let newItem = { text: config ? item[config.value] : item.description };
         if (customParams[item.value]) {
         if (customParams[item.value]) {
@@ -33,15 +33,15 @@ export function convertEnumArr(enumArr: any, customParams: any = {}, config?: {
 /** base64转File */
 /** base64转File */
 export const dataURLtoFile = (dataurl: any, filename: any) => {
 export const dataURLtoFile = (dataurl: any, filename: any) => {
     let arr = dataurl.split(','),
     let arr = dataurl.split(','),
-      mime = arr[0].match(/:(.*?);/)[1],
-      bstr = atob(arr[1]),
-      n = bstr.length,
-      u8arr = new Uint8Array(n);
+        mime = arr[0].match(/:(.*?);/)[1],
+        bstr = atob(arr[1]),
+        n = bstr.length,
+        u8arr = new Uint8Array(n);
     while (n--) {
     while (n--) {
-      u8arr[n] = bstr.charCodeAt(n);
+        u8arr[n] = bstr.charCodeAt(n);
     }
     }
     return new File([u8arr], filename, { type: mime });
     return new File([u8arr], filename, { type: mime });
-  };
+};
 
 
 // 点击复制
 // 点击复制
 export const copy = (str: string) => {
 export const copy = (str: string) => {
@@ -53,4 +53,14 @@ export const copy = (str: string) => {
     document.execCommand("Copy")
     document.execCommand("Copy")
     document.body.removeChild(element);
     document.body.removeChild(element);
     message.success(`复制成功:${str}`)
     message.success(`复制成功:${str}`)
+}
+// 将地址上的参数解析成对象
+export const searchToObj =(searchStr: string) => {
+    const searchParams = new URLSearchParams(searchStr);
+    // 将其转换为对象
+    const paramsObj: any = {};
+    searchParams.forEach((value, key) => {
+        paramsObj[key] = value;
+    });
+    return paramsObj
 }
 }